Kajetan Johannes Hammerle 5 лет назад
Родитель
Сommit
3a7eb601a3

+ 19 - 1
src/me/hammerle/snuviscript/code/Compiler.java

@@ -249,9 +249,27 @@ public class Compiler
                             in[0] = jump;
                             jumps.add(new JumpWrapper(jump, "function"));
                             addCodeInstruction("function", in);
+                           
                             pos = endIndex + 1;
+                            boolean b = true;
+                            while(b)
+                            {
+                                switch(sb.charAt(pos))
+                                {
+                                    case '{':
+                                        b = false;
+                                        break;
+                                    case '\n':
+                                    case ' ':
+                                        break;
+                                    default:
+                                        throw new PreScriptException("invalid character between function and {", line);
+                                }
+                                pos++;
+                            }
+                            
                             layer++;
-                            sb.delete(0, pos + 1);
+                            sb.delete(0, pos);
                         }
                         else
                         {

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

@@ -166,7 +166,7 @@ public class FunctionLoader
         {
             double d = in[0].getDouble(sc);
             int factor = (int) Math.pow(10, in[1].getInt(sc));
-            return (double) (((int) (d * factor)) / factor);
+            return (double) (((double) Math.round(d * factor)) / factor);
         });
         
         // ---------------------------------------------------------------------  
@@ -707,6 +707,7 @@ public class FunctionLoader
             }
             return Void.TYPE;
         }); 
+        registerAlias("ignoregoto", "igoto");
         registerFunction("sgoto", (sc, in) -> 
         {
             int time = in[0].getInt(sc);

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

@@ -138,6 +138,7 @@ public class SnuviParser
         }
         catch(PreScriptException ex)
         {
+            ex.printStackTrace();
             logger.print(ex.getLocalizedMessage(), ex, null, paths[0], null, ex.getEndLine() + 1);
             return null;
         }

+ 6 - 13
test.sbasic

@@ -1,14 +1,7 @@
-n = 5;
-print(n);
-print(wusi(n));
+array.new(a[4]);
+a[0] = 1;
+a[1] = 2;
+a[2] = 3;
+a[3] = 4;
 
-function wusi(n)
-{
-    if(n < 1)
-    {
-        return 1;
-    }
-    return n * wusi(n - 1);
-}
-
-print(n);
+print(a);