Commit Graph

15 Commits

Author SHA1 Message Date
f836f279de Feat: add -S flag to emit LLVM IR
`-S` stops the pipeline after IR emission and writes the `.ll` file
directly to the output path (default `<stem>.ll`). It implies `-c`
(no main required). Combined with `-o`, the IR goes to the specified
path.

Pipeline summary:
  (none)  →  emit → opt → llc → cc  →  executable
  -c      →  emit → opt → llc       →  <stem>.o
  -S      →  emit                   →  <stem>.ll

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-11 20:28:24 +01:00
c2fc83b74b Feat: add LLVM IR backend with opt/llc pipeline
Implements a full LLVM IR text emitter and three-step toolchain:
  1. Emit LLVM IR (.ll) via alloca-based codegen (mem2reg-friendly)
  2. `opt -O2` → optimised IR          (override with FLUXC_OPT)
  3. `llc -filetype=obj` → object file  (override with FLUXC_LLC)
  4. `cc` → link into executable        (override with FLUXC_CC)
     (step 4 skipped in -c mode)

Emitter supports all Flux types, operators, control flow (if/else,
while, loop, break, continue), structs, arrays, pointer operations,
function calls, string literals, and integer literal type inference
via UnboundInt → concrete-type coercion.

Also adds -o <file> CLI flag, exposes CheckResult from the checker
(sigma + phi tables reused by codegen), and updates main.rs to run
the full parse → check → codegen pipeline.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-11 20:21:34 +01:00
9aa6b9694b Feat: add -c flag to skip entry-point check
`fluxc -c <file>` compiles a source file without requiring a `main`
function, matching the convention of C compilers. Pass 4 (entry-point
validation) is skipped when `no_main` is set.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-11 15:36:43 +01:00
bb5e9e42d9 Feat: add UnboundInt type for integer literal inference
Integer literals now produce `Ty::UnboundInt` instead of a hardcoded
`i32`. This flexible type promotes to/from any concrete integer, so
literals resolve naturally in context (e.g. `n < 2` when `n: u8`
works without an explicit cast).

`common(UnboundInt, T)` returns `T` when `T` is a concrete integer,
so binary ops adopt the concrete operand's type. Includes 8 new tests
covering literal coercion, fibonacci-style patterns, and negative cases
(literals still don't coerce to float types).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-11 15:34:18 +01:00
1f3d64f97c Test: fix parser generic annotations and add checker test suite
- Fix two test helpers (top/program) missing <Parsed> type argument
- Add checker/tests.rs with 74 tests covering all §7/§8 rules: entry
  point validation, duplicate defs, struct cycles, literals, promotion,
  type inference, definite assignment, undefined vars/funcs, arithmetic,
  shift, comparison, logical ops, unary ops, pointers, struct literals,
  field/index access, function calls, return checking, mutation, and
  break/continue
- Fix assignment LHS check: bare identifier on the write side of `=`
  must not trigger "uninitialized" — use lhs_ty() helper that skips
  the assigned-set check for the direct write target

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-11 15:17:28 +01:00
aca0dae7de Feat: add type-state AST and semantic analysis pass
- Update ast.rs with Phase trait (Parsed/Typed), Ty enum, and generic
  AST nodes so the same tree works pre- and post-type-checking
- Add checker/ module implementing the 4-pass semantic analyser from
  SEMANTICS.md: struct/function collection, field resolution + size-cycle
  detection, full expression/statement type checking, and entry-point
  validation
- Wire checker into main; semantic errors are only run when the parse
  succeeds and are rendered with the same diagnostic machinery

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-11 15:12:10 +01:00
7cdcad7df3 Feat: add mutable pointer type *mut T and *mut opaque
- Grammar: update pointer_type to support optional mut keyword;
  LL(1) verified (56 named rules, no conflicts)
- AST: update Type enum with mutable: bool field for Pointer and
  OpaquePointer variants
- Parser: consume optional mut token in parse_type; update all
  existing pointer tests; add 4 new mut pointer tests (85 pass)
- VSCode extension: add *mut capture-group pattern for syntax
  highlighting; update SYNTAX.md with pointer mutability table

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-11 10:37:21 +01:00
415dea6fd2 Feat: improve CLI with help menu and multi-file support
Extracts all argument-parsing and help logic into cli.rs:
- -h / --help: colored usage and options summary
- -V / --version: print version from Cargo.toml
- Unknown flags produce a styled error with a hint
- At least one file required; missing-file error is styled
- Multiple files accepted; exit code 1 if any file has parse errors
2026-03-10 18:49:15 +01:00
5bf4a494cb Feat: add structured diagnostics with yansi colors
Introduces fluxc/src/diagnostics.rs with Level (Critical, Error,
Warning, Note), Label (Primary/Secondary with optional message), and
Diagnostic types. Diagnostic::render(src, filename) produces
rustc-style output: colored header, --> file:line:col pointer, source
line with gutter, and ^ / - underlines aligned to the offending span.

Replaces the flat ParseError struct in the parser; all five error
sites now emit Diagnostic values with source-pointing labels.
2026-03-10 18:44:29 +01:00
a82b7e4633 Feat: add compound assignment and shift operators
Compound assignment: +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=
Shift: <<, >>

Each compound assignment token parses at the same precedence as `=`
(right-associative, lowest) and produces ExprKind::CompoundAssign.
Shifts parse between additive and multiplicative precedence.
GRAMMAR.ebnf and SYNTAX.md updated accordingly.
2026-03-10 18:29:52 +01:00
1a4e464d5e Fix: add assignment as right-associative expression
`=` was missing from the Pratt table, causing `a = b;` to fail with
"expected `;`, found `=`". Assignment is now BinaryOp::Assign with
binding power (2, 2) — lowest precedence, right-associative — so
`a = b = c` parses as `a = (b = c)`.
2026-03-10 18:16:25 +01:00
546dc119d0 Add function/struct definition parsing and program entry point
- ast.rs: Param, FieldDef, FuncDef, StructDef, TopLevelDef,
  TopLevelDefKind, Program
- parser.rs: parse_program, parse_top_level_def, parse_func_def,
  parse_struct_def with param/field list helpers;
  synchronize_top_level for recovery; 14 new tests (76 total)
- main.rs: parse source file as a Program and print the AST
2026-03-10 18:03:56 +01:00
d556a54541 Add statement parsing with error recovery
- ast.rs: add Type, Block, ElseBranch, Stmt, StmtKind
- parser.rs: parse_type, parse_block, parse_stmt and all sub-parsers;
  missing-token insertion via expect(), synchronize() for panic-mode
  recovery on non-startable tokens; 26 new tests (62 total)
- main.rs: REPL now parses statements instead of bare expressions
2026-03-10 17:55:22 +01:00
becc7a2d34 Add expression AST and Pratt parser with REPL
- ast.rs: Expr/ExprKind with UnaryOp, BinaryOp, StructField
- parser.rs: Pratt expression parser with allow_struct_literals flag,
  error recovery via dummy tokens, and 19 unit tests
- main.rs: interactive expression REPL (prints parsed AST)
2026-03-10 17:40:52 +01:00
4f80de51b2 Add fluxc compiler skeleton: token definitions and lexer
Introduces the fluxc Rust crate with the first two compiler stages:

- token.rs: define_tokens! macro generates TokenKind enum and its
  Display impl from a single table covering all Flux tokens
  (literals, keywords, operators, punctuation, Eof/Unknown).
  Span (half-open u32 byte range) and Token<'src> (kind + span +
  zero-copy text slice) round out the module.

- lexer.rs: Lexer<'src> produces Token<'src> from a source &str.
  Skips whitespace, // line comments, and /* */ block comments.
  Handles all integer bases (decimal, hex, octal, binary with _
  separators), floats (fractional + exponent), string/char literals
  with escape sequences, and Unicode identifiers via unicode-xid.
  Implements Iterator<Item = Token> and includes 17 unit tests.

Also adds .gitignore (ignores fluxc/target) and expands
examples/fibonacci.flx with an iterative variant.
2026-03-10 17:20:17 +01:00