fixing some bugs and extending runtime of programs
This commit is contained in:
parent
b030b1eeb7
commit
fb11c94af4
|
@ -14,7 +14,7 @@ const stack_pointer_offset = 1 << 20;
|
|||
|
||||
/** @param {WebAssembly.Instance} instance @param {Post[]} packages @param {number} fuel
|
||||
* @returns {string} */
|
||||
function compileCode(instance, packages, fuel = 1) {
|
||||
function compileCode(instance, packages, fuel = 100) {
|
||||
let {
|
||||
INPUT, INPUT_LEN,
|
||||
LOG_MESSAGES, LOG_MESSAGES_LEN,
|
||||
|
|
|
@ -758,11 +758,7 @@ impl Nodes {
|
|||
}
|
||||
|
||||
if let Some(new) = self.peephole(node, tys) {
|
||||
let plen = stack.len();
|
||||
stack.append(&mut self.queued_peeps);
|
||||
for &p in &stack[plen..] {
|
||||
self.lock(p);
|
||||
}
|
||||
self.replace(node, new);
|
||||
self.push_adjacent_nodes(new, stack);
|
||||
}
|
||||
|
@ -998,6 +994,9 @@ impl Nodes {
|
|||
self.lock(target);
|
||||
for i in self[target].outputs.clone() {
|
||||
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.replace(i, self[i].inputs[side]);
|
||||
}
|
||||
|
@ -1272,6 +1271,7 @@ impl Nodes {
|
|||
inps[2] = region;
|
||||
inps[3] = prev_store;
|
||||
prev_store = self.new_node_nop(self[oper].ty, Kind::Stre, inps);
|
||||
self.lock(prev_store);
|
||||
self.queued_peeps.push(prev_store);
|
||||
}
|
||||
|
||||
|
@ -1384,6 +1384,9 @@ impl Nodes {
|
|||
self.remove(prev);
|
||||
self.unlock(o);
|
||||
|
||||
for o in self[o].outputs.clone() {
|
||||
self.lock(o);
|
||||
}
|
||||
self.queued_peeps.extend(self[o].outputs.clone());
|
||||
self.replace(o, self[o].inputs[1]);
|
||||
}
|
||||
|
@ -4925,6 +4928,7 @@ impl<'a> Codegen<'a> {
|
|||
) -> bool {
|
||||
if let Some(upcasted) = src.ty.try_upcast(expected)
|
||||
&& upcasted == expected
|
||||
&& upcasted.is_pointer() == src.ty.is_pointer()
|
||||
{
|
||||
if src.ty.is_never() {
|
||||
return true;
|
||||
|
|
71
smh.hb
Normal file
71
smh.hb
Normal 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
|
||||
}
|
Loading…
Reference in a new issue