From fc6d614bf4fda00d75862d356657bf33776eaf00 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Mon, 22 Aug 2022 07:34:30 +0900 Subject: [PATCH] rustpython-bytecode -> rustpython-compiler-core --- Cargo.lock | 44 +++++++++---------- Cargo.toml | 2 +- compiler/Cargo.toml | 2 +- compiler/ast/Cargo.toml | 2 +- compiler/ast/src/constant.rs | 2 +- compiler/codegen/Cargo.toml | 2 +- compiler/codegen/src/compile.rs | 6 +-- compiler/codegen/src/ir.rs | 2 +- compiler/{bytecode => core}/Cargo.toml | 2 +- .../src/lib.rs => core/src/bytecode.rs} | 18 +++----- compiler/core/src/lib.rs | 8 ++++ compiler/{bytecode => core}/src/mode.rs | 0 compiler/src/lib.rs | 4 +- derive/Cargo.toml | 2 +- derive/src/compile_bytecode.rs | 5 ++- examples/mini_repl.rs | 2 +- jit/Cargo.toml | 2 +- jit/src/instructions.rs | 2 +- jit/src/lib.rs | 2 +- jit/tests/common.rs | 4 +- vm/Cargo.toml | 2 +- vm/pylib-crate/Cargo.toml | 2 +- vm/pylib-crate/src/lib.rs | 8 ++-- vm/src/lib.rs | 4 +- 24 files changed, 66 insertions(+), 63 deletions(-) rename compiler/{bytecode => core}/Cargo.toml (93%) rename compiler/{bytecode/src/lib.rs => core/src/bytecode.rs} (98%) create mode 100644 compiler/core/src/lib.rs rename compiler/{bytecode => core}/src/mode.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index f87870a88..d5f2f4c65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/Cargo.toml b/Cargo.toml index 25f8c3add..a8bb4a721 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", ] diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index 00fc91479..118286f4f 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -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" } diff --git a/compiler/ast/Cargo.toml b/compiler/ast/Cargo.toml index 39eedf4f4..7efefb3ad 100644 --- a/compiler/ast/Cargo.toml +++ b/compiler/ast/Cargo.toml @@ -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 } diff --git a/compiler/ast/src/constant.rs b/compiler/ast/src/constant.rs index 1d1655943..b73bab628 100644 --- a/compiler/ast/src/constant.rs +++ b/compiler/ast/src/constant.rs @@ -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 { diff --git a/compiler/codegen/Cargo.toml b/compiler/codegen/Cargo.toml index 77cd70735..424d85a6a 100644 --- a/compiler/codegen/Cargo.toml +++ b/compiler/codegen/Cargo.toml @@ -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" diff --git a/compiler/codegen/src/compile.rs b/compiler/codegen/src/compile.rs index 59d9faaff..0b5935889 100644 --- a/compiler/codegen/src/compile.rs +++ b/compiler/codegen/src/compile.rs @@ -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 = Result; @@ -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 { diff --git a/compiler/codegen/src/ir.rs b/compiler/codegen/src/ir.rs index 39c3ad1fb..c1ed1dd7b 100644 --- a/compiler/codegen/src/ir.rs +++ b/compiler/codegen/src/ir.rs @@ -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; diff --git a/compiler/bytecode/Cargo.toml b/compiler/core/Cargo.toml similarity index 93% rename from compiler/bytecode/Cargo.toml rename to compiler/core/Cargo.toml index 05d698ede..5821ddc37 100644 --- a/compiler/bytecode/Cargo.toml +++ b/compiler/core/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "rustpython-bytecode" +name = "rustpython-compiler-core" description = "RustPython specific bytecode." version = "0.1.2" authors = ["RustPython Team"] diff --git a/compiler/bytecode/src/lib.rs b/compiler/core/src/bytecode.rs similarity index 98% rename from compiler/bytecode/src/lib.rs rename to compiler/core/src/bytecode.rs index c53697bcc..8e9cc75b1 100644 --- a/compiler/bytecode/src/lib.rs +++ b/compiler/core/src/bytecode.rs @@ -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); diff --git a/compiler/core/src/lib.rs b/compiler/core/src/lib.rs new file mode 100644 index 000000000..ac798da57 --- /dev/null +++ b/compiler/core/src/lib.rs @@ -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; diff --git a/compiler/bytecode/src/mode.rs b/compiler/core/src/mode.rs similarity index 100% rename from compiler/bytecode/src/mode.rs rename to compiler/core/src/mode.rs diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs index 6996589a9..5f3e72cc4 100644 --- a/compiler/src/lib.rs +++ b/compiler/src/lib.rs @@ -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 { diff --git a/derive/Cargo.toml b/derive/Cargo.toml index 594750bc1..1b36bacda 100644 --- a/derive/Cargo.toml +++ b/derive/Cargo.toml @@ -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" diff --git a/derive/src/compile_bytecode.rs b/derive/src/compile_bytecode.rs index 63b52ec2d..2f9b0edc7 100644 --- a/derive/src/compile_bytecode.rs +++ b/derive/src/compile_bytecode.rs @@ -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 { 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! { diff --git a/examples/mini_repl.rs b/examples/mini_repl.rs index 7ea4c2d74..cc85bf8b5 100644 --- a/examples/mini_repl.rs +++ b/examples/mini_repl.rs @@ -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 + // convert the rustpython_compiler_core::CodeObject to a PyRef let code = $vm.ctx.new_code(code); // run the python code in the scope to store the function diff --git a/jit/Cargo.toml b/jit/Cargo.toml index 23e3304d0..1b07ba88e 100644 --- a/jit/Cargo.toml +++ b/jit/Cargo.toml @@ -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" diff --git a/jit/src/instructions.rs b/jit/src/instructions.rs index ab08b524b..13f93bda8 100644 --- a/jit/src/instructions.rs +++ b/jit/src/instructions.rs @@ -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, }; diff --git a/jit/src/lib.rs b/jit/src/lib.rs index 5c6ff01a6..8c45a4776 100644 --- a/jit/src/lib.rs +++ b/jit/src/lib.rs @@ -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)] diff --git a/jit/tests/common.rs b/jit/tests/common.rs index 762170e44..369b7f614 100644 --- a/jit/tests/common.rs +++ b/jit/tests/common.rs @@ -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(); diff --git a/vm/Cargo.toml b/vm/Cargo.toml index a1954da57..4a188af1b 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -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" } diff --git a/vm/pylib-crate/Cargo.toml b/vm/pylib-crate/Cargo.toml index 79c7cb3a0..9f3e31a02 100644 --- a/vm/pylib-crate/Cargo.toml +++ b/vm/pylib-crate/Cargo.toml @@ -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] diff --git a/vm/pylib-crate/src/lib.rs b/vm/pylib-crate/src/lib.rs index c26ba193d..d3d6bd9ee 100644 --- a/vm/pylib-crate/src/lib.rs +++ b/vm/pylib-crate/src/lib.rs @@ -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 { 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 { pub fn frozen_core() -> impl Iterator { 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 { - rustpython_derive::py_freeze!(dir = "../../Lib", crate_name = "rustpython_bytecode") + rustpython_derive::py_freeze!(dir = "../../Lib", crate_name = "rustpython_compiler_core") } diff --git a/vm/src/lib.rs b/vm/src/lib.rs index 066af1598..e4ce18be9 100644 --- a/vm/src/lib.rs +++ b/vm/src/lib.rs @@ -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)]