forked from n3tael/labast
Add "call"
This commit is contained in:
parent
065df34eb1
commit
906a72a195
@ -145,6 +145,10 @@ pub fn execute(stack: &mut Stack, mut origin_stack: Option<&mut Stack>, mod_name
|
|||||||
let arg = instruction.arg.clone();
|
let arg = instruction.arg.clone();
|
||||||
instructions::modules::exec(stack, arg, mod_name.clone())
|
instructions::modules::exec(stack, arg, mod_name.clone())
|
||||||
},
|
},
|
||||||
|
"call" => {
|
||||||
|
let arg = instruction.arg.clone();
|
||||||
|
instructions::modules::call(stack, arg)
|
||||||
|
},
|
||||||
"native" => {
|
"native" => {
|
||||||
let arg = instruction.arg.clone();
|
let arg = instruction.arg.clone();
|
||||||
instructions::native::native(stack, arg)
|
instructions::native::native(stack, arg)
|
||||||
|
@ -34,3 +34,27 @@ pub fn exec(mut stack: &mut Stack, arg: String, mod_name: String) {
|
|||||||
stack.memory.push(*item);
|
stack.memory.push(*item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn call(mut stack: &mut Stack, mod_name: String) {
|
||||||
|
let len: u16 = stack.memory.pop();
|
||||||
|
let mut rev: String = String::new();
|
||||||
|
for _i in 0..len {
|
||||||
|
rev.push(stack.memory.pop() as u8 as char);
|
||||||
|
}
|
||||||
|
let tocall: String = rev.chars().rev().collect::<String>();
|
||||||
|
|
||||||
|
if mod_name == tocall {
|
||||||
|
eprintln!("{}", RunError::ExecuteItself(tocall.to_string()));
|
||||||
|
std::process::exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
let lines = fs::read_to_string(&tocall).expect(&format!("{}", RunError::FailToReadFile));
|
||||||
|
let mut temp_stack = Stack::new(stack.memory.size());
|
||||||
|
|
||||||
|
parse(&mut temp_stack, &lines);
|
||||||
|
execute(&mut temp_stack, Some(&mut stack), tocall.clone());
|
||||||
|
|
||||||
|
for item in temp_stack.memory.iter() {
|
||||||
|
stack.memory.push(*item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user