73
73
import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodesFactory .DirectUpcallNodeGen ;
74
74
import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodesFactory .FastCallArgsToSulongNodeGen ;
75
75
import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodesFactory .FastCallWithKeywordsArgsToSulongNodeGen ;
76
+ import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodesFactory .GetNativeNullNodeGen ;
76
77
import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodesFactory .GetTypeMemberNodeGen ;
77
78
import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodesFactory .IsPointerNodeGen ;
78
79
import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodesFactory .ObjectUpcallNodeGen ;
139
140
import com .oracle .truffle .api .Assumption ;
140
141
import com .oracle .truffle .api .CompilerAsserts ;
141
142
import com .oracle .truffle .api .CompilerDirectives ;
143
+ import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
142
144
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
143
145
import com .oracle .truffle .api .RootCallTarget ;
144
146
import com .oracle .truffle .api .TruffleLanguage .ContextReference ;
@@ -2473,18 +2475,24 @@ public static PCallCapiFunction getUncached() {
2473
2475
return CExtNodesFactory .PCallCapiFunctionNodeGen .getUncached ();
2474
2476
}
2475
2477
}
2478
+
2479
+ public enum MayRaiseErrorResult {
2480
+ NATIVE_NULL , NONE , INT , FLOAT
2481
+ }
2476
2482
2477
2483
// -----------------------------------------------------------------------------------------------------------------
2478
2484
@ Builtin (takesVarArgs = true )
2479
2485
public static class MayRaiseNode extends PRootNode {
2480
2486
@ Child private CallTargetInvokeNode callTargetInvokeNode ;
2481
2487
@ Child private TransformExceptionToNativeNode transformExceptionToNativeNode ;
2482
2488
@ Child private CalleeContext calleeContext ;
2489
+
2490
+ @ Child private GetNativeNullNode getNativeNullNode ;
2483
2491
2484
2492
private final Signature signature ;
2485
- private final Object errorResult ;
2493
+ private final MayRaiseErrorResult errorResult ;
2486
2494
2487
- public MayRaiseNode (PythonLanguage lang , Signature sign , RootCallTarget ct , Object errorResult ) {
2495
+ public MayRaiseNode (PythonLanguage lang , Signature sign , RootCallTarget ct , MayRaiseErrorResult errorResult ) {
2488
2496
super (lang );
2489
2497
this .signature = sign ;
2490
2498
this .callTargetInvokeNode = CallTargetInvokeNode .create (ct , false , false );
@@ -2508,7 +2516,7 @@ public final Object execute(VirtualFrame frame) {
2508
2516
} catch (PException e ) {
2509
2517
// transformExceptionToNativeNode acts as a branch profile
2510
2518
ensureTransformExceptionToNativeNode ().execute (frame , e );
2511
- return errorResult ;
2519
+ return getErrorResult () ;
2512
2520
} finally {
2513
2521
calleeContext .exit (frame , this );
2514
2522
}
@@ -2521,6 +2529,24 @@ private TransformExceptionToNativeNode ensureTransformExceptionToNativeNode() {
2521
2529
}
2522
2530
return transformExceptionToNativeNode ;
2523
2531
}
2532
+
2533
+ private Object getErrorResult () {
2534
+ switch (errorResult ) {
2535
+ case INT :
2536
+ return -1 ;
2537
+ case FLOAT :
2538
+ return -1.0 ;
2539
+ case NONE :
2540
+ return PNone .NONE ;
2541
+ case NATIVE_NULL :
2542
+ if (getNativeNullNode == null ) {
2543
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
2544
+ getNativeNullNode = insert (GetNativeNullNodeGen .create ());
2545
+ }
2546
+ return getNativeNullNode .execute ();
2547
+ }
2548
+ throw CompilerDirectives .shouldNotReachHere ();
2549
+ }
2524
2550
2525
2551
@ Override
2526
2552
public Signature getSignature () {
0 commit comments