@@ -17,6 +17,8 @@ pub struct InstrEncoder {
17
17
///
18
18
/// This is `Some` if fuel metering is enabled, otherwise `None`.
19
19
fuel_costs : Option < FuelCostsProvider > ,
20
+ /// The last pushed non-parameter [`Instruction`].
21
+ last_instr : Option < Instr > ,
20
22
}
21
23
22
24
impl ReusableAllocations for InstrEncoder {
@@ -53,6 +55,7 @@ impl InstrEncoder {
53
55
Self {
54
56
instrs : alloc. instrs ,
55
57
fuel_costs,
58
+ last_instr : None ,
56
59
}
57
60
}
58
61
@@ -75,12 +78,11 @@ impl InstrEncoder {
75
78
let Ok ( base_costs) = u32:: try_from ( base_costs) else {
76
79
panic ! ( "out of bounds base fuel costs: {base_costs}" ) ;
77
80
} ;
78
- let instr = self . next_instr ( ) ;
79
- self . instrs . push ( Instruction :: consume_fuel ( base_costs) ) ;
81
+ let instr = self . push_instr_impl ( Instruction :: consume_fuel ( base_costs) ) ?;
80
82
Ok ( Some ( instr) )
81
83
}
82
84
83
- /// Pushes an [`Instruction`] to the [`InstrEncoder`].
85
+ /// Pushes a non-parameter [`Instruction`] to the [`InstrEncoder`].
84
86
///
85
87
/// Returns an [`Instr`] that refers to the pushed [`Instruction`].
86
88
pub fn push_instr (
@@ -90,8 +92,14 @@ impl InstrEncoder {
90
92
f : impl FnOnce ( & FuelCostsProvider ) -> u64 ,
91
93
) -> Result < Instr , Error > {
92
94
self . bump_fuel_consumption ( consume_fuel, f) ?;
95
+ self . push_instr_impl ( instruction)
96
+ }
97
+
98
+ /// Pushes a non-parameter [`Instruction`] to the [`InstrEncoder`].
99
+ fn push_instr_impl ( & mut self , instruction : Instruction ) -> Result < Instr , Error > {
93
100
let instr = self . next_instr ( ) ;
94
101
self . instrs . push ( instruction) ;
102
+ self . last_instr = Some ( instr) ;
95
103
Ok ( instr)
96
104
}
97
105
0 commit comments