Documentation
¶
Index ¶
- func IsAtomic(expr CoreExpr) bool
- func IsBoolValue(expr CoreExpr, bindings map[string]CoreExpr) bool
- func IsFloatValue(expr CoreExpr, bindings map[string]CoreExpr) bool
- func IsIntValue(expr CoreExpr, bindings map[string]CoreExpr) bool
- func IsListValue(expr CoreExpr, bindings map[string]CoreExpr) bool
- func IsStringValue(expr CoreExpr, bindings map[string]CoreExpr) bool
- func Pretty(prog *Program) string
- type App
- type Array
- type BinOp
- type ConstructorPattern
- type Contract
- type ContractKind
- type CoreExpr
- type CoreNode
- type CorePattern
- type DeclMeta
- type DictAbs
- type DictApp
- type DictParam
- type DictRef
- type DictValue
- type Expr
- type Forall
- type GlobalRef
- type If
- type Intrinsic
- type IntrinsicOp
- type Lam
- type Lambda
- type Let
- type LetRec
- type List
- type ListPattern
- type Lit
- type LitKind
- type LitPattern
- type Match
- type MatchArm
- type Program
- type ProgramFlags
- type RecBinding
- type Record
- type RecordAccess
- type RecordPattern
- type RecordUpdate
- type Tuple
- type TuplePattern
- type UnOp
- type Var
- type VarGlobal
- type VarPattern
- type WildcardPattern
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsBoolValue ¶
IsBoolValue checks if an expression (after resolving variables) is a Bool literal.
func IsFloatValue ¶
IsFloatValue checks if an expression (after resolving variables) is a Float literal.
func IsIntValue ¶
IsIntValue checks if an expression (after resolving variables) is an Int literal.
func IsListValue ¶
IsListValue checks if an expression (after resolving variables) is a List literal. This is useful for determining the concrete type of a value in ANF.
Note: Prefer using CoreTypeInfo from type inference for type-guided operations. IsListValue is a fallback for non-typed passes and debug utilities.
func IsStringValue ¶
IsStringValue checks if an expression (after resolving variables) is a String literal.
Types ¶
type BinOp ¶
type BinOp struct {
CoreNode
Op string
Left CoreExpr // Must be atomic in ANF
Right CoreExpr // Must be atomic in ANF
}
BinOp represents binary operations (in ANF, operands are atomic)
type ConstructorPattern ¶
type ConstructorPattern struct {
Name string
Args []CorePattern
}
func (*ConstructorPattern) String ¶
func (c *ConstructorPattern) String() string
type Contract ¶
type Contract struct {
Kind ContractKind // requires, ensures, or invariant
Expr CoreExpr // The predicate expression (elaborated to Core)
Message string // User-provided or auto-generated message
Location string // Source location "file.ail:42"
}
Contract represents a single contract clause (requires/ensures). M-VERIFY: Contracts are predicates that get compiled to runtime checks.
type ContractKind ¶
type ContractKind int
ContractKind distinguishes between requires and ensures contracts. M-VERIFY: This mirrors ast.ContractKind but lives in core for codegen.
const ( RequiresKind ContractKind = iota // Precondition - checked at function entry EnsuresKind // Postcondition - checked before return InvariantKind // Type/module invariant )
func (ContractKind) String ¶
func (k ContractKind) String() string
String returns the string representation of ContractKind
type CoreExpr ¶
type CoreExpr interface {
ID() uint64
Span() ast.Pos // Core span
OriginalSpan() ast.Pos // Surface origin
String() string
// contains filtered or unexported methods
}
CoreExpr is the base interface for Core expressions
func ResolveValue ¶
ResolveValue follows ANF variable bindings to find the ultimate bound value. This is useful when you need to inspect what a variable is bound to in ANF form.
ANF (A-Normal Form) represents complex expressions as sequences of let-bindings:
let x = [1, 2, 3] in let y = x in let z = y in z ++ [4, 5]
In this example, ResolveValue(z, bindings) will follow the chain:
z → y → x → [1, 2, 3]
Parameters:
- expr: The Core expression to resolve
- bindings: Map of variable names to their bound expressions (ANF-local scope only)
Returns:
- The resolved expression (stops when it hits a non-variable, missing binding, or cycle)
Cycle detection: Uses a visited set to prevent infinite loops. If a cycle is detected, returns the last resolvable expression (fail-closed).
Note: Prefer using CoreTypeInfo from type inference for type-guided operations. ResolveValue is a fallback for non-typed passes and debug utilities.
Example usage:
bindings := map[string]CoreExpr{
"x": &List{Elements: [...]},
"y": &Var{Name: "x"},
"z": &Var{Name: "y"},
}
resolved := ResolveValue(&Var{Name: "z"}, bindings)
// resolved is &List{Elements: [...]}
type CoreNode ¶
type CoreNode struct {
NodeID uint64 // Stable identifier assigned by elaborator
CoreSpan ast.Pos // Position in Core AST
OrigSpan ast.Pos // Original surface position for diagnostics
}
CoreNode is the base for all Core AST nodes
func (CoreNode) OriginalSpan ¶
type CorePattern ¶
type CorePattern interface {
String() string
// contains filtered or unexported methods
}
type DeclMeta ¶
type DeclMeta struct {
Name string
IsExport bool
IsPure bool
SID string // Source ID for tracing
Contracts []*Contract // M-VERIFY: Contract clauses (requires/ensures)
VerifyDepth int // Per-function SMT verify depth override (0 = use global default)
}
DeclMeta contains metadata for top-level declarations
type DictAbs ¶
type DictAbs struct {
CoreNode
Params []DictParam // Dictionary parameters in canonical order
Body CoreExpr // Body with dictionaries available
}
DictAbs represents dictionary abstraction at binders Used for polymorphic functions with type class constraints
type DictApp ¶
type DictApp struct {
CoreNode
Dict CoreExpr // Dictionary reference (must be a Var in ANF)
Method string // Method name: "add", "eq", "lt", etc.
Args []CoreExpr // Method arguments
}
DictApp represents dictionary application at use sites All method calls through type classes become DictApp nodes
type DictParam ¶
type DictParam struct {
Name string // e.g., "dict_Num_α"
ClassName string // e.g., "Num"
Type string // String representation of type
}
DictParam represents a dictionary parameter in DictAbs
type DictRef ¶
type DictRef struct {
CoreNode
ClassName string // e.g., "Num", "Ord"
TypeName string // Normalized type: "Int", "Float", etc.
}
DictRef represents a reference to a built-in dictionary
type DictValue ¶
type DictValue struct {
TypeClass string // Type class name (e.g., "Num", "Eq")
Type string // Type the instance is for (e.g., "Int", "Float")
Methods map[string]interface{} // Method implementations
Provides []string // Other instances this provides (e.g., Ord provides Eq)
}
DictValue represents a runtime dictionary for type class methods
type Expr ¶
type Expr interface {
String() string
}
Expr is a simplified interface for core expressions (used by REPL)
type Forall ¶
type Forall struct {
CoreNode
Var string // Bound variable
Lo CoreExpr // Lower bound (inclusive)
Hi CoreExpr // Upper bound (exclusive)
Body CoreExpr // Quantified body (boolean predicate)
}
Forall represents a bounded universal quantifier in the Core IR. Encodes to (forall ((Var Int)) (=> (and (>= Var Lo) (< Var Hi)) Body)) in SMT-LIB. Only integer quantifiers are supported.
type Intrinsic ¶
type Intrinsic struct {
CoreNode
Op IntrinsicOp
Args []CoreExpr // [left, right] for binary, [operand] for unary
}
Intrinsic represents a built-in operation that will be lowered
type IntrinsicOp ¶
type IntrinsicOp int
IntrinsicOp represents built-in operations
const ( OpAdd IntrinsicOp = iota OpSub OpMul OpDiv OpMod OpEq OpNe OpLt OpLe OpGt OpGe OpConcat // for ++ string concatenation OpAnd // for && boolean and OpOr // for || boolean or OpNot // for unary not OpNeg // for unary negation // Bitwise operators OpBitwiseAnd // for & bitwise AND OpBitwiseXor // for ^ bitwise XOR OpBitwiseNot // for ~ bitwise NOT (unary) OpShiftLeft // for << left shift OpShiftRight // for >> right shift )
type Let ¶
type Let struct {
CoreNode
Name string
Value CoreExpr // In ANF: atomic or simple call
Body CoreExpr
}
Let represents a non-recursive let binding
type LetRec ¶
type LetRec struct {
CoreNode
Bindings []RecBinding
Body CoreExpr
}
LetRec represents mutually recursive bindings
type ListPattern ¶
type ListPattern struct {
Elements []CorePattern
Tail *CorePattern // For ... patterns
}
func (*ListPattern) String ¶
func (l *ListPattern) String() string
type LitPattern ¶
type LitPattern struct {
Value interface{}
}
func (*LitPattern) String ¶
func (l *LitPattern) String() string
type Match ¶
type Match struct {
CoreNode
Scrutinee CoreExpr // Must be atomic in ANF
Arms []MatchArm
Exhaustive bool // Set by elaborator/typechecker
}
Match represents pattern matching
type MatchArm ¶
type MatchArm struct {
Pattern CorePattern
Guard CoreExpr // Optional, must be atomic
Body CoreExpr
}
type Program ¶
type Program struct {
Decls []CoreExpr // Top-level declarations
Meta map[string]*DeclMeta // Metadata for top-level declarations
Flags ProgramFlags // Compilation state flags
}
Program represents a Core program
type ProgramFlags ¶
type ProgramFlags struct {
Lowered bool // Set after OpLowering pass
Linked bool // Set after linking
}
ProgramFlags tracks compilation state
type RecBinding ¶
type RecordAccess ¶
RecordAccess represents field access (record is atomic in ANF)
func (*RecordAccess) String ¶
func (r *RecordAccess) String() string
type RecordPattern ¶
type RecordPattern struct {
Fields map[string]CorePattern
}
func (*RecordPattern) String ¶
func (r *RecordPattern) String() string
type RecordUpdate ¶
type RecordUpdate struct {
CoreNode
Base CoreExpr // Must be atomic in ANF
Updates map[string]CoreExpr // All values must be atomic
}
RecordUpdate represents functional record update: {base | field: value} Base is atomic, Updates contains atomic values for fields to update
func (*RecordUpdate) String ¶
func (r *RecordUpdate) String() string
type TuplePattern ¶
type TuplePattern struct {
Elements []CorePattern
}
func (*TuplePattern) String ¶
func (t *TuplePattern) String() string
type VarPattern ¶
type VarPattern struct {
Name string
}
func (*VarPattern) String ¶
func (v *VarPattern) String() string
type WildcardPattern ¶
type WildcardPattern struct{}
func (*WildcardPattern) String ¶
func (w *WildcardPattern) String() string