core

package
v0.14.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAtomic

func IsAtomic(expr CoreExpr) bool

Helper to check if expression is atomic (for ANF verification)

func IsBoolValue

func IsBoolValue(expr CoreExpr, bindings map[string]CoreExpr) bool

IsBoolValue checks if an expression (after resolving variables) is a Bool literal.

func IsFloatValue

func IsFloatValue(expr CoreExpr, bindings map[string]CoreExpr) bool

IsFloatValue checks if an expression (after resolving variables) is a Float literal.

func IsIntValue

func IsIntValue(expr CoreExpr, bindings map[string]CoreExpr) bool

IsIntValue checks if an expression (after resolving variables) is an Int literal.

func IsListValue

func IsListValue(expr CoreExpr, bindings map[string]CoreExpr) bool

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

func IsStringValue(expr CoreExpr, bindings map[string]CoreExpr) bool

IsStringValue checks if an expression (after resolving variables) is a String literal.

func Pretty

func Pretty(prog *Program) string

Pretty provides a basic string representation of Core programs This is a stub implementation for testing purposes

Types

type App

type App struct {
	CoreNode
	Func CoreExpr
	Args []CoreExpr // All must be atomic in ANF
}

App represents function application (in ANF, args are atomic)

func (*App) String

func (a *App) String() string

type Array

type Array struct {
	CoreNode
	Elements []CoreExpr // All must be atomic in ANF
}

Array represents array construction with O(1) indexed access

func (*Array) String

func (a *Array) String() string

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)

func (*BinOp) String

func (b *BinOp) String() string

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

func ResolveValue(expr CoreExpr, bindings map[string]CoreExpr) CoreExpr

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) ID

func (n CoreNode) ID() uint64

Ensure CoreNode implements base methods

func (CoreNode) OriginalSpan

func (n CoreNode) OriginalSpan() ast.Pos

func (CoreNode) Span

func (n CoreNode) Span() ast.Pos

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

func (*DictAbs) String

func (d *DictAbs) String() string

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

func (*DictApp) String

func (d *DictApp) String() string

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

func (*DictRef) String

func (d *DictRef) String() string

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.

func (*Forall) String

func (f *Forall) String() string

type GlobalRef

type GlobalRef struct {
	Module string // e.g., "math/gcd"
	Name   string // e.g., "gcd"
}

GlobalRef represents a cross-module reference

type If

type If struct {
	CoreNode
	Cond CoreExpr // Must be atomic in ANF
	Then CoreExpr
	Else CoreExpr
}

If represents conditional (in ANF, condition is atomic)

func (*If) String

func (i *If) String() string

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

func (*Intrinsic) String

func (i *Intrinsic) String() string

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 Lam

type Lam struct {
	CoreNode
	Param string
	Body  Expr
}

Lam is a simplified lambda for REPL (single param)

func (*Lam) String

func (l *Lam) String() string

type Lambda

type Lambda struct {
	CoreNode
	Params []string
	Body   CoreExpr
}

Lambda represents a function value

func (*Lambda) String

func (l *Lambda) String() string

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

func (*Let) String

func (l *Let) String() string

type LetRec

type LetRec struct {
	CoreNode
	Bindings []RecBinding
	Body     CoreExpr
}

LetRec represents mutually recursive bindings

func (*LetRec) String

func (l *LetRec) String() string

type List

type List struct {
	CoreNode
	Elements []CoreExpr // All must be atomic in ANF
}

List represents list construction (elements are atomic in ANF)

func (*List) String

func (l *List) String() string

type ListPattern

type ListPattern struct {
	Elements []CorePattern
	Tail     *CorePattern // For ... patterns
}

func (*ListPattern) String

func (l *ListPattern) String() string

type Lit

type Lit struct {
	CoreNode
	Kind  LitKind
	Value interface{}
}

Lit represents a literal value

func (*Lit) String

func (l *Lit) String() string

type LitKind

type LitKind int
const (
	IntLit LitKind = iota
	FloatLit
	StringLit
	BoolLit
	UnitLit
)

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

func (*Match) String

func (m *Match) String() string

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 RecBinding struct {
	Name  string
	Value CoreExpr // Usually Lambda for recursion
}

type Record

type Record struct {
	CoreNode
	Fields map[string]CoreExpr // All values must be atomic
}

Record represents record construction (fields are atomic in ANF)

func (*Record) String

func (r *Record) String() string

type RecordAccess

type RecordAccess struct {
	CoreNode
	Record CoreExpr // Must be atomic in ANF
	Field  string
}

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 Tuple

type Tuple struct {
	CoreNode
	Elements []CoreExpr // All must be atomic in ANF
}

Tuple represents tuple construction (elements are atomic in ANF)

func (*Tuple) String

func (t *Tuple) String() string

type TuplePattern

type TuplePattern struct {
	Elements []CorePattern
}

func (*TuplePattern) String

func (t *TuplePattern) String() string

type UnOp

type UnOp struct {
	CoreNode
	Op      string
	Operand CoreExpr // Must be atomic in ANF
}

UnOp represents unary operations (in ANF, operand is atomic)

func (*UnOp) String

func (u *UnOp) String() string

type Var

type Var struct {
	CoreNode
	Name string
}

Var represents a variable reference

func (*Var) String

func (v *Var) String() string

type VarGlobal

type VarGlobal struct {
	CoreNode
	Ref GlobalRef
}

VarGlobal represents a reference to an imported symbol

func (*VarGlobal) String

func (v *VarGlobal) 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL