pub struct Vm { /* private fields */ }
interp
only.Expand description
A virtual machine for interpreting Pulley bytecode.
Implementations§
Source§impl Vm
impl Vm
Sourcepub fn with_stack(stack: Vec<u8>) -> Self
pub fn with_stack(stack: Vec<u8>) -> Self
Create a new virtual machine with the given stack.
Sourcepub fn state(&self) -> &MachineState
pub fn state(&self) -> &MachineState
Get a shared reference to this VM’s machine state.
Sourcepub fn state_mut(&mut self) -> &mut MachineState
pub fn state_mut(&mut self) -> &mut MachineState
Get an exclusive reference to this VM’s machine state.
Sourcepub fn into_stack(self) -> Vec<u8>
pub fn into_stack(self) -> Vec<u8>
Consumer this VM and return its stack storage.
Sourcepub unsafe fn call<'a>(
&'a mut self,
func: NonNull<u8>,
args: &[Val],
rets: impl IntoIterator<Item = RegType> + 'a,
) -> DoneReason<impl Iterator<Item = Val> + 'a>
pub unsafe fn call<'a>( &'a mut self, func: NonNull<u8>, args: &[Val], rets: impl IntoIterator<Item = RegType> + 'a, ) -> DoneReason<impl Iterator<Item = Val> + 'a>
Call a bytecode function.
The given func
must point to the beginning of a valid Pulley bytecode
function.
The given args
must match the number and type of arguments that
function expects.
The given rets
must match the function’s actual return types.
Returns either the resulting values, or the PC at which a trap was raised.
Sourcepub unsafe fn call_start<'a>(&'a mut self, args: &[Val])
pub unsafe fn call_start<'a>(&'a mut self, args: &[Val])
Peforms the initial part of Vm::call
in setting up the args
provided in registers according to Pulley’s ABI.
§Unsafety
All the same unsafety as call
and additiionally, you must
invoke call_run
and then call_end
after calling call_start
.
If you don’t want to wrangle these invocations, use call
instead
of call_{start,run,end}
.