feat: rec attrset

This commit is contained in:
2025-08-08 12:12:23 +08:00
parent 67cdcfea33
commit a9cfddbf5c
13 changed files with 147 additions and 180 deletions

View File

@@ -23,7 +23,7 @@ mod value;
/// A trait defining the context in which LIR expressions are evaluated.
pub trait EvalContext: Sized {
/// Evaluates an expression by its ID.
fn eval(&mut self, expr: &ExprId) -> Result<Value>;
fn eval(&mut self, expr: ExprId) -> Result<Value>;
/// Enters a `with` scope for the duration of a closure's execution.
fn with_with_env<T>(
@@ -61,7 +61,7 @@ pub trait Evaluate<Ctx: EvalContext> {
impl<Ctx: EvalContext> Evaluate<Ctx> for ExprId {
/// Evaluating an `ExprId` simply delegates to the context.
fn eval(&self, ctx: &mut Ctx) -> Result<Value> {
ctx.eval(self)
ctx.eval(*self)
}
}
@@ -85,8 +85,8 @@ impl<Ctx: EvalContext> Evaluate<Ctx> for lir::Lir {
Str(x) => x.eval(ctx),
Var(x) => x.eval(ctx),
Path(x) => x.eval(ctx),
ExprRef(expr) => ctx.eval(expr),
FuncRef(func) => Ok(Value::Func(unsafe { func.clone() })),
&ExprRef(expr) => ctx.eval(expr),
&FuncRef(func) => Ok(Value::Func(func)),
&ArgRef(idx) => Ok(ctx.lookup_arg(idx).clone()),
&PrimOp(primop) => Ok(Value::PrimOp(primop)),
}
@@ -109,7 +109,7 @@ impl<Ctx: EvalContext> Evaluate<Ctx> for ir::AttrSet {
let mut k = k.eval(ctx)?;
k.coerce_to_string();
let v_eval_result = v.eval(ctx)?;
attrs.push_attr(k.unwrap_string(), v_eval_result);
attrs.push_attr(k.unwrap_string(), v_eval_result)?;
}
let result = Value::AttrSet(attrs.into());
Ok(result)