From 20917bbd5b185a3b9202f64001e9695abc5a6b17 Mon Sep 17 00:00:00 2001 From: rvcas Date: Mon, 19 Feb 2024 20:52:38 -0500 Subject: [PATCH] feat(machine): fix Value::Constr fields order cc @MicroProofs --- crates/uplc/src/machine.rs | 10 ++++++---- .../evaluation/term/constr/constr-3/constr-3.uplc | 4 ++++ .../term/constr/constr-3/constr-3.uplc.budget.expected | 2 ++ .../term/constr/constr-3/constr-3.uplc.expected | 1 + 4 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 crates/uplc/test_data/conformance/evaluation/term/constr/constr-3/constr-3.uplc create mode 100644 crates/uplc/test_data/conformance/evaluation/term/constr/constr-3/constr-3.uplc.budget.expected create mode 100644 crates/uplc/test_data/conformance/evaluation/term/constr/constr-3/constr-3.uplc.expected diff --git a/crates/uplc/src/machine.rs b/crates/uplc/src/machine.rs index 0aa02b2f..dcca572c 100644 --- a/crates/uplc/src/machine.rs +++ b/crates/uplc/src/machine.rs @@ -163,8 +163,10 @@ impl Machine { Term::Constr { tag, mut fields } => { self.step_and_maybe_spend(StepKind::Constr)?; + fields.reverse(); + if !fields.is_empty() { - let popped_field = fields.remove(0); + let popped_field = fields.pop().unwrap(); Ok(MachineState::Compute( Context::FrameConstr(env.clone(), tag, fields, vec![], context.into()), @@ -213,10 +215,10 @@ impl Machine { Context::FrameAwaitArg(fun, ctx) => self.apply_evaluate(*ctx, fun, value), Context::FrameAwaitFunValue(arg, ctx) => self.apply_evaluate(*ctx, value, arg), Context::FrameConstr(env, tag, mut fields, mut resolved_fields, ctx) => { - resolved_fields.insert(0, value); + resolved_fields.push(value); if !fields.is_empty() { - let popped_field = fields.remove(0); + let popped_field = fields.pop().unwrap(); Ok(MachineState::Compute( Context::FrameConstr(env.clone(), tag, fields, resolved_fields, ctx), @@ -376,7 +378,7 @@ fn transfer_arg_stack(mut args: Vec, ctx: Context) -> Context { if args.is_empty() { ctx } else { - let popped_field = args.remove(0); + let popped_field = args.pop().unwrap(); transfer_arg_stack(args, Context::FrameAwaitFunValue(popped_field, ctx.into())) } diff --git a/crates/uplc/test_data/conformance/evaluation/term/constr/constr-3/constr-3.uplc b/crates/uplc/test_data/conformance/evaluation/term/constr/constr-3/constr-3.uplc new file mode 100644 index 00000000..03932fb8 --- /dev/null +++ b/crates/uplc/test_data/conformance/evaluation/term/constr/constr-3/constr-3.uplc @@ -0,0 +1,4 @@ +-- constr can have arbitrary terms in it +(program 1.1.0 + (constr 1 (con integer 1) (lam x x) (constr 0 (con integer 1))) +) diff --git a/crates/uplc/test_data/conformance/evaluation/term/constr/constr-3/constr-3.uplc.budget.expected b/crates/uplc/test_data/conformance/evaluation/term/constr/constr-3/constr-3.uplc.budget.expected new file mode 100644 index 00000000..71e43512 --- /dev/null +++ b/crates/uplc/test_data/conformance/evaluation/term/constr/constr-3/constr-3.uplc.budget.expected @@ -0,0 +1,2 @@ +({cpu: 115100 +| mem: 600}) \ No newline at end of file diff --git a/crates/uplc/test_data/conformance/evaluation/term/constr/constr-3/constr-3.uplc.expected b/crates/uplc/test_data/conformance/evaluation/term/constr/constr-3/constr-3.uplc.expected new file mode 100644 index 00000000..eba1d628 --- /dev/null +++ b/crates/uplc/test_data/conformance/evaluation/term/constr/constr-3/constr-3.uplc.expected @@ -0,0 +1 @@ +(program 1.1.0 (constr 1 (con integer 1) (lam x x) (constr 0 (con integer 1)))) \ No newline at end of file