Skip to main content

Module parse_helpers

Module parse_helpers 

Source
Expand description

Field-level parser helpers wired into #[derive(vihaco_parser::Parse)] via #[parse_with = "..."] on the vihaco_cpu::Instruction enum.

Scope intentionally narrow: the helpers cover only the subset that #[derive(Parse)] can model cleanly. Three families of variants are deferred to the Module orchestrator (Item 4 of the migration plan):

  • Const(Value::String/FunctionRef/HeapRef) — needs a shared string interner / symbol table that Parse has no way to thread through. cpu_const_value() parses only the numeric/bool flavours.
  • Branch, ConditionalBranch, Call — use symbolic @label targets in real .sst source; the symbol table lives in the orchestrator. The never_u32() helper guarantees Instruction::parser() errors out on these mnemonics so the orchestrator can dispatch first.
  • Conversion from the parse-time numeric form to the orchestrator-resolved form is tracked in ~/.claude/plans/vihaco-future-rawvalue-refactor.md.

Functions§

cpu_const_value
Parses the body of const.<type> <literal> — without the leading const keyword (the derive macro emits that). Numeric and bool variants only.
cpu_type
Parses .<typename> and returns the matching [Type]. Used for the typed arithmetic/comparison variants — add.i64, lt.u64, etc.
never_u32
A parser that always fails. Used for variant operands whose real form is a symbolic @label (Branch, ConditionalBranch, Call). Letting these fall through here means Instruction::parser() errors on their mnemonics, which is correct — the orchestrator must intercept first.