intent_runtime/value.rs
1use serde_json::Value;
2use std::collections::HashMap;
3
4/// Context for expression evaluation.
5///
6/// Holds variable bindings (action parameters, quantifier bindings),
7/// optional old-state bindings for `old()` references in postconditions,
8/// and entity instances for quantifier iteration.
9#[derive(Debug, Clone, Default)]
10pub struct EvalContext {
11 /// Current variable bindings (params, quantifier bindings).
12 pub bindings: HashMap<String, Value>,
13 /// Old-state bindings for `old()` references. If `None`, `old()` is invalid.
14 pub old_bindings: Option<HashMap<String, Value>>,
15 /// Entity instances by type name, for `forall`/`exists` evaluation.
16 pub instances: HashMap<String, Vec<Value>>,
17}
18
19impl EvalContext {
20 pub fn new() -> Self {
21 Self::default()
22 }
23
24 /// Create a child context with an additional binding (for quantifier evaluation).
25 pub fn with_binding(&self, name: String, value: Value) -> Self {
26 let mut child = self.clone();
27 child.bindings.insert(name, value);
28 child
29 }
30}