macro_rules! uasm {
($( $tt:tt )+) => { ... };
}Expand description
Macro compiler for AluVM assembler.
ยงExample
use ultrasonic::{uasm, Instr, VmContext};
use zkaluvm::alu::regs::Status;
use zkaluvm::alu::{Lib, LibId, LibSite, Vm};
let code = uasm! {
nop ;
chk CK ;
test E1 ;
cknxi :destructible;
not CO ;
jif CO, +2 ;
mov CO, CK ;
chk CO ;
ldi :immutable ;
clr EA ;
mov E2, 0 ;
mov EB, 20 ;
mov E1, E2 ;
eq E1, E2 ;
neg EA, EH ;
add EA, EH ;
mul EA, EH ;
};
let lib = Lib::assemble::<Instr<LibId>>(&code).unwrap();
let mut vm = Vm::<Instr<LibId>>::new();
let ctx = VmContext {
read_once_input: &[],
immutable_input: &[],
read_once_output: &[],
immutable_output: &[],
};
match vm.exec(LibSite::new(lib.lib_id(), 0), &ctx, |_| Some(&lib)) {
Status::Ok => println!("success"),
Status::Fail => println!("failure"),
}