Skip to content

Commit

Permalink
Remove SOM block restart primitive and use recursion to explain #whil…
Browse files Browse the repository at this point in the history
…eTrue:

The #whileTrue: code is never actually executed, and the block primitive has not been used ever since TruffleSOM.

Remove it as a cleanup. ‘Explaining’ the behavior of #whileTrue: with recursion is much nicer. The implementation relies on a node substitution/lowering anyway. So, stack overflow isn’t an issue.

Signed-off-by: Stefan Marr <git@stefan-marr.de>
  • Loading branch information
smarr committed Apr 24, 2017
1 parent 8004a11 commit c1975c4
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 24 deletions.
10 changes: 2 additions & 8 deletions core-lib/Kernel.som
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,9 @@ class Kernel vmMirror: vmMirror = Object <: Value (
)
public whileTrue: block = (
self value ifFalse: [ ^ nil ].
value ifFalse: [ ^ nil ].
block value.
self restart
^ whileTrue: block
)
(* Exception support *)
Expand All @@ -605,12 +605,6 @@ class Kernel vmMirror: vmMirror = Object <: Value (
public ensure: aBlock = (
^ vmMirror exceptionDo: self ensure: aBlock
)
(* TODO: this feels still like old legacy, it's not how it works...
on the other hand, seeing the #whileTrue: semantics is useful.
so, replacing it directly with a primitive call isn't nice either *)
(* Restarting *)
public restart = ( ^ vmMirror blockRestart: self )
)
protected class Block1 = Block ()()
Expand Down
16 changes: 0 additions & 16 deletions src/som/primitives/BlockPrims.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import som.interpreter.nodes.nary.TernaryExpressionNode;
import som.interpreter.nodes.nary.UnaryExpressionNode;
import som.vm.VmSettings;
import som.vmobjects.SAbstractObject;
import som.vmobjects.SBlock;
import som.vmobjects.SInvokable;
import tools.dym.Tags.OpClosureApplication;
Expand Down Expand Up @@ -48,21 +47,6 @@ public static final IndirectCallNode create() {
return Truffle.getRuntime().createIndirectCallNode();
}

@GenerateNodeFactory
@Primitive(primitive = "blockRestart:")
public abstract static class RestartPrim extends UnaryExpressionNode {
public RestartPrim(final boolean eagWrap, final SourceSection source) { super(eagWrap, source); }

@Specialization
public SAbstractObject doSBlock(final SBlock receiver) {
CompilerDirectives.transferToInterpreter();
// TruffleSOM intrinsifies #whileTrue: and #whileFalse:
throw new RuntimeException("This primitive is not supported anymore! "
+ "Something went wrong with the intrinsification of "
+ "#whileTrue:/#whileFalse:?");
}
}

@GenerateNodeFactory
@ImportStatic(BlockPrims.class)
@Primitive(primitive = "blockValue:", selector = "value", inParser = false,
Expand Down
Binary file modified tests/dym/expected-results.tar.bz2
Binary file not shown.

0 comments on commit c1975c4

Please sign in to comment.