Commit Graph

4 Commits

Author SHA1 Message Date
Jose Luis Montañes Ojados
da9bb6ca62 Complete VM parity with eval and fix operator precedence
VM: add string concatenation in OP_ADD, len() built-in, multi-arg
print/println, undefined variable detection, and GC via OP_NOP.
Parser: fix operator precedence by splitting into parse_expr (+,-)
and parse_term (*,/) so 8 + 2 * 4 = 16 instead of 40.
Compiler: emit OP_NOP at start of NODE_BLOCK to trigger GC.
2026-02-18 02:26:44 +01:00
Jose Luis Montañes Ojados
4442886afa Add bytecode VM backend (compile AST to bytecodes + stack-based VM)
New execution mode: ./run vm <file.j> compiles AST to bytecodes and
runs them in a while/switch loop. Ints/floats live on the stack (no
heap allocation), ~7.7x faster than the tree-walking interpreter.

Implements: opcodes, compiler with backpatching (if/while), stack VM
with arithmetic, comparisons, variables, strings, and print/println.
Reorganizes backend into src/backend/eval/ and src/backend/bytecode/.
2026-02-18 01:01:22 +01:00
Jose Luis Montañes Ojados
65220f88c6 Add if statements, unary minus, and fix GC safe points
- Lexer: recognize 'if' as keyword (TOK_IF)
- Parser: add NODE_IF with if_statement union, parse if/cond/body,
  handle unary minus in parse_term as 0 - expr
- Eval: add NODE_IF evaluation, move GC to NODE_BLOCK level to avoid
  destroying temporary values during sub-expression evaluation
2026-02-16 05:12:28 +01:00
Jose Luis Montañes Ojados
84b3abbfda Add while loops, GC mark-and-sweep, and malloc block reuse
- Lexer: add INDENT/DEDENT tokens, <, >, : operators, while keyword,
  closing DEDENT emission, include guards
- Parser: add NODE_WHILE with while_loop union, parse while/cond/body
  blocks, include guards
- Eval: add while loop evaluation, GC integration with roots from env,
  debug and gc flags, <, > comparison operators
- GC: implement mark-and-sweep collector with 3 stages (mark roots,
  sweep unmarked, join free blocks)
- Allocator: block reuse via first-fit search with splitting, exponential
  heap growth, NULL check on malloc, include guards, marked field in metadata
- Object: add include guards, fix include to use allocator.h
2026-02-16 04:55:52 +01:00