Implements new debug string that outlines the bound script
This commit is contained in:
parent
8f5c165d39
commit
93ae52b04a
|
@ -2,6 +2,7 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
using PorygonSharp.DiagnosticHandling;
|
using PorygonSharp.DiagnosticHandling;
|
||||||
using PorygonSharp.EvalValues;
|
using PorygonSharp.EvalValues;
|
||||||
|
|
||||||
|
@ -127,6 +128,14 @@ namespace PorygonSharp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetBoundTreeString()
|
||||||
|
{
|
||||||
|
var length = GetTreeStringLength(_internalScriptHandle);
|
||||||
|
var sb = new StringBuilder(length - 4);
|
||||||
|
GetTreeString(_internalScriptHandle, sb);
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
[DllImport("PorygonLang", EntryPoint = "CreateScript", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CreateScript", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr Create([MarshalAs(UnmanagedType.LPWStr)]string s, IntPtr options);
|
private static extern IntPtr Create([MarshalAs(UnmanagedType.LPWStr)]string s, IntPtr options);
|
||||||
[DllImport("PorygonLang", EntryPoint = "EvaluateScript", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "EvaluateScript", CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
@ -146,6 +155,9 @@ namespace PorygonSharp
|
||||||
[DllImport("PorygonLang", EntryPoint = "CloneScript", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CloneScript", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr CloneScript(IntPtr script);
|
private static extern IntPtr CloneScript(IntPtr script);
|
||||||
|
|
||||||
|
[DllImport("PorygonLang", EntryPoint = "GetTreeStringLength", CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
private static extern int GetTreeStringLength(IntPtr script);
|
||||||
|
[DllImport("PorygonLang", EntryPoint = "GetTreeString", CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
private static extern void GetTreeString(IntPtr script, StringBuilder sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using PorygonSharp.EvalValues;
|
using PorygonSharp.EvalValues;
|
||||||
using PorygonSharp.HelperLibraries;
|
|
||||||
using PorygonSharp.Utilities;
|
using PorygonSharp.Utilities;
|
||||||
|
|
||||||
namespace PorygonSharp
|
namespace PorygonSharp
|
||||||
|
|
Binary file not shown.
|
@ -153,5 +153,21 @@ namespace PorygonSharpTests
|
||||||
var hash = "Foo".ScriptHash();
|
var hash = "Foo".ScriptHash();
|
||||||
Assert.AreEqual(193501609, hash);
|
Assert.AreEqual(193501609, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestBoundTreeString()
|
||||||
|
{
|
||||||
|
using (var script = new Script("return 10 + 500"))
|
||||||
|
{
|
||||||
|
var tree = script.GetBoundTreeString();
|
||||||
|
const string expectedString = @"BlockStatement
|
||||||
|
ReturnStatement
|
||||||
|
BinaryExpression: addition (number)
|
||||||
|
LiteralInteger: 10 (number)
|
||||||
|
LiteralInteger: 500 (number)";
|
||||||
|
Assert.AreEqual(expectedString, tree);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue