aboutsummaryrefslogtreecommitdiff
path: root/include/bytecode
diff options
context:
space:
mode:
Diffstat (limited to 'include/bytecode')
-rw-r--r--include/bytecode/bytecode.h15
1 files changed, 8 insertions, 7 deletions
diff --git a/include/bytecode/bytecode.h b/include/bytecode/bytecode.h
index 64b54b4..b1b5dda 100644
--- a/include/bytecode/bytecode.h
+++ b/include/bytecode/bytecode.h
@@ -18,18 +18,18 @@
4. 3 bytes:\
4.1 Opcode(u8) + intermediate(u16)\
4.2 Opcode(u8) + data(u16)\
- 4.3 Opcode(u8) + offset(i16)\
+ 4.3 Opcode(u8) + label(i16)\
4.4 Opcode(u8) + register(i8) + num_args(u8)
5. 4 bytes: Opcode(u8) + register(i8) + register(i8) + register(i8)
6. 4 bytes:\
- 6.1 Opcode(u8) + register(i8) + offset(i16)\
+ 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)
7. 5 bytes: Opcode(u8) + index(u16) + num_args(u8) + register(i8)
# Registers
Registers have a range of 128. Local variables start from register 0 and increment while parameters start from -1
- and decrement.
+ and decrement. Registers have the scope of functions and reset after instructions reach a new function (AMAL_OP_FUNC_START).
*/
typedef enum {
AMAL_OP_NOP, /* No operation (do nothing). This can be used for patching code */
@@ -50,11 +50,12 @@ typedef enum {
AMAL_OP_CALLR, /* callr reg, num_args - Call a function using a register. Used for function pointers. num_args is u8 */
AMAL_OP_CALLE, /* calle efi, num_args, dst - Call an extern function using extern function index (efi) and num_args arguments. The result is stored in register dst. efi is u16 and num_args is u8 */
AMAL_OP_CMP, /* cmp dst, reg1, reg2 - Set dst to 1 if reg1 equals reg2, otherwise set it to 0 */
- AMAL_OP_JZ, /* jz reg, offset - Jump to offset if reg is zero. offset is i16 */
- AMAL_OP_JMP, /* jmp offset - Unconditional jump to offset. offset is i16 */
+ AMAL_OP_JZ, /* jz reg, label - Jump to label in the current function if reg is zero. label is u16 */
+ AMAL_OP_JMP, /* jmp label - Unconditional jump to label in the current function. label is u16 */
AMAL_OP_RET, /* ret reg - Return from the function with reg result */
AMAL_OP_FUNC_START, /* func_start flags, num_local_var_reg - Start of a function which has @num_local_var_reg local variable registers allocated and has the flag @flag. @flag is u8 and @num_local_var_reg is u16 */
- AMAL_OP_FUNC_END /* func_end - End of a function. Implementation should do a ret here */
+ AMAL_OP_FUNC_END, /* func_end - End of a function. Implementation should do a ret here */
+ AMAL_OP_LABEL, /* label - Label. This is the target of a jump instruction. Jump instructions only jump to labels in the same function scope */
} AmalOpcode;
#define AMAL_BYTECODE_MAGIC_NUMBER (u32)0xdec05eba
@@ -66,7 +67,7 @@ typedef enum {
typedef enum {
FUNC_FLAG_NONE = 0,
- FUNC_FLAG_EXPORTED = (1 << 1)
+ FUNC_FLAG_EXPORTED = 1 << 0
} amal_func_flag;
typedef u8 AmalOpcodeType;