mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-27 05:44:52 +00:00
rustpython-bytecode -> rustpython-compiler-core
This commit is contained in:
parent
acde8bb625
commit
c16e650071
7 changed files with 18 additions and 16 deletions
19
core/Cargo.toml
Normal file
19
core/Cargo.toml
Normal file
|
@ -0,0 +1,19 @@
|
|||
[package]
|
||||
name = "rustpython-compiler-core"
|
||||
description = "RustPython specific bytecode."
|
||||
version = "0.1.2"
|
||||
authors = ["RustPython Team"]
|
||||
edition = "2021"
|
||||
repository = "https://github.com/RustPython/RustPython"
|
||||
license = "MIT"
|
||||
|
||||
[dependencies]
|
||||
bincode = "1.3.3"
|
||||
bitflags = "1.3.2"
|
||||
bstr = "0.2.17"
|
||||
itertools = "0.10.3"
|
||||
lz4_flex = "0.9.2"
|
||||
num-bigint = { version = "0.4.3", features = ["serde"] }
|
||||
num-complex = { version = "0.4.0", features = ["serde"] }
|
||||
serde = { version = "1.0.136", features = ["derive"] }
|
||||
static_assertions = "1.1.0"
|
1392
core/src/bytecode.rs
Normal file
1392
core/src/bytecode.rs
Normal file
File diff suppressed because it is too large
Load diff
8
core/src/lib.rs
Normal file
8
core/src/lib.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/main/logo.png")]
|
||||
#![doc(html_root_url = "https://docs.rs/rustpython-compiler-core/")]
|
||||
|
||||
pub mod bytecode;
|
||||
mod mode;
|
||||
|
||||
pub use bytecode::*;
|
||||
pub use mode::Mode;
|
32
core/src/mode.rs
Normal file
32
core/src/mode.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
#[derive(Clone, Copy)]
|
||||
pub enum Mode {
|
||||
Exec,
|
||||
Eval,
|
||||
Single,
|
||||
BlockExpr,
|
||||
}
|
||||
|
||||
impl std::str::FromStr for Mode {
|
||||
type Err = ModeParseError;
|
||||
|
||||
// To support `builtins.compile()` `mode` argument
|
||||
fn from_str(s: &str) -> Result<Self, ModeParseError> {
|
||||
match s {
|
||||
"exec" => Ok(Mode::Exec),
|
||||
"eval" => Ok(Mode::Eval),
|
||||
"single" => Ok(Mode::Single),
|
||||
_ => Err(ModeParseError { _priv: () }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ModeParseError {
|
||||
_priv: (),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for ModeParseError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, r#"mode should be "exec", "eval", or "single""#)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue