mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-30 23:27:39 +00:00
rustpython-bytecode -> rustpython-compiler-core
This commit is contained in:
parent
d60ad9be23
commit
b3095c7451
11 changed files with 25 additions and 23 deletions
|
@ -6,7 +6,7 @@ authors = ["RustPython Team"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rustpython-bytecode = { path = "bytecode" }
|
rustpython-compiler-core = { path = "core" }
|
||||||
rustpython-codegen = { path = "codegen" }
|
rustpython-codegen = { path = "codegen" }
|
||||||
rustpython-parser = { path = "parser" }
|
rustpython-parser = { path = "parser" }
|
||||||
|
|
||||||
|
|
|
@ -12,5 +12,5 @@ unparse = ["rustpython-common"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
num-bigint = "0.4.3"
|
num-bigint = "0.4.3"
|
||||||
rustpython-bytecode = { path = "../bytecode" }
|
rustpython-compiler-core = { path = "../core" }
|
||||||
rustpython-common = { path = "../../common", optional = true }
|
rustpython-common = { path = "../../common", optional = true }
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
pub use rustpython_bytecode::ConversionFlag;
|
pub use rustpython_compiler_core::ConversionFlag;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum Constant {
|
pub enum Constant {
|
||||||
|
|
|
@ -9,7 +9,7 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rustpython-ast = { path = "../ast", features = ["unparse"] }
|
rustpython-ast = { path = "../ast", features = ["unparse"] }
|
||||||
rustpython-bytecode = { path = "../bytecode", version = "0.1.1" }
|
rustpython-compiler-core = { path = "../core", version = "0.1.1" }
|
||||||
|
|
||||||
ahash = "0.7.6"
|
ahash = "0.7.6"
|
||||||
indexmap = "1.8.1"
|
indexmap = "1.8.1"
|
||||||
|
|
|
@ -15,10 +15,10 @@ use itertools::Itertools;
|
||||||
use num_complex::Complex64;
|
use num_complex::Complex64;
|
||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
use rustpython_ast as ast;
|
use rustpython_ast as ast;
|
||||||
use rustpython_bytecode::{self as bytecode, CodeObject, ConstantData, Instruction};
|
use rustpython_compiler_core::{self as bytecode, CodeObject, ConstantData, Instruction};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
pub use rustpython_bytecode::Mode;
|
pub use rustpython_compiler_core::Mode;
|
||||||
|
|
||||||
type CompileResult<T> = Result<T, CodegenError>;
|
type CompileResult<T> = Result<T, CodegenError>;
|
||||||
|
|
||||||
|
@ -2698,7 +2698,7 @@ fn compile_constant(value: &ast::Constant) -> ConstantData {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{CompileOpts, Compiler};
|
use super::{CompileOpts, Compiler};
|
||||||
use crate::symboltable::SymbolTable;
|
use crate::symboltable::SymbolTable;
|
||||||
use rustpython_bytecode::CodeObject;
|
use rustpython_compiler_core::CodeObject;
|
||||||
use rustpython_parser::parser;
|
use rustpython_parser::parser;
|
||||||
|
|
||||||
fn compile_exec(source: &str) -> CodeObject {
|
fn compile_exec(source: &str) -> CodeObject {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::IndexSet;
|
use crate::IndexSet;
|
||||||
use rustpython_bytecode::{CodeFlags, CodeObject, ConstantData, Instruction, Label, Location};
|
use rustpython_compiler_core::{CodeFlags, CodeObject, ConstantData, Instruction, Label, Location};
|
||||||
|
|
||||||
pub type BlockIdx = Label;
|
pub type BlockIdx = Label;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "rustpython-bytecode"
|
name = "rustpython-compiler-core"
|
||||||
description = "RustPython specific bytecode."
|
description = "RustPython specific bytecode."
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
authors = ["RustPython Team"]
|
authors = ["RustPython Team"]
|
|
@ -1,12 +1,6 @@
|
||||||
//! Implement python as a virtual machine with bytecodes. This module
|
//! Implement python as a virtual machine with bytecodes. This module
|
||||||
//! implements bytecode structure.
|
//! implements bytecode structure.
|
||||||
|
|
||||||
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/main/logo.png")]
|
|
||||||
#![doc(html_root_url = "https://docs.rs/rustpython-bytecode/")]
|
|
||||||
|
|
||||||
mod mode;
|
|
||||||
pub use mode::Mode;
|
|
||||||
|
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
use bstr::ByteSlice;
|
use bstr::ByteSlice;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
@ -27,7 +21,7 @@ impl Location {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
/// use rustpython_bytecode::Location;
|
/// use rustpython_compiler_core::Location;
|
||||||
/// let loc = Location::new(10, 10);
|
/// let loc = Location::new(10, 10);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new(row: usize, column: usize) -> Self {
|
pub fn new(row: usize, column: usize) -> Self {
|
||||||
|
@ -433,7 +427,7 @@ bitflags! {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
/// use rustpython_bytecode::ConstantData;
|
/// use rustpython_compiler_core::ConstantData;
|
||||||
/// let a = ConstantData::Float {value: 120f64};
|
/// let a = ConstantData::Float {value: 120f64};
|
||||||
/// let b = ConstantData::Boolean {value: false};
|
/// let b = ConstantData::Boolean {value: false};
|
||||||
/// assert_ne!(a, b);
|
/// assert_ne!(a, b);
|
||||||
|
@ -599,8 +593,8 @@ pub enum TestOperator {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use rustpython_bytecode::Instruction::BinaryOperation;
|
/// use rustpython_compiler_core::Instruction::BinaryOperation;
|
||||||
/// use rustpython_bytecode::BinaryOperator::Add;
|
/// use rustpython_compiler_core::BinaryOperator::Add;
|
||||||
/// let op = BinaryOperation {op: Add};
|
/// let op = BinaryOperation {op: Add};
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
@ -943,7 +937,7 @@ impl Instruction {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use rustpython_bytecode::{Instruction, Label};
|
/// use rustpython_compiler_core::{Instruction, Label};
|
||||||
/// let label = Label(0xF);
|
/// let label = Label(0xF);
|
||||||
/// let jump_inst = Instruction::Jump {target: label};
|
/// let jump_inst = Instruction::Jump {target: label};
|
||||||
/// assert!(jump_inst.unconditional_branch())
|
/// assert!(jump_inst.unconditional_branch())
|
||||||
|
@ -960,7 +954,7 @@ impl Instruction {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use rustpython_bytecode::{Instruction, Label, UnaryOperator};
|
/// use rustpython_compiler_core::{Instruction, Label, UnaryOperator};
|
||||||
/// let jump_instruction = Instruction::Jump {target: Label(0xF)};
|
/// let jump_instruction = Instruction::Jump {target: Label(0xF)};
|
||||||
/// let invert_instruction = Instruction::UnaryOperation {op: UnaryOperator::Invert};
|
/// let invert_instruction = Instruction::UnaryOperation {op: UnaryOperator::Invert};
|
||||||
/// assert_eq!(jump_instruction.stack_effect(true), 0);
|
/// assert_eq!(jump_instruction.stack_effect(true), 0);
|
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;
|
|
@ -1,13 +1,13 @@
|
||||||
use rustpython_bytecode::CodeObject;
|
|
||||||
use rustpython_codegen::{compile, symboltable};
|
use rustpython_codegen::{compile, symboltable};
|
||||||
|
use rustpython_compiler_core::CodeObject;
|
||||||
use rustpython_parser::{
|
use rustpython_parser::{
|
||||||
ast::{fold::Fold, ConstantOptimizer, Location},
|
ast::{fold::Fold, ConstantOptimizer, Location},
|
||||||
parser,
|
parser,
|
||||||
};
|
};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
pub use rustpython_bytecode::Mode;
|
|
||||||
pub use rustpython_codegen::compile::CompileOpts;
|
pub use rustpython_codegen::compile::CompileOpts;
|
||||||
|
pub use rustpython_compiler_core::Mode;
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum CodegenErrorType {
|
pub enum CodegenErrorType {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue