Skip to content

Commit

Permalink
- SNEX: fix index templates not working
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph-hart committed Oct 15, 2024
1 parent b826cf4 commit ef3f769
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 1 deletion.
7 changes: 7 additions & 0 deletions hi_snex/snex_core/snex_jit_BaseCompiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,15 @@ class BaseCompiler

bool useCodeSnippetInErrorMessage() const { return useCodeSnippet; }

bool& isProcessingInlineFunction()
{
return inlineProcessFlag;
}

private:

bool inlineProcessFlag = false;

bool useCodeSnippet = false;

FunctionClass::Ptr mathFunctions;
Expand Down
2 changes: 2 additions & 0 deletions hi_snex/snex_core/snex_jit_Inliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ struct SyntaxTreeInlineData : public InlineData

for (int i = 0; i <= currentStatement->currentPass; i++)
{
ScopedValueSetter<bool> ip(c->isProcessingInlineFunction(), true);

auto thisPass = (BaseCompiler::Pass)i;
BaseCompiler::ScopedPassSwitcher svs(c, thisPass);
c->executePass(thisPass, s, e.get());
Expand Down
2 changes: 1 addition & 1 deletion hi_snex/snex_jit/snex_jit_OperationsSymbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ void Operations::ThisPointer::process(BaseCompiler* compiler, BaseScope* scope)
{
auto thisType = dynamic_cast<StructType*>(type.get());

if(thisType != currentClass)
if(thisType != currentClass && !compiler->isProcessingInlineFunction())
{
// Apparently we need to allow different template parameters to go through
// here so we check the namespaced identifier
Expand Down
2 changes: 2 additions & 0 deletions hi_snex/snex_parser/snex_jit_FunctionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ juce::Result SyntaxTreeInlineParser::flush()

try
{
ScopedValueSetter<bool> svs(d->expression->currentCompiler->isProcessingInlineFunction(), true);

if (d->expression->currentCompiler == nullptr)
d->location.throwError("Internal compiler error");

Expand Down
33 changes: 33 additions & 0 deletions tools/snex_playground/test_files/index/index14.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
BEGIN_TEST_DATA
f: main
ret: int
args: int
input: 12
output: 12
error: ""
filename: "index/index14"
END_TEST_DATA
*/

struct MyClass
{
span<int, 4> data = { 1, 2, 12, 4 };

int process() const
{
index::clamped<0, false> idx;
idx = 2;

return data[idx];
}

};

int main(int input)
{
MyClass obj;

return obj.process();
}

39 changes: 39 additions & 0 deletions tools/snex_playground/test_files/struct/inner_getter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
BEGIN_TEST_DATA
f: main
ret: int
args: int
input: 12
output: 12
error: ""
filename: "struct/inner_getter"
END_TEST_DATA
*/

struct Outer
{
struct Inner
{
int getX()
{
return x;
}

int x = 12;
};

int getFromInner()
{
return data.getX();
}

Inner data;
};

int main(int input)
{
Outer obj;

return obj.getFromInner();
}

0 comments on commit ef3f769

Please sign in to comment.