From: Brendan Hansen Date: Tue, 28 Jul 2020 22:14:19 +0000 (-0500) Subject: small updates; removing onyxir X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=03e76d487df4f62fb92d62aaaf443a6540cc6c09;p=onyx.git small updates; removing onyxir --- diff --git a/docs/plan b/docs/plan index b3b3a5b7..5da7f559 100644 --- a/docs/plan +++ b/docs/plan @@ -130,13 +130,13 @@ HOW: bar(member2_of_data); } + [X] Procedures as arguments + [ ] Start work on evaluating compile time known values. - An expression marked COMPTIME will be reduced to its value in the parse tree. [ ] Switch statements - [ ] Procedures as arguments - diff --git a/include/onyxir.h b/include/onyxir.h deleted file mode 100644 index 5a506da1..00000000 --- a/include/onyxir.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef ONYXIR_H -#define ONYXIR_H - -#include "bh.h" -#include "onyxastnodes.h" -#include "onyxtypes.h" -#include "onyxmsgs.h" - -typedef struct IrFunction { - AstFunction* ast_func; - Type* type; - bh_arr(AstLocal *) locals; - AstLocal* first_param; - AstNode* body; - - // NOTE: A function can either be either be: - // Normal - // Intrinsic - // Exported - // Foreign - union { - // NOTE: Set if the function is exported - char* exported_name; - - // NOTE: Set if the function is a foreign - struct { - char* foreign_module; - char* foreign_name; - }; - - // NOTE: Set if the function is intrinsic - OnyxIntrinsic intrinsic; - }; - - u32 is_exported : 1; - u32 is_foreign : 1; - u32 is_intrinsic : 1; - -} IrFunction; - -typedef struct IrContext { - // NOTE: Properties used after ir generation is done - bh_allocator allocator; - - bh_arr(IrFunction *) functions; - - // NOTE: Properties used while ir is generating - IrFunction* curr_function; - - OnyxMessages* msgs; -} IrContext; - - -IrContext ir_context_create(bh_allocator allocator); -void ir_context_free(IrContext* context); -void ir_generate(IrContext* context, ProgramInfo parse_output); - -#endif // #ifndef ONYXIR_H diff --git a/include/onyxwasm.h b/include/onyxwasm.h index c8e4831e..6be722bd 100644 --- a/include/onyxwasm.h +++ b/include/onyxwasm.h @@ -5,7 +5,6 @@ #include "onyxastnodes.h" #include "onyxmsgs.h" -#include "onyxir.h" typedef u8 WasmType; diff --git a/onyx b/onyx index aa0c500c..4aefaecb 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/intrinsics.onyx b/progs/intrinsics.onyx index cb4fce4d..cf4364dc 100644 --- a/progs/intrinsics.onyx +++ b/progs/intrinsics.onyx @@ -1,3 +1,5 @@ +package intrinsics + memory_size :: proc #intrinsic -> i32 --- memory_grow :: proc #intrinsic (val: i32) -> i32 --- diff --git a/src/onyxir.c b/src/onyxir.c deleted file mode 100644 index e326eed7..00000000 --- a/src/onyxir.c +++ /dev/null @@ -1,190 +0,0 @@ -#include "onyxir.h" - -#define IR_FUNC(kind, ...) static void ir_ ## kind (IrContext* c, __VA_ARGS__) - -IR_FUNC(function, AstFunction* ast_func); -IR_FUNC(function_body, AstFunction* fd); -IR_FUNC(block, AstBlock* block); -IR_FUNC(statement, AstNode* stmt); -IR_FUNC(assign_lval, AstTyped* lval); -IR_FUNC(assignment, AstAssign* assign); -IR_FUNC(if, AstIf* if_node); -IR_FUNC(while, AstWhile* while_node); -IR_FUNC(binop, AstBinaryOp* binop); -IR_FUNC(unaryop, AstUnaryOp* unop); -IR_FUNC(call, AstCall* call); -IR_FUNC(intrinsic_call, AstIntrinsicCall* call); -IR_FUNC(expression, AstTyped* expr); -IR_FUNC(cast, AstUnaryOp* cast); -IR_FUNC(return, AstReturn* ret); - -static OnyxIntrinsic intrinsic_lookup(char* name) { - if (!strcmp("memory_size", name)) return ONYX_INTRINSIC_MEMORY_SIZE; - else if (!strcmp("memory_grow", name)) return ONYX_INTRINSIC_MEMORY_GROW; - - else if (!strcmp("clz_i32", name)) return ONYX_INTRINSIC_I32_CLZ; - else if (!strcmp("ctz_i32", name)) return ONYX_INTRINSIC_I32_CTZ; - else if (!strcmp("popcnt_i32", name)) return ONYX_INTRINSIC_I32_POPCNT; - else if (!strcmp("and_i32", name)) return ONYX_INTRINSIC_I32_AND; - else if (!strcmp("or_i32", name)) return ONYX_INTRINSIC_I32_OR; - else if (!strcmp("xor_i32", name)) return ONYX_INTRINSIC_I32_XOR; - else if (!strcmp("shl_i32", name)) return ONYX_INTRINSIC_I32_SHL; - else if (!strcmp("slr_i32", name)) return ONYX_INTRINSIC_I32_SLR; - else if (!strcmp("sar_i32", name)) return ONYX_INTRINSIC_I32_SAR; - else if (!strcmp("rotl_i32", name)) return ONYX_INTRINSIC_I32_ROTL; - else if (!strcmp("rotr_i32", name)) return ONYX_INTRINSIC_I32_ROTR; - - else if (!strcmp("clz_i64", name)) return ONYX_INTRINSIC_I64_CLZ; - else if (!strcmp("ctz_i64", name)) return ONYX_INTRINSIC_I64_CTZ; - else if (!strcmp("popcnt_i64", name)) return ONYX_INTRINSIC_I64_POPCNT; - else if (!strcmp("and_i64", name)) return ONYX_INTRINSIC_I64_AND; - else if (!strcmp("or_i64", name)) return ONYX_INTRINSIC_I64_OR; - else if (!strcmp("xor_i64", name)) return ONYX_INTRINSIC_I64_XOR; - else if (!strcmp("shl_i64", name)) return ONYX_INTRINSIC_I64_SHL; - else if (!strcmp("slr_i64", name)) return ONYX_INTRINSIC_I64_SLR; - else if (!strcmp("sar_i64", name)) return ONYX_INTRINSIC_I64_SAR; - else if (!strcmp("rotl_i64", name)) return ONYX_INTRINSIC_I64_ROTL; - else if (!strcmp("rotr_i64", name)) return ONYX_INTRINSIC_I64_ROTR; - - else if (!strcmp("abs_f32", name)) return ONYX_INTRINSIC_F32_ABS; - else if (!strcmp("ceil_f32", name)) return ONYX_INTRINSIC_F32_CEIL; - else if (!strcmp("floor_f32", name)) return ONYX_INTRINSIC_F32_FLOOR; - else if (!strcmp("trunc_f32", name)) return ONYX_INTRINSIC_F32_TRUNC; - else if (!strcmp("nearest_f32", name)) return ONYX_INTRINSIC_F32_NEAREST; - else if (!strcmp("sqrt_f32", name)) return ONYX_INTRINSIC_F32_SQRT; - else if (!strcmp("min_f32", name)) return ONYX_INTRINSIC_F32_MIN; - else if (!strcmp("max_f32", name)) return ONYX_INTRINSIC_F32_MAX; - else if (!strcmp("copysign_f32", name)) return ONYX_INTRINSIC_F32_COPYSIGN; - - else if (!strcmp("abs_f64", name)) return ONYX_INTRINSIC_F64_ABS; - else if (!strcmp("ceil_f64", name)) return ONYX_INTRINSIC_F64_CEIL; - else if (!strcmp("floor_f64", name)) return ONYX_INTRINSIC_F64_FLOOR; - else if (!strcmp("trunc_f64", name)) return ONYX_INTRINSIC_F64_TRUNC; - else if (!strcmp("nearest_f64", name)) return ONYX_INTRINSIC_F64_NEAREST; - else if (!strcmp("sqrt_f64", name)) return ONYX_INTRINSIC_F64_SQRT; - else if (!strcmp("min_f64", name)) return ONYX_INTRINSIC_F64_MIN; - else if (!strcmp("max_f64", name)) return ONYX_INTRINSIC_F64_MAX; - else if (!strcmp("copysign_f64", name)) return ONYX_INTRINSIC_F64_COPYSIGN; - else return ONYX_INTRINSIC_UNDEFINED; -} - -static void ir_add_local(IrContext* c, AstLocal* local) { - bh_arr_push(c->curr_function->locals, local); -} - -IR_FUNC(ir_function, AstFunction* ast_func) { - IrFunction* func = bh_alloc_item(c->allocator, IrFunction); - - func->ast_func = ast_func; - func->body = ast_func->body->body; - func->first_param = ast_func->params; - - // NOTE: This is actually the return type (for now) - func->type = ast_func->base.type; - - func->locals = NULL; - bh_arr_new(c->allocator, func->locals, 4); - - func->is_exported = (ast_func->base.flags & Ast_Flag_Exported) != 0; - func->is_foreign = (ast_func->base.flags & Ast_Flag_Foreign) != 0; - func->is_intrinsic = (ast_func->base.flags & Ast_Flag_Intrinsic) != 0; - - if (func->is_intrinsic) { - token_toggle_end(ast_func->base.token); - func->intrinsic = intrinsic_lookup(ast_func->base.token->text); - token_toggle_end(ast_func->base.token); - } - - else if (func->is_exported) { - token_toggle_end(ast_func->base.token); - func->exported_name = bh_aprintf(c->allocator, "%s", ast_func->base.token->text); - token_toggle_end(ast_func->base.token); - } - - else if (func->is_foreign) { - token_toggle_end(ast_func->foreign_module); - func->foreign_module = bh_aprintf(c->allocator, "%s", ast_func->foreign_module); - token_toggle_end(ast_func->foreign_module); - - token_toggle_end(ast_func->foreign_name); - func->foreign_module = bh_aprintf(c->allocator, "%s", ast_func->foreign_name); - token_toggle_end(ast_func->foreign_name); - } - - if (func->body != NULL) { - c->curr_function = func; - } -} - -IR_FUNC(function_body, AstFunction* fd) { - if (fd->body == NULL) return; - ir_block(c, fd->body); -} - -IR_FUNC(block, AstBlock* block) { - forll (AstLocal, local, block->locals->last_local, prev_local) { - ir_add_local(c, local); - } - - forll (AstNode, stmt, block->body, next) { - ir_statement(c, stmt); - } -} - -IR_FUNC(statement, AstNode* stmt) { - switch (stmt->kind) { - case Ast_Kind_Return: return ir_return(c, (AstReturn *) stmt); - case Ast_Kind_Assignment: return ir_assignment(c, (AstAssign *) stmt); - case Ast_Kind_If: return ir_if(c, (AstIf *) stmt); - case Ast_Kind_While: return ir_while(c, (AstWhile *) stmt); - case Ast_Kind_Block: return ir_block(c, (AstBlock *) stmt); - - default: break; - } -} - -IR_FUNC(if, AstIf* if_node) { - if (if_node->true_block.as_if->base.kind == Ast_Kind_Block) { - ir_block(c, if_node->true_block.as_block); - } - - if (if_node->false_block.as_if->base.kind == Ast_Kind_Block) { - ir_block(c, if_node->false_block.as_block); - } -} - -IR_FUNC(while, AstWhile* while_node) { - ir_block(c, while_node->body); -} - -// NOTE: Currently, these functions don't have anything to -// do so they are empty and not called. When I have a reason -// to use them, I will populate their bodies -IR_FUNC(assign_lval, AstTyped* lval) {} -IR_FUNC(assignment, AstAssign* assign) {} -IR_FUNC(binop, AstBinaryOp* binop) {} -IR_FUNC(unaryop, AstUnaryOp* unop) {} -IR_FUNC(expression, AstTyped* expr) {} -IR_FUNC(cast, AstUnaryOp* cast) {} -IR_FUNC(return, AstReturn* ret) {} - -IrContext ir_context_create(bh_allocator allocator) { - IrContext context = { - .allocator = allocator, - .functions = NULL, - - .curr_function = NULL, - }; - - bh_arr_new(allocator, context.functions, 4); - - return context; -} - -void ir_context_free(IrContext* context) { - bh_arr_free(context.functions); -} - -void ir_generate(IrContext* context, ParserOutput parse_output) { - -}