Skip to content

Commit dafa4cc

Browse files
committed
[Truffle] Truffle#graal? #substate? and #version
1 parent 8ddcf61 commit dafa4cc

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

truffle/src/main/java/org/jruby/truffle/TruffleBridgeImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public void init() {
101101
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, MethodNodesFactory.getFactories());
102102
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, UnboundMethodNodesFactory.getFactories());
103103
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, ByteArrayNodesFactory.getFactories());
104+
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, TruffleNodesFactory.getFactories());
104105

105106
// Give the core library manager a chance to tweak some of those methods
106107

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
3+
* code is released under a tri EPL/GPL/LGPL license. You can use it,
4+
* redistribute it and/or modify it under the terms of the:
5+
*
6+
* Eclipse Public License version 1.0
7+
* GNU General Public License version 2
8+
* GNU Lesser General Public License version 2.1
9+
*/
10+
package org.jruby.truffle.nodes.core;
11+
12+
import com.oracle.truffle.api.Truffle;
13+
import com.oracle.truffle.api.dsl.Specialization;
14+
import com.oracle.truffle.api.source.SourceSection;
15+
import org.jruby.truffle.runtime.RubyContext;
16+
import org.jruby.truffle.runtime.core.RubyString;
17+
18+
@CoreClass(name = "Truffle")
19+
public abstract class TruffleNodes {
20+
21+
@CoreMethod(names = "graal?", onSingleton = true)
22+
public abstract static class GraalNode extends CoreMethodNode {
23+
24+
public GraalNode(RubyContext context, SourceSection sourceSection) {
25+
super(context, sourceSection);
26+
}
27+
28+
public GraalNode(GraalNode prev) {
29+
super(prev);
30+
}
31+
32+
@Specialization
33+
public boolean graal() {
34+
return Truffle.getRuntime().getName().toLowerCase().contains("graal");
35+
}
36+
37+
}
38+
39+
@CoreMethod(names = "substrate?", onSingleton = true)
40+
public abstract static class SubstrateNode extends CoreMethodNode {
41+
42+
public SubstrateNode(RubyContext context, SourceSection sourceSection) {
43+
super(context, sourceSection);
44+
}
45+
46+
public SubstrateNode(SubstrateNode prev) {
47+
super(prev);
48+
}
49+
50+
@Specialization
51+
public boolean substrate() {
52+
return false;
53+
}
54+
55+
}
56+
57+
@CoreMethod(names = "version", onSingleton = true)
58+
public abstract static class VersionNode extends CoreMethodNode {
59+
60+
public VersionNode(RubyContext context, SourceSection sourceSection) {
61+
super(context, sourceSection);
62+
}
63+
64+
public VersionNode(VersionNode prev) {
65+
super(prev);
66+
}
67+
68+
@Specialization
69+
public RubyString version() {
70+
return getContext().makeString(System.getProperty("graal.version", "unknown"));
71+
}
72+
73+
}
74+
75+
}

0 commit comments

Comments
 (0)