1
1
/*
2
- * Copyright (c) 2021, 2023 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2021, 2024 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* The Universal Permissive License (UPL), Version 1.0
40
40
*/
41
41
package com .oracle .graal .python .builtins .modules ;
42
42
43
+ import static com .oracle .graal .python .nodes .SpecialAttributeNames .T___ALL__ ;
44
+ import static com .oracle .graal .python .util .PythonUtils .tsLiteral ;
45
+
43
46
import java .io .IOException ;
47
+ import java .util .ArrayList ;
44
48
import java .util .List ;
45
49
46
50
import com .oracle .graal .python .PythonLanguage ;
57
61
import com .oracle .graal .python .builtins .objects .cext .common .LoadCExtException .ImportException ;
58
62
import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyContext ;
59
63
import com .oracle .graal .python .builtins .objects .cext .hpy .HPyMode ;
64
+ import com .oracle .graal .python .builtins .objects .module .PythonModule ;
60
65
import com .oracle .graal .python .lib .PyObjectGetItem ;
61
66
import com .oracle .graal .python .nodes .ErrorMessages ;
62
67
import com .oracle .graal .python .nodes .PConstructAndRaiseNode ;
73
78
import com .oracle .graal .python .runtime .IndirectCallData ;
74
79
import com .oracle .graal .python .runtime .PythonContext ;
75
80
import com .oracle .graal .python .runtime .exception .PException ;
76
- import com .oracle .graal .python .util .PythonUtils ;
77
81
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
78
82
import com .oracle .truffle .api .dsl .Bind ;
79
83
import com .oracle .truffle .api .dsl .Cached ;
88
92
@ GenerateNodeFactory
89
93
public final class GraalHPyUniversalModuleBuiltins extends PythonBuiltins {
90
94
91
- public static final String J_HPY_UNIVERSAL = "_hpy_universal" ;
95
+ static final String J_HPY_UNIVERSAL = "_hpy_universal" ;
96
+ private static final TruffleString T_HPY_UNIVERSAL = tsLiteral (J_HPY_UNIVERSAL );
97
+ private static final TruffleString T_HPY = tsLiteral ("HPY" );
98
+
99
+ private static final TruffleString [] ALL_ARRAY ;
100
+
101
+ static {
102
+ List <TruffleString > allList = new ArrayList <>();
103
+ for (HPyMode mode : HPyMode .values ()) {
104
+ allList .add (tsLiteral (mode .name ()));
105
+ }
106
+ allList .add (tsLiteral ("load" ));
107
+ allList .add (tsLiteral ("_load_bootstrap" ));
108
+ ALL_ARRAY = allList .toArray (new TruffleString [0 ]);
109
+ }
92
110
93
111
@ Override
94
112
protected List <? extends NodeFactory <? extends PythonBuiltinBaseNode >> getNodeFactories () {
@@ -103,6 +121,12 @@ public void initialize(Python3Core core) {
103
121
super .initialize (core );
104
122
}
105
123
124
+ @ Override
125
+ public void postInitialize (Python3Core core ) {
126
+ PythonModule module = core .lookupBuiltinModule (T_HPY_UNIVERSAL );
127
+ module .setAttribute (T___ALL__ , core .factory ().createTuple (ALL_ARRAY ));
128
+ }
129
+
106
130
@ Builtin (name = "load" , parameterNames = {"name" , "path" , "spec" , "debug" , "mode" }, minNumOfPositionalArgs = 3 )
107
131
@ GenerateNodeFactory
108
132
@ ArgumentClinic (name = "name" , conversion = ClinicConversion .TString )
@@ -205,7 +229,7 @@ static Object doGeneric(VirtualFrame frame, TruffleString name, TruffleString ex
205
229
private static HPyMode getHPyModeFromEnviron (TruffleString moduleName , Object env ) throws CannotCastException {
206
230
Object result ;
207
231
try {
208
- result = PyObjectGetItem .executeUncached (env , PythonUtils . tsLiteral ( "HPY" ) );
232
+ result = PyObjectGetItem .executeUncached (env , T_HPY );
209
233
} catch (PException e ) {
210
234
e .expect (null , PythonBuiltinClassType .KeyError , IsBuiltinObjectProfile .getUncached ());
211
235
// this is not an error; it just means that the key was not present in 'env'
0 commit comments