aboutsummaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-02-25 13:04:35 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-02-25 13:04:35 -0500
commitf7d403c35849758d68e3a0ca9a9777bfce7da0b7 (patch)
tree0e9fad4e8e8e447e1ba5d837233f985f98d14d69 /compile.c
parent394f720fb0bdcc9acfa3614a5ded650383ec8feb (diff)
WIP on stackrefs
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/compile.c b/compile.c
index 455f13f4..4163a202 100644
--- a/compile.c
+++ b/compile.c
@@ -176,10 +176,10 @@ CORD compile(env_t *env, ast_t *ast)
case Negative: return CORD_asprintf("-(%r)", compile(env, Match(ast, Negative)->value));
case HeapAllocate: return CORD_asprintf("$heap(%r)", compile(env, Match(ast, HeapAllocate)->value));
case StackReference: {
- ast_t *value = Match(ast, StackReference)->value;
- if (value->tag == Var)
- return CORD_cat("&", compile(env, Match(ast, StackReference)->value));
- return CORD_all("$stack(", compile(env, Match(ast, StackReference)->value), ")");
+ ast_t *subject = Match(ast, StackReference)->value;
+ if (can_be_mutated(env, subject))
+ return CORD_cat("&", compile(env, subject));
+ return CORD_all("$stack(", compile(env, subject), ")");
}
case BinaryOp: {
auto binop = Match(ast, BinaryOp);
@@ -886,7 +886,7 @@ CORD compile(env_t *env, ast_t *ast)
if (index_t->tag != IntType)
code_err(indexing->index, "Arrays can only be indexed by integers, not %T", index_t);
type_t *item_type = Match(container_t, ArrayType)->item_type;
- CORD arr = compile_to_pointer_depth(env, indexing->indexed, 1, false);
+ CORD arr = compile_to_pointer_depth(env, indexing->indexed, 0, false);
CORD index = compile(env, indexing->index);
file_t *f = indexing->index->file;
if (indexing->unchecked)