Skip to content

Commit c6627b9

Browse files
author
Josef Haider
committed
[Truffle] Start to use Rubinius for core library implementation.
1 parent e0ca0a4 commit c6627b9

56 files changed

Lines changed: 2562 additions & 107 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/src/main/java/org/jruby/truffle/nodes/ReadConstantNode.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,8 @@ public Object isDefined(VirtualFrame frame) {
8888
}
8989
}
9090

91+
public String getName() {
92+
return name;
93+
}
94+
9195
}

core/src/main/java/org/jruby/truffle/nodes/RubyCallNode.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public class RubyCallNode extends RubyNode {
5151
@Child protected BooleanCastNode respondToMissingCast;
5252

5353
public RubyCallNode(RubyContext context, SourceSection section, String methodName, RubyNode receiver, RubyNode block, boolean isSplatted, RubyNode... arguments) {
54+
this(context, section, methodName, receiver, block, isSplatted, false, arguments);
55+
}
56+
57+
public RubyCallNode(RubyContext context, SourceSection section, String methodName, RubyNode receiver, RubyNode block, boolean isSplatted, boolean rubiniusPrimitive, RubyNode... arguments) {
5458
super(context, section);
5559

5660
this.methodName = methodName;
@@ -66,7 +70,7 @@ public RubyCallNode(RubyContext context, SourceSection section, String methodNam
6670
this.arguments = arguments;
6771
this.isSplatted = isSplatted;
6872

69-
dispatchHead = new DispatchHeadNode(context);
73+
dispatchHead = new DispatchHeadNode(context, false, rubiniusPrimitive, Dispatch.MissingBehavior.CALL_METHOD_MISSING);
7074
respondToMissing = new DispatchHeadNode(context, false, Dispatch.MissingBehavior.RETURN_MISSING);
7175
respondToMissingCast = BooleanCastNodeFactory.create(context, section, null);
7276
}

core/src/main/java/org/jruby/truffle/nodes/RubyNode.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.jruby.truffle.runtime.core.RubyHash;
2929
import org.jruby.truffle.runtime.core.RubyRange;
3030
import org.jruby.truffle.runtime.core.RubyBasicObject;
31+
import org.jruby.truffle.runtime.rubinius.RubiniusByteArray;
32+
import org.jruby.truffle.runtime.rubinius.RubiniusChannel;
3133

3234
import java.math.BigInteger;
3335

@@ -189,6 +191,14 @@ public UndefinedPlaceholder executeUndefinedPlaceholder(VirtualFrame frame) thro
189191
return RubyTypesGen.RUBYTYPES.expectUndefinedPlaceholder(execute(frame));
190192
}
191193

194+
public RubiniusByteArray executeRubiniusByteArray(VirtualFrame frame) throws UnexpectedResultException {
195+
return RubyTypesGen.RUBYTYPES.expectRubiniusByteArray(execute(frame));
196+
}
197+
198+
public RubiniusChannel executeRubiniusChannel(VirtualFrame frame) throws UnexpectedResultException {
199+
return RubyTypesGen.RUBYTYPES.expectRubiniusChannel(execute(frame));
200+
}
201+
192202
public Dispatch.DispatchAction executeDispatchAction(VirtualFrame frame) {
193203
throw new UnsupportedOperationException();
194204
}

core/src/main/java/org/jruby/truffle/nodes/RubyTypes.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import org.jruby.truffle.runtime.core.RubyHash;
2020
import org.jruby.truffle.runtime.core.RubyRange;
2121
import org.jruby.truffle.runtime.core.RubyBasicObject;
22+
import org.jruby.truffle.runtime.rubinius.RubiniusByteArray;
23+
import org.jruby.truffle.runtime.rubinius.RubiniusChannel;
2224

2325
import java.math.BigInteger;
2426

@@ -63,9 +65,12 @@
6365
RubyTime.class, //
6466
RubyTrueClass.class, //
6567
RubyFalseClass.class, //
68+
RubiniusChannel.class, //
69+
RubiniusByteArray.class, //
6670
RubyObject.class, //
6771
RubyBasicObject.class, //
6872
Object[].class})
73+
6974
public class RubyTypes {
7075

7176
@ImplicitCast

core/src/main/java/org/jruby/truffle/nodes/core/CoreMethodNodeManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails
186186
if (methodDetails.getMethodAnnotation().isSplatted()) {
187187
argumentsNodes.add(new ReadAllArgumentsNode(context, sourceSection));
188188
} else {
189-
assert arity.getMaximum() != Arity.NO_MAXIMUM;
189+
if (arity.getMaximum() == Arity.NO_MAXIMUM) {
190+
throw new UnsupportedOperationException("if a core method isn't splatted, you need to specify a maximum");
191+
}
190192

191193
for (int n = 0; n < arity.getMaximum(); n++) {
192194
RubyNode readArgumentNode = new ReadPreArgumentNode(context, sourceSection, n, MissingArgumentBehaviour.UNDEFINED);

core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ public TruffelizedNode(RubyContext context, SourceSection sourceSection) {
957957
super(context, sourceSection);
958958
}
959959

960-
public TruffelizedNode(ThrowNode prev) {
960+
public TruffelizedNode(TruffelizedNode prev) {
961961
super(prev);
962962
}
963963

@@ -968,4 +968,44 @@ public boolean truffelized() {
968968

969969
}
970970

971+
// Rubinius API
972+
@CoreMethod(names = "undefined", isModuleMethod = true, needsSelf = false, maxArgs = 0, visibility = Visibility.PRIVATE)
973+
public abstract static class UndefinedNode extends CoreMethodNode {
974+
975+
public UndefinedNode(RubyContext context, SourceSection sourceSection) {
976+
super(context, sourceSection);
977+
}
978+
979+
public UndefinedNode(UndefinedNode prev) {
980+
super(prev);
981+
}
982+
983+
@Specialization
984+
public UndefinedPlaceholder undefined() {
985+
return UndefinedPlaceholder.INSTANCE;
986+
}
987+
988+
}
989+
990+
// Rubinius API
991+
@CoreMethod(names = "StringValue", isModuleMethod = true, needsSelf = false, minArgs = 1, maxArgs = 1)
992+
public abstract static class StringValueNode extends CoreMethodNode {
993+
@Child
994+
protected DispatchHeadNode argToStringNode;
995+
996+
public StringValueNode(RubyContext context, SourceSection sourceSection) {
997+
super(context, sourceSection);
998+
argToStringNode = new DispatchHeadNode(context);
999+
}
1000+
1001+
public StringValueNode(StringValueNode prev) {
1002+
super(prev);
1003+
argToStringNode = prev.argToStringNode;
1004+
}
1005+
1006+
@Specialization
1007+
public RubyString StringValue(VirtualFrame frame, Object arg) {
1008+
return (RubyString) argToStringNode.call(frame, arg, "to_s", null);
1009+
}
1010+
}
9711011
}

core/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.jruby.truffle.runtime.core.*;
2222
import org.jruby.truffle.runtime.core.RubyArray;
2323
import org.jruby.truffle.runtime.core.RubyRange;
24+
import org.jruby.truffle.runtime.rubinius.RubiniusByteArray;
2425
import org.jruby.util.ByteList;
2526
import org.jruby.util.Pack;
2627

@@ -925,4 +926,21 @@ public RubyArray unpack(RubyString string, RubyString format) {
925926
}
926927

927928
}
929+
930+
// Rubinius API
931+
@CoreMethod(names = "data", maxArgs = 0)
932+
public abstract static class DataNode extends CoreMethodNode {
933+
public DataNode(RubyContext context, SourceSection sourceSection) {
934+
super(context, sourceSection);
935+
}
936+
937+
public DataNode(DataNode prev) {
938+
super(prev);
939+
}
940+
941+
@Specialization
942+
public RubyObject data(RubyString string) {
943+
return new RubiniusByteArray(getContext().getCoreLibrary().getRubiniusLibrary().getByteArrayCLass(), string.getBytes().getUnsafeBytes());
944+
}
945+
}
928946
}

core/src/main/java/org/jruby/truffle/nodes/core/TimeNodes.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public SubNode(SubNode prev) {
3333

3434
@Specialization
3535
public double sub(RubyTime a, RubyTime b) {
36-
return RubyTime.nanosecondsToSecond(a.nanoseconds - b.nanoseconds);
36+
return a.getSeconds() - b.getSeconds();
3737
}
3838

3939
}
@@ -57,6 +57,33 @@ public RubyTime now() {
5757

5858
}
5959

60+
@CoreMethod(names = {"from_array", "time_s_from_array"}, isModuleMethod = true, needsSelf = false, maxArgs = 0)
61+
public abstract static class FromArrayNode extends CoreMethodNode {
62+
63+
public FromArrayNode(RubyContext context, SourceSection sourceSection) {
64+
super(context, sourceSection);
65+
}
66+
67+
public FromArrayNode(FromArrayNode prev) {
68+
super(prev);
69+
}
70+
71+
@CompilerDirectives.SlowPath
72+
@Specialization
73+
public RubyTime fromArray(int second,
74+
int minute,
75+
int hour,
76+
int dayOfMonth,
77+
int month,
78+
int year,
79+
int nanoOfSecond,
80+
boolean isdst,
81+
RubyString zone) {
82+
return RubyTime.fromArray(getContext().getCoreLibrary().getTimeClass(),second, minute, hour, dayOfMonth, month, year, nanoOfSecond, isdst, zone);
83+
}
84+
85+
}
86+
6087
@CoreMethod(names = {"to_s", "inspect"}, maxArgs = 0)
6188
public abstract static class ToSNode extends CoreMethodNode {
6289

core/src/main/java/org/jruby/truffle/nodes/dispatch/DispatchHeadNode.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,28 @@ public class DispatchHeadNode extends Node {
2020

2121
private final RubyContext context;
2222
private final boolean ignoreVisibility;
23+
private final boolean rubiniusPrimitive;
2324
private final Dispatch.MissingBehavior missingBehavior;
2425

2526
@Child protected DispatchNode first;
2627

2728
public DispatchHeadNode(RubyContext context) {
28-
this(context, false, Dispatch.MissingBehavior.CALL_METHOD_MISSING);
29+
this(context, false, false, Dispatch.MissingBehavior.CALL_METHOD_MISSING);
2930
}
3031

3132
public DispatchHeadNode(RubyContext context, Dispatch.MissingBehavior missingBehavior) {
32-
this(context, false, missingBehavior);
33+
this(context, false, false, missingBehavior);
3334
}
3435

3536
public DispatchHeadNode(RubyContext context, boolean ignoreVisibility, Dispatch.MissingBehavior missingBehavior) {
37+
this(context, ignoreVisibility, false, missingBehavior);
38+
}
39+
40+
public DispatchHeadNode(RubyContext context, boolean ignoreVisibility, boolean rubiniusPrimitive, Dispatch.MissingBehavior missingBehavior) {
3641
this.context = context;
3742
this.ignoreVisibility = ignoreVisibility;
3843
this.missingBehavior = missingBehavior;
44+
this.rubiniusPrimitive = rubiniusPrimitive;
3945
first = new UnresolvedDispatchNode(context, ignoreVisibility, missingBehavior);
4046
}
4147

@@ -150,6 +156,17 @@ public Object dispatch(
150156
Object blockObject,
151157
Object argumentsObjects,
152158
Dispatch.DispatchAction dispatchAction) {
159+
if (rubiniusPrimitive) {
160+
return first.executeDispatch(
161+
frame,
162+
methodReceiverObject,
163+
callingSelf,
164+
callingSelf,
165+
methodName,
166+
blockObject,
167+
RubyArguments.concatUserArguments(argumentsObjects, frame.getArguments()),
168+
dispatchAction);
169+
}
153170
return first.executeDispatch(
154171
frame,
155172
methodReceiverObject,

0 commit comments

Comments
 (0)