summaryrefslogtreecommitdiffstats
path: root/bytecode.h
diff options
context:
space:
mode:
authorStephen Dolan <mu@netsoc.tcd.ie>2012-09-18 17:44:43 +0100
committerStephen Dolan <mu@netsoc.tcd.ie>2012-09-18 17:44:43 +0100
commita4eea165bbab6d13f89b59707e835d58b7014a66 (patch)
treeb99ee5dde8540f8dbe5de3d87b99e04ac4dd2673 /bytecode.h
parent25cbab056b1f73e96b636c88779a92400d92dc15 (diff)
Move everything around - delete old Haskell code, clean up build.
Diffstat (limited to 'bytecode.h')
-rw-r--r--bytecode.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/bytecode.h b/bytecode.h
new file mode 100644
index 00000000..5ffe80a6
--- /dev/null
+++ b/bytecode.h
@@ -0,0 +1,52 @@
+#ifndef BYTECODE_H
+#define BYTECODE_H
+#include <stdint.h>
+
+#include "jv.h"
+#include "opcode.h"
+
+typedef void (*cfunction_ptr)(jv input[], jv output[]);
+
+struct cfunction {
+ cfunction_ptr fptr;
+ const char* name;
+ opcode callop;
+};
+
+#define MAX_CFUNCTION_ARGS 10
+struct symbol_table {
+ struct cfunction* cfunctions;
+ int ncfunctions;
+};
+
+// The bytecode format matters in:
+// execute.c - interpreter
+// compile.c - compiler
+// bytecode.c - disassembler
+
+#define ARG_NEWCLOSURE 0x1000
+
+struct bytecode {
+ uint16_t* code;
+ int codelen;
+
+ int nlocals;
+ int nclosures;
+
+ jv constants; // JSON array of constants
+ struct symbol_table* globals;
+
+ struct bytecode** subfunctions;
+ int nsubfunctions;
+
+ struct bytecode* parent;
+};
+
+void dump_disassembly(int, struct bytecode* code);
+void dump_code(int, struct bytecode* code);
+void dump_operation(struct bytecode* bc, uint16_t* op);
+
+void symbol_table_free(struct symbol_table* syms);
+void bytecode_free(struct bytecode* bc);
+
+#endif