Prechádzať zdrojové kódy

bugfixes, preventing scheduling in subscripts

Kajetan Johannes Hammerle 6 rokov pred
rodič
commit
6d768e8dee

+ 0 - 4
src/me/hammerle/snuviscript/SnuviScript.java

@@ -1,9 +1,6 @@
 package me.hammerle.snuviscript;
 
-import java.io.File;
 import java.io.IOException;
-import java.nio.file.Files;
-import java.util.List;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
@@ -65,7 +62,6 @@ public class SnuviScript
         };
         SnuviParser parser = new SnuviParser(logger, scheduler);
         parser.startScript("./test", ".sbasic", true);
-        parser.startScript("./test", ".sbasic", true);
         
         parser.callEvent("testevent", null, null);
     }  

+ 13 - 10
src/me/hammerle/snuviscript/code/Compiler.java

@@ -312,16 +312,19 @@ public class Compiler
                 }
                 pos++;
             }
-            labelIndex = sb.indexOf("@");
-            if(labelIndex != -1)
+            if(!text && !comment)
             {
-                String label = sb.toString().trim();
-                if(label.charAt(0) != '@')
+                labelIndex = sb.indexOf("@");
+                if(labelIndex != -1)
                 {
-                    throw new PreScriptException("you seriously fucked up the syntax here", line);
+                    String label = sb.toString().trim();
+                    if(label.charAt(0) != '@')
+                    {
+                        throw new PreScriptException("you seriously fucked up the syntax here", line);
+                    }
+                    addLabel(label.substring(1), code.size() - 1);
+                    sb = new StringBuilder();
                 }
-                addLabel(label.substring(1), code.size() - 1);
-                sb = new StringBuilder();
             }
         }
         
@@ -329,11 +332,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());

+ 9 - 1
src/me/hammerle/snuviscript/code/FunctionLoader.java

@@ -61,7 +61,7 @@ public class FunctionLoader
             HashMap<String, Variable> vars = new HashMap<>();
             if(in.length != sub.subScriptInput.length)
             {
-                throw new NullPointerException("invalid number of input for function " + function);
+                throw new NullPointerException("invalid number of parameters at function '" + function + "'");
             }
             // generate local vars
             String s;
@@ -608,6 +608,10 @@ public class FunctionLoader
         });       
         registerFunction("sgoto", (sc, in) -> 
         {
+            if(sc.subScript)
+            {
+                throw new IllegalStateException("sgoto is not allowed in functions");
+            }
             int time = in[0].getInt(sc);
             if(time < 0)
             {
@@ -765,6 +769,10 @@ public class FunctionLoader
         
         registerFunction("waitfor", (sc, in) ->    
         {
+            if(sc.subScript)
+            {
+                throw new IllegalStateException("waitfor is not allowed in functions");
+            }
             long l = in[0].getInt(sc);
             if(l < 0)
             {

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

@@ -4,6 +4,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Stack;
+import me.hammerle.snuviscript.exceptions.CodeTooLongException;
 import me.hammerle.snuviscript.variable.LocalVariable;
 import me.hammerle.snuviscript.variable.Variable;
 
@@ -154,6 +155,10 @@ public final class Script
             cpuTime += time;
             if(cpuTime > 10_000_000)
             {
+                if(subScript)
+                {
+                    throw new CodeTooLongException();
+                }
                 isWaiting = true;
                 isHolded = true;
                 scheduler.scheduleTask(() -> 

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

@@ -118,7 +118,7 @@ public class SnuviParser
         }
         catch(PreScriptException ex)
         {
-            logger.print(ex.getLocalizedMessage(), ex, null, path, null, ex.getLine());
+            logger.print(ex.getLocalizedMessage(), ex, null, path, null, ex.getLine() + 1);
             return null;
         }
     }

+ 2 - 1
src/me/hammerle/snuviscript/code/Utils.java

@@ -160,6 +160,7 @@ public class Utils
                         addNonEmptyString(strings, list, sb.substring(old, pos));
                         old = pos;
                         continue;
+                    case '\t':
                     case ' ':
                         addNonEmptyString(strings, list, sb.substring(old, pos));
                         old = pos + 1;
@@ -183,7 +184,7 @@ public class Utils
                         pos--;
                         if(old == pos)
                         {
-                            throw new PreScriptException("unknown syntax " + c, line);
+                            throw new PreScriptException("unknown syntax '" + c + "'", line);
                         }
                         addNonEmptyString(strings, list, sb.substring(old, pos));
                         old = pos;

+ 6 - 0
src/me/hammerle/snuviscript/constants/ConstantBoolean.java

@@ -32,4 +32,10 @@ public class ConstantBoolean extends InputProvider
     {
         return b;
     }
+
+    @Override
+    public String toString()
+    {
+        return String.valueOf(b);
+    }
 }

+ 6 - 0
src/me/hammerle/snuviscript/constants/ConstantNull.java

@@ -31,6 +31,12 @@ public class ConstantNull extends InputProvider
         return "null";
     }   
     
+    @Override
+    public String toString()
+    {
+        return "null";
+    }
+    
     @Override
     public Variable getVariable(Script sc)
     {

+ 5 - 0
src/me/hammerle/snuviscript/exceptions/CodeTooLongException.java

@@ -0,0 +1,5 @@
+package me.hammerle.snuviscript.exceptions;
+
+public class CodeTooLongException extends RuntimeException
+{
+}

+ 8 - 4
test.sbasic

@@ -1,6 +1,10 @@
-print("Start");
-while(true)
+waitfor(20);
+print("hallo");
+
+function hallo(n)
 {
-    print("HEHE");
+    print(20);
 }
-print("END")
+
+hallo("DICK");
+hallo("4354");

+ 3 - 0
translation

@@ -0,0 +1,3 @@
+Translation from SnuviScript to SnuviScriptRecoded
+
+else, try, catch, break, continue must be without ()