Эх сурвалжийг харах

refactoring of scope in progress

Xanathar 11 жил өмнө
parent
commit
618c7f3586
47 өөрчлөгдсөн 273 нэмэгдсэн , 779 устгасан
  1. 4 4
      src/MoonSharp.Interpreter.Tests/ClosureTests.cs
  2. 1 1
      src/MoonSharp.Interpreter.Tests/LuaTestSuiteExtract.cs
  3. 32 32
      src/MoonSharp.Interpreter.Tests/SimpleTests.cs
  4. 8 8
      src/MoonSharp.Interpreter.Tests/TableTests.cs
  5. 1 1
      src/MoonSharp.Interpreter/Execution/DataTypes/CallbackFunction.cs
  6. 2 2
      src/MoonSharp.Interpreter/Execution/DataTypes/Closure.cs
  7. 73 0
      src/MoonSharp.Interpreter/Execution/DataTypes/LRef.cs
  8. 2 1
      src/MoonSharp.Interpreter/Execution/DataTypes/LRefType.cs
  9. 64 44
      src/MoonSharp.Interpreter/Execution/DataTypes/Table.cs
  10. 4 50
      src/MoonSharp.Interpreter/Execution/Scopes/BuildTimeScope.cs
  11. 8 12
      src/MoonSharp.Interpreter/Execution/Scopes/RuntimeScope.cs
  12. 6 19
      src/MoonSharp.Interpreter/Execution/Script.cs
  13. 3 3
      src/MoonSharp.Interpreter/Execution/VM/VmExecutor.cs
  14. 5 4
      src/MoonSharp.Interpreter/MoonSharp.Interpreter.csproj
  15. 7 10
      src/MoonSharp.Interpreter/MoonSharpInterpreter.cs
  16. 0 3
      src/MoonSharp.Interpreter/Tree/Expression.cs
  17. 1 14
      src/MoonSharp.Interpreter/Tree/Expressions/ExprListExpression.cs
  18. 0 11
      src/MoonSharp.Interpreter/Tree/Expressions/FunctionCallChainExpression.cs
  19. 9 9
      src/MoonSharp.Interpreter/Tree/Expressions/FunctionDefinitionExpression.cs
  20. 0 22
      src/MoonSharp.Interpreter/Tree/Expressions/IndexExpression.cs
  21. 0 5
      src/MoonSharp.Interpreter/Tree/Expressions/LiteralExpression.cs
  22. 0 63
      src/MoonSharp.Interpreter/Tree/Expressions/OperatorExpression.cs
  23. 0 22
      src/MoonSharp.Interpreter/Tree/Expressions/SymbolRefExpression.cs
  24. 0 10
      src/MoonSharp.Interpreter/Tree/Expressions/TableConstructor.cs
  25. 0 38
      src/MoonSharp.Interpreter/Tree/FunctionCall.cs
  26. 1 3
      src/MoonSharp.Interpreter/Tree/IVariable.cs
  27. 1 0
      src/MoonSharp.Interpreter/Tree/NodeBase.cs
  28. 3 3
      src/MoonSharp.Interpreter/Tree/NodeFactory.cs
  29. 0 60
      src/MoonSharp.Interpreter/Tree/Statement.cs
  30. 0 15
      src/MoonSharp.Interpreter/Tree/Statements/AssignmentStatement.cs
  31. 25 0
      src/MoonSharp.Interpreter/Tree/Statements/BreakStatement.cs
  32. 0 29
      src/MoonSharp.Interpreter/Tree/Statements/CompositeStatement.cs
  33. 0 38
      src/MoonSharp.Interpreter/Tree/Statements/ExecutionFlowStatement.cs
  34. 0 67
      src/MoonSharp.Interpreter/Tree/Statements/ForEachLoopStatement.cs
  35. 0 31
      src/MoonSharp.Interpreter/Tree/Statements/ForLoopStatement.cs
  36. 0 6
      src/MoonSharp.Interpreter/Tree/Statements/FunctionCallStatement.cs
  37. 1 35
      src/MoonSharp.Interpreter/Tree/Statements/FunctionDefinitionStatement.cs
  38. 0 13
      src/MoonSharp.Interpreter/Tree/Statements/IfStatement.cs
  39. 0 5
      src/MoonSharp.Interpreter/Tree/Statements/LabelStatement.cs
  40. 0 16
      src/MoonSharp.Interpreter/Tree/Statements/LocalAssignmentStatement.cs
  41. 0 4
      src/MoonSharp.Interpreter/Tree/Statements/NullStatement.cs
  42. 0 28
      src/MoonSharp.Interpreter/Tree/Statements/RepeatStatement.cs
  43. 0 5
      src/MoonSharp.Interpreter/Tree/Statements/ReturnStatement.cs
  44. 0 5
      src/MoonSharp.Interpreter/Tree/Statements/ScopeBlockStatement.cs
  45. 0 14
      src/MoonSharp.Interpreter/Tree/Statements/WhileStatement.cs
  46. 2 4
      src/MoonSharp/Program.cs
  47. 10 10
      src/PerformanceComparison/Program.cs

+ 4 - 4
src/MoonSharp.Interpreter.Tests/ClosureTests.cs

@@ -31,7 +31,7 @@ namespace MoonSharp.Interpreter.Tests
 						return a[1](), a[2](), a[3](), a[4](), a[5]()";
 
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Tuple, res.Type);
 			Assert.AreEqual(5, res.Tuple.Length);
@@ -71,7 +71,7 @@ namespace MoonSharp.Interpreter.Tests
 
 						return a[1](), a[2](), a[3](), a[4](), a[5]()";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Tuple, res.Type);
 			Assert.AreEqual(5, res.Tuple.Length);
@@ -112,7 +112,7 @@ namespace MoonSharp.Interpreter.Tests
 
 						return a[1](), a[2](), a[3](), a[4](), a[5]()";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Tuple, res.Type);
 			Assert.AreEqual(5, res.Tuple.Length);
@@ -156,7 +156,7 @@ namespace MoonSharp.Interpreter.Tests
 
 				return a1(), a2(), a3(), a4(), a5()";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Tuple, res.Type);
 			Assert.AreEqual(5, res.Tuple.Length);

+ 1 - 1
src/MoonSharp.Interpreter.Tests/LuaTestSuiteExtract.cs

@@ -37,7 +37,7 @@ namespace MoonSharp.Interpreter.Tests
 					return RValue.Nil;
 				}));
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, globalCtx).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(globalCtx);
 
 			Assert.IsFalse(failedTests.Any(), string.Format("Failed asserts {0}",
 				string.Join(", ", failedTests.Select(xi => xi.ToString()).ToArray())));

+ 32 - 32
src/MoonSharp.Interpreter.Tests/SimpleTests.cs

@@ -22,7 +22,7 @@ namespace MoonSharp.Interpreter.Tests
 				return new RValue(1234.0); 
 			}));
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, globalCtx).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(globalCtx);
 
 			Assert.AreEqual(DataType.Nil, res.Type);
 			Assert.AreEqual(2, args.Length);
@@ -43,7 +43,7 @@ namespace MoonSharp.Interpreter.Tests
 			var globalCtx = new Table();
 			globalCtx[new RValue("print")] = new RValue(new CallbackFunction(a => { args = a; return new RValue(1234.0); }));
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, globalCtx).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(globalCtx);
 
 			Assert.AreEqual(2, args.Length);
 			Assert.AreEqual(DataType.String, args[0].Type);
@@ -68,7 +68,7 @@ namespace MoonSharp.Interpreter.Tests
 
 				return x,y,z";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(3, res.Tuple.Length);
 			Assert.AreEqual(DataType.String, res.Tuple[0].Type);
@@ -84,7 +84,7 @@ namespace MoonSharp.Interpreter.Tests
 		{
 			string script = @"return 6*7";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Number, res.Type);
 			Assert.AreEqual(42, res.Number);
@@ -105,7 +105,7 @@ namespace MoonSharp.Interpreter.Tests
 				throw new Exception("FAIL!");
 			}));
 
-			MoonSharpInterpreter.LoadFromString(script, globalCtx).Execute();
+			MoonSharpInterpreter.LoadFromString(script).Execute(globalCtx);
 		}
 
 
@@ -125,7 +125,7 @@ namespace MoonSharp.Interpreter.Tests
 
 				return false or f(), true or f(), false and f(), true and f(), i";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(5, res.Tuple.Length);
 			Assert.AreEqual(DataType.String, res.Tuple[0].Type);
@@ -153,7 +153,7 @@ namespace MoonSharp.Interpreter.Tests
 			move(4, 1, 2, 3)
 			";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 		}
 
 		[Test]
@@ -171,7 +171,7 @@ namespace MoonSharp.Interpreter.Tests
     
 				return fact(5)";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Number, res.Type);
 			Assert.AreEqual(120.0, res.Number);
@@ -190,7 +190,7 @@ namespace MoonSharp.Interpreter.Tests
     
 				return i, x";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Tuple, res.Type);
 			Assert.AreEqual(2, res.Tuple.Length);
@@ -211,7 +211,7 @@ namespace MoonSharp.Interpreter.Tests
 		
 				return i, x";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Tuple, res.Type);
 			Assert.AreEqual(2, res.Tuple.Length);
@@ -233,7 +233,7 @@ namespace MoonSharp.Interpreter.Tests
     
 				return x";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Number, res.Type);
 			Assert.AreEqual(1, res.Number);
@@ -272,7 +272,7 @@ namespace MoonSharp.Interpreter.Tests
     
 				return x, y";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Tuple, res.Type);
 			Assert.AreEqual(2, res.Tuple.Length);
@@ -311,7 +311,7 @@ namespace MoonSharp.Interpreter.Tests
     
 				return x, y";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Tuple, res.Type);
 			Assert.AreEqual(2, res.Tuple.Length);
@@ -330,7 +330,7 @@ namespace MoonSharp.Interpreter.Tests
    
 				return #x, #y";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Tuple, res.Type);
 			Assert.AreEqual(2, res.Tuple.Length);
@@ -357,7 +357,7 @@ namespace MoonSharp.Interpreter.Tests
     
 				return i, x";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Tuple, res.Type);
 			Assert.AreEqual(2, res.Tuple.Length);
@@ -380,7 +380,7 @@ namespace MoonSharp.Interpreter.Tests
     
 				return fact(5)";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Number, res.Type);
 			Assert.AreEqual(120.0, res.Number);
@@ -391,7 +391,7 @@ namespace MoonSharp.Interpreter.Tests
 		{
 			string script = @"return 5+3*7-2*5+2^3^2";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Number, res.Type);
 			Assert.AreEqual(528, res.Number);
@@ -402,7 +402,7 @@ namespace MoonSharp.Interpreter.Tests
 		{
 			string script = @"return (5+3)*7-2*5+(2^3)^2";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Number, res.Type);
 			Assert.AreEqual(110, res.Number);
@@ -413,7 +413,7 @@ namespace MoonSharp.Interpreter.Tests
 		{
 			string script = @"x = 1; return x;";    
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Number, res.Type);
 			Assert.AreEqual(1, res.Number);
@@ -434,7 +434,7 @@ namespace MoonSharp.Interpreter.Tests
     
 				return w+x+y+z";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Number, res.Type);
 			Assert.AreEqual(6, res.Number);
@@ -455,7 +455,7 @@ namespace MoonSharp.Interpreter.Tests
     
 				return fact(5)";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Number, res.Type);
 			Assert.AreEqual(120.0, res.Number);
@@ -479,7 +479,7 @@ namespace MoonSharp.Interpreter.Tests
     
 				return fact(5)";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Number, res.Type);
 			Assert.AreEqual(120.0, res.Number);
@@ -498,7 +498,7 @@ namespace MoonSharp.Interpreter.Tests
 					return x;
 			";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Number, res.Type);
 			Assert.AreEqual(6.0, res.Number);
@@ -514,7 +514,7 @@ namespace MoonSharp.Interpreter.Tests
     
 				return fact(3)";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Number, res.Type);
 			Assert.AreEqual(3, res.Number);
@@ -536,7 +536,7 @@ namespace MoonSharp.Interpreter.Tests
     
 				return fact(5)";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Number, res.Type);
 			Assert.AreEqual(120.0, res.Number);
@@ -554,7 +554,7 @@ namespace MoonSharp.Interpreter.Tests
 				return fact();
 				";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Function, res.Type);
 		}
@@ -575,7 +575,7 @@ namespace MoonSharp.Interpreter.Tests
 				";
 
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.String, res.Type);
 			Assert.AreEqual("ciao", res.String);
@@ -598,7 +598,7 @@ namespace MoonSharp.Interpreter.Tests
 				";
 
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Table, res.Type);
 
@@ -619,7 +619,7 @@ namespace MoonSharp.Interpreter.Tests
 				";
 
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Tuple, res.Type);
 			Assert.AreEqual(DataType.Number, res.Tuple[0].Type);
@@ -641,7 +641,7 @@ namespace MoonSharp.Interpreter.Tests
 						Allowed();
 								";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 		}
 		[Test]
@@ -658,7 +658,7 @@ namespace MoonSharp.Interpreter.Tests
 						Allowed();
 								";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 		}
 
@@ -679,7 +679,7 @@ namespace MoonSharp.Interpreter.Tests
 						Allowed();
 								";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 		}
 

+ 8 - 8
src/MoonSharp.Interpreter.Tests/TableTests.cs

@@ -20,7 +20,7 @@ namespace MoonSharp.Interpreter.Tests
 
 						return a[1]";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Number, res.Type);
 			Assert.AreEqual(1, res.Number);
@@ -40,7 +40,7 @@ namespace MoonSharp.Interpreter.Tests
 
 						return a[1], a[2], a[3], a['ciao'], a.hello, a.aurevoir, a[false]";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Tuple, res.Type);
 			Assert.AreEqual(7, res.Tuple.Length);
@@ -79,7 +79,7 @@ namespace MoonSharp.Interpreter.Tests
 
 						return x";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Number, res.Type);
 			Assert.AreEqual(1994, res.Number);
@@ -104,7 +104,7 @@ namespace MoonSharp.Interpreter.Tests
 
 						return x";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Number, res.Type);
 			Assert.AreEqual(1994, res.Number);
@@ -129,7 +129,7 @@ namespace MoonSharp.Interpreter.Tests
 
 						return x";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Number, res.Type);
 			Assert.AreEqual(1994, res.Number);
@@ -155,7 +155,7 @@ namespace MoonSharp.Interpreter.Tests
 
 						return x";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Number, res.Type);
 			Assert.AreEqual(1994, res.Number);
@@ -183,7 +183,7 @@ namespace MoonSharp.Interpreter.Tests
 
 						return x";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Number, res.Type);
 			Assert.AreEqual(1994, res.Number);
@@ -200,7 +200,7 @@ namespace MoonSharp.Interpreter.Tests
 						  return (a:add(10):add(20):add(30).x == 60 and a.y == 20)
 						end";
 
-			RValue res = MoonSharpInterpreter.LoadFromString(script, null).Execute();
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
 
 			Assert.AreEqual(DataType.Boolean, res.Type);
 			Assert.AreEqual(true, res.TestAsBoolean());

+ 1 - 1
src/MoonSharp.Interpreter/Execution/DataTypes/CallbackFunction.cs

@@ -14,7 +14,7 @@ namespace MoonSharp.Interpreter.Execution
 			m_CallBack = callBack;
 		}
 
-		public RValue Invoke(RuntimeScope scope, RValue[] args)
+		public RValue Invoke(RValue[] args)
 		{
 			return m_CallBack(args);
 		}

+ 2 - 2
src/MoonSharp.Interpreter/Execution/DataTypes/Closure.cs

@@ -14,7 +14,7 @@ namespace MoonSharp.Interpreter.Execution
 		private static List<RValue> emptyClosure = new List<RValue>();
 
 
-		public Closure(int idx, LRef[] symbols, RuntimeScope scope)
+		internal Closure(int idx, LRef[] symbols, RuntimeScope scope)
 		{
 			ByteCodeLocation = idx;
 
@@ -24,7 +24,7 @@ namespace MoonSharp.Interpreter.Execution
 				closureValues = emptyClosure;
 		}
 
-		public void EnterClosureBeforeCall(RuntimeScope scope)
+		internal void EnterClosureBeforeCall(RuntimeScope scope)
 		{
 			scope.EnterClosure(closureValues);
 		}

+ 73 - 0
src/MoonSharp.Interpreter/Execution/DataTypes/LRef.cs

@@ -0,0 +1,73 @@
+using System;
+using System.Collections.Generic;
+using MoonSharp.Interpreter.Diagnostics;
+using System.Linq;
+using System.Text;
+
+namespace MoonSharp.Interpreter.Execution
+{
+	/// <summary>
+	/// This class stores a possible l-value (that is a potential target of an assignment)
+	/// </summary>
+	public class LRef
+	{
+		// Fields are internal - direct access by the executor was a 10% improvement at profiling here!
+		internal LRefType i_Type;
+		internal int i_Index;
+		internal string i_Name;
+		internal RValue i_TableRefObject;
+		internal RValue i_TableRefIndex;
+
+		public LRefType Type { get { return i_Type; } }
+		public int Index { get { return i_Index; } }
+		public string Name { get { return i_Name; } }
+		public RValue TableRefObject { get { return i_TableRefObject; } }
+		public RValue TableRefIndex { get { return i_TableRefIndex; } } 
+
+
+
+		public static LRef Global(string name)
+		{
+			return new LRef() { i_Index = -1, i_Type = LRefType.Global, i_Name = name };
+		}
+
+		public static LRef Local(string name, int index)
+		{
+			return new LRef() { i_Index = index, i_Type = LRefType.Local, i_Name = name };
+		}
+
+		public static LRef Upvalue(string name, int index)
+		{
+			return new LRef() { i_Index = index, i_Type = LRefType.Upvalue, i_Name = name };
+		}
+		public static LRef Argument(string name, int index)
+		{
+			return new LRef() { i_Index = index, i_Type = LRefType.Argument, i_Name = name };
+		}
+
+		public static LRef Invalid()
+		{
+			return new LRef() { i_Index = -1, i_Type = LRefType.Invalid, i_Name = "!INV!" };
+		}
+
+		public static LRef ObjIndex(RValue baseObject, RValue indexObject)
+		{
+			return new LRef() { i_TableRefObject = baseObject, i_TableRefIndex = indexObject, i_Type = LRefType.Index };
+		}
+
+		public bool IsValid()
+		{
+			return i_Type !=  LRefType.Invalid;
+		}
+
+
+		public override string ToString()
+		{
+			return string.Format("{0}[{1}] : {2}", i_Type, i_Index, i_Name);
+		}
+
+
+
+
+	}
+}

+ 2 - 1
src/MoonSharp.Interpreter/Execution/Scopes/LRefType.cs → src/MoonSharp.Interpreter/Execution/DataTypes/LRefType.cs

@@ -11,6 +11,7 @@ namespace MoonSharp.Interpreter.Execution
 		Global,
 		Local,
 		Upvalue,
-		Index
+		Index,
+		Argument
 	}
 }

+ 64 - 44
src/MoonSharp.Interpreter/Execution/DataTypes/Table.cs

@@ -7,42 +7,11 @@ namespace MoonSharp.Interpreter.Execution
 {
 	public class Table
 	{
-		Dictionary<RValue, RValue> m_Symbols;
+		Dictionary<RValue, RValue> m_Symbols = new Dictionary<RValue, RValue>();
+		Dictionary<string, RValue> m_StringSymbols = new Dictionary<string, RValue>();
 		int m_LastConsecutiveInteger = 0;
 		int m_MaxInteger = 0;
 
-		public Table()
-		{
-			m_Symbols = new Dictionary<RValue, RValue>();
-		}
-
-		public Table(Dictionary<RValue, RValue> symbols, IEnumerable<RValue> positionals)
-		{
-			m_Symbols = symbols;
-
-			RValue lastPositional = null;
-			double positionalIndex = 1;
-
-			foreach (RValue v in positionals)
-			{
-				m_Symbols[new RValue(positionalIndex)] = v.ToSimplestValue();
-				lastPositional = v;
-				positionalIndex += 1;
-			}
-
-			if ((lastPositional != null) && (lastPositional.Type == DataType.Tuple))
-			{
-				positionalIndex -= 1;
-
-				foreach (RValue v in lastPositional.UnpackedTuple())
-				{
-					m_Symbols[new RValue(positionalIndex)] = v.ToSimplestValue();
-					positionalIndex += 1;
-				}
-			}
-
-			RebuildArrayIndex();
-		}
 
 		private void RebuildArrayIndex()
 		{
@@ -98,33 +67,84 @@ namespace MoonSharp.Interpreter.Execution
 
 		private void Remove(RValue key)
 		{
-			m_Symbols.Remove(key);
+			if (key.Type == DataType.String)
+			{
+				m_StringSymbols.Remove(key.String);
+			}
+			else
+			{
+				m_Symbols.Remove(key);
 
-			if (key.Type == DataType.Number)
-				RebuildArrayIndex(); // TODO: Optimize
+				if (key.Type == DataType.Number)
+					RebuildArrayIndex(); // TODO: Optimize
+			}
 		}
 
-		public double Length
+		public void Set(RValue key, RValue value)
 		{
-			get { return m_LastConsecutiveInteger; }
+			if (key.Type == DataType.String)
+			{
+				m_StringSymbols[key.String] = value.CloneAsWritable();
+			}
+			else
+			{
+				m_Symbols[key.Clone()] = value.CloneAsWritable();
+
+				if (key.Type == DataType.Number)
+					RebuildArrayIndex(); // TODO: Optimize
+			}
 		}
 
-		public void Set(RValue key, RValue value)
+		public RValue this[string key]
 		{
-			m_Symbols[key.Clone()] = value.CloneAsWritable();
+			get 
+			{
+				RValue v;
+
+				if (m_StringSymbols.TryGetValue(key, out v))
+					return v;
 
-			if (key.Type == DataType.Number)
-				RebuildArrayIndex(); // TODO: Optimize
+				return RValue.Nil;
+			}
+			set
+			{
+				if (value.Type == DataType.Nil)
+				{
+					m_StringSymbols.Remove(key);
+				}
+				else
+				{
+					m_StringSymbols[key] = value;
+				}
+			}
 		}
 
+
+
+
+
+
 		public RValue GetSymbol(RValue key)
 		{
-			if (m_Symbols.ContainsKey(key))
-				return m_Symbols[key];
+			if (key.Type == DataType.String)
+			{
+				if (m_StringSymbols.ContainsKey(key.String))
+					return m_StringSymbols[key.String];
+			}
+			else
+			{
+				if (m_Symbols.ContainsKey(key))
+					return m_Symbols[key];
+			}
 
 			return RValue.Nil;
 		}
 
+		public double Length
+		{
+			get { return m_LastConsecutiveInteger; }
+		}
+
 
 	}
 }

+ 4 - 50
src/MoonSharp.Interpreter/Execution/Scopes/BuildTimeScope.cs

@@ -8,25 +8,12 @@ namespace MoonSharp.Interpreter.Execution
 {
 	public class BuildTimeScope
 	{
-		BuildTimeScopeFrame m_GlobalRuntimeScope = new BuildTimeScopeFrame(0, 0, true);
-
-		Dictionary<LRef, RValue> m_PredefinedGlobals = new Dictionary<LRef, RValue>();
-
 		List<BuildTimeScopeFrame> m_Locals = new List<BuildTimeScopeFrame>();
-
 		List<IClosureBuilder> m_ClosureBuilders = new List<IClosureBuilder>();
 
-
-		public BuildTimeScope(Table t)
+		public BuildTimeScope()
 		{
 			PushFunction();
-
-			foreach (var kvp in t.Pairs().Where(e => e.Key.Type == DataType.String))
-			{
-				int idx = m_GlobalRuntimeScope.Define(kvp.Key.String);
-				m_PredefinedGlobals.Add(LRef.Global(kvp.Key.String, idx), kvp.Value);
-			}
-
 		}
 
 		public void EnterClosure(IClosureBuilder closureBuilder)
@@ -71,7 +58,7 @@ namespace MoonSharp.Interpreter.Execution
 				if (local)
 					s = LRef.Local(frame.FindRev(i - frame.BaseIndex), i - frame.BaseIndex);
 				else
-					s = LRef.Global(frame.FindRev(i - frame.BaseIndex), i - frame.BaseIndex);
+					s = LRef.Global(frame.FindRev(i - frame.BaseIndex));
 
 				symbols.Add(s);
 			}
@@ -120,19 +107,12 @@ namespace MoonSharp.Interpreter.Execution
 				}
 			}
 
-			int idxglob = m_GlobalRuntimeScope.Find(name);
-			if (idxglob >= 0)
-				return LRef.Global(name, idxglob);
-
-			// Debug.WriteLine(string.Format("Attempted to find '{0}' failed", name));
-			return LRef.Invalid();
+			return LRef.Global(name);
 		}
 
 		public LRef DefineLocal(string name)
 		{
-			var s = LRef.Local(name, m_Locals[m_Locals.Count - 1].Define(name));
-			// Debug.WriteLine(string.Format("Define local  : {0}", s));
-			return s;
+			return LRef.Local(name, m_Locals[m_Locals.Count - 1].Define(name));
 		}
 
 		public LRef TryDefineLocal(string name)
@@ -147,31 +127,5 @@ namespace MoonSharp.Interpreter.Execution
 			return s;
 		}
 
-
-		public LRef DefineGlobal(string name)
-		{
-			int idxglob = m_GlobalRuntimeScope.Find(name);
-			if (idxglob >= 0)
-				return LRef.Global(name, idxglob);
-
-			var s = LRef.Global(name, m_GlobalRuntimeScope.Define(name));
-			// Debug.WriteLine(string.Format("Define global : {0}", s));
-			return s;
-		}
-
-		internal RuntimeScope SpawnRuntimeScope()
-		{
-			RuntimeScope scope = new RuntimeScope();
-
-			scope.ExpandGlobal(m_GlobalRuntimeScope.MaxIndex);
-
-			foreach (var kvp in m_PredefinedGlobals)
-				scope.Assign(kvp.Key, kvp.Value);
-
-			scope.PushFrame(GetRuntimeFrameFromBuildFrame(m_Locals[0], true));
-
-			return scope;
-		}
-
 	}
 }

+ 8 - 12
src/MoonSharp.Interpreter/Execution/Scopes/RuntimeScope.cs

@@ -8,13 +8,18 @@ namespace MoonSharp.Interpreter.Execution
 {
 	public class RuntimeScope
 	{
-		List<RValue> m_GlobalScope = new List<RValue>(131072); // start with a 512KB scope stack
+		Table m_GlobalTable;
 		List<RValue> m_ScopeStack = new List<RValue>(131072); // start with a 512KB scope stack
 		List<LRef> m_DebugStack = new List<LRef>(131072); // start with a 512KB scope stack
 		List<int> m_LocalBaseIndexes = new List<int>(16384);
 		List<List<RValue>> m_ClosureStack = new List<List<RValue>>();
 		List<RuntimeScopeFrame> m_ScopeFrames = new List<RuntimeScopeFrame>(2048);
 
+		public RuntimeScope(Table globalTable)
+		{
+			m_GlobalTable = globalTable;
+		}
+
 		public void EnterClosure(List<RValue> closureValues)
 		{
 			m_ClosureStack.Add(closureValues);
@@ -85,7 +90,7 @@ namespace MoonSharp.Interpreter.Execution
 			{
 				case LRefType.Global:
 					{
-						return m_GlobalScope[symref.i_Index] ?? RValue.Nil;
+						return m_GlobalTable[symref.i_Name];
 					}
 				case LRefType.Local:
 					{
@@ -122,7 +127,7 @@ namespace MoonSharp.Interpreter.Execution
 			{
 				case LRefType.Global:
 					{
-						m_GlobalScope[symref.i_Index] = value.CloneAsWritable();
+						m_GlobalTable[symref.i_Name] = value.CloneAsWritable();
 					}
 					break;
 				case LRefType.Local:
@@ -154,15 +159,6 @@ namespace MoonSharp.Interpreter.Execution
 			}
 		}
 
-		public void ExpandGlobal(int maxidx)
-		{
-			if (m_GlobalScope.Count > 0)
-				throw new ScriptRuntimeException(null, "INTERNAL ERROR");
-
-			for (int i = 0; i <= maxidx; i++)
-				m_GlobalScope.Add(RValue.Nil);
-		}
-
 
 
 

+ 6 - 19
src/MoonSharp.Interpreter/Execution/Script.cs

@@ -10,16 +10,14 @@ namespace MoonSharp.Interpreter.Execution
 {
 	public class Script
 	{
-		CompositeStatement m_Script;
+		ChunkStatement m_Script;
 		ScriptLoadingContext m_LoadingContext;
-		RuntimeScope runtimeScope;
 		Chunk m_GlobalChunk;
 
-		internal Script(CompositeStatement stat, ScriptLoadingContext lcontext)
+		internal Script(ChunkStatement stat, ScriptLoadingContext lcontext)
 		{
 			m_Script = stat;
 			m_LoadingContext = lcontext;
-			runtimeScope = m_LoadingContext.Scope.SpawnRuntimeScope();
 			Compile();
 		}
 
@@ -30,32 +28,21 @@ namespace MoonSharp.Interpreter.Execution
 			m_Script.Compile(m_GlobalChunk);
 			m_GlobalChunk.Nop("Script end");
 
+#if DEBUG
 			m_GlobalChunk.Dump(@"c:\temp\codedump.txt");
+#endif
 		}
 
-		public RValue Execute()
+		public RValue Execute(Table globalContext)
 		{
-
-			VmExecutor executor = new VmExecutor(m_GlobalChunk, runtimeScope);
+			VmExecutor executor = new VmExecutor(m_GlobalChunk, globalContext ?? new Table());
 
 			using (var _ = new CodeChrono("MoonSharpScript.Execute"))
 			{
 				return executor.Execute();
 			}
-
-			//using (var _ = new CodeChrono("MoonSharpScript.Execute"))
-			//{
-			//	return m_Script.ExecRoot(runtimeScope);
-			//}
 		}
 
-		public RValue OldExecute()
-		{
-			using (var _ = new CodeChrono("MoonSharpScript.Execute"))
-			{
-				return m_Script.ExecRoot(runtimeScope);
-			}
-		}
 
 	}
 }

+ 3 - 3
src/MoonSharp.Interpreter/Execution/VM/VmExecutor.cs

@@ -27,11 +27,11 @@ namespace MoonSharp.Interpreter.Execution.VM
 		RValue[] m_TempRegs = new RValue[8];
 
 
-		public VmExecutor(Chunk rootChunk, RuntimeScope scope)
+		public VmExecutor(Chunk rootChunk, Table globalTable)
 		{
 			m_RootChunk = m_CurChunk = rootChunk;
 			m_InstructionPtr = 0;
-			m_Scope = scope;
+			m_Scope = new RuntimeScope(globalTable);
 		}
 
 		private RValue[] StackTopToArray(int items, bool pop)
@@ -478,7 +478,7 @@ namespace MoonSharp.Interpreter.Execution.VM
 			{
 				RValue[] args = StackTopToArray(i.NumVal, true);
 				m_ValueStack.Pop();
-				var ret = fn.Callback.Invoke(m_Scope, args);
+				var ret = fn.Callback.Invoke(args);
 				m_ValueStack.Push(ret);
 			}
 			else if (fn.Type == DataType.Function)

+ 5 - 4
src/MoonSharp.Interpreter/MoonSharp.Interpreter.csproj

@@ -74,10 +74,10 @@
     <Compile Include="Execution\Scopes\BuildTimeScope.cs" />
     <Compile Include="Execution\Scopes\BuildTimeScopeFrame.cs" />
     <Compile Include="Execution\Scopes\IClosureBuilder.cs" />
-    <Compile Include="Execution\Scopes\LRefType.cs" />
+    <Compile Include="Execution\DataTypes\LRefType.cs" />
     <Compile Include="Execution\Scopes\RuntimeScope.cs" />
     <Compile Include="Execution\Scopes\RuntimeScopeFrame.cs" />
-    <Compile Include="Execution\Scopes\LRef.cs" />
+    <Compile Include="Execution\DataTypes\LRef.cs" />
     <Compile Include="Execution\ScriptLoadingContext.cs" />
     <Compile Include="Execution\DataTypes\DataType.cs" />
     <Compile Include="Execution\DataTypes\RValue.cs" />
@@ -98,7 +98,7 @@
     <Compile Include="Grammar\Lua.g4.parser.cs">
       <DependentUpon>Lua.g4</DependentUpon>
     </Compile>
-    <Compile Include="IVariable.cs" />
+    <Compile Include="Tree\IVariable.cs" />
     <Compile Include="MoonSharpInterpreter.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Tree\Expressions\ExprListExpression.cs" />
@@ -114,8 +114,9 @@
     <Compile Include="Tree\NodeBase.cs" />
     <Compile Include="Tree\NodeFactory.cs" />
     <Compile Include="Tree\Statements\AssignmentStatement.cs" />
+    <Compile Include="Tree\Statements\ChunkStatement.cs" />
     <Compile Include="Tree\Statements\CompositeStatement.cs" />
-    <Compile Include="Tree\Statements\ExecutionFlowStatement.cs" />
+    <Compile Include="Tree\Statements\BreakStatement.cs" />
     <Compile Include="Tree\Statements\ForEachLoopStatement.cs" />
     <Compile Include="Tree\Statements\ForLoopStatement.cs" />
     <Compile Include="Tree\Statements\FunctionCallStatement.cs" />

+ 7 - 10
src/MoonSharp.Interpreter/MoonSharpInterpreter.cs

@@ -21,14 +21,11 @@ namespace MoonSharp.Interpreter
 			LuaStrict
 		}
 
-		private static Script LoadFromICharStream(ICharStream charStream, Table globalTable)
+		private static Script LoadFromICharStream(ICharStream charStream)
 		{
 			LuaLexer lexer;
 			LuaParser parser;
 
-			if (globalTable == null)
-				globalTable = new Table();
-
 			using (var _ = new CodeChrono("MoonSharpScript.LoadFromICharStream/AST"))
 			{
 				lexer = new LuaLexer(charStream);
@@ -41,21 +38,21 @@ namespace MoonSharp.Interpreter
 #endif
 			using (var _ = new CodeChrono("MoonSharpScript.LoadFromICharStream/EXE"))
 			{
-				var lcontext = new ScriptLoadingContext() { Scope = new BuildTimeScope(globalTable) };
-				CompositeStatement stat = new CompositeStatement(parser.chunk(), lcontext);
+				var lcontext = new ScriptLoadingContext() { Scope = new BuildTimeScope() };
+				ChunkStatement stat = new ChunkStatement(parser.chunk(), lcontext);
 				return new Script(stat, lcontext);
 			}
 		}
 
 
-		public static Script LoadFromFile(string filename, Table globalTable)
+		public static Script LoadFromFile(string filename)
 		{
-			return LoadFromICharStream(new AntlrFileStream(filename), globalTable);
+			return LoadFromICharStream(new AntlrFileStream(filename));
 		}
 
-		public static Script LoadFromString(string text, Table globalTable)
+		public static Script LoadFromString(string text)
 		{
-			return LoadFromICharStream(new AntlrInputStream(text), globalTable);
+			return LoadFromICharStream(new AntlrInputStream(text));
 		}
 
 	}

+ 0 - 3
src/MoonSharp.Interpreter/Tree/Expression.cs

@@ -14,8 +14,5 @@ namespace MoonSharp.Interpreter.Tree
 			: base(node, lcontext)
 		{ }
 
-
-		public abstract RValue Eval(RuntimeScope scope); 
-
 	}
 }

+ 1 - 14
src/MoonSharp.Interpreter/Tree/Expressions/ExprListExpression.cs

@@ -20,21 +20,8 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 				.ToArray();
 		}
 
-		public override RValue Eval(RuntimeScope scope)
-		{
-			RValue[] values = expressions.Select(e => e.Eval(scope)).ToArray();
-
-			if (values.Length > 1)
-			{
-				return RValue.FromPotentiallyNestedTuple(values);
-			}
-			else if (values.Length == 0)
-				return RValue.Nil;
-			else
-				return values[0].AsReadOnly();
-		}
 
-		public Expression[] Unpack()
+		public Expression[] GetExpressions()
 		{
 			return expressions;
 		}

+ 0 - 11
src/MoonSharp.Interpreter/Tree/Expressions/FunctionCallChainExpression.cs

@@ -39,17 +39,6 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 			: this(context, lcontext, context.varOrExp(), context.nameAndArgs())
 		{ }
 
-		public override RValue Eval(RuntimeScope scope)
-		{
-			RValue value = m_StartingExpression.Eval(scope).AsReadOnly();
-
-			foreach (FunctionCall fn in m_CallChain)
-			{
-				value = fn.Invoke(scope, value).AsReadOnly();
-			}
-
-			return value;
-		}
 
 		public override void Compile(Execution.VM.Chunk bc)
 		{

+ 9 - 9
src/MoonSharp.Interpreter/Tree/Expressions/FunctionDefinitionExpression.cs

@@ -73,7 +73,7 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 
 			lcontext.Scope.PushFunction();
 
-			m_ParamNames = paramnames.Select(n => lcontext.Scope.DefineLocal(n)).ToArray();
+			m_ParamNames = DefineArguments(paramnames, lcontext);
 
 			m_Statement = NodeFactory.CreateStatement(context.block(), lcontext);
 
@@ -82,18 +82,18 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 			lcontext.Scope.LeaveClosure();
 		}
 
-
-		public override RValue Eval(RuntimeScope scope)
+		private LRef[] DefineArguments(string[] paramnames, ScriptLoadingContext lcontext)
 		{
-			//List<RValue> closureValues = m_Closure.Select(s => scope.Get(s)).ToList();
-			//scope.EnterClosure(closureValues);
-			////var closureFunc = new Closure(scope, m_Statement, m_ParamNames, m_StackFrame, closureValues);
-			//scope.LeaveClosure();
+			LRef[] ret = new LRef[paramnames.Length];
+
+			for (int i = 0; i < paramnames.Length; i++)
+				ret[i] = lcontext.Scope.DefineLocal(paramnames[i]);
 
-			//return new RValue(closureFunc);
-			return null;
+			return ret;
 		}
 
+
+
 		public void Compile(Execution.VM.Chunk bc, Action afterDecl)
 		{
 			bc.Closure(m_Closure.ToArray(), bc.GetJumpPointForNextInstruction() + 3);

+ 0 - 22
src/MoonSharp.Interpreter/Tree/Expressions/IndexExpression.cs

@@ -21,28 +21,7 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 			m_IndexExp = indexExp;
 		}
 
-		public override RValue Eval(RuntimeScope scope)
-		{
-			RValue baseValue = m_BaseExp.Eval(scope).ToSimplestValue();
-			RValue indexValue = m_IndexExp.Eval(scope).ToSimplestValue();
-
-			if (baseValue.Type != DataType.Table)
-			{
-				throw new ScriptRuntimeException(this.TreeNode, "Can't index: {0}", baseValue.Type);
-			}
-			else
-			{
-				return baseValue.Table[indexValue];
-			}
-		}
 
-		public void SetValue(RuntimeScope scope, RValue rValue)
-		{
-			RValue baseValue = m_BaseExp.Eval(scope).ToSimplestValue();
-			RValue indexValue = m_IndexExp.Eval(scope).ToSimplestValue();
-
-			baseValue.Table[indexValue] = rValue;
-		}
 
 		public override void Compile(Chunk bc)
 		{
@@ -52,7 +31,6 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 		}
 
 
-
 		public void CompileAssignment(Chunk bc)
 		{
 			m_BaseExp.Compile(bc);

+ 0 - 5
src/MoonSharp.Interpreter/Tree/Expressions/LiteralExpression.cs

@@ -86,11 +86,6 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 			m_Value = new RValue(val).AsReadOnly();
 		}
 
-		public override RValue Eval(RuntimeScope scope)
-		{
-			return m_Value;
-		}
-
 		public override void Compile(Execution.VM.Chunk bc)
 		{
 			bc.Literal(m_Value);

+ 0 - 63
src/MoonSharp.Interpreter/Tree/Expressions/OperatorExpression.cs

@@ -107,71 +107,8 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 			}
 		}
 
-		public override RValue Eval(RuntimeScope scope)
-		{
-			RValue v1 = m_Exp1.Eval(scope);
-
-			if (v1.Type == DataType.Tuple)
-				v1 = v1.ToSimplestValue();
-
-			if (m_Operator == Operator.Or && v1.TestAsBoolean())
-				return RValue.True;
-
-			if (m_Operator == Operator.And && !(v1.TestAsBoolean()))
-				return RValue.False;
 
-			RValue v2 = m_Exp2 != null ? m_Exp2.Eval(scope) : v1;
 
-			if (v2.Type == DataType.Tuple)
-				v2 = v2.ToSimplestValue();
-
-			return ExecuteOperator(m_Operator, v1, v2);
-		}
-
-		public static RValue ExecuteOperator(Operator op, RValue v1, RValue v2)
-		{
-			switch (op)
-			{
-				case Operator.Or:
-					return v2.AsBoolean();
-				case Operator.And:
-					return v2.AsBoolean();
-				case Operator.Less:
-					return new RValue(v1.Number < v2.Number).AsReadOnly();
-				case Operator.Greater:
-					return new RValue(v1.Number > v2.Number).AsReadOnly();
-				case Operator.LessOrEqual:
-					return new RValue(v1.Number < v2.Number).AsReadOnly();
-				case Operator.GreaterOrEqual:
-					return new RValue(v1.Number >= v2.Number).AsReadOnly();
-				case Operator.NotEqual:
-					return new RValue(v1.Number != v2.Number).AsReadOnly();
-				case Operator.Equal:
-					return new RValue(v1.Number == v2.Number).AsReadOnly();
-				case Operator.StrConcat:
-					return new RValue(v1.String + v2.String).AsReadOnly();
-				case Operator.Add:
-					return new RValue(v1.Number + v2.Number).AsReadOnly();
-				case Operator.Sub:
-					return new RValue(v1.Number - v2.Number).AsReadOnly();
-				case Operator.Mul:
-					return new RValue(v1.Number * v2.Number).AsReadOnly();
-				case Operator.Div:
-					return new RValue(v1.Number / v2.Number).AsReadOnly();
-				case Operator.Mod:
-					return new RValue(v1.Number % v2.Number).AsReadOnly();
-				case Operator.Not:
-					return new RValue(!v1.Boolean);
-				case Operator.Size:
-					return v1.GetLength();
-				case Operator.Neg:
-					return new RValue(-v1.Number).AsReadOnly();
-				case Operator.Power:
-					return new RValue(Math.Pow(v1.Number, v2.Number)).AsReadOnly();
-				default:
-					throw new NotImplementedException();
-			}
-		}
 
 		public static bool IsOperatorExpression(IParseTree tree)
 		{

+ 0 - 22
src/MoonSharp.Interpreter/Tree/Expressions/SymbolRefExpression.cs

@@ -17,36 +17,14 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 		{
 			string varName = terminalNode.GetText();
 			m_Ref = lcontext.Scope.Find(varName);
-
-			if (!m_Ref.IsValid())
-			{
-				m_Ref = lcontext.Scope.DefineGlobal(varName);
-			}
 		}
 
-		public override RValue Eval(RuntimeScope scope)
-		{
-			RValue v = scope.Get(m_Ref);
-
-			if (v == null)
-				throw new ScriptRuntimeException(this.TreeNode, "Undefined symbol: {0}", m_Ref.i_Name);
-
-			return v;
-		}
-
-		public void SetValue(RuntimeScope scope, RValue rValue)
-		{
-			scope.Assign(m_Ref, rValue);
-		}
 
 		public override void Compile(Execution.VM.Chunk bc)
 		{
 			bc.Load(m_Ref);
 		}
 
-
-
-
 		public void CompileAssignment(Execution.VM.Chunk bc)
 		{
 			bc.Symbol(m_Ref);

+ 0 - 10
src/MoonSharp.Interpreter/Tree/Expressions/TableConstructor.cs

@@ -48,16 +48,6 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 		}
 
 
-		public override RValue Eval(RuntimeScope scope)
-		{
-			var dic = m_CtorArgs.ToDictionary(
-				kvp => kvp.Key.Eval(scope),
-				kvp => kvp.Value.Eval(scope).ToSimplestValue().CloneAsWritable());
-
-			Table t = new Table(dic, m_PositionalValues.Select(e => e.Eval(scope)));
-
-			return new RValue(t);
-		}
 
 		public override void Compile(Execution.VM.Chunk bc)
 		{

+ 0 - 38
src/MoonSharp.Interpreter/Tree/FunctionCall.cs

@@ -19,48 +19,10 @@ namespace MoonSharp.Interpreter.Tree
 			: base(nameAndArgs, lcontext)
 		{
 			var name = nameAndArgs.NAME();
-
 			m_Name = name != null ? name.GetText().Trim() : null;
-
 			m_Arguments = nameAndArgs.args().children.SelectMany(t => NodeFactory.CreateExpressions(t, lcontext)).Where(t => t != null).ToArray();
 		}
 
-		public RValue Invoke(RuntimeScope scope, RValue value)
-		{
-			RValue[] args;
-
-			if (value.Type == DataType.Table)
-			{
-				var method = value.Table[new RValue(m_Name)];
-
-				args = new RValue[] { value }.Union(
-						m_Arguments
-						.Select(exp => exp.Eval(scope))
-						.SelectMany(val => val.ToArrayOfValues())
-					)
-					.ToArray();
-
-				value = method;
-			}
-			else
-			{
-				args = m_Arguments
-					.Select(exp => exp.Eval(scope))
-					.SelectMany(val => val.ToArrayOfValues())
-					.ToArray();
-			}
-
-			if (value.Type == DataType.ClrFunction)
-			{
-				return value.Callback.Invoke(scope, args);
-			}
-			else
-			{
-				throw RuntimeError("Function was expected, but a {0} was passed.", value.Type.ToString());
-			}
-		}
-
-
 		public override void Compile(Execution.VM.Chunk bc)
 		{
 			if (!string.IsNullOrEmpty(m_Name))

+ 1 - 3
src/MoonSharp.Interpreter/IVariable.cs → src/MoonSharp.Interpreter/Tree/IVariable.cs

@@ -4,12 +4,10 @@ using System.Linq;
 using System.Text;
 using MoonSharp.Interpreter.Execution;
 
-namespace MoonSharp.Interpreter
+namespace MoonSharp.Interpreter.Tree
 {
 	interface IVariable
 	{
-		void SetValue(RuntimeScope scope, RValue rValue);
-
 		void CompileAssignment(Execution.VM.Chunk bc);
 	}
 }

+ 1 - 0
src/MoonSharp.Interpreter/Tree/NodeBase.cs

@@ -40,6 +40,7 @@ namespace MoonSharp.Interpreter.Tree
 			if (!condition)
 				throw  RuntimeError(format, args);
 		}
+
 		public virtual void Compile(Chunk bc)
 		{
 			bc.Invalid(this.GetType().Name);

+ 3 - 3
src/MoonSharp.Interpreter/Tree/NodeFactory.cs

@@ -22,7 +22,7 @@ namespace MoonSharp.Interpreter.Tree
 				return new CompositeStatement((LuaParser.BlockContext)tree, lcontext);
 
 			if (tree is LuaParser.ChunkContext)
-				return new CompositeStatement((LuaParser.ChunkContext)tree, lcontext);
+				return new ChunkStatement((LuaParser.ChunkContext)tree, lcontext);
 
 			if (tree is LuaParser.Stat_funcdefContext)
 				return new FunctionDefinitionStatement((LuaParser.Stat_funcdefContext)tree, lcontext);
@@ -52,7 +52,7 @@ namespace MoonSharp.Interpreter.Tree
 				return new LocalAssignmentStatement((LuaParser.Stat_localassignmentContext)tree, lcontext);
 
 			if (tree is LuaParser.Stat_breakContext)
-				return new ExecutionFlowStatement((LuaParser.Stat_breakContext)tree, lcontext);
+				return new BreakStatement((LuaParser.Stat_breakContext)tree, lcontext);
 
 			if (tree is LuaParser.Stat_forloopContext)
 				return new ForLoopStatement((LuaParser.Stat_forloopContext)tree, lcontext);
@@ -184,7 +184,7 @@ namespace MoonSharp.Interpreter.Tree
 		public static Expression[] CreateExpressions(IParseTree tree, ScriptLoadingContext lcontext)
 		{
 			if (tree is LuaParser.ExplistContext)
-				return new ExprListExpression((LuaParser.ExplistContext)tree, lcontext).Unpack();
+				return new ExprListExpression((LuaParser.ExplistContext)tree, lcontext).GetExpressions();
 
 			return new Expression[] { CreateExpression(tree, lcontext) };
 		}

+ 0 - 60
src/MoonSharp.Interpreter/Tree/Statement.cs

@@ -17,66 +17,6 @@ namespace MoonSharp.Interpreter.Tree
 			: base(tree, lcontext)
 		{ }
 
-		public abstract ExecutionFlow Exec(RuntimeScope scope);
-
-
-		public RValue GetReturnValueAtReturnPoint(ExecutionFlow flow)
-		{
-			if (flow.Type == ExecutionFlowType.Return)
-			{
-				return flow.ReturnValue.ToSimplestValue();
-			}
-			else if (flow.Type == ExecutionFlowType.None)
-			{
-				return RValue.Nil;
-			}
-			else
-			{
-				throw RuntimeError("Can't process flow control '{0}'.", flow.Type.ToString().ToLower());
-			}
-		}
-
-		public static ExecutionFlow PairMultipleAssignment<T>(RuntimeScope scope, T[] lValues, Expression[] rValues, Action<T, RuntimeScope, RValue> setter)
-		{
-			int li = 0;
-
-			for (int ri = 0; ri < rValues.Length && li < lValues.Length; ri++, li++)
-			{
-				RValue vv = rValues[ri].Eval(scope);
-
-				if ((ri != rValues.Length - 1)||(vv.Type != DataType.Tuple))
-				{
-					setter(lValues[li], scope, vv.ToSingleValue());
-					// Debug.WriteLine(string.Format("{0} <- {1}", li, vv.ToSingleValue()));
-				}
-				else
-				{
-					for (int rri = 0; rri < vv.Tuple.Length && li < lValues.Length; rri++, li++)
-					{
-						setter(lValues[li], scope, vv.Tuple[rri].ToSingleValue());
-						// Debug.WriteLine(string.Format("{0} <- {1}", li, vv.Tuple[rri].ToSingleValue()));
-					}
-				}
-			}
-
-			return ExecutionFlow.None;
-		}
-
-		protected ExecutionFlow ExecuteStatementInBlockScope(Statement s, RuntimeScope scope, RuntimeScopeFrame stackframe, LRef symb = null, RValue varvalue = null)
-		{
-			scope.PushFrame(stackframe);
-
-			if (symb != null && varvalue != null)
-				scope.Assign(symb, varvalue);
-
-			ExecutionFlow flow = s.Exec(scope);
-
-			scope.PopFrame(stackframe);
-
-			return flow;
-		}
-
-
 
 	}
 

+ 0 - 15
src/MoonSharp.Interpreter/Tree/Statements/AssignmentStatement.cs

@@ -28,21 +28,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 				.ToArray();
 		}
 
-		public override ExecutionFlow Exec(RuntimeScope scope)
-		{
-			if (m_LValues.Length == 1 && m_RValues.Length >= 1)
-			{
-				m_LValues[0].SetValue(scope, m_RValues[0].Eval(scope).ToSingleValue());
-				return ExecutionFlow.None;
-			}
-			else
-			{
-				return PairMultipleAssignment(scope, m_LValues, m_RValues, (l, s, v) => 
-				{ 
-					l.SetValue(s, v); 
-				} );
-			}
-		}
 
 		public override void Compile(Execution.VM.Chunk bc)
 		{

+ 25 - 0
src/MoonSharp.Interpreter/Tree/Statements/BreakStatement.cs

@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using MoonSharp.Interpreter.Execution;
+using MoonSharp.Interpreter.Execution.VM;
+using MoonSharp.Interpreter.Grammar;
+
+namespace MoonSharp.Interpreter.Tree.Statements
+{
+	class BreakStatement : Statement
+	{
+		public BreakStatement(LuaParser.Stat_breakContext context, ScriptLoadingContext lcontext)
+			: base(context, lcontext)
+		{
+		}
+
+
+
+		public override void Compile(Chunk bc)
+		{
+			bc.LoopTracker.Loops.Peek().CompileBreak(bc);
+		}
+	}
+}

+ 0 - 29
src/MoonSharp.Interpreter/Tree/Statements/CompositeStatement.cs

@@ -17,7 +17,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 		{
 			if (context.ChildCount > 0)
 			{
-
 				m_Statements = context.children
 					.Select(t => NodeFactory.CreateStatement(t, lcontext))
 					.Where(s => s != null)
@@ -37,34 +36,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 			}
 		}
 
-		public CompositeStatement(LuaParser.ChunkContext context, ScriptLoadingContext lcontext)
-			: this((LuaParser.BlockContext)context.children.First(), lcontext)
-		{
-		}
-
-		public RValue ExecRoot(RuntimeScope scope)
-		{
-			ExecutionFlow flow = this.Exec(scope);
-			return base.GetReturnValueAtReturnPoint(flow);
-		}
-
-
-
-		public override ExecutionFlow Exec(RuntimeScope scope)
-		{
-			if (m_Statements != null)
-			{
-				foreach (Statement s in m_Statements)
-				{
-					ExecutionFlow flow = s.Exec(scope);
-
-					if (flow.ChangesFlow()) 
-						return flow;
-				}
-			}
-
-			return ExecutionFlow.None;
-		}
 
 		public override void Compile(Execution.VM.Chunk bc)
 		{

+ 0 - 38
src/MoonSharp.Interpreter/Tree/Statements/ExecutionFlowStatement.cs

@@ -1,38 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using MoonSharp.Interpreter.Execution;
-using MoonSharp.Interpreter.Execution.VM;
-using MoonSharp.Interpreter.Grammar;
-
-namespace MoonSharp.Interpreter.Tree.Statements
-{
-	class ExecutionFlowStatement : Statement
-	{
-		ExecutionFlow m_Flow;
-
-		public ExecutionFlowStatement(LuaParser.Stat_breakContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			m_Flow = ExecutionFlow.Break;
-		}
-
-		public ExecutionFlowStatement(LuaParser.Stat_gotoContext context, ScriptLoadingContext lcontext)
-			: base(context, lcontext)
-		{
-			m_Flow = ExecutionFlow.GoTo(context.NAME().GetText());
-			throw new NotImplementedException("GoTo not implemented yet!");
-		}
-
-		public override ExecutionFlow Exec(RuntimeScope scope)
-		{
-			return m_Flow;
-		}
-
-		public override void Compile(Chunk bc)
-		{
-			bc.LoopTracker.Loops.Peek().CompileBreak(bc);
-		}
-	}
-}

+ 0 - 67
src/MoonSharp.Interpreter/Tree/Statements/ForEachLoopStatement.cs

@@ -101,72 +101,5 @@ namespace MoonSharp.Interpreter.Tree.Statements
 		}
 
 
-		public override ExecutionFlow Exec(RuntimeScope scope)
-		{
-			return ExecutionFlow.None;
-			//List<RValue> values = m_RValues
-			//	.Select(r => r.Eval(scope))
-			//	.SelectMany(r => r.UnpackedTuple())
-			//	.ToList();
-
-			//while (values.Count < 3)
-			//	values.Add(RValue.Nil);
-
-			//RValue F = values[0];
-			//RValue[] args = new RValue[2];
-
-			//args[0] = values[1];
-			//args[1] = values[2];
-
-
-			//while (true)
-			//{
-			//	if (F.Type != DataType.ClrFunction)
-			//		throw RuntimeError("Attempt to call non-function");
-
-			//	RValue tuple = F.Callback.Invoke(scope, args);
-
-			//	scope.PushFrame(m_StackFrame);
-
-			//	int iv = 0;
-			//	RValue firstVal = null;
-
-			//	foreach (var vv in tuple.UnpackedTuple())
-			//	{
-			//		if (iv >= m_Names.Length)
-			//			break;
-
-			//		scope.Assign(m_Names[iv], vv);
-
-			//		if (firstVal == null)
-			//			args[1] = firstVal = vv;
-
-			//		++iv;
-			//	}
-
-
-			//	while (iv < m_Names.Length)
-			//	{
-			//		scope.Assign(m_Names[iv], RValue.Nil);
-			//		++iv;
-			//	}
-
-			//	if (firstVal == null || firstVal.Type == DataType.Nil)
-			//	{
-			//		scope.PopFrame(m_StackFrame);
-			//		return ExecutionFlow.None;
-			//	}
-
-			//	ExecutionFlow flow = m_Block.Exec(scope);
-
-			//	scope.PopFrame(m_StackFrame);
-
-			//	if (flow.Type == ExecutionFlowType.Return)
-			//		return flow;
-
-			//	if (flow.Type == ExecutionFlowType.Break)
-			//		return ExecutionFlow.None;
-			//}
-		}
 	}
 }

+ 0 - 31
src/MoonSharp.Interpreter/Tree/Statements/ForLoopStatement.cs

@@ -36,37 +36,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 			m_StackFrame = lcontext.Scope.Pop();
 		}
 
-		public override ExecutionFlow Exec(RuntimeScope scope)
-		{
-			RValue startv = m_Start.Eval(scope).AsNumber();
-			RValue stopv = m_End.Eval(scope).AsNumber();
-			RValue stepv = m_Step.Eval(scope).AsNumber();
-
-			RuntimeAssert(startv.Type == DataType.Number, "'for' initial value must be a number");
-			RuntimeAssert(stopv.Type == DataType.Number, "'for' stop value must be a number");
-			RuntimeAssert(stepv.Type == DataType.Number, "'for' step value must be a number");
-
-			RValue v = new RValue(startv.Number);
-
-			for (double d = startv.Number;
-				(stepv.Number > 0) ? d <= stopv.Number : d >= stopv.Number;
-				d += stepv.Number)
-			{
-				v.Assign(d);
-
-				ExecutionFlow flow = ExecuteStatementInBlockScope(m_InnerBlock, scope, m_StackFrame, m_VarName, v);
-
-				if (flow.Type == ExecutionFlowType.Break)
-					return ExecutionFlow.None;
-				else if (flow.Type == ExecutionFlowType.Return)
-					return flow;
-			}
-
-			return ExecutionFlow.None;
-		}
-
-
-
 		public override void Compile(Chunk bc)
 		{
 			Loop L = new Loop()

+ 0 - 6
src/MoonSharp.Interpreter/Tree/Statements/FunctionCallStatement.cs

@@ -21,12 +21,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 		}
 
 
-		public override ExecutionFlow Exec(RuntimeScope scope)
-		{
-			m_FunctionCallChain.Eval(scope);
-			return ExecutionFlow.None;
-		}
-
 		public override void Compile(Chunk bc)
 		{
 			m_FunctionCallChain.Compile(bc);

+ 1 - 35
src/MoonSharp.Interpreter/Tree/Statements/FunctionDefinitionStatement.cs

@@ -45,7 +45,7 @@ namespace MoonSharp.Interpreter.Tree.Statements
 			}
 			else
 			{
-				m_FuncName = lcontext.Scope.DefineGlobal(fnname.Text);
+				m_FuncName = LRef.Global(fnname.Text);
 			}
 
 			if (nameOfMethodAccessor != null)
@@ -60,40 +60,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 		}
 
 
-		public override ExecutionFlow Exec(RuntimeScope scope)
-		{
-			if (m_Local)
-			{
-				scope.Assign(m_FuncName, m_FuncDef.Eval(scope));
-			}
-			else
-			{
-				if (m_MethodName == null)
-				{
-					scope.Assign(m_FuncName, m_FuncDef.Eval(scope));
-				}
-				else
-				{
-					RValue rvalue = scope.Get(m_FuncName);
-
-					foreach (string str in m_TableAccessors)
-					{
-						if (rvalue.Type != DataType.Table)
-							throw RuntimeError("Table expected, got {0}", rvalue.Type);
-
-						rvalue = rvalue.Table[new RValue(str)];
-					}
-
-					if (rvalue.Type != DataType.Table)
-						throw RuntimeError("Table expected, got {0}", rvalue.Type);
-
-					rvalue.Table[new RValue(m_MethodName)] = m_FuncDef.Eval(scope);
-				}
-			}
-
-			return ExecutionFlow.None;
-		}
-
 
 		public override void Compile(Execution.VM.Chunk bc)
 		{

+ 0 - 13
src/MoonSharp.Interpreter/Tree/Statements/IfStatement.cs

@@ -49,19 +49,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 			}
 		}
 
-		public override ExecutionFlow Exec(RuntimeScope scope)
-		{
-			foreach (var ifblock in m_Ifs)
-			{
-				if (ifblock.Exp.Eval(scope).TestAsBoolean())
-					return ExecuteStatementInBlockScope(ifblock.Block, scope, ifblock.StackFrame);
-			}
-
-			if (m_Else != null)
-				return ExecuteStatementInBlockScope(m_Else, scope, m_ElseStackFrame);
-
-			return ExecutionFlow.None;
-		}
 
 		public override void Compile(Execution.VM.Chunk bc)
 		{

+ 0 - 5
src/MoonSharp.Interpreter/Tree/Statements/LabelStatement.cs

@@ -16,10 +16,5 @@ namespace MoonSharp.Interpreter.Tree.Statements
 		{
 			Label = context.label().NAME().GetText();
 		}
-
-		public override ExecutionFlow Exec(RuntimeScope scope)
-		{
-			return ExecutionFlow.None;
-		}
 	}
 }

+ 0 - 16
src/MoonSharp.Interpreter/Tree/Statements/LocalAssignmentStatement.cs

@@ -37,22 +37,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 		}
 
 
-		public override ExecutionFlow Exec(RuntimeScope scope)
-		{
-			if (m_Names.Length == 1 && m_RValues.Length >= 1)
-			{
-				scope.Assign(m_Names[0], m_RValues[0].Eval(scope).ToSimplestValue());
-				return ExecutionFlow.None;
-			}
-			else
-			{
-				return PairMultipleAssignment(scope, m_Names, m_RValues, (l, s, v) => 
-				{
-					scope.Assign(l, v);
-				});
-			}
-		}
-
 		public override void Compile(Execution.VM.Chunk bc)
 		{
 			if (m_Names.Length == 1 && m_RValues.Length == 1)

+ 0 - 4
src/MoonSharp.Interpreter/Tree/Statements/NullStatement.cs

@@ -13,10 +13,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 			: base(context, lcontext)
 		{ }
 
-		public override ExecutionFlow Exec(RuntimeScope scope)
-		{
-			return ExecutionFlow.None;
-		}
 
 		public override void Compile(Execution.VM.Chunk bc)
 		{

+ 0 - 28
src/MoonSharp.Interpreter/Tree/Statements/RepeatStatement.cs

@@ -23,34 +23,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 			m_StackFrame = lcontext.Scope.Pop();
 		}
 
-		public override ExecutionFlow Exec(RuntimeScope scope)
-		{
-			bool condition = true;
-
-			while (condition)
-			{
-				scope.PushFrame(m_StackFrame);
-
-				ExecutionFlow flow = m_Block.Exec(scope);
-
-				if (flow.Type == ExecutionFlowType.Break)
-				{
-					scope.PopFrame(m_StackFrame);
-					return ExecutionFlow.None;
-				}
-				else if (flow.Type == ExecutionFlowType.Return)
-				{
-					scope.PopFrame(m_StackFrame);
-					return flow;
-				}
-
-				condition = !m_Condition.Eval(scope).TestAsBoolean();
-
-				scope.PopFrame(m_StackFrame);
-			}
-
-			return ExecutionFlow.None;
-		}
 
 		public override void Compile(Chunk bc)
 		{

+ 0 - 5
src/MoonSharp.Interpreter/Tree/Statements/ReturnStatement.cs

@@ -20,11 +20,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 		}
 
 
-		public override ExecutionFlow Exec(RuntimeScope scope)
-		{
-			RValue val = m_Expression.Eval(scope);
-			return ExecutionFlow.Return(val);
-		}
 
 		public override void Compile(Execution.VM.Chunk bc)
 		{

+ 0 - 5
src/MoonSharp.Interpreter/Tree/Statements/ScopeBlockStatement.cs

@@ -20,11 +20,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 			m_StackFrame = lcontext.Scope.Pop();
 		}
 
-		public override ExecutionFlow Exec(RuntimeScope scope)
-		{
-			return ExecuteStatementInBlockScope(m_Block, scope, m_StackFrame);
-		}
-
 		public override void Compile(Execution.VM.Chunk bc)
 		{
 			bc.Enter(m_StackFrame);

+ 0 - 14
src/MoonSharp.Interpreter/Tree/Statements/WhileStatement.cs

@@ -24,20 +24,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 			m_StackFrame = lcontext.Scope.Pop();
 		}
 
-		public override ExecutionFlow Exec(RuntimeScope scope)
-		{
-			while (m_Condition.Eval(scope).TestAsBoolean())
-			{
-				ExecutionFlow flow = ExecuteStatementInBlockScope(m_Block, scope, m_StackFrame);
-
-				if (flow.Type == ExecutionFlowType.Break)
-					return ExecutionFlow.None;
-				else if (flow.Type == ExecutionFlowType.Return)
-					return flow;
-			}
-
-			return ExecutionFlow.None;
-		}
 
 		public override void Compile(Chunk bc)
 		{

+ 2 - 4
src/MoonSharp/Program.cs

@@ -14,9 +14,7 @@ namespace MoonSharp
 		static RValue Print(RValue[] values)
 		{
 			string prn = string.Join(" ", values.Select(v => v.AsString()).ToArray());
-
 			Console.WriteLine("{0}", prn);
-
 			return RValue.Nil;
 		}
 
@@ -43,9 +41,9 @@ namespace MoonSharp
 				Table globalTable = new Table();
 				globalTable[new RValue("print")] = new RValue(new CallbackFunction(Print));
 
-				var script = MoonSharpInterpreter.LoadFromFile(args[0], globalTable);
+				var script = MoonSharpInterpreter.LoadFromFile(args[0]);
 
-				script.Execute();
+				script.Execute(globalTable);
 
 				Console.WriteLine("Done.");
 				

+ 10 - 10
src/PerformanceComparison/Program.cs

@@ -13,7 +13,7 @@ namespace PerformanceComparison
 {
 	class Program
 	{
-		const int ITERATIONS = 100;
+		const int ITERATIONS = 1000;
 
 		static  string scriptText1 = @"
 			function move(n, src, dst, via)
@@ -63,15 +63,15 @@ if Find_Solution( 1 ) then
     for i = 1, N do
  	for j = 1, N do
   	    if board[i][j] then 
-		print( 'Q' )
+		--print( 'Q' )
 	    else 
-		print( 'x' )
+		--print( 'x' )
 	    end
 	end
-	print( '|' )
+	--print( '|' )
     end
 else
-    print( 'NO!' )
+    --print( 'NO!' )
 end
  
 			";
@@ -94,9 +94,9 @@ end
 			Table t = new Table();
 			t[new RValue("print")] = new RValue(new CallbackFunction(Print));
 
-			Script script = MoonSharpInterpreter.LoadFromFile(@"c:\temp\test.lua", t);
+			Script script = MoonSharpInterpreter.LoadFromFile(@"c:\temp\test.lua");
 
-			RValue retVal = script.Execute();
+			RValue retVal = script.Execute(t);
 		}
 
 		public static void NPrint(params object[] values)
@@ -120,7 +120,7 @@ end
 			Table t = new Table();
 			t[new RValue("print")] = new RValue(new CallbackFunction(Print));
 
-			MoonSharpInterpreter.LoadFromString(scriptText, t);
+			MoonSharpInterpreter.LoadFromString(scriptText);
 
 			sw.Stop();
 
@@ -131,7 +131,7 @@ end
 			t = new Table();
 			t[new RValue("print")] = new RValue(new CallbackFunction(Print));
 
-			var script = MoonSharpInterpreter.LoadFromString(scriptText, t);
+			var script = MoonSharpInterpreter.LoadFromString(scriptText);
 
 			sw.Stop();
 
@@ -141,7 +141,7 @@ end
 			sw = Stopwatch.StartNew();
 			for (int i = 0; i < ITERATIONS; i++)
 			{
-				script.Execute();
+				script.Execute(t);
 			}
 			sw.Stop();