Browse Source

formatting, stack traces

Kajetan Johannes Hammerle 4 years ago
parent
commit
e35e300dbb
50 changed files with 1074 additions and 1554 deletions
  1. 17 26
      src/me/hammerle/snuviscript/ConsoleLogger.java
  2. 20 34
      src/me/hammerle/snuviscript/ConsoleScheduler.java
  3. 7 11
      src/me/hammerle/snuviscript/SnuviScript.java
  4. 183 258
      src/me/hammerle/snuviscript/code/Compiler.java
  5. 1 1
      src/me/hammerle/snuviscript/code/FunctionRegistry.java
  6. 10 29
      src/me/hammerle/snuviscript/code/ISnuviLogger.java
  7. 3 5
      src/me/hammerle/snuviscript/code/ISnuviScheduler.java
  8. 7 12
      src/me/hammerle/snuviscript/code/InputProviderArrayPool.java
  9. 131 204
      src/me/hammerle/snuviscript/code/Script.java
  10. 2 1
      src/me/hammerle/snuviscript/code/ScriptManager.java
  11. 23 46
      src/me/hammerle/snuviscript/code/SnuviUtils.java
  12. 66 125
      src/me/hammerle/snuviscript/config/SnuviConfig.java
  13. 5 8
      src/me/hammerle/snuviscript/exceptions/PreScriptException.java
  14. 27 0
      src/me/hammerle/snuviscript/exceptions/StackTrace.java
  15. 13 21
      src/me/hammerle/snuviscript/inputprovider/ArrayReturnWrapper.java
  16. 11 17
      src/me/hammerle/snuviscript/inputprovider/ConstantBoolean.java
  17. 10 16
      src/me/hammerle/snuviscript/inputprovider/ConstantDouble.java
  18. 10 15
      src/me/hammerle/snuviscript/inputprovider/ConstantNull.java
  19. 8 13
      src/me/hammerle/snuviscript/inputprovider/ConstantString.java
  20. 20 31
      src/me/hammerle/snuviscript/inputprovider/InputProvider.java
  21. 16 25
      src/me/hammerle/snuviscript/inputprovider/LocalVariable.java
  22. 11 18
      src/me/hammerle/snuviscript/inputprovider/ReturnWrapper.java
  23. 16 25
      src/me/hammerle/snuviscript/inputprovider/Variable.java
  24. 10 18
      src/me/hammerle/snuviscript/instructions/Array.java
  25. 3 6
      src/me/hammerle/snuviscript/instructions/Break.java
  26. 5 9
      src/me/hammerle/snuviscript/instructions/Catch.java
  27. 5 9
      src/me/hammerle/snuviscript/instructions/Constant.java
  28. 4 7
      src/me/hammerle/snuviscript/instructions/Continue.java
  29. 7 12
      src/me/hammerle/snuviscript/instructions/Else.java
  30. 9 17
      src/me/hammerle/snuviscript/instructions/ElseIf.java
  31. 6 11
      src/me/hammerle/snuviscript/instructions/EndIf.java
  32. 5 10
      src/me/hammerle/snuviscript/instructions/For.java
  33. 7 13
      src/me/hammerle/snuviscript/instructions/Function.java
  34. 11 19
      src/me/hammerle/snuviscript/instructions/Goto.java
  35. 6 11
      src/me/hammerle/snuviscript/instructions/If.java
  36. 8 14
      src/me/hammerle/snuviscript/instructions/IfGoto.java
  37. 14 22
      src/me/hammerle/snuviscript/instructions/Instruction.java
  38. 9 18
      src/me/hammerle/snuviscript/instructions/Return.java
  39. 5 9
      src/me/hammerle/snuviscript/instructions/SignInverter.java
  40. 4 8
      src/me/hammerle/snuviscript/instructions/Try.java
  41. 7 12
      src/me/hammerle/snuviscript/instructions/UserFunction.java
  42. 6 11
      src/me/hammerle/snuviscript/instructions/While.java
  43. 44 75
      src/me/hammerle/snuviscript/test/Test.java
  44. 21 36
      src/me/hammerle/snuviscript/test/TestLogger.java
  45. 6 10
      src/me/hammerle/snuviscript/test/TestScheduler.java
  46. 4 7
      src/me/hammerle/snuviscript/tokenizer/DataToken.java
  47. 15 28
      src/me/hammerle/snuviscript/tokenizer/StreamCharReader.java
  48. 14 24
      src/me/hammerle/snuviscript/tokenizer/Token.java
  49. 20 32
      src/me/hammerle/snuviscript/tokenizer/TokenType.java
  50. 202 165
      src/me/hammerle/snuviscript/tokenizer/Tokenizer.java

+ 17 - 26
src/me/hammerle/snuviscript/ConsoleLogger.java

@@ -2,62 +2,53 @@ package me.hammerle.snuviscript;
 
 import me.hammerle.snuviscript.code.ISnuviLogger;
 import me.hammerle.snuviscript.code.Script;
+import me.hammerle.snuviscript.exceptions.StackTrace;
 
-public class ConsoleLogger implements ISnuviLogger
-{
+public class ConsoleLogger implements ISnuviLogger {
     @Override
-    public void print(String message, Exception ex, String function, String scriptname, Script sc, int line)
-    {
+    public void print(String message, Exception ex, String function, String scriptname, Script sc, StackTrace lines) {
         StringBuilder sb = new StringBuilder();
 
-        if(ex == null)
-        {
+        if(ex == null) {
             sb.append("debug: '");
             sb.append(message);
             sb.append("'");
-        }
-        else
-        {
+        } else {
             sb.append(ex.getClass().getSimpleName());
             sb.append(": '");
             sb.append(ex.getMessage());
-            if(message != null && !message.isEmpty())
-            {
+            if(message != null && !message.isEmpty()) {
                 sb.append(" - ");
                 sb.append(message);
             }
             sb.append("'");
         }
-        
-        if(scriptname != null && !scriptname.isEmpty())
-        {
+
+        if(scriptname != null && !scriptname.isEmpty()) {
             sb.append(" in script '");
             sb.append(scriptname);
             sb.append("'");
         }
-        
-        if(sc != null)
-        {
+
+        if(sc != null) {
             sb.append(" id '");
             sb.append(sc.getId());
             sb.append("'");
         }
-        
-        if(function != null && !function.isEmpty())
-        {
+
+        if(function != null && !function.isEmpty()) {
             sb.append(" in function '");
             sb.append(function);
             sb.append("'");
         }
-        
-        if(line != -1)
-        {
+
+        if(lines != null) {
             sb.append(" in line '");
-            sb.append(line);
+            sb.append(lines.toString());
             sb.append("'");
         }
-        
+
         System.out.println(sb.toString());
     }
-    
+
 }

+ 20 - 34
src/me/hammerle/snuviscript/ConsoleScheduler.java

@@ -3,54 +3,44 @@ package me.hammerle.snuviscript;
 import java.util.ArrayList;
 import me.hammerle.snuviscript.code.ISnuviScheduler;
 
-public class ConsoleScheduler implements ISnuviScheduler
-{
-    private class Task
-    {
+public class ConsoleScheduler implements ISnuviScheduler {
+    private class Task {
         private Runnable r;
         private long delay;
-        
-        public Task(Runnable r, long delay)
-        {
+
+        public Task(Runnable r, long delay) {
             this.r = r;
             this.delay = delay;
         }
-        
-        public void tick()
-        {
+
+        public void tick() {
             delay--;
-            if(delay <= 0 && r != null)
-            {
+            if(delay <= 0 && r != null) {
                 r.run();
                 r = null;
                 activeTasks--;
             }
         }
-        
-        public void set(Runnable r, long delay)
-        {
+
+        public void set(Runnable r, long delay) {
             this.r = r;
             this.delay = delay;
         }
-        
-        public boolean isFree()
-        {
+
+        public boolean isFree() {
             return r == null;
         }
     }
-    
+
     private int activeTasks = 0;
     private final ArrayList<Task> tasks = new ArrayList<>();
-    
+
     @Override
-    public int scheduleTask(Runnable r, long delay)
-    {
+    public int scheduleTask(Runnable r, long delay) {
         activeTasks++;
-        for(int i = 0; i < tasks.size(); i++)
-        {
+        for(int i = 0; i < tasks.size(); i++) {
             Task t = tasks.get(i);
-            if(t.isFree())
-            {
+            if(t.isFree()) {
                 t.set(r, delay);
                 return -1;
             }
@@ -58,16 +48,12 @@ public class ConsoleScheduler implements ISnuviScheduler
         tasks.add(new Task(r, delay));
         return -1;
     }
-    
-    public void tick()
-    {
-        while(activeTasks > 0)
-        {
-            for(int i = 0; i < tasks.size(); i++)
-            {
+
+    public void tick() {
+        while(activeTasks > 0) {
+            for(int i = 0; i < tasks.size(); i++) {
                 tasks.get(i).tick();
             }
         }
     }
-    
 }

+ 7 - 11
src/me/hammerle/snuviscript/SnuviScript.java

@@ -2,18 +2,14 @@ package me.hammerle.snuviscript;
 
 import me.hammerle.snuviscript.code.ScriptManager;
 
-public class SnuviScript
-{
-    public static void main(String[] args)
-    {
+public class SnuviScript {
+    public static void main(String[] args) {
         me.hammerle.snuviscript.test.Test.test();
         //startForConsole(args);
-    }  
-    
-    private static void startForConsole(String[] args)
-    {
-        if(args.length == 0)
-        {
+    }
+
+    private static void startForConsole(String[] args) {
+        if(args.length == 0) {
             System.out.println("java -jar SnuviScriptRecoded.jar <file_1> [file_2] ...");
             return;
         }
@@ -22,4 +18,4 @@ public class SnuviScript
         sm.startScript(true, args[0], args);
         cs.tick();
     }
-}
+}

+ 183 - 258
src/me/hammerle/snuviscript/code/Compiler.java

@@ -33,47 +33,40 @@ import me.hammerle.snuviscript.instructions.Try;
 import me.hammerle.snuviscript.instructions.UserFunction;
 import me.hammerle.snuviscript.instructions.While;
 
-public class Compiler
-{
+public class Compiler {
     private int index = 0;
     private Token[] tokens = null;
     private final ArrayList<Instruction> instr = new ArrayList<>();
-    
+
     private HashMap<String, Integer> labels = null;
     private HashMap<String, HashMap<String, Integer>> localLabels = null;
     private HashMap<String, Variable> vars = null;
     private final HashMap<String, LocalVariable> localVars = new HashMap<>();
     private HashMap<String, Integer> functions = null;
-    
+
     private final Stack<Break> breakStack = new Stack<>();
     private final Stack<Continue> continueStack = new Stack<>();
-    
+
     private String inFunction = null;
     private boolean lineExpression = false;
 
-    private void addConstant(int line, InputProvider ip)
-    {
+    private void addConstant(int line, InputProvider ip) {
         instr.add(new Constant(line, ip));
     }
-    
-    private void addFunction(int line, int args, String name)
-    {
+
+    private void addFunction(int line, int args, String name) {
         instr.add(new Function(line, args, FunctionRegistry.getFunction(name)));
     }
-    
-    private void addGoto(int line, int jump)
-    {
+
+    private void addGoto(int line, int jump) {
         Goto g = new Goto(line, 0);
         g.setJump(jump);
         instr.add(g);
     }
-    
-    private boolean match(boolean notEOF, TokenType... types)
-    {
-        for(TokenType type : types)
-        {
-            if(check(type, notEOF))
-            {
+
+    private boolean match(boolean notEOF, TokenType... types) {
+        for(TokenType type : types) {
+            if(check(type, notEOF)) {
                 advance();
                 return true;
             }
@@ -81,12 +74,9 @@ public class Compiler
         return false;
     }
 
-    private boolean check(TokenType type, boolean notEOF)
-    {
-        if(isAtEnd())
-        {
-            if(notEOF)
-            {
+    private boolean check(TokenType type, boolean notEOF) {
+        if(isAtEnd()) {
+            if(notEOF) {
                 throw new PreScriptException(String.format("expected %s got %s", type, peek().getType()), peek().getLine());
             }
             return false;
@@ -94,51 +84,41 @@ public class Compiler
         return peek().getType() == type;
     }
 
-    private Token advance()
-    {
-        if(!isAtEnd())
-        {
+    private Token advance() {
+        if(!isAtEnd()) {
             index++;
         }
         return previous();
     }
 
-    private boolean isAtEnd()
-    {
+    private boolean isAtEnd() {
         return peek().getType() == EOF;
     }
 
-    private Token peek()
-    {
+    private Token peek() {
         return tokens[index];
     }
 
-    private Token previous()
-    {
+    private Token previous() {
         return tokens[index - 1];
     }
-    
-    private Token consume(TokenType type) 
-    {
-        if(check(type, false))
-        {
+
+    private Token consume(TokenType type) {
+        if(check(type, false)) {
             return advance();
         }
         throw new PreScriptException(String.format("expected %s got %s", type, peek().getType()), peek().getLine());
-    }  
+    }
 
-    private void noReturnForLastFunction()
-    {
-        if(!instr.isEmpty())
-        {
+    private void noReturnForLastFunction() {
+        if(!instr.isEmpty()) {
             instr.get(instr.size() - 1).setNoReturn();
         }
     }
-    
-    public Instruction[] compile(Token[] tokens, HashMap<String, Integer> labels, 
+
+    public Instruction[] compile(Token[] tokens, HashMap<String, Integer> labels,
             HashMap<String, Variable> vars, HashMap<String, Integer> functions,
-            HashMap<String, HashMap<String, Integer>> localLabels)
-    {
+            HashMap<String, HashMap<String, Integer>> localLabels) {
         this.tokens = tokens;
         index = 0;
         instr.clear();
@@ -149,36 +129,40 @@ public class Compiler
         localVars.clear();
         inFunction = null;
 
-        while(!isAtEnd())
-        {
+        while(!isAtEnd()) {
             line();
         }
-        
+
         this.tokens = null;
         this.labels = null;
         this.vars = null;
         this.functions = null;
         localVars.clear();
-        
+
         Instruction[] code = instr.toArray(new Instruction[instr.size()]);
         instr.clear();
         return code;
     }
-    
-    private void line()
-    {
+
+    private void line() {
         int oldIndex = index;
         Token t = advance();
-        switch(t.getType())
-        {
-            case LABEL: handleLabel(); break;
-            case IF: handleIf(); break;
-            case SEMICOLON: break;
-            case FOR: handleFor(); break;
-            case BREAK: 
+        switch(t.getType()) {
+            case LABEL:
+                handleLabel();
+                break;
+            case IF:
+                handleIf();
+                break;
+            case SEMICOLON:
+                break;
+            case FOR:
+                handleFor();
+                break;
+            case BREAK:
                 Break b = new Break(previous().getLine());
                 breakStack.add(b);
-                instr.add(b); 
+                instr.add(b);
                 consume(SEMICOLON);
                 break;
             case CONTINUE:
@@ -187,45 +171,46 @@ public class Compiler
                 instr.add(c);
                 consume(SEMICOLON);
                 break;
-            case FUNCTION: handleUserFunction(); break;
-            case RETURN: handleReturn(); break;
-            case WHILE: handleWhile(); break;
-            case TRY: handleTry(); break;
+            case FUNCTION:
+                handleUserFunction();
+                break;
+            case RETURN:
+                handleReturn();
+                break;
+            case WHILE:
+                handleWhile();
+                break;
+            case TRY:
+                handleTry();
+                break;
             default:
                 index = oldIndex;
                 lineExpression = false;
                 expression();
-                if(!lineExpression)
-                {
+                if(!lineExpression) {
                     throw new PreScriptException("missing statement", t.getLine());
                 }
                 consume(SEMICOLON);
         }
         noReturnForLastFunction();
     }
-    
-    private void handleLabel()
-    {
+
+    private void handleLabel() {
         String name = previous().getData().toString();
         name = name.substring(1); // cut off @ at start
-        if(inFunction != null)
-        {
+        if(inFunction != null) {
             HashMap<String, Integer> llabel = localLabels.get(inFunction);
-            if(llabel == null)
-            {
+            if(llabel == null) {
                 llabel = new HashMap<>();
                 localLabels.put(inFunction, llabel);
             }
             llabel.put(name, instr.size() - 1);
-        }
-        else
-        {
+        } else {
             labels.put(name, instr.size() - 1);
         }
     }
-    
-    private void handleIf()
-    {
+
+    private void handleIf() {
         Token t = previous();
         consume(OPEN_BRACKET);
         expression();
@@ -233,19 +218,16 @@ public class Compiler
         instr.add(i);
         consume(CLOSE_BRACKET);
         consume(OPEN_CURVED_BRACKET);
-        while(!match(true, CLOSE_CURVED_BRACKET))
-        {
+        while(!match(true, CLOSE_CURVED_BRACKET)) {
             line();
         }
         i.setJump(instr.size() - 1);
         handleElseIf();
         instr.add(new EndIf(instr.get(instr.size() - 1).getLine()));
     }
-    
-    private void handleElseIf()
-    {
-        while(match(false, ELSEIF))
-        {
+
+    private void handleElseIf() {
+        while(match(false, ELSEIF)) {
             Token t = previous();
             consume(OPEN_BRACKET);
             expression();
@@ -253,8 +235,7 @@ public class Compiler
             instr.add(e);
             consume(CLOSE_BRACKET);
             consume(OPEN_CURVED_BRACKET);
-            while(!match(true, CLOSE_CURVED_BRACKET))
-            {
+            while(!match(true, CLOSE_CURVED_BRACKET)) {
                 line();
             }
             e.setJump(instr.size() - 1);
@@ -262,50 +243,41 @@ public class Compiler
         handleElse();
     }
 
-    private void handleElse()
-    {
-        if(match(false, ELSE))
-        {
+    private void handleElse() {
+        if(match(false, ELSE)) {
             Else e = new Else(previous().getLine());
             instr.add(e);
             consume(OPEN_CURVED_BRACKET);
-            while(!match(true, CLOSE_CURVED_BRACKET))
-            {
+            while(!match(true, CLOSE_CURVED_BRACKET)) {
                 line();
             }
             e.setJump(instr.size() - 1);
         }
     }
-    
-    private void handleFor()
-    {
+
+    private void handleFor() {
         Token t = previous();
-        consume(OPEN_BRACKET);    
-        if(!match(false, SEMICOLON))
-        {
+        consume(OPEN_BRACKET);
+        if(!match(false, SEMICOLON)) {
             expression();
             consume(SEMICOLON);
             noReturnForLastFunction();
         }
-        
+
         int forConditionStart = instr.size() - 1;
-        if(!match(false, SEMICOLON))
-        {
+        if(!match(false, SEMICOLON)) {
             expression();
             consume(SEMICOLON);
-        }
-        else
-        {
+        } else {
             int line = instr.isEmpty() ? 1 : instr.get(instr.size() - 1).getLine();
             addConstant(line, ConstantBoolean.TRUE);
         }
         int realGotoLine = instr.get(instr.size() - 1).getLine();
         Goto forGoto = new Goto(realGotoLine, 0);
         instr.add(forGoto);
-        
+
         int forLoopFunctionStart = instr.size() - 1;
-        if(!match(false, CLOSE_BRACKET))
-        {
+        if(!match(false, CLOSE_BRACKET)) {
             expression();
             consume(CLOSE_BRACKET);
             noReturnForLastFunction();
@@ -313,14 +285,13 @@ public class Compiler
         Goto conditionGoto = new Goto(instr.get(instr.size() - 1).getLine(), 0);
         conditionGoto.setJump(forConditionStart);
         instr.add(conditionGoto);
-        
+
         int forStart = instr.size() - 1;
         forGoto.setJump(forStart);
-        For f = new For(t.getLine()); 
+        For f = new For(t.getLine());
         instr.add(f);
         consume(OPEN_CURVED_BRACKET);
-        while(!match(true, CLOSE_CURVED_BRACKET))
-        {
+        while(!match(true, CLOSE_CURVED_BRACKET)) {
             line();
         }
         Goto loopFunctionGoto = new Goto(instr.get(instr.size() - 1).getLine(), 0);
@@ -328,71 +299,60 @@ public class Compiler
         instr.add(loopFunctionGoto);
         int forEnd = instr.size() - 1;
         f.setJump(forEnd);
-        
+
         setBreakContinueJumps(forLoopFunctionStart, forEnd);
     }
-    
-    private void setBreakContinueJumps(int start, int end)
-    {
-        while(!continueStack.empty())
-        {
+
+    private void setBreakContinueJumps(int start, int end) {
+        while(!continueStack.empty()) {
             continueStack.pop().setJump(start);
         }
-        while(!breakStack.empty())
-        {
+        while(!breakStack.empty()) {
             breakStack.pop().setJump(end);
         }
     }
-    
-    private void handleUserFunction()
-    {
+
+    private void handleUserFunction() {
         consume(LITERAL);
         Token t = previous();
         consume(OPEN_BRACKET);
         ArrayList<String> list = new ArrayList<>();
-        if(!match(false, CLOSE_BRACKET))
-        {
-            while(true)
-            {
+        if(!match(false, CLOSE_BRACKET)) {
+            while(true) {
                 consume(LITERAL);
                 list.add(previous().getData().toString());
-                if(match(false, CLOSE_BRACKET))
-                {
+                if(match(false, CLOSE_BRACKET)) {
                     break;
                 }
                 consume(COMMA);
             }
-        }  
+        }
         String name = t.getData().toString().toLowerCase();
         UserFunction uf = new UserFunction(t.getLine(), name, list.toArray(new String[list.size()]));
         functions.put(name, instr.size());
         instr.add(uf);
         consume(OPEN_CURVED_BRACKET);
         inFunction = name;
-        while(!match(true, CLOSE_CURVED_BRACKET))
-        {
+        while(!match(true, CLOSE_CURVED_BRACKET)) {
             line();
         }
         inFunction = null;
         instr.add(new Return(instr.get(instr.size() - 1).getLine(), 0));
         uf.setJump(instr.size() - 1);
     }
-    
-    private void handleReturn()
-    {
+
+    private void handleReturn() {
         Token t = previous();
         int args = 0;
-        if(!match(false, SEMICOLON))
-        {
+        if(!match(false, SEMICOLON)) {
             args = 1;
             expression();
             consume(SEMICOLON);
         }
         instr.add(new Return(t.getLine(), args));
     }
-    
-    private void handleWhile()
-    {
+
+    private void handleWhile() {
         int whileStart = instr.size() - 1;
         Token t = previous();
         consume(OPEN_BRACKET);
@@ -401,8 +361,7 @@ public class Compiler
         instr.add(w);
         consume(CLOSE_BRACKET);
         consume(OPEN_CURVED_BRACKET);
-        while(!match(true, CLOSE_CURVED_BRACKET))
-        {
+        while(!match(true, CLOSE_CURVED_BRACKET)) {
             line();
         }
         addGoto(instr.get(instr.size() - 1).getLine(), whileStart);
@@ -410,14 +369,12 @@ public class Compiler
         w.setJump(whileEnd);
         setBreakContinueJumps(whileStart, whileEnd);
     }
-    
-    private void handleTry()
-    {
+
+    private void handleTry() {
         Try t = new Try(previous().getLine());
         instr.add(t);
         consume(OPEN_CURVED_BRACKET);
-        while(!match(true, CLOSE_CURVED_BRACKET))
-        {
+        while(!match(true, CLOSE_CURVED_BRACKET)) {
             line();
         }
         consume(CATCH);
@@ -425,40 +382,33 @@ public class Compiler
         instr.add(c);
         t.setJump(instr.size() - 1);
         consume(OPEN_CURVED_BRACKET);
-        while(!match(true, CLOSE_CURVED_BRACKET))
-        {
+        while(!match(true, CLOSE_CURVED_BRACKET)) {
             line();
         }
         c.setJump(instr.size() - 1);
     }
 
-    private void expression()
-    {
-        if(isAtEnd())
-        {
+    private void expression() {
+        if(isAtEnd()) {
             throw new PreScriptException(String.format("expected expression got %s", peek().getType()), peek().getLine());
         }
         assignment();
     }
-    
-    private void assignment()
-    {
+
+    private void assignment() {
         logicalOr();
-        if(match(false, SET, ADD_SET, SUB_SET, MUL_SET, DIV_SET, MOD_SET, LEFT_SHIFT_SET, 
-                RIGHT_SHIFT_SET, BIT_AND_SET, BIT_XOR_SET, BIT_OR_SET))
-        {
+        if(match(false, SET, ADD_SET, SUB_SET, MUL_SET, DIV_SET, MOD_SET, LEFT_SHIFT_SET,
+                RIGHT_SHIFT_SET, BIT_AND_SET, BIT_XOR_SET, BIT_OR_SET)) {
             Token t = previous();
             assignment();
             addFunction(t.getLine(), 2, t.getType().getName());
             lineExpression = true;
         }
-    }   
-    
-    private void logicalOr()
-    {
+    }
+
+    private void logicalOr() {
         logicalAnd();
-        while(match(false, OR))
-        {
+        while(match(false, OR)) {
             Token t = previous();
             IfGoto ifGoto = new IfGoto(t.getLine(), true);
             instr.add(ifGoto);
@@ -466,13 +416,11 @@ public class Compiler
             ifGoto.setJump(instr.size());
             addFunction(t.getLine(), 2, t.getType().getName());
         }
-    }  
-    
-    private void logicalAnd()
-    {
+    }
+
+    private void logicalAnd() {
         equality();
-        while(match(false, AND))
-        {
+        while(match(false, AND)) {
             Token t = previous();
             IfGoto ifGoto = new IfGoto(t.getLine(), false);
             instr.add(ifGoto);
@@ -480,183 +428,160 @@ public class Compiler
             ifGoto.setJump(instr.size());
             addFunction(t.getLine(), 2, t.getType().getName());
         }
-    }  
+    }
 
-    private void equality()
-    {
+    private void equality() {
         comparison();
-        while(match(false, EQUAL, NOT_EQUAL))
-        {
+        while(match(false, EQUAL, NOT_EQUAL)) {
             Token t = previous();
             comparison();
             addFunction(t.getLine(), 2, t.getType().getName());
         }
     }
 
-    private void comparison()
-    {
+    private void comparison() {
         addition();
-        while(match(false, GREATER, GREATER_EQUAL, LESS, LESS_EQUAL))
-        {
+        while(match(false, GREATER, GREATER_EQUAL, LESS, LESS_EQUAL)) {
             Token t = previous();
             addition();
             addFunction(t.getLine(), 2, t.getType().getName());
         }
     }
 
-    private void addition()
-    {
+    private void addition() {
         multiplication();
-        while(match(false, SUB, ADD))
-        {
+        while(match(false, SUB, ADD)) {
             Token t = previous();
             multiplication();
             addFunction(t.getLine(), 2, t.getType().getName());
         }
     }
 
-    private void multiplication()
-    {
+    private void multiplication() {
         unary();
-        while(match(false, DIV, MUL, MOD))
-        {
+        while(match(false, DIV, MUL, MOD)) {
             Token t = previous();
             unary();
             addFunction(t.getLine(), 2, t.getType().getName());
         }
     }
 
-    private void unary()
-    {
-        if(match(false, INVERT, BIT_INVERT, SUB, INC, DEC))
-        {
+    private void unary() {
+        if(match(false, INVERT, BIT_INVERT, SUB, INC, DEC)) {
             Token t = previous();
             unary();
             addFunction(t.getLine(), 1, t.getType().getName());
-            if(t.getType() == INC || t.getType() == DEC)
-            {
+            if(t.getType() == INC || t.getType() == DEC) {
                 lineExpression = true;
             }
             return;
         }
         postUnary();
     }
-    
-    private void postUnary()
-    {
+
+    private void postUnary() {
         primary();
-        while(match(false, INC, DEC))
-        {
+        while(match(false, INC, DEC)) {
             Token t = previous();
             addFunction(t.getLine(), 1, "p" + t.getType().getName());
             lineExpression = true;
         }
     }
 
-    private void primary()
-    {
+    private void primary() {
         Token t = advance();
-        switch(t.getType())
-        {
-            case FALSE: addConstant(t.getLine(), ConstantBoolean.FALSE); return;
-            case TRUE: addConstant(t.getLine(), ConstantBoolean.TRUE); return;
-            case NULL: addConstant(t.getLine(), ConstantNull.NULL); return;
-            case STRING: addConstant(t.getLine(), new ConstantString(t.getData().toString())); return;
-            case LABEL: addConstant(t.getLine(), new ConstantString(t.getData().toString().substring(1))); return;
-            case NUMBER: addConstant(t.getLine(), new ConstantDouble((Double) t.getData())); return;
+        switch(t.getType()) {
+            case FALSE:
+                addConstant(t.getLine(), ConstantBoolean.FALSE);
+                return;
+            case TRUE:
+                addConstant(t.getLine(), ConstantBoolean.TRUE);
+                return;
+            case NULL:
+                addConstant(t.getLine(), ConstantNull.NULL);
+                return;
+            case STRING:
+                addConstant(t.getLine(), new ConstantString(t.getData().toString()));
+                return;
+            case LABEL:
+                addConstant(t.getLine(), new ConstantString(t.getData().toString().substring(1)));
+                return;
+            case NUMBER:
+                addConstant(t.getLine(), new ConstantDouble((Double) t.getData()));
+                return;
             case OPEN_BRACKET:
                 expression();
                 consume(CLOSE_BRACKET);
                 return;
             case LITERAL:
-                if(match(false, OPEN_SQUARE_BRACKET))
-                {
+                if(match(false, OPEN_SQUARE_BRACKET)) {
                     handleArray(t);
-                }
-                else if(match(false, OPEN_BRACKET))
-                {
+                } else if(match(false, OPEN_BRACKET)) {
                     handleFunction(t);
-                }
-                else
-                {
+                } else {
                     addConstant(t.getLine(), getVariable(t.getData().toString()));
                 }
                 return;
         }
         throw new PreScriptException(String.format("unexpected token %s", t.getType()), t.getLine());
     }
-    
-    public void handleFunction(Token t)
-    {
+
+    public void handleFunction(Token t) {
         int args = 0;
-        if(peek().getType() != CLOSE_BRACKET)
-        {
-            while(true)
-            {
+        if(peek().getType() != CLOSE_BRACKET) {
+            while(true) {
                 args++;
                 expression();
-                if(match(false, CLOSE_BRACKET))
-                {
+                if(match(false, CLOSE_BRACKET)) {
                     break;
                 }
                 consume(COMMA);
             }
-        }
-        else
-        {
+        } else {
             consume(CLOSE_BRACKET);
         }
         addFunction(t.getLine(), args, t.getData().toString());
         lineExpression = true;
     }
-    
-    public void handleArray(Token t)
-    {
-        if(peek().getType() == CLOSE_SQUARE_BRACKET)
-        {
+
+    public void handleArray(Token t) {
+        if(peek().getType() == CLOSE_SQUARE_BRACKET) {
             throw new PreScriptException("empty array access", peek().getLine());
         }
         int args = 0;
-        while(true)
-        {
+        while(true) {
             args++;
             expression();
-            if(match(false, CLOSE_SQUARE_BRACKET))
-            {
+            if(match(false, CLOSE_SQUARE_BRACKET)) {
                 break;
             }
             consume(COMMA);
         }
         instr.add(new Array(t.getLine(), args, getVariable(t.getData().toString())));
     }
-    
-    private Variable getVariable(String name)
-    {
+
+    private Variable getVariable(String name) {
         boolean global = name.startsWith("$");
-        if(inFunction != null && !global)
-        {
+        if(inFunction != null && !global) {
             LocalVariable v = localVars.get(name);
-            if(v != null)
-            {
+            if(v != null) {
                 return v;
             }
             v = new LocalVariable(name);
             localVars.put(name, v);
             return v;
         }
-        
-        if(global)
-        {
+
+        if(global) {
             name = name.substring(1);
         }
-        
+
         Variable v = vars.get(name);
-        if(v != null)
-        {
+        if(v != null) {
             return v;
         }
         v = new Variable(name);
         vars.put(name, v);
         return v;
     }
-}
+}

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

@@ -484,7 +484,7 @@ public class FunctionRegistry {
             in[1].set(sc, o);
         });
         registerConsumer("print", (sc, in) -> {
-            sc.getScriptManager().getLogger().print(SnuviUtils.connect(sc, in, 0), null, "print", sc.getName(), sc, sc.getActiveSourceLine());
+            sc.getScriptManager().getLogger().print(SnuviUtils.connect(sc, in, 0), null, "print", sc.getName(), sc, sc.getStackTrace());
         });
         registerConsumer("rprint", (sc, in) -> System.out.println(SnuviUtils.connect(sc, in, 0)));
         registerConsumer("waitfor", (sc, in) -> {

+ 10 - 29
src/me/hammerle/snuviscript/code/ISnuviLogger.java

@@ -1,34 +1,15 @@
 package me.hammerle.snuviscript.code;
 
-public interface ISnuviLogger 
-{
-    /** Prints messages depending on the implementation.
-     *
-     * @param message a message, can be null
-     * @param ex an involved exception, can be null
-     * @param function an involved snuvi script function, can be null
-     * @param scriptname the name of an involved script, mainly used for 
-     * prescript exceptions, can be null, but will never be null if sc != null
-     * @param sc an involved script, can be null
-     * @param line an involved script line, -1 if no line is involved
-     */
-    public void print(String message, Exception ex, String function, String scriptname, Script sc, int line);
-    
-    /** Prints messages depending on the implementation.
-     *
-     * @param ex an involved exception, can be null
-     */
-    public default void print(Exception ex)
-    {
-        print(null, ex, null, null, null, -1);
+import me.hammerle.snuviscript.exceptions.StackTrace;
+
+public interface ISnuviLogger {
+    public void print(String message, Exception ex, String function, String scriptname, Script sc, StackTrace lines);
+
+    public default void print(Exception ex) {
+        print(null, ex, null, null, null, null);
     }
-    
-    /** Prints messages depending on the implementation.
-     *
-     * @param message a message, can be null
-     */
-    public default void print(String message)
-    {
-        print(message, null, null, null, null, -1);
+
+    public default void print(String message) {
+        print(message, null, null, null, null, null);
     }
 }

+ 3 - 5
src/me/hammerle/snuviscript/code/ISnuviScheduler.java

@@ -1,11 +1,9 @@
 package me.hammerle.snuviscript.code;
 
-public interface ISnuviScheduler 
-{
-    public default int scheduleTask(Runnable r)
-    {
+public interface ISnuviScheduler {
+    public default int scheduleTask(Runnable r) {
         return scheduleTask(r, 0);
     }
-    
+
     public int scheduleTask(Runnable r, long delay);
 }

+ 7 - 12
src/me/hammerle/snuviscript/code/InputProviderArrayPool.java

@@ -2,23 +2,18 @@ package me.hammerle.snuviscript.code;
 
 import me.hammerle.snuviscript.inputprovider.InputProvider;
 
-public class InputProviderArrayPool
-{
+public class InputProviderArrayPool {
     private final static int POOL_SIZE = 10;
     private final static InputProvider[][] IN = new InputProvider[POOL_SIZE][];
-    
-    static
-    {
-        for(int i = 0; i < IN.length; i++)
-        {
+
+    static {
+        for(int i = 0; i < IN.length; i++) {
             IN[i] = new InputProvider[i];
         }
     }
-    
-    public static InputProvider[] get(int length)
-    {
-        if(length < 0 || length >= POOL_SIZE)
-        {
+
+    public static InputProvider[] get(int length) {
+        if(length < 0 || length >= POOL_SIZE) {
             return new InputProvider[length];
         }
         return IN[length];

+ 131 - 204
src/me/hammerle/snuviscript/code/Script.java

@@ -10,37 +10,37 @@ import java.util.HashSet;
 import java.util.Stack;
 import java.util.function.Consumer;
 import me.hammerle.snuviscript.exceptions.PreScriptException;
+import me.hammerle.snuviscript.exceptions.StackTrace;
 import me.hammerle.snuviscript.inputprovider.ReturnWrapper;
 import me.hammerle.snuviscript.tokenizer.Tokenizer;
 import me.hammerle.snuviscript.inputprovider.Variable;
 import me.hammerle.snuviscript.instructions.Instruction;
 import me.hammerle.snuviscript.instructions.UserFunction;
 
-public final class Script 
-{
+public final class Script {
     private static int idCounter = 0;
-    
+
     private final int id;
     private final String name;
     private final ScriptManager sm;
-    
+
     private int lineIndex = 0;
     private final Instruction[] code;
     private final Stack<InputProvider> dataStack = new Stack<>();
     private final Stack<Integer> returnStack = new Stack<>();
-    
+
     private final HashMap<String, Integer> labels = new HashMap<>();
     private final HashMap<String, HashMap<String, Integer>> localLabels = new HashMap<>();
     private final HashMap<String, Variable> vars = new HashMap<>();
-    private final Stack<HashMap<String, Variable>> localVars = new Stack<>();   
+    private final Stack<HashMap<String, Variable>> localVars = new Stack<>();
     private final HashMap<String, Integer> functions = new HashMap<>();
-    
+
     private Stack<Boolean> ifState = new Stack<>();
     private Stack<Integer> stackElements = new Stack<>();
     private int errorLine = -1;
     private Stack<String> inFunction = new Stack<>();
     private Stack<Boolean> returnVarPop = new Stack<>();
-    
+
     // states if event broadcasts should be received, otherwise only direct event calls work
     private boolean eventBroadcast;
     // waiting scripts stop executing and run again on an event
@@ -48,16 +48,15 @@ public final class Script
     // holded scripts do not receive events
     private boolean isHolded;
     private boolean stackTrace;
-    
+
     private HashSet<String> loadedEvents = new HashSet<>();
-    
+
     private final Consumer<Script> onStart;
     private final Consumer<Script> onTerm;
-    
+
     private final ArrayList<AutoCloseable> closeables = new ArrayList<>();
-    
-    public Script(ScriptManager sm, Consumer<Script> onStart, Consumer<Script> onTerm, String name, String... path)
-    {
+
+    public Script(ScriptManager sm, Consumer<Script> onStart, Consumer<Script> onTerm, String name, String... path) {
         ifState.push(true);
         this.id = idCounter++;
         this.name = name;
@@ -66,28 +65,23 @@ public final class Script
         this.onTerm = onTerm;
         Tokenizer t = new Tokenizer();
         InputStream[] streams = new InputStream[path.length];
-        for(int i = 0; i < streams.length; i++)
-        {
-            try
-            {
+        for(int i = 0; i < streams.length; i++) {
+            try {
                 streams[i] = new FileInputStream(path[i]);
-            }
-            catch(FileNotFoundException ex)
-            {
+            } catch(FileNotFoundException ex) {
                 throw new PreScriptException(ex.getMessage(), -1);
             }
         }
         Compiler c = new Compiler();
         this.code = c.compile(t.tokenize(streams), labels, vars, functions, localLabels);
-        
+
         /*int i = 0;
         for(Instruction in : code)
         {
             System.out.printf("%3d: %5b | %s\n", i, in.shouldNotReturnValue(), in);
             i++;
         }*/
-        
-        /*this.parser = parser;
+ /*this.parser = parser;
         this.logger = parser.getLogger();
         this.scheduler = parser.getScheduler();
         this.labels = new HashMap<>();
@@ -115,71 +109,55 @@ public final class Script
         
         this.code = OldCompiler.compile(this, code, labels, functions, localLabels);*/
     }
-    
-    private void pushIfNotNull(InputProvider in)
-    {
-        if(in != null)
-        {
+
+    private void pushIfNotNull(InputProvider in) {
+        if(in != null) {
             dataStack.push(in);
         }
     }
-    
-    public void run()
-    {
+
+    public void run() {
         isWaiting = false;
         //System.out.println("_________________________");
         long endTime = System.nanoTime() + 15_000_000;
-        while(lineIndex < code.length && !isWaiting && !isHolded)
-        {  
-            try
-            {
+        while(lineIndex < code.length && !isWaiting && !isHolded) {
+            try {
                 Instruction instr = code[lineIndex];
                 //System.out.println("EXECUTE: " + instr + " " + dataStack);
-                if(instr.getArguments() > 0)
-                {
+                if(instr.getArguments() > 0) {
                     InputProvider[] args = InputProviderArrayPool.get(instr.getArguments());
-                    for(int i = args.length - 1; i >= 0; i--)
-                    {
+                    for(int i = args.length - 1; i >= 0; i--) {
                         args[i] = dataStack.pop();
                     }
                     pushIfNotNull(instr.execute(this, args));
-                }
-                else
-                {
+                } else {
                     pushIfNotNull(instr.execute(this, new InputProvider[0]));
                 }
                 //System.out.println("AFTER EXECUTE: " + dataStack);
                 lineIndex++;
-            }
-            catch(Exception ex)
-            {
-                if(stackTrace)
-                {
+            } catch(Exception ex) {
+                if(stackTrace) {
                     ex.printStackTrace();
                 }
-                if(errorLine != -1)
-                {
+                if(errorLine != -1) {
                     int elements = stackElements.pop();
-                    while(dataStack.size() > elements)
-                    {
+                    while(dataStack.size() > elements) {
                         dataStack.pop();
                     }
-                    
+
                     lineIndex = errorLine + 1;
                     errorLine = -1;
                     continue;
                 }
-                sm.getLogger().print(null, ex, code[lineIndex].getName(), name, this, code[lineIndex].getLine());
+                sm.getLogger().print(null, ex, code[lineIndex].getName(), name, this, new StackTrace(code[lineIndex].getLine(), returnStack));
                 break;
             }
-            
-            if(System.nanoTime() > endTime)
-            {
+
+            if(System.nanoTime() > endTime) {
                 isHolded = true;
-                sm.getScheduler().scheduleTask(() -> 
-                {           
-                    if(!shouldTerm())
-                    {
+                sm.getScheduler().scheduleTask(()
+                        -> {
+                    if(!shouldTerm()) {
                         isHolded = false;
                         run();
                     }
@@ -188,107 +166,88 @@ public final class Script
             }
         }
         //System.out.println(count + " " + (15_000_000 / count));
-        if(shouldTerm() && !dataStack.isEmpty())
-        {
+        if(shouldTerm() && !dataStack.isEmpty()) {
             sm.getLogger().print(String.format("data stack is not empty %s", dataStack));
         }
     }
 
-    public String getName() 
-    {
+    public String getName() {
         return name;
     }
 
-    public int getId() 
-    {
+    public int getId() {
         return id;
     }
-    
-    public int getActiveSourceLine()
-    {
-        if(lineIndex >= 0 && lineIndex < code.length)
-        {
-            return code[lineIndex].getLine();
+
+    public StackTrace getStackTrace() {
+        if(lineIndex >= 0 && lineIndex < code.length) {
+            return new StackTrace(code[lineIndex].getLine(), returnStack);
         }
-        return -1;
+        return null;
     }
-    
-    public ScriptManager getScriptManager()
-    {
+
+    public ScriptManager getScriptManager() {
         return sm;
     }
-    
-    private HashMap<String, Integer> getLabels()
-    {
+
+    private HashMap<String, Integer> getLabels() {
         return inFunction.isEmpty() ? labels : localLabels.get(inFunction.peek());
     }
-    
-    public void gotoLabel(String label, boolean error, int add)
-    {
+
+    public void gotoLabel(String label, boolean error, int add) {
         lineIndex = getLabels().getOrDefault(label, error ? null : lineIndex) + add;
     }
-    
-    public void gotoLabel(String label, boolean error)
-    {
+
+    public void gotoLabel(String label, boolean error) {
         gotoLabel(label, error, 0);
     }
-    
-    public void goSub(String label)
-    {
+
+    public void goSub(String label) {
         int line = getLabels().get(label);
         returnStack.push(lineIndex);
         lineIndex = line;
         returnVarPop.push(false);
     }
-    
-    public void jumpTo(int jump)
-    {
+
+    public void jumpTo(int jump) {
         lineIndex = jump;
     }
-    
-    public void setIfState(boolean state)
-    {
+
+    public void setIfState(boolean state) {
         ifState.pop();
         ifState.push(state);
     }
-    
-    public boolean getIfState()
-    {
+
+    public boolean getIfState() {
         return ifState.peek();
     }
-    
-    public void setErrorLine(int line)
-    {
+
+    public void setErrorLine(int line) {
         errorLine = line;
-        if(line != -1)
-        {
+        if(line != -1) {
             stackElements.push(dataStack.size());
         }
     }
-    
-    public void handleFunction(String function, InputProvider[] in) throws Exception
-    {
+
+    public void handleFunction(String function, InputProvider[] in) throws Exception {
         Integer sub = functions.get(function);
-        if(sub == null)
-        {
+        if(sub == null) {
             throw new IllegalArgumentException(String.format("function '%s' does not exist", function));
         }
         UserFunction uf = (UserFunction) code[sub];
         String[] args = uf.getArgumentNames();
-        
+
         HashMap<String, Variable> lvars = new HashMap<>();
-        if(in.length != args.length)
-        {
+        if(in.length != args.length) {
             throw new IllegalArgumentException(String.format("invalid number of arguments at function '%s'", function));
         }
-        
-        for(int i = 0; i < in.length; i++)
-        {
+
+        for(int i = 0; i < in.length; i++) {
             Variable v = new Variable(args[i]);
             v.set(this, in[i].get(this));
             lvars.put(args[i], v);
         }
-        
+
         ifState.push(true);
         localVars.push(lvars);
         returnStack.push(lineIndex);
@@ -296,161 +255,129 @@ public final class Script
         inFunction.push(function);
         returnVarPop.push(true);
     }
-    
-    public void handleReturn(ReturnWrapper wrapper)
-    {
+
+    public void handleReturn(ReturnWrapper wrapper) {
         lineIndex = returnStack.pop();
-        if(returnVarPop.pop())
-        {
+        if(returnVarPop.pop()) {
             ifState.pop();
             inFunction.pop();
             localVars.pop();
-            if(wrapper != null && !code[lineIndex].shouldNotReturnValue())
-            {
+            if(wrapper != null && !code[lineIndex].shouldNotReturnValue()) {
                 dataStack.add(wrapper);
             }
         }
     }
-    
-    public Variable getOrAddLocalVariable(String name)
-    {
+
+    public Variable getOrAddLocalVariable(String name) {
         HashMap<String, Variable> map = localVars.peek();
         Variable v = map.get(name);
-        if(v != null)
-        {
+        if(v != null) {
             return v;
         }
         v = new Variable(name);
         map.put(name, v);
         return v;
     }
-    
-    public InputProvider peekDataStack()
-    {
+
+    public InputProvider peekDataStack() {
         return dataStack.peek();
     }
-    
-    public void setEventBroadcast(boolean eventBroadcast)
-    {
+
+    public void setEventBroadcast(boolean eventBroadcast) {
         this.eventBroadcast = eventBroadcast;
     }
-    
-    public boolean shouldReceiveEventBroadcast()
-    {
+
+    public boolean shouldReceiveEventBroadcast() {
         return eventBroadcast;
     }
-    
-    public void term()
-    {
+
+    public void term() {
         lineIndex = code.length;
     }
-    
-    public boolean shouldTerm()
-    {
+
+    public boolean shouldTerm() {
         return lineIndex < 0 || lineIndex >= code.length;
     }
-    
-    public void onTerm()
-    {
-        if(onTerm != null)
-        {
+
+    public void onTerm() {
+        if(onTerm != null) {
             onTerm.accept(this);
         }
-        closeables.forEach(c -> 
-        {
-            sm.getLogger().print("prepared statement not closed", null, null, name, this, -1);
-            try
-            {
+        closeables.forEach(c
+                -> {
+            sm.getLogger().print("prepared statement not closed", null, null, name, this, null);
+            try {
                 c.close();
-            }
-            catch(Exception ex)
-            {
-                sm.getLogger().print("cannot close closeable in script", ex, null, name, this, -1);
+            } catch(Exception ex) {
+                sm.getLogger().print("cannot close closeable in script", ex, null, name, this, null);
             }
         });
     }
-    
-    public void onStart()
-    {
-        if(onStart != null)
-        {
+
+    public void onStart() {
+        if(onStart != null) {
             onStart.accept(this);
         }
     }
-    
-    public void setHolded(boolean b)
-    {
+
+    public void setHolded(boolean b) {
         isHolded = b;
     }
-    
-    public boolean isHolded()
-    {
+
+    public boolean isHolded() {
         return isHolded;
     }
-    
-    public void setWaiting()
-    {
+
+    public void setWaiting() {
         isWaiting = true;
     }
-    
-    public boolean isWaiting()
-    {
+
+    public boolean isWaiting() {
         return isWaiting;
     }
-    
-    public void setVar(String name, Object value)
-    {
+
+    public void setVar(String name, Object value) {
         Variable v = vars.get(name);
-        if(v != null)
-        {
+        if(v != null) {
             v.set(this, value);
         }
     }
-    
-    public Variable getVar(String name)
-    {
+
+    public Variable getVar(String name) {
         return vars.get(name);
     }
-    
-    public boolean isEventLoaded(String event)
-    {
+
+    public boolean isEventLoaded(String event) {
         return loadedEvents.contains(event);
     }
-    
-    public boolean loadEvent(String event)
-    {
+
+    public boolean loadEvent(String event) {
         return loadedEvents.add(event);
     }
-    
-    public boolean unloadEvent(String event)
-    {
+
+    public boolean unloadEvent(String event) {
         return loadedEvents.remove(event);
     }
-    
-    public void setStackTrace(boolean b)
-    {
+
+    public void setStackTrace(boolean b) {
         stackTrace = b;
     }
-    
-    public synchronized void addCloseable(AutoCloseable closeable)
-    {
+
+    public synchronized void addCloseable(AutoCloseable closeable) {
         closeables.add(closeable);
     }
-    
-    public synchronized void removeCloseable(AutoCloseable closeable)
-    {
+
+    public synchronized void removeCloseable(AutoCloseable closeable) {
         closeables.remove(closeable);
     }
 
     @Override
-    public int hashCode()
-    {
+    public int hashCode() {
         return id;
     }
 
     @Override
-    public boolean equals(Object o)
-    {
+    public boolean equals(Object o) {
         return o != null && o instanceof Script && ((Script) o).id == id;
     }
-}
+}

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

@@ -7,6 +7,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.function.Consumer;
 import me.hammerle.snuviscript.exceptions.PreScriptException;
+import me.hammerle.snuviscript.exceptions.StackTrace;
 
 public class ScriptManager {
     private final ISnuviLogger logger;
@@ -125,7 +126,7 @@ public class ScriptManager {
             }
             return sc;
         } catch(PreScriptException ex) {
-            logger.print(null, ex, null, paths[0], null, ex.getLine());
+            logger.print(null, ex, null, paths[0], null, new StackTrace(ex.getLine()));
             return null;
         }
     }

+ 23 - 46
src/me/hammerle/snuviscript/code/SnuviUtils.java

@@ -3,86 +3,63 @@ package me.hammerle.snuviscript.code;
 import me.hammerle.snuviscript.inputprovider.InputProvider;
 import java.util.Random;
 
-public class SnuviUtils 
-{
+public class SnuviUtils {
     private static final Random RANDOM = new Random();
-    
-    public static int randomInt(int min, int max)
-    {
+
+    public static int randomInt(int min, int max) {
         return RANDOM.nextInt((max - min) + 1) + min;
     }
-    
-    public static String toString(double d)
-    {
-        if(d == (int) d)
-        {
+
+    public static String toString(double d) {
+        if(d == (int) d) {
             return String.valueOf((int) d);
         }
         return String.valueOf(d);
     }
-    
+
     // -------------------------------------------------------------------------
     // connectors
     // -------------------------------------------------------------------------
-    
-    public static String connect(Script sc, InputProvider[] c, int skip) throws Exception
-    {
+    public static String connect(Script sc, InputProvider[] c, int skip) throws Exception {
         StringBuilder sb = new StringBuilder();
-        for(int i = skip; i < c.length; i++)
-        {
+        for(int i = skip; i < c.length; i++) {
             sb.append(c[i].getString(sc));
         }
         return sb.toString();
     }
-    
-    public static String connect(Script sc, InputProvider[] c, String s, int skip) throws Exception
-    {
+
+    public static String connect(Script sc, InputProvider[] c, String s, int skip) throws Exception {
         StringBuilder sb = new StringBuilder();
-        if(skip < c.length)
-        {
+        if(skip < c.length) {
             sb.append(c[skip].getString(sc));
         }
-        for(int i = skip + 1; i < c.length; i++)
-        {
+        for(int i = skip + 1; i < c.length; i++) {
             sb.append(s);
             sb.append(c[i].getString(sc));
         }
         return sb.toString();
     }
-    
-    public static Object convert(String input)
-    {
-        if(input == null)
-        {
+
+    public static Object convert(String input) {
+        if(input == null) {
             return null;
         }
         input = input.trim();
-        if(input.equals("true"))
-        {
+        if(input.equals("true")) {
             return true;
-        }
-        else if(input.equals("false"))
-        {
+        } else if(input.equals("false")) {
             return false;
-        }
-        else if(input.equals("null"))
-        {
+        } else if(input.equals("null")) {
             return null;
-        }
-        else if(input.startsWith("\"") && input.endsWith("\""))
-        {
-            if(input.length() == 1)
-            {
+        } else if(input.startsWith("\"") && input.endsWith("\"")) {
+            if(input.length() == 1) {
                 return "\"";
             }
             return input.substring(1, input.length() - 1);
         }
-        try
-        {
+        try {
             return Double.parseDouble(input);
-        }
-        catch(NumberFormatException ex)
-        {
+        } catch(NumberFormatException ex) {
             return input;
         }
     }

+ 66 - 125
src/me/hammerle/snuviscript/config/SnuviConfig.java

@@ -12,15 +12,13 @@ import me.hammerle.snuviscript.code.ISnuviLogger;
 import me.hammerle.snuviscript.code.Script;
 import me.hammerle.snuviscript.code.SnuviUtils;
 
-public class SnuviConfig
-{            
+public class SnuviConfig {
     protected final ISnuviLogger logger;
     protected final TreeMap<String, Object> conf;
     private final File file;
     private Script sc;
-    
-    private SnuviConfig(Script sc, ISnuviLogger logger, String path, String name)
-    {    
+
+    private SnuviConfig(Script sc, ISnuviLogger logger, String path, String name) {
         this.sc = sc;
         this.logger = logger;
         StringBuilder sb = new StringBuilder("./");
@@ -31,191 +29,134 @@ public class SnuviConfig
         file = new File(sb.toString());
         conf = new TreeMap<>();
     }
-    
-    public SnuviConfig(ISnuviLogger logger, String path, String name)
-    {    
+
+    public SnuviConfig(ISnuviLogger logger, String path, String name) {
         this(null, logger, path, name);
     }
-    
-    public SnuviConfig(Script sc, String path, String name)
-    {    
+
+    public SnuviConfig(Script sc, String path, String name) {
         this(sc, sc.getScriptManager().getLogger(), path, name);
     }
-    
-    private void print(String message, Exception ex)
-    {
-        logger.print(message, ex, null, sc == null ? null : sc.getName(), sc, sc == null ? -1 : sc.getActiveSourceLine());
+
+    private void print(String message, Exception ex) {
+        logger.print(message, ex, null, sc == null ? null : sc.getName(), sc, sc == null ? null : sc.getStackTrace());
     }
-    
-    private void print(String message)
-    {
+
+    private void print(String message) {
         print(message, null);
     }
-    
-    public final void load()
-    {
-        if(!exists())
-        {
+
+    public final void load() {
+        if(!exists()) {
             print("cannot load non existent file '" + file.getPath() + "'");
             return;
         }
-        try
-        {
+        try {
             String warning = "wrong syntax in '" + file.getPath() + "'";
-            Files.readAllLines(file.toPath()).stream().forEach(s -> 
-            {
+            Files.readAllLines(file.toPath()).stream().forEach(s -> {
                 int b = s.indexOf("=");
-                if(b == -1)
-                {
+                if(b == -1) {
                     print(warning);
                     print(s);
-                }
-                else
-                {                
+                } else {
                     conf.put(s.substring(0, b).trim(), SnuviUtils.convert(s.substring(b + 1)));
                 }
             });
-        } 
-        catch(MalformedInputException ex) 
-        {
+        } catch(MalformedInputException ex) {
             print("'" + file.getPath() + "' contains an illegal character, change file encoding", ex);
-        }
-        catch(OutOfMemoryError ex) 
-        {
+        } catch(OutOfMemoryError ex) {
             print("'" + file.getPath() + "' is too big");
-        }
-        catch(SecurityException ex) 
-        {
+        } catch(SecurityException ex) {
             print("'" + file.getPath() + "' is not accessable", ex);
-        }
-        catch(IOException ex) 
-        {
+        } catch(IOException ex) {
             print("'" + file.getPath() + "' cannot be read", ex);
         }
-    }   
-    
-    public final boolean exists()
-    {
+    }
+
+    public final boolean exists() {
         return file.exists();
     }
-    
-    public final boolean delete()
-    {
+
+    public final boolean delete() {
         return file.delete();
     }
-    
-    public final boolean save()
-    {
-        try
-        {
-            if(file.getParentFile() != null)
-            {
+
+    public final boolean save() {
+        try {
+            if(file.getParentFile() != null) {
                 file.getParentFile().mkdirs();
             }
-            if(!file.exists())
-            {
-                try
-                {
+            if(!file.exists()) {
+                try {
                     file.createNewFile();
-                }
-                catch(IOException ex)
-                {
+                } catch(IOException ex) {
                     print("'" + file.getPath() + "' cannot be created", ex);
                     return false;
                 }
             }
             Files.write(Paths.get(file.toURI()), conf.entrySet().stream()
-                            .map(e -> 
-                            {
-                                if(e.getValue().getClass() == String.class)
-                                {
-                                    return e.getKey() + "=\"" + e.getValue() + "\"";
-                                }
-                                return e.getKey() + "=" + String.valueOf(e.getValue());
-                            })
-                            .collect(Collectors.toList()), StandardCharsets.UTF_8);
+                    .map(e -> {
+                        if(e.getValue().getClass() == String.class) {
+                            return e.getKey() + "=\"" + e.getValue() + "\"";
+                        }
+                        return e.getKey() + "=" + String.valueOf(e.getValue());
+                    })
+                    .collect(Collectors.toList()), StandardCharsets.UTF_8);
             return true;
-        }
-        catch(UnsupportedOperationException ex)
-        {
+        } catch(UnsupportedOperationException ex) {
             print("an unsupported operation was used", ex);
             return false;
-        }
-        catch(SecurityException ex)
-        {
+        } catch(SecurityException ex) {
             print("'" + file.getPath() + "' is not accessable", ex);
             return false;
-        }
-        catch(IOException ex)
-        {
+        } catch(IOException ex) {
             print("cannot write to '" + file.getPath() + "'", ex);
             return false;
         }
     }
-    
-    // -----------------------------------------------------------------------------------
-    // getter
-    // -----------------------------------------------------------------------------------
-    
-    public final <T> T get(String key, Class<T> c, T error)
-    {
-        try
-        {
+
+    public final <T> T get(String key, Class<T> c, T error) {
+        try {
             Object o = conf.get(key);
-            if(o == null)
-            {
+            if(o == null) {
                 return error;
             }
             return c.cast(o);
-        }
-        catch(ClassCastException ex)
-        {
+        } catch(ClassCastException ex) {
             print("invalid get", ex);
             return error;
         }
     }
-    
-    public final String getString(String key, String error)
-    {
+
+    public final String getString(String key, String error) {
         return get(key, String.class, error);
     }
-    
-    public final String getString(String key)
-    {
+
+    public final String getString(String key) {
         return getString(key, null);
     }
-    
-    public final float getFloat(String key, float error)
-    {
+
+    public final float getFloat(String key, float error) {
         return get(key, Double.class, (double) error).floatValue();
     }
-    
-    public final double getDouble(String key, double error)
-    {
+
+    public final double getDouble(String key, double error) {
         return get(key, Double.class, error);
     }
-    
-    public final long getLong(String key, long error)
-    {
+
+    public final long getLong(String key, long error) {
         return get(key, Double.class, (double) error).longValue();
     }
-    
-    public final int getInt(String key, int error)
-    {
+
+    public final int getInt(String key, int error) {
         return get(key, Double.class, (double) error).intValue();
     }
-    
-    public final boolean getBoolean(String key, boolean error)
-    {
+
+    public final boolean getBoolean(String key, boolean error) {
         return get(key, Boolean.class, error);
     }
-    
-    // -----------------------------------------------------------------------------------
-    // set
-    // -----------------------------------------------------------------------------------
-    
-    public final void set(String key, Object o)
-    {
+
+    public final void set(String key, Object o) {
         conf.put(key, o);
     }
 }

+ 5 - 8
src/me/hammerle/snuviscript/exceptions/PreScriptException.java

@@ -1,17 +1,14 @@
 package me.hammerle.snuviscript.exceptions;
 
-public class PreScriptException extends RuntimeException
-{
+public class PreScriptException extends RuntimeException {
     private final int line;
-    
-    public PreScriptException(String message, int line) 
-    {
+
+    public PreScriptException(String message, int line) {
         super(message);
         this.line = line;
     }
-    
-    public int getLine()
-    {
+
+    public int getLine() {
         return line;
     }
 }

+ 27 - 0
src/me/hammerle/snuviscript/exceptions/StackTrace.java

@@ -0,0 +1,27 @@
+package me.hammerle.snuviscript.exceptions;
+
+import java.util.Stack;
+
+public class StackTrace {
+    private final String stackTrace;
+
+    public StackTrace(int currentLine, Stack<Integer> stack) {
+        if(stack == null) {
+            stackTrace = String.valueOf(currentLine);
+            return;
+        }
+        StringBuilder sb = new StringBuilder();
+        stack.forEach(line -> sb.append(line).append(" > "));
+        sb.append(currentLine);
+        stackTrace = sb.toString();
+    }
+
+    public StackTrace(int currentLine) {
+        this(currentLine, null);
+    }
+
+    @Override
+    public String toString() {
+        return stackTrace;
+    }
+}

+ 13 - 21
src/me/hammerle/snuviscript/inputprovider/ArrayReturnWrapper.java

@@ -2,50 +2,42 @@ package me.hammerle.snuviscript.inputprovider;
 
 import me.hammerle.snuviscript.code.Script;
 
-public class ArrayReturnWrapper extends InputProvider
-{
+public class ArrayReturnWrapper extends InputProvider {
     private Object array;
     private int index;
-    
-    public void setValue(Object o, int index)
-    {
+
+    public void setValue(Object o, int index) {
         this.array = o;
         this.index = index;
     }
 
     @Override
-    public Object get(Script sc)
-    {
+    public Object get(Script sc) {
         return java.lang.reflect.Array.get(array, index);
     }
-    
+
     @Override
-    public void set(Script sc, Object o)
-    {
+    public void set(Script sc, Object o) {
         java.lang.reflect.Array.set(array, index, o);
     }
-    
+
     @Override
-    public double getDouble(Script sc)
-    {
+    public double getDouble(Script sc) {
         return (double) get(sc);
     }
-    
+
     @Override
-    public String getString(Script sc)
-    {
+    public String getString(Script sc) {
         return String.valueOf(get(sc));
     }
-    
+
     @Override
-    public boolean getBoolean(Script sc)
-    {
+    public boolean getBoolean(Script sc) {
         return (Boolean) get(sc);
     }
 
     @Override
-    public String toString()
-    {
+    public String toString() {
         return String.format("ArrayReturnWrapper(%s, %d)", array, index);
     }
 }

+ 11 - 17
src/me/hammerle/snuviscript/inputprovider/ConstantBoolean.java

@@ -2,39 +2,33 @@ package me.hammerle.snuviscript.inputprovider;
 
 import me.hammerle.snuviscript.code.Script;
 
-public class ConstantBoolean extends InputProvider
-{
+public class ConstantBoolean extends InputProvider {
     public static final ConstantBoolean TRUE = new ConstantBoolean(true);
     public static final ConstantBoolean FALSE = new ConstantBoolean(false);
-    
+
     private final boolean b;
-    
-    private ConstantBoolean(boolean b)
-    {
+
+    private ConstantBoolean(boolean b) {
         this.b = b;
     }
-    
+
     @Override
-    public Object get(Script sc)
-    {
+    public Object get(Script sc) {
         return b;
     }
-    
+
     @Override
-    public String getString(Script sc)
-    {
+    public String getString(Script sc) {
         return String.valueOf(b);
     }
-    
+
     @Override
-    public boolean getBoolean(Script sc)
-    {
+    public boolean getBoolean(Script sc) {
         return b;
     }
 
     @Override
-    public String toString()
-    {
+    public String toString() {
         return String.valueOf(b);
     }
 }

+ 10 - 16
src/me/hammerle/snuviscript/inputprovider/ConstantDouble.java

@@ -3,36 +3,30 @@ package me.hammerle.snuviscript.inputprovider;
 import me.hammerle.snuviscript.code.Script;
 import me.hammerle.snuviscript.code.SnuviUtils;
 
-public class ConstantDouble extends InputProvider
-{
+public class ConstantDouble extends InputProvider {
     private final double d;
-    
-    public ConstantDouble(double f)
-    {
+
+    public ConstantDouble(double f) {
         this.d = f;
     }
-    
+
     @Override
-    public Object get(Script sc)
-    {
+    public Object get(Script sc) {
         return d;
     }
-    
+
     @Override
-    public double getDouble(Script sc)
-    {
+    public double getDouble(Script sc) {
         return d;
     }
-    
+
     @Override
-    public String getString(Script sc)
-    {
+    public String getString(Script sc) {
         return SnuviUtils.toString(d);
     }
 
     @Override
-    public String toString() 
-    {
+    public String toString() {
         return SnuviUtils.toString(d);
     }
 }

+ 10 - 15
src/me/hammerle/snuviscript/inputprovider/ConstantNull.java

@@ -2,29 +2,24 @@ package me.hammerle.snuviscript.inputprovider;
 
 import me.hammerle.snuviscript.code.Script;
 
-public class ConstantNull extends InputProvider
-{
+public class ConstantNull extends InputProvider {
     public static final ConstantNull NULL = new ConstantNull();
-    
-    private ConstantNull()
-    {
+
+    private ConstantNull() {
     }
-    
+
     @Override
-    public Object get(Script sc)
-    {
+    public Object get(Script sc) {
         return null;
     }
-    
+
     @Override
-    public String getString(Script sc)
-    {
+    public String getString(Script sc) {
         return "null";
-    }   
-    
+    }
+
     @Override
-    public String toString()
-    {
+    public String toString() {
         return "null";
     }
 }

+ 8 - 13
src/me/hammerle/snuviscript/inputprovider/ConstantString.java

@@ -2,30 +2,25 @@ package me.hammerle.snuviscript.inputprovider;
 
 import me.hammerle.snuviscript.code.Script;
 
-public class ConstantString extends InputProvider
-{
+public class ConstantString extends InputProvider {
     private final String s;
-    
-    public ConstantString(String s)
-    {
+
+    public ConstantString(String s) {
         this.s = s;
     }
-    
+
     @Override
-    public Object get(Script sc) 
-    {
+    public Object get(Script sc) {
         return s;
     }
-    
+
     @Override
-    public String getString(Script sc) 
-    {
+    public String getString(Script sc) {
         return s;
     }
 
     @Override
-    public String toString() 
-    {
+    public String toString() {
         return "\"" + s + "\"";
     }
 }

+ 20 - 31
src/me/hammerle/snuviscript/inputprovider/InputProvider.java

@@ -2,55 +2,44 @@ package me.hammerle.snuviscript.inputprovider;
 
 import me.hammerle.snuviscript.code.Script;
 
-public abstract class InputProvider 
-{
-    public Object get(Script sc)
-    {
+public abstract class InputProvider {
+    public Object get(Script sc) {
         throw new ClassCastException();
     }
-    
-    public byte getByte(Script sc)
-    {
+
+    public byte getByte(Script sc) {
         return (byte) getDouble(sc);
     }
-    
-    public short getShort(Script sc)
-    {
+
+    public short getShort(Script sc) {
         return (short) getDouble(sc);
     }
-    
-    public int getInt(Script sc)
-    {
+
+    public int getInt(Script sc) {
         return (int) getDouble(sc);
     }
-    
-    public long getLong(Script sc)
-    {
+
+    public long getLong(Script sc) {
         return (long) getDouble(sc);
     }
-    
-    public float getFloat(Script sc)
-    {
+
+    public float getFloat(Script sc) {
         return (float) getDouble(sc);
     }
-    
-    public double getDouble(Script sc)
-    {
+
+    public double getDouble(Script sc) {
         throw new ClassCastException();
     }
-    
-    public String getString(Script sc)
-    {
+
+    public String getString(Script sc) {
         throw new ClassCastException();
     }
-    
-    public boolean getBoolean(Script sc)
-    {
+
+    public boolean getBoolean(Script sc) {
         throw new ClassCastException();
     }
-    
-    public void set(Script sc, Object o)
-    {
+
+    public void set(Script sc, Object o) {
         throw new ClassCastException();
     }
 }

+ 16 - 25
src/me/hammerle/snuviscript/inputprovider/LocalVariable.java

@@ -2,51 +2,42 @@ package me.hammerle.snuviscript.inputprovider;
 
 import me.hammerle.snuviscript.code.Script;
 
-public class LocalVariable extends Variable
-{
-    public LocalVariable(String name)
-    {
+public class LocalVariable extends Variable {
+    public LocalVariable(String name) {
         super(name);
     }
-    
+
     @Override
-    public String toString() 
-    {
+    public String toString() {
         return name + "#L";
     }
-    
+
     @Override
-    public Object get(Script sc) 
-    {
+    public Object get(Script sc) {
         return getVariable(sc).get(sc);
     }
-    
+
     @Override
-    public double getDouble(Script sc)
-    {
+    public double getDouble(Script sc) {
         return getVariable(sc).getDouble(sc);
     }
-    
+
     @Override
-    public String getString(Script sc)
-    {
+    public String getString(Script sc) {
         return getVariable(sc).getString(sc);
     }
-    
+
     @Override
-    public boolean getBoolean(Script sc)
-    {
+    public boolean getBoolean(Script sc) {
         return getVariable(sc).getBoolean(sc);
     }
-    
-    private Variable getVariable(Script sc)
-    {
+
+    private Variable getVariable(Script sc) {
         return sc.getOrAddLocalVariable(name);
     }
-    
+
     @Override
-    public void set(Script sc, Object o) 
-    {
+    public void set(Script sc, Object o) {
         getVariable(sc).set(sc, o);
     }
 }

+ 11 - 18
src/me/hammerle/snuviscript/inputprovider/ReturnWrapper.java

@@ -2,42 +2,35 @@ package me.hammerle.snuviscript.inputprovider;
 
 import me.hammerle.snuviscript.code.Script;
 
-public class ReturnWrapper extends InputProvider
-{
+public class ReturnWrapper extends InputProvider {
     private Object o;
-    
-    public void setValue(Object o)
-    {
+
+    public void setValue(Object o) {
         this.o = o;
     }
 
     @Override
-    public Object get(Script sc)
-    {
+    public Object get(Script sc) {
         return o;
     }
-    
+
     @Override
-    public double getDouble(Script sc)
-    {
+    public double getDouble(Script sc) {
         return (double) o;
     }
-    
+
     @Override
-    public String getString(Script sc)
-    {
+    public String getString(Script sc) {
         return String.valueOf(o);
     }
-    
+
     @Override
-    public boolean getBoolean(Script sc)
-    {
+    public boolean getBoolean(Script sc) {
         return (Boolean) o;
     }
 
     @Override
-    public String toString()
-    {
+    public String toString() {
         return String.format("ReturnWrapper(%s)", o);
     }
 }

+ 16 - 25
src/me/hammerle/snuviscript/inputprovider/Variable.java

@@ -2,55 +2,46 @@ package me.hammerle.snuviscript.inputprovider;
 
 import me.hammerle.snuviscript.code.Script;
 
-public class Variable extends InputProvider
-{
+public class Variable extends InputProvider {
     protected final String name;
     private Object o;
-    
-    public Variable(String name)
-    {
+
+    public Variable(String name) {
         this.name = name;
         this.o = null;
     }
 
-    public String getName() 
-    {
+    public String getName() {
         return name;
     }
-    
+
     @Override
-    public String toString() 
-    {
+    public String toString() {
         return name;
     }
-    
+
     @Override
-    public Object get(Script sc)
-    {
+    public Object get(Script sc) {
         return o;
     }
-    
+
     @Override
-    public double getDouble(Script sc)
-    {
+    public double getDouble(Script sc) {
         return (double) o;
     }
-    
+
     @Override
-    public String getString(Script sc)
-    {
+    public String getString(Script sc) {
         return String.valueOf(o);
     }
-    
+
     @Override
-    public boolean getBoolean(Script sc)
-    {
+    public boolean getBoolean(Script sc) {
         return (boolean) o;
     }
-    
+
     @Override
-    public void set(Script sc, Object o)
-    {
+    public void set(Script sc, Object o) {
         this.o = o;
     }
 }

+ 10 - 18
src/me/hammerle/snuviscript/instructions/Array.java

@@ -5,25 +5,21 @@ import me.hammerle.snuviscript.inputprovider.InputProvider;
 import me.hammerle.snuviscript.code.Script;
 import me.hammerle.snuviscript.inputprovider.Variable;
 
-public class Array extends Instruction
-{
+public class Array extends Instruction {
     private final int arguments;
     private final ArrayReturnWrapper wrapper = new ArrayReturnWrapper();
     private final Variable v;
-    
-    public Array(int line, int arguments, Variable v)
-    {
+
+    public Array(int line, int arguments, Variable v) {
         super(line);
         this.arguments = arguments;
         this.v = v;
     }
-    
+
     @Override
-    public InputProvider execute(Script sc, InputProvider[] in) throws Exception
-    {
+    public InputProvider execute(Script sc, InputProvider[] in) throws Exception {
         Object o = v.get(sc);
-        for(int i = 0; i < in.length - 1; i++)
-        {
+        for(int i = 0; i < in.length - 1; i++) {
             o = java.lang.reflect.Array.get(o, in[i].getInt(sc));
         }
         wrapper.setValue(o, in[in.length - 1].getInt(sc));
@@ -31,22 +27,18 @@ public class Array extends Instruction
     }
 
     @Override
-    public int getArguments()
-    {
+    public int getArguments() {
         return arguments;
     }
 
     @Override
-    public String toString()
-    {
+    public String toString() {
         StringBuilder sb = new StringBuilder();
         sb.append("push ");
         sb.append(v);
-        if(arguments > 0)
-        {
+        if(arguments > 0) {
             sb.append("[");
-            for(int i = 1; i < arguments; i++)
-            {
+            for(int i = 1; i < arguments; i++) {
                 sb.append(",");
             }
             sb.append("]");

+ 3 - 6
src/me/hammerle/snuviscript/instructions/Break.java

@@ -1,15 +1,12 @@
 package me.hammerle.snuviscript.instructions;
 
-public class Break extends Goto
-{
-    public Break(int line)
-    {
+public class Break extends Goto {
+    public Break(int line) {
         super(line, 0);
     }
 
     @Override
-    public String getName()
-    {
+    public String getName() {
         return "break";
     }
 }

+ 5 - 9
src/me/hammerle/snuviscript/instructions/Catch.java

@@ -3,24 +3,20 @@ package me.hammerle.snuviscript.instructions;
 import me.hammerle.snuviscript.inputprovider.InputProvider;
 import me.hammerle.snuviscript.code.Script;
 
-public class Catch extends Goto
-{
-    public Catch(int line)
-    {
+public class Catch extends Goto {
+    public Catch(int line) {
         super(line, 0);
     }
 
     @Override
-    public InputProvider execute(Script sc, InputProvider[] o) throws Exception
-    {
+    public InputProvider execute(Script sc, InputProvider[] o) throws Exception {
         sc.jumpTo(getJump());
         sc.setErrorLine(-1);
         return null;
     }
-    
+
     @Override
-    public String getName()
-    {
+    public String getName() {
         return "catch";
     }
 }

+ 5 - 9
src/me/hammerle/snuviscript/instructions/Constant.java

@@ -3,25 +3,21 @@ package me.hammerle.snuviscript.instructions;
 import me.hammerle.snuviscript.inputprovider.InputProvider;
 import me.hammerle.snuviscript.code.Script;
 
-public class Constant extends Instruction
-{
+public class Constant extends Instruction {
     private final InputProvider constant;
-    
-    public Constant(int line, InputProvider constant)
-    {
+
+    public Constant(int line, InputProvider constant) {
         super(line);
         this.constant = constant;
     }
 
     @Override
-    public InputProvider execute(Script sc, InputProvider[] o) throws Exception
-    {
+    public InputProvider execute(Script sc, InputProvider[] o) throws Exception {
         return constant;
     }
 
     @Override
-    public String toString()
-    {
+    public String toString() {
         return String.format("push %s", constant.toString());
     }
 }

+ 4 - 7
src/me/hammerle/snuviscript/instructions/Continue.java

@@ -1,15 +1,12 @@
 package me.hammerle.snuviscript.instructions;
 
-public class Continue extends Goto
-{
-    public Continue(int line)
-    {
+public class Continue extends Goto {
+    public Continue(int line) {
         super(line, 0);
     }
-    
+
     @Override
-    public String getName()
-    {
+    public String getName() {
         return "continue";
     }
 }

+ 7 - 12
src/me/hammerle/snuviscript/instructions/Else.java

@@ -3,26 +3,21 @@ package me.hammerle.snuviscript.instructions;
 import me.hammerle.snuviscript.inputprovider.InputProvider;
 import me.hammerle.snuviscript.code.Script;
 
-public class Else extends Goto
-{
-    public Else(int line)
-    {
+public class Else extends Goto {
+    public Else(int line) {
         super(line, 0);
     }
-    
+
     @Override
-    public InputProvider execute(Script sc, InputProvider[] o) throws Exception
-    {
-        if(sc.getIfState())
-        {
+    public InputProvider execute(Script sc, InputProvider[] o) throws Exception {
+        if(sc.getIfState()) {
             sc.jumpTo(getJump());
         }
         return null;
     }
-    
+
     @Override
-    public String getName()
-    {
+    public String getName() {
         return "else";
     }
 }

+ 9 - 17
src/me/hammerle/snuviscript/instructions/ElseIf.java

@@ -3,35 +3,27 @@ package me.hammerle.snuviscript.instructions;
 import me.hammerle.snuviscript.inputprovider.InputProvider;
 import me.hammerle.snuviscript.code.Script;
 
-public class ElseIf extends Goto
-{
-    public ElseIf(int line)
-    {
+public class ElseIf extends Goto {
+    public ElseIf(int line) {
         super(line, 1);
     }
-    
+
     @Override
-    public InputProvider execute(Script sc, InputProvider[] o) throws Exception
-    {
-        if(!sc.getIfState())
-        {
+    public InputProvider execute(Script sc, InputProvider[] o) throws Exception {
+        if(!sc.getIfState()) {
             boolean b = o[0].getBoolean(sc);
             sc.setIfState(b);
-            if(!b)
-            {
+            if(!b) {
                 sc.jumpTo(getJump());
             }
-        }
-        else
-        {
+        } else {
             sc.jumpTo(getJump());
         }
         return null;
     }
-    
+
     @Override
-    public String getName()
-    {
+    public String getName() {
         return "elseif";
     }
 }

+ 6 - 11
src/me/hammerle/snuviscript/instructions/EndIf.java

@@ -3,29 +3,24 @@ package me.hammerle.snuviscript.instructions;
 import me.hammerle.snuviscript.inputprovider.InputProvider;
 import me.hammerle.snuviscript.code.Script;
 
-public class EndIf extends Instruction
-{
-    public EndIf(int line)
-    {
+public class EndIf extends Instruction {
+    public EndIf(int line) {
         super(line);
     }
 
     @Override
-    public InputProvider execute(Script sc, InputProvider[] o) throws Exception
-    {
+    public InputProvider execute(Script sc, InputProvider[] o) throws Exception {
         sc.setIfState(true);
         return null;
     }
 
     @Override
-    public String getName()
-    {
+    public String getName() {
         return "endif";
-    }   
+    }
 
     @Override
-    public String toString()
-    {
+    public String toString() {
         return getName();
     }
 }

+ 5 - 10
src/me/hammerle/snuviscript/instructions/For.java

@@ -3,26 +3,21 @@ package me.hammerle.snuviscript.instructions;
 import me.hammerle.snuviscript.inputprovider.InputProvider;
 import me.hammerle.snuviscript.code.Script;
 
-public class For extends Goto
-{
-    public For(int line)
-    {
+public class For extends Goto {
+    public For(int line) {
         super(line, 1);
     }
 
     @Override
-    public InputProvider execute(Script sc, InputProvider[] o) throws Exception
-    {
-        if(!o[0].getBoolean(sc))
-        {
+    public InputProvider execute(Script sc, InputProvider[] o) throws Exception {
+        if(!o[0].getBoolean(sc)) {
             sc.jumpTo(getJump());
         }
         return null;
     }
 
     @Override
-    public String getName()
-    {
+    public String getName() {
         return "for";
     }
 }

+ 7 - 13
src/me/hammerle/snuviscript/instructions/Function.java

@@ -5,25 +5,21 @@ import me.hammerle.snuviscript.code.NamedFunction;
 import me.hammerle.snuviscript.inputprovider.InputProvider;
 import me.hammerle.snuviscript.code.Script;
 
-public class Function extends Instruction
-{
+public class Function extends Instruction {
     private final NamedFunction function;
     private final int arguments;
     private final ReturnWrapper wrapper = new ReturnWrapper();
-    
-    public Function(int line, int arguments, NamedFunction function)
-    {
+
+    public Function(int line, int arguments, NamedFunction function) {
         super(line);
         this.function = function;
         this.arguments = arguments;
     }
 
     @Override
-    public InputProvider execute(Script sc, InputProvider[] in) throws Exception
-    {
+    public InputProvider execute(Script sc, InputProvider[] in) throws Exception {
         Object o = function.execute(sc, in);
-        if(o == Void.TYPE || shouldNotReturnValue())
-        {
+        if(o == Void.TYPE || shouldNotReturnValue()) {
             return null;
         }
         wrapper.setValue(o);
@@ -31,14 +27,12 @@ public class Function extends Instruction
     }
 
     @Override
-    public int getArguments()
-    {
+    public int getArguments() {
         return arguments;
     }
 
     @Override
-    public String toString()
-    {
+    public String toString() {
         return String.format("use %s(%d)", function.getName(), arguments);
     }
 }

+ 11 - 19
src/me/hammerle/snuviscript/instructions/Goto.java

@@ -3,49 +3,41 @@ package me.hammerle.snuviscript.instructions;
 import me.hammerle.snuviscript.inputprovider.InputProvider;
 import me.hammerle.snuviscript.code.Script;
 
-public class Goto extends Instruction
-{
+public class Goto extends Instruction {
     private int jump;
     private final int arguments;
-    
-    public Goto(int line, int arguments)
-    {
+
+    public Goto(int line, int arguments) {
         super(line);
         this.arguments = arguments;
     }
 
     @Override
-    public InputProvider execute(Script sc, InputProvider[] o) throws Exception
-    {
+    public InputProvider execute(Script sc, InputProvider[] o) throws Exception {
         sc.jumpTo(jump);
         return null;
     }
 
     @Override
-    public int getArguments()
-    {
+    public int getArguments() {
         return arguments;
     }
-    
-    public void setJump(int value)
-    {
+
+    public void setJump(int value) {
         jump = value;
     }
 
-    public int getJump()
-    {
+    public int getJump() {
         return jump;
     }
-    
+
     @Override
-    public String getName()
-    {
+    public String getName() {
         return "goto";
     }
 
     @Override
-    public String toString()
-    {
+    public String toString() {
         StringBuilder sb = new StringBuilder();
         sb.append(getName());
         sb.append("(");

+ 6 - 11
src/me/hammerle/snuviscript/instructions/If.java

@@ -3,28 +3,23 @@ package me.hammerle.snuviscript.instructions;
 import me.hammerle.snuviscript.inputprovider.InputProvider;
 import me.hammerle.snuviscript.code.Script;
 
-public class If extends Goto
-{
-    public If(int line)
-    {
+public class If extends Goto {
+    public If(int line) {
         super(line, 1);
     }
-    
+
     @Override
-    public InputProvider execute(Script sc, InputProvider[] o) throws Exception
-    {
+    public InputProvider execute(Script sc, InputProvider[] o) throws Exception {
         boolean b = o[0].getBoolean(sc);
         sc.setIfState(b);
-        if(!b)
-        {
+        if(!b) {
             sc.jumpTo(getJump());
         }
         return null;
     }
 
     @Override
-    public String getName()
-    {
+    public String getName() {
         return "if";
     }
 }

+ 8 - 14
src/me/hammerle/snuviscript/instructions/IfGoto.java

@@ -3,36 +3,30 @@ package me.hammerle.snuviscript.instructions;
 import me.hammerle.snuviscript.inputprovider.InputProvider;
 import me.hammerle.snuviscript.code.Script;
 
-public class IfGoto extends Goto
-{
+public class IfGoto extends Goto {
     private final boolean check;
-    
-    public IfGoto(int line, boolean check)
-    {
+
+    public IfGoto(int line, boolean check) {
         super(line, 0);
         this.check = check;
     }
 
     @Override
-    public InputProvider execute(Script sc, InputProvider[] o) throws Exception
-    {
+    public InputProvider execute(Script sc, InputProvider[] o) throws Exception {
         boolean b = sc.peekDataStack().getBoolean(sc);
-        if(b == check)
-        {
+        if(b == check) {
             sc.jumpTo(getJump());
         }
         return null;
     }
 
     @Override
-    public String getName()
-    {
+    public String getName() {
         return "if goto";
     }
-    
+
     @Override
-    public String toString()
-    {
+    public String toString() {
         StringBuilder sb = new StringBuilder();
         sb.append(getName());
         sb.append("(");

+ 14 - 22
src/me/hammerle/snuviscript/instructions/Instruction.java

@@ -3,43 +3,35 @@ package me.hammerle.snuviscript.instructions;
 import me.hammerle.snuviscript.inputprovider.InputProvider;
 import me.hammerle.snuviscript.code.Script;
 
-public abstract class Instruction
-{
+public abstract class Instruction {
     private final int line;
     private boolean noReturn = false;
-    
-    public Instruction(int line)
-    {
+
+    public Instruction(int line) {
         this.line = line;
     }
-    
-    public void setNoReturn()
-    {
+
+    public void setNoReturn() {
         noReturn = true;
     }
-    
-    public boolean shouldNotReturnValue()
-    {
+
+    public boolean shouldNotReturnValue() {
         return noReturn;
     }
 
-    public int getLine()
-    {
+    public int getLine() {
         return line;
     }
-    
-    public InputProvider execute(Script sc, InputProvider[] o) throws Exception
-    {
+
+    public InputProvider execute(Script sc, InputProvider[] o) throws Exception {
         return null;
     }
-    
-    public int getArguments()
-    {
+
+    public int getArguments() {
         return 0;
     }
-    
-    public String getName()
-    {
+
+    public String getName() {
         return "";
     }
 }

+ 9 - 18
src/me/hammerle/snuviscript/instructions/Return.java

@@ -4,47 +4,38 @@ import me.hammerle.snuviscript.inputprovider.InputProvider;
 import me.hammerle.snuviscript.code.Script;
 import me.hammerle.snuviscript.inputprovider.ReturnWrapper;
 
-public class Return extends Instruction
-{
+public class Return extends Instruction {
     private final int arguments;
-    
-    public Return(int line, int arguments)
-    {
+
+    public Return(int line, int arguments) {
         super(line);
         this.arguments = arguments;
     }
 
     @Override
-    public InputProvider execute(Script sc, InputProvider[] o) throws Exception
-    {
-        if(o.length > 0)
-        {
+    public InputProvider execute(Script sc, InputProvider[] o) throws Exception {
+        if(o.length > 0) {
             ReturnWrapper wrapper = new ReturnWrapper();
             wrapper.setValue(o[0].get(sc));
             sc.handleReturn(wrapper);
-        }
-        else
-        {
+        } else {
             sc.handleReturn(null);
         }
         return null;
     }
 
     @Override
-    public int getArguments()
-    {
+    public int getArguments() {
         return arguments;
     }
 
     @Override
-    public String getName()
-    {
+    public String getName() {
         return "return";
     }
 
     @Override
-    public String toString()
-    {
+    public String toString() {
         return String.format("return(%d)", arguments);
     }
 }

+ 5 - 9
src/me/hammerle/snuviscript/instructions/SignInverter.java

@@ -4,24 +4,20 @@ import me.hammerle.snuviscript.inputprovider.ReturnWrapper;
 import me.hammerle.snuviscript.inputprovider.InputProvider;
 import me.hammerle.snuviscript.code.Script;
 
-public class SignInverter extends Instruction
-{
+public class SignInverter extends Instruction {
     private final ReturnWrapper wrapper = new ReturnWrapper();
-    
-    public SignInverter(int line)
-    {
+
+    public SignInverter(int line) {
         super(line);
     }
 
     @Override
-    public int getArguments()
-    {
+    public int getArguments() {
         return 1;
     }
 
     @Override
-    public InputProvider execute(Script sc, InputProvider[] o) throws Exception
-    {
+    public InputProvider execute(Script sc, InputProvider[] o) throws Exception {
         wrapper.setValue(-o[0].getDouble(sc));
         return wrapper;
     }

+ 4 - 8
src/me/hammerle/snuviscript/instructions/Try.java

@@ -3,23 +3,19 @@ package me.hammerle.snuviscript.instructions;
 import me.hammerle.snuviscript.inputprovider.InputProvider;
 import me.hammerle.snuviscript.code.Script;
 
-public class Try extends Goto
-{
-    public Try(int line)
-    {
+public class Try extends Goto {
+    public Try(int line) {
         super(line, 0);
     }
 
     @Override
-    public InputProvider execute(Script sc, InputProvider[] o) throws Exception
-    {
+    public InputProvider execute(Script sc, InputProvider[] o) throws Exception {
         sc.setErrorLine(getJump());
         return null;
     }
 
     @Override
-    public String getName()
-    {
+    public String getName() {
         return "try";
     }
 }

+ 7 - 12
src/me/hammerle/snuviscript/instructions/UserFunction.java

@@ -3,33 +3,28 @@ package me.hammerle.snuviscript.instructions;
 import me.hammerle.snuviscript.inputprovider.InputProvider;
 import me.hammerle.snuviscript.code.Script;
 
-public class UserFunction extends Goto
-{
+public class UserFunction extends Goto {
     private final String[] vars;
     private final String name;
-    
-    public UserFunction(int line, String name, String[] vars)
-    {
+
+    public UserFunction(int line, String name, String[] vars) {
         super(line, 0);
         this.vars = vars;
         this.name = name;
     }
 
     @Override
-    public InputProvider execute(Script sc, InputProvider[] o) throws Exception
-    {
+    public InputProvider execute(Script sc, InputProvider[] o) throws Exception {
         sc.jumpTo(getJump());
         return null;
     }
-    
-    public String[] getArgumentNames()
-    {
+
+    public String[] getArgumentNames() {
         return vars;
     }
 
     @Override
-    public String getName()
-    {
+    public String getName() {
         return name;
     }
 }

+ 6 - 11
src/me/hammerle/snuviscript/instructions/While.java

@@ -3,26 +3,21 @@ package me.hammerle.snuviscript.instructions;
 import me.hammerle.snuviscript.inputprovider.InputProvider;
 import me.hammerle.snuviscript.code.Script;
 
-public class While extends Goto
-{
-    public While(int line)
-    {
+public class While extends Goto {
+    public While(int line) {
         super(line, 1);
     }
-    
+
     @Override
-    public InputProvider execute(Script sc, InputProvider[] o) throws Exception
-    {
-        if(!o[0].getBoolean(sc))
-        {
+    public InputProvider execute(Script sc, InputProvider[] o) throws Exception {
+        if(!o[0].getBoolean(sc)) {
             sc.jumpTo(getJump());
         }
         return null;
     }
 
     @Override
-    public String getName()
-    {
+    public String getName() {
         return "while";
     }
 }

+ 44 - 75
src/me/hammerle/snuviscript/test/Test.java

@@ -12,106 +12,85 @@ import me.hammerle.snuviscript.tokenizer.Token;
 import me.hammerle.snuviscript.code.Compiler;
 import me.hammerle.snuviscript.instructions.Instruction;
 
-public class Test
-{
+public class Test {
     private static final TestScheduler SCHEDULER = new TestScheduler();
     private static final TestLogger LOGGER = new TestLogger();
     private static final ScriptManager PARSER = new ScriptManager(LOGGER, SCHEDULER);
     private static int done = 0;
-    private static int tests = 0;  
-    
-    public static void test()
-    {
+    private static int tests = 0;
+
+    public static void test() {
         testTokenizer();
         testCompiler();
         testOutput();
-        
+
         LOGGER.reset();
         PARSER.startScript(true, "test", "./test/test.test");
         LOGGER.printAll();
     }
-    
-    private static void testOutput()
-    {
+
+    private static void testOutput() {
         done = 0;
-        tests = 0;  
-        forEachFile(new File("./test"), ".out", (inFile, checkFile) -> 
-        {
+        tests = 0;
+        forEachFile(new File("./test"), ".out", (inFile, checkFile) -> {
             tests++;
-                
+
             LOGGER.reset();
-            
+
             Script sc = new Script(PARSER, null, null, inFile.getName(), inFile.getPath());
             sc.run();
 
-            if(LOGGER.check(checkFile))
-            {
+            if(LOGGER.check(checkFile)) {
                 done++;
             }
         });
         System.out.println(String.format("%d / %d output tests succeeded", done, tests));
     }
-    
-    private static void testTokenizer()
-    {
+
+    private static void testTokenizer() {
         done = 0;
-        tests = 0; 
-        forEachFile(new File("./test"), ".tout", (inFile, checkFile) -> 
-        {
-            try
-            {
-                try(FileInputStream in = new FileInputStream(inFile))
-                {
-                    tests++; 
+        tests = 0;
+        forEachFile(new File("./test"), ".tout", (inFile, checkFile) -> {
+            try {
+                try(FileInputStream in = new FileInputStream(inFile)) {
+                    tests++;
                     Tokenizer tokenizer = new Tokenizer();
                     LOGGER.reset();
-                    for(Token t : tokenizer.tokenize(in))
-                    {
-                        LOGGER.print(t.toString(), null, null, null, null, -1);
+                    for(Token t : tokenizer.tokenize(in)) {
+                        LOGGER.print(t.toString(), null, null, null, null, null);
                     }
-                    if(LOGGER.check(checkFile))
-                    {
+                    if(LOGGER.check(checkFile)) {
                         done++;
                     }
                 }
-            }
-            catch(Exception ex)
-            {
+            } catch(Exception ex) {
                 ex.printStackTrace();
             }
         });
         System.out.println(String.format("%d / %d tokenizer tests succeeded", done, tests));
     }
-    
-    private static void testCompiler()
-    {
+
+    private static void testCompiler() {
         done = 0;
-        tests = 0; 
+        tests = 0;
         final Compiler c = new Compiler();
-        forEachFile(new File("./test"), ".cout", (inFile, checkFile) -> 
-        {
+        forEachFile(new File("./test"), ".cout", (inFile, checkFile) -> {
             tests++;
-            try
-            {
-                try(FileInputStream in = new FileInputStream(inFile))
-                {
+            try {
+                try(FileInputStream in = new FileInputStream(inFile)) {
                     Tokenizer tokenizer = new Tokenizer();
                     LOGGER.reset();
-                    Instruction[] instr = c.compile(tokenizer.tokenize(in), 
-                            new HashMap<>(), new HashMap<>(), new HashMap<>(), 
+                    Instruction[] instr = c.compile(tokenizer.tokenize(in),
+                            new HashMap<>(), new HashMap<>(), new HashMap<>(),
                             new HashMap<>());
-                    for(Instruction i : instr)
-                    {
-                        LOGGER.print(i.toString(), null, null, null, null, -1);
+                    for(Instruction i : instr) {
+                        LOGGER.print(i.toString(), null, null, null, null, null);
                     }
-                    if(LOGGER.check(checkFile))
-                    {
+                    if(LOGGER.check(checkFile)) {
                         done++;
                     }
                 }
-            }
-            catch(Exception ex)
-            {
+            } catch(Exception ex) {
                 System.out.println("_________________________________________");
                 System.out.println(inFile + " failed:");
                 System.out.println(ex.getMessage());
@@ -120,31 +99,21 @@ public class Test
         });
         System.out.println(String.format("%d / %d compiler tests succeeded", done, tests));
     }
-    
-    private static void forEachFile(File f, String ending, BiConsumer<File, File> bc)
-    {
-        if(f.isFile())
-        {
-            if(!f.getName().contains("."))
-            {
+
+    private static void forEachFile(File f, String ending, BiConsumer<File, File> bc) {
+        if(f.isFile()) {
+            if(!f.getName().contains(".")) {
                 File checkFile = new File(f.getPath() + ending);
-                if(!checkFile.exists())
-                {
-                    try
-                    {
+                if(!checkFile.exists()) {
+                    try {
                         checkFile.createNewFile();
-                    }
-                    catch(IOException ex)
-                    {
+                    } catch(IOException ex) {
                     }
                 }
                 bc.accept(f, checkFile);
             }
-        }
-        else if(f.isDirectory())
-        {
-            for(File fi : f.listFiles())
-            {
+        } else if(f.isDirectory()) {
+            for(File fi : f.listFiles()) {
                 forEachFile(fi, ending, bc);
             }
         }

+ 21 - 36
src/me/hammerle/snuviscript/test/TestLogger.java

@@ -7,71 +7,56 @@ import java.util.Arrays;
 import java.util.List;
 import me.hammerle.snuviscript.code.ISnuviLogger;
 import me.hammerle.snuviscript.code.Script;
+import me.hammerle.snuviscript.exceptions.StackTrace;
 
-public class TestLogger implements ISnuviLogger
-{
+public class TestLogger implements ISnuviLogger {
     private final ArrayList<String> list = new ArrayList<>();
-    
+
     @Override
-    public void print(String message, Exception ex, String function, String scriptname, Script sc, int line)
-    {
-        if(ex == null)
-        {
+    public void print(String message, Exception ex, String function, String scriptname, Script sc, StackTrace lines) {
+        if(ex == null) {
             list.addAll(Arrays.asList(message.split("\n")));
-        }
-        else
-        {
+        } else {
             System.out.println(ex);
             System.out.println(ex.getMessage());
-            System.out.println("error line " + line);
+            System.out.println("error line " + lines);
         }
     }
-    
-    public void reset()
-    {
+
+    public void reset() {
         list.clear();
     }
-    
-    public void printAll()
-    {
+
+    public void printAll() {
         list.stream().forEach(s -> System.out.println(s));
         list.clear();
     }
-    
-    public boolean check(File f)
-    {
-        if(!f.exists())
-        {
+
+    public boolean check(File f) {
+        if(!f.exists()) {
             System.out.println(String.format("\"%s\" does not exist", f.getPath()));
             return false;
         }
-        try
-        {
+        try {
             List<String> file = Files.readAllLines(f.toPath());
-            if(file.size() != list.size())
-            {
+            if(file.size() != list.size()) {
                 printNoMatch(f, file);
                 return false;
             }
-            for(int i = 0; i < file.size(); i++)
-            {
-                if(!file.get(i).equals(list.get(i)))
-                {
+            for(int i = 0; i < file.size(); i++) {
+                if(!file.get(i).equals(list.get(i))) {
                     printNoMatch(f, file);
                     return false;
                 }
             }
-        }
-        catch(Exception ex)
-        {
+        } catch(Exception ex) {
             ex.printStackTrace();
             return false;
         }
         return true;
     }
-    
-    private void printNoMatch(File f, List<String> file)
-    {
+
+    private void printNoMatch(File f, List<String> file) {
         System.out.println(String.format("error checking %s ", f.getPath()));
         System.out.println("Expected ----------------------------------------");
         file.forEach(s -> System.out.println(s));

+ 6 - 10
src/me/hammerle/snuviscript/test/TestScheduler.java

@@ -3,21 +3,17 @@ package me.hammerle.snuviscript.test;
 import java.util.LinkedList;
 import me.hammerle.snuviscript.code.ISnuviScheduler;
 
-public class TestScheduler implements ISnuviScheduler
-{
+public class TestScheduler implements ISnuviScheduler {
     private final LinkedList<Runnable> list = new LinkedList<>();
-    
+
     @Override
-    public int scheduleTask(Runnable r, long delay)
-    {
+    public int scheduleTask(Runnable r, long delay) {
         list.add(r);
         return 0;
     }
-    
-    public void execute()
-    {
-        while(!list.isEmpty())
-        {
+
+    public void execute() {
+        while(!list.isEmpty()) {
             list.removeFirst().run();
         }
     }

+ 4 - 7
src/me/hammerle/snuviscript/tokenizer/DataToken.java

@@ -1,18 +1,15 @@
 package me.hammerle.snuviscript.tokenizer;
 
-public class DataToken extends Token
-{
+public class DataToken extends Token {
     private final Object value;
-    
-    public DataToken(TokenType type, int line,  Object value)
-    {
+
+    public DataToken(TokenType type, int line, Object value) {
         super(type, line);
         this.value = value;
     }
 
     @Override
-    public Object getData()
-    {
+    public Object getData() {
         return value;
     }
 }

+ 15 - 28
src/me/hammerle/snuviscript/tokenizer/StreamCharReader.java

@@ -3,38 +3,30 @@ package me.hammerle.snuviscript.tokenizer;
 import java.io.IOException;
 import java.io.InputStream;
 
-public class StreamCharReader
-{
+public class StreamCharReader {
     private final InputStream in;
     private int buffer = -1;
-    
-    public StreamCharReader(InputStream in)
-    {
+
+    public StreamCharReader(InputStream in) {
         this.in = in;
     }
-    
-    public int peekChar()
-    {
-        if(buffer == -1)
-        {
+
+    public int peekChar() {
+        if(buffer == -1) {
             buffer = readChar();
             return buffer;
         }
         return buffer;
     }
-    
-    public int readChar()
-    {
-        if(buffer != -1)
-        {
+
+    public int readChar() {
+        if(buffer != -1) {
             int r = buffer;
             buffer = -1;
             return r;
         }
-        try
-        {
-            if(in.available() <= 0)
-            {
+        try {
+            if(in.available() <= 0) {
                 return -1;
             }
             int data = in.read();
@@ -47,22 +39,17 @@ public class StreamCharReader
                         int a = in.read();
                         int b = in.read();
                         data = ((data & 0xF) << 12) | ((a & 0x3F) << 6) | (b & 0x3F);
-                    }
-                    else // 2 byte unicode
+                    } else // 2 byte unicode
                     {
                         data = ((data & 0x1F) << 6) | (in.read() & 0x3F);
                     }
-                }
-                else
-                {
+                } else {
                     // should not happen as unicode starts with 11
                 }
             }
             return data;
-        }
-        catch(IOException ex)
-        {
+        } catch(IOException ex) {
             return -1;
         }
     }
-}
+}

+ 14 - 24
src/me/hammerle/snuviscript/tokenizer/Token.java

@@ -1,56 +1,46 @@
 package me.hammerle.snuviscript.tokenizer;
 
-public class Token
-{
+public class Token {
     private final TokenType type;
     private final int line;
-    
-    public Token(TokenType type, int line)
-    {
+
+    public Token(TokenType type, int line) {
         this.type = type;
         this.line = line;
     }
 
-    public TokenType getType()
-    {
+    public TokenType getType() {
         return type;
     }
-    
-    public Object getData()
-    {
+
+    public Object getData() {
         return null;
     }
-    
-    public int getLine()
-    {
+
+    public int getLine() {
         return line;
     }
 
     @Override
-    public String toString()
-    {
+    public String toString() {
         StringBuilder sb = new StringBuilder();
-        
+
         sb.append("(");
         sb.append(line);
         sb.append(", ");
         sb.append(type);
-        if(getData() != null)
-        {
+        if(getData() != null) {
             sb.append(", ");
-            if(getData() instanceof String)
-            {
+            if(getData() instanceof String) {
                 sb.append('"');
                 sb.append(getData());
                 sb.append('"');
-            }
-            else
-            {
+            } else {
                 sb.append(getData());
             }
         }
         sb.append(")");
-        
+
         return sb.toString();
     }
 }

+ 20 - 32
src/me/hammerle/snuviscript/tokenizer/TokenType.java

@@ -1,45 +1,33 @@
 package me.hammerle.snuviscript.tokenizer;
 
-public enum TokenType
-{
-    NUMBER("number"), STRING("string"), LITERAL("literal"), LABEL("label"), 
+public enum TokenType {
+    NUMBER("number"), STRING("string"), LITERAL("literal"), LABEL("label"),
     TRUE("true"), FALSE("false"), NULL("null"),
-    
-    OPEN_BRACKET("("), CLOSE_BRACKET(")"), 
-    OPEN_SQUARE_BRACKET("["), CLOSE_SQUARE_BRACKET("]"), 
-    OPEN_CURVED_BRACKET("{"), CLOSE_CURVED_BRACKET("}"), 
-    
-    SEMICOLON(";"), COMMA(","), 
-    
-    INC("++"), DEC("--"), 
-    
-    INVERT("!"), BIT_INVERT("~"), 
-    
-    MUL("*"), DIV("/"), MOD("%"), ADD("+"), SUB("-"), 
-    ADD_SET("+="), SUB_SET("-="), MUL_SET("*="), DIV_SET("/="), MOD_SET("%="), 
-    
-    LEFT_SHIFT("<<"), RIGHT_SHIFT(">>"), 
+    OPEN_BRACKET("("), CLOSE_BRACKET(")"),
+    OPEN_SQUARE_BRACKET("["), CLOSE_SQUARE_BRACKET("]"),
+    OPEN_CURVED_BRACKET("{"), CLOSE_CURVED_BRACKET("}"),
+    SEMICOLON(";"), COMMA(","),
+    INC("++"), DEC("--"),
+    INVERT("!"), BIT_INVERT("~"),
+    MUL("*"), DIV("/"), MOD("%"), ADD("+"), SUB("-"),
+    ADD_SET("+="), SUB_SET("-="), MUL_SET("*="), DIV_SET("/="), MOD_SET("%="),
+    LEFT_SHIFT("<<"), RIGHT_SHIFT(">>"),
     LEFT_SHIFT_SET("<<="), RIGHT_SHIFT_SET(">>="), BIT_AND_SET("&="), BIT_XOR_SET("^="), BIT_OR_SET("|="),
-    
-    LESS("<"), LESS_EQUAL("<="), GREATER(">"), GREATER_EQUAL(">="), EQUAL("=="), NOT_EQUAL("!="), 
-    BIT_AND("&"), BIT_XOR("^"), BIT_OR("|"), 
+    LESS("<"), LESS_EQUAL("<="), GREATER(">"), GREATER_EQUAL(">="), EQUAL("=="), NOT_EQUAL("!="),
+    BIT_AND("&"), BIT_XOR("^"), BIT_OR("|"),
     AND("&&"), OR("||"), SET("="),
-    
-    IF("if"), ELSE("else"), ELSEIF("else if"), WHILE("while"), TRY("try"), 
-    CATCH("catch"), FOR("for"), FUNCTION("function"), BREAK("break"), 
+    IF("if"), ELSE("else"), ELSEIF("else if"), WHILE("while"), TRY("try"),
+    CATCH("catch"), FOR("for"), FUNCTION("function"), BREAK("break"),
     CONTINUE("continue"), RETURN("return"),
-    
     EOF("end of file");
-    
+
     private final String name;
-    
-    private TokenType(String name)
-    {
+
+    private TokenType(String name) {
         this.name = name;
     }
 
-    public String getName()
-    {
+    public String getName() {
         return name;
     }
-}
+}

+ 202 - 165
src/me/hammerle/snuviscript/tokenizer/Tokenizer.java

@@ -5,224 +5,270 @@ import java.util.ArrayList;
 import me.hammerle.snuviscript.exceptions.PreScriptException;
 import static me.hammerle.snuviscript.tokenizer.TokenType.*;
 
-public class Tokenizer
-{
+public class Tokenizer {
     private StreamCharReader stream = null;
     private final ArrayList<Token> tokens = new ArrayList<>();
     private int line = 1;
-    
-    private int next()
-    {
+
+    private int next() {
         return stream.readChar();
     }
-    
-    private int peek()
-    {
+
+    private int peek() {
         return stream.peekChar();
     }
-    
-    private boolean next(char c)
-    {
-        if(peek() == c)
-        {
+
+    private boolean next(char c) {
+        if(peek() == c) {
             next();
             return true;
         }
         return false;
     }
-    
-    private void add(TokenType type)
-    {
+
+    private void add(TokenType type) {
         tokens.add(new Token(type, line));
     }
-    
-    private void add(TokenType type, Object data)
-    {
+
+    private void add(TokenType type, Object data) {
         tokens.add(new DataToken(type, line, data));
     }
-    
-    private void add(char c, TokenType t1, TokenType t2, TokenType t3, TokenType t4)
-    {
+
+    private void add(char c, TokenType t1, TokenType t2, TokenType t3, TokenType t4) {
         int peek = peek();
-        if(peek == c)
-        {
+        if(peek == c) {
             next();
-            if(peek() == '=')
-            {
+            if(peek() == '=') {
                 next();
                 add(t1);
-            }
-            else
-            {
+            } else {
                 add(t2);
             }
-        }
-        else if(peek == '=')
-        {
+        } else if(peek == '=') {
             next();
             add(t3);
-        }
-        else
-        {
+        } else {
             add(t4);
         }
     }
-    
-    public Token[] tokenize(InputStream... streams)
-    {
+
+    public Token[] tokenize(InputStream... streams) {
         tokens.clear();
-        for(InputStream in : streams)
-        {
+        for(InputStream in : streams) {
             line = 1;
             stream = new StreamCharReader(in);
-            
+
             int c;
-            while((c = Tokenizer.this.next()) != -1)
-            {
+            while((c = Tokenizer.this.next()) != -1) {
                 handleChar(c);
             }
         }
         add(EOF);
         return tokens.toArray(new Token[tokens.size()]);
     }
-    
-    private void handleChar(int c)
-    {
-        if(Character.isLetter(c) || c == '_' || c == '.')
-        {
+
+    private void handleChar(int c) {
+        if(Character.isLetter(c) || c == '_' || c == '.') {
             handleLiteral(c, TokenType.LITERAL);
-        }
-        else if(Character.isDigit(c))
-        {
+        } else if(Character.isDigit(c)) {
             handleNumber(c);
-        }
-        else
-        {
+        } else {
             handleSpecial(c);
         }
     }
-    
-    private void handleLiteral(int c, TokenType type)
-    {
+
+    private void handleLiteral(int c, TokenType type) {
         StringBuilder sb = new StringBuilder();
         sb.append((char) c);
-        
-        while(true)
-        {
+
+        while(true) {
             int data = peek();
-            if(!Character.isLetterOrDigit(data) && data != '_' && data != '.')
-            {
+            if(!Character.isLetterOrDigit(data) && data != '_' && data != '.') {
                 break;
             }
             sb.append((char) data);
             next();
         }
-        
+
         String s = sb.toString();
-        switch(s)
-        {
-            case "if": add(IF); break;
-            case "else": add(ELSE); break;
-            case "elseif": add(ELSEIF); break;
-            case "while": add(WHILE); break;
-            case "try": add(TRY); break;
-            case "catch": add(CATCH); break;
-            case "for": add(FOR); break;
-            case "function": add(FUNCTION); break;
-            case "break": add(BREAK); break;
-            case "continue": add(CONTINUE); break;
-            case "return": add(RETURN); break;
-            case "true": add(TRUE); break;
-            case "false": add(FALSE); break;
-            case "null": add(NULL); break;
-            default: add(type, s);
+        switch(s) {
+            case "if":
+                add(IF);
+                break;
+            case "else":
+                add(ELSE);
+                break;
+            case "elseif":
+                add(ELSEIF);
+                break;
+            case "while":
+                add(WHILE);
+                break;
+            case "try":
+                add(TRY);
+                break;
+            case "catch":
+                add(CATCH);
+                break;
+            case "for":
+                add(FOR);
+                break;
+            case "function":
+                add(FUNCTION);
+                break;
+            case "break":
+                add(BREAK);
+                break;
+            case "continue":
+                add(CONTINUE);
+                break;
+            case "return":
+                add(RETURN);
+                break;
+            case "true":
+                add(TRUE);
+                break;
+            case "false":
+                add(FALSE);
+                break;
+            case "null":
+                add(NULL);
+                break;
+            default:
+                add(type, s);
         }
-        
+
     }
-    
-    private void handleNumber(int c)
-    {
+
+    private void handleNumber(int c) {
         StringBuilder sb = new StringBuilder();
         sb.append((char) c);
-        
-        while(true)
-        {
+
+        while(true) {
             int data = peek();
-            if(!Character.isLetterOrDigit(data) && data != '.')
-            {
+            if(!Character.isLetterOrDigit(data) && data != '.') {
                 break;
             }
             next();
             sb.append((char) data);
         }
-        
+
         add(NUMBER, Double.parseDouble(sb.toString()));
     }
-    
-    private void handleSpecial(int c)
-    {
-        switch(c)
-        {
+
+    private void handleSpecial(int c) {
+        switch(c) {
             case ' ':
             case '\t':
-            case '\r': break;
-            case '\n': line++; break;
-            case '"': handleString(); break;
-            case '(': add(OPEN_BRACKET); break;
-            case ')': add(CLOSE_BRACKET); break;
-            case '[': add(OPEN_SQUARE_BRACKET); break;
-            case ']': add(CLOSE_SQUARE_BRACKET); break;
-            case '{': add(OPEN_CURVED_BRACKET); break;
-            case '}': add(CLOSE_CURVED_BRACKET); break;
-            case '$': handleLiteral(c, LITERAL); break;
-            case '@': handleLiteral(c, LABEL); break;
-            case ';': add(SEMICOLON); break;
-            case ',': add(COMMA); break;
-            case '~': add(BIT_INVERT); break;
-            case '+': add(next('=') ? ADD_SET : (next('+') ? INC : ADD)); break;
-            case '-': add(next('=') ? SUB_SET : (next('-') ? DEC : SUB)); break;
-            case '!': add(next('=') ? NOT_EQUAL : INVERT); break;
-            case '=': add(next('=') ? EQUAL : SET); break;
-            case '*': add(next('=') ? MUL_SET : MUL); break;
-            case '/': handleSlash(); break;
-            case '%': add(next('=') ? MOD_SET : MOD); break;
-            case '&': add(next('=') ? BIT_AND_SET : (next('&') ? AND : BIT_AND)); break; 
-            case '|': add(next('=') ? BIT_OR_SET : (next('|') ? OR : BIT_OR)); break;
-            case '^': add(next('=') ? BIT_XOR_SET : BIT_XOR); break;
-            case '<': add('<', LEFT_SHIFT_SET, LEFT_SHIFT, LESS_EQUAL, LESS); break;
-            case '>': add('>', RIGHT_SHIFT_SET, RIGHT_SHIFT, GREATER_EQUAL, GREATER); break;
-            default: throw new PreScriptException("unknown token " + c, line);
+            case '\r':
+                break;
+            case '\n':
+                line++;
+                break;
+            case '"':
+                handleString();
+                break;
+            case '(':
+                add(OPEN_BRACKET);
+                break;
+            case ')':
+                add(CLOSE_BRACKET);
+                break;
+            case '[':
+                add(OPEN_SQUARE_BRACKET);
+                break;
+            case ']':
+                add(CLOSE_SQUARE_BRACKET);
+                break;
+            case '{':
+                add(OPEN_CURVED_BRACKET);
+                break;
+            case '}':
+                add(CLOSE_CURVED_BRACKET);
+                break;
+            case '$':
+                handleLiteral(c, LITERAL);
+                break;
+            case '@':
+                handleLiteral(c, LABEL);
+                break;
+            case ';':
+                add(SEMICOLON);
+                break;
+            case ',':
+                add(COMMA);
+                break;
+            case '~':
+                add(BIT_INVERT);
+                break;
+            case '+':
+                add(next('=') ? ADD_SET : (next('+') ? INC : ADD));
+                break;
+            case '-':
+                add(next('=') ? SUB_SET : (next('-') ? DEC : SUB));
+                break;
+            case '!':
+                add(next('=') ? NOT_EQUAL : INVERT);
+                break;
+            case '=':
+                add(next('=') ? EQUAL : SET);
+                break;
+            case '*':
+                add(next('=') ? MUL_SET : MUL);
+                break;
+            case '/':
+                handleSlash();
+                break;
+            case '%':
+                add(next('=') ? MOD_SET : MOD);
+                break;
+            case '&':
+                add(next('=') ? BIT_AND_SET : (next('&') ? AND : BIT_AND));
+                break;
+            case '|':
+                add(next('=') ? BIT_OR_SET : (next('|') ? OR : BIT_OR));
+                break;
+            case '^':
+                add(next('=') ? BIT_XOR_SET : BIT_XOR);
+                break;
+            case '<':
+                add('<', LEFT_SHIFT_SET, LEFT_SHIFT, LESS_EQUAL, LESS);
+                break;
+            case '>':
+                add('>', RIGHT_SHIFT_SET, RIGHT_SHIFT, GREATER_EQUAL, GREATER);
+                break;
+            default:
+                throw new PreScriptException("unknown token " + c, line);
         }
     }
-    
-    private void handleString()
-    {
+
+    private void handleString() {
         StringBuilder sb = new StringBuilder();
         int oldLine = line;
-        while(true)
-        {
+        while(true) {
             int data = next();
-            if(data == -1)
-            {
+            if(data == -1) {
                 throw new PreScriptException("non closed string literal", oldLine);
             }
-            if(data == '"')
-            {
+            if(data == '"') {
                 add(STRING, sb.toString());
                 break;
             }
-            if(data == '\n')
-            {
+            if(data == '\n') {
                 line++;
             }
-            if(data == '\\')
-            {
+            if(data == '\\') {
                 int escape = next();
-                switch(escape)
-                {
-                    case 'n': data = '\n'; break;
-                    case '\\': data = '\\'; break;
-                    case '"': data = '"'; break;
+                switch(escape) {
+                    case 'n':
+                        data = '\n';
+                        break;
+                    case '\\':
+                        data = '\\';
+                        break;
+                    case '"':
+                        data = '"';
+                        break;
                     default:
                         throw new PreScriptException("invalid escaped character", line);
                 }
@@ -230,20 +276,18 @@ public class Tokenizer
             sb.append((char) data);
         }
     }
-    
-    private void handleSlash()
-    {
-        switch(peek())
-        {
-            case '/': 
+
+    private void handleSlash() {
+        switch(peek()) {
+            case '/':
                 next();
                 handleOneLineComment();
                 break;
-            case '*': 
+            case '*':
                 next();
                 handleMultiLineComment();
                 break;
-            case '=': 
+            case '=':
                 next();
                 add(DIV_SET);
                 break;
@@ -251,36 +295,29 @@ public class Tokenizer
                 add(DIV);
         }
     }
-    
-    private void handleOneLineComment()
-    {
-        while(true)
-        {
+
+    private void handleOneLineComment() {
+        while(true) {
             int data = next();
-            if(data == -1 || data == '\n')
-            {
+            if(data == -1 || data == '\n') {
                 line++;
                 break;
             }
         }
     }
-    
-    private void handleMultiLineComment()
-    {
+
+    private void handleMultiLineComment() {
         int first;
         int sec = -1;
-        while(true)
-        {
+        while(true) {
             first = sec;
             sec = next();
-            if(sec == -1 || (first == '*' && sec == '/'))
-            {
+            if(sec == -1 || (first == '*' && sec == '/')) {
                 break;
             }
-            if(sec == '\n')
-            {
+            if(sec == '\n') {
                 line++;
             }
         }
     }
-}
+}