diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2024-03-28 16:43:34 -0400 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2024-03-28 16:43:34 -0400 |
commit | 6583fe31ad036c3f2dfe2965944fa7db9accf8d3 (patch) | |
tree | c679852197edb932efdc06c77906477bc7c0f304 | |
parent | 331784f2a05f5b18aed46f257f0f6c8173bc2661 (diff) |
Fixes for deref
-rw-r--r-- | compiler.c | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -819,15 +819,15 @@ int _var_size(Variable *var) { if (var->location == LOC_LITL) { return -1; } + size_t count = var->ptr_chain.count; - int *ptype = vect_get(&var->ptr_chain, count - 1); - - while(count > 0 && *ptype == PTYPE_REF) { - ptype = vect_get(&var->ptr_chain, --count); - } - - if(count > 0) { - return 8; + int *ptype; + while(count > 0) { + ptype = vect_get(&var->ptr_chain, count - 1); + if (*ptype != PTYPE_REF) { + return 8; + } + count--; } return var->type->size; @@ -938,8 +938,11 @@ void var_op_dereference(CompData *out, Variable *store, Variable *from) { store->offset = 0; // Keep de-referencing until we reach the pointer (or ptr_chain bottoms out). - int *current = vect_get(&store->ptr_chain, store->ptr_chain.count - 1); - while(*current == PTYPE_REF && store->ptr_chain.count > 1) { + int *current; + while(store->ptr_chain.count > 1) { + current = vect_get(&store->ptr_chain, store->ptr_chain.count - 1); + if (*current != PTYPE_REF) + break; vect_push_string(&out->text, "\tmov rsi, [rsi] ; Dereference\n"); vect_pop(&store->ptr_chain); } |