Support iterating over reflective lists
This commit is contained in:
parent
cdba03c5d7
commit
1a1dc740e8
@ -203,6 +203,32 @@ impl<'a, O: OutputSystem + Send, LS: LocalisationSystem + Sync + Send> Interpret
|
|||||||
self.scopes[scope_idx].variables.remove(binding as &str);
|
self.scopes[scope_idx].variables.remove(binding as &str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Value::Reflective(reflective) => match reflective.reflect_ref() {
|
||||||
|
ReflectRef::List(list) => {
|
||||||
|
if list.is_empty() {
|
||||||
|
self.run_steps(scope_idx, empty_steps).await?;
|
||||||
|
} else {
|
||||||
|
for idx in 0..list.len() {
|
||||||
|
// TODO(performance) I'd like to remove this clone!
|
||||||
|
// Can possibly do so with a Yoke or something...
|
||||||
|
let val = list.get(idx).expect("checked iter").clone_value();
|
||||||
|
self.scopes[scope_idx].variables.insert(
|
||||||
|
String::from(binding as &str),
|
||||||
|
Value::from_reflect(val),
|
||||||
|
);
|
||||||
|
self.run_steps(scope_idx, body_steps).await?;
|
||||||
|
}
|
||||||
|
self.scopes[scope_idx].variables.remove(binding as &str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
other => {
|
||||||
|
return Err(InterpreterError::TypeError {
|
||||||
|
context: "For".to_string(),
|
||||||
|
conflict: format!("not iterable reflective: {reflective:?}."),
|
||||||
|
location: step.locator.clone(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
// TODO string?
|
// TODO string?
|
||||||
// TODO map (with k,v binding)?
|
// TODO map (with k,v binding)?
|
||||||
other => {
|
other => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user