aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-02-25 12:24:38 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-02-25 12:24:38 -0500
commit394f720fb0bdcc9acfa3614a5ded650383ec8feb (patch)
tree8b0f12c3da6948da3ca01cf34b08017d7c3c2154
parent7704a95a0b904d90fd5793eccdab38dfcf678ac8 (diff)
Make stack references work with local vars
-rw-r--r--compile.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/compile.c b/compile.c
index 6607c1b4..455f13f4 100644
--- a/compile.c
+++ b/compile.c
@@ -175,7 +175,12 @@ CORD compile(env_t *env, ast_t *ast)
case Not: return CORD_asprintf("not(%r)", compile(env, Match(ast, Not)->value));
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: return CORD_asprintf("$stack(%r)", compile(env, Match(ast, StackReference)->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), ")");
+ }
case BinaryOp: {
auto binop = Match(ast, BinaryOp);
CORD lhs = compile(env, binop->lhs);