diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-09-29 23:47:52 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | f5dc9ad48db4d22e7d6f15e340063dc7cb14c1e1 (patch) | |
tree | 4465a81a77e936dc2ed6ecd90183ba6af9cc2dae /include | |
parent | c811a743a1528db1d05970e1aa14162ef7c70b75 (diff) |
Implicit cast from str to ?&c_char, fix use of parameters (to use sys v registers)
Diffstat (limited to 'include')
-rw-r--r-- | include/binop_type.h | 3 | ||||
-rw-r--r-- | include/bytecode/bytecode.h | 31 | ||||
-rw-r--r-- | include/ssa/ssa.h | 1 | ||||
-rw-r--r-- | include/tokenizer.h | 1 |
4 files changed, 26 insertions, 10 deletions
diff --git a/include/binop_type.h b/include/binop_type.h index 502392c..94d2b7a 100644 --- a/include/binop_type.h +++ b/include/binop_type.h @@ -7,7 +7,8 @@ typedef enum { BINOP_MUL, BINOP_DIV, BINOP_DOT, - BINOP_EQUALS + BINOP_EQUALS, + BINOP_AND } BinopType; #endif diff --git a/include/bytecode/bytecode.h b/include/bytecode/bytecode.h index 23bc4cf..30f3bb5 100644 --- a/include/bytecode/bytecode.h +++ b/include/bytecode/bytecode.h @@ -10,29 +10,33 @@ /*doc(Instructions) Variable length instructions. Instruction size ranges from 1 to 4 bytes. + # Instruction formats Instructions can be in 7 different formats: 1. 1 byte: Opcode(u8) - 2. 2 bytes: Opcode(u8) + register(i8) - 3. 3 bytes: Opcode(u8) + register(i8) + register(i8) + 2. 2 bytes: Opcode(u8) + register(AmalReg) + 3. 3 bytes: Opcode(u8) + register(AmalReg) + register(AmalReg) 4. 3 bytes:\ 4.1 Opcode(u8) + intermediate(u16)\ 4.2 Opcode(u8) + data(u16)\ 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) + 4.4 Opcode(u8) + register(AmalReg) + num_args(u8) + 5. 4 bytes: Opcode(u8) + register(AmalReg) + register(AmalReg) + register(AmalReg) 6. 4 bytes:\ - 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.1 Opcode(u8) + register(AmalReg) + label(i16)\ + 6.2 Opcode(u8) + register(AmalReg) + intermediate(u16)\ + 6.3 Opcode(u8) + register(AmalReg) + data(u16)\ 6.4 Opcode(u8) + flags(u8) + num_local_var_reg(u16)\ 6.5 Opcode(u8) + index(u8) + index(u16) + # Registers - Registers have a range of 128. Local variables start from register 0 and increment while parameters start from -1 - and decrement. Registers have the scope of functions and reset after instructions reach a new function (AMAL_OP_FUNC_START). + Registers have a range of 128. Parameters have the most significant bit set while local variables dont. + Registers have the scope of functions and reset after instructions reach a new function (AMAL_OP_FUNC_START). If import index for call and calle is 0, then that means the function resides in the same file the function call is being called from. Which means that import index 1 is actually import index 0 into the import list. + + @AmalReg is an alias for u8. */ /* Important: The number of fields in this enum can't exceed 255 */ typedef enum { @@ -56,6 +60,7 @@ typedef enum { AMAL_OP_CALLR, /* callr reg - Call a function using a register. Used for function pointers. The number of arguments is the number of values pushed to stack */ AMAL_OP_CALLE, /* calle ii, efi - Call an extern function in imported file (ii, import index) using extern function index (efi). The number of arguments is the number of values pushed to stack. ii is u8, efi is u16 */ AMAL_OP_CMP, /* cmp dst, reg1, reg2 - Set dst to 1 if reg1 equals reg2, otherwise set it to 0 */ + AMAL_OP_BIT_AND, /* and dst, reg1, reg2 - Perform bit and on reg1 and reg2, store the result in dst */ 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 */ @@ -81,7 +86,15 @@ typedef enum { FUNC_FLAG_VARARGS = 1 << 1 } amal_func_flag; +typedef enum { + REG_FLAG_NONE = 0, + REG_FLAG_PARAM = 1 << 7 +} amal_reg_flag; + typedef u8 AmalOpcodeType; +typedef u8 AmalReg; + +#define AMAL_REG_VALUE(reg) ((reg)&0x7f) /* TODO: Make sure this pragma pack works on all platforms */ #pragma pack(push, 1) diff --git a/include/ssa/ssa.h b/include/ssa/ssa.h index 0ec43b0..c6d58f6 100644 --- a/include/ssa/ssa.h +++ b/include/ssa/ssa.h @@ -22,6 +22,7 @@ typedef enum { SSA_IDIV, SSA_DIV, SSA_EQUALS, + SSA_AND, SSA_FUNC_START, SSA_FUNC_END, SSA_PUSH, diff --git a/include/tokenizer.h b/include/tokenizer.h index 53351a4..4735d6f 100644 --- a/include/tokenizer.h +++ b/include/tokenizer.h @@ -42,6 +42,7 @@ typedef enum { TOK_EXPORT, TOK_RETURN, TOK_QUESTION_MARK, + TOK_AMPERSAND, TOK_C_VARARGS } Token; |