Beispiel #1
0
def _exp_ne(code: Code, exp):
    left = exp['left']
    right = exp['right']
    left_type = exp['left']['type']
    _expression(code, left)
    _expression(code, right)

    if isinstance(left_type, TypeInt) or isinstance(
            left_type, TypeBool) or isinstance(left_type, TypeReal):
        if isinstance(left_type, TypeReal):
            code.cmp_double_l()
            cmp_pos = code.pos()
            code.if_ne()
        else:
            cmp_pos = code.pos()
            code.if_cmp_int_ne()
        code.const_int(0)
        goto_pos = code.pos()
        code.goto()
        true_pos = code.pos()
        code.const_int(1)
        end_pos = code.pos()

        code.update_jump(cmp_pos, true_pos)
        code.update_jump(goto_pos, end_pos)
    elif isinstance(left_type, TypeStr):
        code.invoke_virtual(*JM_STRING_EQUALS)
        cmp_pos = code.pos()
        code.if_eq()
        code.const_int(0)
        goto_pos = code.pos()
        code.goto()
        false_pos = code.pos()
        code.const_int(1)
        end_pos = code.pos()

        code.update_jump(cmp_pos, false_pos)
        code.update_jump(goto_pos, end_pos)
    else:
        raise NotImplementedError()
Beispiel #2
0
def _exp_or(code: Code, exp):
    left = exp['left']
    right = exp['right']
    t = exp['type']
    _expression(code, left)
    _expression(code, right)

    if isinstance(t, TypeBool):
        cmp1_pos = code.pos()
        code.if_ne()
        cmp2_pos = code.pos()
        code.if_ne()
        code.const_int(0)
        goto_pos = code.pos()
        code.goto()
        true_pos = code.pos()
        code.const_int(1)
        end_pos = code.pos()

        code.update_jump(cmp1_pos, true_pos)
        code.update_jump(cmp2_pos, true_pos)
        code.update_jump(goto_pos, end_pos)
    else:
        raise NotImplementedError()