aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-07-18 03:10:03 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commitec1a48e7b86fcd00127dd5a88d56c42083af1d78 (patch)
tree7e6423f20fa795bbba8cbc5ead8bc8a3f7289d2e /include
parent84e65c63e7482590d535e86f7660a00ae8a0cecb (diff)
Setup structure for program execute
Diffstat (limited to 'include')
-rw-r--r--include/ast.h7
-rw-r--r--include/bytecode/bytecode.h5
-rw-r--r--include/program.h22
3 files changed, 30 insertions, 4 deletions
diff --git a/include/ast.h b/include/ast.h
index 2925f6c..f056db7 100644
--- a/include/ast.h
+++ b/include/ast.h
@@ -142,9 +142,12 @@ typedef struct {
} VariableType;
/*
- Note: When resolving AST, more than one thread can end up resolving the same expressions at the same time.
+ Note: When resolving AST, multiple threads can end up resolving the same expressions at the same time.
This is intentional. Instead of using mutex for every expression and locking/unlocking everytime
which uses more memory and affects performance, we assume such race conditions are rare and let them happen.
+ TODO: Investigate possible deadlock when multiple threads resolve the same expression and that
+ expression has a recursive dependency and the threads execute @ast_resolve at the same speed,
+ leading to @ast_resolve running again for the same expression.
*/
struct LhsExpr {
bool is_extern;
@@ -210,7 +213,7 @@ typedef struct {
Parser *parser; /* Borrowed. This is the parser that belongs to the thread */
/*
Borrowed. This is the current scope. Note that this scope can belong to another parser (and thread),
- as such, @parser and scope_get_parser(@scope) parser may not be the same
+ as such, @parser and scope_get_parser(@scope) parser may not be the same.
*/
Scope *scope;
} AstCompilerContext;
diff --git a/include/bytecode/bytecode.h b/include/bytecode/bytecode.h
index 739aa79..b571383 100644
--- a/include/bytecode/bytecode.h
+++ b/include/bytecode/bytecode.h
@@ -21,7 +21,10 @@
4.3 Opcode + index\
4.4 Opcode + offset
5. 4 bytes: Opcode + register + register + register
- 6. 4 bytes: Opcode + register + offset
+ 6. 4 bytes:\
+ 6.1 Opcode + register + offset\
+ 6.2 Opcode + register + intermediate\
+ 6.3 Opcode + register + data
*/
typedef enum {
AMAL_OP_NOP, /* No operation. This can be used for patching */
diff --git a/include/program.h b/include/program.h
index cbd9432..f251fbc 100644
--- a/include/program.h
+++ b/include/program.h
@@ -4,11 +4,31 @@
#include "std/buffer.h"
#include "bytecode/bytecode.h"
+#define AMAL_PROGRAM_OK 0
+#define AMAL_PROGRAM_INVALID_HEADER -1
+#define AMAL_PROGRAM_INVALID_MAGIC_NUMBER -2
+#define AMAL_PROGRAM_INCOMPATIBLE -3
+#define AMAL_PROGRAM_INVALID_INTERMEDIATES -4
+#define AMAL_PROGRAM_INVALID_INTERMEDIATES_SIZE -5
+#define AMAL_PROGRAM_INVALID_STRINGS -6
+#define AMAL_PROGRAM_INVALID_STRINGS_SIZE -7
+#define AMAL_PROGRAM_STRING_ALLOC_FAILURE -8
+#define AMAL_PROGRAM_INVALID_INSTRUCTIONS_SIZE -9
+
+#define AMAL_PROGRAM_MAGIC_NUMBER (u32)0xdec05eba
+#define AMAL_PROGRAM_MAJOR_VERSION 1
+#define AMAL_PROGRAM_MINOR_VERSION 0
+#define AMAL_PROGRAM_PATCH_VERSION 0
+
typedef struct {
Buffer/*<...>*/ data;
+ Buffer/*<u32>*/ string_indices;
+ char *intermediates_start;
+ char *strings_start;
+ usize read_index;
} amal_program;
-void amal_program_init(amal_program *self);
+CHECK_RESULT int amal_program_init(amal_program *self);
void amal_program_deinit(amal_program *self);
CHECK_RESULT int amal_program_append_bytecode(amal_program *self, Bytecode *bytecode);