20 lines
575 B
Rust
20 lines
575 B
Rust
use std::fs;
|
|
use crate::{parse, execute, Stack, errors::RunError};
|
|
|
|
pub fn exec(mut stack: &mut Stack, arg: &String, mod_name: &String) {
|
|
if mod_name == arg {
|
|
eprintln!("{}", RunError::ExecuteItself(arg.to_string()));
|
|
std::process::exit(2);
|
|
}
|
|
|
|
let lines = fs::read_to_string(&arg).expect(&format!("{}", RunError::FailToReadFile));
|
|
let mut temp_stack = Stack::new();
|
|
|
|
parse(&mut temp_stack, &lines);
|
|
|
|
execute(&mut temp_stack, Some(&mut stack), &arg.clone());
|
|
|
|
for item in temp_stack.memory {
|
|
stack.memory.push(item);
|
|
}
|
|
} |