vihaco / virtual ISA & machine framework

QuEra Computing · Rust

vihaco

Rust 2024 License MIT Source github.com/QuEraComputing/vihaco
A component counter.rs
// SPDX-FileCopyrightText: 2026 The vihaco Authors
// SPDX-License-Identifier: MIT

use vihaco::{Execute, NoMessage, component, dialect};

#[dialect]
pub mod counter {
    #[instruction]
    pub struct Add(pub u64);
}

#[component]
#[instructions { counter }]
#[derive(Default)]
pub struct Counter(u64);

impl Execute<counter::Add> for Counter {
    type Message = NoMessage;
    type Effect = u64;
    type Error = eyre::Report;

    fn execute(&mut self, instruction: &counter::Add, _: NoMessage) -> eyre::Result<u64> {
        self.0 = self
            .0
            .checked_add(instruction.0)
            .ok_or_else(|| eyre::eyre!("counter overflow"))?;
        Ok(self.0)
    }
}

A component is an execution unit: it takes a typed instruction plus a resolved message and returns a typed result. Dialects declare the vocabulary; composites supply execution policy.

i. Instruction sets

A vocabulary shared by devices

#[dialect] defines typed instructions. Components declare whole dialects and implement their operations; composites route those operations to direct or nested devices.

ii. Components & effects

Execute and handle results

Components execute through Execute. Authored steps prepare messages, call devices, and apply results. Each machine makes that continuation policy explicit.

iii. Pattern-derived syntax

From source text to module

#[derive(Parse)] generates a chumsky parser for your instruction syntax from declarative, compile-time-checked patterns. Parsing and symbolic lowering build a module, which an image owns beside its mutable execution machine.

§Install

vihaco is the facade for declarations and execution. The author’s guide setup selects the version and dependencies used throughout the examples.

Requires Rust edition 2024.

Continue to the Quick Start →

Continue to the Quick Start, work through the Guides, or browse the API Reference.