aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-11-28 14:14:17 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-11-28 14:14:17 -0500
commit0b0e0a0a1d41e9574de8dc17c688a4894c5e7f92 (patch)
tree0b7cec7ca42e0eca9aa93ab1d1c84f6b018f12a6
parentabe36dcee146fd1a13c338d8d65cd303dc223ed4 (diff)
Support promoting values to readonly views
-rw-r--r--compile.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/compile.c b/compile.c
index bef60a8a..73a4f02e 100644
--- a/compile.c
+++ b/compile.c
@@ -1577,8 +1577,14 @@ CORD compile_to_type(env_t *env, ast_t *ast, type_t *t)
return compile_int_to_type(env, ast, t);
if (ast->tag == None && Match(ast, None)->type == NULL)
return compile_null(t);
- CORD code = compile(env, ast);
+
type_t *actual = get_type(env, ast);
+
+ // Promote values to views-of-values if needed:
+ if (t->tag == PointerType && Match(t, PointerType)->is_view && actual->tag != PointerType)
+ return CORD_all("stack(", compile_to_type(env, ast, Match(t, PointerType)->pointed), ")");
+
+ CORD code = compile(env, ast);
if (!promote(env, ast, &code, actual, t))
code_err(ast, "I expected a %T here, but this is a %T", t, actual);
return code;