Skip to content
Permalink
Browse files
[Truffle] More integration of Enumerable and remove old shims.
  • Loading branch information
chrisseaton committed Jan 30, 2015
1 parent 0a6a2b9 commit 630368c2bfaccf4c957b9cc2a8d3bdf9f27d863a
@@ -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'

This file was deleted.

@@ -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();
@@ -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")
@@ -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;
}
@@ -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() {
@@ -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

@chrisseaton chrisseaton commented on 630368c Jan 30, 2015

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.