58
58
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
59
59
import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
60
60
import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
61
+ import com .oracle .graal .python .nodes .truffle .PythonArithmeticTypes ;
61
62
import com .oracle .graal .python .runtime .exception .PythonErrorType ;
62
63
import com .oracle .truffle .api .CompilerAsserts ;
63
64
import com .oracle .truffle .api .CompilerDirectives ;
68
69
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
69
70
import com .oracle .truffle .api .dsl .NodeFactory ;
70
71
import com .oracle .truffle .api .dsl .Specialization ;
72
+ import com .oracle .truffle .api .dsl .TypeSystemReference ;
71
73
import com .oracle .truffle .api .interop .ArityException ;
72
74
import com .oracle .truffle .api .interop .ForeignAccess ;
73
75
import com .oracle .truffle .api .interop .Message ;
@@ -253,26 +255,21 @@ Object run(Object o) {
253
255
254
256
}
255
257
256
- @ Builtin (name = "tregex_call_safe" , minNumOfArguments = 1 , takesVariableArguments = true )
258
+ @ Builtin (name = "tregex_call_safe" , fixedNumOfArguments = 3 )
259
+ @ TypeSystemReference (PythonArithmeticTypes .class )
257
260
@ GenerateNodeFactory
258
261
abstract static class TRegexCallSafe extends PythonBuiltinNode {
259
- @ Specialization (guards = "isForeignObject(callable)" )
260
- Object call (TruffleObject callable , Object [] arguments ,
262
+
263
+ private Node invokeNode ;
264
+
265
+ private Object doIt (TruffleObject callable , String arg1 , Object arg2 ,
261
266
@ Cached ("create()" ) BranchProfile runtimeError ,
262
- @ Cached ("create()" ) BranchProfile typeError ,
263
- @ Cached ("createExecute()" ) Node invokeNode ) {
267
+ @ Cached ("create()" ) BranchProfile typeError ) {
268
+ if (invokeNode == null ) {
269
+ invokeNode = Message .createExecute (0 ).createNode ();
270
+ }
264
271
try {
265
- // TODO This is a hack. The right solution would be to fix it
266
- // in
267
- // com.oracle.truffle.regex.RegexEngine.RegexEngineMessageResolution.RegexEngineExecuteNode
268
- // where is only check whether the argument is instance of String.
269
- // PString should be there unboxed.
270
- for (int i = 0 ; i < arguments .length ; i ++) {
271
- if (arguments [i ] instanceof PString ) {
272
- arguments [i ] = ((PString ) arguments [i ]).getValue ();
273
- }
274
- }
275
- return ForeignAccess .sendExecute (invokeNode , callable , arguments );
272
+ return ForeignAccess .sendExecute (invokeNode , callable , new Object []{arg1 , arg2 });
276
273
} catch (ArityException | UnsupportedTypeException | UnsupportedMessageException e ) {
277
274
typeError .enter ();
278
275
throw raise (TypeError , "%s" , e );
@@ -282,10 +279,19 @@ Object call(TruffleObject callable, Object[] arguments,
282
279
}
283
280
}
284
281
285
- protected static Node createExecute () {
286
- return Message .createExecute (0 ).createNode ();
282
+ @ Specialization (guards = "isForeignObject(callable)" )
283
+ Object call (TruffleObject callable , String arg1 , String arg2 ,
284
+ @ Cached ("create()" ) BranchProfile runtimeError ,
285
+ @ Cached ("create()" ) BranchProfile typeError ) {
286
+ return doIt (callable , arg1 , arg2 , runtimeError , typeError );
287
+ }
288
+
289
+ @ Specialization (guards = "isForeignObject(callable)" )
290
+ Object call (TruffleObject callable , String arg1 , int arg2 ,
291
+ @ Cached ("create()" ) BranchProfile runtimeError ,
292
+ @ Cached ("create()" ) BranchProfile typeError ) {
293
+ return doIt (callable , arg1 , arg2 , runtimeError , typeError );
287
294
}
288
295
289
296
}
290
-
291
297
}
0 commit comments