diff options
Diffstat (limited to 'sloth.c')
-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) |