aboutsummaryrefslogtreecommitdiff
path: root/sloth.c
diff options
context:
space:
mode:
Diffstat (limited to 'sloth.c')
-rw-r--r--sloth.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/sloth.c b/sloth.c
index 500c327..3ef6334 100644
--- a/sloth.c
+++ b/sloth.c
@@ -43,7 +43,7 @@ SlothError sloth_init(Sloth *ctx)
sloth_deinit(ctx);
return err;
}
- err = sloth_dict_append(ctx, SLOTH_DICT_C(";", sloth_compile_end));
+ err = sloth_dict_append(ctx, SLOTH_DICT_I(";", sloth_compile_end));
if (err != NULL) {
sloth_deinit(ctx);
return err;
@@ -179,12 +179,21 @@ SlothError sloth_compile(Sloth *ctx, const char *s)
return NULL;
}
+static int sloth_is_immediate(Sloth *ctx, const char *s)
+{
+ const SlothHash hash = XXH32(s, strlen(s), 0);
+ for (SlothDict *dict = ctx->dict; dict != NULL; dict = dict->next)
+ if (dict->hash == hash)
+ return dict->immediate;
+ return 0;
+}
+
SlothError sloth_exec_line(Sloth *ctx, char *s)
{
SlothError err = NULL;
static const char *sep = "\t\n\v\f\r ";
for (char *tok = strtok(s, sep); tok != NULL; tok = strtok(NULL, sep)) {
- if (ctx->compile && strcmp(tok, ";") != 0)
+ if (ctx->compile && sloth_is_immediate(ctx, tok))
err = sloth_compile(ctx, tok);
else
err = sloth_exec(ctx, tok);