python3_sys/
compile.rs

1#![allow(unused_imports)]  // imports only used in some configurations
2
3use libc::{c_char, c_int};
4
5use crate::code::*;
6use crate::object::PyObject;
7use crate::pyarena::*;
8use crate::pythonrun::*;
9
10#[repr(C)]
11#[derive(Copy, Clone)]
12#[cfg(Py_3_12)]
13pub struct _PyCompilerSrcLocation {
14    pub lineno: c_int,
15    pub end_lineno: c_int,
16    pub col_offset: c_int,
17    pub end_col_offset: c_int,
18}
19
20#[repr(C)]
21#[derive(Copy, Clone)]
22#[cfg(not(Py_LIMITED_API))]
23pub struct PyFutureFeatures {
24    pub ff_features: c_int,
25    #[cfg(not(Py_3_12))]
26    pub ff_lineno: c_int,
27    #[cfg(Py_3_12)]
28    pub ff_location: _PyCompilerSrcLocation,
29}
30
31// TODO: PyCF_MASK etc. constants
32
33// Note: struct PyCompilerFlags was moved from pythonrun.h to compile.h in Python 3.7;
34// We still have our version in pythonrun.rs
35
36#[cfg(not(Py_LIMITED_API))]
37pub const FUTURE_NESTED_SCOPES: &str = "nested_scopes";
38#[cfg(not(Py_LIMITED_API))]
39pub const FUTURE_GENERATORS: &str = "generators";
40#[cfg(not(Py_LIMITED_API))]
41pub const FUTURE_DIVISION: &str = "division";
42#[cfg(not(Py_LIMITED_API))]
43pub const FUTURE_ABSOLUTE_IMPORT: &str = "absolute_import";
44#[cfg(not(Py_LIMITED_API))]
45pub const FUTURE_WITH_STATEMENT: &str = "with_statement";
46#[cfg(not(Py_LIMITED_API))]
47pub const FUTURE_PRINT_FUNCTION: &str = "print_function";
48#[cfg(not(Py_LIMITED_API))]
49pub const FUTURE_UNICODE_LITERALS: &str = "unicode_literals";
50#[cfg(not(Py_LIMITED_API))]
51pub const FUTURE_BARRY_AS_BDFL: &str = "barry_as_FLUFL";
52#[cfg(all(not(Py_LIMITED_API), Py_3_5))]
53pub const FUTURE_GENERATOR_STOP: &str = "generator_stop";
54#[cfg(all(not(Py_LIMITED_API), Py_3_7))]
55pub const FUTURE_ANNOTATIONS: &str = "annotations";
56
57#[cfg(not(Py_LIMITED_API))]
58#[cfg_attr(windows, link(name = "pythonXY"))]
59extern "C" {
60    #[cfg(not(Py_3_10))]
61    pub fn PyNode_Compile(arg1: *mut _node, arg2: *const c_char) -> *mut PyCodeObject;
62    #[cfg(not(Py_3_10))]
63    pub fn PyAST_CompileEx(
64        _mod: *mut _mod,
65        filename: *const c_char,
66        flags: *mut PyCompilerFlags,
67        optimize: c_int,
68        arena: *mut PyArena,
69    ) -> *mut PyCodeObject;
70    #[cfg(all(Py_3_4, not(Py_3_10)))]
71    pub fn PyAST_CompileObject(
72        _mod: *mut _mod,
73        filename: *mut PyObject,
74        flags: *mut PyCompilerFlags,
75        optimize: c_int,
76        arena: *mut PyArena,
77    ) -> *mut PyCodeObject;
78    #[cfg(not(Py_3_10))]
79    pub fn PyFuture_FromAST(_mod: *mut _mod, filename: *const c_char) -> *mut PyFutureFeatures;
80    #[cfg(all(Py_3_4, not(Py_3_10)))]
81    pub fn PyFuture_FromASTObject(
82        _mod: *mut _mod,
83        filename: *mut PyObject,
84    ) -> *mut PyFutureFeatures;
85    #[cfg(Py_3_4)]
86    pub fn PyCompile_OpcodeStackEffect(opcode: c_int, oparg: c_int) -> c_int;
87    #[cfg(Py_3_8)]
88    pub fn PyCompile_OpcodeStackEffectWithJump(opcode: c_int, oparg: c_int, jump: c_int) -> c_int;
89}
90
91pub const Py_single_input: c_int = 256;
92pub const Py_file_input: c_int = 257;
93pub const Py_eval_input: c_int = 258;
94#[cfg(Py_3_8)]
95pub const Py_func_type_input: c_int = 345;
96#[cfg(Py_3_9)]
97pub const Py_fstring_input: c_int = 800;