1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use super::{Interpreter, RuntimeBalances};
use crate::consts::*;
use crate::context::Context;
use crate::state::Debugger;
use crate::storage::MemoryStorage;
#[cfg(feature = "profile-any")]
use crate::profiler::{ProfileReceiver, Profiler};
use fuel_tx::{CheckedTransaction, ConsensusParameters};
impl<S> Interpreter<S> {
pub fn with_storage(storage: S, params: ConsensusParameters) -> Self {
Self {
registers: [0; VM_REGISTER_COUNT],
memory: vec![0; VM_MAX_RAM as usize],
frames: vec![],
receipts: vec![],
tx: CheckedTransaction::default(),
storage,
debugger: Debugger::default(),
context: Context::default(),
balances: RuntimeBalances::default(),
#[cfg(feature = "profile-any")]
profiler: Profiler::default(),
params,
}
}
pub fn with_params(&mut self, params: ConsensusParameters) -> &mut Self {
self.params = params;
self
}
#[cfg(feature = "profile-any")]
pub fn with_profiler<P>(&mut self, receiver: P) -> &mut Self
where
P: ProfileReceiver + Send + Sync + 'static,
{
self.profiler.set_receiver(Box::new(receiver));
self
}
}
impl<S> Interpreter<S>
where
S: Clone,
{
pub fn build(&mut self) -> Self {
self.clone()
}
}
impl<S> Default for Interpreter<S>
where
S: Default,
{
fn default() -> Self {
Self::with_storage(Default::default(), Default::default())
}
}
impl Interpreter<()> {
pub fn without_storage() -> Self {
Self::default()
}
}
impl Interpreter<MemoryStorage> {
pub fn with_memory_storage() -> Self {
Self::default()
}
}