summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authorPeter Mikkelsen <petermikkelsen10@gmail.com>2022-02-22 12:29:23 +0000
committerPeter Mikkelsen <petermikkelsen10@gmail.com>2022-02-22 12:29:23 +0000
commite8e6feeb95cdc3b81a2c17b5a342a3d0b170ccb4 (patch)
tree8952eb98e03c3153143e8d5598988ef537153135 /eval.c
parent67cbbe89c1b876b88557def75ec376d9f3330588 (diff)
Prepare for error guards
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/eval.c b/eval.c
index 58a745b..4131871 100644
--- a/eval.c
+++ b/eval.c
@@ -113,24 +113,36 @@ retry:
int guardOK = 1;
if(stmt->toks[0]->tag != ArrayTag)
guardOK = 0;
- else if(GetSize(stmt->toks[0]->array) != 1)
+ else if(!stmt->errorguard && GetSize(stmt->toks[0]->array) != 1)
+ guardOK = 0;
+ else if(stmt->errorguard && GetSize(stmt->toks[0]->array) < 1)
guardOK = 0;
else if(GetType(stmt->toks[0]->array) != AtypeInt)
guardOK = 0;
- else if(stmt->toks[0]->array->intdata[0] != 0 && stmt->toks[0]->array->intdata[0] != 1)
+ else if(!stmt->errorguard && stmt->toks[0]->array->intdata[0] != 0 && stmt->toks[0]->array->intdata[0] != 1)
guardOK = 0;
- if(!guardOK)
- throwerror(L"Guard expected single valued boolean", EDomain);
- else{
+ if(!guardOK){
+ if(!stmt->errorguard)
+ throwerror(L"Guard expected single valued boolean", EDomain);
+ else
+ throwerror(L"Error guard expected an array of error numbers", EDomain);
+ }else{
stop = 0;
- if(stmt->toks[0]->array->intdata[0] == 1)
- return eval(stmt->guard, toplevel);
+ if(!stmt->errorguard){
+ if(stmt->toks[0]->array->intdata[0] == 1)
+ return eval(stmt->guard, toplevel);
+ }else
+ print("Not registering error guard for error codes: %S\n", ppdatum(stmt->toks[0]));
}
}
if(stmt->next && !stop)
return eval(stmt->next, toplevel);
- else
+ else if(!stmt->guard)
return stmt->toks[0];
+ else{
+ throwerror(L"No value produced", EValue);
+ return nil;
+ }
}else
return nil;
}