Example #1
0
    def _init_methods(self):
        # XXX clean-up later! Rename _KEYTYPE and _VALUETYPE to KEY and VALUE.
        # For now they are just synonyms, please use KEY/VALUE in new code.
        self.KEY = self._KEYTYPE
        self.VALUE = self._VALUETYPE

        self._generic_types = frozendict({
            self.SELFTYPE_T: self,
            self.KEYTYPE_T: self._KEYTYPE,
            self.VALUETYPE_T: self._VALUETYPE
            })

        # ll_get() is always used just after a call to ll_contains(),
        # always with the same key, so backends can optimize/cache the
        # result
        self._GENERIC_METHODS = frozendict({
            "ll_length": Meth([], Signed),
            "ll_get": Meth([self.KEYTYPE_T], self.VALUETYPE_T),
            "ll_set": Meth([self.KEYTYPE_T, self.VALUETYPE_T], Void),
            "ll_remove": Meth([self.KEYTYPE_T], Bool), # return False is key was not present
            "ll_contains": Meth([self.KEYTYPE_T], Bool),
            "ll_clear": Meth([], Void),
            "ll_get_items_iterator": Meth([], DictItemsIterator(self.KEYTYPE_T, self.VALUETYPE_T)),
        })

        self._setup_methods(self._generic_types)
Example #2
0
 def __init__(self):
     self._null = _null_weak_reference(self)
     self._GENERIC_METHODS = frozendict({
         "ll_set": Meth([ROOT], Void),
         "ll_deref": Meth([], ROOT),
         })
     self._setup_methods({})
Example #3
0
    def _init_methods(self):
        # This defines the abstract list interface that backends will
        # have to map to their native list implementations.
        # 'ITEMTYPE_T' is used as a placeholder for indicating
        # arguments that should have ITEMTYPE type. 'SELFTYPE_T' indicates 'self'

        # XXX clean-up later! Rename _ITEMTYPE to ITEM.  For now they are
        # just synonyms, please use ITEM in new code.
        self.ITEM = self._ITEMTYPE

        generic_types = {
            self.SELFTYPE_T: self,
            self.ITEMTYPE_T: self._ITEMTYPE,
            }

        # the methods are named after the ADT methods of lltypesystem's lists
        self._GENERIC_METHODS = frozendict({
            # "name": Meth([ARGUMENT1_TYPE, ARGUMENT2_TYPE, ...], RESULT_TYPE)
            "ll_length": Meth([], Signed),
            "ll_getitem_fast": Meth([Signed], self.ITEMTYPE_T),
            "ll_setitem_fast": Meth([Signed, self.ITEMTYPE_T], Void),
            "_ll_resize_ge": Meth([Signed], Void),
            "_ll_resize_le": Meth([Signed], Void),
            "_ll_resize": Meth([Signed], Void),
        })

        self._setup_methods(generic_types)
Example #4
0
    def __init__(self):
        self._null = _null_string(self)

        generic_types = { self.SELFTYPE_T: self }
        self._GENERIC_METHODS = frozendict({
            "ll_stritem_nonneg": Meth([Signed], self.CHAR),
            "ll_strlen": Meth([], Signed),
            "ll_strconcat": Meth([self.SELFTYPE_T], self.SELFTYPE_T),
            "ll_streq": Meth([self.SELFTYPE_T], Bool),
            "ll_strcmp": Meth([self.SELFTYPE_T], Signed),
            "ll_startswith": Meth([self.SELFTYPE_T], Bool),
            "ll_endswith": Meth([self.SELFTYPE_T], Bool),
            "ll_find": Meth([self.SELFTYPE_T, Signed, Signed], Signed),
            "ll_rfind": Meth([self.SELFTYPE_T, Signed, Signed], Signed),
            "ll_count": Meth([self.SELFTYPE_T, Signed, Signed], Signed),
            "ll_find_char": Meth([self.CHAR, Signed, Signed], Signed),
            "ll_rfind_char": Meth([self.CHAR, Signed, Signed], Signed),
            "ll_count_char": Meth([self.CHAR, Signed, Signed], Signed),
            "ll_strip": Meth([self.CHAR, Bool, Bool], self.SELFTYPE_T),
            "ll_upper": Meth([], self.SELFTYPE_T),
            "ll_lower": Meth([], self.SELFTYPE_T),
            "ll_substring": Meth([Signed, Signed], self.SELFTYPE_T), # ll_substring(start, count)
            "ll_split_chr": Meth([self.CHAR], List(self.SELFTYPE_T)),
            "ll_contains": Meth([self.CHAR], Bool),
            "ll_replace_chr_chr": Meth([self.CHAR, self.CHAR], self.SELFTYPE_T),
            })
        self._setup_methods(generic_types)
Example #5
0
 def _setup_methods(self, generic_types, can_raise=[]):
     methods = {}
     for name, meth in self._GENERIC_METHODS.iteritems():
         args = [self._specialize_type(arg, generic_types) for arg in meth.ARGS]
         result = self._specialize_type(meth.RESULT, generic_types)
         methods[name] = Meth(args, result)
     self._METHODS = frozendict(methods)
     self._can_raise = tuple(can_raise)
Example #6
0
 def rtyper_makekey(self):
     # grab all attributes of the SomeExternalObject for the key
     attrs = lltype.frozendict(self.__dict__)
     if 'const' in attrs:
         del attrs['const']
     if 'const_box' in attrs:
         del attrs['const_box']
     return self.__class__, attrs
Example #7
0
 def _key_for_types(self, TYPES):
     counts = {}
     for EXACT_TYPE in TYPES:
         if EXACT_TYPE is lltype.Void:
             continue
         ERASED_TYPE = storage_type(EXACT_TYPE)
         counts[ERASED_TYPE] = counts.get(ERASED_TYPE, 0) + 1
     key = lltype.frozendict(counts)
     return key
Example #8
0
 def __init__(self, STRINGTP, CHARTP):
     self._null = _null_string_builder(self)
     self._GENERIC_METHODS = frozendict({
         "ll_allocate": Meth([Signed], Void),
         "ll_append_char": Meth([CHARTP], Void),
         "ll_append": Meth([STRINGTP], Void),
         "ll_build": Meth([], STRINGTP),
         })
     self._setup_methods({})
Example #9
0
    def __init__(self, name, superclass, fields={}, methods={},
            _is_root=False, _hints = {}):
        self._name = name
        self._hints = frozendict(_hints)
        self._subclasses = []

        if _is_root:
            self._superclass = None
        else:
            if superclass is not None:
                self._set_superclass(superclass)

        self._methods = frozendict()
        self._fields = frozendict()
        self._overridden_defaults = frozendict()

        self._add_fields(fields)
        self._add_methods(methods)

        self._null = make_null_instance(self)
        self._class = _class(self)
Example #10
0
    def __init__(self, KEYTYPE, VALUETYPE):
        self._KEYTYPE = KEYTYPE
        self._VALUETYPE = VALUETYPE
        self._null = _null_dict_items_iterator(self)

        generic_types = {
            self.SELFTYPE_T: self,
            self.KEYTYPE_T: KEYTYPE,
            self.VALUETYPE_T: VALUETYPE
            }

        # Dictionaries are not allowed to be changed during an
        # iteration. The ll_go_next method should check this condition
        # and raise RuntimeError in that case.
        self._GENERIC_METHODS = frozendict({
            "ll_go_next": Meth([], Bool), # move forward; return False is there is no more data available
            "ll_current_key": Meth([], self.KEYTYPE_T),
            "ll_current_value": Meth([], self.VALUETYPE_T),
        })
        self._setup_methods(generic_types, can_raise=['ll_go_next'])
Example #11
0
 def __hash__(self):
     return hash(frozendict(self.__dict__))
Example #12
0
 def __init__(self, fields, _hints={}):
     self._fields = frozendict()
     for name, ITEMTYPE in fields.items():
         self._fields[name] = ITEMTYPE, ITEMTYPE._defl()
     self._null = _null_record(self)
     self._hints = frozendict(_hints)