Documentation
¶
Overview ¶
Package stmt defines the Statement IR — the ONLY representation that code generation emitters see. No emitter may import internal/core directly.
Statement IR is target-agnostic: it knows about variable declarations, if/switch control flow, function calls, and field access — concepts that exist in every target language. It does NOT know about Go's interface{}, Rust's Box<dyn Any>, or C's void*.
The IR is produced by lowering passes in internal/gen/lower/ that transform Core AST + CoreTypeInfo into this representation.
Index ¶
- func Validate(prog *Program) error
- type ADTConstructor
- type ADTDecl
- type ADTVariant
- type ArrayLit
- type AssignStmt
- type BinOp
- type BinOpKind
- type Binding
- type BuiltinCall
- type Call
- type Cons
- type Expr
- type ExprStmt
- type FieldAccess
- type FieldInit
- type FuncDecl
- type FuncType
- type GlobalRef
- type IfExpr
- type IfStmt
- type ImportSpec
- type InterfaceType
- type Lambda
- type ListLit
- type LitBool
- type LitFloat
- type LitInt
- type LitString
- type LitUnit
- type MapType
- type NamedType
- type Param
- type PrimitiveKind
- type PrimitiveType
- type Program
- type RecordDecl
- type RecordField
- type RecordLit
- type RecordUpdate
- type ResolvedType
- type ReturnStmt
- type SliceType
- type Stmt
- type SwitchCase
- type SwitchStmt
- type TupleLit
- type TupleType
- type TypeAliasDecl
- type TypeAssert
- type TypeDecl
- type TypeDeclKind
- type UnOp
- type UnOpKind
- type VarDecl
- type VarRef
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ADTConstructor ¶
type ADTConstructor struct {
TypeName string // The ADT type name (e.g., "Option")
Tag string // The variant tag (e.g., "Some")
Args []Expr // Constructor arguments
}
ADTConstructor constructs an ADT variant.
type ADTDecl ¶
type ADTDecl struct {
Variants []ADTVariant
}
ADTDecl declares an algebraic data type with variants.
type ADTVariant ¶
type ADTVariant struct {
Tag string // Constructor name (e.g., "Some", "None")
Fields []ResolvedType // Field types (empty for nullary constructors)
}
ADTVariant is one constructor of an ADT.
type ArrayLit ¶
type ArrayLit struct {
ElemType ResolvedType
Elems []Expr
}
ArrayLit constructs an array value.
type AssignStmt ¶
AssignStmt assigns a value to an existing variable.
type Binding ¶
type Binding struct {
Name string // Variable name to bind
FieldIndex int // Which field of the variant (0-based)
Type ResolvedType // Type of the extracted field
}
Binding captures a field extraction from an ADT match.
type BuiltinCall ¶
type BuiltinCall struct {
Name string // Builtin name (e.g., "_str_trim", "_list_map")
Args []Expr
}
BuiltinCall calls a builtin/stdlib function by name.
type Call ¶
type Call struct {
Func Expr // The function to call (VarRef, GlobalRef, or Lambda)
Args []Expr // Arguments
}
Call invokes a function.
type Expr ¶
type Expr interface {
// contains filtered or unexported methods
}
Expr is an expression that produces a value.
type ExprStmt ¶
ExprStmt wraps an expression used as a statement (e.g., function call for side effects).
type FieldAccess ¶
FieldAccess accesses a field of a record.
KnownFields, when non-empty, lists the record's full field set (in lexicographic order) as inferred by the type checker. The bytecode compiler uses this to resolve the GET_FIELD index for anonymous / row-polymorphic records that never produced an explicit TypeDecl. Empty means "no type info available — fall back to recordTypes lookup". Added for M-BYTECODE-MULTIMODULE M3.
type FuncDecl ¶
type FuncDecl struct {
Name string // Function name (already namespaced by module)
Params []Param // Parameters
ReturnType ResolvedType // Return type
Body []Stmt // Function body statements
Return Expr // Final return expression
Exported bool // Whether this function is public
Module string // Source module name
File string // Source file path (for diagnostics; optional)
Line int // Source line of the func declaration (for diagnostics; 0 = unknown)
// LowerError is non-empty when the lower pass caught a panic or error
// while lowering this function's body. The bytecode compiler will skip
// normal compilation of such functions and mark the prototype as
// EvalOnly with this reason, so the bridge dispatches the call to the
// evaluator at runtime. Body/Return may be empty or partial in this
// case — consumers should not traverse them.
LowerError string
}
FuncDecl declares a function.
type FuncType ¶
type FuncType struct {
Params []ResolvedType
Return ResolvedType
}
FuncType represents a function type.
type IfStmt ¶
type IfStmt struct {
Cond Expr
Then []Stmt
Else []Stmt // may be empty or contain another IfStmt for else-if chains
Line int // source line (0 = unknown)
}
IfStmt is a conditional branch.
type ImportSpec ¶
ImportSpec represents a required import.
type InterfaceType ¶
type InterfaceType struct{}
InterfaceType represents an unresolved or dynamic type (interface{}). This should be used sparingly — only at boundaries where type info is lost.
func (InterfaceType) GoString ¶
func (InterfaceType) GoString() string
type ListLit ¶
type ListLit struct {
ElemType ResolvedType // Element type
Elems []Expr
}
ListLit constructs a list value.
type MapType ¶
type MapType struct{}
MapType represents a map[string]interface{} (AILANG's Map type).
type NamedType ¶
type NamedType struct {
Name string // Type name (e.g., "Color", "Position")
Pointer bool // Whether to use pointer semantics (true for ADTs)
}
NamedType references a user-defined type (ADT or record) by name.
type PrimitiveKind ¶
type PrimitiveKind int
PrimitiveKind enumerates primitive types.
const ( PrimInt PrimitiveKind = iota PrimFloat PrimBool PrimString PrimUnit )
type PrimitiveType ¶
type PrimitiveType struct {
Kind PrimitiveKind
}
PrimitiveType represents a basic type.
func (PrimitiveType) GoString ¶
func (p PrimitiveType) GoString() string
type Program ¶
type Program struct {
Package string // Target package/module name
TypeDecls []TypeDecl // ADT and record type declarations
FuncDecls []FuncDecl // Function declarations
Imports []ImportSpec // Required imports (e.g., "fmt", "strings")
}
Program represents a complete compilation unit ready for emission.
type RecordDecl ¶
type RecordDecl struct {
Fields []RecordField
}
RecordDecl declares a record (struct) type.
type RecordField ¶
type RecordField struct {
Name string
Type ResolvedType
}
RecordField is a named field in a record.
type RecordUpdate ¶
RecordUpdate creates a new record with some fields changed.
type ResolvedType ¶
type ResolvedType interface {
GoString() string // Go type representation (for the Go emitter)
// contains filtered or unexported methods
}
ResolvedType is a fully-resolved type with no type variables. Type projection is a pure function: same input always produces same output. If a type variable is encountered, projection MUST error (no silent defaults).
type ReturnStmt ¶
ReturnStmt returns a value from a function.
type SliceType ¶
type SliceType struct {
Elem ResolvedType
}
SliceType represents a list/array as a Go slice.
type Stmt ¶
type Stmt interface {
// contains filtered or unexported methods
}
Stmt is a statement in a function body.
type SwitchCase ¶
type SwitchCase struct {
Tag string // ADT variant tag to match
Bindings []Binding // Variables bound from the matched variant's fields
Body []Stmt
}
SwitchCase is one arm of a switch.
type SwitchStmt ¶
type SwitchStmt struct {
Scrutinee Expr
ADTName string // The ADT type name (e.g., "Color") — helps emitters generate typed constants
Cases []SwitchCase
Default []Stmt // may be empty; if non-empty, must end in panic or return
Line int // source line (0 = unknown)
}
SwitchStmt dispatches on a value (used for ADT tag matching).
type TupleType ¶
type TupleType struct {
Elems []ResolvedType
}
TupleType represents a tuple (compiled as a struct).
type TypeAliasDecl ¶
type TypeAliasDecl struct {
Target ResolvedType
}
TypeAliasDecl declares a type alias.
type TypeAssert ¶
type TypeAssert struct {
Value Expr
Type ResolvedType
}
TypeAssert asserts a value to a specific type (used at interface{} boundaries).
type TypeDecl ¶
type TypeDecl struct {
Name string
Kind TypeDeclKind
Exported bool
}
TypeDecl declares a named type.
type TypeDeclKind ¶
type TypeDeclKind interface {
// contains filtered or unexported methods
}
TypeDeclKind distinguishes ADTs from records.