Kajetan Johannes Hammerle 6 жил өмнө
parent
commit
4fe9d626b8

+ 9 - 4
src/me/hammerle/snuviscript/code/Compiler.java

@@ -182,7 +182,8 @@ public class Compiler
                             case "elseif":
                             case "if":
                             {
-                                data.data.setRelativeJump(code.size());
+                                data.data.setRelativeJump(code.size() + 1);
+                                addCodeInstruction("endif", new InputProvider[] {});
                                 break;
                             }
                             case "for":
@@ -332,11 +333,11 @@ public class Compiler
         
         Instruction[] input = code.toArray(new Instruction[code.size()]);
         
-        /*for(Instruction in : input)
+        for(Instruction in : input)
         {
             System.out.println(in);
         }
-        System.out.println("__________________________________");*/
+        System.out.println("__________________________________");
         /*labels.entrySet().stream().forEach((e) -> 
         {
             System.out.println("LABEL " + e.getKey() + " " + e.getValue());
@@ -685,7 +686,11 @@ public class Compiler
     
     public static Object convert(String input)
     {
-        if(input.equals("true"))
+        if(input == null)
+        {
+            return null;
+        }
+        else if(input.equals("true"))
         {
             return true;
         }

+ 5 - 0
src/me/hammerle/snuviscript/code/FunctionLoader.java

@@ -673,6 +673,11 @@ public class FunctionLoader
             }
             return Void.TYPE;
         });
+        registerFunction("endif", (sc, in) -> 
+        {
+            sc.ifState = true;
+            return Void.TYPE;
+        });
         registerFunction("elseif", (sc, in) -> 
         {
             if(sc.ifState)

+ 14 - 6
test.sbasic

@@ -1,8 +1,16 @@
-hallo();
-
-function hallo()
+print("start");
+if(true) {
+  print(1);
+  if(false) {
+    print(2);
+  }
+  print(3);
+}
+elseif(3 < 4)
 {
-    print("wusi");
+    print(5);
+} 
+else {
+  print(4);
 }
-
-hallo();
+print("ende");