A Fast Bytecode VM for Arithmetic (Part 2): Compiler and Decompiler in Haskell

2025-08-28
A Fast Bytecode VM for Arithmetic (Part 2): Compiler and Decompiler in Haskell

This post, the second in a series, details a compiler and decompiler for a fast bytecode virtual machine for arithmetic expressions in Haskell. It explains why bytecode is faster than AST interpretation, designs a stack-based bytecode virtual machine, and outlines bytecode instructions for Num, BinOp, Var, and Let AST nodes. The compiler uses pre-allocated byte arrays and pointer manipulation for performance, with robust error handling. Performance benchmarks comparing various data structures and control flow are presented. Finally, a decompiler is implemented to aid debugging and testing.

Read more
Development

A Bytecode VM for Arithmetic in Haskell: The Parser

2025-08-03
A Bytecode VM for Arithmetic in Haskell: The Parser

This post details the first part of a project to build a bytecode virtual machine for arithmetic expressions in Haskell. The VM will parse, compile, interpret, and run simple arithmetic expressions, including let bindings and nested let expressions. The author explains the expression grammar, parser implementation (using the attoparsec library), and error handling. Unit tests are presented to validate the parser's correctness. A brief overview of the AST interpreter's implementation and testing is also included. Future posts will cover the compiler and virtual machine.

Read more
Development