From: Brendan Hansen Date: Mon, 25 Jan 2021 13:56:28 +0000 (-0600) Subject: cleaned up assignment emission X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=bf49f3ef36f77b70d8bea8762506f0c10adb014f;p=onyx.git cleaned up assignment emission --- diff --git a/bin/onyx b/bin/onyx index cbc17971..049fe3fc 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/onyx.exe b/onyx.exe index 2a61a6e6..06570916 100644 Binary files a/onyx.exe and b/onyx.exe differ diff --git a/src/onyxwasm.c b/src/onyxwasm.c index ccfb40eb..43cef707 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -406,59 +406,31 @@ EMIT_FUNC(assignment, AstBinaryOp* assign) { if (lval->kind == Ast_Kind_Local || lval->kind == Ast_Kind_Param) { if (bh_imap_get(&mod->local_map, (u64) lval) & LOCAL_IS_WASM) { - u64 localidx = bh_imap_get(&mod->local_map, (u64) lval); emit_expression(mod, &code, assign->right); + + u64 localidx = bh_imap_get(&mod->local_map, (u64) lval); WIL(WI_LOCAL_SET, localidx); - } else { - u64 offset = 0; - emit_local_location(mod, &code, (AstLocal *) lval, &offset); - emit_expression(mod, &code, assign->right); - emit_store_instruction(mod, &code, lval->type, offset); + *pcode = code; + return; } + } - } else if (lval->kind == Ast_Kind_Global) { - i32 globalidx = (i32) bh_imap_get(&mod->index_map, (u64) lval); - - emit_expression(mod, &code, assign->right); - WID(WI_GLOBAL_SET, globalidx); - - } else if (lval->kind == Ast_Kind_Dereference) { - AstDereference* deref = (AstDereference *) lval; - emit_expression(mod, &code, deref->expr); - emit_expression(mod, &code, assign->right); - - emit_store_instruction(mod, &code, deref->type, 0); - - } else if (lval->kind == Ast_Kind_Array_Access) { - AstArrayAccess* aa = (AstArrayAccess *) lval; - - u64 offset = 0; - emit_array_access_location(mod, &code, aa, &offset); - emit_expression(mod, &code, assign->right); - - emit_store_instruction(mod, &code, aa->type, offset); - - } else if (lval->kind == Ast_Kind_Field_Access) { - AstFieldAccess* field = (AstFieldAccess *) lval; - - u64 offset = 0; - emit_field_access_location(mod, &code, field, &offset); + if (lval->kind == Ast_Kind_Global) { emit_expression(mod, &code, assign->right); - emit_store_instruction(mod, &code, field->type, offset); - - } else if (lval->kind == Ast_Kind_Memres) { - AstMemRes* memres = (AstMemRes *) lval; - - emit_memory_reservation_location(mod, &code, memres); - emit_expression(mod, &code, assign->right); - emit_store_instruction(mod, &code, memres->type, 0); + i32 globalidx = (i32) bh_imap_get(&mod->index_map, (u64) lval); + WID(WI_GLOBAL_SET, globalidx); - } else { - assert(("Invalid lval", 0)); + *pcode = code; + return; } + u64 offset = 0; + emit_location_return_offset(mod, &code, lval, &offset); + emit_expression(mod, &code, assign->right); + emit_store_instruction(mod, &code, lval->type, offset); + *pcode = code; } @@ -492,9 +464,10 @@ EMIT_FUNC(assignment_of_array, AstTyped* left, AstTyped* right) { local_raw_free(mod->local_alloc, WASM_TYPE_INT32); } else { - emit_location(mod, &code, left); + u64 offset = 0; + emit_location_return_offset(mod, &code, left, &offset); emit_expression(mod, &code, right); - emit_array_store(mod, &code, rtype, 0); + emit_array_store(mod, &code, rtype, offset); } *pcode = code; @@ -523,13 +496,14 @@ EMIT_FUNC(compound_assignment, AstBinaryOp* assign) { } } - u64 expr_tmp = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); + WasmType wt = onyx_type_to_wasm_type(lval->type); + u64 expr_tmp = local_raw_allocate(mod->local_alloc, wt); WIL(WI_LOCAL_SET, expr_tmp); u64 offset = 0; emit_location_return_offset(mod, &code, lval, &offset); WIL(WI_LOCAL_GET, expr_tmp); - local_raw_free(mod->local_alloc, WASM_TYPE_INT32); + local_raw_free(mod->local_alloc, wt); emit_store_instruction(mod, &code, lval->type, offset); }