aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/bytecode/bytecode.h20
-rw-r--r--include/program.h3
-rw-r--r--include/std/buffer_view.h1
3 files changed, 19 insertions, 5 deletions
diff --git a/include/bytecode/bytecode.h b/include/bytecode/bytecode.h
index c495d7a..a93fe4f 100644
--- a/include/bytecode/bytecode.h
+++ b/include/bytecode/bytecode.h
@@ -8,8 +8,8 @@
#include <setjmp.h>
-/*doc(Opcode)
- Variable length opcodes. Sizes range from 1 to 5 bytes.
+/*doc(Instructions)
+ Variable length instructions. Instruction size ranges from 1 to 5 bytes.
# Instruction formats
Instructions can be in 7 different formats:
1. 1 byte: Opcode(u8)
@@ -25,7 +25,8 @@
6.1 Opcode(u8) + register(i8) + label(i16)\
6.2 Opcode(u8) + register(i8) + intermediate(u16)\
6.3 Opcode(u8) + register(i8) + data(u16)\
- 6.4 Opcode(u8) + flags(u8) + num_local_var_reg(u16)
+ 6.4 Opcode(u8) + flags(u8) + num_local_var_reg(u16)\
+ 6.5 Opcode(u8) + stack_offset(i24)
7. 5 bytes: Opcode(u8) + index(u8) + index(u16) + num_args(u8)
# Registers
Registers have a range of 128. Local variables start from register 0 and increment while parameters start from -1
@@ -96,6 +97,19 @@ typedef struct {
/* TODO: Make sure this pragma pack works on all platforms */
#pragma pack(push, 1)
typedef struct {
+ u8 num_params;
+ u32 params_num_pointers;
+ u32 params_fixed_size;
+
+ u8 num_return_types;
+ u32 return_types_num_pointers;
+ u32 return_types_fixed_size;
+} BytecodeHeaderExternFunction;
+#pragma pack(pop)
+
+/* TODO: Make sure this pragma pack works on all platforms */
+#pragma pack(push, 1)
+typedef struct {
u32 function_index;
#define parser_index function_index
u32 extern_function_index;
diff --git a/include/program.h b/include/program.h
index b398a3a..aa318d9 100644
--- a/include/program.h
+++ b/include/program.h
@@ -50,7 +50,6 @@ typedef struct {
typedef struct {
Buffer/*<...>*/ data;
u32 *string_indices;
- u32 *extern_func_indices;
u8 *intermediates_start; /* Reference inside @data */
u8 *strings_start; /* Reference inside @data */
u8 *funcs_start; /* Reference inside @data */
@@ -84,7 +83,7 @@ void amal_program_deinit(amal_program *self);
returns @AMAL_PROGRAM_EXTERN_FUNC_ALREADY_EXISTS if a function with the name @name already exists
in the program
*/
-CHECK_RESULT int amal_program_add_extern_func(amal_program *self, BufferView name, void *func_ptr, int args_byte_size);
+CHECK_RESULT int amal_program_register_extern_func(amal_program *self, BufferView name, void *func_ptr, int args_byte_size);
CHECK_RESULT int amal_program_append_bytecode(amal_program *self, Bytecode *bytecode);
CHECK_RESULT int amal_program_run(amal_program *self);
diff --git a/include/std/buffer_view.h b/include/std/buffer_view.h
index 9c0a722..a54f616 100644
--- a/include/std/buffer_view.h
+++ b/include/std/buffer_view.h
@@ -10,6 +10,7 @@ typedef struct {
BufferView create_buffer_view_null(void);
BufferView create_buffer_view(const char *data, usize size);
+BufferView create_buffer_view_auto(const char *data);
bool buffer_view_equals(const BufferView *self, const BufferView *other);
#endif