Introduce IdentifierManager to improve PDT evaluator performance.

This commit is contained in:
2022-11-01 13:47:04 +08:00
parent 3bfc7eb643
commit 2c9be2ef1e
12 changed files with 229 additions and 145 deletions

View File

@@ -47,7 +47,7 @@ namespace Cryville.Common.Pdt {
var i = _rip.Value;
if (i is PdtInstruction.Operate) {
int fc0 = _framecount;
int fc1 = ((PdtInstruction.Operate)i).ParamCount;
int fc1 = ((PdtInstruction.Operate)i).Signature.ParamCount;
try { i.Execute(this); } catch (Exception) { }
if (fc0 - _framecount == fc1) {
unsafe {
@@ -137,7 +137,7 @@ namespace Cryville.Common.Pdt {
_goffset += value.Length;
}
}
internal unsafe void PushVariable(ref string name) {
internal unsafe void PushVariable(int name) {
fixed (StackFrame* frame = &_stack[_framecount++]) {
byte[] value;
GetVariable(name, out frame->Type, out value);
@@ -153,12 +153,12 @@ namespace Cryville.Common.Pdt {
/// <param name="name">The name of the variable.</param>
/// <param name="type">The type of the variable.</param>
/// <param name="value">The value of the variable.</param>
protected abstract void GetVariable(string name, out int type, out byte[] value);
internal void Operate(ref string name, int pc) {
protected abstract void GetVariable(int name, out int type, out byte[] value);
internal void Operate(PdtOperatorSignature sig) {
PdtOperator op;
try { op = GetOperator(name, pc); }
catch (Exception) { _framecount -= pc; return; }
Operate(op, pc);
try { op = GetOperator(sig); }
catch (Exception) { _framecount -= sig.ParamCount; return; }
Operate(op, sig.ParamCount);
}
/// <summary>
/// Gets an operator of the specified name and the suggested parameter count.
@@ -167,7 +167,7 @@ namespace Cryville.Common.Pdt {
/// <param name="pc">Suggested parameter count.</param>
/// <returns>An operator of the specific name.</returns>
/// <remarks>The parameter count of the returned operator does not necessarily equal to <paramref name="pc" />.</remarks>
protected abstract PdtOperator GetOperator(string name, int pc);
protected abstract PdtOperator GetOperator(PdtOperatorSignature sig);
unsafe void Operate(PdtOperator op, int pc, bool noset = false) {
fixed (byte* pmem = _mem) {
op.Begin(this);
@@ -179,7 +179,7 @@ namespace Cryville.Common.Pdt {
op.Call(pmem + _goffset, noset);
}
}
internal unsafe void Collapse(ref string name, LinkedListNode<PdtInstruction> target) {
internal unsafe void Collapse(int name, LinkedListNode<PdtInstruction> target) {
fixed (byte* pmem = _mem) {
var frame = _stack[--_framecount];
if (Collapse(name, new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length))) {
@@ -194,7 +194,7 @@ namespace Cryville.Common.Pdt {
/// <param name="name">The name of the collapse operator.</param>
/// <param name="param">The top frame in the stack as the parameter.</param>
/// <returns>Whether to jump to the target of the collapse instruction.</returns>
protected abstract bool Collapse(string name, PdtVariableMemory param);
protected abstract bool Collapse(int name, PdtVariableMemory param);
internal unsafe PdtVariableMemory StackAlloc(int type, byte* ptr, int len) {
fixed (StackFrame* frame = &_stack[_framecount++]) {
frame->Type = type;