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: bcda96eaed97
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 83327ee67f6d
Choose a head ref
  • 2 commits
  • 1 file changed
  • 2 contributors

Commits on May 2, 2015

  1. [Truffle] add missing RubyMethodForeignAccessFactory

    Matthias Grimmer committed May 2, 2015
    Copy the full SHA
    5d8ce18 View commit details
  2. Copy the full SHA
    83327ee View commit details
Showing with 86 additions and 0 deletions.
  1. +86 −0 truffle/src/main/java/org/jruby/truffle/runtime/core/RubyMethodForeignAccessFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.runtime.core;


import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.interop.InteropNode;
import org.jruby.truffle.runtime.RubyContext;

import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.ForeignAccessFactory;
import com.oracle.truffle.api.interop.InteropPredicate;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.interop.exception.UnsupportedMessageException;
import com.oracle.truffle.api.interop.messages.Message;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.source.NullSourceSection;
import com.oracle.truffle.interop.messages.Execute;
import com.oracle.truffle.interop.messages.HasSize;
import com.oracle.truffle.interop.messages.IsBoxed;
import com.oracle.truffle.interop.messages.IsExecutable;
import com.oracle.truffle.interop.messages.IsNull;
import com.oracle.truffle.interop.messages.Receiver;

public class RubyMethodForeignAccessFactory implements ForeignAccessFactory {

private final RubyContext context;

public RubyMethodForeignAccessFactory(RubyContext context) {
this.context = context;
}

@Override
public InteropPredicate getLanguageCheck() {
return new InteropPredicate() {
@Override
public boolean test(TruffleObject o) {
return o instanceof RubyBasicObject;
}
};
}

public CallTarget getAccess(Message tree) {
if (Execute.create(Receiver.create() ,0).matchStructure(tree)) {
return Truffle.getRuntime().createCallTarget(new RubyInteropRootNode(InteropNode.createExecute(context, new NullSourceSection("", ""))));
} else if (IsExecutable.create(Receiver.create()).matchStructure(tree)) {
return Truffle.getRuntime().createCallTarget(new RubyInteropRootNode(InteropNode.createIsExecutable(context, new NullSourceSection("", ""))));
} else if (IsBoxed.create(Receiver.create()).matchStructure(tree)) {
return Truffle.getRuntime().createCallTarget(new RubyInteropRootNode(InteropNode.createIsBoxedPrimitive(context, new NullSourceSection("", ""))));
} else if (IsNull.create(Receiver.create()).matchStructure(tree)) {
return Truffle.getRuntime().createCallTarget(new RubyInteropRootNode(InteropNode.createIsNull(context, new NullSourceSection("", ""))));
} else if (HasSize.create(Receiver.create()).matchStructure(tree)) {
return Truffle.getRuntime().createCallTarget(new RubyInteropRootNode(InteropNode.createHasSizePropertyFalse(context, new NullSourceSection("", ""))));
} else {
throw new UnsupportedMessageException("Message not supported: " + tree.toString());
}
}

protected static final class RubyInteropRootNode extends RootNode {

@Child private RubyNode node;

public RubyInteropRootNode(RubyNode node) {
this.node = node;
}

@Override
public Object execute(VirtualFrame virtualFrame) {
return node.execute(virtualFrame);
}

@Override
public String toString() {
return "Root of: " + node.toString();
}
}
}