Commit 0a1fac8c authored by Stefan Marr's avatar Stefan Marr

Change the main traced loop from interpreter loop to while loops

- make bytecode loop unroll safe
- refactor while loop implementation to avoid code duplication
Signed-off-by: 's avatarStefan Marr <git@stefan-marr.de>
parent 426ba9d8
......@@ -145,6 +145,7 @@ class Interpreter(object):
self._send(method, frame, signature, receiver.get_class(self._universe), bytecode_index)
@jit.unroll_safe
def interpret(self, method, frame):
bc_idx = 0
......@@ -152,10 +153,10 @@ class Interpreter(object):
while True:
current_bc_idx = bc_idx
jitdriver.jit_merge_point(bytecode_index=current_bc_idx,
interp=self,
method=method,
frame=frame)
# jitdriver.jit_merge_point(bytecode_index=current_bc_idx,
# interp=self,
# method=method,
# frame=frame)
bytecode = method.get_bytecode(current_bc_idx)
......
......@@ -2,41 +2,64 @@ from som.primitives.primitives import Primitives
from som.vmobjects.primitive import Primitive
from som.vmobjects.block import block_evaluate
def _execute_block(frame, block, interpreter, universe):
method = block.get_method()
b = universe.new_block(method, block.get_context())
from rpython.rlib import jit
def get_printable_location(interpreter, method_body, method_condition, while_type):
from som.vmobjects.method import Method
from som.interpreter.bytecodes import bytecode_as_str
assert isinstance(method_body, Method)
assert isinstance(method_condition, Method)
#bc = method.get_bytecode(bytecode_index)
# return "%s @ %d in %s" % (bytecode_as_str(bc),
# bytecode_index,
# method.merge_point_string())
return "TODO"
jitdriver = jit.JitDriver(
greens=['interpreter', 'method_body', 'method_condition', 'while_type'],
reds='auto',
# virtualizables=['frame'],
get_printable_location=get_printable_location)
def _execute_block(frame, block, block_method, interpreter, universe):
b = universe.new_block(block_method, block.get_context())
frame.push(b)
block_evaluate(b, interpreter, frame)
return frame.pop()
def _whileTrue(ivkbl, frame, interpreter):
def _whileLoop(frame, interpreter, while_type):
loop_body = frame.pop()
loop_condition = frame.pop()
universe = interpreter.get_universe()
trueObj = universe.trueObject
method_body = loop_body.get_method()
method_condition = loop_condition.get_method()
condition_result = _execute_block(frame, loop_condition, interpreter, universe)
while condition_result is trueObj:
_execute_block(frame, loop_body, interpreter, universe)
condition_result = _execute_block(frame, loop_condition, interpreter, universe)
while True:
jitdriver.jit_merge_point(interpreter=interpreter,
method_body=method_body,
method_condition=method_condition,
#universe=universe,
while_type=while_type)
condition_result = _execute_block(frame, loop_condition, method_condition, interpreter, universe)
if condition_result is while_type:
_execute_block(frame, loop_body, method_body, interpreter, universe)
else:
break
frame.push(universe.nilObject)
def _whileFalse(ivkbl, frame, interpreter):
loop_body = frame.pop()
loop_condition = frame.pop()
universe = interpreter.get_universe()
trueObj = universe.falseObject
condition_result = _execute_block(frame, loop_condition, interpreter, universe)
while condition_result is trueObj:
_execute_block(frame, loop_body, interpreter, universe)
condition_result = _execute_block(frame, loop_condition, interpreter, universe)
frame.push(universe.nilObject)
_whileLoop(frame, interpreter, interpreter.get_universe().falseObject)
def _whileTrue(ivkbl, frame, interpreter):
_whileLoop(frame, interpreter, interpreter.get_universe().trueObject)
class BlockPrimitives(Primitives):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment