From 4e6bae69a17219fa22877638bbcfea48d7bc3930 Mon Sep 17 00:00:00 2001 From: Spotandjake Date: Wed, 23 Oct 2024 19:55:01 -0400 Subject: [PATCH 1/3] feat(grain): Correct list lifting --- crates/grain/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/grain/src/lib.rs b/crates/grain/src/lib.rs index 532f8c7cb..67e968138 100644 --- a/crates/grain/src/lib.rs +++ b/crates/grain/src/lib.rs @@ -2490,9 +2490,9 @@ impl Bindgen for FunctionBindgen<'_, '_> { self.push_str(&format!("let mut {} = []\n", result)); self.push_str(&format!("Memory.incRef(WasmI32.fromGrain({}))\n", result)); - self.push_str("for (let mut i = WasmI32.(-)("); + self.push_str("for (let mut i = "); self.push_str(&len); - self.push_str(", 1n); WasmI32.gtU(i, 0n); i = WasmI32.(-)(i, 1n)) {\n"); + self.push_str("; WasmI32.gtU(i, 0n); i = WasmI32.(-)(i, 1n)) {\n"); self.push_str("let base = WasmI32.(+)("); self.push_str(&base); self.push_str(", WasmI32.(*)(i, "); From 493415384c64147aa74a1bc60c71faa4f36e684c Mon Sep 17 00:00:00 2001 From: Spotandjake Date: Wed, 23 Oct 2024 20:38:36 -0400 Subject: [PATCH 2/3] feat(grain): Account for off by one --- crates/grain/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/grain/src/lib.rs b/crates/grain/src/lib.rs index 67e968138..e4cfc09a4 100644 --- a/crates/grain/src/lib.rs +++ b/crates/grain/src/lib.rs @@ -2495,7 +2495,7 @@ impl Bindgen for FunctionBindgen<'_, '_> { self.push_str("; WasmI32.gtU(i, 0n); i = WasmI32.(-)(i, 1n)) {\n"); self.push_str("let base = WasmI32.(+)("); self.push_str(&base); - self.push_str(", WasmI32.(*)(i, "); + self.push_str(", WasmI32.(*)(WasmI32.(-)(i, 1n), "); self.push_str(&size.to_string()); self.push_str("n))\n"); self.push_str(&body); From 9aee988e265466853e632bbc9fea8ad50a2eb19c Mon Sep 17 00:00:00 2001 From: Spotandjake Date: Tue, 29 Oct 2024 23:33:15 -0400 Subject: [PATCH 3/3] fix: Prevent Module Generation For Empty Resource --- crates/grain/src/lib.rs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/crates/grain/src/lib.rs b/crates/grain/src/lib.rs index e4cfc09a4..32dab196f 100644 --- a/crates/grain/src/lib.rs +++ b/crates/grain/src/lib.rs @@ -165,21 +165,22 @@ impl WorldGenerator for Grain { _ => false, }) .collect(); - - gen.src.push_str("\nprovide module "); - gen.src.push_str( - &resolve.types[**resource] - .name - .as_ref() - .unwrap() - .to_upper_camel_case(), - ); - gen.src.push_str(" {"); - for (_name, func) in resource_funcs.iter() { - gen.src.push_str("\n"); - gen.import(resolve, func); + if resource_funcs.len() > 0 { + gen.src.push_str("\nprovide module "); + gen.src.push_str( + &resolve.types[**resource] + .name + .as_ref() + .unwrap() + .to_upper_camel_case(), + ); + gen.src.push_str(" {"); + for (_name, func) in resource_funcs.iter() { + gen.src.push_str("\n"); + gen.import(resolve, func); + } + gen.src.push_str("}\n"); } - gen.src.push_str("}\n"); } gen.src.push_str("}\n\n"); gen.finish();