Skip to content

Commit d50d920

Browse files
author
Daniel Watkins
committed
Refactor script running to separate method
1 parent dbae0b0 commit d50d920

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

src/main.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,26 @@ fn main() {
3838
}
3939
}
4040

41-
fn run_script(script_file: &String) {
41+
fn _run_string(source: &String) {
4242
let mut vm = VirtualMachine::new();
43+
let code_obj = compile::compile(&mut vm, &source, compile::Mode::Exec).unwrap();
44+
debug!("Code object: {:?}", code_obj.borrow());
45+
let builtins = vm.get_builtin_scope();
46+
let vars = vm.new_scope(Some(builtins)); // Keep track of local variables
47+
match vm.run_code_obj(code_obj, vars) {
48+
Ok(_value) => {}
49+
Err(exc) => {
50+
panic!("Exception: {:?}", exc);
51+
}
52+
}
53+
}
54+
55+
fn run_script(script_file: &String) {
4356
debug!("Running file {}", script_file);
4457
// Parse an ast from it:
4558
let filepath = Path::new(script_file);
4659
match parser::read_file(filepath) {
47-
Ok(source) => {
48-
let code_obj = compile::compile(&mut vm, &source, compile::Mode::Exec).unwrap();
49-
debug!("Code object: {:?}", code_obj.borrow());
50-
let builtins = vm.get_builtin_scope();
51-
let vars = vm.new_scope(Some(builtins)); // Keep track of local variables
52-
match vm.run_code_obj(code_obj, vars) {
53-
Ok(_value) => {
54-
}
55-
Err(exc) => {
56-
panic!("Exception: {:?}", exc);
57-
}
58-
}
59-
}
60+
Ok(source) => _run_string(&source),
6061
Err(msg) => {
6162
error!("Parsing went horribly wrong: {}", msg);
6263
std::process::exit(1);

0 commit comments

Comments
 (0)