vihaco_stdlib/image.rs
1// SPDX-FileCopyrightText: 2026 The vihaco Authors
2// SPDX-License-Identifier: MIT
3
4//! Program data owned beside a dispatchable machine.
5//!
6//! Construct a module explicitly by parsing and lowering SST or decoding bytecode,
7//! then wrap it with [`Image::new`]. [`crate::Loadable`] pairs the image with a
8//! composite in separate fields so execution borrows code and metadata while
9//! independently mutating the machine.
10//!
11//! Keep the image outside mutable Dispatch and unchanged during an invocation.
12//! `Loadable` rejects replacement while an invocation is active and resets
13//! execution state after successful replacement. Resetting execution does not
14//! reset devices or other independently loaded programs. Image construction is
15//! outside the owner; failures do not roll back caller mutations.
16
17use vihaco_abi::{Type, Value};
18use vihaco_module::module::{LocalModule, NoInfo};
19
20/// Code and metadata for one independently loadable unit.
21///
22/// The outer owner controls replacement. This type contains no PC, stack,
23/// invocation state, or instruction inventory. `ProgramImage` remains the
24/// separate legacy loader/host API.
25#[derive(Debug, Clone)]
26pub struct Image<I, V = Value, Ty = Type, Info = NoInfo> {
27 pub module: LocalModule<I, V, Ty, Info>,
28}
29
30impl<I, V, Ty, Info> Image<I, V, Ty, Info> {
31 pub fn new(module: LocalModule<I, V, Ty, Info>) -> Self {
32 Self { module }
33 }
34}