diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2024-03-15 17:27:21 -0400 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2024-03-15 17:27:21 -0400 |
commit | 7b009880ad7a4182d3fa8d84468526d0d30d8844 (patch) | |
tree | 97b28d976e8486d60d0b5c3b7447891dde709309 /compiler.c | |
parent | e25b738656928b38781458ed85880e8ae7bdd5a6 (diff) |
Slightly better function call
Diffstat (limited to 'compiler.c')
-rw-r--r-- | compiler.c | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -1027,7 +1027,7 @@ void _var_op_set_ptr(CompData *out, Variable *store, Variable *from) { int *cur; for (size_t i = store->ptr_chain.count - 1; i > 0; i--) { cur = vect_get(&store->ptr_chain, i - 1); - if (cur == PTYPE_REF) { + if (*cur == PTYPE_REF) { vect_push_string(&out->text, "\tmov rdi, [rdi]\n"); } else { break; @@ -1054,7 +1054,7 @@ void _var_op_set_ptr(CompData *out, Variable *store, Variable *from) { int *cur; for (size_t i = from->ptr_chain.count - 1; i > 0; i--) { cur = vect_get(&store->ptr_chain, i - 1); - if (cur == PTYPE_REF) { + if (*cur == PTYPE_REF) { vect_push_string(&out->text, "\tmov rsi, [rsi]\n"); } else { break; @@ -1544,18 +1544,23 @@ void var_op_mul(CompData *out, Variable *base, Variable *mul) { if(base->type->name[0] == 'i') { // Integer multiplication if (base->location > 0 && mul->location != LOC_LITL) { + char *store = _var_get_store(out, base); + char *from = _var_get_from(out, base, mul); + vect_push_string(&out->text, "\timul "); - vect_push_free_string(&out->text, _var_get_store(out, base)); + vect_push_free_string(&out->text, store); vect_push_string(&out->text, ", "); - vect_push_free_string(&out->text, _var_get_from(out, base, mul)); + vect_push_free_string(&out->text, from); vect_push_string(&out->text, "; complete mul\n\n"); } else if (base->location > 0) { vect_push_string(&out->text, "\tmov rcx, "); vect_push_free_string(&out->text, int_to_str(mul->offset)); vect_push_string(&out->text, "; literal load\n"); + char *store = _var_get_store(out, base); + vect_push_string(&out->text, "\timul "); - vect_push_free_string(&out->text, _var_get_store(out, base)); + vect_push_free_string(&out->text, store); vect_push_string(&out->text, ", "); vect_push_free_string(&out->text, _op_get_register(3, _var_size(base))); vect_push_string(&out->text, "; complete mul\n\n"); @@ -4134,7 +4139,7 @@ Variable _eval_call(Scope *s, CompData *data, Vector *tokens, Function *f, Varia Variable set = scope_mk_stmp(s, data, cur); Variable from = _eval(s, data, tokens, pstart, pend); // eval and set - var_op_pure_set(data, &set, &from); + var_op_set(data, &set, &from); scope_free_to(s, data, &set); var_end(&from); var_end(&set); @@ -4186,7 +4191,7 @@ Variable _eval_call(Scope *s, CompData *data, Vector *tokens, Function *f, Varia Variable set = scope_mk_stmp(s, data, cur); // eval and set Variable from = _eval(s, data, tokens, pstart, pend); - var_op_pure_set(data, &set, &from); + var_op_set(data, &set, &from); // cleanup scope_free_to(s, data, &set); var_end(&from); |