Implements new debug string that outlines the bound script

This commit is contained in:
Deukhoofd 2019-09-07 12:18:28 +02:00
parent 8f5c165d39
commit 93ae52b04a
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
4 changed files with 29 additions and 2 deletions

View File

@ -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);
}
}

View File

@ -1,7 +1,6 @@
using System;
using System.Runtime.InteropServices;
using PorygonSharp.EvalValues;
using PorygonSharp.HelperLibraries;
using PorygonSharp.Utilities;
namespace PorygonSharp

Binary file not shown.

View File

@ -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);
}
}
}
}