aboutsummaryrefslogtreecommitdiffstats
path: root/optable.h
diff options
context:
space:
mode:
authordan <[email protected]>2023-05-25 11:00:58 -0400
committerdan <[email protected]>2023-05-25 11:00:58 -0400
commit40e23d550506659f7a33057bbbc23cb1cf0632f1 (patch)
treec7c7a53e78f7186b352c9e6a43113d6679257231 /optable.h
parent7463bbc06285690b5b644362d115aa9e82ac6cb4 (diff)
downloadforth-40e23d550506659f7a33057bbbc23cb1cf0632f1.tar.gz
forth-40e23d550506659f7a33057bbbc23cb1cf0632f1.tar.bz2
forth-40e23d550506659f7a33057bbbc23cb1cf0632f1.zip
refactor: split optable and stack into sep files
Diffstat (limited to 'optable.h')
-rw-r--r--optable.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/optable.h b/optable.h
new file mode 100644
index 0000000..d85ff3d
--- /dev/null
+++ b/optable.h
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <stdbool.h>
+#include "stack.h"
+
+#ifndef OPTABLE_H
+#define OPTABLE_H
+
+#define OPTABLE_MAX_SIZE 1024
+#define DEFINED_FUNC_MAX_LENGTH 1024
+#define WORD_LEN_LIMIT 255
+
+typedef void (*stackop)(stack *);
+
+typedef struct {
+ char* word;
+ bool isscript;
+ union {
+ stackop op;
+ struct {
+ char* script;
+ int scriptlen;
+ };
+ };
+} wordop;
+
+/**
+ * defineop reads a function identifier, followed by the commands to run when the function
+ * is called, stopping when a semicolon is reached.
+ * Reading is done from the input string.
+ *
+ * returns new position of input index
+ *
+ */
+int defineop(int starti, char *input);
+
+/**
+ * getop returns the first wordop in the optable which is called by the word given as a parameter
+ * if none exist, returns 0
+ */
+wordop* getop(char *word);
+
+#endif //OPTABLE_H