Skip to content

Commit

Permalink
[Truffle] Moving Kernel#Array to kernel.rb.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjfish committed Mar 30, 2015
1 parent cb72352 commit 716a16c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 56 deletions.
1 change: 1 addition & 0 deletions spec/truffle/tags/core/enumerator/next_values_tags.txt
@@ -1 +1,2 @@
fails:Enumerator#next_values returns an empty array if yield is called without arguments
fails:Enumerator#next_values returns an array with only nil if yield is called with nil
1 change: 1 addition & 0 deletions spec/truffle/tags/core/enumerator/peek_values_tags.txt
@@ -1 +1,2 @@
fails:Enumerator#peek_values returns an empty array if yield is called without arguments
fails:Enumerator#peek_values returns an array with only nil if yield is called with nil
18 changes: 0 additions & 18 deletions spec/truffle/tags/core/kernel/Array_tags.txt

This file was deleted.

Expand Up @@ -257,44 +257,6 @@ public RubyNilClass abort() {
}
}

@CoreMethod(names = "Array", isModuleFunction = true, argumentsAsArray = true)
public abstract static class ArrayNode extends CoreMethodNode {

@Child ArrayBuilderNode arrayBuilderNode;

public ArrayNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
arrayBuilderNode = new ArrayBuilderNode.UninitializedArrayBuilderNode(context);
}

public ArrayNode(ArrayNode prev) {
super(prev);
arrayBuilderNode = prev.arrayBuilderNode;
}

@Specialization(guards = "isOneArrayElement")
public RubyArray arrayOneArrayElement(Object[] args) {
return (RubyArray) args[0];
}

@Specialization(guards = "!isOneArrayElement")
public RubyArray array(Object[] args) {
final int length = args.length;
Object store = arrayBuilderNode.start(length);

for (int n = 0; n < length; n++) {
store = arrayBuilderNode.append(store, n, args[n]);
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), arrayBuilderNode.finish(store, length), length);
}

protected boolean isOneArrayElement(Object[] args) {
return args.length == 1 && args[0] instanceof RubyArray;
}

}

@CoreMethod(names = "at_exit", isModuleFunction = true, needsBlock = true)
public abstract static class AtExitNode extends CoreMethodNode {

Expand Down
13 changes: 13 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/kernel.rb
Expand Up @@ -28,6 +28,19 @@

module Kernel

def Array(obj)
ary = Rubinius::Type.check_convert_type obj, Array, :to_ary

return ary if ary

if array = Rubinius::Type.check_convert_type(obj, Array, :to_a)
array
else
[obj]
end
end
module_function :Array

def Complex(*args)
Rubinius.privately do
Complex.convert(*args)
Expand Down

0 comments on commit 716a16c

Please sign in to comment.