|
212 | 212 | import com.oracle.truffle.api.CompilerDirectives;
|
213 | 213 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
214 | 214 | import com.oracle.truffle.api.RootCallTarget;
|
| 215 | +import com.oracle.truffle.api.TruffleLanguage.Env; |
215 | 216 | import com.oracle.truffle.api.TruffleLogger;
|
216 | 217 | import com.oracle.truffle.api.dsl.Cached;
|
217 | 218 | import com.oracle.truffle.api.dsl.Cached.Exclusive;
|
|
232 | 233 | import com.oracle.truffle.api.interop.UnsupportedMessageException;
|
233 | 234 | import com.oracle.truffle.api.interop.UnsupportedTypeException;
|
234 | 235 | import com.oracle.truffle.api.library.CachedLibrary;
|
| 236 | +import com.oracle.truffle.api.nodes.LanguageInfo; |
235 | 237 | import com.oracle.truffle.api.nodes.Node;
|
236 | 238 | import com.oracle.truffle.api.nodes.RootNode;
|
237 | 239 | import com.oracle.truffle.api.object.DynamicObjectLibrary;
|
|
241 | 243 | import com.oracle.truffle.api.profiles.LoopConditionProfile;
|
242 | 244 | import com.oracle.truffle.api.profiles.ValueProfile;
|
243 | 245 | import com.oracle.truffle.api.utilities.CyclicAssumption;
|
| 246 | +import com.oracle.truffle.llvm.api.Toolchain; |
244 | 247 |
|
245 | 248 | @CoreFunctions(defineModule = PythonCextBuiltins.PYTHON_CEXT)
|
246 | 249 | @GenerateNodeFactory
|
@@ -269,6 +272,15 @@ public void initialize(Python3Core core) {
|
269 | 272 | builtinConstants.put("PyGILState_Release", new PyGILStateRelease());
|
270 | 273 | }
|
271 | 274 |
|
| 275 | + @Override |
| 276 | + public void postInitialize(Python3Core core) { |
| 277 | + super.postInitialize(core); |
| 278 | + if (!core.getContext().getOption(PythonOptions.EnableDebuggingBuiltins)) { |
| 279 | + PythonModule mod = core.lookupBuiltinModule(PYTHON_CEXT); |
| 280 | + mod.setAttribute("PyTruffle_ToNative", PNone.NO_VALUE); |
| 281 | + } |
| 282 | + } |
| 283 | + |
272 | 284 | @FunctionalInterface
|
273 | 285 | public interface TernaryFunction<T1, T2, T3, R> {
|
274 | 286 | R apply(T1 arg0, T2 arg1, T3 arg2);
|
@@ -2376,15 +2388,33 @@ Object tssDelete(Object key,
|
2376 | 2388 | }
|
2377 | 2389 | }
|
2378 | 2390 |
|
| 2391 | + // directly called without landing function |
2379 | 2392 | @Builtin(name = "PyTruffle_Debug", takesVarArgs = true)
|
2380 | 2393 | @GenerateNodeFactory
|
2381 | 2394 | public abstract static class PyTruffleDebugNode extends PythonBuiltinNode {
|
2382 | 2395 | @Specialization
|
2383 | 2396 | @TruffleBoundary
|
2384 |
| - public Object doIt(Object[] args, |
| 2397 | + static Object doIt(Object[] args, |
2385 | 2398 | @Cached DebugNode debugNode) {
|
2386 | 2399 | debugNode.execute(args);
|
2387 | 2400 | return PNone.NONE;
|
2388 | 2401 | }
|
2389 | 2402 | }
|
| 2403 | + |
| 2404 | + // directly called without landing function |
| 2405 | + @Builtin(name = "PyTruffle_ToNative", minNumOfPositionalArgs = 1) |
| 2406 | + @GenerateNodeFactory |
| 2407 | + public abstract static class PyTruffleToNativeNode extends PythonUnaryBuiltinNode { |
| 2408 | + @Specialization |
| 2409 | + @TruffleBoundary |
| 2410 | + Object doIt(Object object) { |
| 2411 | + Env env = getContext().getEnv(); |
| 2412 | + LanguageInfo llvmInfo = env.getInternalLanguages().get(PythonLanguage.LLVM_LANGUAGE); |
| 2413 | + Toolchain toolchain = env.lookup(llvmInfo, Toolchain.class); |
| 2414 | + if ("native".equals(toolchain.getIdentifier())) { |
| 2415 | + InteropLibrary.getUncached().toNative(object); |
| 2416 | + } |
| 2417 | + return PNone.NONE; |
| 2418 | + } |
| 2419 | + } |
2390 | 2420 | }
|
0 commit comments