Compile and Run v3 (Capstone)

hard · compilers, bytecode, vm, capstone

Compile and Run v3 (Capstone)

Connect the full v3 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 to bytecode (Compile)
  5. Encode to BC2 text (Encode)
  6. Decode back to bytecode (Decode)
  7. 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 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