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

Function function_stack_ordering

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

Source from the content-addressed store, hash-verified

674
675 #[test]
676 pub fn function_stack_ordering() {
677 let mut ir = IR::new();
678 let mut f = Node::function::<1, 1>(&mut ir);
679 let input = f.add_argument(&mut ir);
680 let output = f.add_return(&mut ir);
681 // We create a stack slot
682 let mut ss1 = f.add_stack_slot(&mut ir);
683 let initial_ss = ss1;
684
685 // ...and push, which should resolve to a use of ss1
686 let mut push = Node::simple(Operation::StoreStack);
687 ss1 = f.add_body(push, &mut ir, |i, r| {
688 i.connect_input(0, ss1, r);
689 i.connect_input(1, input, r);
690 i.sinks()[0]
691 }).1;
692
693 let mut pop = Node::simple(Operation::LoadStack);
694 let ss_val_0 = f.add_body(pop, &mut ir, |i, r| {
695 i.connect_input(0, ss1, r);
696 i.sinks()[0]
697 }).1;
698
699 // then add to it via ss1
700 let mut two = Node::constant(2);
701 let mut add = Node::simple(Operation::Add);
702 let mut two_const = f.add_body(two, &mut ir, |two, r| {
703 two.sinks()[0]
704 }).1;
705 let added_val = f.add_body(add, &mut ir, |add, r| {
706 println!("add closure {}", r.ports[ss1].storage);
707 add.connect_input(0, ss_val_0, r);
708 add.connect_input(1, two_const, r);
709 add.sinks()[0]
710 }).1;
711
712 // and store it again
713 let mut push = Node::simple(Operation::StoreStack);
714 f.add_body(push, &mut ir, |i, r| {
715 i.connect_input(0, ss1, r);
716 i.connect_input(1, added_val, r);
717 ss1 = i.sinks()[0];
718 });
719
720 // make a use of the *initial* stack value from before the load
721 let mut pop = Node::simple(Operation::LoadStack);
722 let ss_val_1 = f.add_body(pop, &mut ir, |i, r| {
723 i.connect_input(0, initial_ss, r);
724 i.sinks()[0]
725 }).1;
726
727 let mut three = Node::constant(3);
728 let mut add = Node::simple(Operation::Add);
729 let mut three_const = f.add_body(three, &mut ir, |three, r| {
730 three.sinks()[0]
731 }).1;
732 f.add_body(add, &mut ir, |add, r| {
733 add.connect_input(0, ss_val_1, r);

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected