GitLab will continue to be upgraded from 11.4.5-ce.0 on November 25th 2019 at 4.00pm (AEDT) to 5.00pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available.

Commit 1baadfd0 authored by Stefan Marr's avatar Stefan Marr

Convert #whileTrue: and #whileFalse: to primitives

Signed-off-by: 's avatarStefan Marr <git@stefan-marr.de>
parent cdcc9036
Subproject commit b2d362a1f4ffdb6a2a6ad036eb8d582073ddad45
Subproject commit 7186a40ad0a8dd039c62952aef22a84fcfc13c8e
class RestartLoopException(BaseException):
pass
class ReturnException(BaseException):
_immutable_fields_ = ["_result", "_target"]
......
from som.interpreter.control_flow import RestartLoopException
from som.primitives.primitives import Primitives
from som.vmobjects.primitive import Primitive
from som.vmobjects.block import block_evaluate
def _restart(ivkbl, frame, interpreter):
raise RestartLoopException()
def _execute_block(frame, block, interpreter, universe):
method = block.get_method()
b = universe.new_block(method, block.get_context())
frame.push(b)
block_evaluate(b, interpreter, frame)
return frame.pop()
def _whileTrue(ivkbl, frame, interpreter):
loop_body = frame.pop()
loop_condition = frame.pop()
universe = interpreter.get_universe()
trueObj = universe.trueObject
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)
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)
class BlockPrimitives(Primitives):
def install_primitives(self):
self._install_instance_primitive(Primitive("restart", self._universe, _restart))
self._install_instance_primitive(Primitive("whileTrue:", self._universe, _whileTrue))
self._install_instance_primitive(Primitive("whileFalse:", self._universe, _whileFalse))
from rpython.rlib import jit
from som.interpreter.control_flow import RestartLoopException
from som.vmobjects.abstract_object import AbstractObject
from som.vmobjects.primitive import Primitive
......@@ -44,14 +43,18 @@ class Block(AbstractObject):
def block_evaluation_primitive(num_args, universe):
return Block.Evaluation(num_args, universe, _invoke)
def _invoke(ivkbl, frame, interpreter):
assert isinstance(ivkbl, Block.Evaluation)
rcvr = frame.get_stack_element(ivkbl._number_of_arguments - 1)
context = rcvr.get_context()
new_frame = interpreter.new_frame(frame, rcvr.get_method(), context)
def block_evaluate(block, interpreter, frame):
context = block.get_context()
method = block.get_method()
new_frame = interpreter.new_frame(frame, method, context)
new_frame.copy_arguments_from(frame)
result = interpreter.interpret(rcvr.get_method(), new_frame)
frame.pop_old_arguments_and_push_result(rcvr.get_method(), result)
result = interpreter.interpret(method, new_frame)
frame.pop_old_arguments_and_push_result(method, result)
new_frame.clear_previous_frame()
def _invoke(ivkbl, frame, interpreter):
assert isinstance(ivkbl, Block.Evaluation)
rcvr = frame.get_stack_element(ivkbl._number_of_arguments - 1)
block_evaluate(rcvr, interpreter, frame)
......@@ -2,7 +2,7 @@ from __future__ import absolute_import
from rpython.rlib import jit
from som.interpreter.control_flow import ReturnException, RestartLoopException
from som.interpreter.control_flow import ReturnException
from som.vmobjects.abstract_object import AbstractObject
......@@ -98,21 +98,18 @@ class Method(AbstractObject):
new_frame = interpreter.new_frame(frame, self, None)
new_frame.copy_arguments_from(frame)
while True:
try:
result = interpreter.interpret(self, new_frame)
frame.pop_old_arguments_and_push_result(self, result)
new_frame.clear_previous_frame()
try:
result = interpreter.interpret(self, new_frame)
frame.pop_old_arguments_and_push_result(self, result)
new_frame.clear_previous_frame()
return
except ReturnException as e:
if e.has_reached_target(new_frame):
frame.pop_old_arguments_and_push_result(self, e.get_result())
return
except ReturnException as e:
if e.has_reached_target(new_frame):
frame.pop_old_arguments_and_push_result(self, e.get_result())
return
else:
new_frame.clear_previous_frame()
raise e
except RestartLoopException:
new_frame.reset_stack_pointer()
else:
new_frame.clear_previous_frame()
raise e
def __str__(self):
return "Method(" + self.get_holder().get_name().get_string() + ">>" + str(self.get_signature()) + ")"
......
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