Skip to content

ppvm_vihaco::bytecode

bytecode

ppvm_vihaco::bytecode

Binary bytecode (`.ssb`) round-trip for PPVM modules.

Serializes a resolved [`Module`] to a little-endian container — header (magic + version + device info) → strings section → code section — and reads it back. The per-instruction codec is the existing `WriteBytes` / `FromBytes` generated for PPVMInstruction; this module only frames the container around it.

propertyPPVM_BYTECODE_VERSION

ppvm_vihaco::bytecode::PPVM_BYTECODE_VERSION

pub const PPVM_BYTECODE_VERSION: u16

Current `.ssb` format version. The reader rejects any other version.

functioncompile_to_bytessource

ppvm_vihaco::bytecode::compile_to_bytes

pub fn compile_to_bytes(source: &str) -> Result<Vec<u8>>

Parameters

NameTypeDescription
source&amp;str

Returns

Result<Vec<u8>>

“Dump”: compile `.sst` source straight to the `.ssb` byte stream.

source

functionis_bytecodesource

ppvm_vihaco::bytecode::is_bytecode

pub fn is_bytecode(bytes: &[u8]) -> bool

Parameters

NameTypeDescription
bytes&amp;[u8]

Returns

bool

Cheap sniff: does this byte stream begin with the PPVM `.ssb` magic?

Reads the leading four bytes the same way read_module does — as a little-endian `u32` — so a positive result here means read_module will accept the magic. A stream shorter than the magic is not bytecode.

source

functionmodule_from_bytessource

ppvm_vihaco::bytecode::module_from_bytes

pub fn module_from_bytes(bytes: &[u8]) -> Result<PPVMModule>

Parameters

NameTypeDescription
bytes&amp;[u8]

Returns

Result<PPVMModule>

Reconstruct a module from a byte slice.

source

functionmodule_to_bytessource

ppvm_vihaco::bytecode::module_to_bytes

pub fn module_to_bytes(module: &PPVMModule) -> Result<Vec<u8>>

Parameters

NameTypeDescription
module&amp;PPVMModule

Returns

Result<Vec<u8>>

Serialize a module to an owned byte vector.

source

functionread_modulesource

ppvm_vihaco::bytecode::read_module

pub fn read_module<R: Read>(r: &mut R) -> Result<PPVMModule>

Parameters

NameTypeDescription
r&amp;mut R

Returns

Result<PPVMModule>

Reconstruct a module from a v2 `.ssb` byte stream.

source

functionwrite_modulesource

ppvm_vihaco::bytecode::write_module

Signature
pub fn write_module<W: Write>(module: &PPVMModule, w: &mut W) -> Result<()>

Parameters

NameTypeDescription
module&amp;PPVMModule
w&amp;mut W

Returns

Result<()>

Serialize a resolved module to the v2 `.ssb` byte stream.

source