Skip to content
Snippets Groups Projects

Conditional schedules

Merged Aaron Councilman requested to merge conditional-schedules into main
1 file
+ 1
1
Compare changes
  • Side-by-side
  • Inline
+ 35
0
@@ -16,6 +16,7 @@ use juno_utils::stringtab::StringTable;
use std::cell::RefCell;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::env;
use std::fmt;
use std::fs::File;
use std::io::Write;
@@ -1199,6 +1200,23 @@ fn schedule_interpret(
// were made
Ok(i > 1)
}
ScheduleStmt::IfThenElse { cond, thn, els } => {
let (cond, modified) = interp_expr(pm, cond, stringtab, env, functions)?;
let Value::Boolean { val: cond } = cond else {
return Err(SchedulerError::SemanticError(
"Condition must be a boolean value".to_string(),
));
};
let changed = schedule_interpret(
pm,
if cond { &*thn } else { &*els },
stringtab,
env,
functions,
)?;
Ok(modified || changed)
}
ScheduleStmt::Block { body } => {
let mut modified = false;
env.open_scope();
@@ -1443,6 +1461,23 @@ fn interp_expr(
changed,
))
}
ScheduleExp::Feature { feature } => {
let (feature, modified) = interp_expr(pm, &*feature, stringtab, env, functions)?;
let Value::String { val } = feature else {
return Err(SchedulerError::SemanticError(
"Feature expects a single string argument (instead of a selection)".to_string(),
));
};
// To test for features, the scheduler needs to be invoked from a build script so that
// Cargo provides the enabled features via environment variables
let key = "CARGO_FEATURE_".to_string() + &val.to_uppercase().replace("-", "_");
Ok((
Value::Boolean {
val: env::var(key).is_ok(),
},
modified,
))
}
ScheduleExp::Record { fields } => {
let mut result = HashMap::new();
let mut changed = false;
Loading