@@ -3952,12 +3952,45 @@ private static void handleException(VirtualFrame frame, PException e, Node inlin
3952
3952
}
3953
3953
}
3954
3954
3955
+ /**
3956
+ * Loads a user-defined local variable. Unlike a built-in LoadLocal, this operation raises an
3957
+ * unbound local error if the local has not been set.
3958
+ * <p>
3959
+ * This operation makes use of Truffle's boxing overloads. When an operation tries to quicken
3960
+ * this one for boxing elimination, the correct overload will be selected.
3961
+ */
3955
3962
@ Operation
3956
3963
@ ConstantOperand (type = LocalAccessor .class )
3957
3964
@ ConstantOperand (type = int .class )
3958
- public static final class CheckUnboundLocal {
3959
- @ Specialization
3960
- public static void doObject (VirtualFrame frame , LocalAccessor accessor , int index ,
3965
+ public static final class CheckAndLoadLocal {
3966
+ @ Specialization (rewriteOn = UnexpectedResultException .class )
3967
+ public static int doInt (VirtualFrame frame , LocalAccessor accessor , int index ,
3968
+ @ Bind PBytecodeDSLRootNode rootNode ,
3969
+ @ Bind BytecodeNode bytecodeNode ,
3970
+ @ Bind Node inliningTarget ,
3971
+ @ Shared @ Cached InlinedBranchProfile localUnboundProfile ) throws UnexpectedResultException {
3972
+ if (accessor .isCleared (bytecodeNode , frame )) {
3973
+ localUnboundProfile .enter (inliningTarget );
3974
+ throw raiseUnbound (rootNode , inliningTarget , index );
3975
+ }
3976
+ return accessor .getInt (bytecodeNode , frame );
3977
+ }
3978
+
3979
+ @ Specialization (rewriteOn = UnexpectedResultException .class )
3980
+ public static boolean doBoolean (VirtualFrame frame , LocalAccessor accessor , int index ,
3981
+ @ Bind PBytecodeDSLRootNode rootNode ,
3982
+ @ Bind BytecodeNode bytecodeNode ,
3983
+ @ Bind Node inliningTarget ,
3984
+ @ Shared @ Cached InlinedBranchProfile localUnboundProfile ) throws UnexpectedResultException {
3985
+ if (accessor .isCleared (bytecodeNode , frame )) {
3986
+ localUnboundProfile .enter (inliningTarget );
3987
+ throw raiseUnbound (rootNode , inliningTarget , index );
3988
+ }
3989
+ return accessor .getBoolean (bytecodeNode , frame );
3990
+ }
3991
+
3992
+ @ Specialization (replaces = {"doInt" , "doBoolean" })
3993
+ public static Object doObject (VirtualFrame frame , LocalAccessor accessor , int index ,
3961
3994
@ Bind PBytecodeDSLRootNode rootNode ,
3962
3995
@ Bind BytecodeNode bytecodeNode ,
3963
3996
@ Bind Node inliningTarget ,
@@ -3966,6 +3999,7 @@ public static void doObject(VirtualFrame frame, LocalAccessor accessor, int inde
3966
3999
localUnboundProfile .enter (inliningTarget );
3967
4000
throw raiseUnbound (rootNode , inliningTarget , index );
3968
4001
}
4002
+ return accessor .getObject (bytecodeNode , frame );
3969
4003
}
3970
4004
}
3971
4005
0 commit comments