Commit Graph
9 Commits
Author SHA1 Message Date
waozi 2726d54f72 Advance Kry compile-time checks and expression KIR 2026-08-19 18:12:26 -03:00
waozi 93081e4492 test: cover legacy k2c declarations 2026-08-17 19:44:16 -03:00
waozi 3db6d5129c k2c: preserve anonymous enum declarations 2026-08-17 19:36:33 -03:00
waozi 7ebedf9360 kir joiner: adjacent string literals on continuation lines join
A statement whose last token closes a string literal continued nowhere:
the trailing '"' is not a continuation operator, so every fragment of
the C adjacent-literal idiom ("..." \n "..." \n "...") was released
as its own orphan expression statement and the initializer kept only
its first fragment — SQL built that way prepared from a truncated
string and failed silently. The lookahead continuation now also joins a
line that opens a string literal when the statement so far ends with a
closing one, recomputed per joined fragment so chains work.
2026-08-14 19:53:41 -05:00
waozi 807e3fde58 kir joiner: '} #else_if COND {' region chains complete as statements
A chained region closer starts with '}', so the header-line word scan
saw nothing and the trailing '{' counted as an expression brace: the
line kept joining until braces balanced, swallowing the whole branch —
data_root's #if WEB/#else_if ANDROID/#else_if WIN32/#else chain lowered
to just the first region with no #endif, leaving desktop builds with an
empty data root and silently dead storage. Region braces after a '}' now
count as block braces (both FUNCTION-mode lowering and TOP-mode frames
already accept the optional leading '}'). Syntax test covers a full
chain: every branch, the expanded conditions, and the #endif.
2026-08-14 17:59:46 -05:00
waozi f9cd8b2353 tests: default tool paths to the canonical per-platform bin dir
The standalone defaults still pointed at the removed legacy build/bin
aliases. Default to the current platform's build/<plat>-<arch>/bin
first, then any platform dir; the Makefile still passes $(K2C) etc.
explicitly.
2026-08-14 14:56:43 -05:00
waozi db8ae1486e kir: parse K&R '} else {' as close + else re-open
The line-leading word scan saw only '}', so '} else {' failed the
header-line test: its trailing '{' counted as an expression brace and
the tokenizer kept accumulating until braces balanced, merging the else
and its whole body into one BLOCK_CLOSE. Even split correctly, FUNCTION
mode routed any '}'-leading line to a plain BLOCK_CLOSE, dropping the
else the k2c lowering expects as an IF starting with "else". Emit
BLOCK_CLOSE + IF("else ...") with net-zero depth, and teach the brace
classifier that '} else' braces are block braces. Allman else on its own
line already worked (and stays covered); k2c_syntax_test now covers the
K&R form whose else branches used to vanish silently.
2026-08-14 14:27:30 -05:00
waozi 07222de4f8 k2c: Kir is the only pipeline — delete the entire legacy compiler
The legacy kc line-matcher is gone. k2c is now exclusively:
  .kry -> kir_parse_file() -> KirProgram -> k2c_lower() -> .c/.h

Deleted (the whole legacy pipeline):
- cmd/k2c/kc.c (parse_kry line-matcher, 3300 lines)
- kc_codegen.c (write_generated/write_body_line), kc_defer.c (apply_defers
  brace-counting splice), kc_ast.{c,h} (Phase-1 AST reconstruction),
- kc_ir.c, kc_resolve.c, kc_macros.c, kc_diag.c, kc_project.c, kc_util.c,
- kc_internal.h, and the --emit/--dump-ast/--kir flags.

New k2c main.c is a thin CLI over kir_parse_file + k2c_lower. The lowering
implements the essential translation rules on Kir statements:
- ':=' decls -> __auto_type; typed decls -> 'T x = e;' with {0} zero-init
- multi-assign temps (__kryon_assign_<line>_<k>, temps-first ordering)
- nil -> NULL rewrite; unused X -> (void)X;
- if/else-if/else chains with parens + close-suppression before else
- while/for/switch headers with parens; case at parent indent
- defer registered per scope, spliced LIFO at block close and return
- call statements wrapped in PushUIInspectSource/PopUIInspectSource with
  source spans; goto/labels; state fields with C array declarator order
- screens named <Name>_kry_draw; args 'name: Type' -> 'Type name';
  header guards K_<PATH>_H with _H suffix

tests/k2c_syntax_test.sh rewritten for the Kir-based output (fixture +
assertions + compile check of the generated C). make test green.
2026-08-14 06:59:58 -05:00
waozi 2f11e1e773 Rename kc to k2c (kry-to-C compiler)
The .kry->C compiler is now k2c, not kc. This is the first step toward making
Kir the single source of truth (k2c and k2b will both lower from Kir).

- cmd/kc/ -> cmd/k2c/ (directory moved; internal file names unchanged).
- Makefile: KC -> K2C, LEGACY_KC -> LEGACY_K2C, build/bin/kc -> build/bin/k2c.
- tests/kc_syntax_test.sh -> tests/k2c_syntax_test.sh (default binary updated).
- examples/Makefile: KC -> K2C; the two stale --emit-krb lines now use k2b.
- make test green (k2c_syntax_test passes via k2c).
2026-08-13 20:09:53 -05:00