Skip to content

Commit

Permalink
Add "match ... with ..." syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli committed Jan 26, 2025
1 parent 0cf97b8 commit 0039d1b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion compiler/builders/ast_to_builder.jou
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,13 @@ class AstToBuilder:
otherwise = BuilderBlock{} # will be replaced by loop below
for k = 0; k < match_stmt->cases[i].n_case_objs; k++:
case_obj = self->build_expression(&match_stmt->cases[i].case_objs[k])
cond = self->builder->eq(match_obj, case_obj)
if match_stmt->with_func_name[0] == '\0':
cond = self->builder->eq(match_obj, case_obj)
else:
args = [match_obj, case_obj]
with_func_ret = self->builder->call(&match_stmt->with_func_signature, args, 2)
zero = self->builder->integer(with_func_ret.type, 0)
cond = self->builder->eq(with_func_ret, zero)
otherwise = self->builder->add_block()
self->builder->branch(cond, then, otherwise)
self->builder->set_current_block(otherwise)
Expand Down

0 comments on commit 0039d1b

Please sign in to comment.