Browse Source

new test for return wrapper, bugfix for return

Kajetan Johannes Hammerle 4 years ago
parent
commit
b5c67dd92c

+ 1 - 1
src/me/hammerle/snuviscript/code/FunctionRegistry.java

@@ -7,7 +7,6 @@ import me.hammerle.snuviscript.inputprovider.ReturnWrapper;
 public class Return extends Instruction
 {
     private final int arguments;
-    private final ReturnWrapper wrapper = new ReturnWrapper();
     
     public Return(int line, int arguments)
     {
@@ -20,6 +19,7 @@ public class Return extends Instruction
     {
         if(o.length > 0)
         {
+            ReturnWrapper wrapper = new ReturnWrapper();
             wrapper.setValue(o[0].get(sc));
             sc.handleReturn(wrapper);
         }

+ 1 - 2
src/me/hammerle/snuviscript/test/Test.java

@@ -27,8 +27,7 @@ public class Test
         testOutput();
         
         LOGGER.reset();
-        PARSER.startScript(true, "test", "./test/test.test");
-        PARSER.callEvent("testevent", null, null);
+        PARSER.startScript(true, "test", "./test/functions/functions18");
         LOGGER.printAll();
     }
     

+ 10 - 0
test/functions/functions18

@@ -0,0 +1,10 @@
+a = wusi(1);
+b = wusi(2);
+print(wusi(1) == wusi(2));
+print(a == b);
+
+function wusi(c)
+{
+    c += 1;
+    return c;
+}

+ 25 - 0
test/functions/functions18.cout

@@ -0,0 +1,25 @@
+push a
+push 1
+use wusi(1)
+use =(2)
+push b
+push 2
+use wusi(1)
+use =(2)
+push 1
+use wusi(1)
+push 2
+use wusi(1)
+use ==(2)
+use print(1)
+push a
+push b
+use ==(2)
+use print(1)
+wusi(24)
+push c#L
+push 1
+use +=(2)
+push c#L
+return(1)
+return(0)

+ 2 - 0
test/functions/functions18.out

@@ -0,0 +1,2 @@
+false
+false

+ 49 - 0
test/functions/functions18.tout

@@ -0,0 +1,49 @@
+(1, LITERAL, "a")
+(1, SET)
+(1, LITERAL, "wusi")
+(1, OPEN_BRACKET)
+(1, NUMBER, 1.0)
+(1, CLOSE_BRACKET)
+(1, SEMICOLON)
+(2, LITERAL, "b")
+(2, SET)
+(2, LITERAL, "wusi")
+(2, OPEN_BRACKET)
+(2, NUMBER, 2.0)
+(2, CLOSE_BRACKET)
+(2, SEMICOLON)
+(3, LITERAL, "print")
+(3, OPEN_BRACKET)
+(3, LITERAL, "wusi")
+(3, OPEN_BRACKET)
+(3, NUMBER, 1.0)
+(3, CLOSE_BRACKET)
+(3, EQUAL)
+(3, LITERAL, "wusi")
+(3, OPEN_BRACKET)
+(3, NUMBER, 2.0)
+(3, CLOSE_BRACKET)
+(3, CLOSE_BRACKET)
+(3, SEMICOLON)
+(4, LITERAL, "print")
+(4, OPEN_BRACKET)
+(4, LITERAL, "a")
+(4, EQUAL)
+(4, LITERAL, "b")
+(4, CLOSE_BRACKET)
+(4, SEMICOLON)
+(6, FUNCTION)
+(6, LITERAL, "wusi")
+(6, OPEN_BRACKET)
+(6, LITERAL, "c")
+(6, CLOSE_BRACKET)
+(7, OPEN_CURVED_BRACKET)
+(8, LITERAL, "c")
+(8, ADD_SET)
+(8, NUMBER, 1.0)
+(8, SEMICOLON)
+(9, RETURN)
+(9, LITERAL, "c")
+(9, SEMICOLON)
+(10, CLOSE_CURVED_BRACKET)
+(11, EOF)