matrixir

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatementAssign = iota
	StatementPrint
	StatementReturn
	StatementExpression
	StatementClasses
)
View Source
const (
	GrammarBrace = iota
	GrammarIndent
	GrammarEnd
	GrammarSemicolon
	GrammarNewline
	GrammarTypedDeclaration
	GrammarMainWrapper
	GrammarOneBasedIndex
	GrammarIntegerSlashTruncates
	GrammarExclusiveRangeEnd
	GrammarDimensions
)
View Source
const (
	ActionSkip = iota
	ActionBlock
	ActionAssign
	ActionPrint
	ActionReturn
	ActionExpression
	ActionIf
	ActionElse
	ActionWhile
	ActionFor
	ActionFunction
	ActionCall
	ActionIndex
	ActionModule
	ActionObject
	ActionException
	ActionConcurrency
	ActionReflection
	ActionDimensions
)
View Source
const (
	LexIdentifier = iota
	LexNumber
	LexString
	LexStringComment
	LexStringKeyword
	LexBoolean
	LexReturn
	LexPrint
	LexIf
	LexWhile
	LexFor
	LexFunction
	LexObject
	LexException
	LexModule
	LexConcurrency
	LexReflection
	LexArithmetic
	LexDivision
	LexIntegerDivision
	LexComparison
	LexLogical
	LexShortCircuit
	LexBinding
	LexNamedArgument
	LexIndex
	LexGrouping
	LexCall
	LexBlock
	LexComment
	LexicalAxes
)
View Source
const (
	SemProgram = iota
	SemBlock
	SemAssign
	SemPrint
	SemReturn
	SemExpression
	SemIdentifier
	SemNumber
	SemString
	SemBoolean
	SemNull
	SemUnary
	SemBinary
	SemCall
	SemIndex
	SemIf
	SemWhile
	SemFor
	SemFunction
	SemArithmetic
	SemDivision
	SemIntegerDivision
	SemComparison
	SemLogical
	SemBinding
	SemReassignment
	SemScope
	SemClosure
	SemNamedArgument
	SemLazyEvaluation
	SemShortCircuit
	SemOverflow
	SemObject
	SemException
	SemGeneric
	SemOwnership
	SemModule
	SemConcurrency
	SemFFI
	SemReflection
	SemSerialization
	SemIO
	SemEffect
	SemStringComment
	SemStringKeyword
	SemMultiline
	SemGrouping
	SemUnknown
	SemanticDimensions
)

Variables

View Source
var ActionNames = [...]string{
	"skip", "block", "assign", "print", "return", "expression", "if", "else", "while", "for", "function", "call", "index", "module", "object", "exception", "concurrency", "reflection",
}
View Source
var Features = [...]string{
	"arithmetic", "binding", "reassignment", "division", "boolean", "string_comment", "string_keywords", "comparison",
	"multiline", "grouping", "if_else", "while", "for", "function", "index", "integer_division",
	"scope", "closure", "named_args", "lazy_eval", "short_circuit", "overflow", "null_na", "objects",
	"exceptions", "generics", "ownership", "modules", "concurrency", "ffi", "reflection", "serialization",
}
View Source
var GrammarNames = [...]string{
	"brace_blocks", "indent_blocks", "end_blocks", "semicolon", "newline", "typed_declaration", "main_wrapper", "one_based_index", "integer_slash_truncates", "exclusive_range_end",
}
View Source
var Languages = [...]string{"r", "go", "rust", "cpp", "c", "python", "zig", "julia", "nim", "csharp", "java", "kotlin", "swift"}
View Source
var RelationNames = [...]string{"syntax", "control", "data", "binding", "effect"}
View Source
var SemanticNames = [...]string{
	"program", "block", "assign", "print", "return", "expression", "identifier", "number", "string", "boolean", "null",
	"unary", "binary", "call", "index", "if", "while", "for", "function", "arithmetic", "division", "integer_division",
	"comparison", "logical", "binding", "reassignment", "scope", "closure", "named_argument", "lazy_evaluation", "short_circuit",
	"overflow", "object", "exception", "generic", "ownership", "module", "concurrency", "ffi", "reflection", "serialization",
	"io", "effect", "string_comment", "string_keyword", "multiline", "grouping", "unknown",
}

Functions

func BuildLexicalGraph

func BuildLexicalGraph(source, code string) (*Graph, []Lexeme, error)

func ClassifyStatement

func ClassifyStatement(vector Vector) (int, error)

func FeatureIndex

func FeatureIndex(feature string) (int, bool)

func LanguageIndex

func LanguageIndex(language string) (int, bool)

func MustFeatureIndex

func MustFeatureIndex(feature string) int

Types

type CanonicalEvent

type CanonicalEvent struct {
	Text   string
	Source int
}

CanonicalEvent preserves structural action order for direct lowerers. It is not a source string field and is deliberately separate from the legacy R diagnostic view.

type CanonicalNode

type CanonicalNode struct {
	Action Vector
	Text   string
	Source int
	// Close and Post are structural action payload, not R transport text.
	// They make block boundaries available to direct semantic lowerers.
	Close int
	Post  string
}

type CanonicalProgram

type CanonicalProgram struct {
	Source  string
	R       string
	Nodes   []CanonicalNode
	Graph   *Graph
	Actions Matrix
	Grammar Vector
	Roles   Matrix
	Lexemes []Lexeme
	Events  []CanonicalEvent
}

func Canonicalize

func Canonicalize(source, code string) (CanonicalProgram, error)

Canonicalize lowers the supported common subset through token structure and action matrices into R-shaped syntax. It is not a full parser for all source languages; the R expression parser and some header recognizers remain.

type CapabilityModel

type CapabilityModel struct {
	Support Matrix // language x feature
	Known   Matrix // language x feature
}

CapabilityModel holds support and observation masks. A zero in Support is meaningful only when the corresponding Known cell is one.

func NewCapabilityModel

func NewCapabilityModel(support, known Matrix) (CapabilityModel, error)

func (CapabilityModel) DeficitMatrices

func (m CapabilityModel) DeficitMatrices(requirements Matrix) (missing Matrix, unknown Matrix, err error)

DeficitMatrices computes D=R*(K-S)^T and Q=R*(1-K)^T. R is a source/program x feature requirement matrix. D counts known missing contracts per target, Q counts unknown required contracts per target.

func (CapabilityModel) Plan

func (m CapabilityModel) Plan(requirements Vector, target string) (TargetPlan, error)

type Graph

type Graph struct {
	Language string
	Nodes    []Node
	Edges    [RelationCount]SparseMatrix
}

func NewGraph

func NewGraph(language string) (*Graph, error)

func (*Graph) AddNode

func (g *Graph) AddNode(vector Vector, text, symbol string, sourceAt int) int

func (*Graph) AddNodes

func (g *Graph) AddNodes(nodes []Node) []int

AddNodes appends a batch with consecutive graph-owned IDs and copied semantic vectors. Relation matrices grow their dimensions without copying any edges. Invalid vectors are rejected before the graph is changed; incoming IDs are ignored because IDs are positions in this graph's relation matrices.

func (*Graph) Connect

func (g *Graph) Connect(relation Relation, from, to int) error

func (*Graph) NodeMatrix

func (g *Graph) NodeMatrix() Matrix

func (*Graph) RelationCounts

func (g *Graph) RelationCounts() Vector

func (*Graph) Requirements

func (g *Graph) Requirements() Vector

Requirements performs X*W, where X is the node matrix and W projects semantic dimensions onto the shared 32-feature contract. Counts are reduced to a binary program requirement vector after multiplication.

func (*Graph) SemanticRequirements

func (g *Graph) SemanticRequirements() Vector

type Lexeme

type Lexeme struct {
	Class    TokenClass
	Text     string
	Start    int
	End      int
	Depth    int
	Axes     Vector
	Semantic Vector
}

func Tokenize

func Tokenize(source, code string) []Lexeme

type Matrix

type Matrix struct {
	Rows int
	Cols int
	Data []float64
}

Matrix is a dense row-major matrix. The semantic graphs are sparse in meaning, but dense storage keeps dimensions and multiplication auditable at the current program sizes. Storage can later change without changing the IR.

func ActionSemanticProjection

func ActionSemanticProjection() Matrix

ActionSemanticProjection converts an action vector into the shared semantic basis. It is the executable counterpart of the V9 structure-action matrix.

func GrammarProfileMatrix

func GrammarProfileMatrix() Matrix

GrammarProfileMatrix is the V10 source-language grammar contract. Parser behavior is selected by multiplying a language basis vector by this matrix.

func LexicalRuleMatrix

func LexicalRuleMatrix() Matrix

func LoweringMatrix

func LoweringMatrix() Matrix

LoweringMatrix is target-language x semantic statement class. It is the shared structural rule table used before any target-specific renderer runs.

func MatrixFromRows

func MatrixFromRows(rows [][]float64) (Matrix, error)

func NewMatrix

func NewMatrix(rows, cols int) Matrix

func SemanticFeatureProjection

func SemanticFeatureProjection() Matrix

func (Matrix) At

func (m Matrix) At(row, col int) float64

func (Matrix) BooleanClosure

func (m Matrix) BooleanClosure() (Matrix, error)

BooleanClosure computes the transitive closure with boolean addition and multiplication. It deliberately does not add identity edges.

func (Matrix) Hadamard

func (m Matrix) Hadamard(right Matrix) (Matrix, error)

func (Matrix) Multiply

func (m Matrix) Multiply(right Matrix) (Matrix, error)

func (Matrix) Row

func (m Matrix) Row(row int) Vector

func (Matrix) Set

func (m Matrix) Set(row, col int, value float64)

func (Matrix) Threshold

func (m Matrix) Threshold() Matrix

func (Matrix) Transpose

func (m Matrix) Transpose() Matrix

type Node

type Node struct {
	ID       int
	Vector   Vector
	Text     string
	Symbol   string
	SourceAt int
}

type Relation

type Relation int
const (
	Syntax Relation = iota
	Control
	Data
	Binding
	Effect
	RelationCount
)

type SparseMatrix

type SparseMatrix struct {
	Rows int
	Cols int
	// contains filtered or unexported fields
}

SparseMatrix stores only nonzero entries, indexed by row then column. Its coordinates do not depend on dimensions, so graph growth never copies edges. Small semantic/projection matrices deliberately retain the dense Matrix type.

func NewSparseMatrix

func NewSparseMatrix(rows, cols int) SparseMatrix

func (SparseMatrix) At

func (m SparseMatrix) At(r, c int) float64

func (SparseMatrix) BooleanClosure

func (m SparseMatrix) BooleanClosure() (SparseMatrix, error)

BooleanClosure enumerates reachable coordinates, not an n*n temporary array. Dense reachability still requires quadratic output; sparsity is no guarantee that the mathematical result itself is sparse. No identity edges are added.

func (SparseMatrix) Dense

func (m SparseMatrix) Dense() Matrix

func (SparseMatrix) Each

func (m SparseMatrix) Each(f func(int, int, float64))

Each uses stable coordinate order, including in floating-point reductions.

func (*SparseMatrix) Grow

func (m *SparseMatrix) Grow(rows, cols int)

func (SparseMatrix) MarshalJSON

func (m SparseMatrix) MarshalJSON() ([]byte, error)

Sparse serialization is explicit; legacy dense audit fields call Dense at the boundary only. Encoding must never allocate rows*cols implicitly.

func (SparseMatrix) Multiply

func (m SparseMatrix) Multiply(b SparseMatrix) (SparseMatrix, error)

func (SparseMatrix) NonZeros

func (m SparseMatrix) NonZeros() int

func (SparseMatrix) Set

func (m SparseMatrix) Set(r, c int, v float64)

func (SparseMatrix) Sum

func (m SparseMatrix) Sum() float64

func (SparseMatrix) Transpose

func (m SparseMatrix) Transpose() SparseMatrix

func (*SparseMatrix) UnmarshalJSON

func (m *SparseMatrix) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts only the explicit COO representation written above. It rejects duplicate or out-of-range coordinates so a serialized semantic graph cannot silently change meaning while it is loaded.

type TargetPlan

type TargetPlan struct {
	Target     string
	Required   Vector
	Supported  Vector
	Missing    Vector
	Unknown    Vector
	RequiredN  int
	SupportedN int
	MissingN   int
	UnknownN   int
}

type TokenClass

type TokenClass int
const (
	TokenIdentifier TokenClass = iota
	TokenNumber
	TokenString
	TokenOperator
	TokenDelimiter
	TokenNewline
	TokenComment
	TokenClassCount
)

type TokenStructure

type TokenStructure struct {
	Classes Matrix
	Pairs   SparseMatrix
	Code    Vector
}

TokenStructure keeps class selection and delimiter incidence separate from semantic guesses. Strings/comments have zero weight in the code projection. Pairing is a syntax operation; multiplication alone cannot infer a grammar.

func AnalyzeTokenStructure

func AnalyzeTokenStructure(tokens []Lexeme) (TokenStructure, error)

type Vector

type Vector []float64

func ActionSemantic

func ActionSemantic(action Vector) (Vector, error)

func AnalyzeExpression

func AnalyzeExpression(source, text string) Vector

AnalyzeExpression creates a shared semantic vector without rewriting text. It is quote-aware and language-neutral; source-specific syntax is mapped to the same semantic axes. It is a structural scanner, not the translation engine and not a claim of full parsing.

func Basis

func Basis(size, index int) Vector

func FeatureRequirements

func FeatureRequirements(semantic Vector) (Vector, error)

func GrammarProfile

func GrammarProfile(language string) (Vector, error)

func LexicalAxesFor

func LexicalAxesFor(source string, class TokenClass, text string) Vector

func MissingLowerings

func MissingLowerings(target string, required Vector) (Vector, error)

func StatementRequirements

func StatementRequirements(vectors []Vector) (Vector, error)

func (Vector) Dot

func (v Vector) Dot(right Vector) (float64, error)

func (Vector) Or

func (v Vector) Or(right Vector) (Vector, error)

Jump to

Keyboard shortcuts

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