def active_context(space): w_active_process = wrapper.scheduler(space).active_process() active_process = wrapper.ProcessWrapper(space, w_active_process) w_active_context = active_process.suspended_context() assert isinstance(w_active_context, W_PointersObject) active_process.store_suspended_context(space.w_nil) return w_active_context.as_context_get_shadow(space)
def test_step_run_something(): space, interp = runningSomethingImage(cached=False) ap = wrapper.ProcessWrapper(space, wrapper.scheduler(space).active_process()) w_ctx = ap.suspended_context() s_ctx = w_ctx.as_context_get_shadow(space) ap.store_suspended_context(space.w_nil) assert isinstance(s_ctx, storage_contexts.ContextPartShadow) assert s_ctx.top().is_same_object(space.w_true) interp.step(s_ctx) interp.step(s_ctx) assert s_ctx.top().value == 1 interp.step(s_ctx) assert s_ctx.top().value == 2 interp.step(s_ctx) assert s_ctx.top().value == 3
def new_process(w_next=None, w_my_list=None, w_suspended_context=None, priority=0): if w_next is None: w_next = space.w_nil if w_my_list is None: w_my_list = space.w_nil if w_suspended_context is None: w_suspended_context = space.w_nil w_priority = space.wrap_int(priority) w_process = W_PointersObject(space, None, 4) process = wrapper.ProcessWrapper(space, w_process) process.store_next_link(w_next) process.store_my_list(w_my_list) process.store_suspended_context(w_suspended_context) process.write(2, w_priority) return process
def create_process(interp, s_frame): space = interp.space w_active_process = wrapper.scheduler(space).active_process() assert isinstance(w_active_process, W_PointersObject) w_benchmark_proc = W_PointersObject(space, w_active_process.getclass(space), w_active_process.size()) if interp.image.version.has_closures: # Priorities below 10 are not allowed in newer versions of Squeak. active_priority = space.unwrap_int(w_active_process.fetch(space, 2)) priority = active_priority / 2 + 1 priority = max(11, priority) else: priority = 7 w_benchmark_proc.store(space, 1, s_frame.w_self()) w_benchmark_proc.store(space, 2, space.wrap_int(priority)) # Make process eligible for scheduling wrapper.ProcessWrapper(space, w_benchmark_proc).put_to_sleep()
def get_instances_array(interp, s_frame, w_class=None, store=True, some_instance=False): # early return for classes that never had instances. This is true for a # bunch of special classes. if w_class: if interp.space.w_SmallInteger.is_same_object(w_class): return [] if interp.space.is_spur.is_set(): if interp.space.w_Character.is_same_object(w_class): return [] if interp.image.version.is_64bit: if interp.space.w_Float.is_same_object(w_class): return [] if interp.image.version.is_modern: if interp.space.w_BlockContext.is_same_object(w_class): return [] # make sure we also get any objects in the currently active process w_active_process = wrapper.scheduler(interp.space).active_process() active_process = wrapper.ProcessWrapper(interp.space, w_active_process) active_process.store_suspended_context(s_frame.w_self()) try: match_w = s_frame.instances_array(w_class) if match_w is None: if some_instance and interp.space.is_spur.is_set(): # on Spur, someInstance really means just one, it's not used to # start iterating over all instances return get_instances_array_trace(interp, w_class, some_instance=True) match_w = get_instances_array_trace(interp, w_class) if store: s_frame.store_instances_array(w_class, match_w) return match_w finally: active_process.store_suspended_context(interp.space.w_nil)
def func(interp, s_frame, w_rcvr): # we leave the rcvr on the stack, so it is there even if we resume another # process when yielding w_process = wrapper.SchedulerWrapper(interp.space, w_rcvr).active_process() wrapper.ProcessWrapper(interp.space, w_process).yield_(s_frame)
def func(interp, s_frame, w_rcvr): assert_class(interp, w_rcvr, interp.space.w_Process) proc = wrapper.ProcessWrapper(interp.space, w_rcvr) s_frame.pop() # remove receiver s_frame.push(proc.my_list()) # leave my_list on stack as return value proc.suspend(s_frame)
def func(interp, s_frame, w_rcvr): assert_class(interp, w_rcvr, interp.space.w_Process) wrapper.ProcessWrapper(interp.space, w_rcvr).resume(s_frame)
def test_step_forged_image(): ap = wrapper.ProcessWrapper(space, wrapper.scheduler(space).active_process()) s_ctx = ap.suspended_context().as_context_get_shadow(space) assert isinstance(s_ctx, storage_contexts.ContextPartShadow) assert s_ctx.top().is_same_object(space.w_true)