117
117
import com .oracle .truffle .api .Truffle ;
118
118
import com .oracle .truffle .api .dsl .Cached ;
119
119
import com .oracle .truffle .api .dsl .CreateCast ;
120
+ import com .oracle .truffle .api .dsl .Fallback ;
120
121
import com .oracle .truffle .api .dsl .NodeChild ;
121
122
import com .oracle .truffle .api .dsl .ReportPolymorphism ;
122
123
import com .oracle .truffle .api .dsl .Specialization ;
137
138
public class CExtNodes {
138
139
139
140
/* These tag values are derived from MRI source and from the Tk gem and are used to represent different control flow
140
- * states under which code may exit an `rb_protect` plock . The fatal tag is defined but I could not find a point
141
+ * states under which code may exit an `rb_protect` block . The fatal tag is defined but I could not find a point
141
142
* where it is assigned, and am not sure it maps to anything we would use in TruffleRuby. */
142
- public static int RUBY_TAG_RETURN = 0x1 ;
143
- public static int RUBY_TAG_BREAK = 0x2 ;
144
- public static int RUBY_TAG_NEXT = 0x3 ;
145
- public static int RUBY_TAG_RETRY = 0x4 ;
146
- public static int RUBY_TAG_REDO = 0x5 ;
147
- public static int RUBY_TAG_RAISE = 0x6 ;
148
- public static int RUBY_TAG_THROW = 0x7 ;
149
- public static int RUBY_TAG_FATAL = 0x8 ;
143
+ public static final int RUBY_TAG_RETURN = 0x1 ;
144
+ public static final int RUBY_TAG_BREAK = 0x2 ;
145
+ public static final int RUBY_TAG_NEXT = 0x3 ;
146
+ public static final int RUBY_TAG_RETRY = 0x4 ;
147
+ public static final int RUBY_TAG_REDO = 0x5 ;
148
+ public static final int RUBY_TAG_RAISE = 0x6 ;
149
+ public static final int RUBY_TAG_THROW = 0x7 ;
150
+ public static final int RUBY_TAG_FATAL = 0x8 ;
150
151
151
152
public static Pointer newNativeStringPointer (int capacity , RubyLanguage language ) {
152
153
// We need up to 4 \0 bytes for UTF-32. Always use 4 for speed rather than checking the encoding min length.
@@ -1418,32 +1419,57 @@ public abstract static class ExtractRubyTag extends CoreMethodArrayArgumentsNode
1418
1419
1419
1420
@ Specialization
1420
1421
protected int executeThrow (CapturedException captured ,
1421
- @ Cached ConditionProfile localReturnProfile ,
1422
- @ Cached ConditionProfile dynamicReturnProfile ,
1423
- @ Cached ConditionProfile breakProfile ,
1424
- @ Cached ConditionProfile nextProfile ,
1425
- @ Cached ConditionProfile retryProfile ,
1426
- @ Cached ConditionProfile redoProfile ,
1427
- @ Cached ConditionProfile raiseProfile ,
1428
- @ Cached ConditionProfile throwProfile ) {
1429
- final Throwable e = captured .getException ();
1430
- if (dynamicReturnProfile .profile (e instanceof DynamicReturnException )) {
1431
- return RUBY_TAG_RETURN ;
1432
- } else if (localReturnProfile .profile (e instanceof LocalReturnException )) {
1433
- return RUBY_TAG_RETURN ;
1434
- } else if (breakProfile .profile (e instanceof BreakException )) {
1435
- return RUBY_TAG_BREAK ;
1436
- } else if (nextProfile .profile (e instanceof NextException )) {
1437
- return RUBY_TAG_NEXT ;
1438
- } else if (retryProfile .profile (e instanceof RetryException )) {
1439
- return RUBY_TAG_RETRY ;
1440
- } else if (redoProfile .profile (e instanceof RedoException )) {
1441
- return RUBY_TAG_REDO ;
1442
- } else if (raiseProfile .profile (e instanceof RaiseException )) {
1443
- return RUBY_TAG_RAISE ;
1444
- } else if (throwProfile .profile (e instanceof ThrowException )) {
1445
- return RUBY_TAG_THROW ;
1446
- }
1422
+ @ Cached ExtractRubyTagHelperNode helperNode ) {
1423
+ return helperNode .execute (captured .getException ());
1424
+ }
1425
+ }
1426
+
1427
+ public abstract static class ExtractRubyTagHelperNode extends RubyBaseNode {
1428
+
1429
+ public abstract int execute (Throwable e );
1430
+
1431
+ @ Specialization
1432
+ protected int dynamicReturnTag (DynamicReturnException e ) {
1433
+ return RUBY_TAG_RETURN ;
1434
+ }
1435
+
1436
+ @ Specialization
1437
+ protected int localReturnTag (LocalReturnException e ) {
1438
+ return RUBY_TAG_RETURN ;
1439
+ }
1440
+
1441
+ @ Specialization
1442
+ protected int breakTag (BreakException e ) {
1443
+ return RUBY_TAG_BREAK ;
1444
+ }
1445
+
1446
+ @ Specialization
1447
+ protected int nextTag (NextException e ) {
1448
+ return RUBY_TAG_NEXT ;
1449
+ }
1450
+
1451
+ @ Specialization
1452
+ protected int retryTag (RetryException e ) {
1453
+ return RUBY_TAG_RETRY ;
1454
+ }
1455
+
1456
+ @ Specialization
1457
+ protected int redoTag (RedoException e ) {
1458
+ return RUBY_TAG_REDO ;
1459
+ }
1460
+
1461
+ @ Specialization
1462
+ protected int raiseTag (RaiseException e ) {
1463
+ return RUBY_TAG_RAISE ;
1464
+ }
1465
+
1466
+ @ Specialization
1467
+ protected int throwTag (ThrowException e ) {
1468
+ return RUBY_TAG_THROW ;
1469
+ }
1470
+
1471
+ @ Fallback
1472
+ protected int noTag (Throwable e ) {
1447
1473
return 0 ;
1448
1474
}
1449
1475
}
@@ -1460,7 +1486,6 @@ protected Object executeThrow(CapturedException captured,
1460
1486
if (runtimeExceptionProfile .profile (e instanceof RuntimeException )) {
1461
1487
throw (RuntimeException ) e ;
1462
1488
} else if (errorProfile .profile (e instanceof Error )) {
1463
-
1464
1489
throw (Error ) e ;
1465
1490
} else {
1466
1491
throw CompilerDirectives .shouldNotReachHere ("Checked Java Throwable rethrown" , e );
0 commit comments