def test_build_sequence_loop(self) -> None: sequencer = DummySequencer(DummySequencingHardware()) block = DummyInstructionBlock() delegator = DummySequencingElement() body = DummySequencingElement() trigger = Trigger() condition = HardwareCondition(trigger) condition.build_sequence_loop(delegator, body, sequencer, [], block) self.assertEqual(1, len(block.embedded_blocks)) body_block = block.embedded_blocks[0] self.assertEqual( [CJMPInstruction(trigger, body_block, 0)], block.instructions, "The expected conditional jump was not generated by HardwareConditon.", ) self.assertEqual( InstructionPointer(block, 0), body_block.return_ip, "The return address of the loop body block was set wrongly by HardwareCondition.", ) self.assertEqual( {body_block: [(body, [])]}, sequencer.sequencing_stacks, "HardwareCondition did not correctly push the body element to the stack", )
def test_build_sequence_branch(self) -> None: sequencer = DummySequencer(DummySequencingHardware()) block = DummyInstructionBlock() delegator = DummySequencingElement() if_branch = DummySequencingElement() else_branch = DummySequencingElement() trigger = Trigger() condition = HardwareCondition(trigger) condition.build_sequence_branch(delegator, if_branch, else_branch, sequencer, [], block) self.assertEqual(2, len(block.embedded_blocks)) if_block = block.embedded_blocks[0] else_block = block.embedded_blocks[1] self.assertEqual( [CJMPInstruction(trigger, if_block, 0), GOTOInstruction(else_block, 0)], block.instructions, "The expected jump instruction were not generated by HardwareConditon.", ) self.assertEqual( InstructionPointer(block, 2), if_block.return_ip, "The return address of the if branch block was set wrongly by HardwareConditon.", ) self.assertEqual( InstructionPointer(block, 2), else_block.return_ip, "The return address of the else branch block was set wrongly by HardwareConditon.", ) self.assertEqual( {if_block: [(if_branch, [])], else_block: [(else_branch, [])]}, sequencer.sequencing_stacks, "HardwareCondition did not correctly push the branch elements to the stack", )