40
40
*/
41
41
package com .oracle .graal .python .builtins .modules ;
42
42
43
+ import static com .oracle .graal .python .builtins .PythonBuiltinClassType .TypeError ;
43
44
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .ValueError ;
44
45
import static com .oracle .graal .python .runtime .exception .PythonErrorType .SystemError ;
45
46
50
51
import com .oracle .graal .python .builtins .Builtin ;
51
52
import com .oracle .graal .python .builtins .CoreFunctions ;
52
53
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
53
- import static com .oracle .graal .python .builtins .PythonBuiltinClassType .TypeError ;
54
54
import com .oracle .graal .python .builtins .PythonBuiltins ;
55
55
import com .oracle .graal .python .builtins .objects .PNone ;
56
56
import com .oracle .graal .python .builtins .objects .array .PArray ;
66
66
import com .oracle .graal .python .builtins .objects .type .PythonAbstractClass ;
67
67
import com .oracle .graal .python .nodes .ErrorMessages ;
68
68
import com .oracle .graal .python .nodes .attributes .ReadAttributeFromObjectNode ;
69
+ import com .oracle .graal .python .nodes .call .CallNode ;
69
70
import com .oracle .graal .python .nodes .call .special .LookupAndCallUnaryNode ;
70
71
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
71
72
import com .oracle .graal .python .nodes .function .builtins .PythonBinaryBuiltinNode ;
72
73
import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
74
+ import com .oracle .graal .python .nodes .statement .RaiseNode ;
75
+ import com .oracle .graal .python .nodes .statement .RaiseNodeGen ;
73
76
import com .oracle .graal .python .nodes .truffle .PythonArithmeticTypes ;
74
77
import com .oracle .graal .python .runtime .PythonCore ;
75
78
import com .oracle .graal .python .runtime .exception .PException ;
@@ -140,7 +143,9 @@ private byte[] b64decode(byte[] data) {
140
143
@ Builtin (name = "a2b_hex" , minNumOfPositionalArgs = 2 , declaresExplicitSelf = true )
141
144
@ GenerateNodeFactory
142
145
abstract static class A2bHexNode extends PythonBinaryBuiltinNode {
143
- private ReadAttributeFromObjectNode readAttrNode ;
146
+ @ Child private ReadAttributeFromObjectNode readAttrNode ;
147
+ @ Child private RaiseNode raiseNode ;
148
+ @ Child private CallNode callExceptionConstructor ;
144
149
145
150
@ Specialization
146
151
@ TruffleBoundary
@@ -204,11 +209,15 @@ private int digitValue(PythonModule self, char b) {
204
209
}
205
210
206
211
private PException oddLengthError (PythonModule self ) {
207
- throw getRaiseNode ().execute (getAttrNode ().execute (self , ERROR ), PNone .NO_VALUE , ErrorMessages .ODD_LENGTH_STRING , new Object [0 ]);
212
+ raiseObject (getAttrNode ().execute (self , ERROR ), ErrorMessages .ODD_LENGTH_STRING );
213
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
214
+ throw new IllegalStateException ("should not be reached" );
208
215
}
209
216
210
217
private PException nonHexError (PythonModule self ) {
211
- throw getRaiseNode ().execute (getAttrNode ().execute (self , ERROR ), PNone .NO_VALUE , ErrorMessages .NON_HEX_DIGIT_FOUND , new Object [0 ]);
218
+ raiseObject (getAttrNode ().execute (self , ERROR ), ErrorMessages .NON_HEX_DIGIT_FOUND );
219
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
220
+ throw new IllegalStateException ("should not be reached" );
212
221
}
213
222
214
223
private ReadAttributeFromObjectNode getAttrNode () {
@@ -218,6 +227,18 @@ private ReadAttributeFromObjectNode getAttrNode() {
218
227
}
219
228
return readAttrNode ;
220
229
}
230
+
231
+ private void raiseObject (Object exceptionObject , String message ) {
232
+ if (callExceptionConstructor == null ) {
233
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
234
+ callExceptionConstructor = insert (CallNode .create ());
235
+ }
236
+ if (raiseNode == null ) {
237
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
238
+ raiseNode = insert (RaiseNodeGen .create (null , null ));
239
+ }
240
+ raiseNode .execute (callExceptionConstructor .execute (exceptionObject , message ), PNone .NO_VALUE );
241
+ }
221
242
}
222
243
223
244
@ Builtin (name = "b2a_base64" , minNumOfPositionalArgs = 1 , parameterNames = {"data" , "newline" })
0 commit comments