Commit Graph
212 Commits
Author SHA1 Message Date
waozi 2726d54f72 Advance Kry compile-time checks and expression KIR 2026-08-19 18:12:26 -03:00
waozi dae552ec17 krb-run: remove the Linux framebuffer presentation backend
The fb host (mmap of /dev/fb0 or a raw-file stand-in, xrgb8888/rgb565
dirty-rect conversion) served no user: raylib covers desktop
presentation, the Canvas2D backend covers native web, and TUI is the
remaining terminal story. Drop the --backend fb / --fb-device /
--fb-format surface; krb-run keeps the headless PNG/recording flow the
conformance tests drive.
2026-08-18 18:16:43 -03:00
waozi eb9967ce29 theme: drop the dedicated Aero palette, keep the style palette-agnostic
The Aero widget style derives its glass tints from whichever palette is
active, so a 13th palette entry was redundant. Remove THEME_AERO (and
its ini mirrors, locale label and picker slot); the style now defaults
to Sky. Saved theme ids beyond the shrunken count normalize through the
existing out-of-range fallback.
2026-08-18 18:08:54 -03:00
waozi dc86744139 k2g: reach Go parity on the Runtime surface
The Runtime interface now covers every widget family go/kryui itself
exposes, not just the .kry whitelist: the positional controls
(GenericButton, TextButton, LocaleDropdown, VerticalSlider, CanvasGrid,
SelectableText, ShowUIToast(For)), the Props widgets (TextInputControl,
ReadonlyTextBox, TextArea, Radio, Spinbox, Combobox, LabelFrame,
Notebook, PanedView, Collapsible, ListBox, SourceView, TableView), the
dialogs, the canvas (BeginUICanvas/EndUICanvas), the Tk layout helpers
(BeginUIFrameBox, UIFramePack, UIGridCell, UIPlace), and theme control
(SetCurrentTheme/SetThemeDarkMode/SetThemeStyle with THEME_STYLE_*
constants under their C names).

k2g lowers .kry array declarations to Go slices at the use site
(state and local 'name: [N] const char*' references emit 'name[:]'),
accepts UICanvas literals like Props/Spec, and maps the canvas/Tk
handle types. The syntax gate now exercises the whole parity set and
still compiles the output against the real cgo runtime.

Honest remainder, noted in the matrix: DropdownEx's rich option
arrays, forward-goto-over-declarations, and C pointer/Texture2D
values stay outside what .kry can express.
2026-08-18 17:06:20 -03:00
waozi 49206d66d4 k2c: emit a runnable main for screen-only apps
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.
2026-08-18 16:55:59 -03:00
waozi 356b080ce6 tools: aero_shot renders the themed widget showcase to PNG
cmd/aero_shot draws one frame of every themed control (titlebar, tabs,
buttons, field, dropdown, slider, toggle, checkbox, progress, radios,
spinbox, glass panel) under any palette, mode and style, captures it
through the armed pre-swap readback and writes a PNG with kryon's own
writer. make aero-shot builds it; make aero-shots renders the
palette/mode/style reference matrix into build/<platform>/shots.
2026-08-18 16:55:59 -03:00
waozi f2a48285c9 k2g: lower typed declarations, arrays, and goto/labels for real
Declarations no longer degrade to 'any': the declared type is split
from the initializer before translation, go_type skips leading
whitespace and normalizes 'char *' to 'char*', and array types
('[N] const char*', '[N] int') map to Go arrays. Composite-literal
initializers take the Go form 'var x = [N]T{...}'. goto and label
statements emit verbatim — 'name:' and 'goto name' are valid Go, and
a forward jump over declarations stays a loud compile error rather
than a silent TODO.

The shared frontend now classifies a bare 'name:' as KIR_STMT_LABEL
(previously the kind existed but was never produced; labels only
worked through the raw-text path).

Generated code may pass the C-shaped option list to Dropdown/TextLines
— a ';'-joined string, a []string, or a [N]string array — so array
declarations feed widgets directly; Dropdown also tolerates the C
option-count argument, which the Go side derives itself.
2026-08-18 16:27:02 -03:00
waozi 95e96a8095 krb-run: --backend fb presents cartridges on the Linux framebuffer
Plan 11 phase 2 deliverable: mmap /dev/fb0 (or --fb-device /$FB_DEVICE),
query its geometry and pixel layout, and blit each frame's kry_sw dirty
rect converted to the target format — 32-bit truecolor by bit offsets
or RGB565. Ctrl-C stops the loop.

The device may be a regular file: then geometry comes from --w/--h and
--fb-format (xrgb8888 or rgb565) and the raw pixels are written back,
which makes the conversion testable without console hardware. The code
is __linux__-guarded so the windows/macos krb-run builds stay green.
2026-08-18 16:19:26 -03:00
waozi 1d5292704a k2b: lower Combobox to a KRB_CTRL_COMBOBOX control
Combobox((ComboboxProps){...}) previously had no lowering, so the
KRB_CTRL_COMBOBOX kind could never appear in a cartridge. k2b now
parses the Props literal (positional or designated) and emits the
control; the cartridge runtime routes it to the dropdown renderer,
exactly mirroring the C widget, which forwards to DrawUIDropdown.

Option lists can now come from .kry string-array variables (state or
local 'name: [N] const char* = {...}'), registered as joined 'a;b;c'
lists and usable by both Combobox and Dropdown lowering, not just from
inline literals.
2026-08-18 16:13:04 -03:00
waozi ecaa07b4f6 k2g: cover the full widget whitelist on the Go Runtime interface
Grow go/kryui so every whitelisted .kry widget statement lowers and
compiles through k2g: new Props/Spec types (PictureProps,
UIParagraphSpec, BottomNav/TopNav/Toolbar), cgo wrappers (TextInRect,
Paragraph, TextLines, Bevel, IconTexture by icon type, Picture, Toggle,
Modal, TitleBar, nav bars), the raylib color palette and picture-fit
constants under their C names, and the matching Runtime methods
(including Row/Stack, Key, Fade, theme getters, optional-border Rect).

k2g lowers positional Props/Spec literals through a C field-order table,
maps Id to ID, converts int-typed bool Props fields, and resolves the
color/fit constants. The syntax gate now exercises every widget and
still compiles the generated Go against the real cgo runtime.
2026-08-18 16:10:15 -03:00
waozi 537912b0a6 k2g: host bridge, enums, switch and full for headers
k2g now compiles real declarative apps, not just the smoke subset:

- '#extern "pkg.Fn"' lowers to a generated <Guard>Host interface with a
  Set<Guard>Host setter; extern calls become host.Method(...) with numeric
  argument conversions so int/long/float widening always compiles. The Kir
  frontend keeps the quoted host symbol on KirFunction.extern_target.
- 'Name :: enum' lowers to untyped Go constants with C counter semantics
  (explicit literal resets the counter; explicit expressions chain +1), and
  bare member names rewrite to the qualified Go constant at every use site.
- switch bodies translate: case/default labels, including brace-open forms
  and same-line bodies; Go auto-break replaces C fallthrough by design.
- C-style three-clause for headers ('for int i = 0; i < n; i++') become
  Go for headers with typed initializers; Go-style headers pass through.
- 'guard cond' lowers to a plain if (the body is the exit path).
- Assignments lower as statements; '} else {' chains emit on one line.
- Extended C-to-Go type map (short/size_t/long long/unsigned variants,
  char** slices, [N]T arrays, T* pointers, const stripping) removes the
  any-fallback for real signatures.
- Output is flat: nested source trees no longer nest Go files into
  separate packages; duplicate basenames are rejected.

go/kryui grows the widget surface declarative apps need: TabBar (real
DrawUITabBar cgo wrapper with plain string labels), Rect, RectGradientH,
Line, Progress, Checkbox, Dropdown and screen-size getters on the k2g
Runtime interface, plus DropdownLabels for ';' option lists.

tests/k2g_syntax_test.sh now covers the whole subset and keeps the
compile-against-the-real-runtime gate; the full suite passes.
2026-08-17 21:34:07 -03:00
waozi bc0a3999d0 ui: enforce cross-lowering text input latency 2026-08-17 20:26:30 -03:00
waozi 2b700da903 Revert "Fix C-style local declarations in k2c"
This reverts commit 2aae0190b2.
2026-08-17 19:44:34 -03:00
waozi 2aae0190b2 Fix C-style local declarations in k2c 2026-08-17 19:42:58 -03:00
waozi 3db6d5129c k2c: preserve anonymous enum declarations 2026-08-17 19:36:33 -03:00
waozi f8f5cd4c71 ui: add retained declarative tree and typed events 2026-08-17 18:55:05 -03:00
waozi 99bd4a01a9 ui: finalize deferred overlays at frame end 2026-08-17 12:20:36 -03:00
waozi 0a1dab897b go: add native runtime and stateful controls 2026-08-17 08:58:58 -03:00
waozi 7bc838d67a k2ir: strip block comments while reading lines
A multi-line /* ... */ comment before a function silently dropped it from
the generated C: a line ending in the comment close tripped the trailing-
slash continuation rule and glued the comment onto the next function
header, whose name parse then found no leading identifier. Lines starting
with the comment open were likewise swallowed as lookahead continuations.

Strip C-style block comments in place as each line is read (string/char
literal aware, newlines preserved so spans stay honest, state carried
across lines for comments that span them).

Also fix the plain-#-comment catch-all, added recently, swallowing real
#module and #import directive lines - the k2ir test regressed to
'module main' with a missing header import. Directives now fall through
to their own branches.
2026-08-17 08:33:19 -03:00
waozi 41687a5e48 KrbAutoMount: state initializers render without a host
DATA nodes now carry their initializer (ints in x, CSTRs via text),
and KrbAutoMount(img) binds them into malloc'd slots. krb-run and
krb-sdl both call it, so bound counters, checkbox defaults, and
TextField contents render identically with or without generated
host binds. Cross-engine 11/11 byte-identical; suites green,
goldens regenerated.
2026-08-17 08:15:25 -03:00
waozi 37282eaf81 kir_parse: skip plain # comments in TOP mode
A top-level comment line fell through the TOP dispatch and was
treated as a declaration header, silently swallowing the following
state/app/frame blocks into a bogus construct (the screen then
compiled to zero nodes). #if/#else/#endif/#defined still pass through
the conditional-frame machinery.
2026-08-17 08:09:02 -03:00
waozi 6d9702870a atlas: sub-pixel advances; language cartridge from traced values
KFA1 glyph advances are now 1/256-px fixed point ((int)(adv*scale*256
+0.5) at bake; single rounding at draw/measure, matching ui_text.c's
float path). Spec updated.

The instrumented title run exposed the real screen content: the title
is 'Choose Language' (locale key), not 'Language' — resolving the
width anomaly. The cartridge now uses the traced strings, sizes,
and positions ('Choose Language' fs24 phys(159,32), 'Language' fs16
(45,273), 'Next' fs12 (230,377)); per-mille scale verified in-binary
(scale=1125, scale_px(141)=159).

Native parity 5765 -> 5179/307200 (98.3%). The residual is the
classic last mile: every glyph edge sits one sub-pixel off between
an exact integer blit and GL quad rasterization — closing it means
emulating the GPU's quad fill/sample rule in kry_sw. Cross-engine
8/8 byte-identical (after rebuilding the stale SDL host); suites and
goldens green.
2026-08-17 07:12:25 -03:00
waozi d11c4b0b5a atlas: raylib's ascent-shifted glyph offsets + per-mille UI scale
The instrumented ui_text.c run pinned the native tier facts: ui
scale 1.125 (title tier base=27px for a 24 logical size), advances
w=9/adv=10 for 'L' — and glyph offsetY of +6 where raw stbtt gives
-15. raylib rtext.c line 730 adds (int)(ascent*scale) to every
offsetY: glyph offsets are line-top-relative. k2b_atlas now applies
the same shift; per-glyph values match the app trace exactly
('L' off=(1,6), 'a' (0,10)).

kry_sw's UI scale is per-mille (1.125 isn't expressible in integer
percent) with the same (int)(px*s+0.5) rounding as ScaleUIPx; the
native harness threads KRB_EXACT_UI_SCALE. The language cartridge
is now authored in logical units.

Native parity: 6423 -> 5765/307200; glyph positions track the
native within ~1-2px per element. Remaining: fractional-advance
storage (raylib keeps float advanceX; the u16 truncation drifts
~0.5px/glyph) and the title's measured width, under investigation.
Cross-engine: 8/8 byte-identical, suites green, goldens updated.
2026-08-17 06:56:02 -03:00
waozi cde2f3a6fb k2b atlas: fix GetCodepointBitmapBox extents; tier collection and UI-scale plumbing
Three fixes:
- stbtt_GetCodepointBitmapBox returns coordinates (x0,y0,x1,y1), not
  width/height — the measurement pass used raw coordinates, computing
  bogus buffer heights and silently clamping most glyphs away. This
  was the real cause of the missing text with inbe's subset font and
  the krb-sdl/krb-run cross-engine 'noise'.
- Atlas size collection now excludes SCROLL nodes (their font_size
  field carries content height — a 1250px 'font tier' blew the
  cartridge cap on scroll screens 21-24).
- Optional physical-scale plumbing: K2B_UI_SCALE bakes tiers at
  physical sizes, krb.c passes font sizes through scale_px,
  KRB_RUN_UI_SCALE sets the kry_sw UI scale, and the native harness
  threads KRB_EXACT_UI_SCALE (default 1).

Cross-engine exactness restored: 8/8 screens byte-identical
kry_sw == SDL. Native parity holds at 6423/307200 (98.0%); the
remaining delta is the native app's effective font tier for the
title (measured advances imply a physical size above 24 at
480x640), to be pinned by instrumenting ui_text.c once rather
than sweeping scales.
2026-08-17 06:36:20 -03:00
waozi 3d2d0d8ca1 kry_sw: ui_text.c advance rounding; krb-sdl: deterministic single-frame dump
Glyph pen advance now matches ui_text.c exactly:
(int)(advanceX*scale + 0.5f), applied to both draw and measure.
krb-sdl --png renders exactly one frame through the same
draw-then-readback path as the interactive loop, eliminating
frame-count nondeterminism for the exactness comparator.
2026-08-17 06:20:43 -03:00
waozi 554ce05ba5 k2b atlas: raylib-identical glyph rasterization
stbtt_PackFontRange replaced with per-glyph
stbtt_GetCodepointBitmap at stbtt_ScaleForPixelHeight plus
stbtt_GetCodepointHMetrics-scaled advances — the exact calls raylib's
rtext.c LoadFontData(FONT_DEFAULT) makes — row-packed first-fit with
bounds clamps. With KRB_EXACT_FONT pointing at inbe's subset face the
language screen reaches 6133/307200 differing pixels (98.0%): the
residual is raylib's DrawTextEx quad-sampling at glyph edges, not the
raster itself.
2026-08-17 06:12:59 -03:00
waozi e7fde24712 language cartridge: matched to the native reference frame
Measured geometry and palette from the first real native capture:
white background, centered title y37, label y284, dropdown x44/y299/
w391/h48 with #FBFBFB fill and #D3D3D3 border, text-only Next at
y379. krb-run gains KRB_RUN_THEME_LIGHT for the light palette.
Pixel diff vs the C build: 307200/307200 -> 6282/307200 (98.0%).
The remaining delta is glyph antialiasing parity between the KFA1
stb-baked atlas and inbe's raylib font pipeline — the last known
gap to literal 0.
2026-08-17 06:01:58 -03:00
waozi f2559ee56c k2c: initializer items take no inspect wrapper 2026-08-17 00:34:26 -03:00
waozi 0efd236bd5 k2c: multi-line array initializers
'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.
2026-08-17 00:27:34 -03:00
waozi f8d8c7fd1a k2g: .kry -> Go backend on the shared Kir frontend
Third backend alongside k2c/k2b: k2g lowers a KirProgram to Go source
that drives a Go kryon runtime (the cgo surface binding app uses), so
Go-native apps can be written in .kry. One frontend, three backends —
kry -> kir -> {c, krb, go}.

v1 fully translates the declarative subset: state blocks (Go struct +
instance), app metadata (generated main loop), frames, widget/surface
calls (rt.-qualified), compound literals (Vector2/Rectangle/Color),
scalar casts, hex/float literals, and state-field references including
address-of for scroll offsets. Imperative constructs are best-effort;
unsupported ones are emitted as commented TODOs rather than miscompiled.

Usage: k2g [--no-main] [--pkg NAME] [--runtime IMPORT] --root DIR -o DIR file.kry ...
Smoke-tested by tests/k2g_syntax_test.sh in 'make test'.
2026-08-16 23:51:09 -03:00
waozi 0b2c447d5d krb v2: animated geometry — WHM session screen runs live in-cartridge
New VM pieces: OP_MOD, and OP_NODE_SET (pops an i16 and patches a
node's x/y/w/h through a mutable node overlay allocated on first
use). TIME is now a first-class term in expressions. The k2b program
compiler was restructured around an ordered instruction stream
(updates, draws, guard/else brackets interleaved in source order) so
conditional assignments compile correctly — previously both branches
of an if always ran, last-write-wins. Updates accept full
term-or-term-arith-term right sides including % and TIME.

examples/26_inbe_whm_session.kry: the Wim Hof session as a cartridge —
TIME -> elapsed -> phase -> triangle wave -> animated ring radius via
AnimNode('ring0','w',&radius), breath counter with clamp, in/out
phase text. Verified across frames: t=0/600ms/5s produce the exact
expected phase, radius, and breath values. Eight exactness screens
byte-identical kry_sw == SDL.
2026-08-16 23:35:48 -03:00
waozi da6a472139 examples: habits screen cartridge (bound streak counters)
TextFormat now compiles to bound TEXT nodes correctly: the dispatch
was missing entirely, and the value/x/y/font/color args sit one slot
over from plain Text. Habits screen: scrollable rows with completion
checkboxes, live 'Streak: %d days' counters bound to state, and
conditional status lines. Engine goldens refreshed (the file held a
pre-atlas hash). All six exactness screens byte-identical kry_sw ==
SDL.
2026-08-16 23:12:49 -03:00
waozi f087c0654d krb v2: screen navigation — the whole app in one cartridge
KRB_FLAG_NAV buttons write a screen id to a state path on press
(cartridge-owned navigation; no host import). k2b compiles
NavButton(label, x, y, w, h, &state.screen, id). Screens are guarded
node ranges over one state field; examples/23_inbe_app.kry is Inner
Breeze as a single 6 MB cartridge — language, settings, and manual
screens with dropdowns, scroll, checkboxes, and the breath ring,
navigable end to end (verified: Next/Manual/Back transitions via
injected clicks). Scroll containers now draw a 1px outline instead
of a filled rect. All five exactness screens byte-identical
kry_sw == SDL.
2026-08-16 23:01:39 -03:00
waozi 2dda6f2f4a examples: settings screen cartridge (scroll + dropdowns + checkboxes)
Declarative port of inbe's settings/device tab: scroll container with
clamped wheel offset, language and orientation dropdowns, fullscreen
and keep-screen-on checkboxes, conditional hint rows via if/else.
k2b's Scroll() now parses ScaleUIPx content heights (atoi gave 0, so
the wheel clamp never engaged). Cross-engine exactness extended to
this screen: kry_sw == SDL byte-identical.
2026-08-16 22:54:18 -03:00
waozi 22f055ffd1 k2b: fix guard single-term parsing, positional ButtonProps, dropdown height
parse_term now returns consumed length (single-term guards like
'if (x == 0)' previously fell through to nothing while arithmetic
forms worked by accident). ButtonProps positional initializers
(label-first, Rectangle bounds) parse alongside the designated form.
Dropdown accepts an optional height argument.

examples/20_inbe_language.kry: a faithful declarative Inner Breeze
language-picker screen — title, bordered locale dropdown with five
options, if/else hint text, Next button — compiles to a cartridge
that renders complete in every engine with its embedded atlas.
2026-08-16 22:18:33 -03:00
waozi 2151e61414 k2b: arithmetic expressions in guard conditions
Each side of an if comparison is now term or term arith term
(path or integer, + - * /), compiled to the VM stack machine:
if (a + 1 < b - 2) emits PUSH/PUSH/ADD, PUSH/PUSH/SUB, LT, JZ.
2026-08-16 22:12:56 -03:00
waozi e9fe1e17e0 krb v2: dropdown controls
KRB_CTRL_DROPDOWN (kind 4) implemented end to end: the control record's
reserved options_off/option_count now carry consecutive NUL-terminated
option strings (k2b appends them without interning so they stay
contiguous; Dropdown(id,x,y,w,"a;b;c",&val)). Click toggles the popup,
clicking a row writes the selected index to the bound int and closes.
Loader initializes the open-dropdown slot to -1 (0 is a valid index).
2026-08-16 22:11:03 -03:00
waozi 84bd26de20 krb v2: text input — TEXTINPUT node + typed-codepoint vtable path
New node type 13: bounded field drawing the mounted CSTR with a
blinking caret when focused (click to focus). Typed input flows through
the new optional KryBackend.text_key (codepoints, 0x08 backspace):
kry_sw queues via KrySwText (drained per frame by Advance), the raylib
surface backend maps GetCharPressed, SDL maps SDL_TEXTINPUT/BACKSPACE,
krb-web exports krb_web_text from keypress events. UTF-8 runes append
and strip correctly. k2b compiles TextField(x,y,w,h,&state.field).

Verified: click-focus, typing with backspace, and that unfocused
fields ignore keys.
2026-08-16 22:06:53 -03:00
waozi cb6faf430d krb v2: scroll containers
SCROLL node (type 12): viewport bounds, content height in font_size,
mounted pixel offset at name_off. Children (parent = scroll index)
draw translated by -offset and clipped to the viewport; a new
optional KryBackend.wheel entry drives the offset when the pointer is
over the viewport, clamped to [0, content_h - h]. Implemented in
kry_sw (+KrySwWheel injection), the raylib surface backend, the null
and recorder backends; krb-sdl maps SDL_MOUSEWHEEL, krb-web exposes
krb_web_wheel from canvas wheel events. k2b compiles

  Scroll(x, y, w, h, contentH, &state.off) ... EndScroll()

bracketing child widgets (parent-linked). Fixed a compounding-offset
bug where draw_tree's origin was mutated across children.
2026-08-16 22:03:44 -03:00
waozi c1be0cb82d k2b+engines: KFA1 glyph atlas — antialiased Noto text in cartridges
- k2b bakes a per-cartridge atlas (stb_truetype over the vendored
  NotoSans) covering the cartridge's charset at its used pixel sizes,
  embeds it as the kind 1 asset '@atlas'. K2B_FONT overrides the face.
- kry_sw renders atlas text: UTF-8 decoding, per-glyph advances,
  source-over coverage blending, nearest-size scaling; measure uses
  real advance widths. KrySwSetAtlas installs it; krb-run, krb-sdl,
  and krb-web all load '@atlas' after KrbLoad.
- Cartridge cap raised 64 KiB -> 16 MiB (output buffer static) to fit
  atlases/images; krb_cartridge_test budget adjusted. Engine goldens
  regenerated (atlas advances change text layout).
- Fixed on the way: atlas record stride (18 bytes), pack buffer
  ownership, and a realloc'd-header write in the baker.

Verified: 'Ag' at 24px renders as antialiased glyphs from embedded
bytes; full krb suite green.
2026-08-16 21:59:11 -03:00
waozi 6b59bc6109 k2b: else branches and state-vs-state guard comparisons
'if (a > b) { ... } else { ... }' now compiles to compare + JZ/JMP
with true and false node ranges; the right side of a comparison can
be another mounted state path (PUSH_PATH) or an integer literal
(PUSH_CONST). Verified both branches with mounted and unmounted
state.
2026-08-16 21:46:10 -03:00
waozi ddcf455dd3 k2b: decode png/jpg/bmp/webp and embed as cartridge pixels
stb_image (vendored with raylib) decodes referenced Picture() files at
compile time; decoded RGBA8 goes in as kind 0 and renders through
texture_rgba in every engine. KRAW stays for hand-made raw pixels;
undecodable files (wav/ogg/fonts) remain opaque kind 2 blobs for
host-side unpacking. Verified: png cartridge renders after the source
file is deleted.
2026-08-16 21:42:09 -03:00
waozi 3b92292e19 renderers: web player opens any .krb + CI builds per-platform downloads
- krb-web is now a player: drop or pick a .krb, it writes to MEMFS
  and boots the cartridge (krb_web_start export); no preload, the
  bundle is a generic renderer. Drag-drop + file picker + canvas
  mouse with correct scaling. Serving it anywhere gives the web a
  KRB renderer.
- .github/workflows/renderers.yml: matrix builds krb-run binaries
  (linux, windows mingw cross, macos) and the web player; artifacts
  on every push, attached to releases on tags.
2026-08-16 21:37:28 -03:00
waozi 91d96a4983 k2b: embed referenced assets into the cartridge
k2b now packs what a cartridge references, making it self-contained:

- Every Picture() path resolvable under --root is embedded at emit
  time. .kraw files (KRAW magic + u16 w,h + RGBA8 pixels) go in as
  kind 0 and render through texture_rgba in every engine; any other
  file (png, wav, ogg, fonts) is embedded verbatim as a kind 2 opaque
  blob for host-side decoding via KrbAssetFind — sounds and arbitrary
  assets ride in the same section, unpackable by the application.
- The recorder backend forwards+logs texture_rgba (a NULL entry on
  the wrapper silently forced the host-path fallback).

Verified end-to-end: a cartridge whose tile.kraw is deleted after
build still renders the picture, scaled and tinted, purely from
embedded bytes (texture_rgba 2x2 -> 8x8 in the recorded stream).
2026-08-16 21:34:46 -03:00
waozi 6bad9e7e27 k2b: compile .kry state updates and if-guards into v2 VM programs
Cartridges stop needing host C for simple per-frame logic:

- k2b collects '<path> =/+=/-= N', '++', '--' statements from frame
  bodies and simple 'if (<path> <cmp> <int>)' guards over widget
  ranges, and emits them as VM opcodes: state updates run first, then
  one OP_DRAW_NODE per drawable node with guarded ranges wrapped in
  compare + JZ. Render-only cartridges still emit a single
  OP_DRAW_TREE (golden output unchanged).
- parse_color now understands (Color){r,g,b,a} literals everywhere
  (Rect etc.), not just in the circle parser.
- KrbExec JZ bug fixes: the jump-if-zero polarity was inverted, and a
  taken jump was clobbered by the executor epilogue. Both were masked
  by the hand-written test compiling its guard in positive form; a
  k2b-compiled cartridge exposed them.
- krb-run --frames N runs the cartridge N frames (advancing time and
  press edges) for observing state-dependent behavior headlessly.

Verified end-to-end: a .kry with counter += 1 and an if (counter < 4)
guard compiles to a 35-byte program; the guarded rect renders on
frames where the condition holds and disappears after, with the
counter mount showing 1+N.
2026-08-16 21:17:50 -03:00
waozi 89dc220fda krb v2: in-cartridge logic VM + circle/ring geometry nodes
The plan-07 core: cartridges stop being static pictures.

- New v2 opcodes: a 16-deep int stack machine (PUSH_CONST/PUSH_PATH/
  POP_STORE, ADD..GE, JMP/JZ, TIME) plus OP_DRAW_NODE so UI can be
  conditional on mounted state. Loader accepts v1 and v2; k2b now
  writes version 2.
- New node types CIRCLE (center+radius) and RING (annulus), the shapes
  the inbe breath visualizer needs; k2b parses DrawCircleV/DrawRing
  (with (Color){r,g,b,a} literals). KryBackend gains optional circle/
  ring entries — implemented in kry_sw, the raylib surface backend,
  the null backend, and forwarded+logged by the recorder.
- tests/krb_logic_test.c: hand-assembled v2 cartridge proving counter
  increments per frame, conditional node visibility across frames,
  circle/ring rasterization bounds, and TIME. Engine golden test passes
  unchanged on v2 output (render back-compat).
- KRB_FORMAT.md documents v2 and the R>=0x80 theme-slot color caveat.
2026-08-16 20:37:44 -03:00
waozi 8952cbf3af krb-sdl: SDL2 desktop host for KRB cartridges
Plan 11 phase 7 (pulled forward as the Android-template host):
kry_sw renders, SDL2 owns window/input/presentation via a streaming
RGBA texture. --png renders one frame through the renderer and reads
it back, for headless conformance under SDL_VIDEODRIVER=dummy.

Verified: SDL software-renderer readback of examples/02_buttons.kry at
400x300 is byte-identical (sha256) to the native golden frame — native,
wasm web, and SDL now render the same image.

make krb-sdl (pkg-config sdl2; on omega PKG_CONFIG_PATH points at
~/.local/sdl2 automatically in the rule).
2026-08-16 20:23:47 -03:00
waozi 14c8223acc k2c: fix one-line control blocks, char literals, and locals named c
Three parser defects that made k2c exit 0 while emitting broken C:

1. One-line control blocks ('if cond { body }', also while/for/switch/
   case/else/guard) glued the braces into the condition. The finalized
   logical line is now split into header/body/'}' and the parts re-enter
   the main loop through a FIFO that outranks the stashed lookahead
   (whose single slot the read-ahead would otherwise overwrite, losing
   source lines). The read-ahead is also skipped for queued parts and
   while a stash is pending.
2. Char literals containing structural characters ('"', '[', ']', '{',
   '}') toggled the string/bracket scanners and swallowed following
   lines; both brace scanners now skip char literals.
3. An assignment to a local named c was classified as a raw 'c <line>'
   escape and emitted without its trailing semicolon; assignment
   operators after the c token now fall through to the normal
   statement path.
2026-08-16 20:21:40 -03:00
waozi f2e86d9f0d krb-web: native web engine — kry_sw compiled to wasm, blitted to ImageData
Plan 11 phase 3, wasm-first variant (pixel-identical to native):

- cmd/krb-web/main.c: emscripten host running the KRB runtime + kry_sw
  rasterizer; each frame blits the RGBA buffer into an ImageData via
  EM_ASM. Cartridge preloaded at /app.krb, canvas mouse events fed back
  through exported krb_web_mouse/krb_web_button.
- cmd/krb-web/shell.html: minimal shell wiring Module.canvas and input.
- cmd/krb-web/node-capture.js: pre-js for the KRB_WEB_ONESHOT node
  build; stubs a canvas 2D context and dumps the blitted frame to stdout
  so the wasm blit path is testable without a browser.
- make krb-web KRB=examples/xx.kry builds the cartridge + bundle
  (needs emcc on PATH, e.g. source ~/emsdk/emsdk_env.sh).

Verified: node oneshot capture of examples/02_buttons.kry at 800x600 is
byte-identical (sha256) to the native krb-run render; page loads and
runs in a browser.
2026-08-16 20:21:36 -03:00
waozi 6a0591086a krb: kry_sw software rasterizer engine + headless conformance harness
Plan 11 phases 1-2 core:

- src/backend/kry_sw.c: portable software rasterizer behind the
  KryBackend vtable. RGBA8 target with RGB565 conversion, clip stack,
  input injection, theme slots, public-domain font8x8 text (glyph-atlas
  pipeline replaces it later without interface changes).
- src/backend/kry_backend_rec.c: recording backend that logs the
  cartridge draw-call stream while delegating to an inner engine.
- cmd/krb-run: headless cartridge runner; renders one frame to PNG
  (dependency-free writer, stored deflate) and/or dumps the call stream.
- tests: kry_sw unit test plus tests/krb_engine_test.sh golden
  conformance over examples/02_buttons.kry (sha256 goldens, refresh
  with KRB_ENGINE_REGOLDEN=1), wired into make test / make tools.
2026-08-16 20:05:20 -03:00