Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn impl_from_args(input: &DeriveInput) -> TokenStream2 {
quote! {
impl crate::function::FromArgs for #name {
fn from_args(
vm: &mut crate::vm::VirtualMachine,
vm: &crate::vm::VirtualMachine,
args: &mut crate::function::PyFuncArgs
) -> Result<Self, crate::function::ArgumentError> {
Ok(#name { #(#fields)* })
Expand Down
26 changes: 13 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,26 @@ fn main() {
.get_matches();

// Construct vm:
let mut vm = VirtualMachine::new();
let vm = VirtualMachine::new();

// Figure out if a -c option was given:
let result = if let Some(command) = matches.value_of("c") {
run_command(&mut vm, command.to_string())
run_command(&vm, command.to_string())
} else if let Some(module) = matches.value_of("m") {
run_module(&mut vm, module)
run_module(&vm, module)
} else {
// Figure out if a script was passed:
match matches.value_of("script") {
None => run_shell(&mut vm),
Some(filename) => run_script(&mut vm, filename),
None => run_shell(&vm),
Some(filename) => run_script(&vm, filename),
}
};

// See if any exception leaked out:
handle_exception(&mut vm, result);
handle_exception(&vm, result);
}

fn _run_string(vm: &mut VirtualMachine, source: &str, source_path: String) -> PyResult {
fn _run_string(vm: &VirtualMachine, source: &str, source_path: String) -> PyResult {
let code_obj = compile::compile(
source,
&compile::Mode::Exec,
Expand All @@ -80,28 +80,28 @@ fn _run_string(vm: &mut VirtualMachine, source: &str, source_path: String) -> Py
vm.run_code_obj(code_obj, vars)
}

fn handle_exception(vm: &mut VirtualMachine, result: PyResult) {
fn handle_exception(vm: &VirtualMachine, result: PyResult) {
if let Err(err) = result {
print_exception(vm, &err);
std::process::exit(1);
}
}

fn run_command(vm: &mut VirtualMachine, mut source: String) -> PyResult {
fn run_command(vm: &VirtualMachine, mut source: String) -> PyResult {
debug!("Running command {}", source);

// This works around https://github.com/RustPython/RustPython/issues/17
source.push('\n');
_run_string(vm, &source, "<stdin>".to_string())
}

fn run_module(vm: &mut VirtualMachine, module: &str) -> PyResult {
fn run_module(vm: &VirtualMachine, module: &str) -> PyResult {
debug!("Running module {}", module);
let current_path = PathBuf::from(".");
import::import_module(vm, current_path, module)
}

fn run_script(vm: &mut VirtualMachine, script_file: &str) -> PyResult {
fn run_script(vm: &VirtualMachine, script_file: &str) -> PyResult {
debug!("Running file {}", script_file);
// Parse an ast from it:
let file_path = Path::new(script_file);
Expand All @@ -114,7 +114,7 @@ fn run_script(vm: &mut VirtualMachine, script_file: &str) -> PyResult {
}
}

fn shell_exec(vm: &mut VirtualMachine, source: &str, scope: Scope) -> Result<(), CompileError> {
fn shell_exec(vm: &VirtualMachine, source: &str, scope: Scope) -> Result<(), CompileError> {
match compile::compile(
source,
&compile::Mode::Single,
Expand Down Expand Up @@ -153,7 +153,7 @@ fn get_history_path() -> PathBuf {
xdg_dirs.place_cache_file("repl_history.txt").unwrap()
}

fn run_shell(vm: &mut VirtualMachine) -> PyResult {
fn run_shell(vm: &VirtualMachine) -> PyResult {
println!(
"Welcome to the magnificent Rust Python {} interpreter",
crate_version!()
Expand Down
Loading