Skip to main content

qcode/value/insn/
pcode_op.rs

1use super::mnemonic::{Args, MnemonicKind};
2use crate::value::LocalValueId;
3use serde::{Deserialize, Serialize};
4use smallvec::SmallVec;
5
6pub use pcode_types::PCodeOpId;
7
8/// The reserved user op that stops the machine so the environment can act.
9///
10/// `vm.interrupt(code, args...) -> value?` retires everything before it,
11/// runs nothing after it, and surfaces as a typed exit from the VM. The
12/// environment supplies the op's result, if it declares one, and resumes.
13/// It is how an injected hook hands control to the host from inside a block,
14/// whether that block is interpreted or compiled. See `qcode_vm`.
15pub const VM_INTERRUPT: &str = "vm.interrupt";
16
17#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
18pub struct PCodeOp {
19    pub id: PCodeOpId,
20    pub args: Vec<LocalValueId>,
21    pub dst: Option<LocalValueId>,
22}
23
24impl MnemonicKind for PCodeOp {
25    fn opcode(&self) -> &'static str {
26        "pcode_op"
27    }
28
29    fn args(&self) -> Args {
30        SmallVec::from_vec(self.args.clone())
31    }
32}