Compile and Run v4 (Capstone)
Compile and Run v4 (Capstone)
Connect the full v4 compiler pipeline and execute the program.
Function signature
func CompileAndRun(src string) (Value, error)
Pipeline requirements
Your function must:
- Lex source into tokens (
Lex) - Parse tokens into a program AST (
Parse) - Run semantic analysis (
Analyze) - Compile to bytecode (
Compile) - Encode to BC2 text (
Encode) - Decode back to bytecode (
Decode) - Execute in the VM (
Runon a new VM)
Return the final VM result.
This function is intentionally the integration layer.
It should do the following in order:
- call the stage
- inspect error
- abort immediately on failure
- move to next stage on success
Error handling
- If lexing or parsing fails, return that error.
- If semantic analysis returns errors, return the first error as
error. - If decoding or execution fails, return that error.
Notes
- The helper functions and types are provided in this file.
- Keep the implementation readable.
Before implementation
Use the module’s worked reconstruction and independent debugging lab to predict an intermediate artifact first. Preserve one failing counterexample while implementing the stated API. The lesson’s transfer task uses a fresh case after the guided trace.
Run tests to see results
No issues detected