From bbc19305f825b8d2ec2c25da98068cf8ea2f0b0a Mon Sep 17 00:00:00 2001 From: Windel Bouwman Date: Wed, 18 Jul 2018 10:22:00 +0200 Subject: [PATCH] Reduce dependencies of vm and parser crates --- Cargo.lock | 75 ------------------------------------------ Lib/re.py | 11 +++++++ parser/Cargo.toml | 2 -- tests/test_snippets.py | 2 +- vm/Cargo.toml | 1 - vm/src/builtins.rs | 2 +- vm/src/lib.rs | 3 +- vm/src/pyobject.rs | 21 ++++++++++++ vm/src/sysmodule.rs | 15 +++++++++ 9 files changed, 51 insertions(+), 81 deletions(-) create mode 100644 Lib/re.py create mode 100644 vm/src/sysmodule.rs diff --git a/Cargo.lock b/Cargo.lock index 35bedf2f7f..d912c39272 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,11 +1,3 @@ -[[package]] -name = "aho-corasick" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "aho-corasick" version = "0.6.4" @@ -141,15 +133,6 @@ name = "ena" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "env_logger" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "env_logger" version = "0.5.10" @@ -296,14 +279,6 @@ dependencies = [ "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "memchr" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "memchr" version = "2.0.1" @@ -416,18 +391,6 @@ dependencies = [ "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "regex" -version = "0.1.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "regex" version = "0.2.11" @@ -452,11 +415,6 @@ dependencies = [ "utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "regex-syntax" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "regex-syntax" version = "0.4.2" @@ -493,8 +451,6 @@ dependencies = [ name = "rustpython_parser" version = "0.0.1" dependencies = [ - "clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "lalrpop 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "lalrpop-util 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -505,7 +461,6 @@ dependencies = [ name = "rustpython_vm" version = "0.1.0" dependencies = [ - "env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "rustpython_parser 0.0.1", ] @@ -627,23 +582,6 @@ dependencies = [ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "thread-id" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "thread_local" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "thread_local" version = "0.3.5" @@ -681,11 +619,6 @@ dependencies = [ "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "utf8-ranges" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "utf8-ranges" version = "1.0.0" @@ -739,7 +672,6 @@ dependencies = [ ] [metadata] -"checksum aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66" "checksum aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d6531d44de723825aa81398a6415283229725a00fa30713812ab9323faa82fc4" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum arrayref 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0fd1479b7c29641adbd35ff3b5c293922d696a92f25c8c975da3e0acbc87258f" @@ -758,7 +690,6 @@ dependencies = [ "checksum docopt 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d8acd393692c503b168471874953a2531df0e9ab77d0b6bbc582395743300a4a" "checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0" "checksum ena 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cabe5a5078ac8c506d3e4430763b1ba9b609b1286913e7d08e581d1c2de9b7e5" -"checksum env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "15abd780e45b3ea4f76b4e9a26ff4843258dd8a3eed2775a0e7368c2e7936c2f" "checksum env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0e6e40ebb0e66918a37b38c7acab4e10d299e0463fe2af5d29b9cc86710cfd2a" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" "checksum fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33" @@ -775,7 +706,6 @@ dependencies = [ "checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6fddaa003a65722a7fb9e26b0ce95921fe4ba590542ced664d8ce2fa26f9f3ac" -"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20" "checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d" "checksum new_debug_unreachable 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0cdc457076c78ab54d5e0d6fa7c47981757f1e34dc39ff92787f217dede586c4" "checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063" @@ -791,10 +721,8 @@ dependencies = [ "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" "checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)" = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f" "checksum regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384" "checksum regex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75ecf88252dce580404a22444fc7d626c01815debba56a7f4f536772a5ff19d3" -"checksum regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957" "checksum regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8e931c58b93d86f080c734bfd2bce7dd0079ae2331235818133c8be7f422e20e" "checksum regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7" "checksum regex-syntax 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8f1ac0f60d675cc6cf13a20ec076568254472551051ad5dd050364d70671bf6b" @@ -812,15 +740,12 @@ dependencies = [ "checksum termcolor 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "adc4587ead41bf016f11af03e55a624c06568b5a19db4e90fde573d805074f83" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0b59b6b4b44d867f1370ef1bd91bfb262bf07bf0ae65c202ea2fbc16153b693" -"checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03" -"checksum thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5" "checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963" "checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" "checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d" "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" -"checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f" "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" diff --git a/Lib/re.py b/Lib/re.py new file mode 100644 index 0000000000..8511222be3 --- /dev/null +++ b/Lib/re.py @@ -0,0 +1,11 @@ + +""" Regular expressions """ + + +def match(pattern, string, flags=0): + return _compile(pattern, flags).match(string) + + +def _compile(pattern, flags): + p = sre_compile.compile(pattern, flags) + return p diff --git a/parser/Cargo.toml b/parser/Cargo.toml index 24997cfbf4..745b14b984 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -8,8 +8,6 @@ build = "build.rs" lalrpop="0.15.1" [dependencies] -clap="2.20.0" -env_logger="0.5.10" lalrpop-util="0.15.1" log="0.4.1" regex="0.2.2" diff --git a/tests/test_snippets.py b/tests/test_snippets.py index 6307f09299..243e7ccdb6 100644 --- a/tests/test_snippets.py +++ b/tests/test_snippets.py @@ -65,7 +65,7 @@ def run_via_rustpython(filename): env['RUST_LOG'] = 'trace' env['RUST_BACKTRACE'] = '1' with pushd(RUSTPYTHON_RUNNER_DIR): - subprocess.check_call(['cargo', 'run', filename], env=env) + subprocess.check_call(['cargo', 'run', '--release', filename], env=env) def create_test_function(cls, filename, method): diff --git a/vm/Cargo.toml b/vm/Cargo.toml index b66e5cc03d..d5df380357 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -5,5 +5,4 @@ authors = ["Shing Lyu "] [dependencies] log = "0.3" -env_logger = "0.3" rustpython_parser = {path = "../parser"} diff --git a/vm/src/builtins.rs b/vm/src/builtins.rs index d79f0c7e67..6f565c67b6 100644 --- a/vm/src/builtins.rs +++ b/vm/src/builtins.rs @@ -42,7 +42,7 @@ pub fn print(rt: &mut Executor, args: Vec) -> PyResult { // println!("Woot: {:?}", args); trace!("print called with {:?}", args); for a in args { - print!("{} ", a.borrow_mut().str()); + print!("{} ", a.borrow().str()); } println!(); io::stdout().flush().unwrap(); diff --git a/vm/src/lib.rs b/vm/src/lib.rs index 7890bc4e6d..5b32a09647 100644 --- a/vm/src/lib.rs +++ b/vm/src/lib.rs @@ -1,6 +1,6 @@ #[macro_use] extern crate log; -extern crate env_logger; +// extern crate env_logger; //extern crate eval; use eval::eval::*; // use py_code_object::{Function, NativeType, PyCodeObject}; @@ -17,6 +17,7 @@ mod objstr; mod objtuple; mod objtype; pub mod pyobject; +mod sysmodule; mod vm; pub use self::pyobject::Executor; diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index fa047d64bb..e2f3e30341 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -67,6 +67,24 @@ impl PyContext { PyObject::new(PyObjectKind::Boolean { value: b }, self.type_type.clone()) } + pub fn new_tuple(&self) -> PyObjectRef { + PyObject::new( + PyObjectKind::Tuple { + elements: Vec::new(), + }, + self.type_type.clone(), + ) + } + + pub fn new_list(&self) -> PyObjectRef { + PyObject::new( + PyObjectKind::List { + elements: Vec::new(), + }, + self.type_type.clone(), + ) + } + pub fn new_dict(&self) -> PyObjectRef { PyObject::new( PyObjectKind::Dict { @@ -162,6 +180,9 @@ pub enum PyObjectKind { Integer { value: i32, }, + Float { + value: f64, + }, Boolean { value: bool, }, diff --git a/vm/src/sysmodule.rs b/vm/src/sysmodule.rs new file mode 100644 index 0000000000..8431785ebd --- /dev/null +++ b/vm/src/sysmodule.rs @@ -0,0 +1,15 @@ +use super::pyobject::{Executor, PyObject, PyObjectKind, PyObjectRef}; + +/* + * The magic sys module. + */ + + +/* + * TODO: +fn mk_module(rt: &mut Executor) -> PyObjectRef { + let path = rt.new_list(); + let obj = rt.new_module("sys"); + obj +} +*/