pub trait Device {
// Required methods
fn get(&mut self, src: Input) -> Result<i64, String>;
fn put(&mut self, val: i64, dst: Output) -> Result<(), String>;
fn peek(&mut self) -> Result<i64, String>;
fn poke(&mut self, val: i64) -> Result<(), String>;
fn ffi_call(
&mut self,
ffi: &FFIBinding,
tape: Option<&mut Vec<i64>>,
) -> Result<(), String>;
}
Expand description
Create an input / output device for the virtual machine interpreter
to operate on. The method get
retrieves the device’s input, and the
function put
writes to the devices output.
TODO: Make a trait for a device with the standard variant, which requires
get_char
, put_char
, get_int
, put_int
, get_float
, and put_float
methods.
Required Methods§
Sourcefn get(&mut self, src: Input) -> Result<i64, String>
fn get(&mut self, src: Input) -> Result<i64, String>
Get the next input (from a given input source).
Sourcefn put(&mut self, val: i64, dst: Output) -> Result<(), String>
fn put(&mut self, val: i64, dst: Output) -> Result<(), String>
Put the given value to the given output destination.
Sourcefn peek(&mut self) -> Result<i64, String>
fn peek(&mut self) -> Result<i64, String>
Peek at the next value in the FFI buffer for the FFI function calls. Store the peeked value in the register.
Sourcefn poke(&mut self, val: i64) -> Result<(), String>
fn poke(&mut self, val: i64) -> Result<(), String>
Poke a value into the FFI buffer for the FFI function calls.
Sourcefn ffi_call(
&mut self,
ffi: &FFIBinding,
tape: Option<&mut Vec<i64>>,
) -> Result<(), String>
fn ffi_call( &mut self, ffi: &FFIBinding, tape: Option<&mut Vec<i64>>, ) -> Result<(), String>
FFI call to the device. This will get the FFI binding for the device and call the function associated with the binding. If the tape is provided, the foreign function may mutate the tape. Otherwise all interaction with the FFI is done through the FFI channel.
Implementors§
impl Device for StandardDevice
impl Device for TestingDevice
Make the testing device work with the interpreter.