This commit is contained in:
Jakub Doka 2024-11-24 11:26:38 +01:00
parent 5df4fb8882
commit 9dfb2eb606
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
5 changed files with 44 additions and 74 deletions

View file

@ -658,6 +658,20 @@ main := fn(): uint {
### Purely Testing Examples ### Purely Testing Examples
#### pointer_comparison
```hb
main := fn(): int {
a := 10
b := 20
if &a == &a {
return 10
} else {
return 20
}
}
```
#### wrong_dead_code_elimination #### wrong_dead_code_elimination
```hb ```hb
Color := struct {b: u8} Color := struct {b: u8}

View file

@ -871,7 +871,8 @@ impl Nodes {
if lhs == rhs { if lhs == rhs {
match op { match op {
T::Sub => return Some(self.new_const(ty, 0)), T::Ne | T::Gt | T::Lt | T::Sub => return Some(self.new_const(ty, 0)),
T::Eq | T::Ge | T::Le => return Some(self.new_const(ty, 1)),
T::Add => { T::Add => {
let rhs = self.new_const(ty, 2); let rhs = self.new_const(ty, 2);
return Some(self.new_node( return Some(self.new_node(
@ -4548,9 +4549,17 @@ impl<'a> Codegen<'a> {
}) })
} }
fn assign_pattern(&mut self, pat: &Expr, right: Value) { fn assign_pattern(&mut self, pat: &Expr, mut right: Value) {
match *pat { match *pat {
Expr::Ident { id, .. } => { Expr::Ident { id, pos, .. } => {
if parser::find_symbol(&self.file().symbols, id).flags & idfl::REFERENCED != 0
&& !right.ptr
{
let stack = self.new_stack(pos, right.ty);
self.store_mem(stack, right.ty, right.id);
right.id = stack;
right.ptr = true;
}
self.ci.scope.vars.push(Variable::new( self.ci.scope.vars.push(Variable::new(
id, id,
right.ty, right.ty,
@ -5514,6 +5523,7 @@ mod tests {
fb_driver; fb_driver;
// Purely Testing Examples; // Purely Testing Examples;
pointer_comparison;
different_function_destinations; different_function_destinations;
triggering_store_in_divergent_branch; triggering_store_in_divergent_branch;
wrong_dead_code_elimination; wrong_dead_code_elimination;

View file

@ -0,0 +1,7 @@
main:
LI64 r13, 10d
CP r1, r13
JALA r0, r31, 0a
code size: 32
ret: 10
status: Ok(())

View file

@ -8,9 +8,9 @@ main:
ST r33, r254, 0a, 8h ST r33, r254, 0a, 8h
CP r2, r32 CP r2, r32
JAL r31, r0, :modify JAL r31, r0, :modify
CP r2, r33
JAL r31, r0, :drop
LD r32, r254, 0a, 8h LD r32, r254, 0a, 8h
CP r2, r32
JAL r31, r0, :drop
ADDI64 r32, r32, -2d ADDI64 r32, r32, -2d
CP r1, r32 CP r1, r32
LD r31, r254, 8a, 24h LD r31, r254, 8a, 24h

77
smh.hb
View file

@ -1,71 +1,10 @@
log := fn(msg: ^u8): void return @eca(0, msg)
absf := fn(x: f32): f32 {
if (x < 0) {
return -x
}
return x
}
sqrt := fn(x: f32, low: f32, high: f32): f32 {
mid := (high - low)/2.0
if (absf(mid * mid - x) < 0.01) {
return mid
}
if (mid * mid > x) {
return sqrt(x, low, mid)
}
if (mid * mid < x) {
return sqrt(x, mid, high)
}
return -9999.0
}
is_filled := fn(x: uint, y: uint, center_x: f32, center_y: f32, inner_radius: f32, outer_radius: f32): bool {
x_f := @as(f32, @floatcast(@itf(@bitcast(x))))
y_f := @as(f32, @floatcast(@itf(@bitcast(y))))
x_diff := x_f - center_x
y_diff := x_f - center_y
dist := sqrt(x_diff * x_diff + y_diff * y_diff)
if (dist < outer_radius) {
if (dist > inner_radius) {
return true
}
}
return false
}
buffer := @as([u8; 61], idk)
render_row := fn(y: uint): void {
x := 0
loop {
if (x > 60) {
break
}
buffer[x] = 32
}
x = 0
loop {
if (x > 60) {
break
}
if (is_filled(x, y, 30.0, 30.0, 10.0, 20.0)) {
buffer[x] = 35
}
x = x + 1
}
log(buffer[0])
}
main := fn(): int { main := fn(): int {
y := 0 a := 10
loop { b := 20
if (y > 60) {
break if &a == &a {
} return 10
render_row(y) } else {
y = y + 1 return 20
} }
return 0
} }