MCPcopy Create free account
hub / github.com/bytecodealliance/wit-bindgen / list_lower_to_memory

Method list_lower_to_memory

crates/moonbit/src/async_support.rs:574–608  ·  view source on GitHub ↗
(&mut self, lower_func: &str, value: &str, ty: &Type)

Source from the content-addressed store, hash-verified

572 }
573
574 fn list_lower_to_memory(&mut self, lower_func: &str, value: &str, ty: &Type) -> String {
575 // Align the address, moonbit only supports wasm32 for now
576 let ffi = self
577 .world_gen
578 .pkg_resolver
579 .qualify_package(self.name, FFI_DIR);
580 if self.is_list_canonical(self.resolve, ty) {
581 if ty == &Type::U8 {
582 return format!("{ffi}bytes2ptr({value})");
583 }
584
585 let ty = match ty {
586 Type::U32 => "uint",
587 Type::U64 => "uint64",
588 Type::S32 => "int",
589 Type::S64 => "int64",
590 Type::F32 => "float",
591 Type::F64 => "double",
592 _ => unreachable!(),
593 };
594 return format!("{ffi}{ty}_array2ptr({value})");
595 }
596 let size = self.world_gen.sizes.size(ty).size_wasm32();
597 format!(
598 r#"
599 let address = {ffi}malloc(({value}).length() * {size});
600 for index = 0; index < ({value}).length(); index = index + 1 {{
601 let ptr = (address) + (index * {size});
602 let value = {value}[index];
603 {lower_func}(value, ptr);
604 }}
605 address
606 "#
607 )
608 }
609}

Calls 3

qualify_packageMethod · 0.80
is_list_canonicalMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected