MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / make_echo_component_with_params

Function make_echo_component_with_params

tests/all/component_model.rs:207–290  ·  view source on GitHub ↗
(type_definition: &str, params: &[Param])

Source from the content-addressed store, hash-verified

205}
206
207fn make_echo_component_with_params(type_definition: &str, params: &[Param]) -> String {
208 let func = if params.len() == 0 {
209 format!("(func (export \"echo\"))")
210 } else if params.len() == 1 || params.len() > 16 {
211 let primitive = if params.len() == 1 {
212 params[0].0.primitive()
213 } else {
214 "i32"
215 };
216
217 format!(
218 r#"
219 (func (export "echo") (param {primitive}) (result {primitive})
220 local.get 0
221 )"#,
222 )
223 } else {
224 let mut param_string = String::new();
225 let mut store = String::new();
226 let mut size = 8;
227
228 for (index, Param(ty, offset)) in params.iter().enumerate() {
229 let primitive = ty.primitive();
230
231 write!(&mut param_string, " {primitive}").unwrap();
232 if let Some(offset) = offset {
233 write!(
234 &mut store,
235 "({primitive}.{} offset={offset} (local.get $base) (local.get {index}))",
236 ty.store(),
237 )
238 .unwrap();
239
240 size = size.max(offset + 8);
241 }
242 }
243
244 format!(
245 r#"
246 (func (export "echo") (param{param_string}) (result i32)
247 (local $base i32)
248 (local.set $base
249 (call $realloc
250 (i32.const 0)
251 (i32.const 0)
252 (i32.const 4)
253 (i32.const {size})))
254 {store}
255 local.get $base
256 )"#
257 )
258 };
259
260 let type_section = if type_definition.contains("(type ") {
261 type_definition.to_string()
262 } else {
263 format!("(type $Foo' {type_definition})")
264 };

Callers 6

make_echo_componentFunction · 0.85
primitivesFunction · 0.85
recordsFunction · 0.85
variantsFunction · 0.85
flagsFunction · 0.85
everythingFunction · 0.85

Calls 8

newFunction · 0.50
lenMethod · 0.45
primitiveMethod · 0.45
iterMethod · 0.45
unwrapMethod · 0.45
maxMethod · 0.45
containsMethod · 0.45
to_stringMethod · 0.45

Tested by 5

primitivesFunction · 0.68
recordsFunction · 0.68
variantsFunction · 0.68
flagsFunction · 0.68
everythingFunction · 0.68