The Basics
Source files, comments, entrypoints, declarations, local bindings, and the broad shape of Kira code.
The repo's smallest Kira programs have a direct shape:
@Main
function main() {
let left = 40;
let right = 2;
let total = left + right;
print(total);
return;
}Source Files and Modules
Kira source lives in .kira files. The repo commonly uses:
app/main.kirafor an application's entry module- sibling files such as
Support.kiraorUI.kirafor imported modules - nested module names such as
bindings.callbacks
Imports use qualified names and may add an alias:
import Support as Support
import bindings.callbacks as callbacksComments
The current lexer documents single-line comments with //:
// generated by kira FFI autobinding for callbacksThis is the comment form that appears in generated bindings and is tokenized explicitly by the lexer.
The Entrypoint
Programs choose their entry function with @Main, not with a special function name.
Current semantic rules:
- exactly one function must be marked
@Main @Mainmust not declare parameters- duplicate or conflicting execution annotations are rejected
The fail corpus proves diagnostics for:
- missing
@Main - multiple
@Mainentrypoints - duplicate
@Main - invalid
@Mainsignatures
Top-Level Declarations
The current frontend recognizes these top-level declaration forms:
importfunctionclassstructconstruct- construct-defined forms such as
Widget Card(...) { ... }
Those are the forms you see throughout the guide.
Local Bindings
Local declarations use let and var.
let total = left + right;
var monthLabel: String
var aspectRatio: Float = 1.0The declaration model is explicit:
var name = expression: infer the declared type from the initializer expressionvar name: SomeType: declare an uninitialized local of that typevar name: SomeType = expression: require the initializer expression to already match the declared type
Kira prefers inference when the type is obvious, but it does not guess when the program is ambiguous:
@Main
function entry() {
let value;
return;
}That fail case produces KSEM029 ("type inference is ambiguous").
Typed declarations without initializer expressions are valid, but they stay uninitialized until some later assignment gives them a value. Reading them earlier is rejected.
Annotated initializers are strict:
var ok: Float = 0.0
var wrong: Float = 0The second form is rejected because the declared type is Float and the initializer expression is an integer literal.
Statement Style
The checked-in examples use both:
- semicolon-terminated statements
- newline-delimited statements
Both styles are accepted in the forms already exercised by the repo.
Current Status
The basics chapter mixes two real layers of Kira:
- declarations, names, annotations, and constructs belong to the frontend surface
- the fully proven runnable core is smaller and centers on
@Main, functions, locals, direct calls,return,print, and the currently lowered expression subset