pyo3_ffi/cpython/
compile.rs

1#[cfg(not(any(PyPy, Py_3_10)))]
2use crate::object::PyObject;
3#[cfg(not(any(PyPy, Py_3_10)))]
4use crate::pyarena::*;
5#[cfg(not(any(PyPy, Py_3_10)))]
6use crate::pythonrun::*;
7#[cfg(not(any(PyPy, Py_3_10)))]
8use crate::PyCodeObject;
9use crate::INT_MAX;
10#[cfg(not(any(PyPy, Py_3_10)))]
11use std::os::raw::c_char;
12use std::os::raw::c_int;
13
14// skipped PyCF_MASK
15// skipped PyCF_MASK_OBSOLETE
16// skipped PyCF_SOURCE_IS_UTF8
17// skipped PyCF_DONT_IMPLY_DEDENT
18// skipped PyCF_ONLY_AST
19// skipped PyCF_IGNORE_COOKIE
20// skipped PyCF_TYPE_COMMENTS
21// skipped PyCF_ALLOW_TOP_LEVEL_AWAIT
22// skipped PyCF_OPTIMIZED_AST
23// skipped PyCF_COMPILE_MASK
24
25#[repr(C)]
26#[derive(Copy, Clone)]
27pub struct PyCompilerFlags {
28    pub cf_flags: c_int,
29    #[cfg(Py_3_8)]
30    pub cf_feature_version: c_int,
31}
32
33// skipped _PyCompilerFlags_INIT
34
35// NB this type technically existed in the header until 3.13, when it was
36// moved to the internal CPython headers.
37//
38// We choose not to expose it in the public API past 3.10, as it is
39// not used in the public API past that point.
40#[cfg(not(any(PyPy, GraalPy, Py_3_10)))]
41#[repr(C)]
42#[derive(Copy, Clone)]
43pub struct PyFutureFeatures {
44    pub ff_features: c_int,
45    pub ff_lineno: c_int,
46}
47
48// FIXME: these constants should probably be &CStr, if they are used at all
49
50pub const FUTURE_NESTED_SCOPES: &str = "nested_scopes";
51pub const FUTURE_GENERATORS: &str = "generators";
52pub const FUTURE_DIVISION: &str = "division";
53pub const FUTURE_ABSOLUTE_IMPORT: &str = "absolute_import";
54pub const FUTURE_WITH_STATEMENT: &str = "with_statement";
55pub const FUTURE_PRINT_FUNCTION: &str = "print_function";
56pub const FUTURE_UNICODE_LITERALS: &str = "unicode_literals";
57pub const FUTURE_BARRY_AS_BDFL: &str = "barry_as_FLUFL";
58pub const FUTURE_GENERATOR_STOP: &str = "generator_stop";
59pub const FUTURE_ANNOTATIONS: &str = "annotations";
60
61#[cfg(not(any(PyPy, GraalPy, Py_3_10)))]
62extern "C" {
63    pub fn PyNode_Compile(arg1: *mut _node, arg2: *const c_char) -> *mut PyCodeObject;
64
65    pub fn PyAST_CompileEx(
66        _mod: *mut _mod,
67        filename: *const c_char,
68        flags: *mut PyCompilerFlags,
69        optimize: c_int,
70        arena: *mut PyArena,
71    ) -> *mut PyCodeObject;
72
73    pub fn PyAST_CompileObject(
74        _mod: *mut _mod,
75        filename: *mut PyObject,
76        flags: *mut PyCompilerFlags,
77        optimize: c_int,
78        arena: *mut PyArena,
79    ) -> *mut PyCodeObject;
80
81    pub fn PyFuture_FromAST(_mod: *mut _mod, filename: *const c_char) -> *mut PyFutureFeatures;
82
83    pub fn PyFuture_FromASTObject(
84        _mod: *mut _mod,
85        filename: *mut PyObject,
86    ) -> *mut PyFutureFeatures;
87}
88
89pub const PY_INVALID_STACK_EFFECT: c_int = INT_MAX;
90
91extern "C" {
92
93    pub fn PyCompile_OpcodeStackEffect(opcode: c_int, oparg: c_int) -> c_int;
94
95    #[cfg(Py_3_8)]
96    pub fn PyCompile_OpcodeStackEffectWithJump(opcode: c_int, oparg: c_int, jump: c_int) -> c_int;
97}
⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here