aboutsummaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-04-30 13:18:47 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-04-30 13:18:47 -0400
commit2e27b88c1b9fa8ec9b9f243909f5b793b376f207 (patch)
treef70433489c8a1fbf3bae6bf4cce364f6bdf8c9f7 /compile.c
parent3c0a8f0b899a343f43caf9c95147b2cf77a7b525 (diff)
Improved syntax for optionals
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/compile.c b/compile.c
index 1e46be1c..dec8ea46 100644
--- a/compile.c
+++ b/compile.c
@@ -1014,6 +1014,9 @@ CORD compile(env_t *env, ast_t *ast)
return CORD_all("(&", compile(env, subject), ")");
return CORD_all("stack(", compile(env, subject), ")");
}
+ case Optional: {
+ return compile(env, Match(ast, Optional)->value);
+ }
case BinaryOp: {
auto binop = Match(ast, BinaryOp);
CORD lhs = compile(env, binop->lhs);
@@ -1929,9 +1932,12 @@ CORD compile_type_info(env_t *env, type_t *t)
}
case PointerType: {
auto ptr = Match(t, PointerType);
- CORD sigil = ptr->is_stack ? "&" : (ptr->is_optional ? "?" : "@");
+ CORD sigil = ptr->is_stack ? "&" : "@";
if (ptr->is_readonly) sigil = CORD_cat(sigil, "%");
- return CORD_asprintf("$PointerInfo(%r, %r)", Text$quoted(sigil, false), compile_type_info(env, ptr->pointed));
+ return CORD_asprintf("$PointerInfo(%r, %r, %s)",
+ Text$quoted(sigil, false),
+ compile_type_info(env, ptr->pointed),
+ ptr->is_optional ? "yes" : "no");
}
case FunctionType: {
return CORD_asprintf("$FunctionInfo(%r)", Text$quoted(type_to_cord(t), false));