Ejemplo n.º 1
0
def _int_sub(optimizer, box1, box2):
    if isinstance(box2, ConstInt):
        if box2.value == 0:
            return box1
        if isinstance(box1, ConstInt):
            return ConstInt(box1.value - box2.value)
    resbox = BoxInt()
    optimizer.propagate_forward(ResOperation(rop.INT_SUB, [box1, box2], resbox))
    return resbox
Ejemplo n.º 2
0
def _strgetitem(optimizer, strbox, indexbox, mode):
    if isinstance(strbox, ConstPtr) and isinstance(indexbox, ConstInt):
        if mode is mode_string:
            s = strbox.getref(lltype.Ptr(rstr.STR))
            return ConstInt(ord(s.chars[indexbox.getint()]))
        else:
            s = strbox.getref(lltype.Ptr(rstr.UNICODE))
            return ConstInt(ord(s.chars[indexbox.getint()]))
    resbox = BoxInt()
    optimizer.propagate_forward(ResOperation(mode.STRGETITEM, [strbox, indexbox],
                                      resbox))
    return resbox
Ejemplo n.º 3
0
def _int_add(optimizer, box1, box2):
    if isinstance(box1, ConstInt):
        if box1.value == 0:
            return box2
        if isinstance(box2, ConstInt):
            return ConstInt(box1.value + box2.value)
    elif isinstance(box2, ConstInt) and box2.value == 0:
        return box1
    if optimizer is None:
        return None
    resbox = BoxInt()
    optimizer.propagate_forward(ResOperation(rop.INT_ADD, [box1, box2], resbox))
    return resbox