MontyRun
Primary interface for running Monty code.MontyRun supports two execution modes:
- Simple execution: Use
run()orrun_no_limits()to run code to completion - Iterative execution: Use
start()to start execution which will pause at external function calls and can be resumed later
Constructor
new()
Creates a new run snapshot by parsing the given code. This only parses and prepares the code - no heap or namespaces are created yet. Callrun() with inputs to start execution.
The Python code to execute
The script name for error messages
Names of input variables
Result<MontyRun, MontyException>
Returns the parsed
MontyRun or an error if the code cannot be parsedExecution Methods
run()
Executes the code to completion assuming no external functions or snapshotting. This is marginally faster than running with snapshotting enabled since we don’t need to track the position in code, but does not allow calling of external functions.Values to fill the first N slots of the namespace
Custom resource tracker implementation
Print output writer (mutably borrowed so
Collect data is preserved)Result<MontyObject, MontyException>
Returns the final result value or an error if execution fails
run_no_limits()
Executes the code to completion with no resource limits, printing to stdout/stderr.Values to fill the first N slots of the namespace
Result<MontyObject, MontyException>
Returns the final result value or an error if execution fails
start()
Starts execution with the given inputs and resource tracker, consuming self. For iterative execution,start() consumes self and returns a RunProgress:
RunProgress::FunctionCall(call)- external function call, callcall.resume(return_value)to resumeRunProgress::Complete(value)- execution finished
Initial input values (must match length of
input_names from new())Resource tracker for the execution
Writer for print output
Result<RunProgress<T>, MontyException>
Returns a
RunProgress enum indicating the next step in executionMontyException if:
- The number of inputs doesn’t match the expected count
- An input value is invalid (e.g.,
MontyObject::Repr) - A runtime error occurs during execution
Serialization Methods
dump()
Serializes the runner to a binary format. The serialized data can be stored and later restored withload(). This allows caching parsed code to avoid re-parsing on subsequent runs.
Result<Vec<u8>, postcard::Error>
Returns the serialized bytes or an error if serialization fails
load()
Deserializes a runner from binary format.The serialized runner data from
dump()Result<MontyRun, postcard::Error>
Returns the deserialized
MontyRun or an error if deserialization failsOther Methods
code()
Returns the code that was parsed to create this snapshot.&str
Reference to the source code string
