Pull up error handling in PDT evaluator.
This commit is contained in:
@@ -189,6 +189,11 @@ namespace Cryville.Common.Pdt {
|
||||
op.Begin(this, pc);
|
||||
for (int i = 0; i < pc; i++) {
|
||||
var frame = _stack[--_framecount];
|
||||
if (frame.Type == PdtInternalType.Error) {
|
||||
_framecount -= pc - i;
|
||||
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = _goffset, Length = 0 };
|
||||
return;
|
||||
}
|
||||
op.LoadOperand(new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length));
|
||||
_goffset -= frame.Length;
|
||||
}
|
||||
@@ -198,6 +203,11 @@ namespace Cryville.Common.Pdt {
|
||||
internal unsafe void Collapse(int name, LinkedListNode<PdtInstruction> target) {
|
||||
fixed (byte* pmem = _mem) {
|
||||
var frame = _stack[--_framecount];
|
||||
if (frame.Type == PdtInternalType.Error) {
|
||||
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = _goffset, Length = 0 };
|
||||
_rip = target;
|
||||
return;
|
||||
}
|
||||
if (Collapse(name, new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length))) {
|
||||
_framecount++;
|
||||
_rip = target;
|
||||
|
@@ -101,7 +101,6 @@ namespace Cryville.Crtr {
|
||||
static readonly int _colop_and = IdentifierManager.SharedInstance.Request("&");
|
||||
static readonly int _colop_or = IdentifierManager.SharedInstance.Request("|");
|
||||
protected override bool Collapse(int name, PdtVariableMemory param) {
|
||||
if (param.Type == PdtInternalType.Error) throw new ArgumentException("Error");
|
||||
if (name == _colop_and) return param.Type == PdtInternalType.Number && param.AsNumber() <= 0;
|
||||
else if (name == _colop_or) return param.Type != PdtInternalType.Number || param.AsNumber() > 0;
|
||||
else throw new KeyNotFoundException(string.Format("Undefined collapse operator {0}", IdentifierManager.SharedInstance.Retrieve(name)));
|
||||
@@ -280,7 +279,6 @@ namespace Cryville.Crtr {
|
||||
protected override void Execute() {
|
||||
var o0 = GetOperand(0);
|
||||
int type = o0.Type;
|
||||
if (type == PdtInternalType.Error) throw new InvalidOperationException("Error");
|
||||
int len = o0.Length;
|
||||
bool blit = !IsBlittable(type);
|
||||
for (var i = 1; i < LoadedOperandCount; i++) {
|
||||
@@ -350,10 +348,7 @@ namespace Cryville.Crtr {
|
||||
public func_in_area() : base(1) { }
|
||||
protected override unsafe void Execute() {
|
||||
var arg = GetOperand(0);
|
||||
if (arg.Type == PdtInternalType.Error) {
|
||||
throw new InvalidOperationException("Error");
|
||||
}
|
||||
else if (arg.Type == PdtInternalType.Number && arg.AsNumber() <= 0) {
|
||||
if (arg.Type == PdtInternalType.Number && arg.AsNumber() <= 0) {
|
||||
GetReturnFrame(PdtInternalType.Null, 0);
|
||||
}
|
||||
else {
|
||||
@@ -390,12 +385,8 @@ namespace Cryville.Crtr {
|
||||
class func_is : PdtOperator {
|
||||
public func_is() : base(2) { }
|
||||
protected override unsafe void Execute() {
|
||||
var op0 = GetOperand(0);
|
||||
if (op0.Type == PdtInternalType.Error) throw new ArgumentException("Error");
|
||||
var op1 = GetOperand(1);
|
||||
if (op1.Type == PdtInternalType.Error) throw new ArgumentException("Error");
|
||||
var ret = GetReturnFrame(PdtInternalType.Number, sizeof(float));
|
||||
ret.SetNumber(op0.Equals(op1) ? 1 : 0);
|
||||
GetReturnFrame(PdtInternalType.Number, sizeof(float))
|
||||
.SetNumber(GetOperand(0).Equals(GetOperand(1)) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
Reference in New Issue
Block a user