diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/ast.h | 9 | ||||
-rw-r--r-- | include/bytecode/bytecode.h | 8 | ||||
-rw-r--r-- | include/compiler.h | 1 | ||||
-rw-r--r-- | include/ir/ir.h | 6 | ||||
-rw-r--r-- | include/program.h | 2 | ||||
-rw-r--r-- | include/tokenizer.h | 4 |
6 files changed, 25 insertions, 5 deletions
diff --git a/include/ast.h b/include/ast.h index eaaf93e..f56c180 100644 --- a/include/ast.h +++ b/include/ast.h @@ -29,6 +29,7 @@ typedef struct Import Import; typedef struct String String; typedef struct Variable Variable; typedef struct Number Number; +typedef struct AstBool AstBool; typedef struct Binop Binop; typedef struct IfStatement IfStatement; typedef struct ElseIfStatement ElseIfStatement; @@ -47,6 +48,7 @@ typedef union { Import *import; String *string; Number *number; + AstBool *bool; Variable *variable; Binop *binop; IfStatement *if_stmt; @@ -64,6 +66,7 @@ typedef enum { AST_IMPORT, AST_STRING, AST_NUMBER, + AST_BOOL, AST_VARIABLE, AST_BINOP, AST_IF_STATEMENT, @@ -266,6 +269,11 @@ struct Number { BufferView code_ref; }; +struct AstBool { + bool value; + BufferView code_ref; +}; + struct Binop { Ast *lhs; Ast *rhs; @@ -332,6 +340,7 @@ void assignmentexpr_init(AssignmentExpr *self, Ast *lhs_expr, Ast *rhs_expr); void import_init(Import *self, BufferView path); CHECK_RESULT int string_init(String *self, BufferView str); void number_init(Number *self, AmalNumber *value, BufferView code_ref); +void ast_bool_init(AstBool *self, bool value, BufferView code_ref); void variable_init(Variable *self, BufferView name); void binop_init(Binop *self); CHECK_RESULT int if_statement_init(IfStatement *self, Scope *parent, ArenaAllocator *allocator); diff --git a/include/bytecode/bytecode.h b/include/bytecode/bytecode.h index a70bb6f..0547a35 100644 --- a/include/bytecode/bytecode.h +++ b/include/bytecode/bytecode.h @@ -26,8 +26,9 @@ 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) + 6.4 Opcode(u8) + register(AmalReg) + index(u16)\ + 6.5 Opcode(u8) + flags(u8) + num_local_var_reg(u16)\ + 6.6 Opcode(u8) + index(u8) + index(u16) # Registers Registers have a range of 128. Parameters have the most significant bit set while local variables dont. @@ -45,6 +46,7 @@ typedef enum { AMAL_OP_MOV, /* mov dst, src - Move src register to dst register */ AMAL_OP_MOVI, /* movi dst, src - Move src intermediate to dst register */ AMAL_OP_MOVD, /* movd dst, src - Move src data to dst register */ + AMAL_OP_LOADF, /* loadf dst, fi - Move function by index @fi to register @dst. @f1 is u16 */ AMAL_OP_ADD, /* add dst, reg1, reg2 - Add reg1 and reg2 and put the result in dst */ AMAL_OP_SUB, /* sub dst, reg1, reg2 - Substract reg2 from reg1 and put the result in dst */ AMAL_OP_IMUL, /* imul dst, reg1, reg2 - Signed multiplication */ @@ -57,8 +59,8 @@ typedef enum { AMAL_OP_PUSH_RET, /* push_ret reg - Push register as a return value of the next function call */ AMAL_OP_CALL_START, /* call_start num_args - Start of a CALL with @num_args number of arguments. Arguments for the next CALL is pushed immediately after this, followed by a CALL. @num_args is u8 */ AMAL_OP_CALL, /* call ii, fi - Call a function in imported file (ii, import index) using function index (fi). The number of arguments is the number of values pushed to stack. ii is u8, fi is u16 */ - 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_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_EQ, /* eq dst, reg1, reg2 - Set dst to 1 if reg1 equals reg2, otherwise set it to 0 */ AMAL_OP_NEQ, /* neq dst, reg1, reg2 - Set dst to 1 if reg1 is not equal to reg2, otherwise set it to 0 */ AMAL_OP_ILT, /* ilt dst, reg1, reg2 - Set dst to 1 if reg1 is less than reg2 (signed comparison), otherwise set it to 0 */ diff --git a/include/compiler.h b/include/compiler.h index 481a107..3cde9da 100644 --- a/include/compiler.h +++ b/include/compiler.h @@ -22,6 +22,7 @@ typedef struct { } amal_default_type; typedef struct { + amal_default_type *void_type; amal_default_type *i8; amal_default_type *i16; amal_default_type *i32; diff --git a/include/ir/ir.h b/include/ir/ir.h index f7aa4a7..dcc5ea0 100644 --- a/include/ir/ir.h +++ b/include/ir/ir.h @@ -15,6 +15,7 @@ typedef enum { IR_ASSIGN_INTER, IR_ASSIGN_STRING, IR_ASSIGN_REG, + IR_ASSIGN_FUNC, IR_ADD, IR_SUB, IR_IMUL, @@ -39,6 +40,7 @@ typedef enum { IR_CALL_START, IR_CALL, IR_CALL_EXTERN, + IR_CALLR, IR_JUMP_ZERO, IR_JUMP, IR_RET, @@ -161,5 +163,9 @@ typedef struct { /* longjump to context->env on failure */ void scope_generate_ir(Scope *self, IrCompilerContext *context); +/* longjump to context->env on failure */ +void scope_generate_function_ids(Scope *self, IrCompilerContext *context); +/* longjump to context->env on failure */ +void scope_generate_functions_ir(Scope *self, IrCompilerContext *context); #endif diff --git a/include/program.h b/include/program.h index dc65cb7..9104898 100644 --- a/include/program.h +++ b/include/program.h @@ -68,7 +68,7 @@ typedef struct { 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> */ + /* 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; diff --git a/include/tokenizer.h b/include/tokenizer.h index ceb7acf..5d59d73 100644 --- a/include/tokenizer.h +++ b/include/tokenizer.h @@ -22,6 +22,8 @@ typedef enum { TOK_CONST, TOK_VAR, TOK_STRING, + TOK_NUMBER, + TOK_BOOL, TOK_FN, TOK_STRUCT, TOK_EQUALS, @@ -32,7 +34,6 @@ typedef enum { TOK_OPEN_BRACE, TOK_CLOSING_BRACE, TOK_IMPORT, - TOK_NUMBER, TOK_SEMICOLON, TOK_COLON, TOK_BINOP, @@ -66,6 +67,7 @@ struct Tokenizer { BinopType binop_type; } value; AmalNumber number; + bool bool_value; ArenaAllocator *allocator; /* borrowed */ const amal_compiler_options *compiler_options; /* borrowed */ }; |