Skip to content

Commit 24a7be1

Browse files
aardvark179eregon
authored andcommitted
Small tidy up.
1 parent 0602b9a commit 24a7be1

File tree

1 file changed

+61
-36
lines changed

1 file changed

+61
-36
lines changed

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
import com.oracle.truffle.api.Truffle;
118118
import com.oracle.truffle.api.dsl.Cached;
119119
import com.oracle.truffle.api.dsl.CreateCast;
120+
import com.oracle.truffle.api.dsl.Fallback;
120121
import com.oracle.truffle.api.dsl.NodeChild;
121122
import com.oracle.truffle.api.dsl.ReportPolymorphism;
122123
import com.oracle.truffle.api.dsl.Specialization;
@@ -137,16 +138,16 @@
137138
public class CExtNodes {
138139

139140
/* 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
141142
* 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;
150151

151152
public static Pointer newNativeStringPointer(int capacity, RubyLanguage language) {
152153
// 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
14181419

14191420
@Specialization
14201421
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) {
14471473
return 0;
14481474
}
14491475
}
@@ -1460,7 +1486,6 @@ protected Object executeThrow(CapturedException captured,
14601486
if (runtimeExceptionProfile.profile(e instanceof RuntimeException)) {
14611487
throw (RuntimeException) e;
14621488
} else if (errorProfile.profile(e instanceof Error)) {
1463-
14641489
throw (Error) e;
14651490
} else {
14661491
throw CompilerDirectives.shouldNotReachHere("Checked Java Throwable rethrown", e);

0 commit comments

Comments
 (0)