From 7e8604daeb9239e1669c5414dd6caa37af30c4ff Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 11 Oct 2025 15:31:38 -0400 Subject: Make `{a,b,c}` shorthand for `{a:Empty(), b:Empty(), c:Empty()}` and display it that way. Same for type annotations. --- src/compile/expressions.c | 2 +- src/compile/optionals.c | 2 +- src/compile/tables.c | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) (limited to 'src/compile') 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, ")"); } -- cgit v1.2.3