Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Truffle] Remove NilPlaceholder and just use RubyNilClass.
  • Loading branch information
chrisseaton committed Oct 16, 2014
1 parent 9075f66 commit cc5ae83
Show file tree
Hide file tree
Showing 93 changed files with 418 additions and 536 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/truffle/TruffleBridgeImpl.java
Expand Up @@ -20,7 +20,7 @@
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.core.CoreMethodNodeManager;
import org.jruby.truffle.nodes.methods.MethodDefinitionNode;
import org.jruby.truffle.runtime.NilPlaceholder;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
Expand Down Expand Up @@ -121,7 +121,7 @@ public Object get() {
return callTarget.call(RubyArguments.pack(null, parentFrame, self, null, new Object[]{}));
}

}, NilPlaceholder.INSTANCE);
}, truffleContext.getCoreLibrary().getNilObject());
}

@Override
Expand Down
Expand Up @@ -48,7 +48,7 @@ public Object execute(VirtualFrame frame) {

return dispatch.dispatch(
frame,
NilPlaceholder.INSTANCE,
getContext().getCoreLibrary().getNilObject(),
RubyArguments.getSelf(frame.getArguments()),
receiverObject,
name,
Expand Down Expand Up @@ -85,14 +85,14 @@ public Object isDefined(VirtualFrame frame) {
*/

if (e.getRubyException().getLogicalClass() == context.getCoreLibrary().getNameErrorClass()) {
return NilPlaceholder.INSTANCE;
return getContext().getCoreLibrary().getNilObject();
}

throw e;
}

if (value == null) {
return NilPlaceholder.INSTANCE;
return getContext().getCoreLibrary().getNilObject();
} else {
return context.makeString("constant");
}
Expand Down
16 changes: 8 additions & 8 deletions core/src/main/java/org/jruby/truffle/nodes/RubyCallNode.java
Expand Up @@ -161,13 +161,13 @@ private Object[] splat(Object argument) {
public Object isDefined(VirtualFrame frame) {
notDesignedForCompilation();

if (receiver.isDefined(frame) == NilPlaceholder.INSTANCE) {
return NilPlaceholder.INSTANCE;
if (receiver.isDefined(frame) == getContext().getCoreLibrary().getNilObject()) {
return getContext().getCoreLibrary().getNilObject();
}

for (RubyNode argument : arguments) {
if (argument.isDefined(frame) == NilPlaceholder.INSTANCE) {
return NilPlaceholder.INSTANCE;
if (argument.isDefined(frame) == getContext().getCoreLibrary().getNilObject()) {
return getContext().getCoreLibrary().getNilObject();
}
}

Expand All @@ -185,7 +185,7 @@ public Object isDefined(VirtualFrame frame) {

receiverObject = receiver.execute(frame);
} catch (Exception e) {
return NilPlaceholder.INSTANCE;
return getContext().getCoreLibrary().getNilObject();
}

final RubyBasicObject receiverBasicObject = context.getCoreLibrary().box(receiverObject);
Expand All @@ -200,12 +200,12 @@ public Object isDefined(VirtualFrame frame) {
final Object r = respondToMissing.call(frame, receiverBasicObject, "respond_to_missing?", null, context.makeString(methodName));

if (r != Dispatch.MISSING && !respondToMissingCast.executeBoolean(frame, r)) {
return NilPlaceholder.INSTANCE;
return getContext().getCoreLibrary().getNilObject();
}
} else if (method.isUndefined()) {
return NilPlaceholder.INSTANCE;
return getContext().getCoreLibrary().getNilObject();
} else if (!ignoreVisibility && !method.isVisibleTo(this, self)) {
return NilPlaceholder.INSTANCE;
return getContext().getCoreLibrary().getNilObject();
}

return context.makeString("method");
Expand Down
5 changes: 0 additions & 5 deletions core/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Expand Up @@ -18,7 +18,6 @@
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import org.jruby.truffle.nodes.dispatch.Dispatch;
import org.jruby.truffle.nodes.yield.YieldDispatchNode;
import org.jruby.truffle.runtime.NilPlaceholder;
import org.jruby.truffle.runtime.RubyCallStack;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
Expand Down Expand Up @@ -96,10 +95,6 @@ public double executeFloat(VirtualFrame frame) throws UnexpectedResultException
return RubyTypesGen.RUBYTYPES.expectDouble(execute(frame));
}

public NilPlaceholder executeNilPlaceholder(VirtualFrame frame) throws UnexpectedResultException {
return RubyTypesGen.RUBYTYPES.expectNilPlaceholder(execute(frame));
}

public Object[] executeObjectArray(VirtualFrame frame) throws UnexpectedResultException {
return RubyTypesGen.RUBYTYPES.expectObjectArray(execute(frame));
}
Expand Down
7 changes: 0 additions & 7 deletions core/src/main/java/org/jruby/truffle/nodes/RubyTypes.java
Expand Up @@ -12,7 +12,6 @@
import com.oracle.truffle.api.dsl.ImplicitCast;
import com.oracle.truffle.api.dsl.TypeSystem;
import org.jruby.truffle.nodes.dispatch.Dispatch;
import org.jruby.truffle.runtime.NilPlaceholder;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.core.RubyArray;
Expand All @@ -31,7 +30,6 @@
@TypeSystem({ //
Dispatch.DispatchAction.class, //
UndefinedPlaceholder.class, //
NilPlaceholder.class, //
boolean.class, //
int.class, //
long.class, //
Expand Down Expand Up @@ -73,11 +71,6 @@

public class RubyTypes {

@ImplicitCast
public NilPlaceholder unboxNil(@SuppressWarnings("unused") RubyNilClass value) {
return NilPlaceholder.INSTANCE;
}

@ImplicitCast
public boolean unboxBoolean(RubyTrueClass value) {
return true;
Expand Down
Expand Up @@ -19,6 +19,7 @@
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyNilClass;

@NodeChild("child")
public abstract class ArrayCastNode extends RubyNode {
Expand All @@ -43,8 +44,8 @@ public RubyArray doArray(RubyArray array) {
}

@Specialization
public NilPlaceholder doNil(NilPlaceholder nilPlaceholder) {
return nilPlaceholder;
public RubyNilClass doNil(RubyNilClass nil) {
return nil;
}

@Specialization
Expand All @@ -54,7 +55,7 @@ public Object doObject(VirtualFrame frame, Object object) {
final Object result = toArrayNode.call(frame, object, "to_ary", null, new Object[]{});

if (result == Dispatch.MISSING) {
return NilPlaceholder.INSTANCE;
return getContext().getCoreLibrary().getNilObject();
}

if (!(result instanceof RubyArray)) {
Expand Down
Expand Up @@ -36,7 +36,7 @@ public BooleanCastNode(BooleanCastNode copy) {
}

@Specialization
public boolean doNil(@SuppressWarnings("unused") NilPlaceholder nil) {
public boolean doNil(@SuppressWarnings("unused") RubyNilClass nil) {
return false;
}

Expand Down
Expand Up @@ -14,7 +14,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.NilPlaceholder;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyBignum;
Expand Down Expand Up @@ -59,7 +59,7 @@ public RubyBasicObject box(Object value) {
return (RubyBasicObject) value;
}

if (seenNil && value instanceof NilPlaceholder) {
if (seenNil && value instanceof RubyNilClass) {
return getContext().getCoreLibrary().getNilObject();
}

Expand Down Expand Up @@ -94,7 +94,7 @@ public RubyBasicObject box(Object value) {
return (RubyBasicObject) value;
}

if (value instanceof NilPlaceholder) {
if (value instanceof RubyNilClass) {
seenNil = true;
return getContext().getCoreLibrary().getNilObject();
}
Expand Down
Expand Up @@ -36,7 +36,7 @@ public ProcCastNode(ProcCastNode prev) {
}

@Specialization
public NilPlaceholder doNil(NilPlaceholder nil) {
public RubyNilClass doNil(RubyNilClass nil) {
return nil;
}

Expand Down
Expand Up @@ -17,7 +17,7 @@
import org.jruby.truffle.runtime.core.*;

/**
* Wraps some node that will produce either a {@link RubyProc} or a {@link NilPlaceholder} and
* Wraps some node that will produce either a {@link RubyProc} or a {@link RubyNilClass} and
* returns {@code null} in case of the latter. Used in parts of the dispatch chain.
*/
@NodeChild(value = "child", type = RubyNode.class)
Expand All @@ -32,7 +32,7 @@ public ProcOrNullNode(ProcOrNullNode prev) {
}

@Specialization
public Object doNil(@SuppressWarnings("unused") NilPlaceholder nil) {
public Object doNil(@SuppressWarnings("unused") RubyNilClass nil) {
return null;
}

Expand Down
Expand Up @@ -58,13 +58,13 @@ public RubyArray doArray(RubyArray array) {
public RubyArray doObject(VirtualFrame frame, Object object) {
notDesignedForCompilation();

if (object == NilPlaceholder.INSTANCE) {
if (object == getContext().getCoreLibrary().getNilObject()) {
switch (nilBehavior) {
case EMPTY_ARRAY:
return new RubyArray(getContext().getCoreLibrary().getArrayClass());

case ARRAY_WITH_NIL:
return RubyArray.fromObject(getContext().getCoreLibrary().getArrayClass(), NilPlaceholder.INSTANCE);
return RubyArray.fromObject(getContext().getCoreLibrary().getArrayClass(), getContext().getCoreLibrary().getNilObject());

default: {
CompilerAsserts.neverPartOfCompilation();
Expand Down
Expand Up @@ -29,11 +29,7 @@ public BreakNode(RubyContext context, SourceSection sourceSection, RubyNode chil

@Override
public Object execute(VirtualFrame frame) {
if (child instanceof NilLiteralNode) {
throw BreakException.NIL;
} else {
throw new BreakException(child.execute(frame));
}
throw new BreakException(child.execute(frame));
}

}
Expand Up @@ -17,7 +17,7 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.cast.BooleanCastNode;
import org.jruby.truffle.runtime.NilPlaceholder;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.BreakException;
import org.jruby.truffle.runtime.control.NextException;
Expand Down Expand Up @@ -82,7 +82,7 @@ public Object execute(VirtualFrame frame) {
}
}

return NilPlaceholder.INSTANCE;
return getContext().getCoreLibrary().getNilObject();
}

}
Expand Up @@ -17,6 +17,7 @@
import org.jruby.truffle.nodes.literal.*;
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.control.*;
import org.jruby.truffle.runtime.core.RubyNilClass;

public class NextNode extends RubyNode {

Expand All @@ -32,11 +33,7 @@ public NextNode(RubyContext context, SourceSection sourceSection, RubyNode child
public Object execute(VirtualFrame frame) {
notDesignedForCompilation();

if (child instanceof NilLiteralNode) {
throw NextException.NIL;
} else {
throw new NextException(child.execute(frame));
}
throw new NextException(child.execute(frame));
}

}
Expand Up @@ -12,7 +12,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.NilPlaceholder;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.core.*;

Expand Down Expand Up @@ -72,11 +72,6 @@ public double executeFloat(VirtualFrame frame) throws UnexpectedResultException
return child.executeFloat(frame);
}

@Override
public NilPlaceholder executeNilPlaceholder(VirtualFrame frame) throws UnexpectedResultException {
return child.executeNilPlaceholder(frame);
}

@Override
public Object[] executeObjectArray(VirtualFrame frame) throws UnexpectedResultException {
return child.executeObjectArray(frame);
Expand Down
Expand Up @@ -14,8 +14,9 @@
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.nodes.*;
import org.jruby.truffle.nodes.*;
import org.jruby.truffle.nodes.literal.NilLiteralNode;
import org.jruby.truffle.nodes.literal.ObjectLiteralNode;
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.core.RubyNilClass;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -36,7 +37,7 @@ public static RubyNode sequence(RubyContext context, SourceSection sourceSection
final List<RubyNode> flattened = flatten(sequence, true);

if (flattened.isEmpty()) {
return new NilLiteralNode(context, sourceSection);
return new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getNilObject());
} else if (flattened.size() == 1) {
return flattened.get(0);
} else {
Expand All @@ -51,7 +52,7 @@ private static List<RubyNode> flatten(List<RubyNode> sequence, boolean allowTrai
final boolean lastNode = n == sequence.size() - 1;
final RubyNode node = sequence.get(n);

if (node instanceof NilLiteralNode) {
if (node instanceof ObjectLiteralNode && ((ObjectLiteralNode) node).getObject() instanceof RubyNilClass) {
if (allowTrailingNil && lastNode) {
flattened.add(node);
}
Expand Down
Expand Up @@ -70,7 +70,7 @@ public Object execute(VirtualFrame frame) {
}
}

return NilPlaceholder.INSTANCE;
return getContext().getCoreLibrary().getNilObject();
}

}

0 comments on commit cc5ae83

Please sign in to comment.