semantic

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Analyzer

type Analyzer struct {
	// contains filtered or unexported fields
}

Analyzer performs semantic analysis on the AST

func New

func New(program *ast.Program) *Analyzer

New creates a new semantic analyzer

func (*Analyzer) Analyze

func (a *Analyzer) Analyze() []error

Analyze performs semantic analysis on the program

func (*Analyzer) ReturnCounts added in v0.0.2

func (a *Analyzer) ReturnCounts() map[ast.Expression]int

ReturnCounts returns the inferred return counts for expressions. Call after Analyze() to pass these to codegen.

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

Scope represents a lexical scope

func NewScope

func NewScope(parent *Scope) *Scope

NewScope creates a new scope

func (*Scope) Define

func (s *Scope) Define(symbol *Symbol) error

Define adds a symbol to the current scope

func (*Scope) Resolve

func (s *Scope) Resolve(name string) *Symbol

Resolve looks up a symbol in the current scope and parent scopes

type Symbol

type Symbol struct {
	Name     string
	Kind     SymbolKind
	Type     *TypeInfo
	Defined  ast.Position
	Mutable  bool
	Exported bool
}

Symbol represents a symbol in the symbol table

type SymbolKind

type SymbolKind int

SymbolKind represents the kind of symbol

const (
	SymbolVariable SymbolKind = iota
	SymbolParameter
	SymbolFunction
	SymbolType
	SymbolInterface
)

func (SymbolKind) String

func (sk SymbolKind) String() string

type SymbolTable

type SymbolTable struct {
	// contains filtered or unexported fields
}

SymbolTable manages scopes and symbols

func NewSymbolTable

func NewSymbolTable() *SymbolTable

NewSymbolTable creates a new symbol table

func (*SymbolTable) CurrentScope

func (st *SymbolTable) CurrentScope() *Scope

CurrentScope returns the current scope

func (*SymbolTable) Define

func (st *SymbolTable) Define(symbol *Symbol) error

Define adds a symbol to the current scope

func (*SymbolTable) EnterScope

func (st *SymbolTable) EnterScope()

EnterScope creates a new scope

func (*SymbolTable) ExitScope

func (st *SymbolTable) ExitScope()

ExitScope removes the current scope

func (*SymbolTable) Resolve

func (st *SymbolTable) Resolve(name string) *Symbol

Resolve looks up a symbol

type TypeInfo

type TypeInfo struct {
	Kind         TypeKind
	Name         string      // For named types and placeholders
	ElementType  *TypeInfo   // For lists, channels, references
	KeyType      *TypeInfo   // For maps
	ValueType    *TypeInfo   // For maps
	Params       []*TypeInfo // For functions
	Returns      []*TypeInfo // For functions
	Constraint   string      // For placeholders: "any", "comparable", "cmp.Ordered"
	Variadic     bool        // For functions: true if last param is variadic
	ParamNames   []string    // For functions: parameter names (for named argument validation)
	DefaultCount int         // For functions: number of parameters with default values
}

TypeInfo represents type information

func (*TypeInfo) String

func (ti *TypeInfo) String() string

type TypeKind

type TypeKind int

TypeKind represents the kind of type

const (
	TypeKindUnknown TypeKind = iota
	TypeKindInt
	TypeKindFloat
	TypeKindString
	TypeKindBool
	TypeKindList
	TypeKindMap
	TypeKindChannel
	TypeKindReference
	TypeKindFunction
	TypeKindStruct
	TypeKindInterface
	TypeKindNamed
	TypeKindPlaceholder // For generic type placeholders (element, item, etc.)
)

func (TypeKind) String

func (tk TypeKind) String() string

Jump to

Keyboard shortcuts

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