Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6beba1550381
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e062ebd19ff2
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Mar 13, 2015

  1. 2
    Copy the full SHA
    5444ab7 View commit details
  2. Merge pull request #2689 from bjfish/truffle_array_replace_to_ary

    [Truffle] Trying to add #to_ary to Array#replace
    nirvdrum committed Mar 13, 2015
    Copy the full SHA
    e062ebd View commit details
1 change: 0 additions & 1 deletion spec/truffle/tags/core/array/replace_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.jruby.truffle.nodes.coerce;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyArray;


@NodeChild(value = "child", type = RubyNode.class)
public abstract class ToAryNode extends RubyNode {

@Child private CallDispatchHeadNode toAryNode;

public ToAryNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public ToAryNode(ToAryNode prev) {
super(prev);
}

@Specialization
public RubyArray coerceRubyArray(RubyArray rubyArray) {
return rubyArray;
}

@Specialization(guards = "!isRubyArray")
public RubyArray coerceObject(VirtualFrame frame, Object object) {
notDesignedForCompilation();

if (toAryNode == null) {
CompilerDirectives.transferToInterpreter();
toAryNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
}

final Object coerced;

try {
coerced = toAryNode.call(frame, object, "to_ary", null);
} catch (RaiseException e) {
if (e.getRubyException().getLogicalClass() == getContext().getCoreLibrary().getNoMethodErrorClass()) {
CompilerDirectives.transferToInterpreter();

throw new RaiseException(
getContext().getCoreLibrary().typeErrorNoImplicitConversion(object, "Array", this));
} else {
throw e;
}
}
if (coerced instanceof RubyArray) {
return (RubyArray) coerced;
} else {
CompilerDirectives.transferToInterpreter();

throw new RaiseException(
getContext().getCoreLibrary().typeErrorBadCoercion(object, "Array", "to_ary", coerced, this));
}
}
}
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.array.*;
import org.jruby.truffle.nodes.coerce.ToIntNode;
import org.jruby.truffle.nodes.coerce.ToAryNodeFactory;
import org.jruby.truffle.nodes.coerce.ToIntNodeFactory;
import org.jruby.truffle.nodes.dispatch.*;
import org.jruby.truffle.nodes.methods.arguments.MissingArgumentBehaviour;
@@ -2652,7 +2653,12 @@ public Object rejectInPlaceObject(VirtualFrame frame, RubyArray array, RubyProc
}

@CoreMethod(names = "replace", required = 1, raiseIfFrozenSelf = true)
public abstract static class ReplaceNode extends ArrayCoreMethodNode {
@NodeChildren({
@NodeChild(value = "array"),
@NodeChild(value = "other")
})
@ImportGuards(ArrayGuards.class)
public abstract static class ReplaceNode extends RubyNode {

public ReplaceNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
@@ -2662,6 +2668,11 @@ public ReplaceNode(ReplaceNode prev) {
super(prev);
}


@CreateCast("other") public RubyNode coerceOtherToAry(RubyNode index) {
return ToAryNodeFactory.create(getContext(), getSourceSection(), index);
}

@Specialization(guards = "isOtherNull")
public RubyArray replace(RubyArray array, RubyArray other) {
notDesignedForCompilation();