about summary refs log tree commit diff
path: root/boot
diff options
context:
space:
mode:
authorMel <mel@rnrd.eu>2026-05-04 18:39:54 +0200
committerMel <mel@rnrd.eu>2026-05-04 18:39:54 +0200
commit06eff276ce3440df22674572a660e86fc21637d5 (patch)
tree43b7821dcaf9bb9a2600ee7a684d82469069e77d /boot
parent8a69b17ff0ce5c132391124f3c89e03338dede19 (diff)
downloadcatskill-06eff276ce3440df22674572a660e86fc21637d5.tar.zst
catskill-06eff276ce3440df22674572a660e86fc21637d5.zip
Initial lowering pass 2 implementation, create shells for source expressions and statements
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'boot')
-rw-r--r--boot/common.c9
-rw-r--r--boot/lower.c137
-rw-r--r--boot/visit/ir.c156
-rw-r--r--boot/visit/tree.c60
4 files changed, 232 insertions, 130 deletions
diff --git a/boot/common.c b/boot/common.c
index 3da5750..0524b3b 100644
--- a/boot/common.c
+++ b/boot/common.c
@@ -337,11 +337,10 @@ _slice_at(const struct _Slice* slice, uint index)
 #define slice_at(type, slice, index) ((type*)_slice_at(slice, index))
 
 // a macro for iterating over each element in an array.
-#define FOR_EACH_ARRAY(type, element_var, array_ptr, action) \
-    for (uint i = 0; i < array_length(array_ptr); ++i) {     \
-        type element_var = *array_at(type, array_ptr, i);    \
-        action;                                              \
-    }
+// for each iteration you get a pointer to the current element.
+#define FOR_EACH_ARRAY(type, element_var, array_ptr)   \
+    for (type* element_var = (type*)(array_ptr)->data; \
+         element_var < (type*)(array_ptr)->data + array_length(array_ptr); ++element_var)
 
 // the global string region.
 REGION(ascii, string)
diff --git a/boot/lower.c b/boot/lower.c
index 1218281..3820408 100644
--- a/boot/lower.c
+++ b/boot/lower.c
@@ -62,24 +62,24 @@ lower_emit_error_c(struct Unit* unit, struct Span span, const ascii* message)
 bool
 lower_type_lookup_by_name(struct Unit* unit, struct String name, Type_Id* out_id)
 {
-    FOR_EACH_ARRAY(struct Type_Name_To_Id, mapping, &unit->types.by_name, {
-        if (string_equals(mapping.name, name)) {
-            *out_id = mapping.id;
+    FOR_EACH_ARRAY (struct Type_Name_To_Id, mapping, &unit->types.by_name) {
+        if (string_equals(mapping->name, name)) {
+            *out_id = mapping->id;
             return true;
         }
-    })
+    }
     return false;
 }
 
 bool
 lower_function_lookup_by_name(struct Unit* unit, struct String name, Function_Id* out_id)
 {
-    FOR_EACH_ARRAY(struct Function_Name_To_Id, mapping, &unit->functions.by_name, {
-        if (string_equals(mapping.name, name)) {
-            *out_id = mapping.id;
+    FOR_EACH_ARRAY (struct Function_Name_To_Id, mapping, &unit->functions.by_name) {
+        if (string_equals(mapping->name, name)) {
+            *out_id = mapping->id;
             return true;
         }
-    })
+    }
     return false;
 }
 
@@ -192,7 +192,8 @@ lower_synthesize_type_name(struct Lower_Context* ctx)
     const ascii* synthetic_type_name_template = "__cat_type_%lu";
 
     ascii name_buf[64];
-    snprintf(name_buf, sizeof name_buf, synthetic_type_name_template, ctx->synthetic_type_counter++);
+    snprintf(
+        name_buf, sizeof name_buf, synthetic_type_name_template, ctx->synthetic_type_counter++);
     return string_from_c_string(name_buf);
 }
 
@@ -201,9 +202,9 @@ lower_synthesize_type_name(struct Lower_Context* ctx)
 Type_Id
 lower_synthesize_structural(struct Lower_Context* ctx, struct Tree_Type* tree_type, uint64 hash)
 {
-    FOR_EACH_ARRAY(struct Type_Hash_To_Id, mapping, &ctx->unit->types.by_hash, {
-        if (mapping.hash == hash) return mapping.id;
-    })
+    FOR_EACH_ARRAY (struct Type_Hash_To_Id, mapping, &ctx->unit->types.by_hash) {
+        if (mapping->hash == hash) return mapping->id;
+    }
 
     Type_Id id = array_length(&ctx->unit->types.entries);
     struct String name = lower_synthesize_type_name(ctx);
@@ -254,7 +255,7 @@ lower_synthesize_structural(struct Lower_Context* ctx, struct Tree_Type* tree_ty
             .type_id = inner.type_id,
             .mods = array_new(enum Type_Modifier, 4),
         };
-        FOR_EACH_ARRAY(enum Type_Modifier, m, &inner.mods, { array_push(&data_ref.mods, &m); })
+        FOR_EACH_ARRAY (enum Type_Modifier, m, &inner.mods) array_push(&data_ref.mods, m);
         enum Type_Modifier ptr = TYPE_MOD_REFERENCE;
         array_push(&data_ref.mods, &ptr);
 
@@ -317,7 +318,8 @@ lower_synthesize_structural(struct Lower_Context* ctx, struct Tree_Type* tree_ty
         struct Tree_Function_Header* header = &tree_type->value.function.header;
 
         type->value.function.return_type = lower_intern_type_ref(ctx, header->return_type);
-        lower_add_dependency(type, type->value.function.return_type); // possibly hard dependency on return
+        // possibly hard dependency on return type
+        lower_add_dependency(type, type->value.function.return_type);
 
         type->value.function.params = array_new(struct Type_Ref, 16);
         bool variadic = false;
@@ -664,6 +666,88 @@ lower_pass_1(struct Lower_Context* ctx, struct Tree* tree)
     lower_pass_1_fill_bodies(ctx, tree);
 }
 
+struct Block* lower_block(struct Lower_Context* ctx, struct Tree_Block* tree_block);
+struct Statement* lower_statement(struct Lower_Context* ctx, struct Tree_Statement* tree_stmt);
+
+// turns a source expression into the lowered form.
+struct Expression*
+lower_expression(struct Lower_Context* ctx, struct Tree_Expression* tree_expr)
+{
+    // TODO: implement all the expressions
+    switch (tree_expr->kind) {
+    case TREE_EXPRESSION_INTEGER_LITERAL: {
+        union Expression_Value v = { 0 };
+        v.integer_literal.value = tree_expr->value.integer_literal.value;
+        return expression_new(EXPRESSION_INTEGER_LITERAL, v, tree_expr->span);
+    }
+    case TREE_EXPRESSION_FLOAT_LITERAL: {
+        union Expression_Value v = { 0 };
+        v.float_literal.value = tree_expr->value.float_literal.value;
+        return expression_new(EXPRESSION_FLOAT_LITERAL, v, tree_expr->span);
+    }
+    case TREE_EXPRESSION_STRING_LITERAL: {
+        union Expression_Value v = { 0 };
+        v.string_literal.value = tree_expr->value.string_literal.value;
+        return expression_new(EXPRESSION_STRING_LITERAL, v, tree_expr->span);
+    }
+    case TREE_EXPRESSION_BOOLEAN_LITERAL: {
+        union Expression_Value v = { 0 };
+        v.bool_literal.value = tree_expr->value.bool_literal.value;
+        return expression_new(EXPRESSION_BOOLEAN_LITERAL, v, tree_expr->span);
+    }
+    case TREE_EXPRESSION_NAME: {
+        union Expression_Value v = { 0 };
+        v.name.name = tree_expr->value.name.name;
+        return expression_new(EXPRESSION_NAME, v, tree_expr->span);
+    }
+    default:
+        lower_emit_error_c(ctx->unit, tree_expr->span, "unimplemented: this expression kind");
+        return nil;
+    }
+}
+
+// turns a source statement into the lowered form.
+struct Statement*
+lower_statement(struct Lower_Context* ctx, struct Tree_Statement* tree_stmt)
+{
+    // TODO: implement all the statements
+    switch (tree_stmt->kind) {
+    case TREE_STATEMENT_RETURN: {
+        union Statement_Value v = { 0 };
+        if (tree_stmt->value.return_value.value)
+            v.return_value.value = lower_expression(ctx, tree_stmt->value.return_value.value);
+        return statement_new(STATEMENT_RETURN, v, tree_stmt->span);
+    }
+    default:
+        lower_emit_error_c(ctx->unit, tree_stmt->span, "unimplemented: this statement kind");
+        return nil;
+    }
+}
+
+// turns a source block of statements into the lowered form of a block.
+struct Block*
+lower_block(struct Lower_Context* ctx, struct Tree_Block* tree_block)
+{
+    struct Block* block = block_new();
+    block->statements = array_new(struct Statement*, 16);
+
+    FOR_EACH (struct Tree_Statement*, tree_stmt, tree_block->statements) {
+        struct Statement* stmt = lower_statement(ctx, tree_stmt);
+        if (stmt) array_push(&block->statements, &stmt);
+    }
+    return block;
+}
+
+// lowering pass 2
+// walks every collected function's source body and produces a lowered statement block.
+void
+lower_pass_2(struct Lower_Context* ctx)
+{
+    FOR_EACH_ARRAY (struct Function*, fn, &ctx->unit->functions.entries) {
+        if ((*fn)->ast_body) (*fn)->body = lower_block(ctx, (*fn)->ast_body);
+    }
+}
+
 // return line number for the given byte position in the source. (1-based)
 uint
 lower_span_to_line(struct String source, struct Span span)
@@ -745,10 +829,10 @@ lower_topological_sort_dependency_graph(struct Unit* unit, struct Source_File so
     for (uint i = 0; i < n; ++i) {
         struct Type* type = *array_at(struct Type*, &unit->types.entries, i);
         Type_Id me = (Type_Id)i;
-        FOR_EACH_ARRAY(Type_Id, dep, &type->depends_on, {
-            struct _Array* slot = array_at(struct _Array, &reverse_deps, dep);
+        FOR_EACH_ARRAY (Type_Id, dep, &type->depends_on) {
+            struct _Array* slot = array_at(struct _Array, &reverse_deps, *dep);
             _array_push(slot, &me);
-        })
+        }
     }
 
     uint output_count = 0;
@@ -767,10 +851,10 @@ lower_topological_sort_dependency_graph(struct Unit* unit, struct Source_File so
         *array_at(uint, &in_degree, chosen) = done_sentinel;
 
         struct _Array* dependents = array_at(struct _Array, &reverse_deps, chosen);
-        FOR_EACH_ARRAY(Type_Id, dependent, dependents, {
-            uint* d = array_at(uint, &in_degree, dependent);
+        FOR_EACH_ARRAY (Type_Id, dependent, dependents) {
+            uint* d = array_at(uint, &in_degree, *dependent);
             if (*d != done_sentinel) (*d)--;
-        })
+        }
     }
 
     if (output_count == n) return;
@@ -795,12 +879,12 @@ lower_topological_sort_dependency_graph(struct Unit* unit, struct Source_File so
         struct Type* type = *array_at(struct Type*, &unit->types.entries, current);
 
         Type_Id next = (Type_Id)-1;
-        FOR_EACH_ARRAY(Type_Id, dep, &type->depends_on, {
-            if (*array_at(uint, &in_degree, dep) != done_sentinel) {
-                next = dep;
+        FOR_EACH_ARRAY (Type_Id, dep, &type->depends_on) {
+            if (*array_at(uint, &in_degree, *dep) != done_sentinel) {
+                next = *dep;
                 break;
             }
-        })
+        }
         if (next == (Type_Id)-1) return; // not a real cycle
 
         uint chain_len = array_length(&chain);
@@ -851,6 +935,9 @@ lower_tree(struct Tree* tree, struct Source_File source, struct Unit* unit)
         .synthetic_type_counter = 0,
     };
 
-    if (tree) lower_pass_1(&ctx, tree);
+    if (tree) {
+        lower_pass_1(&ctx, tree);
+        lower_pass_2(&ctx);
+    }
     lower_topological_sort_dependency_graph(unit, source);
 }
diff --git a/boot/visit/ir.c b/boot/visit/ir.c
index 20296e3..1920f3b 100644
--- a/boot/visit/ir.c
+++ b/boot/visit/ir.c
@@ -78,14 +78,12 @@ walk(struct Visit* visit, struct Unit* unit)
 void
 walk_unit(struct Visit* visit, struct Unit* unit)
 {
-    FOR_EACH_ARRAY(struct Type*, type, &unit->types.entries, { VISIT(visit_type, type); })
-    FOR_EACH_ARRAY(struct Function*, function, &unit->functions.entries, {
-        VISIT(visit_function, function);
-    })
-    FOR_EACH_ARRAY(struct Import, import, &unit->imports, { VISIT(visit_import, &import); })
-    FOR_EACH_ARRAY(struct Diagnostic, diagnostic, &unit->diagnostics, {
-        VISIT(visit_diagnostic, &diagnostic);
-    })
+    FOR_EACH_ARRAY (struct Type*, type, &unit->types.entries) VISIT(visit_type, *type);
+    FOR_EACH_ARRAY (struct Function*, function, &unit->functions.entries)
+        VISIT(visit_function, *function);
+    FOR_EACH_ARRAY (struct Import, import, &unit->imports) VISIT(visit_import, import);
+    FOR_EACH_ARRAY (struct Diagnostic, diagnostic, &unit->diagnostics)
+        VISIT(visit_diagnostic, diagnostic);
 }
 
 void
@@ -120,33 +118,31 @@ WALK_LEAF_FUNCTION(walk_type_alias, struct Type*);
 void
 walk_type_structure(struct Visit* visit, struct Type* type)
 {
-    FOR_EACH_ARRAY(struct Field, field, &type->value.structure.fields, {
-        VISIT(visit_type_ref, &field.type);
-    })
+    FOR_EACH_ARRAY (struct Field, field, &type->value.structure.fields)
+        VISIT(visit_type_ref, &field->type);
 }
 
 void
 walk_type_variant(struct Visit* visit, struct Type* type)
 {
-    FOR_EACH_ARRAY(struct Variant_Case, one_case, &type->value.variant.cases, {
-        if (one_case.has_payload) VISIT(visit_type_ref, &one_case.payload);
-    })
+    FOR_EACH_ARRAY (struct Variant_Case, one_case, &type->value.variant.cases) {
+        if (one_case->has_payload) VISIT(visit_type_ref, &one_case->payload);
+    }
 }
 
 void
 walk_type_function(struct Visit* visit, struct Type* type)
 {
     VISIT(visit_type_ref, &type->value.function.return_type);
-    FOR_EACH_ARRAY(struct Type_Ref, param, &type->value.function.params, {
-        VISIT(visit_type_ref, &param);
-    })
+    FOR_EACH_ARRAY (struct Type_Ref, param, &type->value.function.params)
+        VISIT(visit_type_ref, param);
 }
 
 void
 walk_function(struct Visit* visit, struct Function* function)
 {
     VISIT(visit_type_ref, &function->return_type);
-    FOR_EACH_ARRAY(struct Param, param, &function->params, { VISIT(visit_type_ref, &param.type); })
+    FOR_EACH_ARRAY (struct Param, param, &function->params) VISIT(visit_type_ref, &param->type);
     VISIT_MAYBE(visit_block, function->body);
 }
 
@@ -217,10 +213,10 @@ walk_statement_expression(struct Visit* visit, struct Statement* stmt)
 void
 walk_statement_conditional(struct Visit* visit, struct Statement* stmt)
 {
-    FOR_EACH_ARRAY(struct If_Branch, branch, &stmt->value.conditional.branches, {
-        VISIT_MAYBE(visit_expression, branch.condition);
-        VISIT(visit_block, branch.body);
-    })
+    FOR_EACH_ARRAY (struct If_Branch, branch, &stmt->value.conditional.branches) {
+        VISIT_MAYBE(visit_expression, branch->condition);
+        VISIT(visit_block, branch->body);
+    }
 }
 
 void
@@ -326,9 +322,8 @@ void
 walk_expression_call(struct Visit* visit, struct Expression* expr)
 {
     VISIT(visit_expression, expr->value.call.subject);
-    FOR_EACH_ARRAY(struct Expression*, argument, &expr->value.call.arguments, {
-        VISIT(visit_expression, argument);
-    })
+    FOR_EACH_ARRAY (struct Expression*, argument, &expr->value.call.arguments)
+        VISIT(visit_expression, *argument);
 }
 
 void
@@ -354,13 +349,16 @@ walk_expression_cast(struct Visit* visit, struct Expression* expr)
 void
 walk_expression_construct(struct Visit* visit, struct Expression* expr)
 {
-    FOR_EACH_ARRAY(struct Construct_Field, field, &expr->value.construct.fields, {
-        VISIT(visit_expression, field.value);
-    })
+    FOR_EACH_ARRAY (struct Construct_Field, field, &expr->value.construct.fields)
+        VISIT(visit_expression, field->value);
 }
 
-void walk_block(struct Visit* visit, struct Block* block){ FOR_EACH_ARRAY(
-    struct Statement*, statement, &block -> statements, { VISIT(visit_statement, statement); }) }
+void
+walk_block(struct Visit* visit, struct Block* block)
+{
+    FOR_EACH_ARRAY (struct Statement*, statement, &block->statements)
+        VISIT(visit_statement, *statement);
+}
 
 WALK_LEAF_FUNCTION(walk_type_ref, struct Type_Ref*);
 WALK_LEAF_FUNCTION(walk_import, struct Import*);
@@ -475,11 +473,11 @@ printer_visit_unit(struct Visit* visit, struct Unit* unit)
         printer_indent(p);
         PRINT("(types");
         p->indentation_level++;
-        FOR_EACH_ARRAY(struct Type*, type, &unit->types.entries, {
+        FOR_EACH_ARRAY (struct Type*, type, &unit->types.entries) {
             PRINT("\n");
             printer_indent(p);
-            VISIT(visit_type, type);
-        })
+            VISIT(visit_type, *type);
+        }
         p->indentation_level--;
         PRINT(")");
     }
@@ -489,11 +487,11 @@ printer_visit_unit(struct Visit* visit, struct Unit* unit)
         printer_indent(p);
         PRINT("(functions");
         p->indentation_level++;
-        FOR_EACH_ARRAY(struct Function*, function, &unit->functions.entries, {
+        FOR_EACH_ARRAY (struct Function*, function, &unit->functions.entries) {
             PRINT("\n");
             printer_indent(p);
-            VISIT(visit_function, function);
-        })
+            VISIT(visit_function, *function);
+        }
         p->indentation_level--;
         PRINT(")");
     }
@@ -502,10 +500,10 @@ printer_visit_unit(struct Visit* visit, struct Unit* unit)
         PRINT("\n");
         printer_indent(p);
         PRINT("(imports");
-        FOR_EACH_ARRAY(struct Import, import, &unit->imports, {
+        FOR_EACH_ARRAY (struct Import, import, &unit->imports) {
             PRINT(" ");
-            VISIT(visit_import, &import);
-        })
+            VISIT(visit_import, import);
+        }
         PRINT(")");
     }
 
@@ -513,7 +511,7 @@ printer_visit_unit(struct Visit* visit, struct Unit* unit)
         PRINT("\n");
         printer_indent(p);
         PRINT("(emission_order");
-        FOR_EACH_ARRAY(Type_Id, id, &unit->type_emission_order, { PRINT(" %lu", id); })
+        FOR_EACH_ARRAY (Type_Id, id, &unit->type_emission_order) PRINT(" %lu", *id);
         PRINT(")");
     }
 
@@ -522,11 +520,11 @@ printer_visit_unit(struct Visit* visit, struct Unit* unit)
         printer_indent(p);
         PRINT("(diagnostics");
         p->indentation_level++;
-        FOR_EACH_ARRAY(struct Diagnostic, diagnostic, &unit->diagnostics, {
+        FOR_EACH_ARRAY (struct Diagnostic, diagnostic, &unit->diagnostics) {
             PRINT("\n");
             printer_indent(p);
-            VISIT(visit_diagnostic, &diagnostic);
-        })
+            VISIT(visit_diagnostic, diagnostic);
+        }
         p->indentation_level--;
         PRINT(")");
     }
@@ -541,9 +539,9 @@ printer_visit_type_ref(struct Visit* visit, struct Type_Ref* ref)
     PRINTER_PREAMBLE
 
     PRINT("(ref");
-    FOR_EACH_ARRAY(enum Type_Modifier, mod, &ref->mods, {
-        if (mod == TYPE_MOD_REFERENCE) PRINT(" &");
-    })
+    FOR_EACH_ARRAY (enum Type_Modifier, mod, &ref->mods) {
+        if (*mod == TYPE_MOD_REFERENCE) PRINT(" &");
+    }
     struct Type* target = printer_type_at(p, ref->type_id);
     if (target)
         PRINT(" %s", string_c_str(target->name));
@@ -562,7 +560,7 @@ printer_visit_type(struct Visit* visit, struct Type* type)
     walk_type(visit, type);
     if (array_length(&type->depends_on) > 0) {
         PRINT(" (depends_on");
-        FOR_EACH_ARRAY(Type_Id, dep, &type->depends_on, { PRINT(" %lu", dep); })
+        FOR_EACH_ARRAY (Type_Id, dep, &type->depends_on) PRINT(" %lu", *dep);
         PRINT(")");
     }
     PRINT(")");
@@ -594,11 +592,11 @@ printer_visit_type_structure(struct Visit* visit, struct Type* type)
     PRINTER_PREAMBLE
 
     PRINT(" structure");
-    FOR_EACH_ARRAY(struct Field, field, &type->value.structure.fields, {
-        PRINT(" (field %s ", string_c_str(field.name));
-        VISIT(visit_type_ref, &field.type);
+    FOR_EACH_ARRAY (struct Field, field, &type->value.structure.fields) {
+        PRINT(" (field %s ", string_c_str(field->name));
+        VISIT(visit_type_ref, &field->type);
         PRINT(")");
-    })
+    }
 }
 
 void
@@ -607,14 +605,14 @@ printer_visit_type_variant(struct Visit* visit, struct Type* type)
     PRINTER_PREAMBLE
 
     PRINT(" variant");
-    FOR_EACH_ARRAY(struct Variant_Case, one_case, &type->value.variant.cases, {
-        PRINT(" (case %s tag=%u", string_c_str(one_case.name), one_case.tag);
-        if (one_case.has_payload) {
+    FOR_EACH_ARRAY (struct Variant_Case, one_case, &type->value.variant.cases) {
+        PRINT(" (case %s tag=%u", string_c_str(one_case->name), one_case->tag);
+        if (one_case->has_payload) {
             PRINT(" ");
-            VISIT(visit_type_ref, &one_case.payload);
+            VISIT(visit_type_ref, &one_case->payload);
         }
         PRINT(")");
-    })
+    }
 }
 
 void
@@ -625,11 +623,11 @@ printer_visit_type_function(struct Visit* visit, struct Type* type)
     PRINT(" function (returns ");
     VISIT(visit_type_ref, &type->value.function.return_type);
     PRINT(")");
-    FOR_EACH_ARRAY(struct Type_Ref, param, &type->value.function.params, {
+    FOR_EACH_ARRAY (struct Type_Ref, param, &type->value.function.params) {
         PRINT(" (param ");
-        VISIT(visit_type_ref, &param);
+        VISIT(visit_type_ref, param);
         PRINT(")");
-    })
+    }
     if (type->value.function.variadic) PRINT(" variadic");
 }
 
@@ -644,11 +642,11 @@ printer_visit_function(struct Visit* visit, struct Function* function)
     PRINT(" (returns ");
     VISIT(visit_type_ref, &function->return_type);
     PRINT(")");
-    FOR_EACH_ARRAY(struct Param, param, &function->params, {
-        PRINT(" (param %s ", string_c_str(param.name));
-        VISIT(visit_type_ref, &param.type);
+    FOR_EACH_ARRAY (struct Param, param, &function->params) {
+        PRINT(" (param %s ", string_c_str(param->name));
+        VISIT(visit_type_ref, &param->type);
         PRINT(")");
-    })
+    }
     if (function->variadic) PRINT(" variadic");
 
     if (function->body) {
@@ -709,17 +707,17 @@ printer_visit_statement_conditional(struct Visit* visit, struct Statement* stmt)
     PRINTER_PREAMBLE
 
     PRINT("(conditional");
-    FOR_EACH_ARRAY(struct If_Branch, branch, &stmt->value.conditional.branches, {
+    FOR_EACH_ARRAY (struct If_Branch, branch, &stmt->value.conditional.branches) {
         PRINT(" ");
-        if (branch.condition) {
+        if (branch->condition) {
             PRINT("(when ");
-            VISIT(visit_expression, branch.condition);
+            VISIT(visit_expression, branch->condition);
             PRINT(") ");
         } else {
             PRINT("(else) ");
         }
-        VISIT(visit_block, branch.body);
-    })
+        VISIT(visit_block, branch->body);
+    }
     PRINT(")");
 }
 
@@ -862,10 +860,10 @@ printer_visit_expression_call(struct Visit* visit, struct Expression* expr)
     PRINTER_PREAMBLE
     PRINT("(call ");
     VISIT(visit_expression, expr->value.call.subject);
-    FOR_EACH_ARRAY(struct Expression*, argument, &expr->value.call.arguments, {
+    FOR_EACH_ARRAY (struct Expression*, argument, &expr->value.call.arguments) {
         PRINT(" ");
-        VISIT(visit_expression, argument);
-    })
+        VISIT(visit_expression, *argument);
+    }
     PRINT(")");
 }
 
@@ -911,14 +909,14 @@ printer_visit_expression_construct(struct Visit* visit, struct Expression* expr)
         PRINT(" %s", string_c_str(type->name));
     else
         PRINT(" #%lu", expr->value.construct.type_id);
-    FOR_EACH_ARRAY(struct Construct_Field, field, &expr->value.construct.fields, {
-        if (field.name.length > 0)
-            PRINT(" (field %s ", string_c_str(field.name));
+    FOR_EACH_ARRAY (struct Construct_Field, field, &expr->value.construct.fields) {
+        if (field->name.length > 0)
+            PRINT(" (field %s ", string_c_str(field->name));
         else
             PRINT(" (positional ");
-        VISIT(visit_expression, field.value);
+        VISIT(visit_expression, field->value);
         PRINT(")");
-    })
+    }
     PRINT(")");
 }
 
@@ -931,10 +929,10 @@ printer_visit_block(struct Visit* visit, struct Block* block)
     if (array_length(&block->statements) > 0) {
         PRINT("\n");
         p->indentation_level++;
-        FOR_EACH_ARRAY(struct Statement*, statement, &block->statements, {
-            VISIT(visit_statement, statement);
+        FOR_EACH_ARRAY (struct Statement*, statement, &block->statements) {
+            VISIT(visit_statement, *statement);
             PRINT("\n");
-        })
+        }
         p->indentation_level--;
         printer_indent(p);
     }
diff --git a/boot/visit/tree.c b/boot/visit/tree.c
index 48db391..efeffe9 100644
--- a/boot/visit/tree.c
+++ b/boot/visit/tree.c
@@ -33,19 +33,26 @@ struct Tree_Visit_Table
     void (*visit_statement_defer)(struct Tree_Visit* visitor, struct Tree_Statement* stmt);
 
     void (*visit_expression)(struct Tree_Visit* visitor, struct Tree_Expression* expr);
-    void (*visit_expression_integer_literal)(struct Tree_Visit* visitor, struct Tree_Expression* expr);
-    void (*visit_expression_float_literal)(struct Tree_Visit* visitor, struct Tree_Expression* expr);
-    void (*visit_expression_string_literal)(struct Tree_Visit* visitor, struct Tree_Expression* expr);
-    void (*visit_expression_boolean_literal)(struct Tree_Visit* visitor, struct Tree_Expression* expr);
+    void (*visit_expression_integer_literal)(
+        struct Tree_Visit* visitor, struct Tree_Expression* expr);
+    void (*visit_expression_float_literal)(
+        struct Tree_Visit* visitor, struct Tree_Expression* expr);
+    void (*visit_expression_string_literal)(
+        struct Tree_Visit* visitor, struct Tree_Expression* expr);
+    void (*visit_expression_boolean_literal)(
+        struct Tree_Visit* visitor, struct Tree_Expression* expr);
     void (*visit_expression_name)(struct Tree_Visit* visitor, struct Tree_Expression* expr);
-    void (*visit_expression_unary_operation)(struct Tree_Visit* visitor, struct Tree_Expression* expr);
-    void (*visit_expression_binary_operation)(struct Tree_Visit* visitor, struct Tree_Expression* expr);
+    void (*visit_expression_unary_operation)(
+        struct Tree_Visit* visitor, struct Tree_Expression* expr);
+    void (*visit_expression_binary_operation)(
+        struct Tree_Visit* visitor, struct Tree_Expression* expr);
     void (*visit_expression_group)(struct Tree_Visit* visitor, struct Tree_Expression* expr);
     void (*visit_expression_call)(struct Tree_Visit* visitor, struct Tree_Expression* expr);
     void (*visit_expression_construct)(struct Tree_Visit* visitor, struct Tree_Expression* expr);
     void (*visit_expression_subscript)(struct Tree_Visit* visitor, struct Tree_Expression* expr);
     void (*visit_expression_member)(struct Tree_Visit* visitor, struct Tree_Expression* expr);
-    void (*visit_expression_increment_decrement)(struct Tree_Visit* visitor, struct Tree_Expression* expr);
+    void (*visit_expression_increment_decrement)(
+        struct Tree_Visit* visitor, struct Tree_Expression* expr);
     void (*visit_expression_try)(struct Tree_Visit* visitor, struct Tree_Expression* expr);
     void (*visit_expression_must)(struct Tree_Visit* visitor, struct Tree_Expression* expr);
     void (*visit_expression_function)(struct Tree_Visit* visitor, struct Tree_Expression* expr);
@@ -63,8 +70,10 @@ struct Tree_Visit_Table
     void (*visit_type_node_class)(struct Tree_Visit* visitor, struct Tree_Type* node);
 
     void (*visit_block_node)(struct Tree_Visit* visitor, struct Tree_Block* node);
-    void (*visit_bare_declaration_node)(struct Tree_Visit* visitor, struct Tree_Bare_Declaration* node);
-    void (*visit_function_header_node)(struct Tree_Visit* visitor, struct Tree_Function_Header* header);
+    void (*visit_bare_declaration_node)(
+        struct Tree_Visit* visitor, struct Tree_Bare_Declaration* node);
+    void (*visit_function_header_node)(
+        struct Tree_Visit* visitor, struct Tree_Function_Header* header);
     void (*visit_argument_group_node)(struct Tree_Visit* visitor, struct Tree_Argument_Group* node);
     void (*visit_pragma_node)(struct Tree_Visit* visitor, struct Tree_Pragma* node);
 };
@@ -291,7 +300,8 @@ tree_walk_expression_member(struct Tree_Visit* visit, struct Tree_Expression* ex
 }
 
 void
-tree_walk_expression_increment_decrement(struct Tree_Visit* visit, struct Tree_Expression* expression)
+tree_walk_expression_increment_decrement(
+    struct Tree_Visit* visit, struct Tree_Expression* expression)
 {
     VISIT(visit_expression, expression->value.increment_decrement.subject);
 }
@@ -416,7 +426,9 @@ tree_walk_type_class(struct Tree_Visit* visit, struct Tree_Type* node)
 void
 tree_walk_block(struct Tree_Visit* visit, struct Tree_Block* node)
 {
-    FOR_EACH (struct Tree_Statement*, statement, node->statements) { VISIT(visit_statement, statement); }
+    FOR_EACH (struct Tree_Statement*, statement, node->statements) {
+        VISIT(visit_statement, statement);
+    }
 }
 
 void
@@ -438,7 +450,9 @@ tree_walk_function_header(struct Tree_Visit* visit, struct Tree_Function_Header*
 void
 tree_walk_argument_group(struct Tree_Visit* visit, struct Tree_Argument_Group* node)
 {
-    FOR_EACH (struct Tree_Expression*, argument, node->arguments) { VISIT(visit_expression, argument); }
+    FOR_EACH (struct Tree_Expression*, argument, node->arguments) {
+        VISIT(visit_expression, argument);
+    }
 }
 
 void
@@ -601,7 +615,8 @@ tree_printer_visit_statement_conditional(struct Tree_Visit* visit, struct Tree_S
 
     PRINT("(conditional");
     for (uint i = 0; i < stmt->value.conditional.condition_count; ++i) {
-        const struct Tree_Statement_Conditional_Branch* branch = &stmt->value.conditional.conditions[i];
+        const struct Tree_Statement_Conditional_Branch* branch =
+            &stmt->value.conditional.conditions[i];
         PRINT(" ");
         if (branch->when) {
             PRINT("(when ");
@@ -707,7 +722,8 @@ tree_printer_visit_expression(struct Tree_Visit* visit, struct Tree_Expression*
 }
 
 void
-tree_printer_visit_expression_integer_literal(struct Tree_Visit* visit, struct Tree_Expression* expr)
+tree_printer_visit_expression_integer_literal(
+    struct Tree_Visit* visit, struct Tree_Expression* expr)
 {
     TREE_PRINTER_PREAMBLE
 
@@ -731,7 +747,8 @@ tree_printer_visit_expression_string_literal(struct Tree_Visit* visit, struct Tr
 }
 
 void
-tree_printer_visit_expression_boolean_literal(struct Tree_Visit* visit, struct Tree_Expression* expr)
+tree_printer_visit_expression_boolean_literal(
+    struct Tree_Visit* visit, struct Tree_Expression* expr)
 {
     TREE_PRINTER_PREAMBLE
 
@@ -747,7 +764,8 @@ tree_printer_visit_expression_name(struct Tree_Visit* visit, struct Tree_Express
 }
 
 void
-tree_printer_visit_expression_unary_operation(struct Tree_Visit* visit, struct Tree_Expression* expr)
+tree_printer_visit_expression_unary_operation(
+    struct Tree_Visit* visit, struct Tree_Expression* expr)
 {
     TREE_PRINTER_PREAMBLE
 
@@ -757,7 +775,8 @@ tree_printer_visit_expression_unary_operation(struct Tree_Visit* visit, struct T
 }
 
 void
-tree_printer_visit_expression_binary_operation(struct Tree_Visit* visit, struct Tree_Expression* expr)
+tree_printer_visit_expression_binary_operation(
+    struct Tree_Visit* visit, struct Tree_Expression* expr)
 {
     TREE_PRINTER_PREAMBLE
 
@@ -827,7 +846,8 @@ tree_printer_visit_expression_member(struct Tree_Visit* visit, struct Tree_Expre
 }
 
 void
-tree_printer_visit_expression_increment_decrement(struct Tree_Visit* visit, struct Tree_Expression* expr)
+tree_printer_visit_expression_increment_decrement(
+    struct Tree_Visit* visit, struct Tree_Expression* expr)
 {
     TREE_PRINTER_PREAMBLE
 
@@ -1016,9 +1036,7 @@ tree_printer_visit_bare_declaration(struct Tree_Visit* visit, struct Tree_Bare_D
     TREE_PRINTER_PREAMBLE
 
     PRINT("(declaration ");
-    FOR_EACH_ARRAY(struct String, name, &node->names, {
-        PRINT("%s ", name.data);
-    })
+    FOR_EACH_ARRAY (struct String, name, &node->names) PRINT("%s ", name->data);
 
     if (node->type && node->type->type != TREE_TYPE_NONE) {
         VISIT(visit_type_node, node->type);