Kry Source Language

Language Reference

Kry is C-close application code for Kryon. This page mirrors the canonical source contract in docs/KRY_LANGUAGE_SPEC.md: source lowers into KIR first, then the same KIR can produce readable C, Go bindings, browser-loadable JS, or portable KRB cartridges.

.kry -> KIR -> C
.kry -> KIR -> Go
.kry -> KIR -> JS
.kry -> KIR -> KRB

Contract

What Kry Guarantees

RuleMeaning
Single frontend.kry parses into KIR before every backend. Backend-specific behavior must be visible in KIR or reported as a diagnostic.
C-close expressionsTypes, pointer expressions, calls, field access, and raw C escape lines stay familiar to C programmers.
Declarative UI shape#ui functions declare named node hierarchies; the runtime owns reconciliation, layout, input routing, focus, and update order.
Inspectable loweringk2ir prints imports, state, functions, statements, assertions, and simple structured expression trees for tooling.
Honest subsetsC is the full path. Go, JS, and KRB accept supported KIR and reject unsupported compile-time assertions instead of silently changing semantics.

Declarations

Top-Level Forms

#import "kryon.h"
ui :: #import "src/ui/panel"

WEB :: #defined(PLATFORM_WEB)
ANSWER :: #run 6 * 7
#assert ANSWER == 42, "compile-time math failed"

state {
    click_count: int = 0
}

Counter :: (viewport: Rectangle, app: App*) #ui {
    Screen root: {
        bounds = viewport

        Column body: {
            gap = 8
            Text("Count", 0, 0, Text16, GetThemeText())
            if Button((ButtonProps){.label = "Increment"}) {
                app->click_count += 1
            }
        }
    }
}
FormPurpose
#import "header.h"Include a C header in generated native code.
name :: #import "module"Import another Kry module.
name :: (...) -> Ret { ... }Define a function. Module functions are source-prefixed in generated C unless exported.
name :: (...) #ui { ... }Define a UI hierarchy function. Named nodes inside it get stable hierarchy paths.
#export, #private, #externControl ABI visibility and declarations that are implemented outside Kry.
#globalCreate a file-level variable; combine with #export for public extern storage.
Type :: struct { ... }Define a C-compatible struct type.
state { ... }Declare persistent app state fields owned by the generated module.

Statements

Function Body Forms

Compile Time

Constants, Guards, And Assertions

FeatureStatusBackend Behavior
#defined(SYMBOL)AvailableExpands to a C preprocessor-style condition for guards and generated C.
NAME :: #run INTEGER_EXPRAvailableEvaluated by the Kry frontend as a small integer constant. It is not a general compile-time function system.
#assert CONDITION, "message"AvailableUngarded constant-false assertions fail during Kry parsing. C emits #if/#error. Go, JS, and KRB require known true assertions.
#if, #else, #endifAvailableRetained in KIR as expanded guards so backends know the active platform conditions.

KIR

Intermediate Representation

KIR keeps raw source statement text for backend compatibility and adds structured metadata where the frontend can parse safely. Today that metadata covers simple identifiers, integer literals, string literals, calls, and binary expressions. More expression kinds can be added without changing the source pipeline.

k2ir --root . -o build/ir src/app.kry
k2c  --root . -o build/c  src/app.kry
k2g  --root . -o build/go src/app.kry
k2js --root . -o build/js src/app.kry
k2b  --root . -o build/krb src/app.kry

Limits

Known Language Boundaries

Backend Contract

Conformance Summary

FeatureKIRCGoJSKRB
#run integer constantsYesYesYesYesYes
#assertYes#if/#errorKnown true onlyKnown true onlyKnown true only
State blockYesYesYesYesYes
Raw C linesPreservedYesNoNoNo
Structured expression metadataPartialMetadataMetadataMetadataMetadata