-
-
Notifications
You must be signed in to change notification settings - Fork 415
/
Copy pathmod.rs
30 lines (28 loc) · 894 Bytes
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use super::{Executable, Interpreter};
use crate::{
builtins::value::{ResultValue, Value},
syntax::ast::node::Switch,
};
impl Executable for Switch {
fn run(&self, interpreter: &mut Interpreter) -> ResultValue {
let default = self.default();
let val = self.val().run(interpreter)?;
let mut result = Value::null();
let mut matched = false;
for case in self.cases().iter() {
let cond = case.condition();
let block = case.body();
if val.strict_equals(&cond.run(interpreter)?) {
matched = true;
block.run(interpreter)?;
}
// TODO: break out of switch on a break statement.
}
if !matched {
if let Some(default) = default {
result = default.run(interpreter)?;
}
}
Ok(result)
}
}