Example #1
0
 def build_sequence_branch(self,
                           delegator: sequencing.SequencingElement,
                           if_branch: sequencing.SequencingElement,
                           else_branch: sequencing.SequencingElement,
                           sequencer: sequencing.Sequencer,
                           parameters: Dict[str, Parameter],
                           conditions: Dict[str, Condition],
                           measurement_mapping: Dict[str, str],
                           channel_mapping: Dict[ChannelID, ChannelID],
                           instruction_block: InstructionBlock) -> None:
     if_block = InstructionBlock()
     else_block = InstructionBlock()
     
     instruction_block.add_instruction_cjmp(self.__trigger, if_block)
     sequencer.push(if_branch, parameters, conditions, window_mapping=measurement_mapping,
                    channel_mapping=channel_mapping,
                    target_block=if_block)
     
     instruction_block.add_instruction_goto(else_block)
     sequencer.push(else_branch, parameters, conditions, window_mapping=measurement_mapping,
                    channel_mapping=channel_mapping,
                    target_block=else_block)
     
     if_block.return_ip = InstructionPointer(instruction_block,
                                             len(instruction_block.instructions))
     else_block.return_ip = if_block.return_ip
Example #2
0
 def test_nested_goto(self) -> None:
     parent_block = InstructionBlock()
     block = InstructionBlock()
     block.return_ip = InstructionPointer(parent_block, 1)
     parent_block.add_instruction_goto(block)
     context = dict()
     immutable_block = ImmutableInstructionBlock(parent_block, context)
     self.__verify_block(parent_block, immutable_block, context)
Example #3
0
 def test_nested_no_context_argument(self) -> None:
     parent_block = InstructionBlock()
     block = InstructionBlock()
     block.return_ip = InstructionPointer(parent_block, 1)
     parent_block.add_instruction_goto(block)
     immutable_block = ImmutableInstructionBlock(parent_block)
     context = {
         parent_block: immutable_block,
         block: immutable_block.instructions[0].target.block
     }
     self.__verify_block(parent_block, immutable_block, context)
 def test_add_instruction_goto(self) -> None:
     block = InstructionBlock()
     expected_instructions = []
     
     targets = [(InstructionBlock(), 0), (InstructionBlock(), 1), (InstructionBlock(), 50)]
     LOOKUP = [0, 1, 1, 0, 2, 1, 0, 0, 0, 1, 2, 2]
     for id in LOOKUP:
         target = targets[id]
         instruction = GOTOInstruction(target[0], target[1])
         expected_instructions.append(instruction)
         block.add_instruction_goto(target[0], target[1])
         
     expected_compiled_instructions = expected_instructions.copy()
     expected_compiled_instructions.append(STOPInstruction())
     self.__verify_block(block, expected_instructions, expected_compiled_instructions)
Example #5
0
    def test_add_instruction_goto(self) -> None:
        block = InstructionBlock()
        expected_instructions = []

        targets = [InstructionBlock(), InstructionBlock(), InstructionBlock()]
        LOOKUP = [0, 1, 1, 0, 2, 1, 0, 0, 0, 1, 2, 2]
        for id in LOOKUP:
            target = targets[id]
            instruction = GOTOInstruction(InstructionPointer(target))
            expected_instructions.append(instruction)
            block.add_instruction_goto(target)

        expected_compiled_instructions = expected_instructions.copy()
        expected_compiled_instructions.append(STOPInstruction())
        self.__verify_block(block, expected_instructions,
                            expected_compiled_instructions, None)
Example #6
0
    def build_sequence_branch(self, delegator: SequencingElement,
                              if_branch: SequencingElement,
                              else_branch: SequencingElement,
                              sequencer: Sequencer,
                              parameters: Dict[str, Parameter],
                              conditions: Dict[str, Condition],
                              instruction_block: InstructionBlock) -> None:
        if_block = InstructionBlock()
        else_block = InstructionBlock()

        instruction_block.add_instruction_cjmp(self.__trigger, if_block)
        sequencer.push(if_branch, parameters, conditions, if_block)

        instruction_block.add_instruction_goto(else_block)
        sequencer.push(else_branch, parameters, conditions, else_block)

        if_block.return_ip = InstructionPointer(
            instruction_block, len(instruction_block.instructions))
        else_block.return_ip = if_block.return_ip