From 83b9294ac1c3793a4e5b5b48e283571673c4ec55 Mon Sep 17 00:00:00 2001 From: rvcas Date: Fri, 15 Jul 2022 18:03:34 -0400 Subject: [PATCH] chore: print runtime --- add_integers.uplc | 2 +- crates/uplc/src/machine.rs | 5 +- crates/uplc/src/machine/cost_model.rs | 68 +++++++++++++++------------ 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/add_integers.uplc b/add_integers.uplc index b3c9bff8..dfca93b9 100644 --- a/add_integers.uplc +++ b/add_integers.uplc @@ -1,4 +1,4 @@ (program 1.0.0 - [ (lam x (lam y [ (builtin addInteger) x y ])) (con integer 5) (con integer 7) ] + [ (force (builtin ifThenElse)) (con bool True) (con integer 1) (con string "yo") ] ) diff --git a/crates/uplc/src/machine.rs b/crates/uplc/src/machine.rs index 9462a98d..f8357310 100644 --- a/crates/uplc/src/machine.rs +++ b/crates/uplc/src/machine.rs @@ -198,6 +198,7 @@ impl Machine { Value::Delay(body) => self.compute(&body), Value::Builtin { fun, term, runtime } => { let force_term = Term::Force(Box::new(term)); + println!("{:#?}", runtime); todo!() } rest => Err(Error::NonPolymorphicInstantiation(rest)), @@ -289,7 +290,7 @@ impl Machine { let mut unspent_step_budget = self.costs.machine_costs.get(StepKind::try_from(i as u8)?); - unspent_step_budget.occurences(self.unbudgeted_steps[i] as i32); + unspent_step_budget.occurences(self.unbudgeted_steps[i] as i64); self.spend_budget(unspent_step_budget)?; @@ -341,7 +342,7 @@ impl Value { matches!(self, Value::Con(Constant::Integer(_))) } - pub fn to_ex_mem(&self) -> i32 { + pub fn to_ex_mem(&self) -> i64 { match self { Value::Con(_) => todo!(), Value::Delay(_) => 1, diff --git a/crates/uplc/src/machine/cost_model.rs b/crates/uplc/src/machine/cost_model.rs index d7097c61..160a44aa 100644 --- a/crates/uplc/src/machine/cost_model.rs +++ b/crates/uplc/src/machine/cost_model.rs @@ -3,18 +3,28 @@ use crate::builtins::DefaultFunction; use super::Value; /// Can be negative -#[derive(Debug, Clone, PartialEq, Copy, Default)] +#[derive(Debug, Clone, PartialEq, Copy)] pub struct ExBudget { - pub mem: i32, - pub cpu: i32, + pub mem: i64, + pub cpu: i64, } impl ExBudget { - pub fn occurences(&mut self, n: i32) { + pub fn occurences(&mut self, n: i64) { self.mem *= n; self.cpu *= n; } } + +impl Default for ExBudget { + fn default() -> Self { + ExBudget { + mem: 14000000, + cpu: 10000000000, + } + } +} + #[derive(Default)] pub struct CostModel { pub machine_costs: MachineCosts, @@ -595,12 +605,12 @@ pub struct CostingFun { } pub enum OneArgument { - ConstantCost(i32), + ConstantCost(i64), LinearCost(LinearSize), } impl OneArgument { - pub fn cost(&self, x: i32) -> i32 { + pub fn cost(&self, x: i64) -> i64 { match self { OneArgument::ConstantCost(c) => *c, OneArgument::LinearCost(m) => m.slope * x + m.intercept, @@ -609,7 +619,7 @@ impl OneArgument { } #[derive(Clone)] pub enum TwoArguments { - ConstantCost(i32), + ConstantCost(i64), LinearInX(LinearSize), LinearInY(LinearSize), AddedSizes(AddedSizes), @@ -622,7 +632,7 @@ pub enum TwoArguments { ConstBelowDiagonal(ConstantOrTwoArguments), } impl TwoArguments { - pub fn cost(&self, x: i32, y: i32) -> i32 { + pub fn cost(&self, x: i64, y: i64) -> i64 { match self { TwoArguments::ConstantCost(c) => *c, TwoArguments::LinearInX(l) => l.slope * x + l.intercept, @@ -660,7 +670,7 @@ impl TwoArguments { } pub enum ThreeArguments { - ConstantCost(i32), + ConstantCost(i64), AddedSizes(AddedSizes), LinearInX(LinearSize), LinearInY(LinearSize), @@ -668,7 +678,7 @@ pub enum ThreeArguments { } impl ThreeArguments { - pub fn cost(&self, x: i32, y: i32, z: i32) -> i32 { + pub fn cost(&self, x: i64, y: i64, z: i64) -> i64 { match self { ThreeArguments::ConstantCost(c) => *c, ThreeArguments::AddedSizes(s) => (x + y + z) * s.slope + s.intercept, @@ -680,11 +690,11 @@ impl ThreeArguments { } pub enum SixArguments { - ConstantCost(i32), + ConstantCost(i64), } impl SixArguments { - pub fn cost(&self, _: i32, _: i32, _: i32, _: i32, _: i32, _: i32) -> i32 { + pub fn cost(&self, _: i64, _: i64, _: i64, _: i64, _: i64, _: i64) -> i64 { match self { SixArguments::ConstantCost(c) => *c, } @@ -693,51 +703,51 @@ impl SixArguments { #[derive(Clone)] pub struct LinearSize { - pub intercept: i32, - pub slope: i32, + pub intercept: i64, + pub slope: i64, } #[derive(Clone)] pub struct AddedSizes { - pub intercept: i32, - pub slope: i32, + pub intercept: i64, + pub slope: i64, } #[derive(Clone)] pub struct SubtractedSizes { - pub intercept: i32, - pub slope: i32, - pub minimum: i32, + pub intercept: i64, + pub slope: i64, + pub minimum: i64, } #[derive(Clone)] pub struct MultipliedSizes { - pub intercept: i32, - pub slope: i32, + pub intercept: i64, + pub slope: i64, } #[derive(Clone)] pub struct MinSize { - pub intercept: i32, - pub slope: i32, + pub intercept: i64, + pub slope: i64, } #[derive(Clone)] pub struct MaxSize { - pub intercept: i32, - pub slope: i32, + pub intercept: i64, + pub slope: i64, } #[derive(Clone)] pub struct ConstantOrLinear { - pub constant: i32, - pub intercept: i32, - pub slope: i32, + pub constant: i64, + pub intercept: i64, + pub slope: i64, } #[derive(Clone)] pub struct ConstantOrTwoArguments { - pub constant: i32, + pub constant: i64, pub model: Box, }