diff options
author | dan <[email protected]> | 2023-06-03 14:47:52 -0400 |
---|---|---|
committer | dan <[email protected]> | 2023-06-03 14:47:52 -0400 |
commit | 30553db7c86a70e43f956d385d317a1dfad9b2d0 (patch) | |
tree | 2493d74d5684d6ce82825397707d10a5ddd4a456 /forthmachine_optable.c | |
parent | 48c02f4fccd13cf329594988a19a4edd1fce4774 (diff) | |
download | forth-30553db7c86a70e43f956d385d317a1dfad9b2d0.tar.gz forth-30553db7c86a70e43f956d385d317a1dfad9b2d0.tar.bz2 forth-30553db7c86a70e43f956d385d317a1dfad9b2d0.zip |
feat: optable errors handled with error handlers, not just by printing
Diffstat (limited to 'forthmachine_optable.c')
-rw-r--r-- | forthmachine_optable.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/forthmachine_optable.c b/forthmachine_optable.c index 8164d5c..cd4b46b 100644 --- a/forthmachine_optable.c +++ b/forthmachine_optable.c @@ -1,3 +1,4 @@ +#include "errorhandler.h" #include "forthmachine.h" #include <stdbool.h> #include <stdio.h> @@ -83,12 +84,13 @@ void optable_addop(optable* ot, char* name, int len, char** words) { ot->len++; } -optable* optable_new() { +optable* optable_new(errorhandler errorhandler) { optable* ot = malloc(sizeof(optable)); ot->optable = malloc(sizeof(wordop) * OPTABLE_MAX_SIZE); int inittablesize = sizeof(inittable); ot->len = inittablesize / sizeof(*inittable); memcpy(ot->optable, inittable, inittablesize); + ot->errorhandler = errorhandler; char* defs[] = { ": nip swap drop ;", @@ -363,9 +365,8 @@ void optable_defineop(optable* optable, char *input, int* starti) { } else { // optable->optable bounds check if (optable->len >= OPTABLE_MAX_SIZE) { - // Error - fprintf(stderr, "Error: optable->optable reached max size, failed to create new user defined operation"); - exit(1); + optable->errorhandler("Error: optable->optable reached max size, failed to create new user defined operation"); + return; } // add op to end of table, and increment size optable->optable[optable->len].word = opcode; |