Add shortcuts for native operations

This commit is contained in:
Rerumu
2022-05-21 04:11:04 -04:00
parent c3a3a09107
commit ce54d834a5
4 changed files with 21 additions and 20 deletions
+10 -1
View File
@@ -230,12 +230,21 @@ fn build_func_list(wasm: &Module, type_info: &TypeInfo) -> Vec<Intermediate> {
.collect()
}
fn write_local_operation(head: &str, tail: &str, w: &mut dyn Write) -> Result<()> {
match (head, tail) {
("abs" | "ceil" | "floor" | "sqrt" | "min" | "max", _) | ("band" | "bor" | "bxor", _) => {
write!(w, "local {head}_{tail} = math.{head} ")
}
_ => write!(w, "local {head}_{tail} = rt.{head}.{tail} "),
}
}
fn write_localize_used(func_list: &[Intermediate], w: &mut dyn Write) -> Result<()> {
let loc_set: BTreeSet<_> = func_list.iter().flat_map(localize::visit).collect();
loc_set
.into_iter()
.try_for_each(|(a, b)| write!(w, "local {a}_{b} = rt.{a}.{b} "))
.try_for_each(|(a, b)| write_local_operation(a, b, w))
}
fn write_memory_used(func_list: &[Intermediate], w: &mut dyn Write) -> Result<Vec<usize>> {