Commit Graph

16 Commits

Author SHA1 Message Date
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
2c91cbb561 Add // line comments, grouped parentheses, and NODE_NOP
- Parse // comments in parse_statement by consuming tokens until newline
- Add NODE_NOP for no-op statements (comments)
- Support grouped expressions with parentheses in parse_term
2026-02-16 22:41:52 +01:00
Jose Luis Montañes Ojados
21efb0563b Allow function calls in expressions and add len() built-in
- Parse function calls in parse_term() so they work inside expressions
  (e.g. z = len(x), y = len(x) + 1)
- Add len() built-in for string length in evaluator
2026-02-16 18:31:39 +01:00
Jose Luis Montañes Ojados
a36e52a9c3 Replace print/println keywords with generic function call mechanism
- Add NODE_CALL with name, args, and arg_count to parser
- Add TOK_COMMA token and tokenize (, ), , in lexer
- Remove TOK_PRINT/TOK_PRINTLN keywords; print/println are now regular
  identifiers resolved as built-in functions in the evaluator
- Add NODE_CALL debug output in ast_print
2026-02-16 18:14:39 +01:00
Jose Luis Montañes Ojados
dd67537598 Add string type support: literals, concatenation, println, and if eval
- Implement string literal tokenization and parsing (lexer + parser)
- Add string concatenation with + operator in evaluator
- Add println keyword for printing with newline
- Add NODE_IF evaluation in VM
- Fix null terminator bug in string concat buffer
2026-02-16 17:40:12 +01:00
Jose Luis Montañes Ojados
667e5564b8 refactor(allocator): use memset when creating allocator 2026-02-16 05:16:41 +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
Jose Luis Montañes Ojados
14b6a2ddd2 Add * and / operators, VM step debugger, and visualizer tweaks
Support multiply and divide in lexer, parser and eval.
Add step-by-step VM debug output with AST and heap visualization.
Remove spacing in visualizer hex output.
2026-02-16 02:24:37 +01:00
Jose Luis Montañes Ojados
01740d4892 Add evaluator with environment and file-based execution
Implements recursive AST evaluator with variable environment,
reads .j files from command line args, and executes programs
end-to-end (lexer -> parser -> eval).
2026-02-16 02:08:54 +01:00
Jose Luis Montañes Ojados
e2896fac5b Add lexer, parser and AST debug printer
Implements tokenizer for basic tokens (INT, ID, ASSIGN, PLUS, MINUS, NEWLINE, PRINT),
recursive descent parser for assignments and binary expressions, and
tree-formatted AST visualization with ast_debug().
2026-02-16 01:36:41 +01:00
Jose Luis Montañes Ojados
d14227efeb Add list type, obj_free for compound types, and self-reference guard
- Implement OBJ_LIST with offset-based items array and capacity
- obj_free now releases child allocations (string buffer, list items)
- obj_print detects self-referencing lists to prevent infinite recursion
- Visualizer distinguishes freed blocks (JLANG_NOT_USE) from active ones
- JLANG_free now zeroes payload on release
2026-02-16 00:33:02 +01:00
Jose Luis Montañes Ojados
13c9d052a0 Refactor allocator to use offsets instead of absolute pointers
JLANG_malloc now returns size_t offsets relative to the heap buffer,
making all references stable across heap growth (realloc). Object API
updated accordingly: constructors return offsets, obj_print/obj_free
receive (allocator, offset). Added heap auto-grow when out of space.
2026-02-15 23:17:51 +01:00
Jose Luis Montañes Ojados
5dc0946a19 add JLANG_free and Object 2026-02-15 22:12:19 +01:00
Jose Luis Montañes Ojados
c90883ac27 base allocator logic 2026-02-15 20:57:19 +01:00
Jose Luis Montañes Ojados
74b426e12d first commit 2026-02-15 20:48:01 +01:00