Commit Graph

5 Commits

Author SHA1 Message Date
542255780d feat: add tuple index access, multiline args, and effect unification fix
- Tuple index: `pair.0`, `pair.1` syntax across parser, typechecker,
  interpreter, C/JS backends, formatter, linter, and symbol table
- Multi-line function args: allow newlines inside argument lists
- Fix effect unification for callback parameters (empty expected
  effects means "no constraint", not "must be pure")

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 16:21:48 -05:00
40c9b4d894 feat: complete JS backend with Dom effect and Html module
- Add full Dom effect: querySelector, createElement, addEventListener,
  setAttribute, classList, styles, forms, scrolling, etc.
- Add Html module for type-safe HTML construction (Elm-style)
- Add TEA (The Elm Architecture) runtime for browser apps
- Add view dependency analysis for Svelte-style optimizations
- Support both browser and Node.js environments

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-15 03:54:04 -05:00
38bf825134 feat: add effects to JS backend and fix code generation bugs
Phase 2 of JS backend: implement effect handlers in runtime

Effects added:
- Console: print, readLine, readInt
- Random: int, bool, float
- Time: now, sleep
- Http: get, post, postJson (async with fetch)

Bug fixes:
- Fix if-else with blocks executing both branches (use if-else
  statement instead of ternary for branches with statements)
- Fix main function being called twice when top-level let binding
  already invokes it
- Fix List module operations incorrectly treated as effect operations

New tests:
- test_js_random_int
- test_js_random_bool
- test_js_random_float
- test_js_time_now

All 19 JS backend tests pass.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 21:34:07 -05:00
ce4344810d test: add comprehensive integration tests for JS backend
Add 10 integration tests that compile Lux to JavaScript and verify
correct execution in Node.js:

- test_js_factorial: Recursion and effects
- test_js_fibonacci: Classic recursive algorithm
- test_js_adt_and_pattern_matching: Custom ADTs with match
- test_js_option_type: Built-in Option type handling
- test_js_closures: Closure creation and variable capture
- test_js_higher_order_functions: Functions as values
- test_js_list_operations: List.map, List.foldl
- test_js_pipe_operator: Pipe (|>) operator
- test_js_records: Record literal and field access
- test_js_string_concatenation: String operations

Also fix List module operations being incorrectly treated as effects
by adding special-case handling in EffectOp emission.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 21:28:07 -05:00
10ff8dc6ad feat: add JavaScript backend for browser/Node.js compilation
Implement Phase 1 of the browser/frontend plan with a complete JS
code generator that compiles Lux programs to JavaScript:

- Basic types: Int, Float, Bool, String, Unit → JS primitives
- Functions and closures → native JS functions with closure capture
- Pattern matching → if/else chains with tag checks
- ADT definitions → tagged object constructors
- Built-in types (Option, Result) → Lux.Some/None/Ok/Err helpers
- Effects → handler objects passed as parameters
- List operations → Array methods (map, filter, reduce, etc.)
- Top-level let bindings and run expressions

CLI usage:
  lux compile app.lux --target js -o app.js
  lux compile app.lux --target js --run

Tested with factorial, datatypes, functional, tailcall, and hello
examples - all producing correct output when run in Node.js.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 21:22:43 -05:00