From 30553db7c86a70e43f956d385d317a1dfad9b2d0 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 3 Jun 2023 14:47:52 -0400 Subject: feat: optable errors handled with error handlers, not just by printing --- forthmachine_optable.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'forthmachine_optable.c') 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 #include @@ -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; -- cgit v1.2.3