Path: blob/main/pulley/src/interp/match_loop.rs
1692 views
//! Implementation of the interpreter loop for Pulley with a simple `match`1//! statement.2//!3//! This module is notably in contrast to the `tail_loop.rs` which implements4//! the interpreter loop with tail calls. It's predicted that tail calls are a5//! more performant solution but that's also not available on stable Rust today,6//! so this module instead compiles on stable Rust.7//!8//! This interpreter loop is a simple `loop` with a "moral `match`" despite not9//! actually having one here. The `Decoder` API is used to dispatch to the10//! `OpVisitor` trait implementation on `Interpreter<'_>`. The literal `match`11//! is embedded within the `Decoder::decode_one` function.12//!13//! Note that as of the time of this writing there hasn't been much performance14//! analysis of this loop just yet. It's probably too simple to compile well and15//! will probably need tweaks to make it more performant.1617use super::*;1819impl Interpreter<'_> {20pub fn run(self) -> Done {21let mut decoder = Decoder::new();22let mut visitor = debug::Debug(self);23loop {24// Here `decode_one` will call the appropriate `OpVisitor` method on25// `self` via the trait implementation in the module above this.26// That'll return whether we should keep going or exit the loop,27// which is then done here with a conditional `break`.28//29// This will then continue indefinitely until the bytecode says it's30// done. Note that only trusted bytecode is interpreted here.31match decoder.decode_one(&mut visitor) {32Ok(ControlFlow::Continue(())) => {}33Ok(ControlFlow::Break(done)) => break done,34}35}36}37}383940