def find(self, name): self = jit.hint(self, promote=True) version = jit.hint(self.version, promote=True) result = self._find_method(name, version) if result is not None: return result return None
def on_enter_jit(self, invariants, reds, bytecode, pos): # Now some strange code that makes a copy of the 'args' list in # a complicated way... this is a workaround forcing the whole 'args' # list to be virtual. It is a way to tell the JIT compiler that it # doesn't have to worry about the 'args' list being unpredictably # modified. oldloops = invariants oldargs = reds.args argcount = promote(len(oldargs)) args = [] n = 0 while n < argcount: hint(n, concrete=True) args.append(oldargs[n]) n += 1 reds.args = args # turn the green 'loops' from 'invariants' into a virtual list oldloops = hint(oldloops, deepfreeze=True) argcount = len(oldloops) loops = [] n = 0 while n < argcount: hint(n, concrete=True) loops.append(oldloops[n]) n += 1 reds.loops = loops
def fn(n): a = get() a[0] = n jit.hint(n, promote=True) x1 = a[0] jit.hint(x1, promote=True) a[n - n] = n + 1 return a[0] + x1
def fn(n): if n > 0: a = a1 else: a = a2 a[0] = n jit.hint(n, promote=True) x1 = a[0] jit.hint(x1, promote=True) a[n - n] = n + 1 return a[0] + x1
def ll_plus_minus(s, x, y): acc = x pc = 0 while pc < len(s): op = s[pc] hint(op, concrete=True) if op == '+': acc += y elif op == '-': acc -= y pc += 1 return acc
def interpret(bytecode, args): """The interpreter's entry point and portal function. """ loops = [] stack = empty_stack() pos = 0 while True: tinyjitdriver.jit_merge_point(args=args, loops=loops, stack=stack, bytecode=bytecode, pos=pos) bytecode = hint(bytecode, deepfreeze=True) if pos >= len(bytecode): break opcode = bytecode[pos] hint(opcode, concrete=True) # same as in tiny1.py pos += 1 if opcode == "ADD": stack = op2(stack, func_add_int, func_add_str) elif opcode == "SUB": stack = op2(stack, func_sub_int, func_sub_str) elif opcode == "MUL": stack = op2(stack, func_mul_int, func_mul_str) elif opcode[0] == "#": n = myint(opcode, start=1) stack = Stack(args[n - 1], stack) elif opcode.startswith("->#"): n = myint(opcode, start=3) if n > len(args): raise IndexError stack, args[n - 1] = stack.pop() elif opcode == "{": loops.append(pos) elif opcode == "}": stack, flag = stack.pop() if flag.as_int() == 0: loops.pop() else: pos = loops[-1] # A common problem when interpreting loops or jumps: the 'pos' # above is read out of a list, so the hint-annotator thinks # it must be red (not a compile-time constant). But the # hint(opcode, concrete=True) in the next iteration of the # loop requires all variables the 'opcode' depends on to be # green, including this 'pos'. We promote 'pos' to a green # here, as early as possible. Note that in practice the 'pos' # read out of the 'loops' list will be a compile-time constant # because it was pushed as a compile-time constant by the '{' # case above into 'loops', which is a virtual list, so the # promotion below is just a way to make the colors match. pos = promote(pos) tinyjitdriver.can_enter_jit(args=args, loops=loops, stack=stack, bytecode=bytecode, pos=pos) else: stack = Stack(StrBox(opcode), stack) return stack
def dispatch(self, pycode, next_instr, ec): self = hint(self, access_directly=True) next_instr = r_uint(next_instr) is_being_profiled = self.is_being_profiled try: while True: pypyjitdriver.jit_merge_point(ec=ec, frame=self, next_instr=next_instr, pycode=pycode, is_being_profiled=is_being_profiled) co_code = pycode.co_code self.valuestackdepth = hint(self.valuestackdepth, promote=True) next_instr = self.handle_bytecode(co_code, next_instr, ec) is_being_profiled = self.is_being_profiled except ExitFrame: return self.popvalue()
def peekvalue(self, index_from_top=0): # NOTE: top of the stack is peekvalue(0). # Contrast this with CPython where it's PEEK(-1). index_from_top = hint(index_from_top, promote=True) index = self.valuestackdepth + ~index_from_top assert index >= self.pycode.co_nlocals, "peek past the bottom of the stack" return self.locals_stack_w[index]
def main(m): f = some(m) n = f.lst[0] f = jit.hint(f, promote=True) res = f.lst[0] * 6 do_stuff_with(n) return res
def impl_univ(engine, heap, first, second): if not isinstance(first, term.Var): if helper.is_term(first): assert isinstance(first, term.Callable) sig = first.signature().atom_signature l = [term.Callable.build(first.name(), signature=sig)] + first.arguments() else: l = [first] u1 = helper.wrap_list(l) if not isinstance(second, term.Var): u1.unify(second, heap) else: u1.unify(second, heap) else: if isinstance(second, term.Var): error.throw_instantiation_error() else: l = helper.unwrap_list(second) head = l[0].dereference(heap) if not isinstance(head, term.Atom): error.throw_type_error("atom", head) l2 = [None] * (len(l) - 1) for i in range(len(l2)): l2[i] = l[i + 1] name = jit.hint(head.signature(), promote=True).name term.Callable.build(name, l2).unify(first, heap)
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)
def dropvaluesuntil(self, finaldepth): depth = self.valuestackdepth - 1 finaldepth = hint(finaldepth, promote=True) while depth >= finaldepth: self.locals_stack_w[depth] = None depth -= 1 self.valuestackdepth = finaldepth
def pop(self): pos = jit.hint(self.stack_pos, promote=True) new_pos = pos - 1 assert new_pos >= 0, 'Stack underflow' v = self.stack[new_pos] self.stack_pos = new_pos return v
def pop_arg(self): argpos = jit.hint(self.arg_pos, promote=True) new_pos = argpos - 1 assert new_pos >= 0, 'Argstack underflow' result = self.argstack[new_pos] self.arg_pos = new_pos #if downsize size = jit.hint(self.argstack_size, promote=True) hsize = size >> 1 if (hsize >= ARGSTACK_MIN) and (self.arg_pos < hsize): self.argstack = self.argstack[:hsize] self.argstack_size = hsize return result
def __init__(self, interp, code, context=None, thisclass=None, w_this=None, is_global_level=False): self = jit.hint(self, fresh_virtualizable=True, access_directly=True) self.interp = interp self.stack = [None] * code.stackdepth self.stackpos = 0 self.bytecode = code self.init_contextclass(code) self.next_instr = 0 self.known_line = -1 # set explicitly when there is a lineno but no next_instr self.ptrs = None # chained list of BasePointers self.context = context # the callable that is being executed self.thisclass = thisclass self.w_this = w_this self.is_global_level = is_global_level self.unique_items = [False] * len(code.varnames) self.vars_w = [None] * len(code.varnames) self.catch_blocks = [] for num, i in enumerate(code.superglobals): if i >= 0: self.vars_w[i] = interp.superglobals[num] i = code.this_var_num if i >= 0: if w_this is None: self.vars_w[i] = None else: self.vars_w[i] = w_this
def pop(self): pos = jit.hint(self.valuestack_pos, promote=True) new_pos = pos - 1 assert new_pos >= 0 v = self.valuestack[new_pos] self.valuestack_pos = new_pos return v
def funcrun_obj(self, func, w_obj, args): frame = self.space.createframe(self, func.w_func_globals, func) sig = self._signature # speed hack fresh_frame = jit.hint(frame, access_directly=True, fresh_virtualizable=True) args.parse_into_scope(w_obj, fresh_frame.locals_stack_w, func.name, sig, func.defs_w) fresh_frame.init_cells() return frame.run()
def get_attribute(self, attname): if self.value_list is None: return None, -1 attmap = jit.hint(self.attmap, promote=True) index = attmap.get_index(attname) if index == -1: return None, -1 return self.value_list[index], index
def add_attribute(self, attname, attribute): attmap = jit.hint(self.attmap, promote=True) index = attmap.get_index(attname) if index != -1: self.value_list[index] = attribute return self.attmap = attmap.with_extra_attribute(attname) self.value_list = self.value_list + [attribute]
def __init__(self, bc): self = jit.hint(self, fresh_virtualizable=True, access_directly=True) self.valuestack = [None] * 3 # safe estimate! self.vars = [None] * bc.numvars self.valuestack_pos = 0 self.arg_pos = 0 self.argstack = [None] * 3 # safe estimate!
def __init__(self, code): self = jit.hint(self, access_directly=True, fresh_virtualizable=True) self.valuestack = [None] * 10 # safe estimate! self.valuestack_pos = 0 self.code = code self.refs = [None] * code.env_size()
def pop_arg(self): argpos = jit.hint(self.arg_pos, promote=True) new_pos = argpos - 1 assert new_pos >= 0, 'Argstack underflow' result = self.argstack[new_pos] self.arg_pos = new_pos return result
def peekvalue(self, index_from_top=0): # NOTE: top of the stack is peekvalue(0). # Contrast this with CPython where it's PEEK(-1). index_from_top = hint(index_from_top, promote=True) index = self.valuestackdepth + ~index_from_top assert self._check_stack_index(index) assert index >= 0 return self.locals_cells_stack_w[index]
def find_first_result(self, ctx): ppos = jit.hint(self.ppos, promote=True) while ctx.pat(ppos): result = sre_match(ctx, ppos + 1, self.start_ptr, self.start_marks) ppos += ctx.pat(ppos) if result is not None: self.subresult = result self.ppos = ppos return self
def pop(self): stackpos = jit.hint(self.stackpos, promote=True) - 1 assert stackpos >= 0 res = self.stack[stackpos] #if self.stack[stackpos] is not None: # self.stack[stackpos].mark_invalid() self.stack[stackpos] = None # don't artificially keep alive stuff self.stackpos = stackpos return res
def activate(self, fcont, heap): nextcont = self.nextcont rule = jit.hint(self.rule, promote=True) nextcall = rule.clone_and_unify_head(heap, self.query) if nextcall is not None: return self.engine.call(nextcall, self.rule, nextcont, fcont, heap) else: cont = nextcont return cont, fcont, heap
def __repr__(self): attrs = [] attmap = jit.hint(self.attmap, promote=True) if self.value_list is not None: for key, index in attmap.indexes.iteritems(): value = self.value_list[index] if value is not None: attrs.append("%s" % (key, )) return "AttVar(%s, %s)" % (self.getbinding(), "[" + ", ".join(attrs) + "]")
def __init__(self, bc, parent=None): self = jit.hint(self, fresh_virtualizable=True, access_directly=True) self.valuestack = [None] * 10 # TODO - get upper bound staticaly # TODO - or maybe have even smaller initial estimate and resize when # needed? self.valuestack_pos = 0 self.names = bc.names self.vars = [None] * len(bc.names) self.parent = parent
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()
def f(n): frame = Frame(n, 0) somewhere_else.top_frame = frame # escapes frame = hint(frame, access_directly=True) while frame.x > 0: myjitdriver.can_enter_jit(frame=frame) myjitdriver.jit_merge_point(frame=frame) frame.y += frame.x frame.x -= 1 return somewhere_else.top_frame.y
def _make_rule_conts(engine, scont, fcont, heap, query, rulechain): rule = jit.hint(rulechain, promote=True) if rule.contains_cut: scont = CutScopeNotifier.insert_scope_notifier(engine, scont, fcont) restchain = rule.find_next_applicable_rule(query) if restchain is not None: fcont = UserCallContinuation.make(query.arguments(), engine, scont, fcont, heap, restchain) heap = heap.branch() try: shared_env = rule.unify_and_standardize_apart_head(heap, query) except error.UnificationFailed: return fcont.fail(heap) scont = RuleContinuation.make(shared_env, engine, scont, rule) return scont, fcont, heap
def __init__(self, interpreter, bytecode): from pyhp.bytecode import ByteCode assert(isinstance(bytecode, ByteCode)) self = jit.hint(self, access_directly=True, fresh_virtualizable=True) self.valuestack_pos = 0 self.valuestack = [None] * bytecode.estimated_stack_size() self.vars = [None] * bytecode.symbol_size() self.bytecode = bytecode # initialize superglobals like $_GET and $_POST for num, i in enumerate(bytecode.superglobals()): # if i is -1 superglobal is not used in the code if i >= 0: self.vars[i] = interpreter.superglobals[num]
def _make_rule_conts(engine, scont, fcont, heap, query, rulechain, simchain): rule = jit.hint(rulechain, promote=True) if rule.contains_cut: scont = CutScopeNotifier.insert_scope_notifier(engine, scont, fcont) restchain, simchain = rule.find_next_applicable_rule( query, heap=heap, similarity=engine.similarity, simchain=simchain, module=rule.module, nargs=len(rule.headargs)) #print "nextrule", restchain #print "nextsimchain", simchain if restchain is not None: fcont = UserCallContinuation.make(query.arguments(), engine, scont, fcont, heap, restchain, simchain, query) heap = heap.branch() try: # TODO: do the query logging here?? queryargs = [] for v in query.arguments(): if isinstance(v, Atom): queryargs.append(v.name()) if isinstance(v, BindingVar): if (v.binding is not None): queryargs.append(v.binding.name()) else: queryargs.append(v.name()) querystring = query._signature.name + '(' + ','.join(queryargs) + ').' heap.queries.append(querystring) shared_env = rule.unify_and_standardize_apart_head( heap, query, similarity=engine.similarity) except error.UnificationFailed: #unlog queries heap.queries = heap.queries[:-1] return fcont.fail(heap) scont = RuleContinuation.make(shared_env, engine, scont, rule, query) return scont, fcont, heap
def __init__(self, bytecode, w_self, lexical_scope, block, parent_interp, top_parent_interp, regexp_match_cell): self = jit.hint(self, fresh_virtualizable=True, access_directly=True) BaseFrame.__init__(self) self.bytecode = bytecode self.localsstack_w = [None] * (len(bytecode.cellvars) + bytecode.max_stackdepth) self.stackpos = len(bytecode.cellvars) self.last_instr = 0 self.cells = [LocalCell() for _ in bytecode.cellvars] + [None] * len(bytecode.freevars) self.regexp_match_cell = regexp_match_cell self.w_self = w_self self.lexical_scope = lexical_scope self.block = block self.parent_interp = parent_interp self.top_parent_interp = top_parent_interp self.visibility = W_FunctionObject.PUBLIC self.lastblock = None
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
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
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
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)
def make_context(space, w_home, s_sender, argcnt, initialip): # create and attach a shadow manually, to not have to carefully put things # into the right places in the W_PointersObject # XXX could hack some more to never have to create the _vars of w_result contextsize = w_home.as_methodcontext_get_shadow(space).myblocksize() w_result = model.W_PointersObject(space, space.w_BlockContext, contextsize) s_result = BlockContextShadow(space, w_result) s_result_non_fresh = s_result # XXX: find a better solution to translation err s_result = jit.hint(s_result, access_directly=True, fresh_virtualizable=True) w_result.store_shadow(s_result) s_result.store_expected_argument_count(argcnt) s_result.store_initialip(initialip) s_result.store_w_home(w_home) s_result.store_pc(initialip) s_result.init_stack_and_temps() return s_result_non_fresh
def run(self, lex_env, ops, stack_size, args=None): frame = hint(Frame(lex_env, ops, stack_size), access_directly=True) if args is not None: frame.push(args) #self.enter(frame) pc = 0 jitdriver.can_enter_jit( pc=pc, ops=frame.ops, self=self, frame=frame, ) try: while True: jitdriver.jit_merge_point( pc=pc, ops=frame.ops, self=self, frame=frame, ) pc = frame.step(self, pc) if pc < 0: return frame.pop() finally: pass #self.leave(frame)
def call(self, query, rule, scont, fcont, heap): if isinstance(query, Var): query = query.dereference(heap) if not isinstance(query, Callable): if isinstance(query, Var): raise error.throw_instantiation_error() raise error.throw_type_error('callable', query) signature = query.signature() builtin = self.get_builtin(signature) if builtin is not None: return BuiltinContinuation(self, rule, scont, builtin, query), fcont, heap # do a real call module = rule.module function = self._get_function(signature, module, query) query = function.add_meta_prefixes(query, module.nameatom) startrulechain = jit.hint(function.rulechain, promote=True) rulechain = startrulechain.find_applicable_rule(query) if rulechain is None: raise error.UnificationFailed scont, fcont, heap = _make_rule_conts(self, scont, fcont, heap, query, rulechain) return scont, fcont, heap
def call(self, query, rule, scont, fcont, heap): if isinstance(query, Var): query = query.dereference(heap) if not isinstance(query, Callable): if isinstance(query, Var): raise error.throw_instantiation_error() raise error.throw_type_error('callable', query) signature = query.signature() builtin = self.get_builtin(signature) if builtin is not None: #print(signature) return BuiltinContinuation(self, rule, scont, builtin, query), fcont, heap # do a real call module = rule.module function = self._get_function(signature, module, query) query = function.add_meta_prefixes(query, module.nameatom) #makes a Callable? # _print_rulechain(function.rulechain) simchain = self._rule_to_simchain(function.rulechain) #print "Simchain is", simchain startrulechain = jit.hint(function.rulechain, promote=True) rulechain, simchain = startrulechain.find_applicable_rule( query, heap, self.similarity, simchain, module, len(startrulechain.headargs)) #print "rule: ", rulechain #print "newsimchain: ", simchain if rulechain is None: raise error.UnificationFailed if heap.depth > self.max_depth: raise error.UnificationFailed scont, fcont, heap = _make_rule_conts(self, scont, fcont, heap, query, rulechain, simchain) return scont, fcont, heap
def get_backstrides(self): backstrides = self.backstrides jit.hint(len(backstrides), promote=True) return backstrides
def poke_nth(self, n, w_obj): stackpos = jit.hint(self.stackpos, promote=True) + ~n assert stackpos >= 0 assert isinstance(w_obj, W_Root) or w_obj is None self.stack[stackpos] = w_obj
def f(n): x = Frame() x = jit.hint(x, access_directly=True) x.meth()
def peek(self): stackpos = jit.hint(self.stackpos, promote=True) - 1 assert stackpos >= 0 return self.stack[stackpos]
def peek_nth(self, n): # peek() == peek_nth(0) stackpos = jit.hint(self.stackpos, promote=True) + ~n assert stackpos >= 0 return self.stack[stackpos]
def noConst(x): """Helper function for tests, returning 'x' as a BoxInt/BoxPtr even if it is a ConstInt/ConstPtr.""" from rpython.rlib import jit return jit.hint(x, force_no_const=True)
def pop_n(self, count): stackpos = jit.hint(self.stackpos, promote=True) - count assert stackpos >= 0 for i in range(count): self.stack[stackpos + i] = None self.stackpos = stackpos
def __init__(self, a, s): self = jit.hint(self, access_directly=True, fresh_virtualizable=True) self.l = [0] * (4 + a) self.s = s
def __init__(self, code, arg=None): self = hint(self, access_directly=True, fresh_virtualizable=True) self.code = code self.registers = [None] * code.regno self.registers[0] = arg
def getcode(self): return hint(self.pycode, promote=True)
def f(): x = hint(5, hello="world") return x
def settopvalue(self, w_object, index_from_top=0): index_from_top = hint(index_from_top, promote=True) index = self.valuestackdepth + ~index_from_top self.assert_stack_index(index) assert index >= 0 self.locals_cells_stack_w[index] = ll_assert_not_none(w_object)
def peekvalue_maybe_none(self, index_from_top=0): index_from_top = hint(index_from_top, promote=True) index = self.valuestackdepth + ~index_from_top self.assert_stack_index(index) assert index >= 0 return self.locals_cells_stack_w[index]
def interpret(pc, block, frame): function = jit.promote(frame.function) module = jit.promote(frame.module) unit = jit.promote(frame.unit) excs = jit.promote(frame.excs) try: while pc < len(block): try: jitdriver.jit_merge_point(pc=pc, block=block, module=module, unit=unit, excs=excs, function=function, frame=frame) #ec=ec, regv=regv, opcode = rffi.r_ulong(block[pc]) >> 8 ix = pc + 1 pc = ix + (rffi.r_ulong(block[pc]) & 255) # Not sure.. #if ec.debug_hook is not None: # hook, ec.debug_hook = ec.debug_hook, None # res = ec.debug_hook.call([DebugContext(rffi.r_long(ix), unit, frame)]) # if res != space.null: # ec.debug_hook = res #print optable.dec[opcode][0] regv = frame # from now on.. if opcode == opcode_of('assert'): obj = regv.load(block[ix + 0]) raise space.unwind(space.LAssertionError(obj)) elif opcode == opcode_of('raise'): obj = regv.load(block[ix + 0]) traceback = obj.getattr(u"traceback") if traceback is space.null: traceback = space.List([]) obj.setattr(u"traceback", traceback) elif not isinstance(traceback, space.List): raise space.unwind( space.LError( u"Expected null or list as .traceback: %s" % obj.repr())) raise space.Unwinder(obj, traceback) elif opcode == opcode_of('constant'): regv.store(block[ix + 0], unit.constants[block[ix + 1]]) elif opcode == opcode_of('list'): contents = [] for i in range(ix + 1, pc): contents.append(regv.load(block[i])) regv.store(block[ix], space.List(contents)) elif opcode == opcode_of('move'): regv.store(block[ix + 0], regv.load(block[ix + 1])) elif opcode == opcode_of('call'): op_call(regv, block, ix, pc) elif opcode == opcode_of('callv'): op_callv(regv, block, ix, pc) elif opcode == opcode_of('return'): return regv.load(block[ix + 0]) elif opcode == opcode_of('yield'): result = regv.load(block[ix + 0]) jit.hint(frame, force_virtualizable=True) raise Yield(pc, result) elif opcode == opcode_of('jump'): pc = rffi.r_ulong(block[ix + 0]) elif opcode == opcode_of('cond'): if space.is_false(regv.load(block[ix + 0])): pc = rffi.r_ulong(block[ix + 2]) else: pc = rffi.r_ulong(block[ix + 1]) elif opcode == opcode_of('func'): regv.store(block[ix + 0], Closure(frame, unit.functions[block[ix + 1]])) elif opcode == opcode_of('iter'): regv.store(block[ix + 0], regv.load(block[ix + 1]).iter()) elif opcode == opcode_of('next'): try: regv.store( block[ix + 0], regv.load(block[ix + 1]).callattr(u'next', [])) except StopIteration as _: pc = rffi.r_ulong(block[ix + 2]) elif opcode == opcode_of('getattr'): name = get_string(unit, block, ix + 2) obj = regv.load(block[ix + 1]) regv.store(block[ix + 0], obj.getattr(name)) elif opcode == opcode_of('setattr'): value = regv.load(block[ix + 3]) name = get_string(unit, block, ix + 2) obj = regv.load(block[ix + 1]) regv.store(block[ix + 0], obj.setattr(name, value)) elif opcode == opcode_of('getitem'): index = regv.load(block[ix + 2]) obj = regv.load(block[ix + 1]) regv.store(block[ix + 0], obj.getitem(index)) elif opcode == opcode_of('setitem'): item = regv.load(block[ix + 3]) index = regv.load(block[ix + 2]) obj = regv.load(block[ix + 1]) regv.store(block[ix + 0], obj.setitem(index, item)) elif opcode == opcode_of('getloc'): regv.store(block[ix + 0], frame.load_local(block[ix + 1])) elif opcode == opcode_of('setloc'): value = regv.load(block[ix + 2]) frame.store_local(block[ix + 1], value) regv.store(block[ix + 0], value) elif opcode == opcode_of('getupv'): value = get_upframe(frame, block[ix + 1]).load_local( block[ix + 2]) regv.store(block[ix + 0], value) elif opcode == opcode_of('setupv'): value = regv.load(block[ix + 3]) get_upframe(frame, block[ix + 1]).store_local( block[ix + 2], value) regv.store(block[ix + 0], value) elif opcode == opcode_of('getglob'): regv.store(block[ix + 0], module.getattr(get_string(unit, block, ix + 1))) elif opcode == opcode_of('setglob'): regv.store( block[ix + 0], module.setattr(get_string(unit, block, ix + 1), regv.load(block[ix + 2]))) elif opcode == opcode_of('loglob'): src_module = regv.load(block[ix + 0]) assert isinstance(src_module, space.Module) for name in src_module.list_locals(): module.setattr(name, src_module.getattr(name)) elif opcode == opcode_of('not'): if space.is_false(regv.load(block[ix + 1])): regv.store(block[ix + 0], space.true) else: regv.store(block[ix + 0], space.false) elif opcode == opcode_of('isnull'): if regv.load(block[ix + 1]) is space.null: regv.store(block[ix + 0], space.true) else: regv.store(block[ix + 0], space.false) elif opcode == opcode_of('contains'): v0 = regv.load(block[ix + 1]) v1 = regv.load(block[ix + 2]) if v0.contains(v1): regv.store(block[ix + 0], space.true) else: regv.store(block[ix + 0], space.false) else: raise space.unwind( space.LInstructionError( optable.names.get(opcode, str(opcode)).decode('utf-8'), opcode)) except space.Unwinder as unwinder: #print "exception detected, doing unwinds", pc, unwinder.exception.repr() for exc in excs: #print exc.start, exc.stop, exc.label, exc.reg if exc.start < pc <= exc.stop: frame.store(exc.reg, unwinder.exception) pc = exc.label #print "exception handler found" break else: raise except StopIteration as stop: # Doing an exception check to see if .next() was called in try block. unwinder = space.unwind(space.LUncatchedStopIteration()) for exc in excs: if exc.start < pc <= exc.stop: frame.store(exc.reg, unwinder.exception) pc = exc.label break else: raise unwinder except space.Unwinder as unwinder: unwinder.traceback.contents.append( TraceEntry(rffi.r_long(pc), unit.sources, frame.sourcemap, unit.path)) raise return space.null
def getclass(self): return jit.hint(self.klass, promote=True)
def push(self, w_v): stackpos = jit.hint(self.stackpos, promote=True) assert w_v is None or isinstance(w_v, W_Root) self.stack[stackpos] = w_v self.stackpos = stackpos + 1
def __init__(self, l, s): self = hint(self, access_directly=True, fresh_virtualizable=True) self.l = l self.s = s
def __init__(self): self.vals = [None] * init_size self.top = -1 self.size = jit.hint(init_size, promote=True)