@@ -32,18 +32,19 @@ private struct Word {
3232 bool inline;
3333 Node[] inlineNodes;
3434 bool error;
35+ Type[] params;
3536}
3637
3738class BackendLua : CompilerBackend {
38- Word[string ] words;
39- string thisFunc;
40- bool inScope;
41- uint blockCounter;
42- bool inWhile;
43- uint currentLoop;
44- bool useLibc;
45- ulong globalStack = 524288 ;
46- ulong arrayStack = 524287 ;
39+ Word[string ] words;
40+ string thisFunc;
41+ bool inScope;
42+ uint blockCounter;
43+ bool inWhile;
44+ uint currentLoop;
45+ bool useLibc;
46+ ulong globalStack = 524288 ;
47+ ulong arrayStack = 524287 ;
4748
4849 this () {
4950 // built in integer types
@@ -106,6 +107,7 @@ class BackendLua : CompilerBackend {
106107 output ~= " gsp = 524288;\n " ;
107108 output ~= " regA = 0;\n " ;
108109 output ~= " regB = 0;\n " ;
110+ output ~= " dspBackup = 0;\n " ;
109111
110112 output ~= "
111113 function cal_pop()
@@ -275,17 +277,29 @@ class BackendLua : CompilerBackend {
275277
276278 thisFunc = node.name;
277279
280+ Type[] params;
281+
282+ foreach (ref type ; node.paramTypes) {
283+ if (! TypeExists(type)) {
284+ Error(node.error, " Type '%s' doesn't exist" , type);
285+ }
286+
287+ params ~= GetType(type);
288+ }
289+
278290 if (node.inline) {
279291 auto globalExtra = cast (GlobalExtra* ) GetGlobal(" _cal_exception" ).extra;
280292 output ~= format(" mem[%d] = 0\n " , globalExtra.addr);
281293
282- words[node.name] = Word(WordType.Callisto, true , node.nodes, node.errors);
294+ words[node.name] = Word(
295+ WordType.Callisto, true , node.nodes, node.errors, params
296+ );
283297 }
284298 else {
285299 assert (! inScope);
286300 inScope = true ;
287301
288- words[node.name] = Word(WordType.Callisto, false , [], node.errors);
302+ words[node.name] = Word(WordType.Callisto, false , [], node.errors, params );
289303
290304 output ~= format(" function func__%s()\n " , node.name.Sanitise());
291305
@@ -302,7 +316,7 @@ class BackendLua : CompilerBackend {
302316 Error(node.error, " Structures cannot be used in function parameters" );
303317 }
304318 }
305- if (paramSize > 0 ) {
319+ if (( paramSize > 0 ) && ! node.manual ) {
306320 output ~= format(" vsp = vsp - %d\n " , paramSize);
307321 foreach (ref var ; variables) {
308322 var.offset += paramSize;
@@ -849,6 +863,9 @@ class BackendLua : CompilerBackend {
849863 Error(node.error, " Non-callisto functions can't throw" );
850864 }
851865
866+ output ~= " vsp = vsp - 1\n " ;
867+ output ~= format(" mem[vsp] = dsp - %d\n " , word.params.length);
868+
852869 if (word.inline) {
853870 foreach (inode ; word.inlineNodes) {
854871 compiler.CompileNode(inode);
@@ -858,6 +875,9 @@ class BackendLua : CompilerBackend {
858875 output ~= format(" func__%s()\n " , node.func.Sanitise());
859876 }
860877
878+ output ~= " dspBackup = mem[vsp]\n " ;
879+ output ~= " vsp = vsp + 1\n " ;
880+
861881 ++ blockCounter;
862882
863883 auto global = GetGlobal(" _cal_exception" );
@@ -866,6 +886,7 @@ class BackendLua : CompilerBackend {
866886 output ~= format(" if mem[%d] == 0 then\n " , globalExtra.addr);
867887 output ~= format(" goto catch_%d_end\n " , blockCounter);
868888 output ~= " end\n " ;
889+ output ~= " dsp = dspBackup\n " ;
869890
870891 // create scope
871892 auto oldVars = variables.dup ;
0 commit comments