Esempio n. 1
0
 def __init__(self, space, code, w_globals, outer_func):
     if not we_are_translated():
         assert type(self) == space.FrameClass, (
             "use space.FrameClass(), not directly PyFrame()")
     self = hint(self, access_directly=True, fresh_virtualizable=True)
     assert isinstance(code, pycode.PyCode)
     self.space = space
     self.pycode = code
     if code.frame_stores_global(w_globals):
         self.getorcreatedebug().w_globals = w_globals
     ncellvars = len(code.co_cellvars)
     nfreevars = len(code.co_freevars)
     size = code.co_nlocals + ncellvars + nfreevars + code.co_stacksize
     # the layout of this list is as follows:
     # | local vars | cells | stack |
     self.locals_cells_stack_w = [None] * size
     self.valuestackdepth = code.co_nlocals + ncellvars + nfreevars
     make_sure_not_resized(self.locals_cells_stack_w)
     check_nonneg(self.valuestackdepth)
     #
     if space.config.objspace.honor__builtins__:
         self.builtin = space.builtin.pick_builtin(w_globals)
     # regular functions always have CO_OPTIMIZED and CO_NEWLOCALS.
     # class bodies only have CO_NEWLOCALS.
     self.initialize_frame_scopes(outer_func, code)
Esempio n. 2
0
 def pushrevvalues(self, n, values_w): # n should be len(values_w)
     make_sure_not_resized(values_w)
     while True:
         n -= 1
         if n < 0:
             break
         self.pushvalue(values_w[n])
Esempio n. 3
0
    def mkdatareg(self, args):
        """
        Takes the arguments to the function and returns a fresh copy of a data array
        suitable for Frame.data registers.
        """
        if self.is_complete == False:
            raise ValueError("Cannot call mkdata on incomplete function")

        assert type(args) is DList

        # make a copy of the function registers that will be the "register" stack during execution
        framedata = [DNull()] * len(self.data)
        make_sure_not_resized(framedata)
        for i, val in enumerate(self.data):
            framedata[i] = val.copy()

        # populate function argument values
        if args.len_py() != len(self.args):
            raise ValueError(
                "Wrong number of arguments passed to function %s" % self.name)
        for i in range(len(self.args)):
            name, fulltype = self.args[i]
            framedata[i] = args.getitem_pyidx(i)

        return framedata
Esempio n. 4
0
    def __init__(self,
                 receiver,
                 arguments,
                 arg_mapping,
                 num_local_temps,
                 num_context_temps,
                 meta_level=False):
        make_sure_not_resized(arguments)
        make_sure_not_resized(arg_mapping)
        self = jit.hint(self, access_directly=True, fresh_virtualizable=True)
        self._receiver = receiver
        self._arguments = arguments
        self._meta_object_environment = None
        self._on_stack = _FrameOnStackMarker()
        self._meta_level = meta_level

        if num_local_temps == 0:
            self._temps = _EMPTY_LIST
        else:
            self._temps = [nilObject] * num_local_temps

        self._args_for_inner = self._collect_shared_args(arg_mapping)
        if num_context_temps == 0:
            self._temps_for_inner = _EMPTY_LIST
        else:
            self._temps_for_inner = [nilObject] * num_context_temps
Esempio n. 5
0
 def pushrevvalues(self, n, values_w):  # n should be len(values_w)
     make_sure_not_resized(values_w)
     while True:
         n -= 1
         if n < 0:
             break
         self.pushvalue(values_w[n])
Esempio n. 6
0
 def __init__(self, space, code, w_globals, outer_func):
     if not we_are_translated():
         assert type(self) == space.FrameClass, (
             "use space.FrameClass(), not directly PyFrame()")
     self = hint(self, access_directly=True, fresh_virtualizable=True)
     assert isinstance(code, pycode.PyCode)
     self.space = space
     self.pycode = code
     if code.frame_stores_global(w_globals):
         self.getorcreatedebug().w_globals = w_globals
     ncellvars = len(code.co_cellvars)
     nfreevars = len(code.co_freevars)
     size = code.co_nlocals + ncellvars + nfreevars + code.co_stacksize
     # the layout of this list is as follows:
     # | local vars | cells | stack |
     self.locals_cells_stack_w = [None] * size
     self.valuestackdepth = code.co_nlocals + ncellvars + nfreevars
     make_sure_not_resized(self.locals_cells_stack_w)
     check_nonneg(self.valuestackdepth)
     #
     if space.config.objspace.honor__builtins__:
         self.builtin = space.builtin.pick_builtin(w_globals)
     # regular functions always have CO_OPTIMIZED and CO_NEWLOCALS.
     # class bodies only have CO_NEWLOCALS.
     self.initialize_frame_scopes(outer_func, code)
Esempio n. 7
0
 def init_stack(self, initstack):
     # The stack is a constant size list. This means that rpython
     # does not need to check if re-allocation/downsizing should
     # occur.
     self.stack = initstack + [0] * (STACKSIZE - len(initstack))
     # The next line is just an assertion of the above comment.
     debug.make_sure_not_resized(self.stack)
     self.sp = len(initstack)
Esempio n. 8
0
    def invoke(self, receiver, arguments, meta_level):
        assert arguments is not None
        make_sure_not_resized(arguments)

        frame = Frame(receiver, arguments, self._arg_mapping,
                      self._num_local_temps, self._num_context_temps, meta_level)

        return self._execute(frame, receiver, arguments);
Esempio n. 9
0
    def invoke_with_semantics(self, receiver, arguments, meta_level, meta_object):
        assert arguments is not None
        make_sure_not_resized(arguments)

        frame = Frame(receiver, arguments, self._arg_mapping,
                      self._num_local_temps, self._num_context_temps, meta_level)
        frame.set_meta_object_environment(meta_object)

        return self._execute(frame, receiver, arguments);
Esempio n. 10
0
 def __init__(self, selector, universe, rcvr_expr, arg_exprs,
              source_section = None):
     ExpressionNode.__init__(self, source_section)
     self._selector = selector
     self._universe = universe
     assert arg_exprs is not None
     make_sure_not_resized(arg_exprs)
     self._rcvr_expr = self.adopt_child(rcvr_expr)
     self._arg_exprs = self.adopt_children(arg_exprs)
Esempio n. 11
0
    def __init__(self, nilObject, number_of_indexable_fields, values = None):
        AbstractObject.__init__(self)

        # Private array of indexable fields
        if values is None:
            self._indexable_fields = [nilObject] * number_of_indexable_fields
        else:
            self._indexable_fields = values
        make_sure_not_resized(self._indexable_fields)
Esempio n. 12
0
    def __init__(self, nilObject, number_of_indexable_fields, values=None):
        AbstractObject.__init__(self)

        # Private array of indexable fields
        if values is None:
            self._indexable_fields = [nilObject] * number_of_indexable_fields
        else:
            self._indexable_fields = values
        make_sure_not_resized(self._indexable_fields)
Esempio n. 13
0
 def execute_evaluated(self, frame, rcvr, args):
     assert frame is not None
     assert rcvr is not None
     assert args is not None
     make_sure_not_resized(args)
     if we_are_jitted():
         return self._direct_dispatch(rcvr, args)
     else:
         return self._dispatch.execute_dispatch(rcvr, args)
Esempio n. 14
0
 def execute_evaluated(self, frame, rcvr, args):
     assert frame is not None
     assert rcvr is not None
     assert args is not None
     make_sure_not_resized(args)
     if we_are_jitted():
         return self._direct_dispatch(rcvr, args)
     else:
         return self._dispatch.execute_dispatch(rcvr, args)
Esempio n. 15
0
 def __init__(self, selector, universe, rcvr_expr, arg_exprs,
              source_section = None):
     ExpressionNode.__init__(self, source_section)
     self._selector = selector
     self._universe = universe
     assert arg_exprs is not None
     make_sure_not_resized(arg_exprs)
     self._rcvr_expr = self.adopt_child(rcvr_expr)
     self._arg_exprs = self.adopt_children(arg_exprs)
Esempio n. 16
0
    def invoke(self, receiver, arguments):
        assert arguments is not None
        make_sure_not_resized(arguments)

        frame = Frame(receiver, arguments, self._arg_mapping,
                      self._num_local_temps, self._num_context_temps)
        jitdriver.jit_merge_point(self=self, receiver=receiver, arguments=arguments, frame=frame)

        return self._expr_or_sequence.execute(frame)
Esempio n. 17
0
File: util.py Progetto: Mu-L/pypy
def args_hash(args):
    make_sure_not_resized(args)
    res = 0x345678
    for arg in args:
        if arg is None:
            y = 17
        else:
            y = arg._get_hash_()
        res = intmask((1000003 * res) ^ y)
    return res
Esempio n. 18
0
def from_values_and_jsonmap(space, values_w, jsonmap):
    if not objectmodel.we_are_translated():
        assert len(values_w) == len(jsonmap.get_keys_in_order())
        assert len(values_w) != 0
    debug.make_sure_not_resized(values_w)
    strategy = jsonmap.strategy_instance
    if strategy is None:
        jsonmap.strategy_instance = strategy = JsonDictStrategy(space, jsonmap)
    storage = strategy.erase(values_w)
    return W_DictObject(space, strategy, storage)
Esempio n. 19
0
 def __init__(self, prev=None):
     self.trail_var = INIT_TRAIL_VAR
     debug.make_sure_not_resized(self.trail_var)
     self.trail_binding = INIT_TRAIL_BINDING
     debug.make_sure_not_resized(self.trail_binding)
     self.i = 0
     self.trail_attrs = None
     self.prev = prev
     self.discarded = False
     self.hook = None
Esempio n. 20
0
 def __init__(self, prev=None):
     self.trail_var = INIT_TRAIL_VAR
     debug.make_sure_not_resized(self.trail_var)
     self.trail_binding = INIT_TRAIL_BINDING
     debug.make_sure_not_resized(self.trail_binding)
     self.i = 0
     self.trail_attrs = None
     self.prev = prev
     self.discarded = False
     self.hook = None
Esempio n. 21
0
def args_hash(args):
    make_sure_not_resized(args)
    res = 0x345678
    for arg in args:
        if arg is None:
            y = 17
        else:
            y = arg._get_hash_()
        res = intmask((1000003 * res) ^ y)
    return res
Esempio n. 22
0
    def invoke(self, receiver, arguments):
        assert arguments is not None
        make_sure_not_resized(arguments)

        frame = Frame(receiver, arguments, self._arg_mapping,
                      self._num_local_temps, self._num_context_temps)
        jitdriver.jit_merge_point(self=self,
                                  receiver=receiver,
                                  arguments=arguments,
                                  frame=frame)

        return self._expr_or_sequence.execute(frame)
Esempio n. 23
0
def args_eq(args1, args2):
    make_sure_not_resized(args1)
    make_sure_not_resized(args2)
    if len(args1) != len(args2):
        return False
    for i in range(len(args1)):
        arg1 = args1[i]
        arg2 = args2[i]
        if arg1 is None:
            if arg2 is not None:
                return False
        elif not arg1.same_box(arg2):
            return False
    return True
Esempio n. 24
0
File: util.py Progetto: Mu-L/pypy
def args_eq(args1, args2):
    make_sure_not_resized(args1)
    make_sure_not_resized(args2)
    if len(args1) != len(args2):
        return False
    for i in range(len(args1)):
        arg1 = args1[i]
        arg2 = args2[i]
        if arg1 is None:
            if arg2 is not None:
                return False
        elif not arg1.same_box(arg2):
            return False
    return True
Esempio n. 25
0
    def _switch_map_and_write_storage(self, obj, w_value):
        from rpython.rlib.debug import make_sure_not_resized
        val = self._unbox(w_value)
        if self.firstunwrapped:
            unboxed = erase_unboxed(make_sure_not_resized([val]))
            if self.storage_needed() > obj._mapdict_storage_length():
                obj._set_mapdict_increase_storage(self, unboxed)
                return

            obj._set_mapdict_map(self)
            obj._mapdict_write_storage(self.storageindex, unboxed)
        else:
            unboxed = unerase_unboxed(
                obj._mapdict_read_storage(self.storageindex))

            obj._set_mapdict_map(self)
            if len(unboxed) <= self.listindex:
                # size can only increase by 1
                assert len(unboxed) == self.listindex
                unboxed = unboxed + [val]
                obj._mapdict_write_storage(self.storageindex,
                                           erase_unboxed(unboxed))
            else:
                # the unboxed list is already large enough, due to reordering
                unboxed[self.listindex] = val
Esempio n. 26
0
    def __init__(self):
        from js.object_space import newnull
        self._property_map_ = new_map()
        self._property_slots_ = debug.make_sure_not_resized([])

        self._prototype_ = newnull()
        W_BasicObject.define_own_property(self, u'__proto__', proto_desc)
Esempio n. 27
0
    def __init__(self, parent, func, pc, max_stack_size, nargs, bc_off, closure):
        self = jit.hint(self, access_directly=True, fresh_virtualizable=True)
        self.parent = parent
        self.stack = [None] * max_stack_size
        debug.make_sure_not_resized(self.stack)
        self.func = func
        self.pc = pc
        self.nargs = nargs # Number of arguments passed to this continuation
        self.bc_off = bc_off # -1 for Py modules
        self.closure = closure
        self.returned = False

        # stackpe always points to the element *after* the end of the stack (this makes a lot of
        # stack-based operations quicker)
        self.stackpe = 0
        # ffp, gfp, and xfp all point *to* the frame they refer to
        self.ffp = self.gfp = self.xfp = -1
Esempio n. 28
0
 def fixedview(self, w_obj, expected_length=-1, unroll=False):
     """ Fast paths
     """
     if isinstance(w_obj, W_AbstractTupleObject) and self._uses_tuple_iter(w_obj):
         t = w_obj.tolist()
     elif type(w_obj) is W_ListObject:
         if unroll:
             t = w_obj.getitems_unroll()
         else:
             t = w_obj.getitems_fixedsize()
     else:
         if unroll:
             return make_sure_not_resized(ObjSpace.unpackiterable_unroll(self, w_obj, expected_length))
         else:
             return make_sure_not_resized(ObjSpace.unpackiterable(self, w_obj, expected_length)[:])
     if expected_length != -1 and len(t) != expected_length:
         raise self._wrap_expected_length(expected_length, len(t))
     return make_sure_not_resized(t)
Esempio n. 29
0
    def __init__(self, receiver, arguments, arg_mapping, num_local_temps,
                 num_context_temps):
        make_sure_not_resized(arguments)
        make_sure_not_resized(arg_mapping)
        self = jit.hint(self, access_directly=True, fresh_virtualizable=True)
        self._receiver        = receiver
        self._arguments       = arguments
        self._on_stack        = _FrameOnStackMarker()
        if num_local_temps == 0:
            self._temps       = _EMPTY_LIST
        else:
            self._temps       = [nilObject] * num_local_temps

        self._args_for_inner  = self._collect_shared_args(arg_mapping)
        if num_context_temps == 0:
            self._temps_for_inner = _EMPTY_LIST
        else:
            self._temps_for_inner = [nilObject] * num_context_temps
Esempio n. 30
0
    def __init__(self, parent, func, pc, max_stack_size, nargs, bc_off,
                 closure):
        self = jit.hint(self, access_directly=True, fresh_virtualizable=True)
        self.parent = parent
        self.stack = [None] * max_stack_size
        debug.make_sure_not_resized(self.stack)
        self.func = func
        self.pc = pc
        self.nargs = nargs  # Number of arguments passed to this continuation
        self.bc_off = bc_off  # -1 for Py modules
        self.closure = closure
        self.returned = False

        # stackpe always points to the element *after* the end of the stack (this makes a lot of
        # stack-based operations quicker)
        self.stackpe = 0
        # ffp, gfp, and xfp all point *to* the frame they refer to
        self.ffp = self.gfp = self.xfp = -1
Esempio n. 31
0
 def set_structdef(self, structdef):
     assert isinstance(structdef, StructDef)
     self.structdef = structdef
     self.typename = structdef.name
     # struct data:
     self.fields = [DNull()] * structdef.numfields
     make_sure_not_resized(self.fields)
     # struct name lookup dict:
     self.fieldnames = OrderedDict()
     # populate fields and fieldnames with data from the StructDef
     for i, (name, FieldCls) in enumerate(structdef.fielddefs.items()):
         self.fields[i] = FieldCls()
         self.fieldnames[name] = i
     # calculate if this type is hashable (eg, if all contained types are):
     self.hashable = True
     for val in self.fields:
         if val.hashable == False:
             self.hashable = False
             break
Esempio n. 32
0
 def set_structdef(self, structdef):
     assert isinstance(structdef, StructDef)
     self.structdef = structdef
     self.typename = structdef.name
     # struct data:
     self.fields = [DNull()] * structdef.numfields
     make_sure_not_resized(self.fields)
     # struct name lookup dict:
     self.fieldnames = OrderedDict()
     # populate fields and fieldnames with data from the StructDef
     for i, (name, FieldCls) in enumerate(structdef.fielddefs.items()):
         self.fields[i] = FieldCls()
         self.fieldnames[name] = i
     # calculate if this type is hashable (eg, if all contained types are):
     self.hashable = True
     for val in self.fields:
         if val.hashable == False:
             self.hashable = False
             break
Esempio n. 33
0
 def __init__(self, space, code, w_globals, outer_func):
     if not we_are_translated():
         assert type(self) == space.FrameClass, (
             "use space.FrameClass(), not directly PyFrame()")
     self = hint(self, access_directly=True, fresh_virtualizable=True)
     assert isinstance(code, pycode.PyCode)
     self.space = space
     self.w_globals = w_globals
     self.pycode = code
     self.locals_stack_w = [None] * (code.co_nlocals + code.co_stacksize)
     self.valuestackdepth = code.co_nlocals
     make_sure_not_resized(self.locals_stack_w)
     check_nonneg(self.valuestackdepth)
     #
     if space.config.objspace.honor__builtins__:
         self.builtin = space.builtin.pick_builtin(w_globals)
     # regular functions always have CO_OPTIMIZED and CO_NEWLOCALS.
     # class bodies only have CO_NEWLOCALS.
     self.initialize_frame_scopes(outer_func, code)
Esempio n. 34
0
 def __init__(self, code_obj, args):
     self = hint(self, access_directly=True, fresh_virtualizable=True)
     self.code_obj = code_obj
     self.sp = r_uint(0)
     self.ip = r_uint(0)
     self.stack = [None] * code_obj.stack_size()
     self.args = debug.make_sure_not_resized(args)
     self.base_code = code_obj.get_base_code()
     if code_obj is not None:
         self.unpack_code_obj()
Esempio n. 35
0
 def __init__(self, space, code, w_globals, outer_func):
     if not we_are_translated():
         assert type(self) in (space.FrameClass, CPythonFrame), (
             "use space.FrameClass(), not directly PyFrame()")
     self = hint(self, access_directly=True, fresh_virtualizable=True)
     assert isinstance(code, pycode.PyCode)
     self.pycode = code
     eval.Frame.__init__(self, space, w_globals)
     self.locals_stack_w = [None] * (code.co_nlocals + code.co_stacksize)
     self.valuestackdepth = code.co_nlocals
     self.lastblock = None
     make_sure_not_resized(self.locals_stack_w)
     check_nonneg(self.valuestackdepth)
     #
     if space.config.objspace.honor__builtins__:
         self.builtin = space.builtin.pick_builtin(w_globals)
     # regular functions always have CO_OPTIMIZED and CO_NEWLOCALS.
     # class bodies only have CO_NEWLOCALS.
     self.initialize_frame_scopes(outer_func, code)
     self.f_lineno = code.co_firstlineno
Esempio n. 36
0
 def fixedview(self, w_obj, expected_length=-1, unroll=False):
     """ Fast paths
     """
     if isinstance(w_obj, W_AbstractTupleObject) and self._uses_tuple_iter(w_obj):
         t = w_obj.tolist()
     elif type(w_obj) is W_ListObject:
         if unroll:
             t = w_obj.getitems_unroll()
         else:
             t = w_obj.getitems_fixedsize()
     else:
         if unroll:
             return make_sure_not_resized(ObjSpace.unpackiterable_unroll(
                 self, w_obj, expected_length))
         else:
             return make_sure_not_resized(ObjSpace.unpackiterable(
                 self, w_obj, expected_length)[:])
     if expected_length != -1 and len(t) != expected_length:
         raise self._wrap_expected_length(expected_length, len(t))
     return make_sure_not_resized(t)
Esempio n. 37
0
    def __init__(self,
                 space,
                 args_w,
                 keywords=None,
                 keywords_w=None,
                 w_stararg=None,
                 w_starstararg=None,
                 keyword_names_w=None,
                 methodcall=False,
                 fnname_parens=None):
        self.space = space
        assert isinstance(args_w, list)
        self.arguments_w = args_w
        self.keywords = keywords
        self.keywords_w = keywords_w
        self.keyword_names_w = keyword_names_w  # matches the tail of .keywords
        if keywords is not None:
            assert keywords_w is not None
            assert len(keywords_w) == len(keywords)
            assert (keyword_names_w is None
                    or len(keyword_names_w) <= len(keywords))
            make_sure_not_resized(self.keywords)
            make_sure_not_resized(self.keywords_w)

        make_sure_not_resized(self.arguments_w)
        self._combine_wrapped(w_stararg, w_starstararg, fnname_parens)
        # a flag that specifies whether the JIT can unroll loops that operate
        # on the keywords
        self._jit_few_keywords = self.keywords is None or jit.isconstant(
            len(self.keywords))
        # a flag whether this is likely a method call, which doesn't change the
        # behaviour but produces better error messages
        self.methodcall = methodcall
Esempio n. 38
0
    def __init__(self,
                 space,
                 args_w,
                 keywords=None,
                 keywords_w=None,
                 w_stararg=None,
                 w_starstararg=None,
                 keyword_names_w=None):
        self.space = space
        assert isinstance(args_w, list)
        self.arguments_w = args_w

        self.keywords = keywords
        self.keywords_w = keywords_w
        self.keyword_names_w = keyword_names_w  # matches the tail of .keywords
        if keywords is not None:
            assert keywords_w is not None
            assert len(keywords_w) == len(keywords)
            assert (keyword_names_w is None
                    or len(keyword_names_w) <= len(keywords))
            make_sure_not_resized(self.keywords)
            make_sure_not_resized(self.keywords_w)

        make_sure_not_resized(self.arguments_w)
        self._combine_wrapped(w_stararg, w_starstararg)
        # a flag that specifies whether the JIT can unroll loops that operate
        # on the keywords
        self._jit_few_keywords = self.keywords is None or jit.isconstant(
            len(self.keywords))
Esempio n. 39
0
    def __init__(self, space, args_w, keywords=None, keywords_w=None,
                 w_stararg=None, w_starstararg=None, keyword_names_w=None,
                 methodcall=False):
        self.space = space
        assert isinstance(args_w, list)
        self.arguments_w = args_w
        self.keywords = keywords
        self.keywords_w = keywords_w
        self.keyword_names_w = keyword_names_w  # matches the tail of .keywords
        if keywords is not None:
            assert keywords_w is not None
            assert len(keywords_w) == len(keywords)
            assert (keyword_names_w is None or
                    len(keyword_names_w) <= len(keywords))
            make_sure_not_resized(self.keywords)
            make_sure_not_resized(self.keywords_w)

        make_sure_not_resized(self.arguments_w)
        self._combine_wrapped(w_stararg, w_starstararg)
        # a flag that specifies whether the JIT can unroll loops that operate
        # on the keywords
        self._jit_few_keywords = self.keywords is None or jit.isconstant(len(self.keywords))
        # a flag whether this is likely a method call, which doesn't change the
        # behaviour but produces better error messages
        self.methodcall = methodcall
Esempio n. 40
0
 def __init__(self,
              shape,
              dtype,
              order,
              strides,
              backstrides,
              storage,
              start=0):
     make_sure_not_resized(shape)
     make_sure_not_resized(strides)
     make_sure_not_resized(backstrides)
     self.shape = shape
     # already tested for overflow in from_shape_and_storage
     self.size = support.product(shape) * dtype.elsize
     if order not in (NPY.CORDER, NPY.FORTRANORDER):
         raise oefmt(
             dtype.itemtype.space.w_ValueError,
             "ConcreteArrayNotOwning but order is not 0,1 rather %d", order)
     self.order = order
     self.dtype = dtype
     self.strides = strides
     self.backstrides = backstrides
     self.storage = storage
     self.start = start
     self.gcstruct = V_OBJECTSTORE
Esempio n. 41
0
 def __init__(self, prev=None):
     self.trail_var = INIT_TRAIL_VAR
     debug.make_sure_not_resized(self.trail_var)
     self.trail_binding = INIT_TRAIL_BINDING
     debug.make_sure_not_resized(self.trail_binding)
     self.i = 0
     self.trail_attrs = None
     self.prev = prev
     self.discarded = False
     self.hook = None
     self.rules = []
     self.unifications = []
     if prev is None:
         self.entity_score = 1.0
         self.predicate_score = 1.0
         self.depth = 0
     else:
         self.entity_score = prev.entity_score
         self.predicate_score = prev.predicate_score
         self.depth = prev.depth
         self.rules += prev.rules
         self.unifications += prev.unifications
Esempio n. 42
0
def setup_revdb(space):
    """Called at run-time, before the space is set up.

    The various register_debug_command() lines attach functions
    to some commands that 'revdb.py' can call, if we are running
    in replay mode.
    """
    assert space.config.translation.reverse_debugger
    dbstate.space = space

    make_sure_not_resized(dbstate.watch_progs)
    make_sure_not_resized(dbstate.metavars)

    revdb.register_debug_command(revdb.CMD_PRINT, lambda_print)
    revdb.register_debug_command(revdb.CMD_BACKTRACE, lambda_backtrace)
    revdb.register_debug_command(revdb.CMD_LOCALS, lambda_locals)
    revdb.register_debug_command(revdb.CMD_BREAKPOINTS, lambda_breakpoints)
    revdb.register_debug_command(revdb.CMD_STACKID, lambda_stackid)
    revdb.register_debug_command("ALLOCATING", lambda_allocating)
    revdb.register_debug_command(revdb.CMD_ATTACHID, lambda_attachid)
    revdb.register_debug_command(revdb.CMD_COMPILEWATCH, lambda_compilewatch)
    revdb.register_debug_command(revdb.CMD_CHECKWATCH, lambda_checkwatch)
    revdb.register_debug_command(revdb.CMD_WATCHVALUES, lambda_watchvalues)
Esempio n. 43
0
 def __init__(self, code_obj, args, self_obj):
     self = hint(self, access_directly=True, fresh_virtualizable=True)
     self.code_obj = code_obj
     self.self_obj = self_obj
     self.sp = r_uint(0)
     self.ip = r_uint(0)
     self.stack = [None] * code_obj.stack_size()
     self.args = debug.make_sure_not_resized(args)
     self.base_code = code_obj.get_base_code()
     self.debug_points = code_obj.get_debug_points()
     self.finished = False
     self._is_continuation = 0
     if code_obj is not None:
         self.unpack_code_obj()
Esempio n. 44
0
 def __init__(self, code_obj, args, self_obj):
     self = hint(self, access_directly=True, fresh_virtualizable=True)
     self.code_obj = code_obj
     self.self_obj = self_obj
     self.sp = r_uint(0)
     self.ip = r_uint(0)
     self.stack = [None] * code_obj.stack_size()
     self.args = debug.make_sure_not_resized(args)
     self.base_code = code_obj.get_base_code()
     self.debug_points = code_obj.get_debug_points()
     self.finished = False
     self._is_continuation = 0
     if code_obj is not None:
         self.unpack_code_obj()
Esempio n. 45
0
    def mkdatareg(self, args):
        """
        Takes the arguments to the function and returns a fresh copy of a data array
        suitable for Frame.data registers.
        """
        if self.is_complete == False:
            raise ValueError("Cannot call mkdata on incomplete function")

        assert type(args) is DList

        # make a copy of the function registers that will be the "register" stack during execution
        framedata = [DNull()] * len(self.data)
        make_sure_not_resized(framedata)
        for i, val in enumerate(self.data):
            framedata[i] = val.copy()

        # populate function argument values
        if args.len_py() != len(self.args):
            raise ValueError("Wrong number of arguments passed to function %s" % self.name)
        for i in range(len(self.args)):
            name, fulltype = self.args[i]
            framedata[i] = args.getitem_pyidx(i)

        return framedata
Esempio n. 46
0
 def __init__(self, shape, dtype, order, strides, backstrides, storage):
     make_sure_not_resized(shape)
     make_sure_not_resized(strides)
     make_sure_not_resized(backstrides)
     self.shape = shape
     self.size = support.product(shape) * dtype.elsize
     self.order = order
     self.dtype = dtype
     self.strides = strides
     self.backstrides = backstrides
     self.storage = storage
Esempio n. 47
0
 def __init__(self, shape, dtype, order, strides, backstrides, storage):
     make_sure_not_resized(shape)
     make_sure_not_resized(strides)
     make_sure_not_resized(backstrides)
     self.shape = shape
     self.size = support.product(shape) * dtype.elsize
     self.order = order
     self.dtype = dtype
     self.strides = strides
     self.backstrides = backstrides
     self.storage = storage
Esempio n. 48
0
 def __init__(self, shape, dtype, order, strides, backstrides, storage, start=0):
     make_sure_not_resized(shape)
     make_sure_not_resized(strides)
     make_sure_not_resized(backstrides)
     self.shape = shape
     # already tested for overflow in from_shape_and_storage
     self.size = support.product(shape) * dtype.elsize
     self.order = order
     self.dtype = dtype
     self.strides = strides
     self.backstrides = backstrides
     self.storage = storage
     self.start = start
     self.gcstruct = V_OBJECTSTORE
Esempio n. 49
0
 def __init__(self, shape, dtype, order, strides, backstrides, storage, start=0):
     make_sure_not_resized(shape)
     make_sure_not_resized(strides)
     make_sure_not_resized(backstrides)
     self.shape = shape
     # already tested for overflow in from_shape_and_storage
     self.size = support.product(shape) * dtype.elsize
     if order not in (NPY.CORDER, NPY.FORTRANORDER):
         raise oefmt(dtype.itemtype.space.w_ValueError, "ConcreteArrayNotOwning but order is not 0,1 rather %d", order)
     self.order = order
     self.dtype = dtype
     self.strides = strides
     self.backstrides = backstrides
     self.storage = storage
     self.start = start
     self.gcstruct = V_OBJECTSTORE
Esempio n. 50
0
    def __init__(self, parent, func, local_vars, literal_vars, stack_size):
        self = jit.hint(self, access_directly=True, fresh_virtualizable=True)
        self.parent = parent
        self.locals = [None] * (local_vars + 1)
        make_sure_not_resized(self.locals)

        self.stack = [None] * (stack_size + 1)
        make_sure_not_resized(self.stack)

        self.literals = [None] * len(literal_vars)
        make_sure_not_resized(self.literals)
        assert len(literal_vars) == len(self.literals)
        for i in range(len(literal_vars)):
            self.literals[i] = literal_vars[i]

        self.stacktop = 0
        self.func = func
        self.pc = 0
Esempio n. 51
0
def get_bases_from_params(space, ctx, params):
    KIND = llapi.cts.gettype('HPyType_SpecParam_Kind')
    params = rffi.cast(rffi.CArrayPtr(llapi.cts.gettype('HPyType_SpecParam')),
                       params)
    if not params:
        return []
    found_base = False
    found_basestuple = False
    bases_w = []
    i = 0
    while True:
        # in llapi.py, HPyType_SpecParam.object is declared of type "struct
        # _HPy_s", so we need to manually fish the ._i inside
        p_kind = rffi.cast(lltype.Signed, params[i].c_kind)
        p_h = params[i].c_object.c__i
        if p_kind == 0:
            break
        i += 1
        if p_kind == KIND.HPyType_SpecParam_Base:
            found_base = True
            w_base = handles.deref(space, p_h)
            bases_w.append(w_base)
        elif p_kind == KIND.HPyType_SpecParam_BasesTuple:
            found_basestuple = True
            w_bases = handles.deref(space, p_h)
            bases_w = space.unpackiterable(w_bases)
        else:
            raise NotImplementedError('XXX write a test')

    if found_basestuple > 1:
        raise NotImplementedError('XXX write a test')
    if found_basestuple and found_base:
        raise NotImplementedError('XXX write a test')

    # return a copy of bases_w to ensure that it's a not-resizable list
    return make_sure_not_resized(bases_w[:])
Esempio n. 52
0
    def __init__(self, space, args_w, keywords=None, keywords_w=None,
                 w_stararg=None, w_starstararg=None, keyword_names_w=None):
        self.space = space
        assert isinstance(args_w, list)
        self.arguments_w = args_w
        self.keywords = keywords
        self.keywords_w = keywords_w
        self.keyword_names_w = keyword_names_w  # matches the tail of .keywords
        if keywords is not None:
            assert keywords_w is not None
            assert len(keywords_w) == len(keywords)
            assert (keyword_names_w is None or
                    len(keyword_names_w) <= len(keywords))
            make_sure_not_resized(self.keywords)
            make_sure_not_resized(self.keywords_w)

        make_sure_not_resized(self.arguments_w)
        self._combine_wrapped(w_stararg, w_starstararg)
        # a flag that specifies whether the JIT can unroll loops that operate
        # on the keywords
        self._jit_few_keywords = self.keywords is None or jit.isconstant(len(self.keywords))
Esempio n. 53
0
 def new_array_from_list(self, values):
     make_sure_not_resized(values)
     return Array(self.nilObject, 0, values)
Esempio n. 54
0
 def __init__(self, parent, num_vars):
     self.parent = parent
     self.vars = [None] * num_vars
     debug.make_sure_not_resized(self.vars)
Esempio n. 55
0
 def f(n):
     if n > 5:
         result = None
     else:
         result = [1,2,3]
     make_sure_not_resized(result)
Esempio n. 56
0
 def _init_empty(self, map):
     from rpython.rlib.debug import make_sure_not_resized
     self.map = map
     self.storage = make_sure_not_resized([None] * map.size_estimate())
Esempio n. 57
0
 def newtuple(self, list_w):
     from pypy.objspace.std.tupleobject import wraptuple
     assert isinstance(list_w, list)
     make_sure_not_resized(list_w)
     return wraptuple(self, list_w)