aboutsummaryrefslogtreecommitdiff
path: root/include/program.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/program.h')
-rw-r--r--include/program.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/program.h b/include/program.h
index e3a4ac9..b398a3a 100644
--- a/include/program.h
+++ b/include/program.h
@@ -35,9 +35,13 @@
#define AMAL_PROGRAM_INVALID_EXPORTED_FUNCTIONS_SIZE -23
#define AMAL_PROGRAM_INSTRUCTION_INVALID_EXPORTED_FUNC_INDEX -24
#define AMAL_PROGRAM_NO_MAIN_FUNC -25
+#define AMAL_PROGRAM_INVALID_IMPORTS -26
+#define AMAL_PROGRAM_SECTION_ERROR -27
#define AMAL_PROGRAM_ARGS_SIZE_VARARGS -1
+#define AMAL_PROGRAM_MAX_RETURN_VALUES 128
+
typedef struct {
void *func;
int args_byte_size; /* -1 if varargs (AMAL_PROGRAM_ARGS_SIZE_VARARGS) */
@@ -49,9 +53,11 @@ typedef struct {
u32 *extern_func_indices;
u8 *intermediates_start; /* Reference inside @data */
u8 *strings_start; /* Reference inside @data */
+ u8 *funcs_start; /* Reference inside @data */
u8 *extern_funcs_start; /* Reference inside @data */
u8 *exported_funcs; /* Reference inside @data */
u8 *exported_funcs_end; /* Reference inside @data */
+ u8 *imports_start; /* Reference inside @data */
usize read_index;
u32 main_func_instruction_offset;
@@ -61,9 +67,14 @@ typedef struct {
u16 num_functions;
u16 num_extern_functions;
u16 num_exported_functions;
+ u8 num_imports;
ArenaAllocator allocator; /* Owned. Used by @extern_funcs_map */
HashMapType(BufferView, ProgramExternFunc) extern_funcs_map;
+ /* key=((func_index<<32)&funcs_start), value=Buffer<u32=current_code_index> */
+ HashMapType(u64, Buffer) deferred_func_calls;
+ i8 return_values_stack[AMAL_PROGRAM_MAX_RETURN_VALUES];
+ int return_value_index;
} amal_program;
CHECK_RESULT int amal_program_init(amal_program *self);