Skip to content

Commit

Permalink
fix: eval hangs for ever
Browse files Browse the repository at this point in the history
  • Loading branch information
ali77gh committed Oct 10, 2023
1 parent e3b1509 commit 33473bd
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/eval/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::common::errors::{Result, ErrorType};
use crate::common::errors::ErrorType;
use crate::preprocessor::Preprocessor;
use crate::parser::Parser;
use crate::runtime::Runtime;

pub fn eval(code: String, std_out: fn(&str), std_in: fn() -> String, on_exit: fn(), on_error: fn(&str)) -> Result<()>{
pub fn eval(code: String, std_out: fn(&str), std_in: fn() -> String, on_exit: fn(), on_error: fn(&str)) {

// initialize
let mut preprocessor = Preprocessor::default();
Expand Down Expand Up @@ -31,12 +31,24 @@ pub fn eval(code: String, std_out: fn(&str), std_in: fn() -> String, on_exit: fn
loop {
if let Err(e) = runtime.execution_cycle(){
match e.err_type {
ErrorType::NothingToExecute | ErrorType::Stop => on_exit(),
ErrorType::NothingToExecute | ErrorType::Stop => {on_exit();return;},
_=> {
on_error(e.error_message().as_str());
}
}
}
}

}


#[cfg(test)]
mod tests{
use super::eval;

#[test]
fn test_eval(){
eval(
"3".to_string(), |x|{}, ||{"".to_string()}, ||{}, |e|{});
}
}

0 comments on commit 33473bd

Please sign in to comment.