Fixed some error handling for invalid if statements. Started if codegen.

This commit is contained in:
2025-01-18 22:22:16 +01:00
parent b4d119230b
commit 45ea54cf93
23 changed files with 344 additions and 11 deletions

View File

@@ -374,6 +374,7 @@ emit_node :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
emit_field(state, node, indentation);
}
case .Block; {
assert(false, "Not implemented yet: block");
}
case .Variable; {
@@ -436,9 +437,28 @@ emit_node :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
append(*state.builder, "return ");
emit_node(state, node.children[0], 0);
}
case .If; {
indent(*state.builder, indentation);
append(*state.builder, "if ");
cond := node.children[0];
emit_node(state, cond, 0);
body := node.children[1];
emit_block(state, body, 0);
if node.children.count == 2 {
emit_else(state, node.children[2]);
}
}
}
}
emit_else :: (state : *Codegen_State, node : *AST_Node) {
append(*state.builder, "else ");
emit_node(state, node.children[0], 0);
}
emit_field_list :: (state : *Codegen_State, field_list : *AST_Node, indentation : int) {
for child : field_list.children {
emit_node(state, child, 1);