88
88
import com .oracle .graal .python .builtins .objects .floats .PFloat ;
89
89
import com .oracle .graal .python .builtins .objects .function .PFunction ;
90
90
import com .oracle .graal .python .builtins .objects .function .PKeyword ;
91
+ import com .oracle .graal .python .builtins .objects .function .Signature ;
91
92
import com .oracle .graal .python .builtins .objects .getsetdescriptor .DescriptorDeleteMarker ;
92
93
import com .oracle .graal .python .builtins .objects .ints .PInt ;
93
94
import com .oracle .graal .python .builtins .objects .module .PythonModule ;
103
104
import com .oracle .graal .python .nodes .PGuards ;
104
105
import com .oracle .graal .python .nodes .PNodeWithContext ;
105
106
import com .oracle .graal .python .nodes .PRaiseNode ;
107
+ import com .oracle .graal .python .nodes .PRootNode ;
106
108
import com .oracle .graal .python .nodes .SpecialMethodNames ;
107
109
import com .oracle .graal .python .nodes .argument .CreateArgumentsNode ;
108
110
import com .oracle .graal .python .nodes .argument .ReadArgumentNode ;
109
111
import com .oracle .graal .python .nodes .argument .ReadVarArgsNode ;
110
112
import com .oracle .graal .python .nodes .attributes .ReadAttributeFromObjectNode ;
111
113
import com .oracle .graal .python .nodes .call .CallNode ;
114
+ import com .oracle .graal .python .nodes .call .CallTargetInvokeNode ;
112
115
import com .oracle .graal .python .nodes .call .FunctionInvokeNode ;
113
116
import com .oracle .graal .python .nodes .call .special .CallBinaryMethodNode ;
114
117
import com .oracle .graal .python .nodes .call .special .CallTernaryMethodNode ;
115
118
import com .oracle .graal .python .nodes .call .special .CallUnaryMethodNode ;
116
119
import com .oracle .graal .python .nodes .call .special .LookupAndCallUnaryNode .LookupAndCallUnaryDynamicNode ;
117
120
import com .oracle .graal .python .nodes .classes .IsSubtypeNode ;
118
121
import com .oracle .graal .python .nodes .frame .GetCurrentFrameRef ;
119
- import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
120
- import com .oracle .graal .python .nodes .function .builtins .PythonBinaryBuiltinNode ;
121
122
import com .oracle .graal .python .nodes .function .builtins .PythonTernaryBuiltinNode ;
122
123
import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
123
124
import com .oracle .graal .python .nodes .object .GetClassNode ;
137
138
import com .oracle .truffle .api .Assumption ;
138
139
import com .oracle .truffle .api .CompilerAsserts ;
139
140
import com .oracle .truffle .api .CompilerDirectives ;
141
+ import com .oracle .truffle .api .RootCallTarget ;
142
+ import com .oracle .truffle .api .Truffle ;
143
+ import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
140
144
import com .oracle .truffle .api .TruffleLanguage .ContextReference ;
141
145
import com .oracle .truffle .api .TruffleLogger ;
142
146
import com .oracle .truffle .api .dsl .Cached ;
157
161
import com .oracle .truffle .api .interop .UnsupportedMessageException ;
158
162
import com .oracle .truffle .api .interop .UnsupportedTypeException ;
159
163
import com .oracle .truffle .api .library .CachedLibrary ;
164
+ import com .oracle .truffle .api .nodes .DirectCallNode ;
160
165
import com .oracle .truffle .api .nodes .ExplodeLoop ;
161
166
import com .oracle .truffle .api .nodes .InvalidAssumptionException ;
162
167
import com .oracle .truffle .api .nodes .Node ;
@@ -2527,145 +2532,26 @@ public static PCallCapiFunction getUncached() {
2527
2532
}
2528
2533
}
2529
2534
2530
- // -----------------------------------------------------------------------------------------------------------------
2531
- @ Builtin (minNumOfPositionalArgs = 1 )
2532
- public abstract static class MayRaiseUnaryNode extends PythonUnaryBuiltinNode {
2533
- @ Child private CreateArgumentsNode createArgsNode ;
2534
- @ Child private FunctionInvokeNode invokeNode ;
2535
- @ Child private TransformExceptionToNativeNode transformExceptionToNativeNode ;
2536
-
2537
- private final PFunction func ;
2538
- private final Object errorResult ;
2539
-
2540
- public MayRaiseUnaryNode (PFunction func , Object errorResult ) {
2541
- this .createArgsNode = CreateArgumentsNode .create ();
2542
- this .func = func ;
2543
- this .invokeNode = FunctionInvokeNode .create (func );
2544
- this .errorResult = errorResult ;
2545
- }
2546
-
2547
- @ Specialization
2548
- Object doit (VirtualFrame frame , Object argument ) {
2549
- try {
2550
- Object [] arguments = createArgsNode .execute (func , new Object []{argument });
2551
- return invokeNode .execute (frame , arguments );
2552
- } catch (PException e ) {
2553
- // transformExceptionToNativeNode acts as a branch profile
2554
- ensureTransformExceptionToNativeNode ().execute (frame , e );
2555
- return errorResult ;
2556
- }
2557
- }
2558
-
2559
- private TransformExceptionToNativeNode ensureTransformExceptionToNativeNode () {
2560
- if (transformExceptionToNativeNode == null ) {
2561
- CompilerDirectives .transferToInterpreterAndInvalidate ();
2562
- transformExceptionToNativeNode = insert (TransformExceptionToNativeNodeGen .create ());
2563
- }
2564
- return transformExceptionToNativeNode ;
2565
- }
2566
- }
2567
-
2568
- // -----------------------------------------------------------------------------------------------------------------
2569
- @ Builtin (minNumOfPositionalArgs = 2 )
2570
- public abstract static class MayRaiseBinaryNode extends PythonBinaryBuiltinNode {
2571
- @ Child private CreateArgumentsNode createArgsNode ;
2572
- @ Child private FunctionInvokeNode invokeNode ;
2573
- @ Child private TransformExceptionToNativeNode transformExceptionToNativeNode ;
2574
-
2575
- private final PFunction func ;
2576
- private final Object errorResult ;
2577
-
2578
- public MayRaiseBinaryNode (PFunction func , Object errorResult ) {
2579
- this .createArgsNode = CreateArgumentsNode .create ();
2580
- this .func = func ;
2581
- this .invokeNode = FunctionInvokeNode .create (func );
2582
- this .errorResult = errorResult ;
2583
- }
2584
-
2585
- @ Specialization
2586
- Object doit (VirtualFrame frame , Object arg1 , Object arg2 ) {
2587
- try {
2588
- Object [] arguments = createArgsNode .execute (func , new Object []{arg1 , arg2 });
2589
- return invokeNode .execute (frame , arguments );
2590
- } catch (PException e ) {
2591
- // transformExceptionToNativeNode acts as a branch profile
2592
- ensureTransformExceptionToNativeNode ().execute (frame , e );
2593
- return errorResult ;
2594
- }
2595
- }
2596
-
2597
- private TransformExceptionToNativeNode ensureTransformExceptionToNativeNode () {
2598
- if (transformExceptionToNativeNode == null ) {
2599
- CompilerDirectives .transferToInterpreterAndInvalidate ();
2600
- transformExceptionToNativeNode = insert (TransformExceptionToNativeNodeGen .create ());
2601
- }
2602
- return transformExceptionToNativeNode ;
2603
- }
2604
- }
2605
-
2606
- // -----------------------------------------------------------------------------------------------------------------
2607
- @ Builtin (minNumOfPositionalArgs = 3 )
2608
- public abstract static class MayRaiseTernaryNode extends PythonTernaryBuiltinNode {
2609
- @ Child private CreateArgumentsNode createArgsNode ;
2610
- @ Child private FunctionInvokeNode invokeNode ;
2611
- @ Child private TransformExceptionToNativeNode transformExceptionToNativeNode ;
2612
-
2613
- private final PFunction func ;
2614
- private final Object errorResult ;
2615
-
2616
- public MayRaiseTernaryNode (PFunction func , Object errorResult ) {
2617
- this .createArgsNode = CreateArgumentsNode .create ();
2618
- this .func = func ;
2619
- this .invokeNode = FunctionInvokeNode .create (func );
2620
- this .errorResult = errorResult ;
2621
- }
2622
-
2623
- @ Specialization
2624
- Object doit (VirtualFrame frame , Object arg1 , Object arg2 , Object arg3 ) {
2625
- try {
2626
- Object [] arguments = createArgsNode .execute (func , new Object []{arg1 , arg2 , arg3 });
2627
- return invokeNode .execute (frame , arguments );
2628
- } catch (PException e ) {
2629
- // transformExceptionToNativeNode acts as a branch profile
2630
- ensureTransformExceptionToNativeNode ().execute (frame , e );
2631
- return errorResult ;
2632
- }
2633
- }
2634
-
2635
- private TransformExceptionToNativeNode ensureTransformExceptionToNativeNode () {
2636
- if (transformExceptionToNativeNode == null ) {
2637
- CompilerDirectives .transferToInterpreterAndInvalidate ();
2638
- transformExceptionToNativeNode = insert (TransformExceptionToNativeNodeGen .create ());
2639
- }
2640
- return transformExceptionToNativeNode ;
2641
- }
2642
- }
2643
-
2644
2535
// -----------------------------------------------------------------------------------------------------------------
2645
2536
@ Builtin (takesVarArgs = true )
2646
- public static class MayRaiseNode extends PythonBuiltinNode {
2647
- @ Child private FunctionInvokeNode invokeNode ;
2648
- @ Child private ReadVarArgsNode readVarargsNode ;
2649
- @ Child private CreateArgumentsNode createArgsNode ;
2537
+ public static class MayRaiseNode extends PRootNode {
2538
+ @ Child private DirectCallNode callNode ;
2650
2539
@ Child private TransformExceptionToNativeNode transformExceptionToNativeNode ;
2651
2540
2652
- private final PFunction func ;
2541
+ private final Signature signature ;
2653
2542
private final Object errorResult ;
2654
2543
2655
- public MayRaiseNode (PFunction callable , Object errorResult ) {
2656
- this .readVarargsNode = ReadVarArgsNode .create (0 , true );
2657
- this .createArgsNode = CreateArgumentsNode .create ();
2658
- this .func = callable ;
2659
- this .invokeNode = FunctionInvokeNode .create (callable );
2544
+ public MayRaiseNode (PythonLanguage lang , Signature sign , RootCallTarget ct , Object errorResult ) {
2545
+ super (lang );
2546
+ this .signature = sign ;
2547
+ this .callNode = Truffle .getRuntime ().createDirectCallNode (ct );
2660
2548
this .errorResult = errorResult ;
2661
2549
}
2662
2550
2663
2551
@ Override
2664
2552
public final Object execute (VirtualFrame frame ) {
2665
- Object [] args = readVarargsNode .executeObjectArray (frame );
2666
2553
try {
2667
- Object [] arguments = createArgsNode .execute (func , args );
2668
- return invokeNode .execute (frame , arguments );
2554
+ return callNode .call (frame .getArguments ());
2669
2555
} catch (PException e ) {
2670
2556
// transformExceptionToNativeNode acts as a branch profile
2671
2557
ensureTransformExceptionToNativeNode ().execute (frame , e );
@@ -2682,8 +2568,13 @@ private TransformExceptionToNativeNode ensureTransformExceptionToNativeNode() {
2682
2568
}
2683
2569
2684
2570
@ Override
2685
- protected ReadArgumentNode [] getArguments () {
2686
- throw new IllegalAccessError ();
2571
+ public Signature getSignature () {
2572
+ return signature ;
2573
+ }
2574
+
2575
+ @ Override
2576
+ public boolean isPythonInternal () {
2577
+ return true ;
2687
2578
}
2688
2579
}
2689
2580
0 commit comments