1+ py_object = object
2+ import pixie .vm .object as object
3+ from pixie .vm .primitives import nil , true , false
4+ from pixie .vm .code import BaseCode
5+ from pixie .vm .numbers import Integer
6+ import pixie .vm .protocols as proto
7+ from pixie .vm .code import extend , as_var
8+ from rpython .rlib .rarithmetic import r_uint as r_uint32 , intmask , widen
9+ import rpython .rlib .jit as jit
10+ import pixie .vm .rt as rt
11+ import rpython .rlib .rstacklet as rstacklet
12+
13+ th = rstacklet .StackletThread (None )
14+
15+ class Box (py_object ):
16+ def __init__ (self ):
17+ self ._val = None
18+
19+ box = Box ()
20+
21+ class WrappedHandler (BaseCode ):
22+ _type = object .Type ("Stacklet" )
23+ def __init__ (self , h , box ):
24+ self ._h = h
25+ self ._box = box
26+
27+ def switch_to (self , val ):
28+ self ._box ._val = val
29+ self ._h = th .switch (self ._h )
30+ return self ._box ._val
31+
32+ def _invoke (self , args ):
33+ assert len (args ) == 1
34+ return self .switch_to (args [0 ])
35+
36+
37+
38+ def new_stacklet (f , val ):
39+ global box
40+ box = Box ()
41+ self_box = box
42+ def default_handler (h , o ):
43+ global box
44+ handler = WrappedHandler (h , box )
45+ box = None
46+ handler ._h = th .switch (handler ._h )
47+ retval = f .invoke ([handler , val ])
48+ return handler ._h
49+
50+ h = th .new (default_handler )
51+ return WrappedHandler (h , self_box )
0 commit comments