git.delta.rocks / jrsonnet / refs/commits / a47ce2dc6910

difftreelog

refactor objextend can use the same object

zloyqryzYaroslav Bolyukin2026-03-23parent: #bb0b902.patch.diff
in: master

1 file changed

modifiedcrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth
16 bail,16 bail,
17 destructure::evaluate_dest,17 destructure::evaluate_dest,
18 error::{suggest_object_fields, ErrorKind::*},18 error::{suggest_object_fields, ErrorKind::*},
19 evaluate::operator::{evaluate_add_op, evaluate_binary_op_special, evaluate_unary_op},19 evaluate::operator::{evaluate_binary_op_special, evaluate_unary_op},
20 function::{CallLocation, FuncDesc, FuncVal},20 function::{CallLocation, FuncDesc, FuncVal},
21 gc::WithCapacityExt as _,21 gc::WithCapacityExt as _,
22 in_frame,22 in_frame,
284284
285#[allow(clippy::too_many_lines)]285#[allow(clippy::too_many_lines)]
286pub fn evaluate_member_list_object(ctx: Context, members: &ObjMembers) -> Result<ObjValue> {286pub fn evaluate_member_list_object(
287 super_obj: Option<ObjValue>,
288 ctx: Context,
289 members: &ObjMembers,
290) -> Result<ObjValue> {
287 let mut builder = ObjValueBuilder::new();291 let mut builder = ObjValueBuilder::new();
292 if let Some(super_obj) = super_obj {
293 builder.with_super(super_obj);
294 }
295
288 let locals = members.locals.clone();296 let locals = members.locals.clone();
289297
319}327}
320328
321pub fn evaluate_object(ctx: Context, object: &ObjBody) -> Result<ObjValue> {329pub fn evaluate_object(
330 super_obj: Option<ObjValue>,
331 ctx: Context,
332 object: &ObjBody,
333) -> Result<ObjValue> {
322 Ok(match object {334 Ok(match object {
323 ObjBody::MemberList(members) => evaluate_member_list_object(ctx, members)?,335 ObjBody::MemberList(members) => evaluate_member_list_object(super_obj, ctx, members)?,
324 ObjBody::ObjComp(obj) => {336 ObjBody::ObjComp(obj) => {
325 let mut builder = ObjValueBuilder::new();337 let mut builder = ObjValueBuilder::new();
338 if let Some(super_obj) = super_obj {
339 builder.with_super(super_obj);
340 }
326 let locals = obj.locals.clone();341 let locals = obj.locals.clone();
327 evaluate_comp(ctx, &obj.compspecs, &mut |ctx| {342 evaluate_comp(ctx, &obj.compspecs, &mut |ctx| {
328 let uctx = evaluate_object_locals(ctx.clone(), locals.clone());343 let uctx = evaluate_object_locals(ctx.clone(), locals.clone());
584 })?;599 })?;
585 Val::Arr(ArrValue::lazy(out))600 Val::Arr(ArrValue::lazy(out))
586 }601 }
587 Obj(body) => Val::Obj(evaluate_object(ctx, body)?),602 Obj(body) => Val::Obj(evaluate_object(None, ctx, body)?),
588 ObjExtend(a, b) => evaluate_add_op(603 ObjExtend(a, b) => {
589 &evaluate(ctx.clone(), a)?,604 let base = evaluate(ctx.clone(), a)?;
605 match base {
590 &Val::Obj(evaluate_object(ctx, b)?),606 Val::Obj(base_obj) => Val::Obj(evaluate_object(Some(base_obj), ctx, b)?),
591 )?,607 _ => bail!("ObjExtend lhs should be an object value"),
608 }
609 }
592 Apply(value, args, tailstrict) => ensure_sufficient_stack(|| {610 Apply(value, args, tailstrict) => ensure_sufficient_stack(|| {
593 evaluate_apply(ctx, value, args, CallLocation::new(&args.span), *tailstrict)611 evaluate_apply(ctx, value, args, CallLocation::new(&args.span), *tailstrict)
594 })?,612 })?,