Пример #1
0
 def key(self):
     key = []
     key.append(self.name)
     key.append(values.wrap(self.init_field_cnt))
     if self.auto_field_cnt > 0:
         lst = values.wrap(self.auto_v, values.w_null)
         lst = values.wrap(self.auto_field_cnt, lst)
         key.append(lst)
     if self.mutables:
         vector = values_vector.wrap_vector(self.mutables)
         key.append(vector)
     if self.super_key:
         key.extend(self.super_key.key())
     return key
Пример #2
0
 def key(self):
     key = []
     key.append(self.name)
     key.append(values.wrap(self.init_field_cnt))
     if self.auto_field_cnt > 0:
         lst = values.wrap(self.auto_v, values.w_null)
         lst = values.wrap(self.auto_field_cnt, lst)
         key.append(lst)
     if self.mutables:
         vector = values_vector.wrap_vector(self.mutables)
         key.append(vector)
     if self.super_key:
         key.extend(self.super_key.key())
     return key
Пример #3
0
 def struct_type_info(self, cont):
     name = self.name
     init_field_cnt = values.wrap(self.init_field_cnt)
     auto_field_cnt = values.wrap(self.auto_field_cnt)
     immutable_k_list = values.wrap_list(self.immutables)
     current_inspector = current_inspector_param.get(cont)
     super = values.w_false
     typ = self.super
     while isinstance(typ, W_StructType):
         if current_inspector.has_control(typ):
             super = typ
         typ = typ.super
     skipped = values.W_Bool.make(super is values.w_false and
         isinstance(self.super, W_StructType))
     return [name, init_field_cnt, auto_field_cnt, self.accessor,
             self.mutator, immutable_k_list, super, skipped]
Пример #4
0
def integer_length(obj):

    if isinstance(obj, values.W_Fixnum):
        val = obj.value
        if val < 0:
            val = ~val

        n = r_uint(val)
        result = 0
        while n:
            n >>= r_uint(1)
            result += 1
        return values.wrap(result)

    if isinstance(obj, values.W_Bignum):
        # XXX The bit_length operation on rbigints is off by one for negative
        # powers of two (this may be intentional?).
        # So, we detect this case and apply a correction.
        bignum = obj.value
        negative_power_of_two = True

        if not bignum.tobool():
            return values.W_Fixnum.ZERO
        elif bignum.sign != -1:
            negative_power_of_two = False
        else:
            for i in range(bignum.size - 1):
                if bignum.udigit(i) != 0:
                    negative_power_of_two = False
                    break

            msd = bignum.udigit(r_uint(bignum.size - 1))
            while msd:
                if (msd & r_uint(0x1)) and msd != r_uint(1):
                    negative_power_of_two = False
                    break
                msd >>= r_uint(1)

        bit_length = bignum.bit_length()
        if negative_power_of_two:
            bit_length -= 1
        return values.wrap(bit_length)

    raise SchemeException("integer-length: expected exact-integer? got %s" %
                          obj.tostring())
Пример #5
0
 def struct_type_info(self, cont):
     name = self.name
     init_field_cnt = values.wrap(self.init_field_cnt)
     auto_field_cnt = values.wrap(self.auto_field_cnt)
     immutable_k_list = values.wrap_list(self.immutables)
     current_inspector = current_inspector_param.get(cont)
     super = values.w_false
     typ = self.super
     while isinstance(typ, W_StructType):
         if current_inspector.has_control(typ):
             super = typ
         typ = typ.super
     skipped = values.W_Bool.make(super is values.w_false
                                  and isinstance(self.super, W_StructType))
     return [
         name, init_field_cnt, auto_field_cnt, self.accessor, self.mutator,
         immutable_k_list, super, skipped
     ]
Пример #6
0
def integer_length(obj):

    if isinstance(obj, values.W_Fixnum):
        val = obj.value
        if val < 0:
            val = ~val

        n = r_uint(val)
        result = 0
        while n:
            n >>= r_uint(1)
            result += 1
        return values.wrap(result)

    if isinstance(obj, values.W_Bignum):
        # XXX The bit_length operation on rbigints is off by one for negative
        # powers of two (this may be intentional?).
        # So, we detect this case and apply a correction.
        bignum = obj.value
        negative_power_of_two = True

        if not bignum.tobool():
            return values.W_Fixnum.ZERO
        elif bignum.sign != -1:
            negative_power_of_two = False
        else:
            for i in range(bignum.size - 1):
                if bignum.udigit(i) != 0:
                    negative_power_of_two = False
                    break

            msd = bignum.udigit(r_uint(bignum.size - 1))
            while msd:
                if (msd & r_uint(0x1)) and msd != r_uint(1):
                    negative_power_of_two = False
                    break
                msd >>= r_uint(1)

        bit_length = bignum.bit_length()
        if negative_power_of_two:
            bit_length -= 1
        return values.wrap(bit_length)

    raise SchemeException("integer-length: expected exact-integer? got %s" % obj.tostring())
Пример #7
0
        def hash_iterate_next(self, w_dict, pos):
            from pycket.hash.persistent_hash_map import MASK_32
            storage = self.unerase(w_dict.hstorage)
            i = pos.value
            assert i >= 0
            index    = r_uint(i & MASK_32)
            subindex = r_uint((i >> 32) & MASK_32)

            bucket = get_dict_item(storage, index)[1]
            subindex += 1
            if subindex == r_uint(len(bucket)):
                subindex = r_uint(0)
                next = next_valid_index(
                        storage, intmask(index), valid=lambda x: bool(x[1]))
                index = r_uint(next)

            next = intmask((subindex << r_uint(32)) | index)
            return values.wrap(next)
Пример #8
0
        def hash_iterate_next(self, w_dict, pos):
            from pycket.hash.persistent_hash_map import MASK_32
            storage = self.unerase(w_dict.hstorage)
            i = pos.value
            assert i >= 0
            index    = r_uint(i & MASK_32)
            subindex = r_uint((i >> 32) & MASK_32)

            bucket = get_dict_item(storage, index)[1]
            subindex += 1
            if subindex == r_uint(len(bucket)):
                subindex = r_uint(0)
                next = next_valid_index(
                        storage, intmask(index), valid=lambda x: bool(x[1]))
                index = r_uint(next)

            next = intmask((subindex << r_uint(32)) | index)
            return values.wrap(next)
Пример #9
0
        def hash_iterate_next(self, w_dict, pos):
            from pycket.hash.persistent_hash_map import MASK_32
            storage = self.unerase(w_dict.hstorage)
            i = r_uint(pos.value)
            assert i >= 0
            index    = r_uint(i & MASK_32)
            subindex = r_uint((i >> 32) & MASK_32)

            bucket = get_dict_item(storage, index)[1]
            subindex += 1
            if subindex == r_uint(len(bucket)):
                subindex = r_uint(0)
                try:
                    next = next_valid_index(storage, intmask(index),
                                            valid=self._valid_bucket)
                except IndexError:
                    return values.w_false
                index = r_uint(next)

            next = intmask((subindex << r_uint(32)) | index)
            return values.wrap(next)
Пример #10
0
 def initialize_props(self, props, proc_spec, env, cont):
     """
     Properties initialization contains few steps:
         1. call initialize_prop for each property from the input list,
            it extracts all super values and stores them into props array
            with a flat structure
         2. recursively call attach_prop for each property from props and
            prepare the value:
            * if the current property has a subproperty, the value is the result
              of calling value procedure with a sub value as an argument
            * if the current property has a guard, the value is the result of
              calling guard with a value and struct type info as arguments
            * in other case, just keep the current value
     """
     proplist = values.from_list(props)
     props = []
     for p in proplist:
         self.initialize_prop(props, p)
     if proc_spec is not values.w_false:
         self.initialize_prop(props, values.wrap(w_prop_procedure, proc_spec))
     return self.attach_prop(props, 0, False, env, cont)
Пример #11
0
        def hash_iterate_next(self, w_dict, pos):
            from pycket.hash.persistent_hash_map import MASK_32
            storage = self.unerase(w_dict.hstorage)
            i = r_uint(pos.value)
            assert i >= 0
            index    = r_uint(i & MASK_32)
            subindex = r_uint((i >> 32) & MASK_32)

            bucket = get_dict_item(storage, index)[1]
            subindex += 1
            if subindex == r_uint(len(bucket)):
                subindex = r_uint(0)
                try:
                    next = next_valid_index(storage, intmask(index),
                                            valid=self._valid_bucket)
                except IndexError:
                    return values.w_false
                index = r_uint(next)

            next = intmask((subindex << r_uint(32)) | index)
            return values.wrap(next)
Пример #12
0
 def initialize_props(self, props, proc_spec, env, cont):
     """
     Properties initialization contains few steps:
         1. call initialize_prop for each property from the input list,
            it extracts all super values and stores them into props array
            with a flat structure
         2. recursively call attach_prop for each property from props and
            prepare the value:
            * if the current property has a subproperty, the value is the result
              of calling value procedure with a sub value as an argument
            * if the current property has a guard, the value is the result of
              calling guard with a value and struct type info as arguments
            * in other case, just keep the current value
     """
     proplist = values.from_list(props)
     props = []
     for p in proplist:
         self.initialize_prop(props, p)
     if proc_spec is not values.w_false:
         self.initialize_prop(props, values.wrap(w_prop_procedure,
                                                 proc_spec))
     return self.attach_prop(props, 0, False, env, cont)
Пример #13
0
def bytes_to_list(bs):
    acc = values.w_null
    for i in range(bs.length()-1, -1, -1):
        byte = ord(bs.ref_char(i))
        acc = values.wrap(byte, acc)
    return acc
Пример #14
0
 def hash_iterate_next(self, pos):
     i = pos.value
     if i >= self.length() - 1:
         return values.w_false
     return values.wrap(i + 1)
Пример #15
0
 def hash_iterate_next(self, pos):
     i = pos.value
     if i >= self.length() - 1:
         return values.w_false
     return values.wrap(i + 1)
Пример #16
0
 def hash_iterate_next(self, w_dict, i):
     index = i.value
     if index >= self.length(w_dict) - 1:
         return values.w_false
     return values.wrap(index + 1)
Пример #17
0
 def hash_iterate_next(self, w_dict, i):
     index = i.value
     if index >= self.length(w_dict) - 1:
         return values.w_false
     return values.wrap(index + 1)
Пример #18
0
def bytes_to_list(bs):
    acc = values.w_null
    for i in range(bs.length()-1, -1, -1):
        byte = ord(bs.ref_char(i))
        acc = values.wrap(byte, acc)
    return acc