Skip to content

Commit 6af823a

Browse files
committed
Add executable, example, and README.
1 parent efed6a3 commit 6af823a

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@ name = "pythonvm"
33
version = "0.1.0"
44
authors = ["Valentin Lorentz <progval+git@progval.net>"]
55

6+
[lib]
7+
name = "pythonvm"
8+
path = "src/lib.rs"
9+
10+
[[bin]]
11+
name = "pythonvm"
12+
path = "src/bin.rs"
13+
614
[dependencies]

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# pythonvm-rust
2+
3+
A Python virtual machine, written in Rust.
4+
5+
## Features
6+
7+
* prints strings to stdout
8+
* useable as a library
9+
* a fine-grained sandbox
10+
11+
## Try it
12+
13+
1. Install git, [Rust](https://www.rust-lang.org/downloads.html) and [Cargo](https://crates.io/install)
14+
2. `git clone https://github.com/ProgVal/pythonvm-rust.git`
15+
3. `cd pythonvm-rust`
16+
4. `cargo run examples/helloworld.pyc`

examples/helloworld.pyc

121 Bytes
Binary file not shown.

src/bin.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
extern crate pythonvm;
2+
3+
use std::env::args;
4+
use std::fs::File;
5+
6+
fn parse_args() -> (String, Option<String>) {
7+
let mut args = args();
8+
let executable = args.next().unwrap();
9+
let filename = args.next();
10+
let extra = args.next();
11+
match (filename, extra) {
12+
(Some(filename), None) => (executable, Some(filename)),
13+
_ => (executable, None),
14+
}
15+
}
16+
17+
18+
pub fn main() {
19+
let filename = match parse_args() {
20+
(_, Some(filename)) => filename,
21+
(executable, None) => {
22+
println!("Syntax: {} filename.pyc", executable);
23+
return
24+
}
25+
};
26+
let mut file = File::open(filename).unwrap();
27+
let env_proxy = pythonvm::RealEnvProxy::new();
28+
let (_processor, _result) = pythonvm::run_module(&mut file, env_proxy).unwrap();
29+
}

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use std::fmt;
88
use std::io;
99
use processor::Processor;
1010

11+
pub use sandbox::{RealEnvProxy, MockEnvProxy};
12+
1113
#[derive(Debug)]
1214
pub enum InterpreterError {
1315
Io(io::Error),

0 commit comments

Comments
 (0)