fixing some bugs and extending runtime of programs

This commit is contained in:
Jakub Doka 2024-11-23 12:35:16 +01:00
parent b030b1eeb7
commit fb11c94af4
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
3 changed files with 80 additions and 5 deletions

View file

@ -14,7 +14,7 @@ const stack_pointer_offset = 1 << 20;
/** @param {WebAssembly.Instance} instance @param {Post[]} packages @param {number} fuel /** @param {WebAssembly.Instance} instance @param {Post[]} packages @param {number} fuel
* @returns {string} */ * @returns {string} */
function compileCode(instance, packages, fuel = 1) { function compileCode(instance, packages, fuel = 100) {
let { let {
INPUT, INPUT_LEN, INPUT, INPUT_LEN,
LOG_MESSAGES, LOG_MESSAGES_LEN, LOG_MESSAGES, LOG_MESSAGES_LEN,

View file

@ -758,11 +758,7 @@ impl Nodes {
} }
if let Some(new) = self.peephole(node, tys) { if let Some(new) = self.peephole(node, tys) {
let plen = stack.len();
stack.append(&mut self.queued_peeps); stack.append(&mut self.queued_peeps);
for &p in &stack[plen..] {
self.lock(p);
}
self.replace(node, new); self.replace(node, new);
self.push_adjacent_nodes(new, stack); self.push_adjacent_nodes(new, stack);
} }
@ -998,6 +994,9 @@ impl Nodes {
self.lock(target); self.lock(target);
for i in self[target].outputs.clone() { for i in self[target].outputs.clone() {
if self[i].kind == Kind::Phi { if self[i].kind == Kind::Phi {
for o in self[i].outputs.clone() {
self.lock(o);
}
self.queued_peeps.extend(self[i].outputs.clone()); self.queued_peeps.extend(self[i].outputs.clone());
self.replace(i, self[i].inputs[side]); self.replace(i, self[i].inputs[side]);
} }
@ -1272,6 +1271,7 @@ impl Nodes {
inps[2] = region; inps[2] = region;
inps[3] = prev_store; inps[3] = prev_store;
prev_store = self.new_node_nop(self[oper].ty, Kind::Stre, inps); prev_store = self.new_node_nop(self[oper].ty, Kind::Stre, inps);
self.lock(prev_store);
self.queued_peeps.push(prev_store); self.queued_peeps.push(prev_store);
} }
@ -1384,6 +1384,9 @@ impl Nodes {
self.remove(prev); self.remove(prev);
self.unlock(o); self.unlock(o);
for o in self[o].outputs.clone() {
self.lock(o);
}
self.queued_peeps.extend(self[o].outputs.clone()); self.queued_peeps.extend(self[o].outputs.clone());
self.replace(o, self[o].inputs[1]); self.replace(o, self[o].inputs[1]);
} }
@ -4925,6 +4928,7 @@ impl<'a> Codegen<'a> {
) -> bool { ) -> bool {
if let Some(upcasted) = src.ty.try_upcast(expected) if let Some(upcasted) = src.ty.try_upcast(expected)
&& upcasted == expected && upcasted == expected
&& upcasted.is_pointer() == src.ty.is_pointer()
{ {
if src.ty.is_never() { if src.ty.is_never() {
return true; return true;

71
smh.hb Normal file
View file

@ -0,0 +1,71 @@
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
}
render_row(y)
y = y + 1
}
return 0
}