summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2024-03-28 16:43:34 -0400
committerKyle Gunger <kgunger12@gmail.com>2024-03-28 16:43:34 -0400
commit6583fe31ad036c3f2dfe2965944fa7db9accf8d3 (patch)
treec679852197edb932efdc06c77906477bc7c0f304
parent331784f2a05f5b18aed46f257f0f6c8173bc2661 (diff)
Fixes for deref
-rw-r--r--compiler.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/compiler.c b/compiler.c
index 6bcb201..2a524b8 100644
--- a/compiler.c
+++ b/compiler.c
@@ -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);
}