monty_types/results.rs
1//! Host-supplied results fed back into a suspended run:
2//! [`NameLookupResult`] and [`ExtFunctionResult`].
3
4use crate::{exceptions::MontyException, object::MontyObject};
5/// Result of a name lookup from the host.
6///
7/// When the VM encounters an unresolved name, the host provides one of these:
8/// - `Value(obj)`: The name resolves to this value (cached in the namespace for future access).
9/// - `Undefined`: The name is truly undefined, causing `NameError`.
10#[derive(Debug)]
11pub enum NameLookupResult {
12 /// The name resolves to this value.
13 Value(MontyObject),
14 /// The name is undefined — VM will raise `NameError`.
15 Undefined,
16}
17
18impl From<MontyObject> for NameLookupResult {
19 fn from(value: MontyObject) -> Self {
20 Self::Value(value)
21 }
22}
23
24/// Return value or exception from an external function.
25#[derive(Debug)]
26pub enum ExtFunctionResult {
27 /// Continues execution with the return value from the external function.
28 Return(MontyObject),
29 /// Continues execution with the exception raised by the external function.
30 Error(MontyException),
31 /// Pending future — the external function is a coroutine.
32 ///
33 /// The `u32` is the `call_id` from the `FunctionCall` that created this
34 /// snapshot. It is used to track the pending future so it can be resolved
35 /// later via `ResolveFutures::resume()`.
36 Future(u32),
37 /// The function was not found, should result in a `NameError` exception.
38 NotFound(String),
39}
40impl From<MontyObject> for ExtFunctionResult {
41 fn from(value: MontyObject) -> Self {
42 Self::Return(value)
43 }
44}
45
46impl From<MontyException> for ExtFunctionResult {
47 fn from(exception: MontyException) -> Self {
48 Self::Error(exception)
49 }
50}