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

Function function_references

cranelift/interpreter/src/interpreter.rs:646–674  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

644 // single function at a time--we need more than one function in the store for this test.
645 #[test]
646 fn function_references() {
647 let code = "
648 function %child(i32) -> i32 {
649 block0(v0: i32):
650 v2 = iconst.i32 -1
651 v1 = iadd v0, v2
652 return v1
653 }
654
655 function %parent(i32) -> i32 {
656 fn42 = %child(i32) -> i32
657 block0(v0: i32):
658 v3 = iconst.i32 1
659 v1 = iadd v0, v3
660 v2 = call fn42(v1)
661 return v2
662 }";
663
664 let mut env = FunctionStore::default();
665 let funcs = parse_functions(code).unwrap().to_vec();
666 funcs.iter().for_each(|f| env.add(f.name.to_string(), f));
667
668 let state = InterpreterState::default().with_function_store(env);
669 let result = Interpreter::new(state)
670 .call_by_name("%parent", &[DataValue::I32(0)])
671 .unwrap();
672
673 assert_eq!(result, ControlFlow::Return(smallvec![DataValue::I32(0)]));
674 }
675
676 #[test]
677 fn fuel() {

Callers

nothing calls this directly

Calls 9

parse_functionsFunction · 0.85
with_function_storeMethod · 0.80
call_by_nameMethod · 0.80
newFunction · 0.50
to_vecMethod · 0.45
unwrapMethod · 0.45
iterMethod · 0.45
addMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected