def test_create_embedded_block(self) -> None:
     parent_block = InstructionBlock()
     block = parent_block.create_embedded_block()
     self.assertRaises(InstructionBlockNotYetPlacedException, block.get_start_address)
     self.assertRaises(MissingReturnAddressException, block.compile_sequence)
     block.return_ip = InstructionPointer(parent_block, 0)
     self.__verify_block(block, [], [GOTOInstruction(parent_block, 0)])
     self.__verify_block(parent_block, [], [STOPInstruction(), GOTOInstruction(parent_block, 0)])
     self.assertEqual(1, block.get_start_address())
 def test_nested_block_construction(self) -> None:
     main_block = InstructionBlock()
     expected_instructions = [[], [], [], []]
     expected_compiled_instructions = [[], [], [], []]
     
     blocks = []
         
     waveforms = [DummyWaveform(), DummyWaveform(), DummyWaveform()]
     
     main_block.add_instruction_exec(waveforms[0])
     expected_instructions[0].append(EXECInstruction(waveforms[0]))
     
     block = main_block.create_embedded_block() 
     trigger = Trigger()
     main_block.add_instruction_cjmp(trigger, block)
     expected_instructions[0].append(CJMPInstruction(trigger, block, 0))
     block.return_ip = InstructionPointer(main_block, len(main_block))
     blocks.append(block)
     
     block = main_block.create_embedded_block()
     trigger = Trigger()
     main_block.add_instruction_cjmp(trigger, block)
     expected_instructions[0].append(CJMPInstruction(trigger, block, 0))
     block.return_ip = InstructionPointer(main_block, len(main_block))
     blocks.append(block)
     
     WAVEFORM_LOOKUP = [[2, 2, 1, 1],[0, 1, 1, 0, 2, 1]]
     for i in [0, 1]:
         block = blocks[i]
         lookup = WAVEFORM_LOOKUP[i]
         for id in lookup:
             waveform = waveforms[id]
             expected_instructions[i + 1].append(EXECInstruction(waveform))
             block.add_instruction_exec(waveform)
         
     block = blocks[0].create_embedded_block()
     blocks[0].add_instruction_cjmp(trigger, block)
     expected_instructions[1].append(CJMPInstruction(trigger, block, 0))
     block.return_ip = InstructionPointer(blocks[0], len(blocks[0]))
     blocks.append(block)
     
     for id in [1, 2, 0, 2]:
         waveform = waveforms[id]
         expected_instructions[3].append(EXECInstruction(waveform))
         block.add_instruction_exec(waveform)
     
     for i in [0, 1, 2, 3]:
         expected_compiled_instructions[i] = expected_instructions[i].copy()
     
     expected_compiled_instructions[0].append(STOPInstruction())
     for i in [0, 1, 2]:
         expected_compiled_instructions[i + 1].append(GOTOInstruction(blocks[i].return_ip.block, blocks[i].return_ip.offset))
     
     positions = [0, None, None, None]                
     positions[3] = len(expected_compiled_instructions[1])
     
     expected_compiled_instructions[1].extend(expected_compiled_instructions[3])
     for i in [1, 2]:
         positions[i] = len(expected_compiled_instructions[0])
         expected_compiled_instructions[0].extend(expected_compiled_instructions[i])
         
     positions[3] += positions[1]
     
     self.__verify_block(blocks[2], expected_instructions[3], expected_compiled_instructions[3])
     self.__verify_block(blocks[1], expected_instructions[2], expected_compiled_instructions[2])
     self.__verify_block(blocks[0], expected_instructions[1], expected_compiled_instructions[1])
     self.__verify_block(main_block, expected_instructions[0], expected_compiled_instructions[0])
     
     self.assertEqual(positions[3], blocks[2].get_start_address())
     self.assertEqual(positions[2], blocks[1].get_start_address())
     self.assertEqual(positions[1], blocks[0].get_start_address())
     self.assertEqual(positions[0], main_block.get_start_address())
     
     for instruction in main_block.instructions:
         if isinstance(instruction, GOTOInstruction) or isinstance(instruction, CJMPInstruction):
             self.assertIsInstance(instruction.target.get_absolute_address(), int)