Skip to content

Commit

Permalink
Showing 12 changed files with 163 additions and 252 deletions.
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@
import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.nodes.NodeUtil;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import org.jruby.truffle.nodes.cast.BooleanCastNode;
import org.jruby.truffle.nodes.cast.BooleanCastNodeGen;
import org.jruby.truffle.nodes.cast.ProcOrNullNode;
122 changes: 122 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/RubyGuards.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* Copyright (c) 2013, 2015 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.nodes;

import com.oracle.truffle.api.interop.TruffleObject;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.core.*;

public abstract class RubyGuards {

public static boolean isUndefinedPlaceholder(Object value) {
return value instanceof UndefinedPlaceholder;
}

public static boolean isBoolean(Object value) {
return value instanceof Boolean;
}

public static boolean isInteger(Object value) {
return value instanceof Integer;
}

public static boolean isLong(Object value) {
return value instanceof Long;
}

public static boolean isDouble(Object value) {
return value instanceof Double;
}

public static boolean isRubyBignum(Object value) {
return value instanceof RubyBignum;
}

public static boolean isIntegerFixnumRange(Object value) {
return value instanceof RubyRange.IntegerFixnumRange;
}

public static boolean isRubyArray(Object value) {
return value instanceof RubyArray;
}

public static boolean isRubyBinding(Object value) {
return value instanceof RubyBinding;
}

public static boolean isRubyClass(Object value) {
return value instanceof RubyClass;
}

public static boolean isRubyHash(Object value) {
return value instanceof RubyHash;
}

public static boolean isRubyModule(Object value) {
return value instanceof RubyModule;
}

public static boolean isRubyNilClass(Object value) {
return value instanceof RubyNilClass;
}

public static boolean isRubyRange(Object value) {
return value instanceof RubyRange;
}

public static boolean isRubyRegexp(Object value) {
return value instanceof RubyRegexp;
}

public static boolean isRubyString(Object value) {
return value instanceof RubyString;
}

public static boolean isRubyEncoding(Object value) {
return value instanceof RubyEncoding;
}

public static boolean isRubySymbol(Object value) {
return value instanceof RubySymbol;
}

public static boolean isRubyMethod(Object value) {
return value instanceof RubyMethod;
}

public static boolean isRubyUnboundMethod(Object value) {
return value instanceof RubyUnboundMethod;
}

public static boolean isRubyBasicObject(Object value) {
return value instanceof RubyBasicObject;
}

public static boolean isThreadLocal(Object value) {
return value instanceof ThreadLocal;
}

public static boolean isForeignObject(Object object) {
return (object instanceof TruffleObject) && !(object instanceof RubyBasicObject);
}

public static boolean isTrue(boolean value) {
return value;
}

public static boolean isNaN(double value) {
return Double.isNaN(value);
}

public static boolean isInfinity(double value) {
return Double.isInfinite(value);
}

}
274 changes: 38 additions & 236 deletions truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Original file line number Diff line number Diff line change
@@ -11,26 +11,21 @@

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.instrument.ProbeNode;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.source.SourceSection;
import jnr.posix.POSIX;
import org.jruby.truffle.nodes.dispatch.DispatchAction;
import org.jruby.truffle.nodes.instrument.RubyWrapperNode;
import org.jruby.truffle.nodes.yield.YieldDispatchNode;
import org.jruby.truffle.runtime.LexicalScope;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.rubinius.RubiniusByteArray;

@ImportStatic(RubyGuards.class)
public abstract class RubyNode extends Node {

private final RubyContext context;
@@ -220,264 +215,79 @@ public Object[] executeObjectArray(VirtualFrame frame) throws UnexpectedResultEx
}
}

@Override
public boolean isInstrumentable() {
return true;
}

@Override
public ProbeNode.WrapperNode createWrapperNode() {
return new RubyWrapperNode(this);
}
// Guards which use the context and so can't be static

/**
* Records that this node was wrapped by the JRuby parser with a "newline" node.
*/
public void setAtNewline() {
atNewline = true;
}

/**
* Was this ndoe wrapped by a JRuby parser "newline" node?
*/
public boolean isAtNewline() {
return atNewline;
}

/**
* Ruby's parallel semantic path.
*
* @see DefinedNode
*/
public Object isDefined(VirtualFrame frame) {
return getContext().makeString("expression");
}

public RubyNode getNonProxyNode() {
return this;
}

public RubyContext getContext() {
return context;
}

public static void notDesignedForCompilation() {
CompilerDirectives.bailout("this code either doesn't implement Ruby semantics properly, or is a basic implementation that will not compile");
}

public boolean isTrue(boolean value) {
return value;
public boolean isRubyNilObject(Object value) {
return value == nil();
}

public RubyNode getNonWrapperNode() {
return this;
public boolean isRubiniusUndefined(Object value) {
return value == getContext().getCoreLibrary().getRubiniusUndefined();
}

public boolean isRational(RubyBasicObject o) {
// TODO(CS, 10-Jan-15) should this be a full is_a? test? We'd need a node for that.
return o.getLogicalClass() == getContext().getCoreLibrary().getRationalClass();
}

public boolean isForeignObject(Object object) {
return (object instanceof TruffleObject) && !(isRubyBasicObject(object));
}

public boolean isComplex(RubyBasicObject o) {
// TODO(BF, 4-4-15) COPIED from isRational - should this be a full is_a? test? We'd need a node for that.
return o.getLogicalClass() == getContext().getCoreLibrary().getComplexClass();
}

public boolean isNaN(double value) {
return Double.isNaN(value);
}

public boolean isInfinity(double value) {
return Double.isInfinite(value);
}

// Copied from RubyTypesGen

@SuppressWarnings("static-method")
public boolean isDispatchAction(Object value) {
return value instanceof DispatchAction;
}

@SuppressWarnings("static-method")
public boolean isLexicalScope(Object value) {
return value instanceof LexicalScope;
}

@SuppressWarnings("static-method")
public boolean isUndefinedPlaceholder(Object value) {
return value instanceof UndefinedPlaceholder;
}

@SuppressWarnings("static-method")
public boolean isBoolean(Object value) {
return value instanceof Boolean;
}

@SuppressWarnings("static-method")
public boolean isInteger(Object value) {
return value instanceof Integer;
}

@SuppressWarnings("static-method")
public boolean isLong(Object value) {
return value instanceof Long;
}

@SuppressWarnings("static-method")
public boolean isDouble(Object value) {
return value instanceof Double;
}

@SuppressWarnings("static-method")
public boolean isString(Object value) {
return value instanceof String;
}

@SuppressWarnings("static-method")
public boolean isRubyBignum(Object value) {
return value instanceof RubyBignum;
}

@SuppressWarnings("static-method")
public boolean isIntegerFixnumRange(Object value) {
return value instanceof RubyRange.IntegerFixnumRange;
}

@SuppressWarnings("static-method")
public boolean isLongFixnumRange(Object value) {
return value instanceof RubyRange.LongFixnumRange;
}

@SuppressWarnings("static-method")
public boolean isObjectRange(Object value) {
return value instanceof RubyRange.ObjectRange;
}

@SuppressWarnings("static-method")
public boolean isRubyArray(Object value) {
return value instanceof RubyArray;
}

@SuppressWarnings("static-method")
public boolean isRubyBinding(Object value) {
return value instanceof RubyBinding;
}

@SuppressWarnings("static-method")
public boolean isRubyClass(Object value) {
return value instanceof RubyClass;
}

@SuppressWarnings("static-method")
public boolean isRubyException(Object value) {
return value instanceof RubyException;
}

@SuppressWarnings("static-method")
public boolean isRubyFiber(Object value) {
return value instanceof RubyFiber;
}

@SuppressWarnings("static-method")
public boolean isRubyHash(Object value) {
return value instanceof RubyHash;
}

@SuppressWarnings("static-method")
public boolean isRubyMatchData(Object value) {
return value instanceof RubyMatchData;
}
// Helpers methods for terseness

@SuppressWarnings("static-method")
public boolean isRubyModule(Object value) {
return value instanceof RubyModule;
}

@SuppressWarnings("static-method")
public boolean isRubyNilClass(Object value) {
return value instanceof RubyNilClass;
}

@SuppressWarnings("static-method")
public boolean isRubyProc(Object value) {
return value instanceof RubyProc;
}

@SuppressWarnings("static-method")
public boolean isRubyRange(Object value) {
return value instanceof RubyRange;
}

@SuppressWarnings("static-method")
public boolean isRubyRegexp(Object value) {
return value instanceof RubyRegexp;
}

@SuppressWarnings("static-method")
public boolean isRubyString(Object value) {
return value instanceof RubyString;
}

@SuppressWarnings("static-method")
public boolean isRubyEncoding(Object value) {
return value instanceof RubyEncoding;
protected RubyNilClass nil() {
return getContext().getCoreLibrary().getNilObject();
}

@SuppressWarnings("static-method")
public boolean isRubySymbol(Object value) {
return value instanceof RubySymbol;
protected POSIX posix() {
return getContext().getPosix();
}

@SuppressWarnings("static-method")
public boolean isRubyThread(Object value) {
return value instanceof RubyThread;
}
// Instrumentation

@SuppressWarnings("static-method")
public boolean isRubyTime(Object value) {
return value instanceof RubyTime;
@Override
public boolean isInstrumentable() {
return true;
}

@SuppressWarnings("static-method")
public boolean isRubyEncodingConverter(Object value) {
return value instanceof RubyEncodingConverter;
@Override
public ProbeNode.WrapperNode createWrapperNode() {
return new RubyWrapperNode(this);
}

@SuppressWarnings("static-method")
public boolean isRubyMethod(Object value) {
return value instanceof RubyMethod;
public RubyNode getNonWrapperNode() {
return this;
}

@SuppressWarnings("static-method")
public boolean isRubyUnboundMethod(Object value) {
return value instanceof RubyUnboundMethod;
public void setAtNewline() {
atNewline = true;
}

@SuppressWarnings("static-method")
public boolean isRubyBasicObject(Object value) {
return value instanceof RubyBasicObject;
public boolean isAtNewline() {
return atNewline;
}

@SuppressWarnings("static-method")
public boolean isThreadLocal(Object value) {
return value instanceof ThreadLocal;
public RubyNode getNonProxyNode() {
return this;
}

@SuppressWarnings("static-method")
public boolean isJavaObjectArray(Object value) {
return value instanceof Object[];
/**
* Ruby's parallel semantic path.
*
* @see DefinedNode
*/
public Object isDefined(VirtualFrame frame) {
return getContext().makeString("expression");
}

public boolean isRubyNilObject(Object value) {
return value == nil();
public RubyContext getContext() {
return context;
}

public boolean isRubiniusUndefined(Object value) {
return value == getContext().getCoreLibrary().getRubiniusUndefined();
public static void notDesignedForCompilation() {
CompilerDirectives.bailout("this code either doesn't implement Ruby semantics properly, or is a basic implementation that will not compile");
}

protected Object ruby(VirtualFrame frame, String expression, Object... arguments) {
@@ -510,12 +320,4 @@ private MaterializedFrame setupFrame(Object self, Object... arguments) {

return evalFrame;
}

protected RubyNilClass nil() {
return getContext().getCoreLibrary().getNilObject();
}

protected POSIX posix() {
return getContext().getPosix();
}
}
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.GeneratedBy;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.NodeUtil;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.CoreSourceSection;
@@ -32,7 +31,6 @@
import org.jruby.truffle.runtime.methods.SharedMethodInfo;
import org.jruby.truffle.runtime.util.ArrayUtils;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
import com.oracle.truffle.interop.messages.Read;
import com.oracle.truffle.interop.messages.Receiver;
import com.oracle.truffle.interop.node.ForeignObjectAccessNode;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.KernelNodes;
import org.jruby.truffle.nodes.core.KernelNodesFactory;
@@ -90,10 +91,10 @@ public DispatchNode call() throws Exception {
newDispathNode = new UncachedDispatchNode(getContext(), ignoreVisibility, getDispatchAction(), missingBehavior);
} else {
depth++;
if (isRubyBasicObject(receiverObject)) {
if (receiverObject instanceof RubyBasicObject) {
newDispathNode = doRubyBasicObject(frame, first, receiverObject, methodName, argumentsObjects);
}
else if (isForeign(receiverObject)) {
else if (RubyGuards.isForeignObject(receiverObject)) {
newDispathNode = createForeign(argumentsObjects, first, methodName);
} else {
newDispathNode = doUnboxedObject(frame, first, receiverObject, methodName);
@@ -108,10 +109,6 @@ else if (isForeign(receiverObject)) {
return dispatch.executeDispatch(frame, receiverObject, methodName, blockObject, argumentsObjects);
}

private boolean isForeign(Object receiverObject) {
return isForeignObject(receiverObject);
}

private DispatchNode createForeign(Object argumentsObjects, DispatchNode first, Object methodName) {
Object[] args = (Object[]) argumentsObjects;
return new CachedForeignDispatchNode(getContext(), first, methodName, args.length);
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.FrameSlotTypeException;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
*/
package org.jruby.truffle.pack.nodes;

import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.FrameSlotTypeException;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@
import org.jruby.truffle.pack.nodes.type.ToDoubleNode;
import org.jruby.truffle.pack.nodes.type.ToDoubleNodeGen;
import org.jruby.truffle.pack.nodes.write.NullNode;
import org.jruby.truffle.runtime.RubyContext;

/**
* Read a {@code double} value from the source.
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@

import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.ForeignAccessFactory;
import com.oracle.truffle.api.interop.InteropPredicate;
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@

import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.ForeignAccessFactory;
import com.oracle.truffle.api.interop.InteropPredicate;
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@

import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.ForeignAccessFactory;
import com.oracle.truffle.api.interop.InteropPredicate;
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@

import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.ForeignAccessFactory;
import com.oracle.truffle.api.interop.InteropPredicate;

0 comments on commit 6a374e6

Please sign in to comment.