bools can now upcast to any integer

Signed-off-by: Jakub Doka <jakub.doka2@gmail.com>
This commit is contained in:
Jakub Doka 2024-12-16 13:54:52 +01:00
parent f7d5bccdd9
commit 1571938e9f
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
3 changed files with 16 additions and 17 deletions

View file

@ -47,7 +47,7 @@ main := fn(): uint {
#### arithmetic
```hb
main := fn(): uint {
return 10 - 20 / 2 + 4 * (2 + 2) - 4 * 4 + (1 << 0) + -1
return 10 - 20 / 2 + 4 * (2 + 2) - 4 * 4 + (true << 0) + -1
}
```
@ -891,8 +891,8 @@ main := fn(): int {
loop if y == H break else {
x := @as(int, 0)
loop if x == W break else {
c_r := @itf(x)
c_i := @itf(y)
c_r := @as(f64, @itf(x))
c_i := @as(f64, @itf(y))
if c_i * c_r >= 10.0 return 0
x += 1
}
@ -1070,7 +1070,7 @@ sin := fn(theta: f32): f32 {
PI := 3.14159265358979323846
TABLE_SIZE := @as(i32, 256)
si := @fti(theta * 0.5 * @itf(TABLE_SIZE) / PI)
d := theta - @floatcast(@itf(si)) * 2.0 * PI / @itf(TABLE_SIZE)
d := theta - @itf(si) * 2.0 * PI / @itf(TABLE_SIZE)
ci := si + TABLE_SIZE / 4 & TABLE_SIZE - 1
si &= TABLE_SIZE - 1
return sin_table[@bitcast(si)] + (sin_table[@bitcast(ci)] - 0.5 * sin_table[@bitcast(si)] * d) * d
@ -1760,7 +1760,7 @@ main := fn(): uint {
}
if multiple_breaks(0) != 3 {
return 1
return true
}
if multiple_breaks(4) != 10 {

View file

@ -5558,13 +5558,13 @@ impl<'a> Codegen<'a> {
self.wrap_in_opt(pos, src);
} else {
debug_assert!(
src.ty.is_integer() || src.ty == ty::Id::NEVER,
src.ty.is_integer() || src.ty == ty::Id::BOOL,
"{} {}",
self.ty_display(src.ty),
self.ty_display(upcasted)
);
debug_assert!(
upcasted.is_integer() || src.ty == ty::Id::NEVER,
upcasted.is_integer() || src.ty == ty::Id::BOOL,
"{} {}",
self.ty_display(src.ty),
self.ty_display(upcasted)

View file

@ -19,23 +19,22 @@ sin:
FDIV32 r14, r14, r15
FTI32 r14, r14, 1b
ANDI r15, r14, 255d
ITF64 r16, r14
MULI64 r15, r15, 4d
LRA r17, r0, :sin_table
LI32 r18, 1086918619w
FC64T32 r16, r16, 1b
LRA r16, r0, :sin_table
LI32 r17, 1086918619w
ITF32 r18, r14
ADDI64 r14, r14, 64d
ADD64 r15, r17, r15
ADD64 r15, r16, r15
LI32 r19, 1132462080w
FMUL32 r16, r16, r18
FMUL32 r17, r18, r17
ANDI r14, r14, 255d
LI32 r18, 1056964608w
LD r15, r15, 0a, 4h
FDIV32 r16, r16, r19
FDIV32 r17, r17, r19
MULI64 r14, r14, 4d
FMUL32 r18, r15, r18
FSUB32 r13, r13, r16
ADD64 r14, r17, r14
FSUB32 r13, r13, r17
ADD64 r14, r16, r14
FMUL32 r16, r13, r18
LD r14, r14, 0a, 4h
FSUB32 r14, r14, r16
@ -43,6 +42,6 @@ sin:
FADD32 r13, r15, r13
CP r1, r13
JALA r0, r31, 0a
code size: 1315
code size: 1311
ret: 826
status: Ok(())