5858import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
5959import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
6060import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
61+ import com .oracle .graal .python .nodes .truffle .PythonArithmeticTypes ;
6162import com .oracle .graal .python .runtime .exception .PythonErrorType ;
6263import com .oracle .truffle .api .CompilerAsserts ;
6364import com .oracle .truffle .api .CompilerDirectives ;
6869import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
6970import com .oracle .truffle .api .dsl .NodeFactory ;
7071import com .oracle .truffle .api .dsl .Specialization ;
72+ import com .oracle .truffle .api .dsl .TypeSystemReference ;
7173import com .oracle .truffle .api .interop .ArityException ;
7274import com .oracle .truffle .api .interop .ForeignAccess ;
7375import com .oracle .truffle .api .interop .Message ;
@@ -253,26 +255,21 @@ Object run(Object o) {
253255
254256 }
255257
256- @ Builtin (name = "tregex_call_safe" , minNumOfArguments = 1 , takesVariableArguments = true )
258+ @ Builtin (name = "tregex_call_safe" , fixedNumOfArguments = 3 )
259+ @ TypeSystemReference (PythonArithmeticTypes .class )
257260 @ GenerateNodeFactory
258261 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 ,
261266 @ 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+ }
264271 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 });
276273 } catch (ArityException | UnsupportedTypeException | UnsupportedMessageException e ) {
277274 typeError .enter ();
278275 throw raise (TypeError , "%s" , e );
@@ -282,10 +279,19 @@ Object call(TruffleObject callable, Object[] arguments,
282279 }
283280 }
284281
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 );
287294 }
288295
289296 }
290-
291297}
0 commit comments