MCPcopy Create free account
hub / github.com/chc4/lineiform / function_tailcall_external

Function function_tailcall_external

tangle/src/ir.rs:746–770  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

744
745 #[test]
746 pub fn function_tailcall_external() {
747 let mut ir = IR::new();
748 let mut f = Node::function::<1, 1>(&mut ir);
749 let input = f.add_argument(&mut ir);
750 let output = f.add_return(&mut ir);
751
752 extern "C" fn external_function(a: usize) -> usize {
753 a + 2
754 }
755
756 let mut addr = Node::constant(external_function as *const () as isize);
757 let mut tailcall = Node::leave();
758 let mut addr_const = None;
759 f.add_body(addr, &mut ir, |addr, r| {
760 addr_const = Some(addr.sinks()[0]);
761 });
762 f.add_body(tailcall, &mut ir, |tailcall, r| {
763 tailcall.connect_input(0, addr_const.unwrap(), r);
764 });
765
766 ir.set_body(f);
767 let hello_fn: extern "C" fn(usize) -> usize = ir.compile_fn().unwrap().0;
768 assert_eq!(hello_fn(0), 2);
769 assert_eq!(hello_fn(1), 3);
770 }
771
772 #[test]
773 pub fn function_tailcall_with_shuffle() {

Callers

nothing calls this directly

Calls 7

add_argumentMethod · 0.80
add_returnMethod · 0.80
add_bodyMethod · 0.80
sinksMethod · 0.80
connect_inputMethod · 0.80
set_bodyMethod · 0.80
compile_fnMethod · 0.80

Tested by

no test coverage detected