pub struct Vm { /* private fields */ }Expand description
The virtual machine with a program loaded.
Implementations§
Source§impl Vm
impl Vm
Sourcepub fn set_file_safety(&mut self, read: u8, write: u8)
pub fn set_file_safety(&mut self, read: u8, write: u8)
Set how much of the file system the program may read and write.
Sourcepub fn add_resource(&mut self, name: &str, data: &[u8])
pub fn add_resource(&mut self, name: &str, data: &[u8])
Supply a resource for the program to open by name.
Sourcepub fn close_files(&mut self)
pub fn close_files(&mut self)
Finish with every file at the end of the run.
Source§impl Vm
impl Vm
Sourcepub fn push_input_script(
&mut self,
data: &[u8],
quiet: bool,
pause_output: bool,
)
pub fn push_input_script( &mut self, data: &[u8], quiet: bool, pause_output: bool, )
Read input from a script before asking the player for any. The
script is the contents of a command file: a line starting with >
is a command, or, in a file that starts with the line
<eventscript>, each line is an event such as <line>look.
Source§impl Vm
impl Vm
Sourcepub fn set_image_name(&mut self, name: &str)
pub fn set_image_name(&mut self, name: &str)
Record the name of the image file, which saved states carry so that a saved state can lead back to its program.
Sourcepub fn run(&mut self, args: &[String]) -> VmResult<()>
pub fn run(&mut self, args: &[String]) -> VmResult<()>
Run the program to its end. The program sees args as the
arguments of its main function.
This is for a host that can wait for the player. With one that
cannot, use Vm::start and Vm::resume.
Sourcepub fn start(&mut self, args: &[String]) -> VmResult<RunState>
pub fn start(&mut self, args: &[String]) -> VmResult<RunState>
Start the program, and run it until it ends or has to wait for
the host. The program sees args as the arguments of its main
function.
Sourcepub fn resume(&mut self) -> VmResult<RunState>
pub fn resume(&mut self) -> VmResult<RunState>
Carry on with a program that stopped to wait for the host, until it ends or has to wait again.
Sourcepub fn error_message(
&mut self,
error: &VmError,
unhandled_prefix: bool,
) -> String
pub fn error_message( &mut self, error: &VmError, unhandled_prefix: bool, ) -> String
Describe an error that ended the program, in the reference VM’s words.
Source§impl Vm
impl Vm
Sourcepub fn set_runtime_symbols(
&mut self,
symbols: Vec<GlobalSymbol>,
macros: Vec<Macro>,
)
pub fn set_runtime_symbols( &mut self, symbols: Vec<GlobalSymbol>, macros: Vec<Macro>, )
Give the program the compiler’s table of global symbols and of
macros, for globalSymbols, as the compiler does for a
program it runs before writing the image. The order is the
order of the tables the program sees.
Sourcepub fn run_preinit(&mut self, args: &[String]) -> VmResult<()>
pub fn run_preinit(&mut self, args: &[String]) -> VmResult<()>
Run the program as it is run before its image is written: with
inPreinit() true, and with the arguments given.
Sourcepub fn rewrite_image(&mut self, original: &[u8]) -> VmResult<RebuiltImage>
pub fn rewrite_image(&mut self, original: &[u8]) -> VmResult<RebuiltImage>
Write the program as it now stands as an image, given the image it was loaded from. This is what the reference does after preinitialization.
Sourcepub fn rewrite_image_keeping(
&mut self,
original: &[u8],
unspecified: &[(usize, usize)],
) -> VmResult<RebuiltImage>
pub fn rewrite_image_keeping( &mut self, original: &[u8], unspecified: &[(usize, usize)], ) -> VmResult<RebuiltImage>
The same, given the stretches of the image it was loaded from that mean nothing: those in the parts that are copied are carried over to where the parts go.
Source§impl Vm
impl Vm
Sourcepub fn seed_random(&mut self)
pub fn seed_random(&mut self)
Seed the random number generator from the host’s entropy. Without this, every run of a program makes the same random choices.
Source§impl Vm
impl Vm
Sourcepub fn set_error_trace(&mut self, on: bool)
pub fn set_error_trace(&mut self, on: bool)
Report each VM error on standard error as it is raised, with the address of the instruction that caused it. This is a debugging aid for work on the VM itself.
Sourcepub fn flush_output(&mut self)
pub fn flush_output(&mut self)
Write out any text the console is holding for an unfinished line. Call this when the program ends.