Browse Source

All tests passing!!

Xanathar 11 years ago
parent
commit
468261ca50
43 changed files with 1161 additions and 660 deletions
  1. 16 0
      src/MoonSharp.Debugger/DoubleBufferedListView.cs
  2. 209 81
      src/MoonSharp.Debugger/MainForm.Designer.cs
  3. 122 35
      src/MoonSharp.Debugger/MainForm.cs
  4. 50 44
      src/MoonSharp.Debugger/MainForm.resx
  5. 22 0
      src/MoonSharp.Debugger/MoonSharp.Debugger.csproj
  6. 30 0
      src/MoonSharp.Debugger/Properties/Resources.Designer.cs
  7. 11 2
      src/MoonSharp.Debugger/Properties/Resources.resx
  8. BIN
      src/MoonSharp.Debugger/Resources/GoToDeclaration_5576.png
  9. BIN
      src/MoonSharp.Debugger/Resources/NavigateBackwards_6270.png
  10. BIN
      src/MoonSharp.Debugger/Resources/NavigateForward_6271.png
  11. 7 2
      src/MoonSharp.Debugger/SourceCodeDebugControl.cs
  12. 329 0
      src/MoonSharp.Debugger/ValueBrowser.Designer.cs
  13. 240 0
      src/MoonSharp.Debugger/ValueBrowser.cs
  14. 21 0
      src/MoonSharp.Interpreter.Tests/ClosureTests.cs
  15. 30 20
      src/MoonSharp.Interpreter.Tests/LuaTestSuiteExtract.cs
  16. 2 2
      src/MoonSharp.Interpreter/CoreLib/BasicMethods.cs
  17. 5 1
      src/MoonSharp.Interpreter/DataStructs/FastStack.cs
  18. 0 89
      src/MoonSharp.Interpreter/Execution/Behaviours/Behaviour.cs
  19. 0 132
      src/MoonSharp.Interpreter/Execution/Behaviours/DefaultBehaviour.cs
  20. 4 4
      src/MoonSharp.Interpreter/Execution/DataTypes/Closure.cs
  21. 0 1
      src/MoonSharp.Interpreter/Execution/DataTypes/DataType.cs
  22. 4 4
      src/MoonSharp.Interpreter/Execution/DataTypes/RValue.cs
  23. 6 2
      src/MoonSharp.Interpreter/Execution/DataTypes/Table.cs
  24. 0 68
      src/MoonSharp.Interpreter/Execution/ExecutionFlow.cs
  25. 0 16
      src/MoonSharp.Interpreter/Execution/ExecutionFlowType.cs
  26. 0 23
      src/MoonSharp.Interpreter/Execution/Operator.cs
  27. 0 3
      src/MoonSharp.Interpreter/Execution/Scopes/BuildTimeScope.cs
  28. 2 2
      src/MoonSharp.Interpreter/Execution/Scopes/ClosureContext.cs
  29. 1 1
      src/MoonSharp.Interpreter/Execution/Scopes/LoopTracker.cs
  30. 2 8
      src/MoonSharp.Interpreter/Execution/VM/Chunk.cs
  31. 0 5
      src/MoonSharp.Interpreter/Execution/VM/Instruction.cs
  32. 1 7
      src/MoonSharp.Interpreter/Execution/VM/OpCode.cs
  33. 1 2
      src/MoonSharp.Interpreter/Execution/VM/Processor/Processor.cs
  34. 1 1
      src/MoonSharp.Interpreter/Execution/VM/Processor/Processor_Debugger.cs
  35. 19 38
      src/MoonSharp.Interpreter/Execution/VM/Processor/Processor_InstructionLoop.cs
  36. 0 0
      src/MoonSharp.Interpreter/Grammar/LuaGrammar_ExtensionMethods.cs
  37. 0 44
      src/MoonSharp.Interpreter/Helpers/List_ExtensionMethods.cs
  38. 1 7
      src/MoonSharp.Interpreter/MoonSharp.Interpreter.csproj
  39. 6 0
      src/MoonSharp.Interpreter/MoonSharpInterpreter.cs
  40. 12 0
      src/MoonSharp.Interpreter/Tree/Expressions/OperatorExpression.cs
  41. 5 15
      src/MoonSharp.Interpreter/Tree/FunctionCall.cs
  42. 0 1
      src/MoonSharp.Interpreter/Tree/Statements/ForEachLoopStatement.cs
  43. 2 0
      src/MoonSharp.Interpreter/Tree/Statements/FunctionDefinitionStatement.cs

+ 16 - 0
src/MoonSharp.Debugger/DoubleBufferedListView.cs

@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MoonSharp.Debugger
+{
+	class DoubleBufferedListView : System.Windows.Forms.ListView
+	{
+		public DoubleBufferedListView()
+			: base()
+		{
+			this.DoubleBuffered = true;
+		}
+	}
+}

+ 209 - 81
src/MoonSharp.Debugger/MainForm.Designer.cs

@@ -49,13 +49,13 @@
 			this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
 			this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
 			this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
 			this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
 			this.toolStrip1 = new System.Windows.Forms.ToolStrip();
 			this.toolStrip1 = new System.Windows.Forms.ToolStrip();
-			this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
+			this.btnOpenFile = new System.Windows.Forms.ToolStripButton();
 			this.toolStripButton2 = new System.Windows.Forms.ToolStripButton();
 			this.toolStripButton2 = new System.Windows.Forms.ToolStripButton();
 			this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
 			this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
 			this.toolStripButton3 = new System.Windows.Forms.ToolStripButton();
 			this.toolStripButton3 = new System.Windows.Forms.ToolStripButton();
 			this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
 			this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
-			this.toolStripButton6 = new System.Windows.Forms.ToolStripButton();
-			this.toolStripButton4 = new System.Windows.Forms.ToolStripButton();
+			this.toolGO = new System.Windows.Forms.ToolStripButton();
+			this.toolStepOver = new System.Windows.Forms.ToolStripButton();
 			this.toolStepIN = new System.Windows.Forms.ToolStripButton();
 			this.toolStepIN = new System.Windows.Forms.ToolStripButton();
 			this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
 			this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
 			this.toolStripButton5 = new System.Windows.Forms.ToolStripButton();
 			this.toolStripButton5 = new System.Windows.Forms.ToolStripButton();
@@ -64,7 +64,7 @@
 			this.splitContainer2 = new System.Windows.Forms.SplitContainer();
 			this.splitContainer2 = new System.Windows.Forms.SplitContainer();
 			this.tabControl2 = new System.Windows.Forms.TabControl();
 			this.tabControl2 = new System.Windows.Forms.TabControl();
 			this.tabPage3 = new System.Windows.Forms.TabPage();
 			this.tabPage3 = new System.Windows.Forms.TabPage();
-			this.lvWatches = new System.Windows.Forms.ListView();
+			this.lvWatches = new MoonSharp.Debugger.DoubleBufferedListView();
 			this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
 			this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
 			this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
 			this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
 			this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
 			this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
@@ -74,24 +74,32 @@
 			this.btnRemoveWatch = new System.Windows.Forms.ToolStripButton();
 			this.btnRemoveWatch = new System.Windows.Forms.ToolStripButton();
 			this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
 			this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
 			this.btnViewWatch = new System.Windows.Forms.ToolStripButton();
 			this.btnViewWatch = new System.Windows.Forms.ToolStripButton();
+			this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
 			this.label3 = new System.Windows.Forms.Label();
 			this.label3 = new System.Windows.Forms.Label();
 			this.tabPage4 = new System.Windows.Forms.TabPage();
 			this.tabPage4 = new System.Windows.Forms.TabPage();
+			this.lvVStack = new MoonSharp.Debugger.DoubleBufferedListView();
+			this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.columnHeader6 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.columnHeader7 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.toolStrip3 = new System.Windows.Forms.ToolStrip();
+			this.btnViewVStk = new System.Windows.Forms.ToolStripButton();
+			this.toolGoToCodeVStack = new System.Windows.Forms.ToolStripButton();
 			this.label2 = new System.Windows.Forms.Label();
 			this.label2 = new System.Windows.Forms.Label();
 			this.imageList1 = new System.Windows.Forms.ImageList(this.components);
 			this.imageList1 = new System.Windows.Forms.ImageList(this.components);
 			this.tabControl1 = new System.Windows.Forms.TabControl();
 			this.tabControl1 = new System.Windows.Forms.TabControl();
 			this.tabPage1 = new System.Windows.Forms.TabPage();
 			this.tabPage1 = new System.Windows.Forms.TabPage();
-			this.lvCallStack = new System.Windows.Forms.ListView();
+			this.lvCallStack = new MoonSharp.Debugger.DoubleBufferedListView();
 			this.colAddress = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
 			this.colAddress = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
 			this.colName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
 			this.colName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
 			this.colReturn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
 			this.colReturn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
 			this.colBP = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
 			this.colBP = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.toolStrip4 = new System.Windows.Forms.ToolStrip();
+			this.toolGoToCodeXStack = new System.Windows.Forms.ToolStripButton();
 			this.tabPage2 = new System.Windows.Forms.TabPage();
 			this.tabPage2 = new System.Windows.Forms.TabPage();
 			this.label1 = new System.Windows.Forms.Label();
 			this.label1 = new System.Windows.Forms.Label();
+			this.splitContainer3 = new System.Windows.Forms.SplitContainer();
 			this.codeView = new MoonSharp.Debugger.SourceCodeDebugControl();
 			this.codeView = new MoonSharp.Debugger.SourceCodeDebugControl();
-			this.lvVStack = new System.Windows.Forms.ListView();
-			this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
-			this.columnHeader6 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
-			this.columnHeader7 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.txtOutput = new System.Windows.Forms.TextBox();
 			this.menuStrip1.SuspendLayout();
 			this.menuStrip1.SuspendLayout();
 			this.toolStrip1.SuspendLayout();
 			this.toolStrip1.SuspendLayout();
 			this.splitContainer1.Panel1.SuspendLayout();
 			this.splitContainer1.Panel1.SuspendLayout();
@@ -104,9 +112,14 @@
 			this.tabPage3.SuspendLayout();
 			this.tabPage3.SuspendLayout();
 			this.toolStrip2.SuspendLayout();
 			this.toolStrip2.SuspendLayout();
 			this.tabPage4.SuspendLayout();
 			this.tabPage4.SuspendLayout();
+			this.toolStrip3.SuspendLayout();
 			this.tabControl1.SuspendLayout();
 			this.tabControl1.SuspendLayout();
 			this.tabPage1.SuspendLayout();
 			this.tabPage1.SuspendLayout();
+			this.toolStrip4.SuspendLayout();
 			this.tabPage2.SuspendLayout();
 			this.tabPage2.SuspendLayout();
+			this.splitContainer3.Panel1.SuspendLayout();
+			this.splitContainer3.Panel2.SuspendLayout();
+			this.splitContainer3.SuspendLayout();
 			this.SuspendLayout();
 			this.SuspendLayout();
 			// 
 			// 
 			// menuStrip1
 			// menuStrip1
@@ -203,6 +216,7 @@
 			this.stepOverToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F10;
 			this.stepOverToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F10;
 			this.stepOverToolStripMenuItem.Size = new System.Drawing.Size(190, 22);
 			this.stepOverToolStripMenuItem.Size = new System.Drawing.Size(190, 22);
 			this.stepOverToolStripMenuItem.Text = "Step-Over";
 			this.stepOverToolStripMenuItem.Text = "Step-Over";
+			this.stepOverToolStripMenuItem.Click += new System.EventHandler(this.stepOverToolStripMenuItem_Click);
 			// 
 			// 
 			// stepInToolStripMenuItem
 			// stepInToolStripMenuItem
 			// 
 			// 
@@ -238,6 +252,7 @@
 			this.gOToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F5;
 			this.gOToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F5;
 			this.gOToolStripMenuItem.Size = new System.Drawing.Size(190, 22);
 			this.gOToolStripMenuItem.Size = new System.Drawing.Size(190, 22);
 			this.gOToolStripMenuItem.Text = "GO";
 			this.gOToolStripMenuItem.Text = "GO";
+			this.gOToolStripMenuItem.Click += new System.EventHandler(this.gOToolStripMenuItem_Click);
 			// 
 			// 
 			// helpToolStripMenuItem
 			// helpToolStripMenuItem
 			// 
 			// 
@@ -256,13 +271,13 @@
 			// toolStrip1
 			// toolStrip1
 			// 
 			// 
 			this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
 			this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
-            this.toolStripButton1,
+            this.btnOpenFile,
             this.toolStripButton2,
             this.toolStripButton2,
             this.toolStripSeparator1,
             this.toolStripSeparator1,
             this.toolStripButton3,
             this.toolStripButton3,
             this.toolStripSeparator2,
             this.toolStripSeparator2,
-            this.toolStripButton6,
-            this.toolStripButton4,
+            this.toolGO,
+            this.toolStepOver,
             this.toolStepIN,
             this.toolStepIN,
             this.toolStripSeparator3,
             this.toolStripSeparator3,
             this.toolStripButton5});
             this.toolStripButton5});
@@ -272,14 +287,15 @@
 			this.toolStrip1.TabIndex = 1;
 			this.toolStrip1.TabIndex = 1;
 			this.toolStrip1.Text = "toolStrip1";
 			this.toolStrip1.Text = "toolStrip1";
 			// 
 			// 
-			// toolStripButton1
+			// btnOpenFile
 			// 
 			// 
-			this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
-			this.toolStripButton1.Image = global::MoonSharp.Debugger.Properties.Resources.Open_6529;
-			this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
-			this.toolStripButton1.Name = "toolStripButton1";
-			this.toolStripButton1.Size = new System.Drawing.Size(23, 22);
-			this.toolStripButton1.Text = "toolStripButton1";
+			this.btnOpenFile.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
+			this.btnOpenFile.Image = global::MoonSharp.Debugger.Properties.Resources.Open_6529;
+			this.btnOpenFile.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.btnOpenFile.Name = "btnOpenFile";
+			this.btnOpenFile.Size = new System.Drawing.Size(23, 22);
+			this.btnOpenFile.Text = "Open File";
+			this.btnOpenFile.Click += new System.EventHandler(this.btnOpenFile_Click);
 			// 
 			// 
 			// toolStripButton2
 			// toolStripButton2
 			// 
 			// 
@@ -310,23 +326,25 @@
 			this.toolStripSeparator2.Name = "toolStripSeparator2";
 			this.toolStripSeparator2.Name = "toolStripSeparator2";
 			this.toolStripSeparator2.Size = new System.Drawing.Size(6, 25);
 			this.toolStripSeparator2.Size = new System.Drawing.Size(6, 25);
 			// 
 			// 
-			// toolStripButton6
+			// toolGO
 			// 
 			// 
-			this.toolStripButton6.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
-			this.toolStripButton6.Image = global::MoonSharp.Debugger.Properties.Resources.startwithoutdebugging_6556;
-			this.toolStripButton6.ImageTransparentColor = System.Drawing.Color.Magenta;
-			this.toolStripButton6.Name = "toolStripButton6";
-			this.toolStripButton6.Size = new System.Drawing.Size(23, 22);
-			this.toolStripButton6.Text = "toolStripButton6";
+			this.toolGO.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
+			this.toolGO.Image = global::MoonSharp.Debugger.Properties.Resources.startwithoutdebugging_6556;
+			this.toolGO.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.toolGO.Name = "toolGO";
+			this.toolGO.Size = new System.Drawing.Size(23, 22);
+			this.toolGO.Text = "GO";
+			this.toolGO.Click += new System.EventHandler(this.toolGO_Click);
 			// 
 			// 
-			// toolStripButton4
+			// toolStepOver
 			// 
 			// 
-			this.toolStripButton4.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
-			this.toolStripButton4.Image = global::MoonSharp.Debugger.Properties.Resources.StepOver_6328;
-			this.toolStripButton4.ImageTransparentColor = System.Drawing.Color.Magenta;
-			this.toolStripButton4.Name = "toolStripButton4";
-			this.toolStripButton4.Size = new System.Drawing.Size(23, 22);
-			this.toolStripButton4.Text = "toolStripButton4";
+			this.toolStepOver.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
+			this.toolStepOver.Image = global::MoonSharp.Debugger.Properties.Resources.StepOver_6328;
+			this.toolStepOver.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.toolStepOver.Name = "toolStepOver";
+			this.toolStepOver.Size = new System.Drawing.Size(23, 22);
+			this.toolStepOver.Text = "Step-Over";
+			this.toolStepOver.Click += new System.EventHandler(this.toolStepOver_Click);
 			// 
 			// 
 			// toolStepIN
 			// toolStepIN
 			// 
 			// 
@@ -372,7 +390,7 @@
 			// 
 			// 
 			// splitContainer1.Panel2
 			// splitContainer1.Panel2
 			// 
 			// 
-			this.splitContainer1.Panel2.Controls.Add(this.codeView);
+			this.splitContainer1.Panel2.Controls.Add(this.splitContainer3);
 			this.splitContainer1.Size = new System.Drawing.Size(1094, 663);
 			this.splitContainer1.Size = new System.Drawing.Size(1094, 663);
 			this.splitContainer1.SplitterDistance = 364;
 			this.splitContainer1.SplitterDistance = 364;
 			this.splitContainer1.TabIndex = 3;
 			this.splitContainer1.TabIndex = 3;
@@ -438,6 +456,7 @@
 			this.lvWatches.TabIndex = 4;
 			this.lvWatches.TabIndex = 4;
 			this.lvWatches.UseCompatibleStateImageBehavior = false;
 			this.lvWatches.UseCompatibleStateImageBehavior = false;
 			this.lvWatches.View = System.Windows.Forms.View.Details;
 			this.lvWatches.View = System.Windows.Forms.View.Details;
+			this.lvWatches.SelectedIndexChanged += new System.EventHandler(this.lvWatches_SelectedIndexChanged);
 			// 
 			// 
 			// columnHeader1
 			// columnHeader1
 			// 
 			// 
@@ -465,7 +484,8 @@
             this.btnAddWatch,
             this.btnAddWatch,
             this.btnRemoveWatch,
             this.btnRemoveWatch,
             this.toolStripSeparator4,
             this.toolStripSeparator4,
-            this.btnViewWatch});
+            this.btnViewWatch,
+            this.toolStripButton1});
 			this.toolStrip2.Location = new System.Drawing.Point(3, 3);
 			this.toolStrip2.Location = new System.Drawing.Point(3, 3);
 			this.toolStrip2.Name = "toolStrip2";
 			this.toolStrip2.Name = "toolStrip2";
 			this.toolStrip2.Size = new System.Drawing.Size(350, 25);
 			this.toolStrip2.Size = new System.Drawing.Size(350, 25);
@@ -502,6 +522,16 @@
 			this.btnViewWatch.Name = "btnViewWatch";
 			this.btnViewWatch.Name = "btnViewWatch";
 			this.btnViewWatch.Size = new System.Drawing.Size(52, 22);
 			this.btnViewWatch.Size = new System.Drawing.Size(52, 22);
 			this.btnViewWatch.Text = "View";
 			this.btnViewWatch.Text = "View";
+			this.btnViewWatch.Click += new System.EventHandler(this.btnViewWatch_Click);
+			// 
+			// toolStripButton1
+			// 
+			this.toolStripButton1.Image = global::MoonSharp.Debugger.Properties.Resources.GoToDeclaration_5576;
+			this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.toolStripButton1.Name = "toolStripButton1";
+			this.toolStripButton1.Size = new System.Drawing.Size(87, 22);
+			this.toolStripButton1.Text = "Go to Code";
+			this.toolStripButton1.ToolTipText = "Go to Code";
 			// 
 			// 
 			// label3
 			// label3
 			// 
 			// 
@@ -516,6 +546,7 @@
 			// tabPage4
 			// tabPage4
 			// 
 			// 
 			this.tabPage4.Controls.Add(this.lvVStack);
 			this.tabPage4.Controls.Add(this.lvVStack);
+			this.tabPage4.Controls.Add(this.toolStrip3);
 			this.tabPage4.Controls.Add(this.label2);
 			this.tabPage4.Controls.Add(this.label2);
 			this.tabPage4.ImageIndex = 1;
 			this.tabPage4.ImageIndex = 1;
 			this.tabPage4.Location = new System.Drawing.Point(4, 23);
 			this.tabPage4.Location = new System.Drawing.Point(4, 23);
@@ -526,6 +557,67 @@
 			this.tabPage4.Text = "V-Stack";
 			this.tabPage4.Text = "V-Stack";
 			this.tabPage4.UseVisualStyleBackColor = true;
 			this.tabPage4.UseVisualStyleBackColor = true;
 			// 
 			// 
+			// lvVStack
+			// 
+			this.lvVStack.BackColor = System.Drawing.SystemColors.Window;
+			this.lvVStack.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
+            this.columnHeader5,
+            this.columnHeader6,
+            this.columnHeader7});
+			this.lvVStack.Dock = System.Windows.Forms.DockStyle.Fill;
+			this.lvVStack.FullRowSelect = true;
+			this.lvVStack.GridLines = true;
+			this.lvVStack.Location = new System.Drawing.Point(3, 28);
+			this.lvVStack.Name = "lvVStack";
+			this.lvVStack.Size = new System.Drawing.Size(350, 249);
+			this.lvVStack.TabIndex = 7;
+			this.lvVStack.UseCompatibleStateImageBehavior = false;
+			this.lvVStack.View = System.Windows.Forms.View.Details;
+			// 
+			// columnHeader5
+			// 
+			this.columnHeader5.Text = "Stack ofs";
+			this.columnHeader5.Width = 72;
+			// 
+			// columnHeader6
+			// 
+			this.columnHeader6.Text = "Type";
+			this.columnHeader6.Width = 94;
+			// 
+			// columnHeader7
+			// 
+			this.columnHeader7.Text = "Value";
+			this.columnHeader7.Width = 157;
+			// 
+			// toolStrip3
+			// 
+			this.toolStrip3.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+            this.btnViewVStk,
+            this.toolGoToCodeVStack});
+			this.toolStrip3.Location = new System.Drawing.Point(3, 3);
+			this.toolStrip3.Name = "toolStrip3";
+			this.toolStrip3.Size = new System.Drawing.Size(350, 25);
+			this.toolStrip3.TabIndex = 6;
+			this.toolStrip3.Text = "toolStrip3";
+			// 
+			// btnViewVStk
+			// 
+			this.btnViewVStk.Image = global::MoonSharp.Debugger.Properties.Resources.FindSymbol_6263;
+			this.btnViewVStk.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.btnViewVStk.Name = "btnViewVStk";
+			this.btnViewVStk.Size = new System.Drawing.Size(52, 22);
+			this.btnViewVStk.Text = "View";
+			this.btnViewVStk.Click += new System.EventHandler(this.btnViewVStk_Click);
+			// 
+			// toolGoToCodeVStack
+			// 
+			this.toolGoToCodeVStack.Image = global::MoonSharp.Debugger.Properties.Resources.GoToDeclaration_5576;
+			this.toolGoToCodeVStack.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.toolGoToCodeVStack.Name = "toolGoToCodeVStack";
+			this.toolGoToCodeVStack.Size = new System.Drawing.Size(87, 22);
+			this.toolGoToCodeVStack.Text = "Go to Code";
+			this.toolGoToCodeVStack.ToolTipText = "Go to Code";
+			// 
 			// label2
 			// label2
 			// 
 			// 
 			this.label2.Dock = System.Windows.Forms.DockStyle.Fill;
 			this.label2.Dock = System.Windows.Forms.DockStyle.Fill;
@@ -560,6 +652,7 @@
 			// tabPage1
 			// tabPage1
 			// 
 			// 
 			this.tabPage1.Controls.Add(this.lvCallStack);
 			this.tabPage1.Controls.Add(this.lvCallStack);
+			this.tabPage1.Controls.Add(this.toolStrip4);
 			this.tabPage1.ImageIndex = 0;
 			this.tabPage1.ImageIndex = 0;
 			this.tabPage1.Location = new System.Drawing.Point(4, 23);
 			this.tabPage1.Location = new System.Drawing.Point(4, 23);
 			this.tabPage1.Name = "tabPage1";
 			this.tabPage1.Name = "tabPage1";
@@ -580,10 +673,10 @@
 			this.lvCallStack.Dock = System.Windows.Forms.DockStyle.Fill;
 			this.lvCallStack.Dock = System.Windows.Forms.DockStyle.Fill;
 			this.lvCallStack.FullRowSelect = true;
 			this.lvCallStack.FullRowSelect = true;
 			this.lvCallStack.GridLines = true;
 			this.lvCallStack.GridLines = true;
-			this.lvCallStack.Location = new System.Drawing.Point(3, 3);
+			this.lvCallStack.Location = new System.Drawing.Point(3, 28);
 			this.lvCallStack.Name = "lvCallStack";
 			this.lvCallStack.Name = "lvCallStack";
-			this.lvCallStack.Size = new System.Drawing.Size(350, 319);
-			this.lvCallStack.TabIndex = 0;
+			this.lvCallStack.Size = new System.Drawing.Size(350, 294);
+			this.lvCallStack.TabIndex = 8;
 			this.lvCallStack.UseCompatibleStateImageBehavior = false;
 			this.lvCallStack.UseCompatibleStateImageBehavior = false;
 			this.lvCallStack.View = System.Windows.Forms.View.Details;
 			this.lvCallStack.View = System.Windows.Forms.View.Details;
 			// 
 			// 
@@ -607,6 +700,25 @@
 			this.colBP.Text = "Base Ptr";
 			this.colBP.Text = "Base Ptr";
 			this.colBP.Width = 72;
 			this.colBP.Width = 72;
 			// 
 			// 
+			// toolStrip4
+			// 
+			this.toolStrip4.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+            this.toolGoToCodeXStack});
+			this.toolStrip4.Location = new System.Drawing.Point(3, 3);
+			this.toolStrip4.Name = "toolStrip4";
+			this.toolStrip4.Size = new System.Drawing.Size(350, 25);
+			this.toolStrip4.TabIndex = 7;
+			this.toolStrip4.Text = "toolStrip4";
+			// 
+			// toolGoToCodeXStack
+			// 
+			this.toolGoToCodeXStack.Image = global::MoonSharp.Debugger.Properties.Resources.GoToDeclaration_5576;
+			this.toolGoToCodeXStack.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.toolGoToCodeXStack.Name = "toolGoToCodeXStack";
+			this.toolGoToCodeXStack.Size = new System.Drawing.Size(87, 22);
+			this.toolGoToCodeXStack.Text = "Go to Code";
+			this.toolGoToCodeXStack.ToolTipText = "Go to Code";
+			// 
 			// tabPage2
 			// tabPage2
 			// 
 			// 
 			this.tabPage2.Controls.Add(this.label1);
 			this.tabPage2.Controls.Add(this.label1);
@@ -629,6 +741,24 @@
 			this.label1.Text = "Not Implemented Yet";
 			this.label1.Text = "Not Implemented Yet";
 			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
 			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
 			// 
 			// 
+			// splitContainer3
+			// 
+			this.splitContainer3.Dock = System.Windows.Forms.DockStyle.Fill;
+			this.splitContainer3.Location = new System.Drawing.Point(0, 0);
+			this.splitContainer3.Name = "splitContainer3";
+			this.splitContainer3.Orientation = System.Windows.Forms.Orientation.Horizontal;
+			// 
+			// splitContainer3.Panel1
+			// 
+			this.splitContainer3.Panel1.Controls.Add(this.codeView);
+			// 
+			// splitContainer3.Panel2
+			// 
+			this.splitContainer3.Panel2.Controls.Add(this.txtOutput);
+			this.splitContainer3.Size = new System.Drawing.Size(726, 663);
+			this.splitContainer3.SplitterDistance = 446;
+			this.splitContainer3.TabIndex = 0;
+			// 
 			// codeView
 			// codeView
 			// 
 			// 
 			this.codeView.ActiveLine = -1;
 			this.codeView.ActiveLine = -1;
@@ -640,41 +770,21 @@
 			this.codeView.Location = new System.Drawing.Point(0, 0);
 			this.codeView.Location = new System.Drawing.Point(0, 0);
 			this.codeView.Margin = new System.Windows.Forms.Padding(4);
 			this.codeView.Margin = new System.Windows.Forms.Padding(4);
 			this.codeView.Name = "codeView";
 			this.codeView.Name = "codeView";
-			this.codeView.Size = new System.Drawing.Size(726, 663);
+			this.codeView.Size = new System.Drawing.Size(726, 446);
 			this.codeView.SourceCode = null;
 			this.codeView.SourceCode = null;
-			this.codeView.TabIndex = 0;
-			// 
-			// lvVStack
-			// 
-			this.lvVStack.BackColor = System.Drawing.SystemColors.Window;
-			this.lvVStack.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
-            this.columnHeader5,
-            this.columnHeader6,
-            this.columnHeader7});
-			this.lvVStack.Dock = System.Windows.Forms.DockStyle.Fill;
-			this.lvVStack.FullRowSelect = true;
-			this.lvVStack.GridLines = true;
-			this.lvVStack.Location = new System.Drawing.Point(3, 3);
-			this.lvVStack.Name = "lvVStack";
-			this.lvVStack.Size = new System.Drawing.Size(350, 274);
-			this.lvVStack.TabIndex = 5;
-			this.lvVStack.UseCompatibleStateImageBehavior = false;
-			this.lvVStack.View = System.Windows.Forms.View.Details;
+			this.codeView.TabIndex = 1;
 			// 
 			// 
-			// columnHeader5
-			// 
-			this.columnHeader5.Text = "Stack ofs";
-			this.columnHeader5.Width = 72;
+			// txtOutput
 			// 
 			// 
-			// columnHeader6
-			// 
-			this.columnHeader6.Text = "Type";
-			this.columnHeader6.Width = 94;
-			// 
-			// columnHeader7
-			// 
-			this.columnHeader7.Text = "Value";
-			this.columnHeader7.Width = 157;
+			this.txtOutput.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
+			this.txtOutput.Dock = System.Windows.Forms.DockStyle.Fill;
+			this.txtOutput.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))));
+			this.txtOutput.Location = new System.Drawing.Point(0, 0);
+			this.txtOutput.Multiline = true;
+			this.txtOutput.Name = "txtOutput";
+			this.txtOutput.ReadOnly = true;
+			this.txtOutput.Size = new System.Drawing.Size(726, 213);
+			this.txtOutput.TabIndex = 0;
 			// 
 			// 
 			// MainForm
 			// MainForm
 			// 
 			// 
@@ -705,9 +815,19 @@
 			this.toolStrip2.ResumeLayout(false);
 			this.toolStrip2.ResumeLayout(false);
 			this.toolStrip2.PerformLayout();
 			this.toolStrip2.PerformLayout();
 			this.tabPage4.ResumeLayout(false);
 			this.tabPage4.ResumeLayout(false);
+			this.tabPage4.PerformLayout();
+			this.toolStrip3.ResumeLayout(false);
+			this.toolStrip3.PerformLayout();
 			this.tabControl1.ResumeLayout(false);
 			this.tabControl1.ResumeLayout(false);
 			this.tabPage1.ResumeLayout(false);
 			this.tabPage1.ResumeLayout(false);
+			this.tabPage1.PerformLayout();
+			this.toolStrip4.ResumeLayout(false);
+			this.toolStrip4.PerformLayout();
 			this.tabPage2.ResumeLayout(false);
 			this.tabPage2.ResumeLayout(false);
+			this.splitContainer3.Panel1.ResumeLayout(false);
+			this.splitContainer3.Panel2.ResumeLayout(false);
+			this.splitContainer3.Panel2.PerformLayout();
+			this.splitContainer3.ResumeLayout(false);
 			this.ResumeLayout(false);
 			this.ResumeLayout(false);
 			this.PerformLayout();
 			this.PerformLayout();
 
 
@@ -737,7 +857,6 @@
 		private System.Windows.Forms.ToolStripMenuItem scriptCodeToolStripMenuItem;
 		private System.Windows.Forms.ToolStripMenuItem scriptCodeToolStripMenuItem;
 		private System.Windows.Forms.ToolStripMenuItem bytecodeToolStripMenuItem;
 		private System.Windows.Forms.ToolStripMenuItem bytecodeToolStripMenuItem;
 		private System.Windows.Forms.ToolStripButton toolStepIN;
 		private System.Windows.Forms.ToolStripButton toolStepIN;
-		private SourceCodeDebugControl codeView;
 		private System.Windows.Forms.TabControl tabControl2;
 		private System.Windows.Forms.TabControl tabControl2;
 		private System.Windows.Forms.TabPage tabPage3;
 		private System.Windows.Forms.TabPage tabPage3;
 		private System.Windows.Forms.Label label3;
 		private System.Windows.Forms.Label label3;
@@ -747,23 +866,18 @@
 		private System.Windows.Forms.TabPage tabPage1;
 		private System.Windows.Forms.TabPage tabPage1;
 		private System.Windows.Forms.TabPage tabPage2;
 		private System.Windows.Forms.TabPage tabPage2;
 		private System.Windows.Forms.Label label1;
 		private System.Windows.Forms.Label label1;
-		private System.Windows.Forms.ListView lvCallStack;
-		private System.Windows.Forms.ColumnHeader colAddress;
-		private System.Windows.Forms.ColumnHeader colName;
-		private System.Windows.Forms.ColumnHeader colBP;
-		private System.Windows.Forms.ColumnHeader colReturn;
 		private System.Windows.Forms.ImageList imageList1;
 		private System.Windows.Forms.ImageList imageList1;
-		private System.Windows.Forms.ToolStripButton toolStripButton1;
+		private System.Windows.Forms.ToolStripButton btnOpenFile;
 		private System.Windows.Forms.ToolStripButton toolStripButton2;
 		private System.Windows.Forms.ToolStripButton toolStripButton2;
 		private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
 		private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
 		private System.Windows.Forms.ToolStripButton toolStripButton3;
 		private System.Windows.Forms.ToolStripButton toolStripButton3;
 		private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
 		private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
-		private System.Windows.Forms.ToolStripButton toolStripButton6;
-		private System.Windows.Forms.ToolStripButton toolStripButton4;
+		private System.Windows.Forms.ToolStripButton toolGO;
+		private System.Windows.Forms.ToolStripButton toolStepOver;
 		private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
 		private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
 		private System.Windows.Forms.ToolStripButton toolStripButton5;
 		private System.Windows.Forms.ToolStripButton toolStripButton5;
 		private System.Windows.Forms.ToolStripMenuItem connectToolStripMenuItem;
 		private System.Windows.Forms.ToolStripMenuItem connectToolStripMenuItem;
-		private System.Windows.Forms.ListView lvWatches;
+		private DoubleBufferedListView lvWatches;
 		private System.Windows.Forms.ColumnHeader columnHeader1;
 		private System.Windows.Forms.ColumnHeader columnHeader1;
 		private System.Windows.Forms.ColumnHeader columnHeader2;
 		private System.Windows.Forms.ColumnHeader columnHeader2;
 		private System.Windows.Forms.ColumnHeader columnHeader3;
 		private System.Windows.Forms.ColumnHeader columnHeader3;
@@ -773,10 +887,24 @@
 		private System.Windows.Forms.ToolStripButton btnRemoveWatch;
 		private System.Windows.Forms.ToolStripButton btnRemoveWatch;
 		private System.Windows.Forms.ToolStripButton btnViewWatch;
 		private System.Windows.Forms.ToolStripButton btnViewWatch;
 		private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
 		private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
-		private System.Windows.Forms.ListView lvVStack;
+		private System.Windows.Forms.SplitContainer splitContainer3;
+		private SourceCodeDebugControl codeView;
+		private System.Windows.Forms.TextBox txtOutput;
+		private DoubleBufferedListView lvVStack;
 		private System.Windows.Forms.ColumnHeader columnHeader5;
 		private System.Windows.Forms.ColumnHeader columnHeader5;
 		private System.Windows.Forms.ColumnHeader columnHeader6;
 		private System.Windows.Forms.ColumnHeader columnHeader6;
 		private System.Windows.Forms.ColumnHeader columnHeader7;
 		private System.Windows.Forms.ColumnHeader columnHeader7;
+		private System.Windows.Forms.ToolStrip toolStrip3;
+		private System.Windows.Forms.ToolStripButton btnViewVStk;
+		private System.Windows.Forms.ToolStripButton toolStripButton1;
+		private System.Windows.Forms.ToolStripButton toolGoToCodeVStack;
+		private DoubleBufferedListView lvCallStack;
+		private System.Windows.Forms.ColumnHeader colAddress;
+		private System.Windows.Forms.ColumnHeader colName;
+		private System.Windows.Forms.ColumnHeader colReturn;
+		private System.Windows.Forms.ColumnHeader colBP;
+		private System.Windows.Forms.ToolStrip toolStrip4;
+		private System.Windows.Forms.ToolStripButton toolGoToCodeXStack;
 
 
 
 
 	}
 	}

+ 122 - 35
src/MoonSharp.Debugger/MainForm.cs

@@ -28,6 +28,7 @@ namespace MoonSharp.Debugger
 		private void MainForm_Load(object sender, EventArgs e)
 		private void MainForm_Load(object sender, EventArgs e)
 		{
 		{
 			m_Ctx = SynchronizationContext.Current;
 			m_Ctx = SynchronizationContext.Current;
+			MoonSharpInterpreter.WarmUp();
 		}
 		}
 
 
 		private void openToolStripMenuItem_Click(object sender, EventArgs e)
 		private void openToolStripMenuItem_Click(object sender, EventArgs e)
@@ -47,6 +48,43 @@ namespace MoonSharp.Debugger
 		Script m_Script;
 		Script m_Script;
 		SynchronizationContext m_Ctx;
 		SynchronizationContext m_Ctx;
 
 
+		RValue Print(RValue[] values)
+		{
+			string prn = string.Join(" ", values.Select(v => v.AsString()).ToArray());
+			Console_WriteLine("{0}", prn);
+			return RValue.Nil;
+		}
+
+		RValue Assert(RValue[] values)
+		{
+			if (!values[0].TestAsBoolean())
+				Console_WriteLine("ASSERT FAILED!");
+
+			return RValue.Nil;
+		}
+
+		RValue XAssert(RValue[] values)
+		{
+			if (!values[1].TestAsBoolean())
+				Console_WriteLine("ASSERT FAILED! : {0}", values[0].ToString());
+
+			return RValue.Nil;
+		}
+
+		private void Console_WriteLine(string fmt, params object[] args)
+		{
+			fmt = string.Format(fmt, args);
+
+			m_Ctx.Post(str =>
+			{
+				txtOutput.Text = txtOutput.Text + fmt.ToString() + "\n";
+				txtOutput.SelectionStart = txtOutput.Text.Length - 1;
+				txtOutput.SelectionLength = 0;
+				txtOutput.ScrollToCaret();
+			}, fmt);
+		}
+
+
 		private void DebugScript(string filename)
 		private void DebugScript(string filename)
 		{
 		{
 			m_Script = MoonSharpInterpreter.LoadFromFile(filename);
 			m_Script = MoonSharpInterpreter.LoadFromFile(filename);
@@ -87,8 +125,6 @@ namespace MoonSharp.Debugger
 			DebuggerAction action = m_NextAction;
 			DebuggerAction action = m_NextAction;
 			m_NextAction = null;
 			m_NextAction = null;
 
 
-			Debug.WriteLine("Sending " + action.ToString());
-
 			m_WaitBack.Set();
 			m_WaitBack.Set();
 
 
 			return action;
 			return action;
@@ -106,12 +142,19 @@ namespace MoonSharp.Debugger
 
 
 		void DebugMain()
 		void DebugMain()
 		{
 		{
-			m_Script.Execute(null);
-		}
+			Table T = new Table();
+			T["print"] = new RValue(new CallbackFunction(Print));
+			T["assert"] = new RValue(new CallbackFunction(Assert));
+			T["xassert"] = new RValue(new CallbackFunction(XAssert));
 
 
-		private void toolStripButton1_Click(object sender, EventArgs e)
-		{
-			StepIN();
+			try
+			{
+				m_Script.Execute(T);
+			}
+			catch (Exception ex)
+			{
+				Console_WriteLine("Guest raised unhandled CLR exception: {0}\n{1}\n", ex.GetType(), ex.ToString());
+			}
 		}
 		}
 
 
 		private void StepIN()
 		private void StepIN()
@@ -119,6 +162,16 @@ namespace MoonSharp.Debugger
 			DebugAction(new DebuggerAction() { Action = DebuggerAction.ActionType.StepIn });
 			DebugAction(new DebuggerAction() { Action = DebuggerAction.ActionType.StepIn });
 		}
 		}
 
 
+		private void StepOVER()
+		{
+			DebugAction(new DebuggerAction() { Action = DebuggerAction.ActionType.StepOver });
+		}
+
+		private void GO()
+		{
+			DebugAction(new DebuggerAction() { Action = DebuggerAction.ActionType.Run });
+		}
+
 
 
 		void IDebugger.Update(WatchType watchType, List<WatchItem> items)
 		void IDebugger.Update(WatchType watchType, List<WatchItem> items)
 		{
 		{
@@ -138,12 +191,11 @@ namespace MoonSharp.Debugger
 
 
 			foreach (var item in items)
 			foreach (var item in items)
 			{
 			{
-				var lvi = BuildListViewItem(
+				lvVStack.Add(
 					item.Address.ToString("X4"),
 					item.Address.ToString("X4"),
 					(item.Value != null) ? item.Value.Type.ToString() : "(undefined)",
 					(item.Value != null) ? item.Value.Type.ToString() : "(undefined)",
 					(item.Value != null) ? item.Value.ToString() : "(undefined)"
 					(item.Value != null) ? item.Value.ToString() : "(undefined)"
-					);
-				lvVStack.Items.Add(lvi);
+					).Tag = item.Value;
 			}
 			}
 
 
 			lvVStack.EndUpdate();
 			lvVStack.EndUpdate();
@@ -160,13 +212,12 @@ namespace MoonSharp.Debugger
 
 
 			foreach (var item in items)
 			foreach (var item in items)
 			{
 			{
-				var lvi = BuildListViewItem(
+				lvWatches.Add(
 					item.Name ?? "(???)",
 					item.Name ?? "(???)",
 					(item.Value != null) ? item.Value.Type.ToLuaTypeString() : "(undefined)",
 					(item.Value != null) ? item.Value.Type.ToLuaTypeString() : "(undefined)",
 					(item.Value != null) ? item.Value.ToString() : "(undefined)",
 					(item.Value != null) ? item.Value.ToString() : "(undefined)",
 					(item.LValue != null) ? item.LValue.ToString() : "(undefined)"
 					(item.LValue != null) ? item.LValue.ToString() : "(undefined)"
-					);
-				lvWatches.Items.Add(lvi);
+					).Tag = item.Value;
 			}
 			}
 
 
 			lvWatches.EndUpdate();
 			lvWatches.EndUpdate();
@@ -181,34 +232,20 @@ namespace MoonSharp.Debugger
 			lvCallStack.Items.Clear();
 			lvCallStack.Items.Clear();
 			foreach (var item in items)
 			foreach (var item in items)
 			{
 			{
-				var lvi = BuildListViewItem(
+				lvCallStack.Add(
 					item.Address.ToString("X8"),
 					item.Address.ToString("X8"),
 					item.Name ?? "(???)",
 					item.Name ?? "(???)",
 					item.RetAddress.ToString("X8"),
 					item.RetAddress.ToString("X8"),
 					item.BasePtr.ToString("X8")
 					item.BasePtr.ToString("X8")
-					);
-				lvCallStack.Items.Add(lvi);
+					).Tag = item.Address;
 			}
 			}
 
 
-			lvCallStack.Items.Add(BuildListViewItem("---", "(main)", "---", "---"));
+			lvCallStack.Add("---", "(main)", "---", "---");
 
 
 			lvCallStack.EndUpdate();
 			lvCallStack.EndUpdate();
 		}
 		}
 
 
-		private ListViewItem BuildListViewItem(params string[] texts)
-		{
-			ListViewItem lvi = new ListViewItem();
-			lvi.Text = texts[0];
-
-			for (int i = 1; i < texts.Length; i++)
-			{
-				ListViewItem.ListViewSubItem lvsi = new ListViewItem.ListViewSubItem();
-				lvsi.Text = texts[i];
-				lvi.SubItems.Add(lvsi);
-			}
 
 
-			return lvi;
-		}
 
 
 
 
 		List<string> IDebugger.GetWatchItems()
 		List<string> IDebugger.GetWatchItems()
@@ -216,11 +253,6 @@ namespace MoonSharp.Debugger
 			return m_Watches;
 			return m_Watches;
 		}
 		}
 
 
-		private void stepInToolStripMenuItem_Click(object sender, EventArgs e)
-		{
-			StepIN();
-		}
-
 		private void btnAddWatch_Click(object sender, EventArgs e)
 		private void btnAddWatch_Click(object sender, EventArgs e)
 		{
 		{
 			string text = WatchInputDialog.GetNewWatchName();
 			string text = WatchInputDialog.GetNewWatchName();
@@ -241,5 +273,60 @@ namespace MoonSharp.Debugger
 			if (i != 0)
 			if (i != 0)
 				DebugAction(new DebuggerAction() { Action = DebuggerAction.ActionType.Refresh });
 				DebugAction(new DebuggerAction() { Action = DebuggerAction.ActionType.Refresh });
 		}
 		}
+		private void stepInToolStripMenuItem_Click(object sender, EventArgs e)
+		{
+			StepIN();
+		}
+
+		private void btnOpenFile_Click(object sender, EventArgs e)
+		{
+			openToolStripMenuItem.PerformClick();
+		}
+
+		private void stepOverToolStripMenuItem_Click(object sender, EventArgs e)
+		{
+			StepOVER();
+		}
+
+		private void toolGO_Click(object sender, EventArgs e)
+		{
+			GO();
+		}
+
+		private void gOToolStripMenuItem_Click(object sender, EventArgs e)
+		{
+			GO();
+		}
+		private void toolStripButton1_Click(object sender, EventArgs e)
+		{
+			StepIN();
+		}
+
+		private void toolStepOver_Click(object sender, EventArgs e)
+		{
+			StepOVER();
+		}
+
+		private void btnViewVStk_Click(object sender, EventArgs e)
+		{
+			ValueBrowser.StartBrowse(lvVStack.SelectedItems.OfType<ListViewItem>().Select(lvi => lvi.Tag).Cast<RValue>().FirstOrDefault());
+		}
+
+		private void lvVStack_MouseDoubleClick(object sender, MouseEventArgs e)
+		{
+
+		}
+
+		private void btnViewWatch_Click(object sender, EventArgs e)
+		{
+			ValueBrowser.StartBrowse(lvWatches.SelectedItems.OfType<ListViewItem>().Select(lvi => lvi.Tag).Cast<RValue>().FirstOrDefault());
+		}
+
+		private void lvWatches_SelectedIndexChanged(object sender, EventArgs e)
+		{
+			ValueBrowser.StartBrowse(lvWatches.SelectedItems.OfType<ListViewItem>().Select(lvi => lvi.Tag).Cast<RValue>().FirstOrDefault());
+		}
+
+
 	}
 	}
 }
 }

+ 50 - 44
src/MoonSharp.Debugger/MainForm.resx

@@ -129,6 +129,9 @@
   <metadata name="toolStrip2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
   <metadata name="toolStrip2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>463, 17</value>
     <value>463, 17</value>
   </metadata>
   </metadata>
+  <metadata name="toolStrip3.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>568, 17</value>
+  </metadata>
   <metadata name="imageList1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
   <metadata name="imageList1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>353, 17</value>
     <value>353, 17</value>
   </metadata>
   </metadata>
@@ -137,57 +140,57 @@
         AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w
         AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w
         LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
         LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
         ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAACe
         ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAACe
-        DQAAAk1TRnQBSQFMAgEBBAEAAcgBAAHIAQABEAEAARABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAFA
+        DQAAAk1TRnQBSQFMAgEBBAEAARgBAQEYAQEBEAEAARABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAFA
         AwABIAMAAQEBAAEgBgABIP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8AIgADDAEQA1kBvwP2
         AwABIAMAAQEBAAEgBgABIP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8AIgADDAEQA1kBvwP2
         Af8D9gH/A1kBvwMqAUADKgFAAyoBQAMqAUADKgFAAyoBQAMqAUADKgFAAyoBQAMqAUADKgFAEAAD9gH/
         Af8D9gH/A1kBvwMqAUADKgFAAyoBQAMqAUADKgFAAyoBQAMqAUADKgFAAyoBQAMqAUADKgFAEAAD9gH/
-        A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/5AAA1kBvw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        A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8EAAP2Af8DKQH/AykB/wMp
-        Af8DKQH/AykB/wP2Af8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8D9gH/CAAD9gH/AykB/wP2Af8D9gH/
-        A/YB/wNiAe8DYgHvAyEBMAgAA/YB/wP2Af8D9gH/AykB/wP2Af8EAAP2Af8DKQH/AykB/wMpAf8DKQH/
-        AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/A/YB/wP2Af8DKQH/AykB/wMpAf8DKQH/
-        AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wP2Af8EAAP2Af8DKQH/AykB/wMp
-        Af8DKQH/AykB/wP2Af8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8D9gH/CAAD9gH/AykB/wMpAf8DKQH/
-        A/YB/wMhATADIQEwDAAD9gH/AykB/wMpAf8DKQH/A/YB/wQAA/YB/wMpAf8DKQH/AykB/wMpAf8DKQH/
-        AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8D9gH/A/YB/wMpAf8DKQH/AykB/wMpAf8DKQH/
-        AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/AykB/wMpAf8DKQH/A/YB/wQAA/YB/wP2Af8D9gH/A/YB/wP2
+        A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/CAAD9gH/Ax8B/wP2Af8DIQEwA2IB7wOG
+        Af8DQQH/A2IB7wMhATADIQEwA2IB7wNcAd8D9gH/Ax8B/wP2Af8EAAP2Af8DHwH/Ax8B/wMfAf8DHwH/
+        Ax8B/wMfAf8DHwH/Ax8B/wMfAf8DHwH/Ax8B/wMfAf8DHwH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/
+        A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/w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D9gH/A/YB/wP2Af8D9gH/
         A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/
         A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/A/YB/wP2Af8D9gH/
@@ -198,4 +201,7 @@
         AYMB4AGAAwAE/ws=
         AYMB4AGAAwAE/ws=
 </value>
 </value>
   </data>
   </data>
+  <metadata name="toolStrip4.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>673, 17</value>
+  </metadata>
 </root>
 </root>

+ 22 - 0
src/MoonSharp.Debugger/MoonSharp.Debugger.csproj

@@ -43,6 +43,10 @@
     <Reference Include="System.Xml" />
     <Reference Include="System.Xml" />
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
+    <Compile Include="DoubleBufferedListView.cs">
+      <SubType>Component</SubType>
+    </Compile>
+    <Compile Include="Ext_Methods.cs" />
     <Compile Include="MainForm.cs">
     <Compile Include="MainForm.cs">
       <SubType>Form</SubType>
       <SubType>Form</SubType>
     </Compile>
     </Compile>
@@ -57,6 +61,12 @@
     <Compile Include="SourceCodeDebugControl.Designer.cs">
     <Compile Include="SourceCodeDebugControl.Designer.cs">
       <DependentUpon>SourceCodeDebugControl.cs</DependentUpon>
       <DependentUpon>SourceCodeDebugControl.cs</DependentUpon>
     </Compile>
     </Compile>
+    <Compile Include="ValueBrowser.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="ValueBrowser.Designer.cs">
+      <DependentUpon>ValueBrowser.cs</DependentUpon>
+    </Compile>
     <Compile Include="WatchInputDialog.cs">
     <Compile Include="WatchInputDialog.cs">
       <SubType>Form</SubType>
       <SubType>Form</SubType>
     </Compile>
     </Compile>
@@ -79,6 +89,9 @@
     <EmbeddedResource Include="SourceCodeDebugControl.resx">
     <EmbeddedResource Include="SourceCodeDebugControl.resx">
       <DependentUpon>SourceCodeDebugControl.cs</DependentUpon>
       <DependentUpon>SourceCodeDebugControl.cs</DependentUpon>
     </EmbeddedResource>
     </EmbeddedResource>
+    <EmbeddedResource Include="ValueBrowser.resx">
+      <DependentUpon>ValueBrowser.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="WatchInputDialog.resx">
     <EmbeddedResource Include="WatchInputDialog.resx">
       <DependentUpon>WatchInputDialog.cs</DependentUpon>
       <DependentUpon>WatchInputDialog.cs</DependentUpon>
     </EmbeddedResource>
     </EmbeddedResource>
@@ -143,6 +156,15 @@
   <ItemGroup>
   <ItemGroup>
     <None Include="Resources\FindSymbol_6263.png" />
     <None Include="Resources\FindSymbol_6263.png" />
   </ItemGroup>
   </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\NavigateBackwards_6270.png" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\NavigateForward_6271.png" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\GoToDeclaration_5576.png" />
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
        Other similar extension points exist, see Microsoft.Common.targets.

+ 30 - 0
src/MoonSharp.Debugger/Properties/Resources.Designer.cs

@@ -130,6 +130,16 @@ namespace MoonSharp.Debugger.Properties {
             }
             }
         }
         }
         
         
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap GoToDeclaration_5576 {
+            get {
+                object obj = ResourceManager.GetObject("GoToDeclaration_5576", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
         /// <summary>
         /// <summary>
         ///   Looks up a localized resource of type System.Drawing.Bitmap.
         ///   Looks up a localized resource of type System.Drawing.Bitmap.
         /// </summary>
         /// </summary>
@@ -140,6 +150,26 @@ namespace MoonSharp.Debugger.Properties {
             }
             }
         }
         }
         
         
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap NavigateBackwards_6270 {
+            get {
+                object obj = ResourceManager.GetObject("NavigateBackwards_6270", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap NavigateForward_6271 {
+            get {
+                object obj = ResourceManager.GetObject("NavigateForward_6271", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
         /// <summary>
         /// <summary>
         ///   Looks up a localized resource of type System.Drawing.Bitmap.
         ///   Looks up a localized resource of type System.Drawing.Bitmap.
         /// </summary>
         /// </summary>

+ 11 - 2
src/MoonSharp.Debugger/Properties/Resources.resx

@@ -118,6 +118,9 @@
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
   </resheader>
   <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
   <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+  <data name="FindSymbol_6263" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\FindSymbol_6263.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
   <data name="StepIn_6326" type="System.Resources.ResXFileRef, System.Windows.Forms">
   <data name="StepIn_6326" type="System.Resources.ResXFileRef, System.Windows.Forms">
     <value>..\Resources\StepIn_6326.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
     <value>..\Resources\StepIn_6326.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
   </data>
   </data>
@@ -130,6 +133,9 @@
   <data name="StepOver_6328" type="System.Resources.ResXFileRef, System.Windows.Forms">
   <data name="StepOver_6328" type="System.Resources.ResXFileRef, System.Windows.Forms">
     <value>..\Resources\StepOver_6328.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
     <value>..\Resources\StepOver_6328.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
   </data>
   </data>
+  <data name="NavigateForward_6271" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\NavigateForward_6271.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
   <data name="Open_6529" type="System.Resources.ResXFileRef, System.Windows.Forms">
   <data name="Open_6529" type="System.Resources.ResXFileRef, System.Windows.Forms">
     <value>..\Resources\Open_6529.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
     <value>..\Resources\Open_6529.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
   </data>
   </data>
@@ -145,6 +151,9 @@
   <data name="AddConnection_477" type="System.Resources.ResXFileRef, System.Windows.Forms">
   <data name="AddConnection_477" type="System.Resources.ResXFileRef, System.Windows.Forms">
     <value>..\Resources\AddConnection_477.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
     <value>..\Resources\AddConnection_477.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
   </data>
   </data>
+  <data name="NavigateBackwards_6270" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\NavigateBackwards_6270.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
   <data name="startwithoutdebugging_6556" type="System.Resources.ResXFileRef, System.Windows.Forms">
   <data name="startwithoutdebugging_6556" type="System.Resources.ResXFileRef, System.Windows.Forms">
     <value>..\Resources\startwithoutdebugging_6556.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
     <value>..\Resources\startwithoutdebugging_6556.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
   </data>
   </data>
@@ -161,7 +170,7 @@
     <value>..\Resources\Breakall_6323.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
     <value>..\Resources\Breakall_6323.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
   </data>
   </data>
   <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
   <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
-  <data name="FindSymbol_6263" type="System.Resources.ResXFileRef, System.Windows.Forms">
-    <value>..\Resources\FindSymbol_6263.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  <data name="GoToDeclaration_5576" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\GoToDeclaration_5576.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
   </data>
   </data>
 </root>
 </root>

BIN
src/MoonSharp.Debugger/Resources/GoToDeclaration_5576.png


BIN
src/MoonSharp.Debugger/Resources/NavigateBackwards_6270.png


BIN
src/MoonSharp.Debugger/Resources/NavigateForward_6271.png


+ 7 - 2
src/MoonSharp.Debugger/SourceCodeDebugControl.cs

@@ -38,10 +38,15 @@ namespace MoonSharp.Debugger
 			if (line < m_Line)
 			if (line < m_Line)
 				m_Line = line;
 				m_Line = line;
 
 
-			if (line > m_Line + (this.Height / this.Font.Height))
+			if (line > m_Line + (this.GetHeight() / this.Font.Height))
 				m_Line = line;
 				m_Line = line;
 		}
 		}
 
 
+		private int GetHeight()
+		{
+			return this.Height - horizScroll.Height;
+		}
+
 		public int CursorLine
 		public int CursorLine
 		{
 		{
 			get { return m_CursorLine; }
 			get { return m_CursorLine; }
@@ -111,7 +116,7 @@ namespace MoonSharp.Debugger
 			int W = (int)e.Graphics.MeasureString("X", this.Font).Width;
 			int W = (int)e.Graphics.MeasureString("X", this.Font).Width;
 			int Y = 0;
 			int Y = 0;
 
 
-			for (int i = m_Line; i < m_SourceCode.Length && H < this.Height; i++, Y += H)
+			for (int i = m_Line; i < m_SourceCode.Length && H < this.GetHeight(); i++, Y += H)
 			{
 			{
 				if (m_ActiveLine == i)
 				if (m_ActiveLine == i)
 				{
 				{

+ 329 - 0
src/MoonSharp.Debugger/ValueBrowser.Designer.cs

@@ -0,0 +1,329 @@
+namespace MoonSharp.Debugger
+{
+	partial class ValueBrowser
+	{
+		/// <summary>
+		/// Required designer variable.
+		/// </summary>
+		private System.ComponentModel.IContainer components = null;
+
+		/// <summary>
+		/// Clean up any resources being used.
+		/// </summary>
+		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+		protected override void Dispose(bool disposing)
+		{
+			if (disposing && (components != null))
+			{
+				components.Dispose();
+			}
+			base.Dispose(disposing);
+		}
+
+		#region Windows Form Designer generated code
+
+		/// <summary>
+		/// Required method for Designer support - do not modify
+		/// the contents of this method with the code editor.
+		/// </summary>
+		private void InitializeComponent()
+		{
+			this.toolStrip1 = new System.Windows.Forms.ToolStrip();
+			this.toolBack = new System.Windows.Forms.ToolStripButton();
+			this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
+			this.toolDigData = new System.Windows.Forms.ToolStripButton();
+			this.splitContainer1 = new System.Windows.Forms.SplitContainer();
+			this.lvProps = new System.Windows.Forms.ListView();
+			this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.label2 = new System.Windows.Forms.Label();
+			this.label1 = new System.Windows.Forms.Label();
+			this.splitContainer2 = new System.Windows.Forms.SplitContainer();
+			this.lvTableData = new System.Windows.Forms.ListView();
+			this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.txtString = new System.Windows.Forms.TextBox();
+			this.lblData = new System.Windows.Forms.Label();
+			this.lvMetaTable = new System.Windows.Forms.ListView();
+			this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.columnHeader6 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+			this.label4 = new System.Windows.Forms.Label();
+			this.toolStrip1.SuspendLayout();
+			this.splitContainer1.Panel1.SuspendLayout();
+			this.splitContainer1.Panel2.SuspendLayout();
+			this.splitContainer1.SuspendLayout();
+			this.splitContainer2.Panel1.SuspendLayout();
+			this.splitContainer2.Panel2.SuspendLayout();
+			this.splitContainer2.SuspendLayout();
+			this.SuspendLayout();
+			// 
+			// toolStrip1
+			// 
+			this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+            this.toolBack,
+            this.toolStripSeparator1,
+            this.toolDigData});
+			this.toolStrip1.Location = new System.Drawing.Point(0, 0);
+			this.toolStrip1.Name = "toolStrip1";
+			this.toolStrip1.Size = new System.Drawing.Size(963, 25);
+			this.toolStrip1.TabIndex = 0;
+			this.toolStrip1.Text = "toolStrip1";
+			// 
+			// toolBack
+			// 
+			this.toolBack.Enabled = false;
+			this.toolBack.Image = global::MoonSharp.Debugger.Properties.Resources.NavigateBackwards_6270;
+			this.toolBack.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.toolBack.Name = "toolBack";
+			this.toolBack.Size = new System.Drawing.Size(52, 22);
+			this.toolBack.Text = "Back";
+			this.toolBack.Click += new System.EventHandler(this.toolBack_Click);
+			// 
+			// toolStripSeparator1
+			// 
+			this.toolStripSeparator1.Name = "toolStripSeparator1";
+			this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25);
+			// 
+			// toolDigData
+			// 
+			this.toolDigData.Image = global::MoonSharp.Debugger.Properties.Resources.FindSymbol_6263;
+			this.toolDigData.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.toolDigData.Name = "toolDigData";
+			this.toolDigData.Size = new System.Drawing.Size(79, 22);
+			this.toolDigData.Text = "View Data";
+			this.toolDigData.Click += new System.EventHandler(this.toolDigData_Click);
+			// 
+			// splitContainer1
+			// 
+			this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
+			this.splitContainer1.Location = new System.Drawing.Point(0, 25);
+			this.splitContainer1.Name = "splitContainer1";
+			// 
+			// splitContainer1.Panel1
+			// 
+			this.splitContainer1.Panel1.Controls.Add(this.lvProps);
+			this.splitContainer1.Panel1.Controls.Add(this.label2);
+			this.splitContainer1.Panel1.Controls.Add(this.label1);
+			// 
+			// splitContainer1.Panel2
+			// 
+			this.splitContainer1.Panel2.Controls.Add(this.splitContainer2);
+			this.splitContainer1.Size = new System.Drawing.Size(963, 647);
+			this.splitContainer1.SplitterDistance = 321;
+			this.splitContainer1.TabIndex = 1;
+			// 
+			// lvProps
+			// 
+			this.lvProps.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
+            this.columnHeader1,
+            this.columnHeader2});
+			this.lvProps.Dock = System.Windows.Forms.DockStyle.Fill;
+			this.lvProps.FullRowSelect = true;
+			this.lvProps.GridLines = true;
+			this.lvProps.Location = new System.Drawing.Point(0, 17);
+			this.lvProps.MultiSelect = false;
+			this.lvProps.Name = "lvProps";
+			this.lvProps.Size = new System.Drawing.Size(321, 630);
+			this.lvProps.TabIndex = 3;
+			this.lvProps.UseCompatibleStateImageBehavior = false;
+			this.lvProps.View = System.Windows.Forms.View.Details;
+			this.lvProps.SelectedIndexChanged += new System.EventHandler(this.lvProps_SelectedIndexChanged);
+			this.lvProps.DoubleClick += new System.EventHandler(this.lvAnyTable_DoubleClick);
+			// 
+			// columnHeader1
+			// 
+			this.columnHeader1.Text = "Key";
+			this.columnHeader1.Width = 122;
+			// 
+			// columnHeader2
+			// 
+			this.columnHeader2.Text = "Value";
+			this.columnHeader2.Width = 175;
+			// 
+			// label2
+			// 
+			this.label2.BackColor = System.Drawing.SystemColors.ActiveCaption;
+			this.label2.Dock = System.Windows.Forms.DockStyle.Top;
+			this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+			this.label2.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
+			this.label2.Location = new System.Drawing.Point(0, 0);
+			this.label2.Name = "label2";
+			this.label2.Size = new System.Drawing.Size(321, 17);
+			this.label2.TabIndex = 1;
+			this.label2.Text = "PROPERTIES";
+			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+			// 
+			// label1
+			// 
+			this.label1.AutoSize = true;
+			this.label1.Location = new System.Drawing.Point(48, 90);
+			this.label1.Name = "label1";
+			this.label1.Size = new System.Drawing.Size(0, 13);
+			this.label1.TabIndex = 0;
+			// 
+			// splitContainer2
+			// 
+			this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
+			this.splitContainer2.Location = new System.Drawing.Point(0, 0);
+			this.splitContainer2.Name = "splitContainer2";
+			this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal;
+			// 
+			// splitContainer2.Panel1
+			// 
+			this.splitContainer2.Panel1.Controls.Add(this.lvTableData);
+			this.splitContainer2.Panel1.Controls.Add(this.txtString);
+			this.splitContainer2.Panel1.Controls.Add(this.lblData);
+			// 
+			// splitContainer2.Panel2
+			// 
+			this.splitContainer2.Panel2.Controls.Add(this.lvMetaTable);
+			this.splitContainer2.Panel2.Controls.Add(this.label4);
+			this.splitContainer2.Size = new System.Drawing.Size(638, 647);
+			this.splitContainer2.SplitterDistance = 290;
+			this.splitContainer2.TabIndex = 0;
+			// 
+			// lvTableData
+			// 
+			this.lvTableData.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
+            this.columnHeader3,
+            this.columnHeader4});
+			this.lvTableData.Dock = System.Windows.Forms.DockStyle.Fill;
+			this.lvTableData.FullRowSelect = true;
+			this.lvTableData.GridLines = true;
+			this.lvTableData.Location = new System.Drawing.Point(0, 17);
+			this.lvTableData.MultiSelect = false;
+			this.lvTableData.Name = "lvTableData";
+			this.lvTableData.Size = new System.Drawing.Size(638, 273);
+			this.lvTableData.TabIndex = 6;
+			this.lvTableData.UseCompatibleStateImageBehavior = false;
+			this.lvTableData.View = System.Windows.Forms.View.Details;
+			this.lvTableData.SelectedIndexChanged += new System.EventHandler(this.lvTableData_SelectedIndexChanged);
+			this.lvTableData.DoubleClick += new System.EventHandler(this.lvAnyTable_DoubleClick);
+			// 
+			// columnHeader3
+			// 
+			this.columnHeader3.Text = "Key";
+			this.columnHeader3.Width = 260;
+			// 
+			// columnHeader4
+			// 
+			this.columnHeader4.Text = "Value";
+			this.columnHeader4.Width = 260;
+			// 
+			// txtString
+			// 
+			this.txtString.Dock = System.Windows.Forms.DockStyle.Fill;
+			this.txtString.Location = new System.Drawing.Point(0, 17);
+			this.txtString.Multiline = true;
+			this.txtString.Name = "txtString";
+			this.txtString.ReadOnly = true;
+			this.txtString.ScrollBars = System.Windows.Forms.ScrollBars.Both;
+			this.txtString.Size = new System.Drawing.Size(638, 273);
+			this.txtString.TabIndex = 5;
+			// 
+			// lblData
+			// 
+			this.lblData.BackColor = System.Drawing.SystemColors.ActiveCaption;
+			this.lblData.Dock = System.Windows.Forms.DockStyle.Top;
+			this.lblData.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+			this.lblData.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
+			this.lblData.Location = new System.Drawing.Point(0, 0);
+			this.lblData.Name = "lblData";
+			this.lblData.Size = new System.Drawing.Size(638, 17);
+			this.lblData.TabIndex = 2;
+			this.lblData.Text = "DATA";
+			this.lblData.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+			// 
+			// lvMetaTable
+			// 
+			this.lvMetaTable.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
+            this.columnHeader5,
+            this.columnHeader6});
+			this.lvMetaTable.Dock = System.Windows.Forms.DockStyle.Fill;
+			this.lvMetaTable.FullRowSelect = true;
+			this.lvMetaTable.GridLines = true;
+			this.lvMetaTable.Location = new System.Drawing.Point(0, 17);
+			this.lvMetaTable.MultiSelect = false;
+			this.lvMetaTable.Name = "lvMetaTable";
+			this.lvMetaTable.Size = new System.Drawing.Size(638, 336);
+			this.lvMetaTable.TabIndex = 4;
+			this.lvMetaTable.UseCompatibleStateImageBehavior = false;
+			this.lvMetaTable.View = System.Windows.Forms.View.Details;
+			this.lvMetaTable.SelectedIndexChanged += new System.EventHandler(this.lvMetaTable_SelectedIndexChanged);
+			this.lvMetaTable.DoubleClick += new System.EventHandler(this.lvAnyTable_DoubleClick);
+			// 
+			// columnHeader5
+			// 
+			this.columnHeader5.Text = "Key";
+			this.columnHeader5.Width = 260;
+			// 
+			// columnHeader6
+			// 
+			this.columnHeader6.Text = "Value";
+			this.columnHeader6.Width = 260;
+			// 
+			// label4
+			// 
+			this.label4.BackColor = System.Drawing.SystemColors.ActiveCaption;
+			this.label4.Dock = System.Windows.Forms.DockStyle.Top;
+			this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+			this.label4.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
+			this.label4.Location = new System.Drawing.Point(0, 0);
+			this.label4.Name = "label4";
+			this.label4.Size = new System.Drawing.Size(638, 17);
+			this.label4.TabIndex = 2;
+			this.label4.Text = "METATABLE";
+			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+			// 
+			// ValueBrowser
+			// 
+			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+			this.ClientSize = new System.Drawing.Size(963, 672);
+			this.Controls.Add(this.splitContainer1);
+			this.Controls.Add(this.toolStrip1);
+			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
+			this.MaximizeBox = false;
+			this.MinimizeBox = false;
+			this.Name = "ValueBrowser";
+			this.Text = "Moon# Value Browser";
+			this.Load += new System.EventHandler(this.ValueBrowser_Load);
+			this.toolStrip1.ResumeLayout(false);
+			this.toolStrip1.PerformLayout();
+			this.splitContainer1.Panel1.ResumeLayout(false);
+			this.splitContainer1.Panel1.PerformLayout();
+			this.splitContainer1.Panel2.ResumeLayout(false);
+			this.splitContainer1.ResumeLayout(false);
+			this.splitContainer2.Panel1.ResumeLayout(false);
+			this.splitContainer2.Panel1.PerformLayout();
+			this.splitContainer2.Panel2.ResumeLayout(false);
+			this.splitContainer2.ResumeLayout(false);
+			this.ResumeLayout(false);
+			this.PerformLayout();
+
+		}
+
+		#endregion
+
+		private System.Windows.Forms.ToolStrip toolStrip1;
+		private System.Windows.Forms.ToolStripButton toolBack;
+		private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
+		private System.Windows.Forms.ToolStripButton toolDigData;
+		private System.Windows.Forms.SplitContainer splitContainer1;
+		private System.Windows.Forms.ListView lvProps;
+		private System.Windows.Forms.ColumnHeader columnHeader1;
+		private System.Windows.Forms.ColumnHeader columnHeader2;
+		private System.Windows.Forms.Label label2;
+		private System.Windows.Forms.Label label1;
+		private System.Windows.Forms.SplitContainer splitContainer2;
+		private System.Windows.Forms.Label lblData;
+		private System.Windows.Forms.ListView lvMetaTable;
+		private System.Windows.Forms.ColumnHeader columnHeader5;
+		private System.Windows.Forms.ColumnHeader columnHeader6;
+		private System.Windows.Forms.Label label4;
+		private System.Windows.Forms.TextBox txtString;
+		private System.Windows.Forms.ListView lvTableData;
+		private System.Windows.Forms.ColumnHeader columnHeader3;
+		private System.Windows.Forms.ColumnHeader columnHeader4;
+	}
+}

+ 240 - 0
src/MoonSharp.Debugger/ValueBrowser.cs

@@ -0,0 +1,240 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+using MoonSharp.Interpreter.Execution;
+
+namespace MoonSharp.Debugger
+{
+	public partial class ValueBrowser : Form
+	{
+		Stack<RValue> m_ValueStack = new Stack<RValue>();
+		public static void StartBrowse(RValue v)
+		{
+			if (v == null)
+				return;
+
+			ValueBrowser b = new ValueBrowser();
+			b.m_ValueStack.Push(v);
+			b.ShowDialog();
+		}
+
+		public ValueBrowser()
+		{
+			InitializeComponent();
+		}
+
+		private void ValueBrowser_Load(object sender, EventArgs e)
+		{
+			InvalidateData();
+		}
+
+		private void InvalidateData()
+		{
+			RValue V = m_ValueStack.Peek();
+			toolBack.Enabled = (m_ValueStack.Count > 1);
+
+			lvMetaTable.BeginUpdate();
+			lvProps.BeginUpdate();
+			lvTableData.BeginUpdate();
+
+			lvMetaTable.Items.Clear();
+			lvProps.Items.Clear();
+			txtString.Text = "";
+			lvTableData.Items.Clear();
+			lblData.Text = "VALUE";
+			lvTableData.Visible = false;
+			txtString.Visible = false;
+
+			AddProperty("Ref ID#", V.ReferenceID.ToString("X8"));
+			AddProperty("Read Only", V.ReadOnly);
+			AddProperty("VM Type", V.Type);
+
+			switch (V.Type)
+			{
+				case DataType.Nil:
+					txtString.Visible = true;
+					txtString.Text = "Value is nil";
+					break;
+				case DataType.Boolean:
+					txtString.Visible = true;
+					txtString.Text = V.Boolean.ToString();
+					break;
+				case DataType.Number:
+					txtString.Visible = true;
+					txtString.Text = V.Boolean.ToString();
+					break;
+				case DataType.String:
+					txtString.Visible = true;
+					txtString.Text = V.String.ToString();
+					AddProperty("Raw Length", V.GetLength());
+					break;
+				case DataType.Function:
+					lvTableData.Visible = true;
+					lblData.Text = "CLOSURE SCOPE";
+					BuildFunctionTable(V);
+					break;
+				case DataType.Table:
+					lvTableData.Visible = true;
+					lblData.Text = "TABLE CONTENTS";
+					AddProperty("Raw Length", V.GetLength());
+					BuildTableTable(lvTableData, V);
+					break;
+				case DataType.Tuple:
+					lvTableData.Visible = true;
+					lblData.Text = "TUPLE";
+					AddProperty("Count", V.Tuple.Length);
+					BuildTupleTable(V);
+					break;
+				case DataType.Symbol:
+					lblData.Text = "SYMBOL / TABLE-REF";
+					txtString.Text = V.String.ToString();
+					BuildSymbolTable(V);
+					break;
+				case DataType.ClrFunction:
+					txtString.Visible = true;
+					txtString.Text = "Value is a CLR function.";
+					break;
+				case DataType.UNSUPPORTED_UserData:
+					txtString.Visible = true;
+					txtString.Text = "Value is a CLR object (userdata).";
+					break;
+				case DataType.UNSUPPORTED_Thread:
+					txtString.Visible = true;
+					txtString.Text = "Value is a coroutine.";
+					break;
+				default:
+					break;
+			}
+
+			Colorize(lvMetaTable);
+			Colorize(lvProps);
+			Colorize(lvTableData);
+
+			lvMetaTable.EndUpdate();
+			lvProps.EndUpdate();
+			lvTableData.EndUpdate();
+		}
+
+		private void Colorize(ListView lv)
+		{
+			foreach (ListViewItem lvi in lv.Items)
+			{
+				if (lvi.Tag is RValue)
+				{
+					lvi.ForeColor = Color.Blue;
+				}
+			}
+		}
+
+		private void BuildSymbolTable(RValue V)
+		{
+			var S = V.Symbol;
+			lvTableData.Add("Type", S.Type);
+			lvTableData.Add("Index", S.Index);
+			lvTableData.Add("Name", S.Name);
+			lvTableData.Add("Table Ref Index", S.TableRefIndex);
+			lvTableData.Add("Table Ref Object", S.TableRefObject).Tag = S.TableRefObject;
+		}
+
+		private void BuildFunctionTable(RValue V)
+		{
+			var F = V.Function;
+			var C = F.ClosureContext;
+			lvProps.Add("Bytecode Location", F.ByteCodeLocation);
+
+			for (int i = 0; i < C.Count; i++)
+			{
+				lvTableData.Add(C.Symbols[i], C[i]).Tag = C[i];
+			}
+		}
+
+		private void BuildTupleTable(RValue V)
+		{
+			var T = V.Tuple;
+
+			for (int i = 0; i < T.Length; i++)
+			{
+				lvTableData.Add(i.ToString(), T[i]).Tag = T[i];
+			}
+		}
+
+		private void BuildTableTable(ListView listView, RValue V)
+		{
+			var T = V.Table;
+
+			foreach (var kvp in T.DebugPairs())
+			{
+				listView.Add(kvp.Key, kvp.Value).Tag = kvp.Value;
+			}
+		}
+
+		private void AddProperty(string p1, object p2)
+		{
+			lvProps.Add(p1, p2.ToString());
+		}
+
+		private void lvTableData_SelectedIndexChanged(object sender, EventArgs e)
+		{
+			lvMetaTable.SelectedIndices.Clear();
+			lvProps.SelectedIndices.Clear();
+		}
+
+		private void lvMetaTable_SelectedIndexChanged(object sender, EventArgs e)
+		{
+			lvTableData.SelectedIndices.Clear();
+			lvProps.SelectedIndices.Clear();
+		}
+
+		private void lvProps_SelectedIndexChanged(object sender, EventArgs e)
+		{
+			lvTableData.SelectedIndices.Clear();
+			lvMetaTable.SelectedIndices.Clear();
+		}
+
+		private void lvAnyTable_DoubleClick(object sender, EventArgs e)
+		{
+			DigData(sender as ListView);
+		}
+
+		private void DigData(ListView listView)
+		{
+			if (listView == null) return;
+			ListViewItem lvi = listView.SelectedItems.OfType<ListViewItem>().FirstOrDefault();
+			if (lvi == null) return;
+
+			RValue v = lvi.Tag as RValue;
+
+			if (v != null)
+			{
+				m_ValueStack.Push(v);
+				InvalidateData();
+			}
+		}
+
+		private void toolDigData_Click(object sender, EventArgs e)
+		{
+			ListView[] lvs = new ListView[] { lvMetaTable, lvTableData, lvProps };
+			DigData(lvs.FirstOrDefault(lv => lv.SelectedItems.Count > 0));
+		}
+
+		private void toolBack_Click(object sender, EventArgs e)
+		{
+			m_ValueStack.Pop();
+			InvalidateData();
+		}
+
+
+
+
+
+
+
+
+
+	}
+}

+ 21 - 0
src/MoonSharp.Interpreter.Tests/ClosureTests.cs

@@ -7,6 +7,27 @@ namespace MoonSharp.Interpreter.Tests
 	[TestFixture]
 	[TestFixture]
 	public class ClosureTests
 	public class ClosureTests
 	{
 	{
+		[Test]
+		public void ClosureOnParam()
+		{
+			string script = @"
+				local function g (z)
+				  local function f(a)
+					return a + z;
+				  end
+				  return f;
+				end
+
+				return (g(3)(2));";
+
+			RValue res = MoonSharpInterpreter.LoadFromString(script).Execute(null);
+
+			Assert.AreEqual(DataType.Number, res.Type);
+			Assert.AreEqual(5, res.Number);
+		}
+
+
+
 		[Test]
 		[Test]
 		public void Closures()
 		public void Closures()
 		{
 		{

+ 30 - 20
src/MoonSharp.Interpreter.Tests/LuaTestSuiteExtract.cs

@@ -16,20 +16,28 @@ namespace MoonSharp.Interpreter.Tests
 	{
 	{
 		void RunTest(string script)
 		void RunTest(string script)
 		{
 		{
-			HashSet<int> failedTests = new HashSet<int>();
+			HashSet<string> failedTests = new HashSet<string>();
 			int i = 0;
 			int i = 0;
 
 
 			var globalCtx = new Table();
 			var globalCtx = new Table();
-			globalCtx[new RValue("assert")] = new RValue(new CallbackFunction(
-				a => 
+			globalCtx[new RValue("xassert")] = new RValue(new CallbackFunction(
+				a =>
 				{
 				{
-					++i;
-
-					if (!a[0].TestAsBoolean())
-						failedTests.Add(i);
+					if (!a[1].TestAsBoolean())
+						failedTests.Add(a[0].String);
 
 
-					return RValue.Nil; 
+					return RValue.Nil;
 				}));
 				}));
+			globalCtx[new RValue("assert")] = new RValue(new CallbackFunction(
+			 a =>
+			 {
+				 ++i;
+
+				 if (!a[0].TestAsBoolean())
+					 failedTests.Add(string.Format("assert #{0}", i));
+
+				 return RValue.Nil;
+			 }));
 
 
 			globalCtx[new RValue("print")] = new RValue(new CallbackFunction(a =>
 			globalCtx[new RValue("print")] = new RValue(new CallbackFunction(a =>
 				{
 				{
@@ -56,9 +64,9 @@ namespace MoonSharp.Interpreter.Tests
 					else return n*fact(n-1)
 					else return n*fact(n-1)
 					end
 					end
 				  end
 				  end
-				  assert(fact(5) == 120)
+				  xassert('fact(5) == 120', fact(5) == 120)
 				end
 				end
-				assert(fact == false)
+				xassert('fact == false', fact == false)
 				");
 				");
 		}
 		}
 
 
@@ -73,25 +81,25 @@ namespace MoonSharp.Interpreter.Tests
 				function a:x (x) return x+self.i end
 				function a:x (x) return x+self.i end
 				function a.y (x) return x+self end
 				function a.y (x) return x+self end
 
 
-				assert(a:x(1)+10 == a.y(1))
+				xassert('a:x(1)+10 == a.y(1)', a:x(1)+10 == a.y(1))
 
 
 				a.t = {i=-100}
 				a.t = {i=-100}
 				a['t'].x = function (self, a,b) return self.i+a+b end
 				a['t'].x = function (self, a,b) return self.i+a+b end
 
 
-				assert(a.t:x(2,3) == -95)
+				xassert('a.t:x(2,3) == -95', a.t:x(2,3) == -95)
 
 
 				do
 				do
 				  local a = {x=0}
 				  local a = {x=0}
 				  function a:add (x) self.x, a.y = self.x+x, 20; return self end
 				  function a:add (x) self.x, a.y = self.x+x, 20; return self end
-				  assert(a:add(10):add(20):add(30).x == 60 and a.y == 20)
+				  xassert('a:add(10):add(20):add(30).x == 60 and a.y == 20', a:add(10):add(20):add(30).x == 60 and a.y == 20)
 				end
 				end
 
 
 				local a = {b={c={}}}
 				local a = {b={c={}}}
 
 
 				function a.b.c.f1 (x) return x+1 end
 				function a.b.c.f1 (x) return x+1 end
 				function a.b.c:f2 (x,y) self[x] = y end
 				function a.b.c:f2 (x,y) self[x] = y end
-				assert(a.b.c.f1(4) == 5)
-				a.b.c:f2('k', 12); assert(a.b.c.k == 12)
+				xassert('a.b.c.f1(4) == 5', a.b.c.f1(4) == 5)
+				a.b.c:f2('k', 12); xassert('a.b.c.k == 12', a.b.c.k == 12)
 
 
 				print('+')
 				print('+')
 
 
@@ -100,14 +108,16 @@ namespace MoonSharp.Interpreter.Tests
 
 
 				f(      -- this line change must be valid
 				f(      -- this line change must be valid
 				  1,2)
 				  1,2)
-				assert(t[1] == 1 and t[2] == 2 and t[3] == nil and t[4] == 'a')
+				xassert('missingparam', t[1] == 1 and t[2] == 2 and t[3] == nil and t[4] == 'a')
 				f(1,2,   -- this one too
 				f(1,2,   -- this one too
 					  3,4)
 					  3,4)
-				assert(t[1] == 1 and t[2] == 2 and t[3] == 3 and t[4] == 'a')
+				xassert('extraparam', t[1] == 1 and t[2] == 2 and t[3] == 3 and t[4] == 'a')
 
 
 				");
 				");
 		}
 		}
 
 
+
+
 		[Test]
 		[Test]
 		public void LuaSuite_Calls_Closures()
 		public void LuaSuite_Calls_Closures()
 		{
 		{
@@ -132,7 +142,7 @@ namespace MoonSharp.Interpreter.Tests
 
 
 				fat = Z(F)
 				fat = Z(F)
 
 
-				assert(fat(0) == 1 and fat(4) == 24 and Z(F)(5)==5*Z(F)(4))
+				xassert('fat(0) == 1 and fat(4) == 24 and Z(F)(5)==5*Z(F)(4)', fat(0) == 1 and fat(4) == 24 and Z(F)(5)==5*Z(F)(4))
 
 
 				local function g (z)
 				local function g (z)
 				  local function f (a,b,c,d)
 				  local function f (a,b,c,d)
@@ -143,10 +153,10 @@ namespace MoonSharp.Interpreter.Tests
 
 
 				f = g(10)
 				f = g(10)
 
 
-				assert(f(9, 16) == 10+11+12+13+10+9+16+10)
+				xassert('f(9, 16) == 10+11+12+13+10+9+16+10', f(9, 16) == 10+11+12+13+10+9+16+10)
 
 
 				Z, F, f = nil
 				Z, F, f = nil
-				print('+')
+				--print('+')
 				");
 				");
 		}
 		}
 
 

+ 2 - 2
src/MoonSharp.Interpreter/CoreLib/BasicMethods.cs

@@ -13,7 +13,6 @@ namespace MoonSharp.Interpreter.CoreLib
 
 
 		public static RValue assert(RValue[] values) { return RValue.Nil; }
 		public static RValue assert(RValue[] values) { return RValue.Nil; }
 		public static RValue collectgarbage(RValue[] values) { return RValue.Nil; }
 		public static RValue collectgarbage(RValue[] values) { return RValue.Nil; }
-		public static RValue dofile(RValue[] values) { return RValue.Nil; }
 		public static RValue error(RValue[] values) { return RValue.Nil; }
 		public static RValue error(RValue[] values) { return RValue.Nil; }
 		public static RValue ipairs(RValue[] values) { return RValue.Nil; }
 		public static RValue ipairs(RValue[] values) { return RValue.Nil; }
 		public static RValue pairs(RValue[] values) { return RValue.Nil; }
 		public static RValue pairs(RValue[] values) { return RValue.Nil; }
@@ -29,9 +28,10 @@ namespace MoonSharp.Interpreter.CoreLib
 
 
 
 
 
 
-		// Unsupported - will raise exceptions:
+		// Unsupported (?) - will raise exceptions:
 		public static RValue load(RValue[] values) { return RValue.Nil; }
 		public static RValue load(RValue[] values) { return RValue.Nil; }
 		public static RValue loadfile(RValue[] values) { return RValue.Nil; }
 		public static RValue loadfile(RValue[] values) { return RValue.Nil; }
+		public static RValue dofile(RValue[] values) { return RValue.Nil; }
 
 
 	}
 	}
 }
 }

+ 5 - 1
src/MoonSharp.Interpreter/DataStructs/FastStack.cs

@@ -63,7 +63,7 @@ namespace MoonSharp.Interpreter.Execution.VM
 			{
 			{
 				int oldhead = m_HeadIdx;
 				int oldhead = m_HeadIdx;
 				m_HeadIdx -= cnt;
 				m_HeadIdx -= cnt;
-				Zero(m_HeadIdx + 1, oldhead);
+				Zero(m_HeadIdx, oldhead);
 			}
 			}
 		}
 		}
 
 
@@ -87,6 +87,8 @@ namespace MoonSharp.Interpreter.Execution.VM
 		}
 		}
 
 
 
 
+		#region IList<T> Impl.
+
 		int IList<T>.IndexOf(T item)
 		int IList<T>.IndexOf(T item)
 		{
 		{
 			throw new NotImplementedException();
 			throw new NotImplementedException();
@@ -159,5 +161,7 @@ namespace MoonSharp.Interpreter.Execution.VM
 			throw new NotImplementedException();
 			throw new NotImplementedException();
 		}
 		}
 
 
+		#endregion
+
 	}
 	}
 }
 }

+ 0 - 89
src/MoonSharp.Interpreter/Execution/Behaviours/Behaviour.cs

@@ -1,89 +0,0 @@
-#if false
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace MoonSharp.Interpreter.Execution.Behaviours
-{
-	public abstract class Behaviour : IFunction
-	{
-		public const int STANDARD_RELEVANCE = 0;
-		public const int METATABLE_RELEVANCE = 10;
-
-		public abstract bool IsCompatibleWithType(DataType t);
-		public abstract RValue OnAdd(RValue op1, RValue op2);
-		public abstract RValue OnSub(RValue op1, RValue op2);
-		public abstract RValue OnMul(RValue op1, RValue op2);
-		public abstract RValue OnDiv(RValue op1, RValue op2);
-		public abstract RValue OnMod(RValue op1, RValue op2);
-		public abstract RValue OnPow(RValue op1, RValue op2);
-		public abstract RValue OnNeg(RValue op1);
-		public abstract RValue OnCat(RValue op1, RValue op2);
-		public abstract RValue OnLen(RValue op1);
-		public abstract RValue OnEq(RValue op1, RValue op2);
-		public abstract RValue OnLtEq(RValue op1, RValue op2);
-		public abstract RValue OnLt(RValue op1, RValue op2);
-		public abstract RValue Index(RValue table, RValue key);
-		public abstract RValue NewIndex(RValue table, RValue key);
-		public abstract RValue Invoke(RuntimeScope scope, RValue[] args);
-		public abstract string AsString(RValue op);
-		public abstract double AsNumber(RValue op);
-		public abstract bool AsBoolean(RValue op);
-
-		public abstract int Relevance { get; }
-
-
-		public static RValue Dispatch_OnAdd(RValue op1, RValue op2)
-		{
-			return (op1.Behaviour.Relevance > op2.Behaviour.Relevance) ? op1.Behaviour.OnAdd(op1, op2) : op2.Behaviour.OnAdd(op1, op2);
-		}
-		public static RValue Dispatch_OnSub(RValue op1, RValue op2)
-		{
-			return (op1.Behaviour.Relevance > op2.Behaviour.Relevance) ? op1.Behaviour.OnSub(op1, op2) : op2.Behaviour.OnSub(op1, op2);
-		}
-		public static RValue Dispatch_OnMul(RValue op1, RValue op2)
-		{
-			return (op1.Behaviour.Relevance > op2.Behaviour.Relevance) ? op1.Behaviour.OnMul(op1, op2) : op2.Behaviour.OnMul(op1, op2);
-		}
-		public static RValue Dispatch_OnDiv(RValue op1, RValue op2)
-		{
-			return (op1.Behaviour.Relevance > op2.Behaviour.Relevance) ? op1.Behaviour.OnDiv(op1, op2) : op2.Behaviour.OnDiv(op1, op2);
-		}
-		public static RValue Dispatch_OnMod(RValue op1, RValue op2)
-		{
-			return (op1.Behaviour.Relevance > op2.Behaviour.Relevance) ? op1.Behaviour.OnMod(op1, op2) : op2.Behaviour.OnMod(op1, op2);
-		}
-		public static RValue Dispatch_OnPow(RValue op1, RValue op2)
-		{
-			return (op1.Behaviour.Relevance > op2.Behaviour.Relevance) ? op1.Behaviour.OnPow(op1, op2) : op2.Behaviour.OnPow(op1, op2);
-		}
-		public static RValue Dispatch_OnCat(RValue op1, RValue op2)
-		{
-			return (op1.Behaviour.Relevance > op2.Behaviour.Relevance) ? op1.Behaviour.OnCat(op1, op2) : op2.Behaviour.OnCat(op1, op2);
-		}
-		public static RValue Dispatch_OnEq(RValue op1, RValue op2)
-		{
-			return (op1.Behaviour.Relevance > op2.Behaviour.Relevance) ? op1.Behaviour.OnEq(op1, op2) : op2.Behaviour.OnEq(op1, op2);
-		}
-		public static RValue Dispatch_OnLtEq(RValue op1, RValue op2)
-		{
-			return (op1.Behaviour.Relevance > op2.Behaviour.Relevance) ? op1.Behaviour.OnLtEq(op1, op2) : op2.Behaviour.OnLtEq(op1, op2);
-		}
-		public static RValue Dispatch_OnLt(RValue op1, RValue op2)
-		{
-			return (op1.Behaviour.Relevance > op2.Behaviour.Relevance) ? op1.Behaviour.OnLt(op1, op2) : op2.Behaviour.OnLt(op1, op2);
-		}
-
-
-
-
-
-		public VM.Chunk ByteCode
-		{
-			get { throw new NotImplementedException(); }
-		}
-	}
-}
-
-#endif

+ 0 - 132
src/MoonSharp.Interpreter/Execution/Behaviours/DefaultBehaviour.cs

@@ -1,132 +0,0 @@
-#if false
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace MoonSharp.Interpreter.Execution.Behaviours
-{
-	public class DefaultBehaviour : Behaviour 
-	{
-		public override bool IsCompatibleWithType(DataType t)
-		{
-			return t == DataType.Number;
-		}
-
-		public override RValue OnAdd(RValue op1, RValue op2)
-		{
-			double n1 = op1.Behaviour.AsNumber(op1);
-			double n2 = op2.Behaviour.AsNumber(op2);
-			return new RValue(n1 + n2);
-		}
-
-		public override RValue OnSub(RValue op1, RValue op2)
-		{
-			double n1 = op1.Behaviour.AsNumber(op1);
-			double n2 = op2.Behaviour.AsNumber(op2);
-			return new RValue(n1 - n2);
-		}
-
-		public override RValue OnMul(RValue op1, RValue op2)
-		{
-			double n1 = op1.Behaviour.AsNumber(op1);
-			double n2 = op2.Behaviour.AsNumber(op2);
-			return new RValue(n1 * n2);
-		}
-
-		public override RValue OnDiv(RValue op1, RValue op2)
-		{
-			double n1 = op1.Behaviour.AsNumber(op1);
-			double n2 = op2.Behaviour.AsNumber(op2);
-			return new RValue(n1 / n2);
-		}
-
-		public override RValue OnMod(RValue op1, RValue op2)
-		{
-			double n1 = op1.Behaviour.AsNumber(op1);
-			double n2 = op2.Behaviour.AsNumber(op2);
-			return new RValue(n1 % n2);
-
-		}
-
-		public override RValue OnPow(RValue op1, RValue op2)
-		{
-			double n1 = op1.Behaviour.AsNumber(op1);
-			double n2 = op2.Behaviour.AsNumber(op2);
-			return new RValue(Math.Pow(n1, n2));
-
-		}
-
-		public override RValue OnNeg(RValue op1)
-		{
-			double n1 = op1.Behaviour.AsNumber(op1);
-			return new RValue(-n1);
-		}
-
-		public override RValue OnCat(RValue op1, RValue op2)
-		{
-			string s1 = op1.Behaviour.AsString(op1);
-			string s2 = op1.Behaviour.AsString(op2);
-			return new RValue(s1 + s2);
-		}
-
-		public override RValue OnLen(RValue op1)
-		{
-			throw new NotImplementedException();
-		}
-
-		public override RValue OnEq(RValue op1, RValue op2)
-		{
-			throw new NotImplementedException();
-		}
-
-		public override RValue OnLtEq(RValue op1, RValue op2)
-		{
-			throw new NotImplementedException();
-		}
-
-		public override RValue OnLt(RValue op1, RValue op2)
-		{
-			throw new NotImplementedException();
-		}
-
-		public override RValue Index(RValue table, RValue key)
-		{
-			throw new NotImplementedException();
-		}
-
-		public override RValue NewIndex(RValue table, RValue key)
-		{
-			throw new NotImplementedException();
-		}
-
-		public override RValue Invoke(RuntimeScope scope, RValue[] args)
-		{
-			throw new NotImplementedException();
-		}
-
-		public override string AsString(RValue op)
-		{
-			throw new NotImplementedException();
-		}
-
-		public override double AsNumber(RValue op)
-		{
-			throw new NotImplementedException();
-		}
-
-		public override bool AsBoolean(RValue op)
-		{
-			throw new NotImplementedException();
-		}
-
-		public override int Relevance
-		{
-			get { throw new NotImplementedException(); }
-		}
-	}
-}
-
-
-#endif

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

@@ -9,7 +9,7 @@ namespace MoonSharp.Interpreter.Execution
 	{
 	{
 		public int ByteCodeLocation { get; private set; }
 		public int ByteCodeLocation { get; private set; }
 
 
-		private ClosureContext closureCtx = null;
+		public ClosureContext ClosureContext { get; private set; }
 
 
 		private static ClosureContext emptyClosure = new ClosureContext();
 		private static ClosureContext emptyClosure = new ClosureContext();
 
 
@@ -19,14 +19,14 @@ namespace MoonSharp.Interpreter.Execution
 			ByteCodeLocation = idx;
 			ByteCodeLocation = idx;
 
 
 			if (symbols.Length > 0)
 			if (symbols.Length > 0)
-				closureCtx = new ClosureContext(symbols, symbols.Select(s => scope.Get(s)));
+				ClosureContext = new ClosureContext(symbols, symbols.Select(s => scope.Get(s)));
 			else
 			else
-				closureCtx = emptyClosure;
+				ClosureContext = emptyClosure;
 		}
 		}
 
 
 		internal void EnterClosureBeforeCall(RuntimeScope scope)
 		internal void EnterClosureBeforeCall(RuntimeScope scope)
 		{
 		{
-			scope.EnterClosure(closureCtx);
+			scope.EnterClosure(ClosureContext);
 		}
 		}
 
 
 	}
 	}

+ 0 - 1
src/MoonSharp.Interpreter/Execution/DataTypes/DataType.cs

@@ -17,7 +17,6 @@ namespace MoonSharp.Interpreter.Execution
 		Tuple,
 		Tuple,
 
 
 		Symbol,
 		Symbol,
-		TableRef,
 		ClrFunction,
 		ClrFunction,
 
 
 		UNSUPPORTED_UserData,
 		UNSUPPORTED_UserData,

+ 4 - 4
src/MoonSharp.Interpreter/Execution/DataTypes/RValue.cs

@@ -24,7 +24,7 @@ namespace MoonSharp.Interpreter.Execution
 		public string String { get; private set; }
 		public string String { get; private set; }
 		public bool ReadOnly { get; internal set; }
 		public bool ReadOnly { get; internal set; }
 
 
-		internal LRef Symbol { get; private set; }
+		public LRef Symbol { get; private set; }
 
 
 
 
 
 
@@ -152,7 +152,7 @@ namespace MoonSharp.Interpreter.Execution
 		public RValue Clone()
 		public RValue Clone()
 		{
 		{
 			if (this.Type == DataType.Symbol)
 			if (this.Type == DataType.Symbol)
-				throw new ArgumentException("Can't clone Symbol or TableRef values");
+				throw new ArgumentException("Can't clone Symbol values");
 
 
 			RValue v = new RValue();
 			RValue v = new RValue();
 			v.Boolean = this.Boolean;
 			v.Boolean = this.Boolean;
@@ -170,8 +170,8 @@ namespace MoonSharp.Interpreter.Execution
 
 
 		public RValue CloneAsWritable()
 		public RValue CloneAsWritable()
 		{
 		{
-			if (this.Type == DataType.Symbol || this.Type == DataType.TableRef)
-				throw new ArgumentException("Can't clone Symbol or TableRef values");
+			if (this.Type == DataType.Symbol)
+				throw new ArgumentException("Can't clone Symbol values");
 
 
 			RValue v = new RValue();
 			RValue v = new RValue();
 			v.Boolean = this.Boolean;
 			v.Boolean = this.Boolean;

+ 6 - 2
src/MoonSharp.Interpreter/Execution/DataTypes/Table.cs

@@ -60,9 +60,13 @@ namespace MoonSharp.Interpreter.Execution
 			}
 			}
 		}
 		}
 
 
-		public IEnumerable<KeyValuePair<RValue, RValue>> Pairs()
+		public IEnumerable<KeyValuePair<RValue, RValue>> DebugPairs()
 		{
 		{
-			return m_Symbols;
+			foreach (var kvp in m_Symbols)
+				yield return kvp;
+
+			foreach (var kvp in m_StringSymbols)
+				yield return new KeyValuePair<RValue, RValue>(new RValue(kvp.Key), kvp.Value);
 		}
 		}
 
 
 		private void Remove(RValue key)
 		private void Remove(RValue key)

+ 0 - 68
src/MoonSharp.Interpreter/Execution/ExecutionFlow.cs

@@ -1,68 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace MoonSharp.Interpreter.Execution
-{
-	public class ExecutionFlow
-	{
-		public ExecutionFlowType Type { get; private set; }
-
-		public string GoToLabel { get; private set; }
-
-		public RValue ReturnValue { get; private set; }
-
-		private ExecutionFlow()
-		{ }
-
-		public static ExecutionFlow GoTo(string label)
-		{
-			return new ExecutionFlow()
-			{
-				GoToLabel = label,
-				Type = ExecutionFlowType.GoTo
-			};
-		}
-
-		public static ExecutionFlow Return(RValue value)
-		{
-			return new ExecutionFlow()
-			{
-				ReturnValue = value,
-				Type = ExecutionFlowType.Return
-			};
-		}
-
-		private static ExecutionFlow s_None = new ExecutionFlow() { Type = ExecutionFlowType.None };
-		private static ExecutionFlow s_Break = new ExecutionFlow() { Type = ExecutionFlowType.Break };
-		private static ExecutionFlow s_Continue = new ExecutionFlow() { Type = ExecutionFlowType.Continue };
-
-		public static ExecutionFlow None { get { return s_None; } }
-		public static ExecutionFlow Break { get { return s_Break; } }
-		public static ExecutionFlow Continue { get { return s_Continue; } }
-
-
-		public bool ChangesFlow() { return this.Type != ExecutionFlowType.None; }
-
-		public override string ToString()
-		{
-			switch (this.Type)
-			{
-				case ExecutionFlowType.None:
-					return "none";
-				case ExecutionFlowType.GoTo:
-					return string.Format("goto {0}", this.GoToLabel);
-				case ExecutionFlowType.Break:
-					return "break";
-				case ExecutionFlowType.Continue:
-					return "continue";
-				case ExecutionFlowType.Return:
-					return string.Format("return {0}", this.ReturnValue);
-				default:
-					return "!!UNKNOWN FLOW!!";
-			}
-		}
-
-	}
-}

+ 0 - 16
src/MoonSharp.Interpreter/Execution/ExecutionFlowType.cs

@@ -1,16 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace MoonSharp.Interpreter.Execution
-{
-	public enum ExecutionFlowType
-	{
-		None,
-		GoTo,
-		Break,
-		Continue,
-		Return
-	}
-}

+ 0 - 23
src/MoonSharp.Interpreter/Execution/Operator.cs

@@ -1,23 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-
-namespace MoonSharp.Interpreter.Execution
-{
-	public enum Operator
-	{
-		Or,
-		And,
-		Less, Greater, LessOrEqual, GreaterOrEqual, NotEqual, Equal,
-		StrConcat,
-		Add, Sub,
-		Mul, Div, Mod,
-		Not, Size, Neg,
-		Power
-	}
-
-
-
-}

+ 0 - 3
src/MoonSharp.Interpreter/Execution/Scopes/BuildTimeScope.cs

@@ -100,9 +100,6 @@ namespace MoonSharp.Interpreter.Execution
 						int idx = m_Locals[i].Find(name);
 						int idx = m_Locals[i].Find(name);
 						if (idx >= 0)
 						if (idx >= 0)
 							return closure.CreateUpvalue(this, LRef.Local(name, idx));
 							return closure.CreateUpvalue(this, LRef.Local(name, idx));
-
-						if (m_Locals[i].Breaking)
-							break;
 					}
 					}
 				}
 				}
 			}
 			}

+ 2 - 2
src/MoonSharp.Interpreter/Execution/Scopes/ClosureContext.cs

@@ -9,13 +9,13 @@ namespace MoonSharp.Interpreter.Execution
 	{
 	{
 		public string[] Symbols { get; private set; }
 		public string[] Symbols { get; private set; }
 
 
-		public ClosureContext(LRef[] symbols, IEnumerable<RValue> values)
+		internal ClosureContext(LRef[] symbols, IEnumerable<RValue> values)
 		{
 		{
 			Symbols = symbols.Select(s => s.i_Name).ToArray();
 			Symbols = symbols.Select(s => s.i_Name).ToArray();
 			this.AddRange(values);
 			this.AddRange(values);
 		}
 		}
 
 
-		public ClosureContext()
+		internal ClosureContext()
 		{
 		{
 			Symbols = new string[0];
 			Symbols = new string[0];
 		}
 		}

+ 1 - 1
src/MoonSharp.Interpreter/Execution/Scopes/LoopTracker.cs

@@ -14,6 +14,6 @@ namespace MoonSharp.Interpreter.Execution
 
 
 	class LoopTracker
 	class LoopTracker
 	{
 	{
-		public List<ILoop> Loops = new List<ILoop>();
+		public FastStack<ILoop> Loops = new FastStack<ILoop>(16384);
 	}
 	}
 }
 }

+ 2 - 8
src/MoonSharp.Interpreter/Execution/VM/Chunk.cs

@@ -233,15 +233,9 @@ namespace MoonSharp.Interpreter.Execution.VM
 			return Emit(new Instruction() { OpCode = OpCode.IterUpd });
 			return Emit(new Instruction() { OpCode = OpCode.IterUpd });
 		}
 		}
 
 
-		public void Reverse(int p)
+		public Instruction Method()
 		{
 		{
-			if (p > 1)
-				Emit(new Instruction() { OpCode = OpCode.Reverse, NumVal = p });
-		}
-
-		internal string[] ToSourceCode()
-		{
-			throw new NotImplementedException();
+			return Emit(new Instruction() { OpCode = OpCode.Method });
 		}
 		}
 	}
 	}
 }
 }

+ 0 - 5
src/MoonSharp.Interpreter/Execution/VM/Instruction.cs

@@ -52,13 +52,8 @@ namespace MoonSharp.Interpreter.Execution.VM
 				case OpCode.Ret:
 				case OpCode.Ret:
 				case OpCode.MkTuple:
 				case OpCode.MkTuple:
 				case OpCode.ExpTuple:
 				case OpCode.ExpTuple:
-				case OpCode.Reverse:
 				case OpCode.Incr:
 				case OpCode.Incr:
 				case OpCode.Pop:
 				case OpCode.Pop:
-				case OpCode.TmpClear:
-				case OpCode.TmpPush:
-				case OpCode.TmpPop:
-				case OpCode.TmpPeek:
 					append = string.Format("{0}{1}", GenSpaces(), NumVal);
 					append = string.Format("{0}{1}", GenSpaces(), NumVal);
 					break;
 					break;
 				case OpCode.JtOrPop:
 				case OpCode.JtOrPop:

+ 1 - 7
src/MoonSharp.Interpreter/Execution/VM/OpCode.cs

@@ -22,7 +22,6 @@ namespace MoonSharp.Interpreter.Execution.VM
 		SymStorN,	// Performs a store to a symbol, without needing the symbol on the v-stack and without extracting the operand from the v-stack.
 		SymStorN,	// Performs a store to a symbol, without needing the symbol on the v-stack and without extracting the operand from the v-stack.
 		Store,		// Performs a single value assignment [including table fields]
 		Store,		// Performs a single value assignment [including table fields]
 		Assign,		// Performs complex assignment supporting tuples [including table fields]
 		Assign,		// Performs complex assignment supporting tuples [including table fields]
-		Reverse,	// Reverses the last n elements of the stack
 		Closure,	// Creates a closure on the top of the v-stack, using the symbols for upvalues and num-val for entry point of the function.
 		Closure,	// Creates a closure on the top of the v-stack, using the symbols for upvalues and num-val for entry point of the function.
 
 
 		// Stack-frame ops and calls
 		// Stack-frame ops and calls
@@ -68,14 +67,9 @@ namespace MoonSharp.Interpreter.Execution.VM
 		Index,		// Performs an index operation, pushing the indexed value on the stack.
 		Index,		// Performs an index operation, pushing the indexed value on the stack.
 		IndexRef,	// Performs an index operation, pushing a writable indexded value on the stack.
 		IndexRef,	// Performs an index operation, pushing a writable indexded value on the stack.
 		IndexRefN,	// Performs an index operation, pushing a writable indexed value on the stack, does not pop the table.
 		IndexRefN,	// Performs an index operation, pushing a writable indexed value on the stack, does not pop the table.
+		Method,		// Performs an index operation and pushes the table after the indexed value on the stack
 		NewTable,	// Creates a new table on the stack
 		NewTable,	// Creates a new table on the stack
 
 
-		// ScratchPad
-		TmpPeek,	// Peeks the top of the stack in a temporary reg. 
-		TmpPush,	// Pushes a temporary reg on the top of the stack. 
-		TmpPop,		// Pops the top of the stack in a temporary reg. 
-		TmpClear,	// Clears a temporary reg
-
 		// Iterators
 		// Iterators
 		IterPrep,   // Prepares an interator for execution 
 		IterPrep,   // Prepares an interator for execution 
 		IterUpd,	// Updates the var part of an iterator
 		IterUpd,	// Updates the var part of an iterator

+ 1 - 2
src/MoonSharp.Interpreter/Execution/VM/Processor/Processor.cs

@@ -12,12 +12,11 @@ namespace MoonSharp.Interpreter.Execution.VM
 		Chunk m_RootChunk;
 		Chunk m_RootChunk;
 		Chunk m_CurChunk;
 		Chunk m_CurChunk;
 		int m_InstructionPtr;
 		int m_InstructionPtr;
+		bool m_Terminate = false;
 
 
 		FastStack<RValue> m_ValueStack = new FastStack<RValue>(131072);
 		FastStack<RValue> m_ValueStack = new FastStack<RValue>(131072);
 		FastStack<CallStackItem> m_ExecutionStack = new FastStack<CallStackItem>(131072);
 		FastStack<CallStackItem> m_ExecutionStack = new FastStack<CallStackItem>(131072);
-		bool m_Terminate = false;
 		RuntimeScope m_Scope;
 		RuntimeScope m_Scope;
-		RValue[] m_TempRegs = new RValue[8];
 
 
 		IDebugger m_DebuggerAttached = null;
 		IDebugger m_DebuggerAttached = null;
 		DebuggerAction.ActionType m_DebuggerCurrentAction = DebuggerAction.ActionType.None;
 		DebuggerAction.ActionType m_DebuggerCurrentAction = DebuggerAction.ActionType.None;

+ 1 - 1
src/MoonSharp.Interpreter/Execution/VM/Processor/Processor_Debugger.cs

@@ -78,7 +78,7 @@ namespace MoonSharp.Interpreter.Execution.VM
 		private List<WatchItem> Debugger_RefreshVStack()
 		private List<WatchItem> Debugger_RefreshVStack()
 		{
 		{
 			List<WatchItem> lwi = new List<WatchItem>();
 			List<WatchItem> lwi = new List<WatchItem>();
-			for (int i = 0; i < Math.Min(16, m_ValueStack.Count); i++)
+			for (int i = 0; i < Math.Min(32, m_ValueStack.Count); i++)
 			{
 			{
 				lwi.Add(new WatchItem()
 				lwi.Add(new WatchItem()
 				{
 				{

+ 19 - 38
src/MoonSharp.Interpreter/Execution/VM/Processor/Processor_InstructionLoop.cs

@@ -132,7 +132,10 @@ namespace MoonSharp.Interpreter.Execution.VM
 						ExecJFor(i);
 						ExecJFor(i);
 						break;
 						break;
 					case OpCode.Index:
 					case OpCode.Index:
-						ExecIndexGet(i);
+						ExecIndexGet(i, false);
+						break;
+					case OpCode.Method:
+						ExecIndexGet(i, true);
 						break;
 						break;
 					case OpCode.IndexRef:
 					case OpCode.IndexRef:
 						ExecIndexRef(i, false);
 						ExecIndexRef(i, false);
@@ -143,24 +146,9 @@ namespace MoonSharp.Interpreter.Execution.VM
 					case OpCode.NewTable:
 					case OpCode.NewTable:
 						m_ValueStack.Push(new RValue(new Table()));
 						m_ValueStack.Push(new RValue(new Table()));
 						break;
 						break;
-					case OpCode.TmpClear:
-						m_TempRegs[i.NumVal] = null;
-						break;
-					case OpCode.TmpPeek:
-						m_TempRegs[i.NumVal] = m_ValueStack.Peek();
-						break;
-					case OpCode.TmpPop:
-						m_TempRegs[i.NumVal] = m_ValueStack.Pop();
-						break;
-					case OpCode.Reverse:
-						ExecReverse(i);
-						break;
 					case OpCode.Len:
 					case OpCode.Len:
 						ExecLen(i);
 						ExecLen(i);
 						break;
 						break;
-					case OpCode.TmpPush:
-						m_ValueStack.Push(m_TempRegs[i.NumVal]);
-						break;
 					case OpCode.IterPrep:
 					case OpCode.IterPrep:
 						ExecIterPrep(i);
 						ExecIterPrep(i);
 						break;
 						break;
@@ -241,22 +229,6 @@ namespace MoonSharp.Interpreter.Execution.VM
 			m_ValueStack.Push(v);
 			m_ValueStack.Push(v);
 		}
 		}
 
 
-		private void ExecReverse(Instruction i)
-		{
-			int cnt = i.NumVal;
-			int cnth = cnt / 2;
-
-			int len = m_ValueStack.Count - 1;
-
-			for (int idx = 0; idx < cnth; idx++)
-			{
-				var tmp = m_ValueStack[len - idx];
-				m_ValueStack[len - idx] = m_ValueStack[len - (cnt - 1 - idx)];
-				m_ValueStack[len - (cnt - 1 - idx)] = tmp;
-			}
-		}
-
-
 		private void ExecExit(Instruction i)
 		private void ExecExit(Instruction i)
 		{
 		{
 			if (i.Frame == null)
 			if (i.Frame == null)
@@ -271,9 +243,6 @@ namespace MoonSharp.Interpreter.Execution.VM
 			}
 			}
 		}
 		}
 
 
-
-
-
 		private void ExecJFor(Instruction i)
 		private void ExecJFor(Instruction i)
 		{
 		{
 			double val = m_ValueStack.Peek(0).Number;
 			double val = m_ValueStack.Peek(0).Number;
@@ -361,9 +330,18 @@ namespace MoonSharp.Interpreter.Execution.VM
 
 
 		private void ExecArgs(Instruction I)
 		private void ExecArgs(Instruction I)
 		{
 		{
+			int numargs = (int)m_ValueStack.Peek(0).Number;
+
 			for (int i = 0; i < I.SymbolList.Length; i++)
 			for (int i = 0; i < I.SymbolList.Length; i++)
 			{
 			{
-				m_Scope.Assign(I.SymbolList[i], m_ValueStack.Peek(i + 1));
+				if (i >= numargs)
+				{
+					m_Scope.Assign(I.SymbolList[i], new RValue());
+				}
+				else
+				{
+					m_Scope.Assign(I.SymbolList[i], m_ValueStack.Peek(numargs - i).CloneAsWritable());
+				}
 			}
 			}
 		}
 		}
 
 
@@ -373,7 +351,7 @@ namespace MoonSharp.Interpreter.Execution.VM
 
 
 			if (fn.Type == DataType.ClrFunction)
 			if (fn.Type == DataType.ClrFunction)
 			{
 			{
-				RValue[] args = StackTopToArray(i.NumVal, true);
+				RValue[] args = StackTopToArrayReverse(i.NumVal, true);
 				m_ValueStack.Pop();
 				m_ValueStack.Pop();
 				var ret = fn.Callback.Invoke(args);
 				var ret = fn.Callback.Invoke(args);
 				m_ValueStack.Push(ret);
 				m_ValueStack.Push(ret);
@@ -569,7 +547,7 @@ namespace MoonSharp.Interpreter.Execution.VM
 			}
 			}
 		}
 		}
 
 
-		private void ExecIndexGet(Instruction i)
+		private void ExecIndexGet(Instruction i, bool methodCall)
 		{
 		{
 			RValue indexValue = m_ValueStack.Pop();
 			RValue indexValue = m_ValueStack.Pop();
 			RValue baseValue = m_ValueStack.Pop();
 			RValue baseValue = m_ValueStack.Pop();
@@ -583,6 +561,9 @@ namespace MoonSharp.Interpreter.Execution.VM
 				RValue v = baseValue.Table[indexValue];
 				RValue v = baseValue.Table[indexValue];
 				m_ValueStack.Push(v.AsReadOnly());
 				m_ValueStack.Push(v.AsReadOnly());
 			}
 			}
+
+			if (methodCall)
+				m_ValueStack.Push(baseValue);
 		}
 		}
 
 
 		private void ExecIndexRef(Instruction i, bool keepOnStack)
 		private void ExecIndexRef(Instruction i, bool keepOnStack)

+ 0 - 0
src/MoonSharp.Interpreter/Helpers/LuaGrammar_ExtensionMethods.cs → src/MoonSharp.Interpreter/Grammar/LuaGrammar_ExtensionMethods.cs


+ 0 - 44
src/MoonSharp.Interpreter/Helpers/List_ExtensionMethods.cs

@@ -1,44 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace MoonSharp.Interpreter
-{
-	internal static class List_ExtensionMethods
-	{
-
-		public static void CropAtCount<T>(this List<T> list, int count)
-		{
-			list.RemoveRange(count, list.Count - count);
-		}
-
-		public static T Peek<T>(this List<T> list, int idxofs = 0)
-		{
-			T item = list[list.Count - 1 - idxofs];
-			return item;
-		}
-		public static void RemoveLast<T>(this List<T> list, int cnt = 1)
-		{
-			if (cnt == 1)
-				list.RemoveAt(list.Count - 1);
-			else
-				for (int i = 0; i < cnt; i++)
-					list.RemoveAt(list.Count - 1);
-		}
-		public static T Pop<T>(this List<T> list)
-		{
-			T item = list[list.Count - 1];
-			list.RemoveAt(list.Count - 1);
-			return item;
-		}
-		public static T Push<T>(this List<T> list, T item)
-		{
-			list.Add(item);
-			return item;
-		}
-
-
-
-	}
-}

+ 1 - 7
src/MoonSharp.Interpreter/MoonSharp.Interpreter.csproj

@@ -63,15 +63,11 @@
     <Compile Include="Debugging\WatchType.cs" />
     <Compile Include="Debugging\WatchType.cs" />
     <Compile Include="Diagnostics\Debug.cs" />
     <Compile Include="Diagnostics\Debug.cs" />
     <Compile Include="Errors\InternalErrorException.cs" />
     <Compile Include="Errors\InternalErrorException.cs" />
-    <Compile Include="Execution\Behaviours\Behaviour.cs" />
-    <Compile Include="Execution\Behaviours\DefaultBehaviour.cs" />
     <Compile Include="Diagnostics\AstDump.cs" />
     <Compile Include="Diagnostics\AstDump.cs" />
     <Compile Include="Diagnostics\CodeChrono.cs" />
     <Compile Include="Diagnostics\CodeChrono.cs" />
     <Compile Include="Errors\ScriptRuntimeException.cs" />
     <Compile Include="Errors\ScriptRuntimeException.cs" />
     <Compile Include="Errors\SyntaxErrorException.cs" />
     <Compile Include="Errors\SyntaxErrorException.cs" />
     <Compile Include="Execution\DataTypes\Closure.cs" />
     <Compile Include="Execution\DataTypes\Closure.cs" />
-    <Compile Include="Execution\ExecutionFlow.cs" />
-    <Compile Include="Execution\ExecutionFlowType.cs" />
     <Compile Include="Execution\DataTypes\CallbackFunction.cs" />
     <Compile Include="Execution\DataTypes\CallbackFunction.cs" />
     <Compile Include="Execution\Scopes\ClosureContext.cs" />
     <Compile Include="Execution\Scopes\ClosureContext.cs" />
     <Compile Include="Execution\Scopes\LoopTracker.cs" />
     <Compile Include="Execution\Scopes\LoopTracker.cs" />
@@ -86,7 +82,6 @@
     <Compile Include="Execution\DataTypes\DataType.cs" />
     <Compile Include="Execution\DataTypes\DataType.cs" />
     <Compile Include="Execution\DataTypes\RValue.cs" />
     <Compile Include="Execution\DataTypes\RValue.cs" />
     <Compile Include="Execution\Script.cs" />
     <Compile Include="Execution\Script.cs" />
-    <Compile Include="Execution\Operator.cs" />
     <Compile Include="Execution\DataTypes\Table.cs" />
     <Compile Include="Execution\DataTypes\Table.cs" />
     <Compile Include="Execution\VM\Chunk.cs" />
     <Compile Include="Execution\VM\Chunk.cs" />
     <Compile Include="DataStructs\FastStack.cs" />
     <Compile Include="DataStructs\FastStack.cs" />
@@ -100,7 +95,6 @@
     <Compile Include="Execution\VM\Processor\Processor_Debugger.cs" />
     <Compile Include="Execution\VM\Processor\Processor_Debugger.cs" />
     <Compile Include="Execution\VM\Processor\Processor_InstructionLoop.cs" />
     <Compile Include="Execution\VM\Processor\Processor_InstructionLoop.cs" />
     <Compile Include="Execution\VM\Processor\Processor_UtilityFunctions.cs" />
     <Compile Include="Execution\VM\Processor\Processor_UtilityFunctions.cs" />
-    <Compile Include="Helpers\List_ExtensionMethods.cs" />
     <Compile Include="Grammar\Lua.g4.lexer.cs">
     <Compile Include="Grammar\Lua.g4.lexer.cs">
       <DependentUpon>Lua.g4</DependentUpon>
       <DependentUpon>Lua.g4</DependentUpon>
     </Compile>
     </Compile>
@@ -137,7 +131,7 @@
     <Compile Include="Tree\Statements\NullStatement.cs" />
     <Compile Include="Tree\Statements\NullStatement.cs" />
     <Compile Include="Tree\Statements\RepeatStatement.cs" />
     <Compile Include="Tree\Statements\RepeatStatement.cs" />
     <Compile Include="Tree\Statements\ReturnStatement.cs" />
     <Compile Include="Tree\Statements\ReturnStatement.cs" />
-    <Compile Include="Helpers\LuaGrammar_ExtensionMethods.cs" />
+    <Compile Include="Grammar\LuaGrammar_ExtensionMethods.cs" />
     <Compile Include="Tree\Expressions\TableConstructor.cs" />
     <Compile Include="Tree\Expressions\TableConstructor.cs" />
     <Compile Include="Tree\Statements\ScopeBlockStatement.cs" />
     <Compile Include="Tree\Statements\ScopeBlockStatement.cs" />
     <Compile Include="Tree\Statements\WhileStatement.cs" />
     <Compile Include="Tree\Statements\WhileStatement.cs" />

+ 6 - 0
src/MoonSharp.Interpreter/MoonSharpInterpreter.cs

@@ -55,5 +55,11 @@ namespace MoonSharp.Interpreter
 			return LoadFromICharStream(new AntlrInputStream(text));
 			return LoadFromICharStream(new AntlrInputStream(text));
 		}
 		}
 
 
+
+
+		public static void WarmUp()
+		{
+			LoadFromString("return 1;");
+		}
 	}
 	}
 }
 }

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

@@ -11,6 +11,18 @@ namespace MoonSharp.Interpreter.Tree.Expressions
 {
 {
 	class OperatorExpression : Expression 
 	class OperatorExpression : Expression 
 	{
 	{
+		private enum Operator
+		{
+			Or,
+			And,
+			Less, Greater, LessOrEqual, GreaterOrEqual, NotEqual, Equal,
+			StrConcat,
+			Add, Sub,
+			Mul, Div, Mod,
+			Not, Size, Neg,
+			Power
+		}
+
 		static HashSet<Type> s_OperatorTypes = new HashSet<Type>();
 		static HashSet<Type> s_OperatorTypes = new HashSet<Type>();
 
 
 		static OperatorExpression()
 		static OperatorExpression()

+ 5 - 15
src/MoonSharp.Interpreter/Tree/FunctionCall.cs

@@ -25,29 +25,19 @@ namespace MoonSharp.Interpreter.Tree
 
 
 		public override void Compile(Execution.VM.Chunk bc)
 		public override void Compile(Execution.VM.Chunk bc)
 		{
 		{
+			int argslen = m_Arguments.Length;
+
 			if (!string.IsNullOrEmpty(m_Name))
 			if (!string.IsNullOrEmpty(m_Name))
 			{
 			{
-				bc.TempOp(OpCode.TmpPeek, 0);
 				bc.Literal(new RValue(m_Name));
 				bc.Literal(new RValue(m_Name));
-				bc.Index();
+				bc.Method();
+				++argslen;
 			}
 			}
 
 
-
 			for (int i = 0; i < m_Arguments.Length; i++)
 			for (int i = 0; i < m_Arguments.Length; i++)
 				m_Arguments[i].Compile(bc);
 				m_Arguments[i].Compile(bc);
 
 
-			bc.Reverse(m_Arguments.Length);
-
-			if (string.IsNullOrEmpty(m_Name))
-			{
-				bc.Call(m_Arguments.Length);
-			}
-			else
-			{
-				bc.TempOp(OpCode.TmpPush, 0);
-				bc.TempOp(OpCode.TmpClear, 0);
-				bc.Call(m_Arguments.Length + 1);
-			}
+			bc.Call(argslen);
 		}
 		}
 	}
 	}
 }
 }

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

@@ -63,7 +63,6 @@ namespace MoonSharp.Interpreter.Tree.Statements
 
 
 			// expand the tuple - stack : iterator-tuple, iter-var-symbols, f, var, s
 			// expand the tuple - stack : iterator-tuple, iter-var-symbols, f, var, s
 			bc.ExpTuple(m_Names.Length);  
 			bc.ExpTuple(m_Names.Length);  
-			bc.Reverse(2);
 
 
 			// calls f(s, var) - stack : iterator-tuple, iter-var-symbols, iteration result
 			// calls f(s, var) - stack : iterator-tuple, iter-var-symbols, iteration result
 			bc.Call(2);
 			bc.Call(2);

+ 2 - 0
src/MoonSharp.Interpreter/Tree/Statements/FunctionDefinitionStatement.cs

@@ -24,6 +24,8 @@ namespace MoonSharp.Interpreter.Tree.Statements
 			m_Local = true;
 			m_Local = true;
 			m_FuncName = lcontext.Scope.TryDefineLocal(context.NAME().GetText());
 			m_FuncName = lcontext.Scope.TryDefineLocal(context.NAME().GetText());
 			m_FuncDef = new FunctionDefinitionExpression(context.funcbody(), lcontext);
 			m_FuncDef = new FunctionDefinitionExpression(context.funcbody(), lcontext);
+
+			m_FriendlyName = string.Format("{0} (local)", m_FuncName.i_Name);
 		}
 		}
 
 
 		public FunctionDefinitionStatement(LuaParser.Stat_funcdefContext context, ScriptLoadingContext lcontext)
 		public FunctionDefinitionStatement(LuaParser.Stat_funcdefContext context, ScriptLoadingContext lcontext)