|
1 | 1 | /* |
2 | | - * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * The Universal Permissive License (UPL), Version 1.0 |
|
48 | 48 | import java.util.NoSuchElementException; |
49 | 49 |
|
50 | 50 | import com.oracle.truffle.api.CallTarget; |
| 51 | +import com.oracle.truffle.api.CompilerDirectives; |
51 | 52 | import com.oracle.truffle.api.RootCallTarget; |
52 | 53 | import com.oracle.truffle.api.Scope; |
53 | 54 | import com.oracle.truffle.api.Truffle; |
|
58 | 59 | import com.oracle.truffle.api.frame.Frame; |
59 | 60 | import com.oracle.truffle.api.instrumentation.ProvidedTags; |
60 | 61 | import com.oracle.truffle.api.instrumentation.StandardTags; |
| 62 | +import com.oracle.truffle.api.interop.InteropLibrary; |
61 | 63 | import com.oracle.truffle.api.interop.TruffleObject; |
| 64 | +import com.oracle.truffle.api.interop.UnsupportedMessageException; |
62 | 65 | import com.oracle.truffle.api.nodes.Node; |
63 | 66 | import com.oracle.truffle.api.nodes.RootNode; |
64 | 67 | import com.oracle.truffle.api.object.DynamicObject; |
|
72 | 75 | import com.oracle.truffle.sl.builtins.SLStackTraceBuiltin; |
73 | 76 | import com.oracle.truffle.sl.nodes.SLEvalRootNode; |
74 | 77 | import com.oracle.truffle.sl.nodes.SLTypes; |
75 | | -import com.oracle.truffle.sl.nodes.access.SLReadPropertyCacheNode; |
76 | | -import com.oracle.truffle.sl.nodes.access.SLReadPropertyNode; |
77 | | -import com.oracle.truffle.sl.nodes.access.SLWritePropertyCacheNode; |
78 | | -import com.oracle.truffle.sl.nodes.access.SLWritePropertyNode; |
79 | | -import com.oracle.truffle.sl.nodes.call.SLDispatchNode; |
80 | | -import com.oracle.truffle.sl.nodes.call.SLInvokeNode; |
81 | 78 | import com.oracle.truffle.sl.nodes.controlflow.SLBlockNode; |
82 | 79 | import com.oracle.truffle.sl.nodes.controlflow.SLBreakNode; |
83 | 80 | import com.oracle.truffle.sl.nodes.controlflow.SLContinueNode; |
|
90 | 87 | import com.oracle.truffle.sl.nodes.expression.SLDivNode; |
91 | 88 | import com.oracle.truffle.sl.nodes.expression.SLEqualNode; |
92 | 89 | import com.oracle.truffle.sl.nodes.expression.SLFunctionLiteralNode; |
| 90 | +import com.oracle.truffle.sl.nodes.expression.SLInvokeNode; |
93 | 91 | import com.oracle.truffle.sl.nodes.expression.SLLessOrEqualNode; |
94 | 92 | import com.oracle.truffle.sl.nodes.expression.SLLessThanNode; |
95 | 93 | import com.oracle.truffle.sl.nodes.expression.SLLogicalAndNode; |
96 | 94 | import com.oracle.truffle.sl.nodes.expression.SLLogicalOrNode; |
97 | 95 | import com.oracle.truffle.sl.nodes.expression.SLMulNode; |
| 96 | +import com.oracle.truffle.sl.nodes.expression.SLReadPropertyNode; |
98 | 97 | import com.oracle.truffle.sl.nodes.expression.SLStringLiteralNode; |
99 | 98 | import com.oracle.truffle.sl.nodes.expression.SLSubNode; |
| 99 | +import com.oracle.truffle.sl.nodes.expression.SLWritePropertyNode; |
100 | 100 | import com.oracle.truffle.sl.nodes.local.SLLexicalScope; |
101 | 101 | import com.oracle.truffle.sl.nodes.local.SLReadLocalVariableNode; |
102 | 102 | import com.oracle.truffle.sl.nodes.local.SLWriteLocalVariableNode; |
|
190 | 190 | * variables. |
191 | 191 | * </ul> |
192 | 192 | */ |
193 | | -@TruffleLanguage.Registration(id = SLLanguage.ID, name = "SL", defaultMimeType = SLLanguage.MIME_TYPE, characterMimeTypes = SLLanguage.MIME_TYPE, contextPolicy = ContextPolicy.SHARED) |
| 193 | +@TruffleLanguage.Registration(id = SLLanguage.ID, name = "SL", defaultMimeType = SLLanguage.MIME_TYPE, characterMimeTypes = SLLanguage.MIME_TYPE, contextPolicy = ContextPolicy.SHARED, fileTypeDetectors = SLFileDetector.class) |
194 | 194 | @ProvidedTags({StandardTags.CallTag.class, StandardTags.StatementTag.class, StandardTags.RootTag.class, StandardTags.ExpressionTag.class, DebuggerTags.AlwaysHalt.class}) |
195 | 195 | public final class SLLanguage extends TruffleLanguage<SLContext> { |
196 | 196 | public static volatile int counter; |
@@ -267,57 +267,91 @@ protected Object findExportedSymbol(SLContext context, String globalName, boolea |
267 | 267 |
|
268 | 268 | @Override |
269 | 269 | protected boolean isVisible(SLContext context, Object value) { |
270 | | - return value != SLNull.SINGLETON; |
| 270 | + return !InteropLibrary.getFactory().getUncached(value).isNull(value); |
271 | 271 | } |
272 | 272 |
|
273 | 273 | @Override |
274 | 274 | protected boolean isObjectOfLanguage(Object object) { |
275 | 275 | if (!(object instanceof TruffleObject)) { |
276 | 276 | return false; |
| 277 | + } else if (object instanceof SLBigNumber || object instanceof SLFunction || object instanceof SLNull) { |
| 278 | + return true; |
| 279 | + } else if (SLContext.isSLObject(object)) { |
| 280 | + return true; |
| 281 | + } else { |
| 282 | + return false; |
277 | 283 | } |
278 | | - TruffleObject truffleObject = (TruffleObject) object; |
279 | | - return truffleObject instanceof SLFunction || truffleObject instanceof SLBigNumber || SLContext.isSLObject(truffleObject); |
280 | 284 | } |
281 | 285 |
|
282 | 286 | @Override |
283 | 287 | protected String toString(SLContext context, Object value) { |
284 | | - if (value == SLNull.SINGLETON) { |
285 | | - return "NULL"; |
286 | | - } |
287 | | - if (value instanceof SLBigNumber) { |
288 | | - return super.toString(context, ((SLBigNumber) value).getValue()); |
289 | | - } |
290 | | - if (value instanceof Long) { |
291 | | - return Long.toString((Long) value); |
| 288 | + return toString(value); |
| 289 | + } |
| 290 | + |
| 291 | + public static String toString(Object value) { |
| 292 | + try { |
| 293 | + if (value == null) { |
| 294 | + return "ANY"; |
| 295 | + } |
| 296 | + InteropLibrary interop = InteropLibrary.getFactory().getUncached(value); |
| 297 | + if (interop.fitsInLong(value)) { |
| 298 | + return Long.toString(interop.asLong(value)); |
| 299 | + } else if (interop.isBoolean(value)) { |
| 300 | + return Boolean.toString(interop.asBoolean(value)); |
| 301 | + } else if (interop.isString(value)) { |
| 302 | + return interop.asString(value); |
| 303 | + } else if (interop.isNull(value)) { |
| 304 | + return "NULL"; |
| 305 | + } else if (interop.isExecutable(value)) { |
| 306 | + if (value instanceof SLFunction) { |
| 307 | + return ((SLFunction) value).getName(); |
| 308 | + } else { |
| 309 | + return "Function"; |
| 310 | + } |
| 311 | + } else if (interop.hasMembers(value)) { |
| 312 | + return "Object"; |
| 313 | + } else if (value instanceof SLBigNumber) { |
| 314 | + return value.toString(); |
| 315 | + } else { |
| 316 | + return "Unsupported"; |
| 317 | + } |
| 318 | + } catch (UnsupportedMessageException e) { |
| 319 | + CompilerDirectives.transferToInterpreter(); |
| 320 | + throw new AssertionError(); |
292 | 321 | } |
293 | | - return super.toString(context, value); |
294 | 322 | } |
295 | 323 |
|
296 | 324 | @Override |
297 | 325 | protected Object findMetaObject(SLContext context, Object value) { |
298 | | - if (value instanceof Number || value instanceof SLBigNumber) { |
299 | | - return "Number"; |
| 326 | + return getMetaObject(value); |
| 327 | + } |
| 328 | + |
| 329 | + public static String getMetaObject(Object value) { |
| 330 | + if (value == null) { |
| 331 | + return "ANY"; |
300 | 332 | } |
301 | | - if (value instanceof Boolean) { |
| 333 | + InteropLibrary interop = InteropLibrary.getFactory().getUncached(value); |
| 334 | + if (interop.isNumber(value) || value instanceof SLBigNumber) { |
| 335 | + return "Number"; |
| 336 | + } else if (interop.isBoolean(value)) { |
302 | 337 | return "Boolean"; |
303 | | - } |
304 | | - if (value instanceof String) { |
| 338 | + } else if (interop.isString(value)) { |
305 | 339 | return "String"; |
306 | | - } |
307 | | - if (value == SLNull.SINGLETON) { |
308 | | - return "Null"; |
309 | | - } |
310 | | - if (value instanceof SLFunction) { |
| 340 | + } else if (interop.isNull(value)) { |
| 341 | + return "NULL"; |
| 342 | + } else if (interop.isExecutable(value)) { |
311 | 343 | return "Function"; |
| 344 | + } else if (interop.hasMembers(value)) { |
| 345 | + return "Object"; |
| 346 | + } else { |
| 347 | + return "Unsupported"; |
312 | 348 | } |
313 | | - return "Object"; |
314 | 349 | } |
315 | 350 |
|
316 | 351 | @Override |
317 | 352 | protected SourceSection findSourceLocation(SLContext context, Object value) { |
318 | 353 | if (value instanceof SLFunction) { |
319 | | - SLFunction f = (SLFunction) value; |
320 | | - return f.getCallTarget().getRootNode().getSourceSection(); |
| 354 | + return ((SLFunction) value).getDeclaredLocation(); |
321 | 355 | } |
322 | 356 | return null; |
323 | 357 | } |
|
0 commit comments