chore: print runtime

This commit is contained in:
rvcas 2022-07-15 18:03:34 -04:00 committed by Kasey White
parent b7e6f7b27f
commit 83b9294ac1
3 changed files with 43 additions and 32 deletions

View File

@ -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") ]
)

View File

@ -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,

View File

@ -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<T> {
}
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<TwoArguments>,
}