forked from ground/ground
Add catch support
This commit is contained in:
@@ -758,7 +758,18 @@ GroundValue interpretGroundProgram(GroundProgram* in, GroundScope* inScope) {
|
||||
instructionsToPause --;
|
||||
int ci = currentInstruction;
|
||||
GroundValue gv = interpretGroundInstruction(in->instructions[i], &scope);
|
||||
if (gv.type != NONE) {
|
||||
if (gv.type == ERROR) {
|
||||
GroundCatch* catch = findCatch(*scope.catches, gv.data.errorVal.type);
|
||||
if (catch != NULL) {
|
||||
currentInstruction = catch->label->lineNum;
|
||||
} else {
|
||||
if (scope.isMainScope) {
|
||||
throwError(&gv.data.errorVal);
|
||||
} else {
|
||||
return gv;
|
||||
}
|
||||
}
|
||||
} else if (gv.type != NONE) {
|
||||
return gv;
|
||||
}
|
||||
if (ci != currentInstruction) {
|
||||
@@ -1964,16 +1975,6 @@ GroundValue interpretGroundInstruction(GroundInstruction inst, GroundScope* scop
|
||||
returnValue.data.errorVal.line = currentInstruction;
|
||||
returnValue.data.errorVal.hasLine = true;
|
||||
returnValue.data.errorVal.where = in;
|
||||
|
||||
GroundCatch* catch = findCatch(*scope->catches, returnValue.data.errorVal.type);
|
||||
if (catch != NULL) {
|
||||
// Jump to label where catch points to
|
||||
currentInstruction = catch->label->lineNum;
|
||||
}
|
||||
|
||||
if (scope->isMainScope) {
|
||||
throwError(&returnValue.data.errorVal);
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
if (returnValue.type != ANY && returnValue.type != function->returnType) {
|
||||
@@ -2451,8 +2452,8 @@ GroundValue interpretGroundInstruction(GroundInstruction inst, GroundScope* scop
|
||||
|
||||
return createErrorGroundValue(
|
||||
createGroundError(
|
||||
in->args.args[0].value.value.data.stringVal,
|
||||
in->args.args[1].value.value.data.stringVal,
|
||||
in->args.args[0].value.value.data.stringVal,
|
||||
in,
|
||||
(size_t*)¤tInstruction
|
||||
)
|
||||
@@ -2478,8 +2479,9 @@ GroundValue interpretGroundInstruction(GroundInstruction inst, GroundScope* scop
|
||||
}
|
||||
|
||||
GroundCatch catch = {
|
||||
.label = label
|
||||
.label = label,
|
||||
};
|
||||
snprintf(catch.id, sizeof(catch.id), "%s", in->args.args[0].value.value.data.stringVal);
|
||||
|
||||
HASH_ADD_STR(*scope->catches, id, &catch);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user