aboutsummaryrefslogtreecommitdiff
path: root/sloth.h
diff options
context:
space:
mode:
Diffstat (limited to 'sloth.h')
-rw-r--r--sloth.h31
1 files changed, 24 insertions, 7 deletions
diff --git a/sloth.h b/sloth.h
index 0fc4ceb..cc56b76 100644
--- a/sloth.h
+++ b/sloth.h
@@ -10,6 +10,17 @@ typedef XXH32_hash_t SlothHash;
typedef struct SlothDict SlothDict;
typedef const char* SlothError;
typedef struct Sloth Sloth;
+typedef struct SlothInstr SlothInstr;
+
+struct SlothDict {
+ SlothHash hash;
+ int c_func;
+ SlothError (*func)(Sloth *ctx);
+ SlothInstr *instrs;
+ SlothDict *next;
+};
+#define SLOTH_DICT_C(word, func) \
+ (SlothDict){XXH32(word, strlen(word), 0), 1, func, NULL, NULL}
struct Sloth {
SlothByte *stack;
@@ -17,20 +28,24 @@ struct Sloth {
size_t stack_capacity;
SlothByte mem[1 << SLOTH_BITS];
SlothDict *dict;
+ int compile;
+ SlothDict comp;
};
-struct SlothDict {
- SlothHash hash;
- int c_func;
- SlothError (*func)(Sloth *ctx);
- SlothDict *next;
+struct SlothInstr {
+ int litteral;
+ union {
+ SlothByte byte;
+ SlothHash hash;
+ };
+ SlothInstr *next;
};
-#define SLOTH_DICT_C(word, func) \
- (SlothDict){XXH32(word, strlen(word), 0), 1, func, NULL}
SlothError sloth_init(Sloth *ctx);
void sloth_deinit(Sloth *ctx);
SlothError sloth_dict_append(Sloth *ctx, SlothDict dict);
+SlothError sloth_str_to_instr(Sloth *ctx, const char *s, SlothInstr *instr);
+SlothError sloth_exec_instr(Sloth *ctx, const SlothInstr *instr);
SlothError sloth_exec(Sloth *ctx, const char *s);
SlothError sloth_exec_line(Sloth *ctx, char *s);
SlothError sloth_pop(Sloth *ctx, SlothByte *v);
@@ -40,4 +55,6 @@ SlothError sloth_write(Sloth *ctx);
SlothError sloth_store(Sloth *ctx);
SlothError sloth_retrieve(Sloth *ctx);
SlothError sloth_compare(Sloth *ctx);
+SlothError sloth_compile_begin(Sloth *ctx);
+SlothError sloth_compile_end(Sloth *ctx);
void sloth_inspect_stack(const Sloth *ctx);