Skip to content

Commit 9e293bf

Browse files
committed
Make Processor::step public and unsafe
1 parent 75a498f commit 9e293bf

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/vm/processor.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ impl Processor {
279279
// casting to usize truncates the fractional part
280280
// so this is equivalent to `while self.state.accumulator >= 1.`
281281
for i in 0..(self.state.accumulator as usize) {
282-
if let InstructionResult::Yield = self.step(vm) {
282+
// SAFETY: self.state.enabled is always false if self.instructions is empty
283+
if let InstructionResult::Yield = unsafe { self.step(vm) } {
283284
self.state.accumulator -= (i + 1) as f64;
284285
return;
285286
}
@@ -289,8 +290,12 @@ impl Processor {
289290
self.state.accumulator = self.state.accumulator.fract();
290291
}
291292

292-
/// Do not call if the processor is disabled.
293-
fn step(&mut self, vm: &LogicVM) -> InstructionResult {
293+
/// Executes a single instruction.
294+
///
295+
/// # Safety
296+
///
297+
/// Calling this method on a processor with no instructions is undefined behavior.
298+
pub unsafe fn step(&mut self, vm: &LogicVM) -> InstructionResult {
294299
let mut counter = self.state.counter;
295300
if counter >= self.instructions.len() {
296301
counter = 0;

0 commit comments

Comments
 (0)