Example #1
0
class IntOptValue(OptValue):
    _attrs_ = ('intbound',)

    intbound = ImmutableIntUnbounded()

    def __init__(self, box, level=None, known_class=None, intbound=None):
        OptValue.__init__(self, box, level, None, None)
        if isinstance(box, Const):
            return
        if intbound:
            self.intbound = intbound
        else:
            if isinstance(box, BoxInt):
                self.intbound = IntBound(MININT, MAXINT)
            else:
                self.intbound = IntUnbounded()

    def copy_from(self, other_value):
        assert isinstance(other_value, IntOptValue)
        self.box = other_value.box
        self.intbound = other_value.intbound
        self._tag = other_value._tag

    def make_constant(self, constbox):
        """Replace 'self.box' with a Const box."""
        assert isinstance(constbox, ConstInt)
        self.box = constbox
        self.setlevel(LEVEL_CONSTANT)
        val = constbox.getint()
        self.intbound = IntBound(val, val)

    def is_nonnull(self):
        if OptValue.is_nonnull(self):
            return True
        if self.intbound:
            if self.intbound.known_gt(IntBound(0, 0)) or \
               self.intbound.known_lt(IntBound(0, 0)):
                return True
        return False

    def make_nonnull(self, optimizer):
        assert self.getlevel() < LEVEL_NONNULL
        self.setlevel(LEVEL_NONNULL)

    def import_from(self, other, optimizer):
        OptValue.import_from(self, other, optimizer)
        if self.getlevel() != LEVEL_CONSTANT:
            if other.getintbound() is not None: # VRawBufferValue
                self.intbound.intersect(other.getintbound())

    def make_guards(self, box):
        guards = []
        level = self.getlevel()
        if level == LEVEL_CONSTANT:
            op = ResOperation(rop.GUARD_VALUE, [box, self.box], None)
            guards.append(op)
        elif level == LEVEL_KNOWNCLASS:
            op = ResOperation(rop.GUARD_NONNULL, [box], None)
            guards.append(op)
        else:
            if level == LEVEL_NONNULL:
                op = ResOperation(rop.GUARD_NONNULL, [box], None)
                guards.append(op)
            self.intbound.make_guards(box, guards)
        return guards

    def getintbound(self):
        return self.intbound

    def get_last_guard(self, optimizer):
        return None

    def get_known_class(self):
        return None

    def getlenbound(self):
        return None
Example #2
0
class IntOptValue(OptValue):
    _attrs_ = ('intbound', )

    intbound = ImmutableIntUnbounded()

    def __init__(self, box, level=None, known_class=None, intbound=None):
        OptValue.__init__(self, box, level, None, None)
        if isinstance(box, Const):
            return
        if intbound:
            self.intbound = intbound
        else:
            if isinstance(box, BoxInt):
                self.intbound = IntBound(MININT, MAXINT)
            else:
                self.intbound = IntUnbounded()

    def copy_from(self, other_value):
        assert isinstance(other_value, IntOptValue)
        self.box = other_value.box
        self.intbound = other_value.intbound
        self._tag = other_value._tag

    def make_constant(self, constbox):
        """Replace 'self.box' with a Const box."""
        assert isinstance(constbox, ConstInt)
        self.box = constbox
        self.setlevel(LEVEL_CONSTANT)
        val = constbox.getint()
        self.intbound = IntBound(val, val)

    def is_nonnull(self):
        if OptValue.is_nonnull(self):
            return True
        if self.intbound:
            if self.intbound.known_gt(IntBound(0, 0)) or \
               self.intbound.known_lt(IntBound(0, 0)):
                return True
        return False

    def make_nonnull(self, optimizer):
        assert self.getlevel() < LEVEL_NONNULL
        self.setlevel(LEVEL_NONNULL)

    def import_from(self, other, optimizer):
        OptValue.import_from(self, other, optimizer)
        if self.getlevel() != LEVEL_CONSTANT:
            if other.getintbound() is not None:  # VRawBufferValue
                self.intbound.intersect(other.getintbound())

    def make_guards(self, box):
        guards = []
        level = self.getlevel()
        if level == LEVEL_CONSTANT:
            op = ResOperation(rop.GUARD_VALUE, [box, self.box], None)
            guards.append(op)
        elif level == LEVEL_KNOWNCLASS:
            op = ResOperation(rop.GUARD_NONNULL, [box], None)
            guards.append(op)
        else:
            if level == LEVEL_NONNULL:
                op = ResOperation(rop.GUARD_NONNULL, [box], None)
                guards.append(op)
            self.intbound.make_guards(box, guards)
        return guards

    def getintbound(self):
        return self.intbound

    def get_last_guard(self, optimizer):
        return None

    def get_known_class(self):
        return None

    def getlenbound(self):
        return None