diff --git a/PorygonSharp/Script.cs b/PorygonSharp/Script.cs index d9c4bd5..74fe14e 100644 --- a/PorygonSharp/Script.cs +++ b/PorygonSharp/Script.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Text; using PorygonSharp.DiagnosticHandling; 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)] private static extern IntPtr Create([MarshalAs(UnmanagedType.LPWStr)]string s, IntPtr options); [DllImport("PorygonLang", EntryPoint = "EvaluateScript", CallingConvention = CallingConvention.Cdecl)] @@ -146,6 +155,9 @@ namespace PorygonSharp [DllImport("PorygonLang", EntryPoint = "CloneScript", CallingConvention = CallingConvention.Cdecl)] 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); } } \ No newline at end of file diff --git a/PorygonSharp/StaticScope.cs b/PorygonSharp/StaticScope.cs index 7d3979c..95e21d0 100644 --- a/PorygonSharp/StaticScope.cs +++ b/PorygonSharp/StaticScope.cs @@ -1,7 +1,6 @@ using System; using System.Runtime.InteropServices; using PorygonSharp.EvalValues; -using PorygonSharp.HelperLibraries; using PorygonSharp.Utilities; namespace PorygonSharp diff --git a/PorygonSharp/libPorygonLang.so b/PorygonSharp/libPorygonLang.so index 7a98049..aec19b2 100755 Binary files a/PorygonSharp/libPorygonLang.so and b/PorygonSharp/libPorygonLang.so differ diff --git a/PorygonSharpTests/UnitTest1.cs b/PorygonSharpTests/UnitTest1.cs index 418ef74..50af59c 100644 --- a/PorygonSharpTests/UnitTest1.cs +++ b/PorygonSharpTests/UnitTest1.cs @@ -153,5 +153,21 @@ namespace PorygonSharpTests var hash = "Foo".ScriptHash(); 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); + } + } + } } \ No newline at end of file