aboutsummaryrefslogtreecommitdiff
path: root/src/compile
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-10-11 15:31:38 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-10-11 15:31:38 -0400
commit7e8604daeb9239e1669c5414dd6caa37af30c4ff (patch)
tree8fcab61a296381280902a3fc7b2d8456e2a9b227 /src/compile
parent25fa8ace21f0f6874f5b3ad1248e0e5d21190c84 (diff)
Make `{a,b,c}` shorthand for `{a:Empty(), b:Empty(), c:Empty()}` and
display it that way. Same for type annotations.
Diffstat (limited to 'src/compile')
-rw-r--r--src/compile/expressions.c2
-rw-r--r--src/compile/optionals.c2
-rw-r--r--src/compile/tables.c12
3 files changed, 10 insertions, 6 deletions
diff --git a/src/compile/expressions.c b/src/compile/expressions.c
index fcd1d136..108bda80 100644
--- a/src/compile/expressions.c
+++ b/src/compile/expressions.c
@@ -27,7 +27,7 @@ Text_t compile_empty(type_t *t) {
if (t->tag == OptionalType) return compile_none(t);
if (t == PATH_TYPE) return Text("NONE_PATH");
- else if (t == PATH_TYPE_TYPE) return Text("((OptionalPathType_t){})");
+ else if (t == PATH_TYPE_TYPE) return Text("PATHTYPE_ABSOLUTE");
switch (t->tag) {
case BigIntType: return Text("I(0)");
diff --git a/src/compile/optionals.c b/src/compile/optionals.c
index c8a7276c..b4930d02 100644
--- a/src/compile/optionals.c
+++ b/src/compile/optionals.c
@@ -53,7 +53,7 @@ Text_t compile_none(type_t *t) {
if (t == NULL) compiler_err(NULL, NULL, NULL, "I can't compile a `none` value with no type");
if (t == PATH_TYPE) return Text("NONE_PATH");
- else if (t == PATH_TYPE_TYPE) return Text("((OptionalPathType_t){.type = PATHTYPE_NONE})");
+ else if (t == PATH_TYPE_TYPE) return Text("PATHTYPE_NONE");
switch (t->tag) {
case BigIntType: return Text("NONE_INT");
diff --git a/src/compile/tables.c b/src/compile/tables.c
index 2b6d3538..958e5af5 100644
--- a/src/compile/tables.c
+++ b/src/compile/tables.c
@@ -10,8 +10,10 @@
static ast_t *add_to_table_comprehension(ast_t *entry, ast_t *subject) {
DeclareMatch(e, entry, TableEntry);
- return WrapAST(entry, MethodCall, .name = "set", .self = subject,
- .args = new (arg_ast_t, .value = e->key, .next = new (arg_ast_t, .value = e->value)));
+ return WrapAST(
+ entry, MethodCall, .name = "set", .self = subject,
+ .args = new (arg_ast_t, .value = e->key,
+ .next = new (arg_ast_t, .value = e->value ? e->value : WrapAST(entry, Var, .name = "EMPTY"))));
}
Text_t compile_typed_table(env_t *env, ast_t *ast, type_t *table_type) {
@@ -47,8 +49,10 @@ Text_t compile_typed_table(env_t *env, ast_t *ast, type_t *table_type) {
for (ast_list_t *entry = table->entries; entry; entry = entry->next) {
DeclareMatch(e, entry->ast, TableEntry);
- code = Texts(code, ",\n\t{", compile_to_type(key_scope, e->key, key_t), ", ",
- compile_to_type(value_scope, e->value, value_t), "}");
+ code = Texts(
+ code, ",\n\t{", compile_to_type(key_scope, e->key, key_t), ", ",
+ compile_to_type(value_scope, e->value ? e->value : WrapAST(entry->ast, Var, .name = "EMPTY"), value_t),
+ "}");
}
return Texts(code, ")");
}