18
18
19
19
import com .oracle .truffle .api .dsl .CachedContext ;
20
20
import com .oracle .truffle .api .frame .VirtualFrame ;
21
+ import com .oracle .truffle .api .interop .ExceptionType ;
21
22
import com .oracle .truffle .api .interop .NodeLibrary ;
22
23
import org .jcodings .specific .UTF8Encoding ;
23
24
import org .truffleruby .RubyContext ;
@@ -282,6 +283,160 @@ protected boolean isPolyglotBindingsAccessAllowed() {
282
283
}
283
284
// endregion
284
285
286
+ // region Exception
287
+ @ CoreMethod (names = "exception?" , onSingleton = true , required = 1 )
288
+ public abstract static class IsExceptionNode extends InteropCoreMethodArrayArgumentsNode {
289
+
290
+ @ Specialization (limit = "getCacheLimit()" )
291
+ protected boolean isException (Object receiver ,
292
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ) {
293
+ return receivers .isException (receiver );
294
+ }
295
+ }
296
+
297
+ @ CoreMethod (names = "has_exception_cause?" , onSingleton = true , required = 1 )
298
+ public abstract static class HasExceptionCauseNode extends InteropCoreMethodArrayArgumentsNode {
299
+
300
+ @ Specialization (limit = "getCacheLimit()" )
301
+ protected boolean hasExceptionCause (Object receiver ,
302
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ) {
303
+ return receivers .hasExceptionCause (receiver );
304
+ }
305
+ }
306
+
307
+ @ CoreMethod (names = "exception_cause" , onSingleton = true , required = 1 )
308
+ public abstract static class ExceptionCauseNode extends InteropCoreMethodArrayArgumentsNode {
309
+
310
+ @ Specialization (limit = "getCacheLimit()" )
311
+ protected Object getExceptionCause (Object receiver ,
312
+ @ Cached TranslateInteropExceptionNode translateInteropException ,
313
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ) {
314
+ try {
315
+ return receivers .getExceptionCause (receiver );
316
+ } catch (UnsupportedMessageException e ) {
317
+ throw translateInteropException .execute (e );
318
+ }
319
+ }
320
+ }
321
+
322
+ @ CoreMethod (names = "exception_exit_status" , onSingleton = true , required = 1 )
323
+ public abstract static class ExceptionExitStatusSourceNode extends InteropCoreMethodArrayArgumentsNode {
324
+
325
+ @ Specialization (limit = "getCacheLimit()" )
326
+ protected int getExceptionExitStatus (Object receiver ,
327
+ @ Cached TranslateInteropExceptionNode translateInteropException ,
328
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ) {
329
+ try {
330
+ return receivers .getExceptionExitStatus (receiver );
331
+ } catch (UnsupportedMessageException e ) {
332
+ throw translateInteropException .execute (e );
333
+ }
334
+ }
335
+ }
336
+
337
+ @ CoreMethod (names = "exception_incomplete_source?" , onSingleton = true , required = 1 )
338
+ public abstract static class IsExceptionIncompleteSourceNode extends InteropCoreMethodArrayArgumentsNode {
339
+
340
+ @ Specialization (limit = "getCacheLimit()" )
341
+ protected boolean isExceptionIncompleteSource (Object receiver ,
342
+ @ Cached TranslateInteropExceptionNode translateInteropException ,
343
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ) {
344
+ try {
345
+ return receivers .isExceptionIncompleteSource (receiver );
346
+ } catch (UnsupportedMessageException e ) {
347
+ throw translateInteropException .execute (e );
348
+ }
349
+ }
350
+ }
351
+
352
+ @ CoreMethod (names = "has_exception_message?" , onSingleton = true , required = 1 )
353
+ public abstract static class HasExceptionMessageNode extends InteropCoreMethodArrayArgumentsNode {
354
+
355
+ @ Specialization (limit = "getCacheLimit()" )
356
+ protected boolean hasExceptionMessage (Object receiver ,
357
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ) {
358
+ return receivers .hasExceptionMessage (receiver );
359
+ }
360
+ }
361
+
362
+ @ CoreMethod (names = "exception_message" , onSingleton = true , required = 1 )
363
+ public abstract static class ExceptionMessageNode extends InteropCoreMethodArrayArgumentsNode {
364
+
365
+ @ Specialization (limit = "getCacheLimit()" )
366
+ protected RubyString getExceptionMessage (Object receiver ,
367
+ @ Cached FromJavaStringNode fromJavaStringNode ,
368
+ @ Cached TranslateInteropExceptionNode translateInteropException ,
369
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ,
370
+ @ CachedLibrary (limit = "1" ) InteropLibrary asStrings ) {
371
+ final String string ;
372
+ try {
373
+ final Object exceptionMessage = receivers .getExceptionMessage (receiver );
374
+ string = asStrings .asString (exceptionMessage );
375
+ } catch (UnsupportedMessageException e ) {
376
+ throw translateInteropException .execute (e );
377
+ }
378
+ return fromJavaStringNode .executeFromJavaString (string );
379
+ }
380
+ }
381
+
382
+ @ CoreMethod (names = "has_exception_stack_trace?" , onSingleton = true , required = 1 )
383
+ public abstract static class HasExceptionStackTraceNode extends InteropCoreMethodArrayArgumentsNode {
384
+
385
+ @ Specialization (limit = "getCacheLimit()" )
386
+ protected boolean hasExceptionStackTrace (Object receiver ,
387
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ) {
388
+ return receivers .hasExceptionStackTrace (receiver );
389
+ }
390
+ }
391
+
392
+ @ CoreMethod (names = "exception_stack_trace" , onSingleton = true , required = 1 )
393
+ public abstract static class ExceptionStackTraceNode extends InteropCoreMethodArrayArgumentsNode {
394
+
395
+ @ Specialization (limit = "getCacheLimit()" )
396
+ protected Object getExceptionStackTrace (Object receiver ,
397
+ @ Cached TranslateInteropExceptionNode translateInteropException ,
398
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ) {
399
+ try {
400
+ return receivers .getExceptionStackTrace (receiver );
401
+ } catch (UnsupportedMessageException e ) {
402
+ throw translateInteropException .execute (e );
403
+ }
404
+ }
405
+ }
406
+
407
+ @ CoreMethod (names = "exception_type" , onSingleton = true , required = 1 )
408
+ public abstract static class ExceptionTypeNode extends InteropCoreMethodArrayArgumentsNode {
409
+
410
+ @ Specialization (limit = "getCacheLimit()" )
411
+ protected RubySymbol getExceptionType (Object receiver ,
412
+ @ Cached TranslateInteropExceptionNode translateInteropException ,
413
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ) {
414
+ try {
415
+ final ExceptionType exceptionType = receivers .getExceptionType (receiver );
416
+ return getLanguage ().getSymbol (exceptionType .name ());
417
+ } catch (UnsupportedMessageException e ) {
418
+ throw translateInteropException .execute (e );
419
+ }
420
+ }
421
+ }
422
+
423
+ @ CoreMethod (names = "throw_exception" , onSingleton = true , required = 1 )
424
+ public abstract static class ThrowExceptionNode extends InteropCoreMethodArrayArgumentsNode {
425
+
426
+ @ Specialization (limit = "getCacheLimit()" )
427
+ protected Object throwException (Object receiver ,
428
+ @ Cached TranslateInteropExceptionNode translateInteropException ,
429
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ) {
430
+ try {
431
+ throw receivers .throwException (receiver );
432
+ } catch (UnsupportedMessageException e ) {
433
+ throw translateInteropException .execute (e );
434
+ }
435
+ }
436
+ }
437
+
438
+ // endregion
439
+
285
440
// region Executable
286
441
@ CoreMethod (names = "executable?" , onSingleton = true , required = 1 )
287
442
public abstract static class IsExecutableNode extends InteropCoreMethodArrayArgumentsNode {
@@ -293,6 +448,37 @@ protected boolean isExecutable(Object receiver,
293
448
}
294
449
}
295
450
451
+
452
+ @ CoreMethod (names = "has_executable_name?" , onSingleton = true , required = 1 )
453
+ public abstract static class HasExecutableNameNode extends InteropCoreMethodArrayArgumentsNode {
454
+
455
+ @ Specialization (limit = "getCacheLimit()" )
456
+ protected boolean hasExecutableName (Object receiver ,
457
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ) {
458
+ return receivers .hasExecutableName (receiver );
459
+ }
460
+ }
461
+
462
+ @ CoreMethod (names = "executable_name" , onSingleton = true , required = 1 )
463
+ public abstract static class ExecutableNameNode extends InteropCoreMethodArrayArgumentsNode {
464
+
465
+ @ Specialization (limit = "getCacheLimit()" )
466
+ protected RubyString getExecutableName (Object receiver ,
467
+ @ Cached FromJavaStringNode fromJavaStringNode ,
468
+ @ Cached TranslateInteropExceptionNode translateInteropException ,
469
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ,
470
+ @ CachedLibrary (limit = "1" ) InteropLibrary asStrings ) {
471
+ final String string ;
472
+ try {
473
+ final Object executableName = receivers .getExecutableName (receiver );
474
+ string = asStrings .asString (executableName );
475
+ } catch (UnsupportedMessageException e ) {
476
+ throw translateInteropException .execute (e );
477
+ }
478
+ return fromJavaStringNode .executeFromJavaString (string );
479
+ }
480
+ }
481
+
296
482
@ GenerateUncached
297
483
@ GenerateNodeFactory
298
484
@ NodeChild (value = "arguments" , type = RubyNode [].class )
@@ -602,6 +788,32 @@ protected boolean isArrayElementExisting(Object receiver, long index,
602
788
}
603
789
// endregion
604
790
791
+ // region SourceLocation
792
+ @ CoreMethod (names = "has_source_location?" , onSingleton = true , required = 1 )
793
+ public abstract static class HasSourceLocationNode extends InteropCoreMethodArrayArgumentsNode {
794
+ @ Specialization (limit = "getCacheLimit()" )
795
+ protected boolean hasSourceLocation (Object receiver ,
796
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ) {
797
+ return receivers .hasSourceLocation (receiver );
798
+ }
799
+ }
800
+
801
+ @ CoreMethod (names = "source_location" , onSingleton = true , required = 1 )
802
+ public abstract static class GetSourceLocationNode extends InteropCoreMethodArrayArgumentsNode {
803
+ @ Specialization (limit = "getCacheLimit()" )
804
+ protected Object getSourceLocation (Object receiver ,
805
+ @ CachedContext (RubyLanguage .class ) RubyContext context ,
806
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ,
807
+ @ Cached TranslateInteropExceptionNode translateInteropException ) {
808
+ try {
809
+ return context .getEnv ().asGuestValue (receivers .getSourceLocation (receiver ));
810
+ } catch (UnsupportedMessageException e ) {
811
+ throw translateInteropException .execute (e );
812
+ }
813
+ }
814
+ }
815
+ // endregion
816
+
605
817
// region String
606
818
@ CoreMethod (names = "string?" , onSingleton = true , required = 1 )
607
819
public abstract static class IsStringNode extends InteropCoreMethodArrayArgumentsNode {
@@ -705,6 +917,128 @@ protected boolean asBoolean(Object receiver,
705
917
}
706
918
// endregion
707
919
920
+ // region DateTime
921
+ @ CoreMethod (names = "date?" , onSingleton = true , required = 1 )
922
+ public abstract static class IsDateNode extends InteropCoreMethodArrayArgumentsNode {
923
+ @ Specialization (limit = "getCacheLimit()" )
924
+ protected boolean isDate (Object receiver ,
925
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ) {
926
+ return receivers .isDate (receiver );
927
+ }
928
+ }
929
+
930
+ @ CoreMethod (names = "as_date" , onSingleton = true , required = 1 )
931
+ public abstract static class AsDateNode extends InteropCoreMethodArrayArgumentsNode {
932
+ @ Specialization (limit = "getCacheLimit()" )
933
+ protected Object asDate (Object receiver ,
934
+ @ CachedContext (RubyLanguage .class ) RubyContext context ,
935
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ,
936
+ @ Cached TranslateInteropExceptionNode translateInteropException ) {
937
+ try {
938
+ return context .getEnv ().asGuestValue (receivers .asDate (receiver ));
939
+ } catch (UnsupportedMessageException e ) {
940
+ throw translateInteropException .execute (e );
941
+ }
942
+ }
943
+ }
944
+
945
+ @ CoreMethod (names = "duration?" , onSingleton = true , required = 1 )
946
+ public abstract static class IsDurationNode extends InteropCoreMethodArrayArgumentsNode {
947
+ @ Specialization (limit = "getCacheLimit()" )
948
+ protected boolean isDuration (Object receiver ,
949
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ) {
950
+ return receivers .isDuration (receiver );
951
+ }
952
+ }
953
+
954
+ @ CoreMethod (names = "as_duration" , onSingleton = true , required = 1 )
955
+ public abstract static class AsDurationNode extends InteropCoreMethodArrayArgumentsNode {
956
+ @ Specialization (limit = "getCacheLimit()" )
957
+ protected Object asDuration (Object receiver ,
958
+ @ CachedContext (RubyLanguage .class ) RubyContext context ,
959
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ,
960
+ @ Cached TranslateInteropExceptionNode translateInteropException ) {
961
+ try {
962
+ return context .getEnv ().asGuestValue (receivers .asDuration (receiver ));
963
+ } catch (UnsupportedMessageException e ) {
964
+ throw translateInteropException .execute (e );
965
+ }
966
+ }
967
+ }
968
+
969
+ @ CoreMethod (names = "instant?" , onSingleton = true , required = 1 )
970
+ public abstract static class IsInstantNode extends InteropCoreMethodArrayArgumentsNode {
971
+ @ Specialization (limit = "getCacheLimit()" )
972
+ protected boolean isInstant (Object receiver ,
973
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ) {
974
+ return receivers .isInstant (receiver );
975
+ }
976
+ }
977
+
978
+ @ CoreMethod (names = "as_instant" , onSingleton = true , required = 1 )
979
+ public abstract static class AsInstantNode extends InteropCoreMethodArrayArgumentsNode {
980
+ @ Specialization (limit = "getCacheLimit()" )
981
+ protected Object asInstant (Object receiver ,
982
+ @ CachedContext (RubyLanguage .class ) RubyContext context ,
983
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ,
984
+ @ Cached TranslateInteropExceptionNode translateInteropException ) {
985
+ try {
986
+ return context .getEnv ().asGuestValue (receivers .asInstant (receiver ));
987
+ } catch (UnsupportedMessageException e ) {
988
+ throw translateInteropException .execute (e );
989
+ }
990
+ }
991
+ }
992
+
993
+ @ CoreMethod (names = "time?" , onSingleton = true , required = 1 )
994
+ public abstract static class IsTimeNode extends InteropCoreMethodArrayArgumentsNode {
995
+ @ Specialization (limit = "getCacheLimit()" )
996
+ protected boolean isTime (Object receiver ,
997
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ) {
998
+ return receivers .isTime (receiver );
999
+ }
1000
+ }
1001
+
1002
+ @ CoreMethod (names = "as_time" , onSingleton = true , required = 1 )
1003
+ public abstract static class AsTimeNode extends InteropCoreMethodArrayArgumentsNode {
1004
+ @ Specialization (limit = "getCacheLimit()" )
1005
+ protected Object asTime (Object receiver ,
1006
+ @ CachedContext (RubyLanguage .class ) RubyContext context ,
1007
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ,
1008
+ @ Cached TranslateInteropExceptionNode translateInteropException ) {
1009
+ try {
1010
+ return context .getEnv ().asGuestValue (receivers .asTime (receiver ));
1011
+ } catch (UnsupportedMessageException e ) {
1012
+ throw translateInteropException .execute (e );
1013
+ }
1014
+ }
1015
+ }
1016
+
1017
+ @ CoreMethod (names = "time_zone?" , onSingleton = true , required = 1 )
1018
+ public abstract static class IsTimeZoneNode extends InteropCoreMethodArrayArgumentsNode {
1019
+ @ Specialization (limit = "getCacheLimit()" )
1020
+ protected boolean isTimeZone (Object receiver ,
1021
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ) {
1022
+ return receivers .isTimeZone (receiver );
1023
+ }
1024
+ }
1025
+
1026
+ @ CoreMethod (names = "as_time_zone" , onSingleton = true , required = 1 )
1027
+ public abstract static class AsTimeZoneNode extends InteropCoreMethodArrayArgumentsNode {
1028
+ @ Specialization (limit = "getCacheLimit()" )
1029
+ protected Object asTimeZone (Object receiver ,
1030
+ @ CachedContext (RubyLanguage .class ) RubyContext context ,
1031
+ @ CachedLibrary ("receiver" ) InteropLibrary receivers ,
1032
+ @ Cached TranslateInteropExceptionNode translateInteropException ) {
1033
+ try {
1034
+ return context .getEnv ().asGuestValue (receivers .asTimeZone (receiver ));
1035
+ } catch (UnsupportedMessageException e ) {
1036
+ throw translateInteropException .execute (e );
1037
+ }
1038
+ }
1039
+ }
1040
+ // endregion
1041
+
708
1042
// region Number
709
1043
@ CoreMethod (names = "number?" , onSingleton = true , required = 1 )
710
1044
public abstract static class IsNumberNode extends InteropCoreMethodArrayArgumentsNode {
0 commit comments