aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-01-14 20:12:32 +0100
committerkdx <kikoodx@paranoici.org>2023-01-14 20:14:00 +0100
commit0e83662094b5b48d6170abbcab4cb56a1caec008 (patch)
treed9024c07a46de9a9f24a7763d8915c64cfd7c5c8
parent2d40b8053029be33334e143a2ed6ba13bce15e2e (diff)
downloadsloth-0e83662094b5b48d6170abbcab4cb56a1caec008.tar.gz
exec good
-rw-r--r--sloth.c14
1 files 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 <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)