aboutsummaryrefslogtreecommitdiff
path: root/sloth.h
diff options
context:
space:
mode:
Diffstat (limited to 'sloth.h')
-rw-r--r--sloth.h24
1 files changed, 21 insertions, 3 deletions
diff --git a/sloth.h b/sloth.h
index 809b99d..8032403 100644
--- a/sloth.h
+++ b/sloth.h
@@ -1,22 +1,40 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
+#include <xxhash.h>
/* Replace '16' by desired byte size on both following lines. */
#define SLOTH_BITS 16
typedef uint16_t SlothByte;
-
+typedef XXH32_hash_t SlothHash;
+typedef struct SlothDict SlothDict;
typedef const char* SlothError;
-typedef struct Sloth {
+typedef struct Sloth Sloth;
+
+struct Sloth {
SlothByte *stack;
size_t stack_size;
size_t stack_capacity;
SlothByte mem[1 << SLOTH_BITS];
-} Sloth;
+ SlothDict *dict;
+};
+
+struct SlothDict {
+ SlothHash hash;
+ int c_func;
+ SlothError (*func)(Sloth *ctx);
+ SlothDict *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_exec(Sloth *ctx, const char *s);
SlothError sloth_exec_line(Sloth *ctx, char *s);
SlothError sloth_pop(Sloth *ctx, SlothByte *v);
SlothError sloth_push(Sloth *ctx, SlothByte v);
+SlothError sloth_add(Sloth *ctx);
+SlothError sloth_write(Sloth *ctx);
void sloth_inspect_stack(const Sloth *ctx);