Projects without an explicit frame hook got a bare ScreenName() call in
the generated main: no drawing frame and no viewport argument, which
did not compile against screens lowered as fn(Rectangle viewport).
Wrap the call in BeginDrawing/BeginUIFrame and pass the screen
rectangle, mirroring what hosts do around DrawAppScreen. The example
font helper is now included in kryon_project.c when the app block asks
for the examples font, and the examples link rule compiles
kryon_project.c alongside the module so the binaries actually contain
main.
'name: [N] T = {' opens an initializer: the declaration emits without
a semicolon, item statements join without one, and the brace closes
as '};'. Fixes the stray '{;' that broke compiling generated code
for array initializers spanning PushUIInspectSource lines.
'Name :: #define value' constants emitted in the .c only, but the
header's array bounds and extern declarations reference them (e.g.
extern char pending_path[ANDROID_IMPORT_PATH_MAX]), so every consumer
of the header failed to compile. Emit them in the header too, first and
under their #if guard, exactly like the .c emission.
- k2b drops its KC_* macro aliases (56 uses) for the KIR_* names.
- CHANGELOG, plan docs, examples README, scene-source comments all say
k2c; the removed 512-statement cap entry no longer names the dead
KC_BODY_MAX constant.
- k2c_lower: fix '&&' within '||' precedence in the member-access skip
and three scope_stack[scope_top++] sequence-point UBs that -Wextra
on the Android host build surfaced.
Legacy rule restored: non-public functions emit 'static
KRYON_PRIVATE_UNUSED' definitions with no header prototype, so two
modules can each define their own #private 'finish' without a link
collision. Forward static prototypes precede globals/state/functions
because initializers reference private functions ('.is_active =
practice_whm_is_active') before their definition.
- 'guard cond' lowers to if(cond) { defers; return; } (legacy rule).
- '[N] T name' parameters emit C declarator order.
- Cross-module alias calls match the import's file-path target against
the module source stem too — inbe imports name file paths
('src/screens/settings/settings_theme'), not dotted module names.
- Global initializers pass through rewrite_body2 (nil -> NULL, local
function-name resolution) and KIR_TEXT_MAX grew to 4096 so joined
multi-element initializers stop truncating mid-list.
- A trailing ':' (open ternary) continues the statement, matching the
existing leading-':' rule — multi-line ternaries now join.
- A pending that is just '{' is a scope-open, not a compound-literal
brace: the whole following block used to join into one statement
('{ labels: [7] const char* = {...} slot_w := ... for {...}').
- k2c bare-reference resolution never fires for 'name->'/'name.'
accesses: 'habits->count' resolved the screen name 'habits' into
'habits_kry_draw' whenever a module had a screen of that name.
Ports the legacy compile-conditional model onto Kir instead of skipping
unevaluated regions (which dropped '#if !WEB' desktop code inbe needs):
- kir_parse tracks a frame stack: '#if COND {', '} #else_if COND {',
'#else'. Conditions expand through 'Name :: expr' constants ('WEB ::
#defined(PLATFORM_WEB)' -> 'defined(PLATFORM_WEB)', '#defined' ->
'defined'); unknown identifiers stay for the C preprocessor.
- Top-level captures inside a region are stamped with the combined
guard (new 'guard' field on KirImport/KirGlobal/KirType/KirStateField/
KirFunction); k2c wraps every stamped item in '#if cond / #endif' in
both .h and .c. Body-level regions lower to raw #if/#elif/#else/
#endif statements with their braces consumed.
- 'static'/'#private' globals no longer emit a header extern; the .c
definition carries the 'static' prefix.
- 'name :: Type = init #global' splits type/init at ' = ' (the type
previously swallowed the initializer); '#private' ::-globals capture
as internal-linkage statics.
- Header emission order fixed: named enums and structs now precede the
extern globals referencing them.
'out_hex: [65] char' lowered as '[65] char out_hex' -- invalid C. Run the
parameter type through split_array_type like globals and fields, so it
emits 'char out_hex[65]'.
'args <decl>' inside a screen ('args InbeApp *app') appends parameters to
the function signature (colon screens only, top level of the body).
convert_args now emits colon-less parts as-is (C-style 'InbeApp *app')
instead of dropping them.
k2c_write_project runs after all files lower: kryon_project.h includes
every generated header; kryon_project.c auto-collects routes from public
screen-keyword functions (screen/preview/page/frame/scene/fn — the legacy
exact_name rule: colon helpers stay public-but-unrouted), emits
per-route wrappers dispatching on Rectangle/app-pointer/void args, the
route table, and CreateAppHost/DestroyAppHost over the weak
CreateApp/DestroyApp/ApplyRoute/BeginScreenDraw hooks. main() appends to
kryon_project.c from KirAppMeta (InitWindow/SetTargetFPS/InitUI/theme/
init-frame-shutdown hooks) unless --no-main.
Verified: a frame-app fixture emits a compiling project (main + route +
host ABI); the full krait corpus still compiles clean; make test green.
Globals emit without 'static' and get 'extern' declarations in the header
(krait's main.c references istate). Emission order fixed so enum constants
used as global array sizes are declared first.
Legacy naming restored: 'Name :: (...) {' functions get the module prefix
but NO _kry_draw suffix (screens keep it) — krait's module.kry references
these exact names. Bare identifier resolution now fires only in '= name'
assignment-RHS position, so locals shadowing function names (strlen(name))
are never rewritten. All 9 krait .kry files (ide/* + modules/kryon) now
compile with zero errors through the pure Kir pipeline.
Only bare identifiers followed by '(' resolve to module function C names;
field calls through '->' or '.' stay as-is (function-pointer typedef
fields like ModuleState.file_syntax).
- Typed-decl classification requires an identifier LHS (ternary fragments
like '1 : 0' no longer misclassify as decls).
- Ternary else-branches (': value' leading lines) join via one-line
read-ahead (lookahead stash).
- Typed decls convert array types to C declarator order with alias-stripped
bases (temp buffers, no src==dst snprintf UB).
krait ide/*.kry -> C now syntax-checks clean across state/app/editor/
widgets/preview/console/problems/start_page. kryon make test green.
- '#type' lines build real C declarators (name inserted after '(*' for
function pointers) and are matched BEFORE the struct '::' catch-all that
silently swallowed them.
- Enum members emitted with commas (newline-separated .kry members).
- Header emits typedefs, then enums, then structs (structs reference both).
- Ternary '?' and '&&'/'||' line continuations; pointer types ('char*') and
'<header.h>' closes no longer join.
- Global array sizes strip interior aliases via the body rewriter
('[state.MAX]' -> '[MAX]').
'Name :: C-type #type' is captured as a #typedef KirType and emitted as
'typedef C-type;'. The '>' closing '#import <header.h>' no longer triggers
the operator continuation (space required before < and > too).
Lines ending in a binary operator (&&, ||, +, -, *, /, %, =, <, >, comma)
now continue onto the next line (legacy line_needs_continuation), so
multi-line if conditions stay one statement. ++/-- are excluded. Global
array sizes with alias qualifiers (state.IDE_MAX_PANE_TABS) are stripped.
main now parses ALL inputs first (two passes), builds a per-module symbol
table (module slash-path + every function's .kry -> C name), then lowers
with it. alias.fn( calls resolve through the import target's module table
(start.draw_start_page(...) -> ide_start_page_draw_start_page_kry_draw(...));
same-module bare calls still resolve locally.
rewrite_body now rewrites bare calls ('draw_pane_group(...)') to the
module-prefixed C name ('ide_app_draw_pane_group_kry_draw(...)') when the
identifier names a function in the same module — the rewrite_kry_expr alias
rule.
strip_alias_type(src==dst) is UB via snprintf overlap — it emptied every
struct field type ('left_width;' with no type). Route through a temp.
#enum { A, B } blocks are captured (ENUM mode) and emitted as C enums.
Struct fields ('name: [N] Type') now emit 'Type name[N];' with alias
stripping, instead of verbatim .kry text. '#' comment lines inside struct
and function bodies are skipped (directives are top-level only).
Brace tracking: depth now counts NET braces at paren/bracket depth 0 only —
compound-literal braces inside calls (e.g. (Props){...}) no longer
mis-increment block depth, which previously ended function bodies early and
swallowed following top-level definitions.
Body rewrite: rewrite_nil became rewrite_body(m, ...) which additionally
strips 'alias.' qualifiers from identifiers when the alias is a module
import (state.IDE_PANE_LEFT -> IDE_PANE_LEFT), matching legacy
rewrite_kry_expr's alias rule.
KirType captures the struct body verbatim (TYPE mode in the parser); the
lowering emits typedef struct {...} Name; in the header. Return-type
extraction no longer swallows the opening brace of the function body.
Frontend (kir_parse.c): extract '-> T' return types from function headers;
capture #extern (body-less prototypes stay TOP-mode); capture
'name :: Type #global' module globals (KirGlobal in kir.h/kir.c).
Lowering (k2c_lower.c): functions named <module>_<name>_kry_draw (module
dots->underscores); return types in prototypes + definitions; #extern
emitted as prototypes only; #global emitted as statics; alias-qualified
types ('st: state.IdeState*') stripped to bare C types when the alias is a
module import of the same module.
Verified: k2c_syntax_test green; k2ir shows module imports captured.
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.
Call statements (EXPR kind with a '(' token) now get Push/Pop wrapping using
the KirStmt's source span (path:line). This is the first byte-identity detail
toward matching kc's output. Also adds #include "ui_inspect.h" to the
generated .c preamble.
Example output:
PushUIInspectSource("test.kry", 4);
Background(GetThemeBackground());
PopUIInspectSource();
make test green. Next byte-identity steps: __auto_type for ':=' decls,
function naming (_kry_draw), rewrite_kry_expr (nil->NULL), indent recompute.
Stage 2 start: k2c now has a --kir flag that parses .kry via the shared
kir_parse_file frontend and lowers KirProgram to .c/.h via k2c_lower.c.
The lowering currently produces structurally valid C (function definitions,
body statements, header guards, includes) but does NOT yet reproduce kc's
byte-for-byte output (PushUIInspectSource wrapping, __auto_type temps, defer
splicing, indent recompute, rewrite_kry_expr, module prefixing). Those land
fixture-by-fixture against the k2c_syntax_test.sh oracle.
The legacy pipeline (parse_kry + write_generated) remains the default path.
k2c links kir.c + kir_parse.c; make test green.
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).