Skip to content

Commit

Permalink
[Truffle] More integration of Enumerable and remove old shims.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Jan 30, 2015
1 parent 0a6a2b9 commit 630368c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 34 deletions.
1 change: 0 additions & 1 deletion core/src/main/ruby/jruby/truffle/core.rb
Expand Up @@ -15,7 +15,6 @@
require_relative 'core/rubinius/api/shims/rubinius'
require_relative 'core/rubinius/api/shims/lookuptable'
require_relative 'core/rubinius/api/shims/thread'
require_relative 'core/rubinius/api/shims/enumerator'
require_relative 'core/rubinius/api/shims/undefined'
require_relative 'core/rubinius/api/shims/metrics'

Expand Down

This file was deleted.

13 changes: 13 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Expand Up @@ -1373,6 +1373,8 @@ public Object deleteAtIntegerFixnum(RubyArray array, int index) {
@ImportGuards(ArrayGuards.class)
public abstract static class EachNode extends YieldingCoreMethodNode {

@Child private CallDispatchHeadNode toEnumNode;

private final BranchProfile breakProfile = BranchProfile.create();
private final BranchProfile nextProfile = BranchProfile.create();
private final BranchProfile redoProfile = BranchProfile.create();
Expand All @@ -1383,6 +1385,17 @@ public EachNode(RubyContext context, SourceSection sourceSection) {

public EachNode(EachNode prev) {
super(prev);
toEnumNode = prev.toEnumNode;
}

@Specialization
public Object eachEnumerator(VirtualFrame frame, RubyArray array, UndefinedPlaceholder block) {
if (toEnumNode == null) {
CompilerDirectives.transferToInterpreter();
toEnumNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
}

return toEnumNode.call(frame, array, "to_enum", null, getContext().getCoreLibrary().getEachSymbol());
}

@Specialization(guards = "isNull")
Expand Down
Expand Up @@ -125,6 +125,8 @@ public class CoreLibrary {
private ArrayNodes.MinBlock arrayMinBlock;
private ArrayNodes.MaxBlock arrayMaxBlock;

@CompilerDirectives.CompilationFinal private RubySymbol eachSymbol;

public CoreLibrary(RubyContext context) {
this.context = context;
}
Expand Down Expand Up @@ -387,6 +389,10 @@ public void initialize() {
Object value = context.getRuntime().warningsEnabled() ? context.getRuntime().isVerbose() : nilObject;
RubyNode.notDesignedForCompilation();
globalVariablesObject.getOperations().setInstanceVariable(globalVariablesObject, "$VERBOSE", value);

// Common symbols

eachSymbol = getContext().getSymbolTable().getSymbol("each");
}

public void initializeAfterMethodsAdded() {
Expand Down Expand Up @@ -986,4 +992,8 @@ public RubyClass getComplexClass() {
public RubyClass getByteArrayClass() {
return byteArrayClass;
}

public RubySymbol getEachSymbol() {
return eachSymbol;
}
}

1 comment on commit 630368c

@chrisseaton
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nirvdrum @eregon Array#each returning an enumerator - turned out quite simple

Please sign in to comment.