git.delta.rocks / jrsonnet / refs/commits / 3c251da01a10

difftreelog

feat minimal tco

yzrzokypYaroslav Bolyukin2026-05-07parent: #e468723.patch.diff
in: master

3 files changed

modifiedcrates/jrsonnet-evaluator/src/evaluate/destructure.rsdiffbeforeafterboth
5use crate::{5use crate::{
6 Context, LocalsFrame, PackedContext, Result, SupThis, Thunk, Unbound, Val,6 Context, LocalsFrame, PackedContext, Result, SupThis, Thunk, Unbound, Val,
7 analyze::{7 analyze::{ClosureShape, LBind, LDestruct, LDestructField, LDestructRest, LocalSlot},
8 ClosureShape, LBind, LDestruct, LDestructField, LDestructRest, LLocalExpr, LocalSlot,
9 },
10 bail,8 bail,
11 evaluate::evaluate,9 evaluate::evaluate,
189 }187 }
190}188}
191
192pub fn evaluate_local_expr(parent: Context, l: &LLocalExpr) -> Result<Val> {
193 let ctx = parent
194 .pack_captures_sup_this(&l.frame_shape)
195 .enter(|fill, ctx| {
196 fill_letrec_binds(fill, ctx, &l.binds);
197 });
198 evaluate(ctx, &l.body)
199}
200189
201pub trait CloneableUnbound<T>: Unbound<Bound = T> + Clone {}190pub trait CloneableUnbound<T>: Unbound<Bound = T> + Clone {}
202impl<V, T> CloneableUnbound<T> for V where V: Unbound<Bound = T> + Clone {}191impl<V, T> CloneableUnbound<T> for V where V: Unbound<Bound = T> + Clone {}
modifiedcrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth
77
8use self::{8use self::{
9 compspec::{evaluate_arr_comp, evaluate_obj_comp},9 compspec::{evaluate_arr_comp, evaluate_obj_comp},
10 destructure::{evaluate_local_expr, evaluate_locals_unbound},10 destructure::evaluate_locals_unbound,
11 operator::evaluate_binary_op_special,11 operator::evaluate_binary_op_special,
12};12};
13use crate::{13use crate::{
116}116}
117117
118#[allow(clippy::too_many_lines)]118#[allow(clippy::too_many_lines)]
119pub fn evaluate(ctx: Context, expr: &LExpr) -> Result<Val> {119pub fn evaluate(mut ctx: Context, mut expr: &LExpr) -> Result<Val> {
120 loop {
120 Ok(match expr {121 return Ok(match expr {
121 LExpr::Null => Val::Null,122 LExpr::Null => Val::Null,
122 LExpr::Bool(b) => Val::Bool(*b),123 LExpr::Bool(b) => Val::Bool(*b),
123 LExpr::Str(s) => Val::string(s.clone()),124 LExpr::Str(s) => Val::string(s.clone()),
130 evaluate_unary_op(*op, &value)?131 evaluate_unary_op(*op, &value)?
131 }132 }
132 LExpr::BinaryOp { lhs, op, rhs } => evaluate_binary_op_special(ctx, lhs, *op, rhs)?,133 LExpr::BinaryOp { lhs, op, rhs } => evaluate_binary_op_special(ctx, lhs, *op, rhs)?,
133 LExpr::LocalExpr(local_expr) => evaluate_local_expr(ctx, local_expr)?,134 LExpr::LocalExpr(l) => {
135 ctx = ctx
136 .pack_captures_sup_this(&l.frame_shape)
137 .enter(|fill, ctx| {
138 fill_letrec_binds(fill, ctx, &l.binds);
139 });
140 expr = &l.body;
141 continue;
142 }
134 LExpr::IfElse {143 LExpr::IfElse {
135 cond,144 cond,
136 cond_then,145 cond_then,
145 ))154 ))
146 };155 };
147 if b {156 if b {
148 evaluate(ctx, cond_then)?157 expr = cond_then;
158 continue;
149 } else if let Some(e) = cond_else {159 } else if let Some(e) = cond_else {
150 evaluate(ctx, e)?160 expr = e;
161 continue;
151 } else {162 }
152 Val::Null163 Val::Null
153 }
154 }164 }
155 LExpr::Error(s, e) => in_frame(165 LExpr::Error(s, e) => in_frame(
156 CallLocation::new(s),166 CallLocation::new(s),
159 )?,169 )?,
160 LExpr::AssertExpr { assert, rest } => {170 LExpr::AssertExpr { assert, rest } => {
161 evaluate_assert(ctx.clone(), assert)?;171 evaluate_assert(ctx.clone(), assert)?;
162 evaluate(ctx, rest)?172 expr = rest;
173 continue;
163 }174 }
164175
165 LExpr::Function(func) => evaluate_method(176 LExpr::Function(func) => evaluate_method(
238 ImportKind::Bin => Val::arr(state.import_resolved_bin(resolved)?),251 ImportKind::Bin => Val::arr(state.import_resolved_bin(resolved)?),
239 })252 })
240 })?,253 })?,
241 })254 });
255 }
242}256}
243257
244fn evaluate_apply(258fn evaluate_apply(
modifiedcrates/jrsonnet-evaluator/src/function/mod.rsdiffbeforeafterboth
14 Context, PackedContextSupThis, Result, Thunk, Val,14 Context, PackedContextSupThis, Result, Thunk, Val,
15 analyze::LFunction,15 analyze::LFunction,
16 arr::arridx,16 arr::arridx,
17 ensure_sufficient_stack,
17 evaluate::{destructure::destruct, ensure_sufficient_stack, evaluate, evaluate_trivial},18 evaluate::{destructure::destruct, evaluate, evaluate_trivial},
18 function::builtin::BuiltinFunc,19 function::builtin::BuiltinFunc,
19};20};
2021
68 self.func.signature.clone()69 self.func.signature.clone()
69 }70 }
7071
71 pub fn call(72 fn call(
72 &self,73 &self,
73 unnamed: &[Thunk<Val>],74 unnamed: &[Thunk<Val>],
74 named: &[Thunk<Val>],75 named: &[Thunk<Val>],