Skip to content

Commit

Permalink
Remove all support for inlining
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Dec 5, 2023
1 parent b7acae5 commit 228f028
Show file tree
Hide file tree
Showing 24 changed files with 2 additions and 2,900 deletions.
127 changes: 0 additions & 127 deletions src/som/compiler/ast/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@
from som.interpreter.ast.nodes.return_non_local_node import ReturnNonLocalNode
from som.interpreter.ast.nodes.sequence_node import SequenceNode
from som.interpreter.ast.nodes.specialized.int_inc_node import IntIncrementNode
from som.interpreter.ast.nodes.specialized.literal_and_or import (
AndInlinedNode,
OrInlinedNode,
)
from som.interpreter.ast.nodes.specialized.literal_if import (
IfInlinedNode,
IfElseInlinedNode,
)
from som.interpreter.ast.nodes.specialized.literal_while import WhileInlinedNode
from som.vm.symbols import symbol_for

from som.vmobjects.array import Array
Expand Down Expand Up @@ -205,17 +196,6 @@ def _binary_message(self, mgenc, receiver):

source = self._get_source_section(coord)

if not is_super_send:
sel = selector.get_embedded_string()
if sel == "&&":
inlined = self._try_inlining_and(receiver, arg_expr, source, mgenc)
if inlined is not None:
return inlined
elif sel == "||":
inlined = self._try_inlining_or(receiver, arg_expr, source, mgenc)
if inlined is not None:
return inlined

if is_super_send:
return BinarySuper(
selector, receiver, arg_expr, mgenc.holder.get_super_class(), source
Expand All @@ -239,58 +219,6 @@ def _binary_operand(self, mgenc):

return operand

@staticmethod
def _try_inlining_if(if_true, receiver, arguments, source, mgenc):
arg = arguments[0]
if not isinstance(arg, BlockNode):
return None

method = arg.get_method()
body_expr = method.inline(mgenc)
return IfInlinedNode(receiver, body_expr, if_true, source)

@staticmethod
def _try_inlining_if_else(if_true, receiver, arguments, source, mgenc):
arg1 = arguments[0]
if not isinstance(arg1, BlockNode):
return None

arg2 = arguments[1]
if not isinstance(arg2, BlockNode):
return None

true_expr = arg1.get_method().inline(mgenc)
false_expr = arg2.get_method().inline(mgenc)
return IfElseInlinedNode(receiver, true_expr, false_expr, if_true, source)

@staticmethod
def _try_inlining_while(while_true, receiver, arguments, source, mgenc):
if not isinstance(receiver, BlockNode):
return None

if not isinstance(arguments[0], BlockNode):
return None

cond_expr = receiver.get_method().inline(mgenc)
body_expr = arguments[0].get_method().inline(mgenc)
return WhileInlinedNode(cond_expr, body_expr, while_true, source)

@staticmethod
def _try_inlining_and(receiver, arg_expr, source, mgenc):
if not isinstance(arg_expr, BlockNode):
return None

arg_body = arg_expr.get_method().inline(mgenc)
return AndInlinedNode(receiver, arg_body, source)

@staticmethod
def _try_inlining_or(receiver, arg_expr, source, mgenc):
if not isinstance(arg_expr, BlockNode):
return None

arg_body = arg_expr.get_method().inline(mgenc)
return OrInlinedNode(receiver, arg_body, source)

def _keyword_message(self, mgenc, receiver):
is_super_send = self._super_send

Expand All @@ -303,61 +231,6 @@ def _keyword_message(self, mgenc, receiver):
arguments.append(self._formula(mgenc))

keyword = "".join(keyword_parts)
source = self._get_source_section(coord)

num_args = len(arguments)

if not is_super_send:
if num_args == 1:
if keyword == "ifTrue:":
inlined = self._try_inlining_if(
True, receiver, arguments, source, mgenc
)
if inlined is not None:
return inlined
elif keyword == "ifFalse:":
inlined = self._try_inlining_if(
False, receiver, arguments, source, mgenc
)
if inlined is not None:
return inlined
elif keyword == "whileTrue:":
inlined = self._try_inlining_while(
True, receiver, arguments, source, mgenc
)
if inlined is not None:
return inlined
elif keyword == "whileFalse:":
inlined = self._try_inlining_while(
False, receiver, arguments, source, mgenc
)
if inlined is not None:
return inlined
elif keyword == "and:":
inlined = self._try_inlining_and(
receiver, arguments[0], source, mgenc
)
if inlined is not None:
return inlined
elif keyword == "or:":
inlined = self._try_inlining_or(
receiver, arguments[0], source, mgenc
)
if inlined is not None:
return inlined
elif num_args == 2:
if keyword == "ifTrue:ifFalse:":
inlined = self._try_inlining_if_else(
True, receiver, arguments, source, mgenc
)
if inlined is not None:
return inlined
elif keyword == "ifFalse:ifTrue:":
inlined = self._try_inlining_if_else(
False, receiver, arguments, source, mgenc
)
if inlined is not None:
return inlined

selector = symbol_for(keyword)

Expand Down
8 changes: 0 additions & 8 deletions src/som/compiler/ast/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,10 @@ def get_initialized_read_node(self, context_level, source_section):
return LocalFrameVarReadNode(FRAME_AND_INNER_RCVR_IDX, source_section)
return _Variable.get_initialized_read_node(self, context_level, source_section)

def copy_for_inlining(self, idx):
if self._name == "$blockSelf":
return None
return Argument(self._name, idx, self.source)

def __str__(self):
return "Argument(" + self._name + " idx: " + str(self.idx) + ")"


class Local(_Variable):
def copy_for_inlining(self, idx):
return Local(self._name, idx, self.source)

def __str__(self):
return "Local(" + self._name + " idx: " + str(self.idx) + ")"
35 changes: 0 additions & 35 deletions src/som/compiler/bc/bytecode_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,41 +186,6 @@ def emit_push_constant_index(mgenc, lit_index):
emit2(mgenc, BC.push_constant, lit_index, 1)


def emit_jump_on_bool_with_dummy_offset(mgenc, is_if_true, needs_pop):
# Remember: true and false seem flipped here.
# This is because if the test passes, the block is inlined directly.
# But if the test fails, we need to jump.
# Thus, an `#ifTrue:` needs to generated a jump_on_false.
if needs_pop:
bc = BC.jump_on_false_pop if is_if_true else BC.jump_on_true_pop
stack_effect = -1
else:
bc = BC.jump_on_false_top_nil if is_if_true else BC.jump_on_true_top_nil
stack_effect = 0

emit1(mgenc, bc, stack_effect)
idx = mgenc.add_bytecode_argument_and_get_index(0)
mgenc.add_bytecode_argument(0)
return idx


def emit_jump_with_dummy_offset(mgenc):
emit1(mgenc, BC.jump, 0)
idx = mgenc.add_bytecode_argument_and_get_index(0)
mgenc.add_bytecode_argument(0)
return idx


def emit_jump_backward_with_offset(mgenc, offset):
emit3(
mgenc,
BC.jump_backward if offset <= 0xFF else BC.jump2_backward,
offset & 0xFF,
offset >> 8,
0,
)


def emit1(mgenc, code, stack_effect):
mgenc.add_bytecode(code, stack_effect)

Expand Down
13 changes: 0 additions & 13 deletions src/som/compiler/bc/disassembler.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from som.compiler.bc.bytecode_generator import compute_offset
from som.vm.current import current_universe
from som.vm.universe import error_print, error_println
from som.interpreter.bc.bytecodes import (
bytecode_as_str,
bytecode_length,
Bytecodes,
is_one_of,
JUMP_BYTECODES,
)


Expand Down Expand Up @@ -186,15 +183,5 @@ def dump_bytecode(m, b, indent=""):
)
elif bytecode == Bytecodes.return_non_local:
error_println("context: " + str(m.get_bytecode(b + 1)))
elif is_one_of(bytecode, JUMP_BYTECODES):
offset = compute_offset(m.get_bytecode(b + 1), m.get_bytecode(b + 2))
if bytecode == Bytecodes.jump_backward or bytecode == Bytecodes.jump2_backward:
target = b - offset
else:
target = b + offset

error_println(
"(jump offset: " + str(offset) + " -> jump target: " + str(target) + ")"
)
else:
error_println("<incorrect bytecode>")
Loading

0 comments on commit 228f028

Please sign in to comment.