|
15 | 15 |
|
16 | 16 | import com.oracle.truffle.api.CompilerDirectives;
|
17 | 17 | import com.oracle.truffle.api.instrumentation.AllocationReporter;
|
| 18 | +import com.oracle.truffle.api.object.Shape; |
18 | 19 | import org.graalvm.options.OptionDescriptors;
|
| 20 | +import org.truffleruby.core.RubyHandle; |
| 21 | +import org.truffleruby.core.array.RubyArray; |
| 22 | +import org.truffleruby.core.basicobject.RubyBasicObject; |
| 23 | +import org.truffleruby.core.binding.RubyBinding; |
| 24 | +import org.truffleruby.core.encoding.RubyEncoding; |
| 25 | +import org.truffleruby.core.encoding.RubyEncodingConverter; |
| 26 | +import org.truffleruby.core.exception.RubyException; |
| 27 | +import org.truffleruby.core.exception.RubyNameError; |
| 28 | +import org.truffleruby.core.exception.RubyNoMethodError; |
| 29 | +import org.truffleruby.core.exception.RubySystemCallError; |
| 30 | +import org.truffleruby.core.fiber.RubyFiber; |
| 31 | +import org.truffleruby.core.hash.RubyHash; |
19 | 32 | import org.truffleruby.core.kernel.TraceManager;
|
| 33 | +import org.truffleruby.core.klass.RubyClass; |
| 34 | +import org.truffleruby.core.method.RubyMethod; |
| 35 | +import org.truffleruby.core.method.RubyUnboundMethod; |
| 36 | +import org.truffleruby.core.module.RubyModule; |
| 37 | +import org.truffleruby.core.mutex.RubyConditionVariable; |
| 38 | +import org.truffleruby.core.mutex.RubyMutex; |
20 | 39 | import org.truffleruby.core.objectspace.ObjectSpaceManager;
|
| 40 | +import org.truffleruby.core.objectspace.RubyWeakMap; |
| 41 | +import org.truffleruby.core.proc.RubyProc; |
| 42 | +import org.truffleruby.core.queue.RubyQueue; |
| 43 | +import org.truffleruby.core.queue.RubySizedQueue; |
| 44 | +import org.truffleruby.core.range.RubyIntRange; |
| 45 | +import org.truffleruby.core.range.RubyLongRange; |
| 46 | +import org.truffleruby.core.range.RubyObjectRange; |
| 47 | +import org.truffleruby.core.regexp.RubyMatchData; |
| 48 | +import org.truffleruby.core.regexp.RubyRegexp; |
21 | 49 | import org.truffleruby.core.rope.Rope;
|
22 | 50 | import org.truffleruby.core.rope.RopeCache;
|
23 | 51 | import org.truffleruby.core.string.CoreStrings;
|
| 52 | +import org.truffleruby.core.string.RubyString; |
24 | 53 | import org.truffleruby.core.string.StringUtils;
|
| 54 | +import org.truffleruby.core.support.RubyByteArray; |
| 55 | +import org.truffleruby.core.support.RubyIO; |
| 56 | +import org.truffleruby.core.support.RubyRandomizer; |
25 | 57 | import org.truffleruby.core.symbol.CoreSymbols;
|
26 | 58 | import org.truffleruby.core.symbol.RubySymbol;
|
27 | 59 | import org.truffleruby.core.symbol.SymbolTable;
|
| 60 | +import org.truffleruby.core.thread.RubyBacktraceLocation; |
28 | 61 | import org.truffleruby.core.thread.RubyThread;
|
| 62 | +import org.truffleruby.core.time.RubyTime; |
| 63 | +import org.truffleruby.core.tracepoint.RubyTracePoint; |
29 | 64 | import org.truffleruby.debug.GlobalScope;
|
30 | 65 | import org.truffleruby.debug.LexicalScope;
|
| 66 | +import org.truffleruby.extra.RubyAtomicReference; |
| 67 | +import org.truffleruby.extra.ffi.RubyPointer; |
31 | 68 | import org.truffleruby.language.NotProvided;
|
| 69 | +import org.truffleruby.language.RubyDynamicObject; |
32 | 70 | import org.truffleruby.language.RubyEvalInteractiveRootNode;
|
33 | 71 | import org.truffleruby.language.RubyInlineParsingRequestNode;
|
34 | 72 | import org.truffleruby.language.RubyParsingRequestNode;
|
| 73 | +import org.truffleruby.language.objects.RubyObjectType; |
35 | 74 | import org.truffleruby.platform.Platform;
|
36 | 75 | import org.truffleruby.shared.Metrics;
|
37 | 76 | import org.truffleruby.shared.TruffleRuby;
|
|
53 | 92 | import com.oracle.truffle.api.nodes.ExecutableNode;
|
54 | 93 | import com.oracle.truffle.api.nodes.Node;
|
55 | 94 | import com.oracle.truffle.api.utilities.CyclicAssumption;
|
| 95 | +import org.truffleruby.stdlib.bigdecimal.RubyBigDecimal; |
| 96 | +import org.truffleruby.stdlib.digest.RubyDigest; |
56 | 97 |
|
57 | 98 | @TruffleLanguage.Registration(
|
58 | 99 | name = "Ruby",
|
@@ -103,6 +144,54 @@ public class RubyLanguage extends TruffleLanguage<RubyContext> {
|
103 | 144 |
|
104 | 145 | private final AtomicLong nextObjectID = new AtomicLong(ObjectSpaceManager.INITIAL_LANGUAGE_OBJECT_ID);
|
105 | 146 |
|
| 147 | + private static final RubyObjectType objectType = new RubyObjectType(); |
| 148 | + |
| 149 | + public final Shape basicObjectShape = createShape(RubyBasicObject.class); |
| 150 | + public final Shape moduleShape = createShape(RubyModule.class); |
| 151 | + public final Shape classShape = createShape(RubyClass.class); |
| 152 | + |
| 153 | + // TODO (eregon, 25 Sep 2020): These Shapes should ideally be stored in the language instance, |
| 154 | + // so different Engines/RubyLanguage instances can have different type profiles. |
| 155 | + // However that requires passing the language instance around a lot which is inconvenient |
| 156 | + // and does not seem worth it currently. Also these builtin types are rather unlikely to have |
| 157 | + // instance variables. |
| 158 | + public static final Shape arrayShape = createShape(RubyArray.class); |
| 159 | + public static final Shape atomicReferenceShape = createShape(RubyAtomicReference.class); |
| 160 | + public static final Shape bigDecimalShape = createShape(RubyBigDecimal.class); |
| 161 | + public static final Shape bindingShape = createShape(RubyBinding.class); |
| 162 | + public static final Shape byteArrayShape = createShape(RubyByteArray.class); |
| 163 | + public static final Shape conditionVariableShape = createShape(RubyConditionVariable.class); |
| 164 | + public static final Shape digestShape = createShape(RubyDigest.class); |
| 165 | + public static final Shape encodingConverterShape = createShape(RubyEncodingConverter.class); |
| 166 | + public static final Shape encodingShape = createShape(RubyEncoding.class); |
| 167 | + public static final Shape exceptionShape = createShape(RubyException.class); |
| 168 | + public static final Shape fiberShape = createShape(RubyFiber.class); |
| 169 | + public static final Shape handleShape = createShape(RubyHandle.class); |
| 170 | + public static final Shape hashShape = createShape(RubyHash.class); |
| 171 | + public static final Shape intRangeShape = createShape(RubyIntRange.class); |
| 172 | + public static final Shape ioShape = createShape(RubyIO.class); |
| 173 | + public static final Shape longRangeShape = createShape(RubyLongRange.class); |
| 174 | + public static final Shape matchDataShape = createShape(RubyMatchData.class); |
| 175 | + public static final Shape methodShape = createShape(RubyMethod.class); |
| 176 | + public static final Shape mutexShape = createShape(RubyMutex.class); |
| 177 | + public static final Shape nameErrorShape = createShape(RubyNameError.class); |
| 178 | + public static final Shape noMethodErrorShape = createShape(RubyNoMethodError.class); |
| 179 | + public static final Shape objectRangeShape = createShape(RubyObjectRange.class); |
| 180 | + public static final Shape procShape = createShape(RubyProc.class); |
| 181 | + public static final Shape queueShape = createShape(RubyQueue.class); |
| 182 | + public static final Shape randomizerShape = createShape(RubyRandomizer.class); |
| 183 | + public static final Shape regexpShape = createShape(RubyRegexp.class); |
| 184 | + public static final Shape sizedQueueShape = createShape(RubySizedQueue.class); |
| 185 | + public static final Shape stringShape = createShape(RubyString.class); |
| 186 | + public static final Shape systemCallErrorShape = createShape(RubySystemCallError.class); |
| 187 | + public static final Shape threadBacktraceLocationShape = createShape(RubyBacktraceLocation.class); |
| 188 | + public static final Shape threadShape = createShape(RubyThread.class); |
| 189 | + public static final Shape timeShape = createShape(RubyTime.class); |
| 190 | + public static final Shape tracePointShape = createShape(RubyTracePoint.class); |
| 191 | + public static final Shape truffleFFIPointerShape = createShape(RubyPointer.class); |
| 192 | + public static final Shape unboundMethodShape = createShape(RubyUnboundMethod.class); |
| 193 | + public static final Shape weakMapShape = createShape(RubyWeakMap.class); |
| 194 | + |
106 | 195 | public RubyLanguage() {
|
107 | 196 | coreStrings = new CoreStrings(this);
|
108 | 197 | coreSymbols = new CoreSymbols();
|
@@ -197,6 +286,10 @@ public static RubyContext getCurrentContext() {
|
197 | 286 | return getCurrentContext(RubyLanguage.class);
|
198 | 287 | }
|
199 | 288 |
|
| 289 | + public static RubyLanguage getCurrentLanguage() { |
| 290 | + return getCurrentLanguage(RubyLanguage.class); |
| 291 | + } |
| 292 | + |
200 | 293 | @Override
|
201 | 294 | protected RootCallTarget parse(ParsingRequest request) {
|
202 | 295 | if (request.getSource().isInteractive()) {
|
@@ -314,4 +407,13 @@ public long getNextObjectID() {
|
314 | 407 | return id;
|
315 | 408 | }
|
316 | 409 |
|
| 410 | + private static Shape createShape(Class<? extends RubyDynamicObject> layoutClass) { |
| 411 | + return Shape |
| 412 | + .newBuilder() |
| 413 | + .allowImplicitCastIntToLong(true) |
| 414 | + .layout(layoutClass) |
| 415 | + .dynamicType(RubyLanguage.objectType) |
| 416 | + .build(); |
| 417 | + } |
| 418 | + |
317 | 419 | }
|
0 commit comments