Bytecode Format: A Real Compile Artifact
- Derive BC1 sections and quote-safe instruction lines.
- Distinguish structural round trips from runtime validity.
- Design malformed-artifact tests and deterministic output checks.
1 / 6
A function plus its call can be represented as:
BC1
FUNC difference a b
LOAD a
LOAD b
SUB
RETURN
END
MAIN
PUSH_NUM 9
PUSH_NUM 2
CALL difference 2
END
The function's code and Main each have their own zero-based instruction
coordinates. FUNC and END are format delimiters, not VM instructions. Adding
a comment line does not shift an instruction jump target. Running this
hand-authored Main returns 7 because it has no final POP.
A decoder counts every text line when interpreting JUMP 4. Adding a comment changes execution even though the decoded instructions are otherwise identical. What coordinate system was confused?
Write a BC1 string containing a quoted space, escaped quote, and newline escape. Predict the decoded string, then corrupt exactly one delimiter. Compare structural round-trip checks with an independent runtime expected value.
Carry an encoded artifact and a malformed counterpart into the v2 capstone. The VM must be able to run a decoded copy without any AST or parser state.