Author: Anton Gulenko <[email protected]>
Branch: storage
Changeset: r806:1f802c5946b7
Date: 2014-05-07 15:10 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/1f802c5946b7/
Log: Moved the _loop flag of Interpreter into a separate Subclass
TestInterpreter used in tests.
diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -38,6 +38,8 @@
evented=True,
max_stack_depth=constants.MAX_LOOP_DEPTH):
import time
+
+ # === Initialize immutable variables
self.space = space
self.image = image
self.image_name = image_name
@@ -46,22 +48,21 @@
else:
self.startup_time = constants.CompileTime
self.max_stack_depth = max_stack_depth
- self.remaining_stack_depth = max_stack_depth
- self._loop = False
- self.next_wakeup_tick = 0
self.evented = evented
try:
self.interrupt_counter_size = int(os.environ["SPY_ICS"])
except KeyError:
self.interrupt_counter_size = constants.INTERRUPT_COUNTER_SIZE
+
+ # === Initialize mutable variables
self.interrupt_check_counter = self.interrupt_counter_size
- #
######################################################################
+ self.remaining_stack_depth = max_stack_depth
+ self.next_wakeup_tick = 0
self.trace = trace
self.trace_proxy = False
def loop(self, w_active_context):
# just a trampoline for the actual loop implemented in c_loop
- self._loop = True
s_new_context = w_active_context.as_context_get_shadow(self.space)
while True:
assert self.remaining_stack_depth == self.max_stack_depth
@@ -114,9 +115,6 @@
s_context.push(nlr.value)
def stack_frame(self, s_new_frame, may_context_switch=True):
- if not self._loop:
- return s_new_frame # this test is done to not loop in test,
- # but rather step just once where wanted
if self.remaining_stack_depth <= 1:
raise StackOverflow(s_new_frame)
@@ -180,7 +178,7 @@
return self.trace
if objectmodel.we_are_translated() or conftest.option is None:
return False
- if primitivies:
+ if primitives:
return conftest.option.prim_trace
else:
return conftest.option.bc_trace
diff --git a/spyvm/test/test_interpreter.py b/spyvm/test/test_interpreter.py
--- a/spyvm/test/test_interpreter.py
+++ b/spyvm/test/test_interpreter.py
@@ -1,6 +1,6 @@
import py, operator, sys
from spyvm import model, interpreter, primitives, shadow, objspace, wrapper,
constants
-from .util import create_space_interp, copy_to_module, cleanup_module,
import_bytecodes
+from .util import create_space_interp, copy_to_module, cleanup_module,
import_bytecodes, TestInterpreter
from spyvm.wrapper import PointWrapper
from spyvm.conftest import option
@@ -985,7 +985,7 @@
# ifTrue: [ 0 ]
# ifFalse: [ (testBlock value: aNumber - 1) + aNumber ]].
# ^ testBlock value: 11
- interp = interpreter.Interpreter(space, max_stack_depth=3)
+ interp = TestInterpreter(space, max_stack_depth=3)
#create a method with the correct bytecodes and a literal
bytes = reduce(operator.add, map(chr, [0x8a, 0x01, 0x68, 0x10, 0x8f, 0x11,
0x00, 0x11, 0x10, 0x75, 0xb6, 0x9a, 0x75, 0xa4, 0x09, 0x8c, 0x00, 0x01,
@@ -1007,7 +1007,7 @@
except interpreter.StackOverflow, e:
assert False
try:
- interp = interpreter.Interpreter(space, None, "", max_stack_depth=10)
+ interp = TestInterpreter(space, image_name="", max_stack_depth=10)
interp._loop = True
interp.c_loop(w_method.create_frame(space, space.wrap_int(0), []))
except interpreter.StackOverflow, e:
@@ -1015,7 +1015,7 @@
except interpreter.ReturnFromTopLevel, e:
assert False
-class StackTestInterpreter(interpreter.Interpreter):
+class StackTestInterpreter(TestInterpreter):
def stack_frame(self, w_frame, may_interrupt=True):
stack_depth = self.max_stack_depth - self.remaining_stack_depth
for i in range(stack_depth + 1):
diff --git a/spyvm/test/test_miniimage.py b/spyvm/test/test_miniimage.py
--- a/spyvm/test/test_miniimage.py
+++ b/spyvm/test/test_miniimage.py
@@ -1,6 +1,6 @@
import py, math
from spyvm import squeakimage, model, constants, interpreter, shadow,
objspace, wrapper, primitives
-from .util import read_image, open_reader, copy_to_module, cleanup_module
+from .util import read_image, open_reader, copy_to_module, cleanup_module,
TestInterpreter
def setup_module():
space, interp, image, reader = read_image("mini.image")
@@ -213,7 +213,7 @@
w_ctx = ap.suspended_context()
ap.store_suspended_context(space.w_nil)
- interp = interpreter.Interpreter(space)
+ interp = TestInterpreter(space)
interp.interpret_toplevel(w_ctx)
def test_compile_method():
@@ -355,7 +355,7 @@
s_ctx = w_ctx.as_context_get_shadow(space)
ap.store_suspended_context(space.w_nil)
- interp = interpreter.Interpreter(space)
+ interp = TestInterpreter(space)
assert isinstance(s_ctx, shadow.MethodContextShadow)
assert s_ctx.top().is_same_object(space.w_true)
interp.step(s_ctx)
diff --git a/spyvm/test/test_primitives.py b/spyvm/test/test_primitives.py
--- a/spyvm/test/test_primitives.py
+++ b/spyvm/test/test_primitives.py
@@ -5,7 +5,7 @@
from rpython.rlib.rfloat import INFINITY, NAN, isinf, isnan
from rpython.rlib.rarithmetic import intmask
from rpython.rtyper.lltypesystem import lltype, rffi
-from .util import create_space, copy_to_module, cleanup_module
+from .util import create_space, copy_to_module, cleanup_module, TestInterpreter
from .test_interpreter import _new_frame
def setup_module():
@@ -47,7 +47,7 @@
frame = context
for i in range(len(stack)):
frame.as_context_get_shadow(space).push(stack[i])
- interp = interpreter.Interpreter(space, image_name=IMAGENAME)
+ interp = TestInterpreter(space, image_name=IMAGENAME)
return interp, frame, len(stack)
def _prim(space, code, stack, context = None):
@@ -595,7 +595,7 @@
closure = space.newClosure(w_frame, 4, #pc
size_arguments, copiedValues)
s_initial_context.push_all([closure] + args)
- interp = interpreter.Interpreter(space)
+ interp = TestInterpreter(space)
s_active_context = prim_table[primitives.CLOSURE_VALUE +
size_arguments](interp, s_initial_context, size_arguments)
return s_initial_context, closure, s_active_context
@@ -639,7 +639,7 @@
w_frame, s_context = new_frame("<never called, but needed for method
generation>")
s_context.push(space.w_Array)
- interp = interpreter.Interpreter(space)
+ interp = TestInterpreter(space)
prim_table[primitives.SOME_INSTANCE](interp, s_context, 0)
w_1 = s_context.pop()
assert w_1.getclass(space) is space.w_Array
@@ -655,7 +655,7 @@
w_frame, s_context = new_frame("<never called, but needed for method
generation>")
s_context.push(space.w_Array)
- interp = interpreter.Interpreter(space)
+ interp = TestInterpreter(space)
w_1 = someInstances[0]
assert w_1.getclass(space) is space.w_Array
@@ -680,7 +680,7 @@
closure = space.newClosure(w_frame, 4, 0, [])
s_frame = w_frame.as_methodcontext_get_shadow(space)
- interp = interpreter.Interpreter(space, image_name=IMAGENAME)
+ interp = TestInterpreter(space, image_name=IMAGENAME)
interp._loop = True
try:
diff --git a/spyvm/test/util.py b/spyvm/test/util.py
--- a/spyvm/test/util.py
+++ b/spyvm/test/util.py
@@ -17,7 +17,7 @@
reader.initialize()
image = squeakimage.SqueakImage()
image.from_reader(space, reader)
- interp = interpreter.Interpreter(space, image)
+ interp = TestInterpreter(space, image)
return space, interp, image, reader
def create_space(bootstrap = bootstrap_by_default):
@@ -28,7 +28,7 @@
def create_space_interp(bootstrap = bootstrap_by_default):
space = create_space(bootstrap)
- interp = interpreter.Interpreter(space)
+ interp = TestInterpreter(space)
return space, interp
def find_symbol_in_methoddict_of(string, s_class):
@@ -72,6 +72,21 @@
else:
make_getter(entry)
+# This interpreter allows fine grained control of the interpretation
+# by manually stepping through the bytecodes, if _loop is set to False.
+class TestInterpreter(interpreter.Interpreter):
+ _loop = False
+
+ def loop(self, w_active_context):
+ self._loop = True
+ return interpreter.Interpreter.loop(self, w_active_context)
+
+ def stack_frame(self, s_new_frame, may_context_switch=True):
+ if not self._loop:
+ return s_new_frame # this test is done to not loop in test,
+ # but rather step just once where wanted
+ return interpreter.Interpreter.stack_frame(self, s_new_frame,
may_context_switch)
+
class BootstrappedObjSpace(objspace.ObjSpace):
def bootstrap(self):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit