Skip to content

Commit

Permalink
[Truffle] Remove RubyNilClass.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed May 10, 2015
1 parent 1ba7df2 commit 32baccf
Showing 73 changed files with 228 additions and 157 deletions.
4 changes: 0 additions & 4 deletions truffle/src/main/java/org/jruby/truffle/nodes/RubyGuards.java
Original file line number Diff line number Diff line change
@@ -103,10 +103,6 @@ public static boolean isForeignObject(Object object) {
return (object instanceof TruffleObject) && !(object instanceof RubyBasicObject);
}

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

public static boolean isTrue(boolean value) {
return value;
}
6 changes: 5 additions & 1 deletion truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Original file line number Diff line number Diff line change
@@ -221,7 +221,11 @@ public Object[] executeObjectArray(VirtualFrame frame) throws UnexpectedResultEx

// Guards which use the context and so can't be static

public boolean isRubiniusUndefined(Object value) {
protected boolean isNil(Object value) {
return value == nil();
}

protected boolean isRubiniusUndefined(Object value) {
return value == getContext().getCoreLibrary().getRubiniusUndefined();
}

Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyBignum;
import org.jruby.truffle.runtime.core.RubyNilClass;

/*
* TODO(CS): could probably unify this with SplatCastNode with some final configuration options.
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyNilClass;

/**
* Casts a value into a boolean.
Original file line number Diff line number Diff line change
@@ -32,7 +32,6 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyBignum;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyString;

/**
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyBignum;
import org.jruby.truffle.runtime.core.RubyHash;
import org.jruby.truffle.runtime.core.RubyNilClass;

// TODO(CS): copy and paste of ArrayCastNode

Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyProc;

/**
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyProc;

@NodeChild(value = "child", type = RubyNode.class)
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyNilClass;

@NodeChild(value = "child", type = RubyNode.class)
public abstract class SingleValueCastNode extends RubyNode {
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyNilClass;

/**
* Splat as used to cast a value to an array if it isn't already, as in {@code *value}.
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@
import org.jruby.truffle.nodes.defined.DefinedWrapperNode;
import org.jruby.truffle.nodes.literal.ObjectLiteralNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyNilClass;

import java.util.ArrayList;
import java.util.Arrays;
Original file line number Diff line number Diff line change
@@ -22,7 +22,6 @@
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyClass;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyProc;

@CoreClass(name = "Class")
Original file line number Diff line number Diff line change
@@ -28,7 +28,6 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyEncodingConverter;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.util.ByteList;
import org.jruby.util.io.EncodingUtils;

Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@
import org.jruby.truffle.runtime.backtrace.Backtrace;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyException;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyString;

@CoreClass(name = "Exception")
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyNilClass;

@NodeChildren({
@NodeChild(value="array", type=RubyNode.class),
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyNilClass;

import java.util.Arrays;

Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyNilClass;

@NodeChild("value")
public abstract class AssertConstantNode extends RubyNode {
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyNilClass;

public abstract class AssertNotCompiledNode extends RubyNode {

Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyMatchData;
import org.jruby.truffle.runtime.core.RubyNilClass;

public class CheckMatchVariableTypeNode extends RubyNode {

Original file line number Diff line number Diff line change
@@ -26,7 +26,6 @@
import org.jruby.truffle.runtime.ModuleOperations;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.truffle.runtime.core.RubySymbol;
import org.jruby.truffle.runtime.methods.InternalMethod;
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyBignum;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubySymbol;

@NodeChild(value = "child")
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyBignum;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubySymbol;

@NodeChild(value = "child")
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@
import jnr.constants.platform.Errno;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyException;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyString;

/**
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyClass;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.util.Dir;

Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@
import org.jruby.truffle.nodes.objects.TaintNodeGen;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.object.ObjectIDOperations;

/**
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.util.unsafe.UnsafeHolder;
import sun.misc.Unsafe;
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyModule;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyProc;

@CoreClass(name = "Rubinius::Type")
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyProc;

/**
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@

import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBignum;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyString;

import java.math.BigInteger;
@@ -22,10 +21,6 @@ public static boolean isNull(Object object) {
return object == null;
}

public static boolean isNil(Object object) {
return object instanceof RubyNilClass;
}

public static boolean isBoolean(Object object) {
return object instanceof Boolean;
}
16 changes: 15 additions & 1 deletion truffle/src/main/java/org/jruby/truffle/pack/nodes/PackNode.java
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jruby.truffle.pack.runtime.PackFrameDescriptor;
import org.jruby.truffle.pack.runtime.exceptions.TooFewArgumentsException;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.util.ByteList;

import java.util.Arrays;
@@ -31,7 +32,13 @@
@ImportStatic(PackGuards.class)
public abstract class PackNode extends Node {

private ConditionProfile writeMoreThanZeroBytes = ConditionProfile.createBinaryProfile();
private final RubyContext context;

private final ConditionProfile writeMoreThanZeroBytes = ConditionProfile.createBinaryProfile();

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

public abstract Object execute(VirtualFrame frame);

@@ -177,5 +184,12 @@ private byte[] ensureCapacity(VirtualFrame frame, int length) {
return output;
}

protected RubyContext getContext() {
return context;
}

protected boolean isNil(Object object) {
return object == context.getCoreLibrary().getNilObject();
}

}
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@

import com.oracle.truffle.api.frame.VirtualFrame;
import org.jruby.truffle.pack.nodes.PackNode;
import org.jruby.truffle.runtime.RubyContext;

/**
* Moves the output position to a particular location - similar to seek
@@ -23,7 +24,8 @@ public class AtNode extends PackNode {

private final int position;

public AtNode(int position) {
public AtNode(RubyContext context, int position) {
super(context);
this.position = position;
}

Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import org.jruby.truffle.pack.nodes.PackNode;
import org.jruby.truffle.pack.runtime.exceptions.OutsideOfStringException;
import org.jruby.truffle.runtime.RubyContext;

/**
* Moves the output position to the previous byte - similar to seek
@@ -23,6 +24,10 @@
*/
public class BackNode extends PackNode {

public BackNode(RubyContext context) {
super(context);
}

@Override
public Object execute(VirtualFrame frame) {
final int position = getOutputPosition(frame);
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import org.jruby.truffle.pack.nodes.PackNode;
import org.jruby.truffle.runtime.RubyContext;

/**
* Repeats a child node N times.
@@ -30,7 +31,8 @@ public class NNode extends PackNode {
private final int repeats;
@Child private PackNode child;

public NNode(int repeats, PackNode child) {
public NNode(RubyContext context, int repeats, PackNode child) {
super(context);
this.repeats = repeats;
this.child = child;
}
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import org.jruby.truffle.pack.nodes.PackNode;
import org.jruby.truffle.runtime.RubyContext;

/**
* Run a sequence of child nodes.
@@ -23,7 +24,8 @@ public class SequenceNode extends PackNode {

@Children private final PackNode[] children;

public SequenceNode(PackNode... children) {
public SequenceNode(RubyContext context, PackNode... children) {
super(context);
this.children = children;
}

Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import org.jruby.truffle.pack.nodes.PackNode;
import org.jruby.truffle.runtime.RubyContext;

/**
* Keep applying a child node as long as there is still source to read.
@@ -22,7 +23,8 @@ public class StarNode extends PackNode {

@Child private PackNode child;

public StarNode(PackNode child) {
public StarNode(RubyContext context, PackNode child) {
super(context);
this.child = child;
}

Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import com.oracle.truffle.api.dsl.Specialization;
import org.jruby.truffle.pack.nodes.PackNode;
import org.jruby.truffle.pack.parser.FormatDirective;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.util.ByteList;

import java.nio.charset.StandardCharsets;
@@ -28,7 +29,8 @@ public abstract class FormatFloatNode extends PackNode {
private final int precision;
private final char format;

public FormatFloatNode(int spacePadding, int zeroPadding, int precision, char format) {
public FormatFloatNode(RubyContext context, int spacePadding, int zeroPadding, int precision, char format) {
super(context);
this.spacePadding = spacePadding;
this.zeroPadding = zeroPadding;
this.precision = precision;
Loading

0 comments on commit 32baccf

Please sign in to comment.