Skip to content

Commit

Permalink
[Truffle] Should convert the foreign return value back to Ruby.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Sep 19, 2016
1 parent b66f889 commit da04e6a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Expand Up @@ -19,9 +19,16 @@
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.language.RubyNode;

/**
* Only converts primitive types (including java.lang.String).
*/
@NodeChild(value = "value", type = RubyNode.class)
public abstract class ForeignToRubyNode extends RubyNode {

public static ForeignToRubyNode create() {
return ForeignToRubyNodeGen.create(null);
}

public abstract Object executeConvert(VirtualFrame frame, Object value);

@Specialization(guards = "stringsEquals(cachedValue, value)", limit = "getLimit()")
Expand Down
Expand Up @@ -59,15 +59,19 @@ public Object callCached(
Object[] args,
@Cached("args.length") int cachedArgsLength,
@Cached("createHelperNode(cachedArgsLength)") OutgoingNode outgoingNode,
@Cached("createToForeignNodes(cachedArgsLength)") RubyToForeignNode[] toForeignNodes) {
return outgoingNode.executeCall(frame, receiver, argsToForeign(frame, toForeignNodes, args));
@Cached("createToForeignNodes(cachedArgsLength)") RubyToForeignNode[] toForeignNodes,
@Cached("create()") ForeignToRubyNode toRubyNode) {
Object[] foreignArgs = argsToForeign(frame, toForeignNodes, args);
Object foreignValue = outgoingNode.executeCall(frame, receiver, foreignArgs);
return toRubyNode.executeConvert(frame, foreignValue);
}

@Specialization(contains = "callCached")
public Object callUncached(
VirtualFrame frame,
TruffleObject receiver,
Object[] args) {
Object[] args,
@Cached("create()") ForeignToRubyNode toRubyNode) {
PerformanceWarnings.warn("megamorphic outgoing foreign call");

if (megamorphicToForeignNode == null) {
Expand All @@ -81,7 +85,8 @@ public Object callUncached(
foreignArgs[n] = megamorphicToForeignNode.executeConvert(frame, args[n]);
}

return createHelperNode(args.length).executeCall(frame, receiver, foreignArgs);
Object foreignValue = createHelperNode(args.length).executeCall(frame, receiver, foreignArgs);
return toRubyNode.executeConvert(frame, foreignValue);
}

@TruffleBoundary
Expand Down

0 comments on commit da04e6a

Please sign in to comment.