Skip to main content

amaru_uplc/machine/cost_model/
ex_budget.rs

1#[derive(Debug, Copy, Clone, PartialEq)]
2pub struct ExBudget {
3    pub mem: i64,
4    pub cpu: i64,
5}
6
7impl Default for ExBudget {
8    fn default() -> Self {
9        Self::machine()
10    }
11}
12
13impl ExBudget {
14    pub fn new(mem: i64, cpu: i64) -> Self {
15        ExBudget { mem, cpu }
16    }
17
18    pub fn max() -> Self {
19        Self::machine_max()
20    }
21
22    pub fn occurrences(&mut self, n: i64) {
23        self.mem *= n;
24        self.cpu *= n;
25    }
26
27    pub fn machine() -> Self {
28        ExBudget {
29            mem: 14_000_000,
30            cpu: 10_000_000_000,
31        }
32    }
33
34    pub fn machine_max() -> Self {
35        ExBudget {
36            mem: 14_000_000_000_000,
37            cpu: 10_000_000_000_000_000,
38        }
39    }
40
41    pub fn start_up() -> Self {
42        ExBudget { mem: 100, cpu: 100 }
43    }
44
45    pub fn var() -> Self {
46        ExBudget {
47            mem: 100,
48            cpu: 16000,
49        }
50    }
51
52    pub fn constant() -> Self {
53        ExBudget {
54            mem: 100,
55            cpu: 16000,
56        }
57    }
58
59    pub fn lambda() -> Self {
60        ExBudget {
61            mem: 100,
62            cpu: 16000,
63        }
64    }
65
66    pub fn delay() -> Self {
67        ExBudget {
68            mem: 100,
69            cpu: 16000,
70        }
71    }
72
73    pub fn force() -> Self {
74        ExBudget {
75            mem: 100,
76            cpu: 16000,
77        }
78    }
79
80    pub fn apply() -> Self {
81        ExBudget {
82            mem: 100,
83            cpu: 16000,
84        }
85    }
86
87    pub fn builtin() -> Self {
88        ExBudget {
89            mem: 100,
90            cpu: 16000,
91        }
92    }
93
94    pub fn constr() -> Self {
95        ExBudget {
96            mem: 100,
97            cpu: 16000,
98        }
99    }
100
101    pub fn case() -> Self {
102        ExBudget {
103            mem: 100,
104            cpu: 16000,
105        }
106    }
107}
108
109impl std::ops::Sub for ExBudget {
110    type Output = ExBudget;
111
112    fn sub(self, rhs: Self) -> Self::Output {
113        ExBudget {
114            mem: self.mem - rhs.mem,
115            cpu: self.cpu - rhs.cpu,
116        }
117    }
118}