def _translate_varnames(self): for idx, (op, var, val) in enumerate(self.program): if op not in (Instruction.TAG, Instruction.CPY): self.program[idx] = op, Instruction.var_to_num(var), int(val) elif op == Instruction.CPY: var1 = Instruction.var_to_num(var) var2 = Instruction.var_to_num(val) self.program[idx] = op, var1, var2
def rebuild_ast(instructions): tags, exit = _extract_tags(instructions) for idx, (op, var, val) in enumerate(instructions): if op == Instruction.TAG: yield (op, None, tags[idx + 1]) elif op in (Instruction.INC, Instruction.DEC): yield (op, Instruction.num_to_var(var), str(val)) elif op == Instruction.JNZ: yield (op, Instruction.num_to_var(var), tags.get(idx + 1, exit))