diff options
author | kdx <kikoodx@paranoici.org> | 2023-01-15 02:09:24 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-01-15 02:09:24 +0100 |
commit | e44e9fbdb4fcdb71bdeba28deeb3dfca8526bbd3 (patch) | |
tree | 5143619a25c06a7278b9109cb7ac553f5bc7c6e0 | |
parent | 49aeb9687849941d73e63669ff1313295e22af76 (diff) | |
download | sloth-main.tar.gz |
-rw-r--r-- | sloth.c | 13 | ||||
-rw-r--r-- | sloth.h | 5 |
2 files changed, 15 insertions, 3 deletions
@@ -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); @@ -15,12 +15,15 @@ typedef struct SlothInstr SlothInstr; struct SlothDict { SlothHash hash; int c_func; + int immediate; SlothError (*func)(Sloth *ctx); SlothInstr *instrs; SlothDict *next; }; #define SLOTH_DICT_C(word, func) \ - (SlothDict){XXH32(word, strlen(word), 0), 1, func, NULL, NULL} + (SlothDict){XXH32(word, strlen(word), 0), 1, 0, func, NULL, NULL} +#define SLOTH_DICT_I(word, func) \ + (SlothDict){XXH32(word, strlen(word), 0), 1, 1, func, NULL, NULL} struct Sloth { SlothByte *stack; |