From 0e83662094b5b48d6170abbcab4cb56a1caec008 Mon Sep 17 00:00:00 2001 From: kdx Date: Sat, 14 Jan 2023 20:12:32 +0100 Subject: exec good --- sloth.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sloth.c b/sloth.c index 9cb045a..e64264c 100644 --- a/sloth.c +++ b/sloth.c @@ -1,4 +1,5 @@ #include "sloth.h" +#include #include #include #include @@ -53,14 +54,23 @@ SlothError sloth_dict_append(Sloth *ctx, SlothDict dict) SlothError sloth_exec(Sloth *ctx, const char *s) { + SlothError err; const SlothHash hash = XXH32(s, strlen(s), 0); for (SlothDict *dict = ctx->dict; dict != NULL; dict = dict->next) if (dict->hash == hash) { - const SlothError err = dict->func(ctx); + err = dict->func(ctx); if (err != NULL) return err; + return NULL; } - return "sloth_exec: unrecognized token"; + for (size_t i = 0; s[i] != '\0'; i++) + if (!isdigit(s[i])) + return "sloth_exec: unrecognized token"; + "a litteral"; + err = sloth_push(ctx, atoi(s)); + if (err != NULL) + return err; + return NULL; } SlothError sloth_exec_line(Sloth *ctx, char *s) -- cgit v1.2.3