From 559d7f24cf5d3a129fdf7b6cc7c75ecb6ca5a8c5 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 24 Aug 2025 17:27:40 -0400 Subject: Move optional stuff into its file --- src/compile.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) (limited to 'src/compile.c') diff --git a/src/compile.c b/src/compile.c index 35503644..12717b98 100644 --- a/src/compile.c +++ b/src/compile.c @@ -148,26 +148,9 @@ Text_t compile(env_t *env, ast_t *ast) { code_err(ast, "I don't know how to get the negative value of type ", type_to_str(t)); } case HeapAllocate: - case StackReference: { - return compile_typed_allocation(env, ast, get_type(env, ast)); - } - case Optional: { - ast_t *value = Match(ast, Optional)->value; - Text_t value_code = compile(env, value); - return promote_to_optional(get_type(env, value), value_code); - } - case NonOptional: { - ast_t *value = Match(ast, NonOptional)->value; - type_t *t = get_type(env, value); - Text_t value_code = compile(env, value); - int64_t line = get_line_number(ast->file, ast->start); - return Texts("({ ", compile_declaration(t, Text("opt")), " = ", value_code, "; ", "if unlikely (", - check_none(t, Text("opt")), ")\n", "#line ", String(line), "\n", "fail_source(", - quoted_str(ast->file->filename), ", ", String((int64_t)(value->start - value->file->text)), ", ", - String((int64_t)(value->end - value->file->text)), ", ", - "\"This was expected to be a value, but it's none\");\n", optional_into_nonnone(t, Text("opt")), - "; })"); - } + case StackReference: return compile_typed_allocation(env, ast, get_type(env, ast)); + case Optional: return compile_optional(env, ast); + case NonOptional: return compile_non_optional(env, ast); case Power: case Multiply: case Divide: -- cgit v1.2.3