示例#1
0
def set_range_ignore(ctx, index, char_code):
    # <RANGE_IGNORE> <lower> <upper>
    # the char_code is already lower cased
    pat = ctx.pattern
    lower = pat[index + 1]
    upper = pat[index + 2]
    match1 = int_between(lower, char_code, upper + 1)
    match2 = int_between(lower, getupper(char_code, ctx.flags), upper + 1)
    return match1 | match2, index + 3
示例#2
0
 def wrap_positive_32bit_int(self, val):
     # This will always return a positive value.
     # XXX: For now, we assume that val is at most 32bit, i.e. overflows are
     # checked for before wrapping. Also, we ignore tagging.
     if int_between(0, val, constants.MAXINT):
         return model.W_SmallInteger(val)
     else:
         return model.W_LargePositiveInteger1Word(val)
示例#3
0
 def wrap_positive_wordsize_int(self, val):
     # This will always return a positive value.
     from rpython.rlib.objectmodel import we_are_translated
     if not we_are_translated() and val < 0:
         print "WARNING: wrap_positive_32bit_int casts %d to 32bit unsigned" % val
     if int_between(0, val, constants.MAXINT):
         return model.W_SmallInteger(val)
     else:
         return model.W_LargePositiveInteger1Word(val)
示例#4
0
 def short_atput0(self, space, index0, w_value):
     from rpython.rlib.rarithmetic import int_between
     i_value = space.unwrap_int(w_value)
     if not int_between(-0x8000, i_value, 0x8000):
         raise error.PrimitiveFailedError
     byte_index0 = index0 * 2
     byte0 = i_value & 0xff
     byte1 = (i_value & 0xff00) >> 8
     self.setchar(byte_index0, chr(byte0))
     self.setchar(byte_index0 + 1, chr(byte1))
示例#5
0
 def unwrap_char_as_byte(self, space):
     # We do not implement the STRING_REPLACE primitive, but some code paths
     # in Squeak rely on that primitive's munging of ByteArrays and
     # ByteStrings. We are forgiving, so we also allow bytes extraced from
     # ByteArrays to be unwrapped as characters and put into strings
     from rpython.rlib.rarithmetic import int_between
     value = self.value
     if not int_between(0, value, 256):
         raise error.UnwrappingError
     else:
         return chr(self.value)
示例#6
0
def getlower(char_ord, flags):
    if flags & SRE_FLAG_LOCALE:
        if char_ord < 256:      # cheating!  Well, CPython does too.
            char_ord = tolower(char_ord)
        return char_ord
    elif flags & SRE_FLAG_UNICODE:
        assert unicodedb is not None
        char_ord = unicodedb.tolower(char_ord)
    else:
        if int_between(ord('A'), char_ord, ord('Z') + 1):   # ASCII lower
            char_ord += ord('a') - ord('A')
    return char_ord
示例#7
0
def getupper(char_ord, flags):
    if flags & SRE_FLAG_LOCALE:
        if char_ord < 256:      # cheating!  Well, CPython does too.
            char_ord = toupper(char_ord)
        return char_ord
    elif flags & SRE_FLAG_UNICODE:
        assert unicodedb is not None
        char_ord = unicodedb.toupper(char_ord)
    else:
        if int_between(ord('a'), char_ord, ord('z') + 1):   # ASCII upper
            char_ord += ord('A') - ord('a')
    return char_ord
示例#8
0
 def short_atput0(self, space, index0, w_value):
     from rpython.rlib.rarithmetic import int_between
     i_value = space.unwrap_int(w_value)
     if not int_between(-0x8000, i_value, 0x8000):
         raise error.PrimitiveFailedError
     word_index0 = index0 / 2
     word = intmask(self.getword(word_index0))
     if index0 % 2 == 0:
         word = intmask(r_uint(word) & r_uint(0xffff0000)) | (i_value & 0xffff)
     else:
         word = (i_value << 16) | (word & 0xffff)
     value = r_uint(word)
     self.setword(word_index0, value)
示例#9
0
 def _compare(self, space, w_other):
     if isinstance(w_other, W_FloatObject):
         return space.newbool(op(self.floatval, w_other.floatval))
     if space.isinstance_w(w_other, space.w_int):
         f1 = self.floatval
         i2 = space.int_w(w_other)
         # (double-)floats have always at least 48 bits of precision
         if LONG_BIT > 32 and not int_between(-1, i2 >> 48, 1):
             res = do_compare_bigint(f1, rbigint.fromint(i2))
         else:
             f2 = float(i2)
             res = op(f1, f2)
         return space.newbool(res)
     if space.isinstance_w(w_other, space.w_long):
         return space.newbool(do_compare_bigint(self.floatval, space.bigint_w(w_other)))
     return space.w_NotImplemented
示例#10
0
 def _compare(self, space, w_other):
     if isinstance(w_other, W_FloatObject):
         return space.newbool(op(self.floatval, w_other.floatval))
     if space.isinstance_w(w_other, space.w_int):
         f1 = self.floatval
         i2 = space.int_w(w_other)
         # (double-)floats have always at least 48 bits of precision
         if LONG_BIT > 32 and not int_between(-1, i2 >> 48, 1):
             res = do_compare_bigint(f1, rbigint.fromint(i2))
         else:
             f2 = float(i2)
             res = op(f1, f2)
         return space.newbool(res)
     if space.isinstance_w(w_other, space.w_long):
         return space.newbool(
             do_compare_bigint(self.floatval, space.bigint_w(w_other)))
     return space.w_NotImplemented
示例#11
0
def func(interp, s_frame, receiver, shift):
    if isinstance(receiver, int):
        if not (int_between(-constants.LONG_BIT + 1, shift, constants.LONG_BIT)):
            raise PrimitiveFailedError
    if shift >= 0:
        if isinstance(receiver, int):
            try:
                if receiver >= 0:
                    return interp.space.wrap_int(r_uint(ovfcheck(receiver << shift)))
                else:
                    return interp.space.wrap_int((ovfcheck(receiver << shift)))
            except OverflowError:
                raise PrimitiveFailedError
        elif isinstance(receiver, rbigint):
            return interp.space.wrap_rbigint(receiver.lshift(shift))
        else:
            raise PrimitiveFailedError # no point in trying
    else:
        shift = -shift
        if isinstance(receiver, int) or isinstance(receiver, r_int64):
            return interp.space.wrap_int(receiver >> shift)
        else:
            return interp.space.wrap_rbigint(receiver.rshift(shift))
示例#12
0
def is_space(code):
    return (code == 32) | int_between(9, code, 14)
示例#13
0
def getupper_ascii(char_ord):
    return char_ord - int_between(ord('a'), char_ord,
                                  ord('z') + 1) * (ord('a') - ord('A'))
示例#14
0
 def fn(a, b, c):
     return int_between(a, b, c)
示例#15
0
 def check_index(self, w_self, index0):
     if not rarithmetic.int_between(0, index0, self.size(w_self)):
         raise IndexError
示例#16
0
def is_space(code):
    return (code == 32) | int_between(9, code, 14)
示例#17
0
def is_digit(code):
    return int_between(48, code, 58)
示例#18
0
def getlower_ascii(char_ord):
    return char_ord + int_between(ord('A'), char_ord,
                                  ord('Z') + 1) * (ord('a') - ord('A'))
示例#19
0
def set_range(ctx, pattern, index, char_code):
    # <RANGE> <lower> <upper>
    match = int_between(pattern.pattern[index + 1], char_code,
                        pattern.pattern[index + 2] + 1)
    return match, index + 3
示例#20
0
def assert_valid_inst_index(space, n0, w_obj):
    if not int_between(0, n0, w_obj.size()):
        raise PrimitiveFailedError()
    # return the index, since from here on the annotator knows that
    # n0 cannot be negative
    return n0
示例#21
0
文件: values.py 项目: rjnw/pycket
    def make_or_interned(val):
        from rpython.rlib.rarithmetic import int_between

        if int_between(W_Fixnum.MIN_INTERNED, val, W_Fixnum.MAX_INTERNED):
            return W_Fixnum.cache[val - W_Fixnum.MIN_INTERNED]
        return W_Fixnum(val)
示例#22
0
def is_digit(code):
    return int_between(48, code, 58)
示例#23
0
def set_range(ctx, index, char_code):
    # <RANGE> <lower> <upper>
    pat = ctx.pattern
    match = int_between(pat[index+1], char_code, pat[index+2] + 1)
    return match, index + 3