Browse Source

more function tests, correct resetting of var index

Kajetan Johannes Hammerle 4 years ago
parent
commit
f4d46a5ea4

+ 4 - 1
Compiler.c

@@ -271,7 +271,9 @@ static bool cFunction() {
             cError("unexpected end of file: function not closed on line %d", oldLine);
             return false;
         }
-        cLine();
+        if(!cLine()) {
+            return false;
+        }
     }
 
     varIndex = 0;
@@ -320,6 +322,7 @@ static void cForEachLine() {
 }
 
 static void cAllocAndCompile() {
+    varIndex = 0;
     simInit(vars);
     simInit(vars + 1);
     simInit(&functions);

+ 6 - 0
tests/functions/arguments

@@ -1,11 +1,17 @@
 a = 2;
 b = 3;
 
+function wusi(c, d) {
+    print c;
+    print d;
+}
+
 function test(c, d) {
     print a;
     print b;
     print c;
     print d;
+    wusi(4, 5 + 6);
 }
 
 test(a, b);

+ 2 - 0
tests/functions/arguments.out

@@ -2,6 +2,8 @@ null
 null
 2
 3
+4
+11
 2
 3
 null

+ 13 - 0
tests/functions/function2

@@ -0,0 +1,13 @@
+function wusi() {
+    print 6;
+    print 7;
+}
+
+function test() {
+    print 4;
+    print 5;
+    wusi();
+}
+
+test();
+test();

+ 8 - 0
tests/functions/function2.out

@@ -0,0 +1,8 @@
+4
+5
+6
+7
+4
+5
+6
+7