Files
kryon/tests/runtime_declarations_test.sh
T
waozi c763af67d2 Share color math in the runtime and fix re-entrant runtime parsing
Move LightenColor/DarkenColor and their private HSL helpers from the C-only
src/ui/ui_color.kry into runtime/drawing_props.kry, which generates the tracked
include/ui_drawing_props.generated.h plus Go DrawingProps_LightenColor and
DrawingProps_DarkenColor. Delete include/ui_color.h and src/ui/ui_color.kry and
re-point kryon.h, ui_internal.h, button.kry, and system_theme.c at the generated
header.

Adding functions to an embedded runtime module exposed a k2c/k2cpp/k2go stack
overflow: runtime_program() cached a source only after kir_parse_source()
returned, so a type probe during parsing (a parenthesized expression whose first
token is an identifier, e.g. "(q - p)") re-parsed the same embedded source
forever. cmd/kir/kir.c now tracks the in-progress source and returns NULL until
its parse completes.

Also make runtime_declarations_test.sh skip the C-only runtime modules the
Makefile excludes from RUNTIME_GO_KRY.

Gates: generated-runtime-parity-test, fast-test, runtime-declarations-check,
k2c/k2cpp/k2go-syntax-test, go-runtime-test, examples-syntax-test, and
kryon-boundary-check pass; the public-API snapshot is regenerated.
2026-09-21 00:21:29 -03:00

102 lines
3.6 KiB
Bash

#!/bin/sh
# Generated public declarations must match the canonical runtime modules.
set -eu
build=${1:-build/linux-x86_64}
root=$(pwd)
work=$(mktemp -d "${TMPDIR:-/tmp}/kryon-runtime-declarations.XXXXXX")
trap 'rm -rf "$work"' EXIT HUP INT TERM
python3 scripts/embed-runtime-declarations.py "$work/runtime_declarations.generated.h"
cmp "$work/runtime_declarations.generated.h" cmd/kir/runtime_declarations.generated.h
"$build/bin/k2c" --strict --no-main --root . -o "$work/c" runtime/*.kry
"$build/bin/k2go" --strict --no-main --runtime-implementation --pkg kryon \
--root . -o "$work/go" runtime/*.kry
gofmt -w "$work/go"/*.go
cmp "$work/go/numeric_support.go" go/kryon/numeric_support.go
for source in runtime/*_props.kry; do
name=$(basename "$source" .kry)
cmp "$work/c/runtime/$name.h" "include/ui_$name.generated.h"
done
"$build/bin/k2js" --strict --no-main --root runtime --runtime ./kryon-runtime.js \
-o "$work/web" runtime/control_props.kry
cmp "$work/web/control_props.js" web/control_props.js
# runtime/guide.kry, guide_pager.kry, and profile_header.kry are C-only:
# the Makefile's RUNTIME_GO_KRY excludes them, so they have no checked-in Go
# output to compare against.
for source in runtime/*.kry; do
name=$(basename "$source" .kry)
case "$name" in
guide|guide_pager|profile_header|terminal_pane) continue ;;
esac
cmp "$work/go/$name.go" "go/kryon/$name.go"
done
# Preserve the C struct tag as well as the typedef when moving a public record.
cat > "$work/consumer.c" <<'C'
#include "ui_button_props.generated.h"
int main(void) {
struct ButtonProps value = {0};
ButtonProps *props = &value;
enum ButtonTone tone = ButtonToneAccent;
enum ButtonState state = ButtonStateHover;
props->tone = tone;
props->state = state;
props->class_name = 23;
props->disabled = true;
return props->disabled && props->tone == ButtonToneAccent &&
props->state == ButtonStateHover &&
props->class_name == 23 ? 0 : 1;
}
C
${CC:-cc} -Iinclude -I"$build/generated/include" "$work/consumer.c" -o "$work/consumer"
"$work/consumer"
# A relocated compiler resolves native props without a source checkout nearby.
cp "$build/bin/k2go" "$work/k2go"
cat > "$work/props.kry" <<'KRY'
#module "props"
Read :: () -> i32 {
props: ButtonProps = (ButtonProps){(Rectangle){1, 2, 3, 4}, "label", 17}
return props.id
}
Change :: (props: ButtonProps) {
props.id = 99
}
ReadZero :: () -> i32 {
props: ButtonProps
props.id = 18
Change(props)
return props.id
}
KRY
(cd "$work" && ./k2go --strict --no-main --pkg props --root . -o app props.kry)
cat > "$work/app/go.mod" <<MOD
module props
go 1.25.0
require github.com/waozixyz/kryon/go/kryon v0.0.0
replace github.com/waozixyz/kryon/go/kryon => "$root/go/kryon"
MOD
cat > "$work/app/props_test.go" <<'GO'
package props
import "testing"
func TestProps(t *testing.T) {
if Props_Read() != 17 || Props_ReadZero() != 18 {
t.Fatal("positional native props did not follow the declaration")
}
}
GO
(cd "$work/app" && GOWORK=off go test -mod=mod ./...)
cp "$build/bin/k2js" "$work/k2js"
(cd "$work" && ./k2js --strict --no-main --runtime ./kryon-runtime.js --root . -o js props.kry)
cp web/*.js "$work/js/"
printf '{"type":"module"}\n' > "$work/js/package.json"
cat > "$work/js/check.mjs" <<'JS'
import { Props_Read, Props_ReadZero } from "./props.js";
if (Props_Read() !== 17 || Props_ReadZero() !== 18) {
throw new Error("native props lost their field order, zero value, or copy semantics");
}
JS
node "$work/js/check.mjs"
echo "runtime declarations match generated C and Go interfaces"