diff options
author | kdx <kikoodx@paranoici.org> | 2023-01-14 20:12:32 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-01-14 20:14:00 +0100 |
commit | 0e83662094b5b48d6170abbcab4cb56a1caec008 (patch) | |
tree | d9024c07a46de9a9f24a7763d8915c64cfd7c5c8 | |
parent | 2d40b8053029be33334e143a2ed6ba13bce15e2e (diff) | |
download | sloth-0e83662094b5b48d6170abbcab4cb56a1caec008.tar.gz |
exec good
-rw-r--r-- | sloth.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -1,4 +1,5 @@ #include "sloth.h" +#include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -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) |