Skip to content

Commit

Permalink
More bool shenanigans.
Browse files Browse the repository at this point in the history
  • Loading branch information
Goubermouche committed Feb 1, 2024
1 parent a2ccde9 commit 80f3703
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion source/compiler/compiler/type_system/semantic_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace sigma {

switch (type.base_type) {
case data_type::VOID: return VOID_TYPE;
case data_type::BOOL: return BOOL_TYPE;
case data_type::BOOL:
case data_type::I8:
case data_type::U8: return I8_TYPE;
case data_type::I16:
Expand Down
16 changes: 8 additions & 8 deletions source/compiler/test/main.s
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
// - set crashes with more than 4(?) parameters
// - implicit returns for non-void functions should be a thing

i32 run(i32 x) {
ret x;
}
i32 main() {
bool a = true;
// printf("%d\n", a);
printf("%d\n", !a);

i32 test() {
ret 12;
}
// bool b = 100;
// printf("%d\n", b);
// printf("%d\n", !b);

i32 main() {
printf("%d\n", run(test()));
ret 0;
}


// THIS CRASHES
// i32 main() {
// i32* memory = cast<i32*>(malloc(100));
Expand Down
6 changes: 3 additions & 3 deletions source/ir_translator/ir_translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ namespace sigma {
const handle<ir::node> expression = translate_node(operator_node->children[0]);

// negate it
// NOTE: booleans are 32 bits
return m_context.builder.create_cmp_eq(expression, m_context.builder.create_unsigned_integer(0, 1));
// NOTE: booleans are 8 bits
return m_context.builder.create_cmp_eq(expression, m_context.builder.create_unsigned_integer(0, 8));
}

auto ir_translator::translate_cast(handle<ast::node> cast_node) -> handle<ir::node> {
Expand Down Expand Up @@ -429,7 +429,7 @@ namespace sigma {
case data_type::U64: return m_context.builder.create_unsigned_integer(utility::detail::from_string<u64>(value, overflow), 64);
// for cases when a numerical literal is implicitly converted to a bool (ie. "if(1)")
case data_type::BOOL: {
return m_context.builder.create_bool(!utility::detail::is_only_char(value, '0'));
return m_context.builder.create_unsigned_integer(!utility::detail::is_only_char(value, '0'), 8);
}
// for cases when a numerical literal is implicitly converted to a char (ie. "char c = 12")
case data_type::CHAR: return m_context.builder.create_signed_integer(utility::detail::from_string<i32>(value, overflow), 32);
Expand Down

0 comments on commit 80f3703

Please sign in to comment.