mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 19:24:57 +08:00
52 lines
1.2 KiB
Rust
52 lines
1.2 KiB
Rust
//extern crate rustpython_parser;
|
|
#[macro_use]
|
|
extern crate clap;
|
|
extern crate env_logger;
|
|
#[macro_use]
|
|
extern crate log;
|
|
extern crate rustpython_parser;
|
|
extern crate rustpython_vm;
|
|
|
|
mod compile;
|
|
use clap::{Arg, App};
|
|
use std::path::Path;
|
|
use rustpython_parser::parse;
|
|
use rustpython_vm::evaluate;
|
|
|
|
|
|
fn main() {
|
|
env_logger::init();
|
|
let matches = App::new("RustPython")
|
|
.version(crate_version!())
|
|
.author(crate_authors!())
|
|
.about("Rust implementation of the Python language")
|
|
.arg(Arg::with_name("script")
|
|
.required(true)
|
|
.index(1))
|
|
.arg(Arg::with_name("v")
|
|
.short("v")
|
|
.multiple(true)
|
|
.help("Give the verbosity"))
|
|
.get_matches();
|
|
|
|
// Figure out the filename:
|
|
let script_file = matches.value_of("script").unwrap_or("foo");
|
|
debug!("Running file {}", script_file);
|
|
|
|
// Parse an ast from it:
|
|
let filepath = Path::new(script_file);
|
|
match parse(filepath) {
|
|
Ok(program) => {
|
|
debug!("Got ast: {:?}", program);
|
|
let bytecode = compile::compile(program);
|
|
debug!("Code object: {:?}", bytecode);
|
|
evaluate(bytecode);
|
|
},
|
|
Err(msg) => {
|
|
error!("Parsing went horribly wrong: {}", msg);
|
|
std::process::exit(1);
|
|
},
|
|
}
|
|
}
|
|
|