From e8e6feeb95cdc3b81a2c17b5a342a3d0b170ccb4 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Tue, 22 Feb 2022 12:29:23 +0000 Subject: Prepare for error guards --- eval.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'eval.c') 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; } -- cgit v1.2.3