def example(): v1 = f(one(), 2*one()) s2 = rstack.resume_state_create(None, "rp2", 2*one()) c = C() c.x = 4*one() s1 = rstack.resume_state_create(s2, "rp1", c) return v1*100 + rstack.resume_state_invoke(int, s1)
def example(): v1 = f(one(), 2 * one()) s2 = rstack.resume_state_create(None, "rp2", 2 * one()) c = C() c.x = 4 * one() s1 = rstack.resume_state_create(s2, "rp1", c) return v1 * 100 + rstack.resume_state_invoke(int, s1)
def example(): out = [] x = h(out) l = len(out) chain = rstack.resume_state_create(None, 'h', out) chain = rstack.resume_state_create(chain, 'g') x += rstack.resume_state_invoke(int, chain) l += len(out) return l*100+x
def example(): out = [] x = h(out) l = len(out) chain = rstack.resume_state_create(None, 'h', out) chain = rstack.resume_state_create(chain, 'g') x += rstack.resume_state_invoke(int, chain) l += len(out) return l * 100 + x
def example(): main_coro = rcoroutine.Coroutine.getcurrent() sub_coro = rcoroutine.Coroutine() thunk_f = T(main_coro, 5, 1) sub_coro.bind(thunk_f) sub_coro.switch() new_coro = rcoroutine.Coroutine() new_thunk_f = T(main_coro, 5, 1) new_coro.bind(new_thunk_f) costate = rcoroutine.Coroutine._get_default_costate() bottom = resume_state_create(None, "yield_current_frame_to_caller_1") _bind_frame = resume_state_create(bottom, "coroutine__bind", costate) f_frame_1 = resume_state_create(_bind_frame, "f_1", main_coro, 5, 1) f_frame_2 = resume_state_create(f_frame_1, "f_1", main_coro, 4, 2) f_frame_3 = resume_state_create(f_frame_2, "f_1", main_coro, 3, 4) f_frame_4 = resume_state_create(f_frame_3, "f_1", main_coro, 2, 8) f_frame_5 = resume_state_create(f_frame_4, "f_1", main_coro, 1, 16) f_frame_0 = resume_state_create(f_frame_5, "f_0") switch_frame = resume_state_create(f_frame_0, "coroutine_switch", costate) new_coro.frame = switch_frame new_coro.switch() return output == [16, 8, 4, 2, 1]
def example(): main_coro = Coroutine.getcurrent() sub_coro = Coroutine() thunk_f = T(main_coro, 5, 1) sub_coro.bind(thunk_f) sub_coro.switch() new_coro = Coroutine() new_thunk_f = T(main_coro, 5, 1) new_coro.bind(new_thunk_f) costate = Coroutine._get_default_costate() bottom = resume_state_create(None, "yield_current_frame_to_caller_1") _bind_frame = resume_state_create(bottom, "coroutine__bind", costate) f_frame_1 = resume_state_create(_bind_frame, "f_1", main_coro, 5, 1) f_frame_2 = resume_state_create(f_frame_1, "f_1", main_coro, 4, 2) f_frame_3 = resume_state_create(f_frame_2, "f_1", main_coro, 3, 4) f_frame_4 = resume_state_create(f_frame_3, "f_1", main_coro, 2, 8) f_frame_5 = resume_state_create(f_frame_4, "f_1", main_coro, 1, 16) f_frame_0 = resume_state_create(f_frame_5, "f_0") switch_frame = resume_state_create(f_frame_0, "coroutine_switch", costate) new_coro.frame = switch_frame new_coro.switch() return output == [16, 8, 4, 2, 1]
def example(): v1 = g(one()) s = rstack.resume_state_create(None, "rp0", one() - 1) try: v2 = rstack.resume_state_invoke(int, s) except KeyError: v2 = 42 return v1 * 100 + v2
def example(): v1 = g(one()) s = rstack.resume_state_create(None, "rp0", one()-1) try: v2 = rstack.resume_state_invoke(int, s) except KeyError: v2 = 42 return v1*100 + v2
def example(): v1 = f(one() + one()) s1 = rstack.resume_state_create(None, "rp1") s0 = rstack.resume_state_create(s1, "rp0", 0) v2 = rstack.resume_state_invoke(int, s0, raising=KeyError()) return v1 * 100 + v2
def example(): v1 = f(one() + one()) s1 = rstack.resume_state_create(None, "rp1") s0 = rstack.resume_state_create(s1, "rp0", one() - 1) v2 = rstack.resume_state_invoke(int, s0) return v1 * 100 + v2
def example(): v1 = g(one()).x c = C() c.x = 4 * one() s1 = rstack.resume_state_create(None, "rp1", c) return v1 * 100 + rstack.resume_state_invoke(C, s1).x
def example(): v1 = g(one()).x c = C() c.x = 4*one() s1 = rstack.resume_state_create(None, "rp1", c) return v1*100 + rstack.resume_state_invoke(C, s1).x
def example(): v1 = f(one(), 2 * one(), 3 * one()) s2 = rstack.resume_state_create(None, "rp2", 2 * one()) s1 = rstack.resume_state_create(s2, "rp1", 4 * one(), 5 * one()) return 100 * v1 + rstack.resume_state_invoke(int, s1)
def example(): v1 = f(one(),one()+one()) state = rstack.resume_state_create(None, "rp0", one(), one()+one()+one()) v2 = rstack.resume_state_invoke(int, state) return v1*10 + v2
def example(): v1 = f(one(), one() + one()) state = rstack.resume_state_create(None, "rp0", one()) return v1
def example(): v1 = f(one(),one()+one()) s = rstack.resume_state_create(None, "rp1", 5*one()) v2 = rstack.resume_state_invoke(int, s, returning=C(one()*3)) return v1*100 + v2
def example(): v1 = f(one(),one()+one()) state = rstack.resume_state_create(None, "rp0", one()) return v1
def example(): v1 = f(one()+one()) s1 = rstack.resume_state_create(None, "rp1") s0 = rstack.resume_state_create(s1, "rp0", one()-1) v2 = rstack.resume_state_invoke(int, s0) return v1*100 + v2
def example(): v1 = f(one(), one() + one()) state = rstack.resume_state_create(None, "rp0", one(), one() + one() + one()) v2 = rstack.resume_state_invoke(int, state) return v1 * 10 + v2
def reconstruct_framechain(self): from pypy.interpreter.pyframe import PyFrame from pypy.rlib.rstack import resume_state_create if self.subctx.topframe is None: self.frame = None return space = self.space ec = space.getexecutioncontext() costate = self.costate # now the big fun of recreating tiny things... bottom = resume_state_create(None, "yield_current_frame_to_caller_1") # ("coroutine__bind", state) _bind_frame = resume_state_create(bottom, "coroutine__bind", costate) # ("appthunk", costate, returns=w_result) appthunk_frame = resume_state_create(_bind_frame, "appthunk", costate) chain = appthunk_frame for frame in self.subctx.getframestack(): assert isinstance(frame, PyFrame) # ("execute_frame", self, executioncontext, returns=w_exitvalue) chain = resume_state_create(chain, "execute_frame", frame, ec) code = frame.pycode.co_code # ("dispatch", self, co_code, ec, returns=next_instr) chain = resume_state_create(chain, "dispatch", frame, code, ec) # ("handle_bytecode", self, co_code, ec, returns=next_instr) chain = resume_state_create(chain, "handle_bytecode", frame, code, ec) instr = frame.last_instr opcode = ord(code[instr]) map = pythonopcode.opmap call_ops = [map['CALL_FUNCTION'], map['CALL_FUNCTION_KW'], map['CALL_FUNCTION_VAR'], map['CALL_FUNCTION_VAR_KW'], map['CALL_METHOD']] assert opcode in call_ops # ("dispatch_call", self, co_code, next_instr, ec) chain = resume_state_create(chain, "dispatch_call", frame, code, instr+3, ec) instr += 1 oparg = ord(code[instr]) | ord(code[instr + 1]) << 8 nargs = oparg & 0xff if space.config.objspace.opcodes.CALL_METHOD and opcode == map['CALL_METHOD']: chain = resume_state_create(chain, 'CALL_METHOD', frame, nargs) elif opcode == map['CALL_FUNCTION'] and (oparg >> 8) & 0xff == 0: # Only positional arguments # case1: ("CALL_FUNCTION", f, nargs, returns=w_result) chain = resume_state_create(chain, 'CALL_FUNCTION', frame, nargs) else: # case2: ("call_function", f, returns=w_result) chain = resume_state_create(chain, 'call_function', frame) # ("w_switch", state, space) w_switch_frame = resume_state_create(chain, 'w_switch', costate, space) # ("coroutine_switch", state, returns=incoming_frame) switch_frame = resume_state_create(w_switch_frame, "coroutine_switch", costate) self.frame = switch_frame
def reconstruct_framechain(self): from pypy.interpreter.pyframe import PyFrame from pypy.rlib.rstack import resume_state_create if self.subctx.topframe is None: self.frame = None return space = self.space ec = space.getexecutioncontext() costate = self.costate # now the big fun of recreating tiny things... bottom = resume_state_create(None, "yield_current_frame_to_caller_1") # ("coroutine__bind", state) _bind_frame = resume_state_create(bottom, "coroutine__bind", costate) # ("appthunk", costate, returns=w_result) appthunk_frame = resume_state_create(_bind_frame, "appthunk", costate) chain = appthunk_frame for frame in self.subctx.getframestack(): assert isinstance(frame, PyFrame) # ("execute_frame", self, executioncontext, returns=w_exitvalue) chain = resume_state_create(chain, "execute_frame", frame, ec) code = frame.pycode.co_code # ("dispatch", self, co_code, ec, returns=next_instr) chain = resume_state_create(chain, "dispatch", frame, code, ec) # ("handle_bytecode", self, co_code, ec, returns=next_instr) chain = resume_state_create(chain, "handle_bytecode", frame, code, ec) instr = frame.last_instr opcode = ord(code[instr]) map = pythonopcode.opmap call_ops = [ map['CALL_FUNCTION'], map['CALL_FUNCTION_KW'], map['CALL_FUNCTION_VAR'], map['CALL_FUNCTION_VAR_KW'], map['CALL_METHOD'] ] assert opcode in call_ops # ("dispatch_call", self, co_code, next_instr, ec) chain = resume_state_create(chain, "dispatch_call", frame, code, instr + 3, ec) instr += 1 oparg = ord(code[instr]) | ord(code[instr + 1]) << 8 nargs = oparg & 0xff if space.config.objspace.opcodes.CALL_METHOD and opcode == map[ 'CALL_METHOD']: chain = resume_state_create(chain, 'CALL_METHOD', frame, nargs) elif opcode == map['CALL_FUNCTION'] and (oparg >> 8) & 0xff == 0: # Only positional arguments # case1: ("CALL_FUNCTION", f, nargs, returns=w_result) chain = resume_state_create(chain, 'CALL_FUNCTION', frame, nargs) else: # case2: ("call_function", f, returns=w_result) chain = resume_state_create(chain, 'call_function', frame) # ("w_switch", state, space) w_switch_frame = resume_state_create(chain, 'w_switch', costate, space) # ("coroutine_switch", state, returns=incoming_frame) switch_frame = resume_state_create(w_switch_frame, "coroutine_switch", costate) self.frame = switch_frame
def example(): v1 = f(one()+one()) s1 = rstack.resume_state_create(None, "rp1") s0 = rstack.resume_state_create(s1, "rp0", 0) v2 = rstack.resume_state_invoke(int, s0, raising=KeyError()) return v1*100 + v2
def example(): v1 = f(one(), one() + one()) s = rstack.resume_state_create(None, "rp1", 5 * one()) v2 = rstack.resume_state_invoke(int, s, returning=C(one() * 3)) return v1 * 100 + v2
def example(): v1 = f(one(), 2*one(), 3*one()) s2 = rstack.resume_state_create(None, "rp2", 2*one()) s1 = rstack.resume_state_create(s2, "rp1", 4*one(), 5*one()) return 100*v1 + rstack.resume_state_invoke(int, s1)