rustpython-bytecode -> rustpython-compiler-core

This commit is contained in:
Jeong YunWon
2022-08-22 07:34:30 +09:00
parent 6eeaf976a2
commit fc6d614bf4
24 changed files with 66 additions and 63 deletions

44
Cargo.lock generated
View File

@@ -1735,23 +1735,8 @@ name = "rustpython-ast"
version = "0.1.0"
dependencies = [
"num-bigint",
"rustpython-bytecode",
"rustpython-common",
]
[[package]]
name = "rustpython-bytecode"
version = "0.1.2"
dependencies = [
"bincode",
"bitflags",
"bstr",
"itertools",
"lz4_flex",
"num-bigint",
"num-complex",
"serde",
"static_assertions",
"rustpython-compiler-core",
]
[[package]]
@@ -1766,7 +1751,7 @@ dependencies = [
"num-complex",
"num-traits",
"rustpython-ast",
"rustpython-bytecode",
"rustpython-compiler-core",
"rustpython-parser",
]
@@ -1797,12 +1782,27 @@ dependencies = [
name = "rustpython-compiler"
version = "0.1.2"
dependencies = [
"rustpython-bytecode",
"rustpython-codegen",
"rustpython-compiler-core",
"rustpython-parser",
"thiserror",
]
[[package]]
name = "rustpython-compiler-core"
version = "0.1.2"
dependencies = [
"bincode",
"bitflags",
"bstr",
"itertools",
"lz4_flex",
"num-bigint",
"num-complex",
"serde",
"static_assertions",
]
[[package]]
name = "rustpython-derive"
version = "0.1.2"
@@ -1813,9 +1813,9 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"rustpython-bytecode",
"rustpython-codegen",
"rustpython-compiler",
"rustpython-compiler-core",
"rustpython-doc",
"syn",
"syn-ext",
@@ -1840,7 +1840,7 @@ dependencies = [
"cranelift-module",
"libffi",
"num-traits",
"rustpython-bytecode",
"rustpython-compiler-core",
"rustpython-derive",
"thiserror",
]
@@ -1872,7 +1872,7 @@ name = "rustpython-pylib"
version = "0.1.0"
dependencies = [
"glob",
"rustpython-bytecode",
"rustpython-compiler-core",
"rustpython-derive",
]
@@ -1991,10 +1991,10 @@ dependencies = [
"result-like",
"rustc_version",
"rustpython-ast",
"rustpython-bytecode",
"rustpython-codegen",
"rustpython-common",
"rustpython-compiler",
"rustpython-compiler-core",
"rustpython-derive",
"rustpython-jit",
"rustpython-parser",

View File

@@ -14,7 +14,7 @@ include = ["LICENSE", "Cargo.toml", "src/**/*.rs"]
[workspace]
resolver = "2"
members = [
"compiler", "compiler/ast", "compiler/bytecode", "compiler/codegen", "compiler/parser",
"compiler", "compiler/ast", "compiler/core", "compiler/codegen", "compiler/parser",
".", "common", "derive", "jit", "vm", "vm/pylib-crate", "stdlib", "wasm/lib",
]

View File

@@ -6,7 +6,7 @@ authors = ["RustPython Team"]
edition = "2021"
[dependencies]
rustpython-bytecode = { path = "bytecode" }
rustpython-compiler-core = { path = "core" }
rustpython-codegen = { path = "codegen" }
rustpython-parser = { path = "parser" }

View File

@@ -12,5 +12,5 @@ unparse = ["rustpython-common"]
[dependencies]
num-bigint = "0.4.3"
rustpython-bytecode = { path = "../bytecode" }
rustpython-compiler-core = { path = "../core" }
rustpython-common = { path = "../../common", optional = true }

View File

@@ -1,5 +1,5 @@
use num_bigint::BigInt;
pub use rustpython_bytecode::ConversionFlag;
pub use rustpython_compiler_core::ConversionFlag;
#[derive(Debug, PartialEq)]
pub enum Constant {

View File

@@ -9,7 +9,7 @@ edition = "2021"
[dependencies]
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"
indexmap = "1.8.1"

View File

@@ -15,10 +15,10 @@ use itertools::Itertools;
use num_complex::Complex64;
use num_traits::ToPrimitive;
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;
pub use rustpython_bytecode::Mode;
pub use rustpython_compiler_core::Mode;
type CompileResult<T> = Result<T, CodegenError>;
@@ -2698,7 +2698,7 @@ fn compile_constant(value: &ast::Constant) -> ConstantData {
mod tests {
use super::{CompileOpts, Compiler};
use crate::symboltable::SymbolTable;
use rustpython_bytecode::CodeObject;
use rustpython_compiler_core::CodeObject;
use rustpython_parser::parser;
fn compile_exec(source: &str) -> CodeObject {

View File

@@ -1,5 +1,5 @@
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;

View File

@@ -1,5 +1,5 @@
[package]
name = "rustpython-bytecode"
name = "rustpython-compiler-core"
description = "RustPython specific bytecode."
version = "0.1.2"
authors = ["RustPython Team"]

View File

@@ -1,12 +1,6 @@
//! Implement python as a virtual machine with bytecodes. This module
//! 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 bstr::ByteSlice;
use itertools::Itertools;
@@ -27,7 +21,7 @@ impl Location {
///
/// # Example
/// ```
/// use rustpython_bytecode::Location;
/// use rustpython_compiler_core::Location;
/// let loc = Location::new(10, 10);
/// ```
pub fn new(row: usize, column: usize) -> Self {
@@ -433,7 +427,7 @@ bitflags! {
///
/// # Examples
/// ```
/// use rustpython_bytecode::ConstantData;
/// use rustpython_compiler_core::ConstantData;
/// let a = ConstantData::Float {value: 120f64};
/// let b = ConstantData::Boolean {value: false};
/// assert_ne!(a, b);
@@ -599,8 +593,8 @@ pub enum TestOperator {
/// # Examples
///
/// ```
/// use rustpython_bytecode::Instruction::BinaryOperation;
/// use rustpython_bytecode::BinaryOperator::Add;
/// use rustpython_compiler_core::Instruction::BinaryOperation;
/// use rustpython_compiler_core::BinaryOperator::Add;
/// let op = BinaryOperation {op: Add};
/// ```
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
@@ -943,7 +937,7 @@ impl Instruction {
/// # Examples
///
/// ```
/// use rustpython_bytecode::{Instruction, Label};
/// use rustpython_compiler_core::{Instruction, Label};
/// let label = Label(0xF);
/// let jump_inst = Instruction::Jump {target: label};
/// assert!(jump_inst.unconditional_branch())
@@ -960,7 +954,7 @@ impl Instruction {
/// # Examples
///
/// ```
/// use rustpython_bytecode::{Instruction, Label, UnaryOperator};
/// use rustpython_compiler_core::{Instruction, Label, UnaryOperator};
/// let jump_instruction = Instruction::Jump {target: Label(0xF)};
/// let invert_instruction = Instruction::UnaryOperation {op: UnaryOperator::Invert};
/// assert_eq!(jump_instruction.stack_effect(true), 0);

8
compiler/core/src/lib.rs Normal file
View 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;

View File

@@ -1,13 +1,13 @@
use rustpython_bytecode::CodeObject;
use rustpython_codegen::{compile, symboltable};
use rustpython_compiler_core::CodeObject;
use rustpython_parser::{
ast::{fold::Fold, ConstantOptimizer, Location},
parser,
};
use std::fmt;
pub use rustpython_bytecode::Mode;
pub use rustpython_codegen::compile::CompileOpts;
pub use rustpython_compiler_core::Mode;
#[derive(Debug, thiserror::Error)]
pub enum CodegenErrorType {

View File

@@ -11,9 +11,9 @@ edition = "2021"
proc-macro = true
[dependencies]
rustpython-bytecode = { path = "../compiler/bytecode", version = "0.1.1" }
rustpython-codegen = { path = "../compiler/codegen", version = "0.1.1" }
rustpython-compiler = { path = "../compiler", version = "0.1.1" }
rustpython-compiler-core = { path = "../compiler/core", version = "0.1.1" }
rustpython-doc = { git = "https://github.com/RustPython/__doc__", branch = "main" }
indexmap = "1.8.1"

View File

@@ -17,9 +17,9 @@ use crate::{extract_spans, Diagnostic};
use once_cell::sync::Lazy;
use proc_macro2::{Span, TokenStream};
use quote::quote;
use rustpython_bytecode::{CodeObject, FrozenModule};
use rustpython_codegen as codegen;
use rustpython_compiler::compile;
use rustpython_compiler_core::{CodeObject, FrozenModule};
use std::{
collections::HashMap,
env, fs,
@@ -380,7 +380,8 @@ pub fn impl_py_freeze(input: TokenStream) -> Result<TokenStream, Diagnostic> {
let crate_name = args.crate_name;
let code_map = args.source.compile(args.mode, args.module_name)?;
let data = rustpython_bytecode::frozen_lib::encode_lib(code_map.iter().map(|(k, v)| (&**k, v)));
let data =
rustpython_compiler_core::frozen_lib::encode_lib(code_map.iter().map(|(k, v)| (&**k, v)));
let bytes = LitByteStr::new(&data, Span::call_site());
let output = quote! {

View File

@@ -14,7 +14,7 @@ macro_rules! add_python_function {
( $scope:ident, $vm:ident, $src:literal $(,)? ) => {{
// compile the code to bytecode
let code = vm::py_compile!(source = $src);
// convert the rustpython_bytecode::CodeObject to a PyRef<PyCode>
// convert the rustpython_compiler_core::CodeObject to a PyRef<PyCode>
let code = $vm.ctx.new_code(code);
// run the python code in the scope to store the function

View File

@@ -10,7 +10,7 @@ edition = "2021"
autotests = false
[dependencies]
rustpython-bytecode = { path = "../compiler/bytecode", version = "0.1.2" }
rustpython-compiler-core = { path = "../compiler/core", version = "0.1.2" }
cranelift = "0.76.0"
cranelift-jit = "0.76.0"

View File

@@ -1,6 +1,6 @@
use cranelift::prelude::*;
use num_traits::cast::ToPrimitive;
use rustpython_bytecode::{
use rustpython_compiler_core::{
self as bytecode, BinaryOperator, BorrowedConstant, CodeObject, ComparisonOperator,
Instruction, Label, UnaryOperator,
};

View File

@@ -4,7 +4,7 @@ use cranelift::prelude::*;
use cranelift_jit::{JITBuilder, JITModule};
use cranelift_module::{FuncId, Linkage, Module, ModuleError};
use instructions::FunctionCompiler;
use rustpython_bytecode as bytecode;
use rustpython_compiler_core as bytecode;
use std::{fmt, mem::ManuallyDrop};
#[derive(Debug, thiserror::Error)]

View File

@@ -1,4 +1,4 @@
use rustpython_bytecode::{CodeObject, ConstantData, Instruction};
use rustpython_compiler_core::{CodeObject, ConstantData, Instruction};
use rustpython_jit::{CompiledCode, JitType};
use std::collections::HashMap;
@@ -157,7 +157,7 @@ macro_rules! jit_function {
($func_name:ident => $($t:tt)*) => {
{
let code = rustpython_derive::py_compile!(
crate_name = "rustpython_bytecode",
crate_name = "rustpython_compiler_core",
source = $($t)*
);
let mut machine = $crate::common::StackMachine::new();

View File

@@ -27,7 +27,7 @@ rustpython-compiler = { path = "../compiler", optional = true, version = "0.1.2"
rustpython-ast = { path = "../compiler/ast", optional = true, version = "0.1" }
rustpython-parser = { path = "../compiler/parser", optional = true, version = "0.1.2" }
rustpython-codegen = { path = "../compiler/codegen", optional = true, version = "0.1.2" }
rustpython-bytecode = { path = "../compiler/bytecode", version = "0.1.2" }
rustpython-compiler-core = { path = "../compiler/core", version = "0.1.2" }
rustpython-common = { path = "../common" }
rustpython-derive = { path = "../derive", version = "0.1.2" }
rustpython-jit = { path = "../jit", optional = true, version = "0.1.2" }

View File

@@ -12,7 +12,7 @@ include = ["Cargo.toml", "src/**/*.rs", "Lib/", "!Lib/**/test/", "!Lib/**/*.pyc"
freeze-stdlib = []
[dependencies]
rustpython-bytecode = { version = "0.1.2", path = "../../compiler/bytecode" }
rustpython-compiler-core = { version = "0.1.2", path = "../../compiler/core" }
rustpython-derive = { version = "0.1.2", path = "../../derive" }
[build-dependencies]

View File

@@ -9,12 +9,12 @@ pub const LIB_PATH: &str = match option_env!("win_lib_path") {
None => concat!(env!("CARGO_MANIFEST_DIR"), "/../../Lib"),
};
use rustpython_bytecode::FrozenModule;
use rustpython_compiler_core::FrozenModule;
pub fn frozen_builtins() -> impl Iterator<Item = (String, FrozenModule)> {
rustpython_derive::py_freeze!(
dir = "../Lib/python_builtins",
crate_name = "rustpython_bytecode"
crate_name = "rustpython_compiler_core"
)
}
@@ -22,11 +22,11 @@ pub fn frozen_builtins() -> impl Iterator<Item = (String, FrozenModule)> {
pub fn frozen_core() -> impl Iterator<Item = (String, FrozenModule)> {
rustpython_derive::py_freeze!(
dir = "../Lib/core_modules",
crate_name = "rustpython_bytecode"
crate_name = "rustpython_compiler_core"
)
}
#[cfg(feature = "freeze-stdlib")]
pub fn frozen_stdlib() -> impl Iterator<Item = (String, FrozenModule)> {
rustpython_derive::py_freeze!(dir = "../../Lib", crate_name = "rustpython_bytecode")
rustpython_derive::py_freeze!(dir = "../../Lib", crate_name = "rustpython_compiler_core")
}

View File

@@ -84,15 +84,15 @@ pub use self::object::{
};
pub use self::vm::{Context, Interpreter, Settings, VirtualMachine};
pub use rustpython_bytecode as bytecode;
pub use rustpython_common as common;
pub use rustpython_compiler_core as bytecode;
pub mod compile {
pub use rustpython_bytecode::Mode;
#[cfg(feature = "rustpython-codegen")]
pub use rustpython_codegen::CompileOpts;
#[cfg(feature = "rustpython-compiler")]
pub use rustpython_compiler::*;
pub use rustpython_compiler_core::Mode;
}
#[doc(hidden)]