From 2e69035618e2c94a57a439740e5264e5a9974bb4 Mon Sep 17 00:00:00 2001 From: PopSlime Date: Mon, 3 Apr 2023 17:00:05 +0800 Subject: [PATCH] Returns whether PDT evaluation succeeded. --- Assets/Cryville/Common/Pdt/PdtEvaluatorBase.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Assets/Cryville/Common/Pdt/PdtEvaluatorBase.cs b/Assets/Cryville/Common/Pdt/PdtEvaluatorBase.cs index 525af57..63c3c0d 100644 --- a/Assets/Cryville/Common/Pdt/PdtEvaluatorBase.cs +++ b/Assets/Cryville/Common/Pdt/PdtEvaluatorBase.cs @@ -23,16 +23,18 @@ namespace Cryville.Common.Pdt { /// /// The target operator. /// The expression to evaluate. - public void Evaluate(PdtOperator target, PdtExpression exp) { + /// Whether the evaluaton succeeded. + public bool Evaluate(PdtOperator target, PdtExpression exp) { _framecount = 0; _goffset = 0; _revokepttconst = false; for (_rip = exp.Instructions.First; _rip != null; _rip = _rip.Next) _rip.Value.Execute(this); - Operate(target, _framecount, true); + if (!Operate(target, _framecount, true)) return false; if (exp.IsPotentialConstant) { exp.IsConstant = exp.IsPotentialConstant = !_revokepttconst; } + return true; } /// /// Patches an expression with a lefthand variable and a compound operator. @@ -184,7 +186,7 @@ namespace Cryville.Common.Pdt { /// An operator of the specific name. /// The parameter count of the returned operator does not necessarily equal to . protected abstract PdtOperator GetOperator(PdtOperatorSignature sig); - unsafe void Operate(PdtOperator op, int pc, bool noset = false) { + unsafe bool Operate(PdtOperator op, int pc, bool noset = false) { fixed (byte* pmem = _mem) { op.Begin(this, pc); for (int i = 0; i < pc; i++) { @@ -192,12 +194,13 @@ namespace Cryville.Common.Pdt { if (frame.Type == PdtInternalType.Error) { _framecount -= pc - i; _stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = _goffset, Length = 0 }; - return; + return false; } op.LoadOperand(new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length)); _goffset -= frame.Length; } op.Call(pmem + _goffset, noset); + return true; } } internal unsafe void Collapse(int name, LinkedListNode target) {