Compile and Run v5 (Capstone)

hard · compilers, bytecode, vm, capstone

Compile and Run v5 (Capstone)

Connect the full v5 compiler pipeline and execute the program.

Function signature

func CompileAndRun(src string) (Value, error)

Pipeline requirements

Your function must:

  1. Lex source into tokens (Lex)
  2. Parse tokens into a program AST (Parse)
  3. Run semantic analysis (Analyze)
  4. Compile modules to bytecode (CompileModules)
  5. Link modules into a single program (Link)
  6. Encode to BC2 text (Encode)
  7. Decode back to bytecode (Decode)
  8. Execute in the VM (Run on a new VM)

Return the final VM result.

Error handling

  • If lexing or parsing fails, return that error.
  • If semantic analysis returns errors, return the first error as error.
  • If linking, decoding, or execution fails, return that error.

Notes

  • The helper functions and types are provided in this file.
  • Keep the implementation readable.
Run tests to see results
No issues detected