Interpreter - Handle return value in functions
This commit is contained in:
parent
0de6b927b5
commit
d6ea1c3099
1 changed files with 5 additions and 3 deletions
|
@ -5,7 +5,7 @@ use itertools::izip;
|
|||
use crate::{
|
||||
ast,
|
||||
errors::InterpreterError,
|
||||
interpreter::{Environment, Interpretable},
|
||||
interpreter::{Environment, Interpretable, InterpreterFlowControl},
|
||||
tokens::Token,
|
||||
};
|
||||
|
||||
|
@ -54,8 +54,10 @@ impl Callable for Function {
|
|||
let child = Environment::create_child(¶m_env);
|
||||
for stmt in self.body.iter() {
|
||||
let result = stmt.interpret(&child)?;
|
||||
if result.is_flow_control() {
|
||||
panic!("unexpected flow control");
|
||||
match result {
|
||||
InterpreterFlowControl::Result(_) => (),
|
||||
InterpreterFlowControl::Return(v) => return Ok(v),
|
||||
_ => panic!("unexpected flow control {:?}", result),
|
||||
}
|
||||
}
|
||||
Ok(Value::Nil)
|
||||
|
|
Loading…
Reference in a new issue