Skip to content

Commit

Permalink
port to self-hosted
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli committed Dec 26, 2023
1 parent 82e84bb commit 7b9f0ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 7 additions & 3 deletions self_hosted/create_llvm_ir.jou
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,13 @@ class AstToIR:
if rhs_type->kind == TypeKind::Enum:
rhs_type = int_type

got_numbers = lhs_type->is_number_type() and rhs_type->is_number_type()
got_pointers = lhs_type->is_pointer_type() and rhs_type->is_pointer_type()
assert got_numbers or got_pointers
if lhs_type == &bool_type and rhs_type == &bool_type:
# bools are 1-bit integers in llvm
if op == AstExpressionKind::Eq:
return LLVMBuildICmp(self->builder, LLVMIntPredicate::EQ, lhs, rhs, "eq")
if op == AstExpressionKind::Ne:
return LLVMBuildICmp(self->builder, LLVMIntPredicate::NE, lhs, rhs, "ne")
assert False

if lhs_type->kind == TypeKind::FloatingPoint and rhs_type->kind == TypeKind::FloatingPoint:
if op == AstExpressionKind::Add:
Expand Down
7 changes: 5 additions & 2 deletions self_hosted/typecheck.jou
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ def check_binop(
do_what = "compare"
result_is_bool = True

got_bools = lhs_types->original_type == &bool_type and rhs_types->original_type == &bool_type
got_integers = lhs_types->original_type->is_integer_type() and rhs_types->original_type->is_integer_type()
got_numbers = lhs_types->original_type->is_number_type() and rhs_types->original_type->is_number_type()
got_enums = lhs_types->original_type->kind == TypeKind::Enum and rhs_types->original_type->kind == TypeKind::Enum
Expand All @@ -703,7 +704,7 @@ def check_binop(
)

if (
(not got_numbers and not got_enums and not got_pointers)
(not got_bools and not got_numbers and not got_enums and not got_pointers)
or (op != AstExpressionKind::Eq and op != AstExpressionKind::Ne and not got_numbers)
):
message: byte[500]
Expand All @@ -714,7 +715,9 @@ def check_binop(
)
fail(location, message)

if got_integers:
if got_bools:
cast_type = &bool_type
elif got_integers:
size = max(lhs_types->original_type->size_in_bits, rhs_types->original_type->size_in_bits)
if (
lhs_types->original_type->kind == TypeKind::SignedInteger
Expand Down

0 comments on commit 7b9f0ee

Please sign in to comment.