From a64383e72b0920ef1c03773aac197404c78b330f Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Sat, 16 Nov 2024 20:52:34 +0100 Subject: [PATCH] saving --- lang/README.md | 42 +++++++++++++----------------------------- lang/src/son.rs | 2 +- xtask/src/main.rs | 2 +- 3 files changed, 15 insertions(+), 31 deletions(-) diff --git a/lang/README.md b/lang/README.md index ee8f1a5..fa595d4 100644 --- a/lang/README.md +++ b/lang/README.md @@ -707,40 +707,24 @@ main := fn(): void { #### very_nested_loops ```hb -$W := 200 -$H := 200 -$MAX_ITER := 20 -$ZOOM := 0.5 + +$H := 3 +$W := 3 main := fn(): int { - mv_x := 0.5 - mv_y := 0.0 - - y := 0 - loop if y < H break else { - x := 0 - loop if x < W break else { - i := MAX_ITER - 1 - - c_i := (2.0 * @floatcast(@itf(@as(i32, @intcast(x)))) - @floatcast(@itf(@as(i32, @intcast(W))))) / (W * ZOOM) + mv_x - c_r := (2.0 * @floatcast(@itf(@as(i32, @intcast(y)))) - @floatcast(@itf(@as(i32, @intcast(H))))) / (H * ZOOM) + mv_y - - z_i := c_i - z_r := c_r - - // iteration - loop if (z_r + z_i) * (z_r + z_i) >= 4 | i == 0 break else { - // z = z * z + c - z_i = z_i * z_i + c_i - z_r = z_r * z_r + c_r - i -= 1 - } - // b g r - put_pixel(.(x, y), .(@intcast(i), @intcast(i), @intcast(i), 255)) + y := @as(int, 0) + loop if y == H break else { + x := @as(int, 0) + loop if x == W break else { + c_r := @itf(x) + c_i := @itf(y) + if c_i * c_r >= 10.0 return 0 + x += 1 } + y += 1 } - return 0 + return 1 } Color := struct {r: u8, g: u8, b: u8, a: u8} diff --git a/lang/src/son.rs b/lang/src/son.rs index 9208ed0..080638e 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -4844,7 +4844,7 @@ mod tests { fn generate(ident: &'static str, input: &'static str, output: &mut String) { _ = log::set_logger(&crate::fs::Logger); log::set_max_level(log::LevelFilter::Info); - //log::set_max_level(log::LevelFilter::Trace); + log::set_max_level(log::LevelFilter::Trace); let mut ctx = CodegenCtx::default(); let (ref files, embeds) = crate::test_parse_files(ident, input, &mut ctx.parser); diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 1c544c2..6e73341 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -25,7 +25,7 @@ fn build_cmd(cmd: impl AsRef) -> std::process::Command { } fn exec(mut cmd: std::process::Command) -> io::Result<()> { - if !cmd.status()?.success() { + if !cmd.status().inspect_err(|e| println!("failed to execute '{cmd:?}': {e}"))?.success() { return Err(io::Error::other(format!("command failed: {:?}", cmd))); } Ok(())