@@ -2263,8 +2263,7 @@ public void emitYieldFrom(Runnable generatorOrCoroutineProducer) {
2263
2263
b .beginBlock ();
2264
2264
BytecodeLabel loopEnd = b .createLabel ();
2265
2265
// Step 2: yield yieldValue to the caller
2266
- BytecodeLocal thrownException = b .createLocal ();
2267
- b .beginTryCatch (thrownException );
2266
+ b .beginTryCatch ();
2268
2267
2269
2268
// try clause: yield
2270
2269
b .beginStoreLocal (sentValue );
@@ -2275,7 +2274,7 @@ public void emitYieldFrom(Runnable generatorOrCoroutineProducer) {
2275
2274
b .beginIfThenElse ();
2276
2275
b .beginYieldFromThrow (yieldValue , returnValue );
2277
2276
b .emitLoadLocal (generator );
2278
- b .emitLoadLocal ( thrownException );
2277
+ b .emitLoadException ( );
2279
2278
b .endYieldFromThrow ();
2280
2279
2281
2280
// StopIteration was raised; go to the end.
@@ -4043,9 +4042,7 @@ public Void visit(StmtTy.Try node) {
4043
4042
* reraise uncaught_ex
4044
4043
* }
4045
4044
*/
4046
- BytecodeLocal uncaughtException = b .createLocal ();
4047
- BytecodeLocal handlerException = b .createLocal ();
4048
- b .beginFinallyTryCatch (uncaughtException , () -> {
4045
+ b .beginFinallyTryCatch (() -> {
4049
4046
b .beginBlock (); // finally
4050
4047
visitSequence (node .finalBody );
4051
4048
b .endBlock ();
@@ -4056,32 +4053,32 @@ public Void visit(StmtTy.Try node) {
4056
4053
b .beginBlock (); // catch
4057
4054
BytecodeLocal savedException = b .createLocal ();
4058
4055
emitSaveCurrentException (savedException );
4059
- emitSetCurrentException (uncaughtException );
4056
+ emitSetCurrentException ();
4060
4057
// Mark this location for the stack trace.
4061
4058
b .beginMarkExceptionAsCaught ();
4062
- b .emitLoadLocal ( uncaughtException );
4059
+ b .emitLoadException ( );
4063
4060
b .endMarkExceptionAsCaught ();
4064
4061
4065
- b .beginFinallyTryCatch (handlerException , () -> emitSetCurrentException (savedException ));
4062
+ b .beginFinallyTryCatch (() -> emitRestoreCurrentException (savedException ));
4066
4063
b .beginBlock (); // try
4067
4064
visitSequence (node .finalBody );
4068
4065
b .endBlock (); // try
4069
4066
4070
4067
b .beginBlock (); // catch
4071
- emitSetCurrentException (savedException );
4068
+ emitRestoreCurrentException (savedException );
4072
4069
4073
4070
b .beginMarkExceptionAsCaught ();
4074
- b .emitLoadLocal ( handlerException );
4071
+ b .emitLoadException ( );
4075
4072
b .endMarkExceptionAsCaught ();
4076
4073
4077
4074
b .beginReraise ();
4078
- b .emitLoadLocal ( handlerException );
4075
+ b .emitLoadException ( );
4079
4076
b .endReraise ();
4080
4077
b .endBlock (); // catch
4081
4078
b .endFinallyTryCatch ();
4082
4079
4083
4080
b .beginReraise ();
4084
- b .emitLoadLocal ( uncaughtException );
4081
+ b .emitLoadException ( );
4085
4082
b .endReraise ();
4086
4083
b .endBlock (); // catch
4087
4084
b .endFinallyTryCatch ();
@@ -4130,11 +4127,11 @@ private void emitTryExceptElse(StmtTy.Try node) {
4130
4127
* handler_1_body
4131
4128
* } finally {
4132
4129
* unbind handler_1_name
4133
- * } catch handler_ex {
4130
+ * } catch handler_1_ex {
4134
4131
* unbind handler_1_name
4135
4132
* // Freeze the bci before it gets rethrown.
4136
4133
* markCaught(handler_ex)
4137
- * throw handler_ex
4134
+ * throw handler_1_ex
4138
4135
* }
4139
4136
* goto afterElse
4140
4137
* }
@@ -4160,26 +4157,24 @@ private void emitTryExceptElse(StmtTy.Try node) {
4160
4157
*/
4161
4158
b .beginBlock (); // outermost block
4162
4159
4163
- BytecodeLocal exception = b .createLocal ();
4164
4160
BytecodeLocal savedException = b .createLocal ();
4165
4161
BytecodeLabel afterElse = b .createLabel ();
4166
4162
4167
- b .beginTryCatch (exception );
4163
+ b .beginTryCatch ();
4168
4164
4169
4165
b .beginBlock (); // try
4170
4166
visitSequence (node .body );
4171
4167
b .endBlock (); // try
4172
4168
4173
4169
b .beginBlock (); // catch
4174
4170
emitSaveCurrentException (savedException );
4175
- emitSetCurrentException (exception );
4171
+ emitSetCurrentException ();
4176
4172
// Mark this location for the stack trace.
4177
4173
b .beginMarkExceptionAsCaught ();
4178
- b .emitLoadLocal ( exception );
4174
+ b .emitLoadException (); // ex
4179
4175
b .endMarkExceptionAsCaught ();
4180
4176
4181
- BytecodeLocal handlerException = b .createLocal ();
4182
- b .beginFinallyTryCatch (handlerException , () -> emitSetCurrentException (savedException ));
4177
+ b .beginFinallyTryCatch (() -> emitRestoreCurrentException (savedException ));
4183
4178
b .beginBlock (); // try
4184
4179
SourceRange bareExceptRange = null ;
4185
4180
for (ExceptHandlerTy h : node .handlers ) {
@@ -4192,7 +4187,7 @@ private void emitTryExceptElse(StmtTy.Try node) {
4192
4187
if (handler .type != null ) {
4193
4188
b .beginIfThen ();
4194
4189
b .beginExceptMatch ();
4195
- b .emitLoadLocal ( exception );
4190
+ b .emitLoadException (); // ex
4196
4191
handler .type .accept (this );
4197
4192
b .endExceptMatch ();
4198
4193
} else {
@@ -4205,11 +4200,11 @@ private void emitTryExceptElse(StmtTy.Try node) {
4205
4200
// Assign exception to handler name.
4206
4201
beginStoreLocal (handler .name , b );
4207
4202
b .beginUnwrapException ();
4208
- b .emitLoadLocal ( exception );
4203
+ b .emitLoadException (); // ex
4209
4204
b .endUnwrapException ();
4210
4205
endStoreLocal (handler .name , b );
4211
4206
4212
- b .beginFinallyTryCatch (handlerException , () -> emitUnbindHandlerVariable (handler ));
4207
+ b .beginFinallyTryCatch (() -> emitUnbindHandlerVariable (handler ));
4213
4208
b .beginBlock (); // try
4214
4209
visitSequence (handler .body );
4215
4210
b .endBlock (); // try
@@ -4218,11 +4213,11 @@ private void emitTryExceptElse(StmtTy.Try node) {
4218
4213
emitUnbindHandlerVariable (handler );
4219
4214
4220
4215
b .beginMarkExceptionAsCaught ();
4221
- b .emitLoadLocal ( handlerException );
4216
+ b .emitLoadException (); // handler_i_ex
4222
4217
b .endMarkExceptionAsCaught ();
4223
4218
4224
4219
b .beginThrow ();
4225
- b .emitLoadLocal ( handlerException );
4220
+ b .emitLoadException (); // handler_i_ex
4226
4221
b .endThrow ();
4227
4222
b .endBlock (); // catch
4228
4223
b .endFinallyTryCatch ();
@@ -4245,14 +4240,14 @@ private void emitTryExceptElse(StmtTy.Try node) {
4245
4240
b .endBlock (); // try
4246
4241
4247
4242
b .beginBlock (); // catch
4248
- emitSetCurrentException (savedException );
4243
+ emitRestoreCurrentException (savedException );
4249
4244
4250
4245
b .beginMarkExceptionAsCaught ();
4251
- b .emitLoadLocal ( handlerException );
4246
+ b .emitLoadException (); // handler_ex
4252
4247
b .endMarkExceptionAsCaught ();
4253
4248
4254
4249
b .beginReraise ();
4255
- b .emitLoadLocal ( handlerException );
4250
+ b .emitLoadException (); // handler_ex
4256
4251
b .endReraise ();
4257
4252
b .endBlock (); // catch
4258
4253
b .endFinallyTryCatch ();
@@ -4265,7 +4260,7 @@ private void emitTryExceptElse(StmtTy.Try node) {
4265
4260
*/
4266
4261
if (bareExceptRange == null ) {
4267
4262
b .beginReraise ();
4268
- b .emitLoadLocal ( exception );
4263
+ b .emitLoadException (); // ex
4269
4264
b .endReraise ();
4270
4265
}
4271
4266
@@ -4295,9 +4290,15 @@ private void emitSaveCurrentException(BytecodeLocal savedException) {
4295
4290
b .endStoreLocal ();
4296
4291
}
4297
4292
4298
- private void emitSetCurrentException (BytecodeLocal newException ) {
4293
+ private void emitSetCurrentException () {
4299
4294
b .beginSetCurrentException ();
4300
- b .emitLoadLocal (newException );
4295
+ b .emitLoadException ();
4296
+ b .endSetCurrentException ();
4297
+ }
4298
+
4299
+ private void emitRestoreCurrentException (BytecodeLocal savedException ) {
4300
+ b .beginSetCurrentException ();
4301
+ b .emitLoadLocal (savedException );
4301
4302
b .endSetCurrentException ();
4302
4303
}
4303
4304
@@ -4410,7 +4411,6 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool
4410
4411
b .endContextManagerEnter ();
4411
4412
}
4412
4413
4413
- BytecodeLocal ex = b .createLocal ();
4414
4414
Runnable finallyHandler ;
4415
4415
if (async ) {
4416
4416
finallyHandler = () -> emitAwait (() -> {
@@ -4430,7 +4430,7 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool
4430
4430
b .endContextManagerExit ();
4431
4431
};
4432
4432
}
4433
- b .beginFinallyTryCatch (ex , finallyHandler );
4433
+ b .beginFinallyTryCatch (finallyHandler );
4434
4434
b .beginBlock (); // try
4435
4435
if (item .optionalVars != null ) {
4436
4436
item .optionalVars .accept (new StoreVisitor (() -> b .emitLoadLocal (value )));
@@ -4446,17 +4446,17 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool
4446
4446
4447
4447
// Mark this location for the stack trace.
4448
4448
b .beginMarkExceptionAsCaught ();
4449
- b .emitLoadLocal ( ex );
4449
+ b .emitLoadException ( );
4450
4450
b .endMarkExceptionAsCaught ();
4451
4451
4452
4452
// exceptional exit
4453
4453
if (async ) {
4454
4454
// call, await, and handle result of __aexit__
4455
4455
b .beginAsyncContextManagerExit ();
4456
- b .emitLoadLocal ( ex );
4456
+ b .emitLoadException ( );
4457
4457
emitAwait (() -> {
4458
4458
b .beginAsyncContextManagerCallExit ();
4459
- b .emitLoadLocal ( ex );
4459
+ b .emitLoadException ( );
4460
4460
b .emitLoadLocal (exit );
4461
4461
b .emitLoadLocal (contextManager );
4462
4462
b .endAsyncContextManagerCallExit ();
@@ -4465,7 +4465,7 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool
4465
4465
} else {
4466
4466
// call __exit__
4467
4467
b .beginContextManagerExit ();
4468
- b .emitLoadLocal ( ex );
4468
+ b .emitLoadException ( );
4469
4469
b .emitLoadLocal (exit );
4470
4470
b .emitLoadLocal (contextManager );
4471
4471
b .endContextManagerExit ();
0 commit comments