aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-10-01 13:05:48 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-10-01 13:05:48 -0400
commit6be5430c131311106d720a4573e7509bd8b5a346 (patch)
tree16bf786e5ff69bcc93e05b34a3253c5b6268dbdd /src
parentfb32f766501e089953e8cb0353e60af7bc8fc042 (diff)
Fix up some more none cases
Diffstat (limited to 'src')
-rw-r--r--src/compile/expressions.c12
-rw-r--r--src/compile/lists.c4
-rw-r--r--src/compile/optionals.c6
-rw-r--r--src/compile/tables.c2
-rw-r--r--src/stdlib/text.h2
5 files changed, 13 insertions, 13 deletions
diff --git a/src/compile/expressions.c b/src/compile/expressions.c
index 72fc5e73..b9fafeb8 100644
--- a/src/compile/expressions.c
+++ b/src/compile/expressions.c
@@ -41,9 +41,9 @@ Text_t compile_empty(type_t *t) {
}
case ByteType: return Text("((Byte_t)0)");
case BoolType: return Text("((Bool_t)no)");
- case ListType: return Text("((List_t){.has_value=1})");
- case TableType: return Text("((Table_t){.entries.has_value=1})");
- case TextType: return Text("Text(\"\")");
+ case ListType: return Text("EMPTY_LIST");
+ case TableType: return Text("EMPTY_TABLE");
+ case TextType: return Text("EMPTY_TEXT");
case CStringType: return Text("\"\"");
case PointerType: {
DeclareMatch(ptr, t, PointerType);
@@ -177,7 +177,7 @@ Text_t compile(env_t *env, ast_t *ast) {
}
case List: {
DeclareMatch(list, ast, List);
- if (!list->items) return Text("(List_t){.has_value=1, .length=0}");
+ if (!list->items) return Text("EMPTY_LIST");
type_t *list_type = get_type(env, ast);
return compile_typed_list(env, ast, list_type);
@@ -185,8 +185,8 @@ Text_t compile(env_t *env, ast_t *ast) {
case Table: {
DeclareMatch(table, ast, Table);
if (!table->entries) {
- Text_t code = Text("((Table_t){");
- if (table->fallback) code = Texts(code, ".fallback=heap(", compile(env, table->fallback), ")");
+ Text_t code = Text("((Table_t){.entries=EMPTY_LIST");
+ if (table->fallback) code = Texts(code, ", .fallback=heap(", compile(env, table->fallback), ")");
return Texts(code, "})");
}
diff --git a/src/compile/lists.c b/src/compile/lists.c
index 7bbf0471..d9fb46a3 100644
--- a/src/compile/lists.c
+++ b/src/compile/lists.c
@@ -20,7 +20,7 @@ static ast_t *add_to_list_comprehension(ast_t *item, ast_t *subject) {
public
Text_t compile_typed_list(env_t *env, ast_t *ast, type_t *list_type) {
DeclareMatch(list, ast, List);
- if (!list->items) return Text("(List_t){.has_value=1, .length=0}");
+ if (!list->items) return Text("EMPTY_LIST");
type_t *item_type = Match(list_type, ListType)->item_type;
@@ -48,7 +48,7 @@ list_comprehension: {
LiteralCode(Texts("&", comprehension_name), .type = Type(PointerType, .pointed = list_type, .is_stack = true));
Closure_t comp_action = {.fn = add_to_list_comprehension, .userdata = comprehension_var};
scope->comprehension_action = &comp_action;
- Text_t code = Texts("({ List_t ", comprehension_name, " = {.has_value=1};");
+ Text_t code = Texts("({ List_t ", comprehension_name, " = EMPTY_LIST;");
// set_binding(scope, comprehension_name, list_type, comprehension_name);
for (ast_list_t *item = list->items; item; item = item->next) {
if (item->ast->tag == Comprehension) code = Texts(code, "\n", compile_statement(scope, item->ast));
diff --git a/src/compile/optionals.c b/src/compile/optionals.c
index e855c73c..6ef83b5b 100644
--- a/src/compile/optionals.c
+++ b/src/compile/optionals.c
@@ -99,10 +99,10 @@ Text_t check_none(type_t *t, Text_t value) {
else if (t->tag == ClosureType) return Texts("((", value, ").fn == NULL)");
else if (t->tag == NumType)
return Texts(Match(t, NumType)->bits == TYPE_NBITS64 ? "Num$isnan(" : "Num32$isnan(", value, ")");
- else if (t->tag == ListType) return Texts("!(", value, ").has_value");
- else if (t->tag == TableType) return Texts("!(", value, ").entries.has_value");
+ else if (t->tag == ListType) return Texts("((", value, ").data == NULL)");
+ else if (t->tag == TableType) return Texts("((", value, ").entries.data == NULL)");
else if (t->tag == BoolType) return Texts("((", value, ") == NONE_BOOL)");
- else if (t->tag == TextType) return Texts("!(", value, ").has_value");
+ else if (t->tag == TextType) return Texts("((", value, ").tag == TEXT_NONE)");
else if (t->tag == IntType || t->tag == ByteType || t->tag == StructType) return Texts("(", value, ").is_none");
else if (t->tag == EnumType) {
if (enum_has_fields(t)) return Texts("((", value, ").$tag == 0)");
diff --git a/src/compile/tables.c b/src/compile/tables.c
index 1ceb96b3..2b6d3538 100644
--- a/src/compile/tables.c
+++ b/src/compile/tables.c
@@ -60,7 +60,7 @@ table_comprehension: {
ast_t *comprehension_var =
LiteralCode(Texts("&", comprehension_name), .type = Type(PointerType, .pointed = table_type, .is_stack = true));
- Text_t code = Texts("({ Table_t ", comprehension_name, " = {.entries.has_value=1");
+ Text_t code = Texts("({ Table_t ", comprehension_name, " = {.entries=EMPTY_LIST");
if (table->fallback) code = Texts(code, ", .fallback=heap(", compile(env, table->fallback), "), ");
code = Texts(code, "};");
diff --git a/src/stdlib/text.h b/src/stdlib/text.h
index 75f300eb..821325a9 100644
--- a/src/stdlib/text.h
+++ b/src/stdlib/text.h
@@ -59,7 +59,7 @@ OptionalText_t Text$cluster(Text_t text, Int_t index_int);
const Text_t text = text_expr; \
Int_t index = index_expr; \
OptionalText_t cluster = Text$cluster(text, index); \
- if (unlikely(!cluster.has_value)) \
+ if (unlikely(cluster.tag == TEXT_NONE)) \
fail_source(__SOURCE_FILE__, start, end, "Invalid text index: ", index, " (text has length ", \
(int64_t)text.length, ")\n"); \
cluster; \