forked from AbleOS/holey-bytes
fg
This commit is contained in:
parent
5df4fb8882
commit
9dfb2eb606
|
@ -658,6 +658,20 @@ main := fn(): uint {
|
|||
|
||||
### 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
|
||||
```hb
|
||||
Color := struct {b: u8}
|
||||
|
|
|
@ -871,7 +871,8 @@ impl Nodes {
|
|||
|
||||
if lhs == rhs {
|
||||
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 => {
|
||||
let rhs = self.new_const(ty, 2);
|
||||
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 {
|
||||
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(
|
||||
id,
|
||||
right.ty,
|
||||
|
@ -5514,6 +5523,7 @@ mod tests {
|
|||
fb_driver;
|
||||
|
||||
// Purely Testing Examples;
|
||||
pointer_comparison;
|
||||
different_function_destinations;
|
||||
triggering_store_in_divergent_branch;
|
||||
wrong_dead_code_elimination;
|
||||
|
|
7
lang/tests/son_tests_pointer_comparison.txt
Normal file
7
lang/tests/son_tests_pointer_comparison.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
main:
|
||||
LI64 r13, 10d
|
||||
CP r1, r13
|
||||
JALA r0, r31, 0a
|
||||
code size: 32
|
||||
ret: 10
|
||||
status: Ok(())
|
|
@ -8,9 +8,9 @@ main:
|
|||
ST r33, r254, 0a, 8h
|
||||
CP r2, r32
|
||||
JAL r31, r0, :modify
|
||||
CP r2, r33
|
||||
JAL r31, r0, :drop
|
||||
LD r32, r254, 0a, 8h
|
||||
CP r2, r32
|
||||
JAL r31, r0, :drop
|
||||
ADDI64 r32, r32, -2d
|
||||
CP r1, r32
|
||||
LD r31, r254, 8a, 24h
|
||||
|
|
75
smh.hb
75
smh.hb
|
@ -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 {
|
||||
y := 0
|
||||
loop {
|
||||
if (y > 60) {
|
||||
break
|
||||
a := 10
|
||||
b := 20
|
||||
|
||||
if &a == &a {
|
||||
return 10
|
||||
} else {
|
||||
return 20
|
||||
}
|
||||
render_row(y)
|
||||
y = y + 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue