Skip to content

Commit

Permalink
[Truffle] Try moving Kernel#loop to Rubinius.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Apr 22, 2015
1 parent 5385f46 commit bae615c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/kernel/loop_tags.txt

This file was deleted.

Expand Up @@ -1163,30 +1163,6 @@ public RubyArray localVariables() {

}

@CoreMethod(names = "loop", isModuleFunction = true, returnsEnumeratorIfNoBlock = true)
public abstract static class LoopNode extends CoreMethodNode {

@Child private WhileNode whileNode;

public LoopNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
whileNode = WhileNode.createWhile(context, sourceSection,
new BooleanLiteralNode(context, sourceSection, true),
new YieldNode(context, getSourceSection(), new RubyNode[]{}, false)
);
}

public LoopNode(LoopNode prev) {
super(prev);
whileNode = prev.whileNode;
}

@Specialization
public Object loop(VirtualFrame frame) {
return whileNode.execute(frame);
}
}

@CoreMethod(names = "__method__", needsSelf = false)
public abstract static class MethodNameNode extends CoreMethodNode {

Expand Down
12 changes: 12 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/kernel.rb
Expand Up @@ -228,4 +228,16 @@ def tap
self
end

def loop
return to_enum(:loop) unless block_given?

begin
while true
yield
end
rescue StopIteration
end
end
module_function :loop

end

0 comments on commit bae615c

Please sign in to comment.