Skip to content

Commit

Permalink
Showing 154 changed files with 344 additions and 475 deletions.
Original file line number Diff line number Diff line change
@@ -16,8 +16,8 @@
import org.jruby.truffle.nodes.core.UnboundMethodNodes;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.core.hash.HashNodes;
import org.jruby.truffle.runtime.ThreadLocalObject;
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.ThreadLocalObject;
import org.jruby.truffle.runtime.core.*;

public abstract class RubyGuards {
27 changes: 13 additions & 14 deletions truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Original file line number Diff line number Diff line change
@@ -19,18 +19,15 @@
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.source.SourceSection;

import jnr.ffi.provider.MemoryManager;
import jnr.posix.POSIX;

import org.jcodings.Encoding;
import org.jcodings.specific.USASCIIEncoding;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.instrument.RubyWrapperNode;
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.sockets.NativeSockets;
import org.jruby.util.ByteList;
@@ -172,16 +169,6 @@ public RubyArray executeRubyArray(VirtualFrame frame) throws UnexpectedResultExc
}
}

public RubyHash executeRubyHash(VirtualFrame frame) throws UnexpectedResultException {
final Object value = execute(frame);

if (value instanceof RubyHash) {
return (RubyHash) value;
} else {
throw new UnexpectedResultException(value);
}
}

public RubyRegexp executeRubyRegexp(VirtualFrame frame) throws UnexpectedResultException {
final Object value = execute(frame);

@@ -212,6 +199,18 @@ public RubyProc executeRubyProc(VirtualFrame frame) throws UnexpectedResultExcep
}
}

// If you try to make this RubyBasicObject things break in the DSL

public RubyHash executeRubyHash(VirtualFrame frame) throws UnexpectedResultException {
final Object value = execute(frame);

if (RubyGuards.isRubyHash(value)) {
return (RubyHash) value;
} else {
throw new UnexpectedResultException(value);
}
}

public RubyBasicObject executeRubyBasicObject(VirtualFrame frame) throws UnexpectedResultException {
final Object value = execute(frame);

Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyHash;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.hash.HashOperations;
import org.jruby.truffle.runtime.hash.KeyValue;
import org.jruby.truffle.runtime.methods.Arity;
@@ -45,7 +45,7 @@ public CheckArityNode(RubyContext context, SourceSection sourceSection, Arity ar
public void executeVoid(VirtualFrame frame) {
final Object[] frameArguments = frame.getArguments();
final int given;
final RubyHash keywordArguments;
final RubyBasicObject keywordArguments;

//TODO (MS): Check merge
if (RubyArguments.isKwOptimized(frame.getArguments())) {
@@ -76,7 +76,7 @@ public void executeVoid(VirtualFrame frame) {
}
}

private boolean checkArity(VirtualFrame frame, int given, RubyHash keywordArguments) {
private boolean checkArity(VirtualFrame frame, int given, RubyBasicObject keywordArguments) {
if (keywordArguments != null) {
given -= 1;
}
Original file line number Diff line number Diff line change
@@ -9,17 +9,16 @@
*/
package org.jruby.truffle.nodes.arguments;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;
import com.oracle.truffle.api.utilities.ValueProfile;

import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyHash;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.hash.HashOperations;
import org.jruby.truffle.runtime.hash.KeyValue;

@@ -56,7 +55,7 @@ public Object execute(VirtualFrame frame) {
return kwarg;
}
} else {
final RubyHash hash = RubyArguments.getUserKeywordsHash(frame.getArguments(), minimum);
final RubyBasicObject hash = RubyArguments.getUserKeywordsHash(frame.getArguments(), minimum);

if (defaultProfile.profile(hash == null)) {
return defaultValue.execute(frame);
@@ -73,7 +72,9 @@ public Object execute(VirtualFrame frame) {
}

@TruffleBoundary
private Object lookupKeywordInHash(RubyHash hash) {
private Object lookupKeywordInHash(RubyBasicObject hash) {
assert RubyGuards.isRubyHash(hash);

for (KeyValue keyValue : HashOperations.verySlowToKeyValues(hash)) {
if (keyValue.getKey().toString().equals(name)) {
return keyValue.getValue();
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
import org.jruby.truffle.nodes.methods.MarkerNode;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyHash;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.hash.HashOperations;
import org.jruby.truffle.runtime.hash.KeyValue;

@@ -59,7 +59,7 @@ public Object execute(VirtualFrame frame) {
private Object lookupRestKeywordArgumentHash(VirtualFrame frame) {
CompilerDirectives.transferToInterpreter();

final RubyHash hash = RubyArguments.getUserKeywordsHash(frame.getArguments(), minimum);
final RubyBasicObject hash = RubyArguments.getUserKeywordsHash(frame.getArguments(), minimum);

if (hash == null) {
return HashNodes.createEmptyHash(getContext().getCoreLibrary().getHashClass());
Original file line number Diff line number Diff line change
@@ -14,9 +14,9 @@
import com.oracle.truffle.api.utilities.BranchProfile;
import com.oracle.truffle.api.utilities.ValueProfile;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.NotProvided;

/**
* Read pre-optional argument.
Original file line number Diff line number Diff line change
@@ -12,13 +12,13 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyClass;
import org.jruby.truffle.runtime.core.RubyHash;
import org.jruby.truffle.runtime.array.ArrayUtils;
import org.jruby.truffle.runtime.core.RubyClass;

/**
* Read the rest of arguments after a certain point into an array.
@@ -50,7 +50,7 @@ public Object execute(VirtualFrame frame) {
if (keywordArguments) {
final Object lastArgument = RubyArguments.getUserArgument(frame.getArguments(), RubyArguments.getUserArgumentsCount(frame.getArguments()) - 1);

if (lastArgument instanceof RubyHash) {
if (RubyGuards.isRubyHash(lastArgument)) {
endIndex -= 1;
}
}
Original file line number Diff line number Diff line change
@@ -33,7 +33,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.RubyBignum;
import org.jruby.truffle.runtime.core.RubyString;

/**
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
@@ -22,8 +23,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.RubyBignum;
import org.jruby.truffle.runtime.core.RubyHash;

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

@@ -59,30 +58,30 @@ public RubyBasicObject cast(double value) {
return nil();
}

@Specialization(guards = "isRubyBignum(value)")
public RubyBasicObject cast(RubyBasicObject value) {
@Specialization(guards = "isNil(nil)")
public RubyBasicObject castNil(RubyBasicObject nil) {
return nil();
}

@Specialization
public RubyHash cast(RubyHash hash) {
return hash;
@Specialization(guards = "isRubyBignum(value)")
public RubyBasicObject castBignum(RubyBasicObject value) {
return nil();
}

@Specialization(guards = "isNil(nil)")
public RubyBasicObject cast(Object nil) {
return nil();
@Specialization(guards = "isRubyHash(hash)")
public RubyBasicObject castHash(RubyBasicObject hash) {
return hash;
}

@Specialization(guards = {"!isNil(object)", "!isRubyHash(object)"})
@Specialization(guards = {"!isNil(object)", "!isRubyBignum(object)", "!isRubyHash(object)"})
public Object cast(VirtualFrame frame, RubyBasicObject object) {
final Object result = toHashNode.call(frame, object, "to_hash", null, new Object[]{});

if (result == DispatchNode.MISSING) {
return nil();
}

if (!(result instanceof RubyHash)) {
if (!RubyGuards.isRubyHash(result)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorShouldReturn(object.toString(), "to_hash", "HAsh", this));
}
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.runtime.RubyContext;
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.nodes.core.array.ArrayDupNode;
import org.jruby.truffle.nodes.core.array.ArrayDupNodeGen;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
Original file line number Diff line number Diff line change
@@ -24,7 +24,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.RubyBignum;

@NodeChild(value = "child", type = RubyNode.class)
public abstract class ToIntNode extends RubyNode {
Original file line number Diff line number Diff line change
@@ -9,6 +9,13 @@
*/
package org.jruby.truffle.nodes.constants;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.KernelNodes.RequireNode;
import org.jruby.truffle.nodes.core.KernelNodesFactory;
@@ -22,14 +29,6 @@
import org.jruby.truffle.runtime.core.RubySymbol;
import org.jruby.util.IdUtil;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;

@NodeChildren({
@NodeChild("module"), @NodeChild("name"),
@NodeChild(value = "lookupConstantNode", type = LookupConstantNode.class, executeWith = { "module", "name" })
Original file line number Diff line number Diff line change
@@ -9,15 +9,6 @@
*/
package org.jruby.truffle.nodes.constants;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.DispatchNode;
import org.jruby.truffle.runtime.LexicalScope;
import org.jruby.truffle.runtime.ModuleOperations;
import org.jruby.truffle.runtime.RubyConstant;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyModule;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
@@ -27,6 +18,14 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.DispatchNode;
import org.jruby.truffle.runtime.LexicalScope;
import org.jruby.truffle.runtime.ModuleOperations;
import org.jruby.truffle.runtime.RubyConstant;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyModule;

@NodeChildren({ @NodeChild("module"), @NodeChild("name") })
public abstract class LookupConstantNode extends RubyNode {
Original file line number Diff line number Diff line change
@@ -9,18 +9,16 @@
*/
package org.jruby.truffle.nodes.constants;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.nodes.literal.LiteralNode;
import org.jruby.truffle.runtime.LexicalScope;
import org.jruby.truffle.runtime.RubyConstant;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;

public class ReadConstantNode extends RubyNode {

private final String name;
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@
import com.oracle.truffle.api.nodes.InvalidAssumptionException;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBinding;
Original file line number Diff line number Diff line change
@@ -9,13 +9,11 @@
*/
package org.jruby.truffle.nodes.conversion;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
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.RubyString;
Loading

0 comments on commit 3d9f6f1

Please sign in to comment.