def da_if_transform(insts: dal.InstGrp, body: dal.InstGrp, elseBody: dal.InstGrp) -> None: test_result = insts.getFlag(insts.TEST_EXPR) assert (isinstance(test_result, core.DBool) or isinstance(test_result, dal.Var)) # Create Jmp instruction else_exists = len(elseBody) > 0 body_exists = len(body) > 0 if else_exists: next_inst_idx = len(elseBody) + 1 + len(insts) jmp_inst = dal.JmpTrue(test_result, core.DInt(next_inst_idx)) else: if body_exists: next_inst_idx = len(body) + 1 + len(insts) jmp_inst = dal.JmpFalse(test_result, core.DInt(next_inst_idx)) else: return insts.addInst(jmp_inst) insts.addInsts(elseBody.insts()) insts.addInsts(body.insts())
def IfStmt_Case_1() -> bool: box = BoxMachinePlus() if box.query(DStr("ident")) == "Box": v = core.DInt(1) else: v = core.DInt(2) return True