compiler

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RugoExt is the preferred file extension for Rugo source files.
	RugoExt = ".rugo"
	// DeprecatedExt is the old file extension, still supported but deprecated.
	DeprecatedExt = ".rg"
)

Variables

This section is empty.

Functions

func FindLocalEntryPoint added in v0.11.0

func FindLocalEntryPoint(dir string) (string, error)

FindLocalEntryPoint resolves the entry point Rugo file within a local directory. Resolution order: <dirname>.rugo → <dirname>.rg → main.rugo → main.rg → sole Rugo file.

func FindRugoFile added in v0.12.0

func FindRugoFile(basePath string) string

FindRugoFile looks for a Rugo source file, preferring .rugo over .rg. Given a base path without extension, returns the path if found, empty string otherwise.

func IsRugoBenchFile added in v0.12.0

func IsRugoBenchFile(name string) bool

IsRugoBenchFile returns true if the filename is a Rugo benchmark file (_bench.rugo or _bench.rg).

func IsRugoFile added in v0.12.0

func IsRugoFile(name string) bool

IsRugoFile returns true if the filename has a Rugo extension (.rugo or .rg).

func IsRugoTestFile added in v0.12.0

func IsRugoTestFile(name string) bool

IsRugoTestFile returns true if the filename is a Rugo test file (_test.rugo or _test.rg).

func TrimRugoExt added in v0.12.0

func TrimRugoExt(name string) string

TrimRugoExt removes the Rugo file extension (.rugo or .rg) from a filename.

func WarnDeprecatedExt added in v0.12.0

func WarnDeprecatedExt(filename string)

WarnDeprecatedExt prints a deprecation warning to stderr if the file uses the old .rg extension.

Types

type ArrayLiteral

type ArrayLiteral struct {
	Elements []Expr
}

ArrayLiteral is [elem, ...].

type AssignStmt

type AssignStmt struct {
	BaseStmt
	Target    string
	Value     Expr
	Namespace string // non-empty for top-level assignments from require'd files
}

AssignStmt represents target = value.

type BaseStmt

type BaseStmt struct {
	SourceLine int // line number in the original source
}

BaseStmt provides common fields for all statements.

func (BaseStmt) StmtLine

func (b BaseStmt) StmtLine() int

type BenchDef

type BenchDef struct {
	BaseStmt
	Name string
	Body []Statement
}

BenchDef represents bench "name" body end.

type BinaryExpr

type BinaryExpr struct {
	Left  Expr
	Op    string
	Right Expr
}

BinaryExpr represents left op right.

type BoolLiteral

type BoolLiteral struct {
	Value bool
}

BoolLiteral is true or false.

type BreakStmt

type BreakStmt struct{ BaseStmt }

BreakStmt represents break.

type CallExpr

type CallExpr struct {
	Func Expr
	Args []Expr
}

CallExpr represents func(args...).

type CompileResult

type CompileResult struct {
	GoSource   string
	Program    *Program
	SourceFile string // original source filename
}

CompileResult holds the output of a compilation.

type Compiler

type Compiler struct {
	// BaseDir is the directory of the main source file (for resolving requires).
	BaseDir string
	// TestMode enables test harness generation (rats blocks are included).
	// When false (default), rats blocks are silently skipped during codegen.
	TestMode bool
	// ModuleDir overrides the default module cache directory (~/.rugo/modules).
	// Used for testing. When empty, the default is used.
	ModuleDir string
	// Frozen errors if the lock file is stale or a new dependency is resolved.
	Frozen bool
	// Resolver overrides the default remote resolver. When set, the compiler
	// uses this resolver instead of creating one. Used by mod tidy to share
	// a single resolver across multiple compilations.
	Resolver *remote.Resolver
	// contains filtered or unexported fields
}

Compiler orchestrates the full compilation pipeline.

func (*Compiler) Build

func (c *Compiler) Build(filename, output string) error

Build compiles a Rugo source file to a native binary.

func (*Compiler) Compile

func (c *Compiler) Compile(filename string) (*CompileResult, error)

Compile reads a Rugo source file, resolves requires, and produces Go source.

func (*Compiler) Emit

func (c *Compiler) Emit(filename string) (string, error)

Emit compiles a Rugo source file and outputs the Go source.

func (*Compiler) Run

func (c *Compiler) Run(filename string, extraArgs ...string) error

Run compiles and runs a Rugo source file, passing extraArgs to the compiled binary.

type DotAssignStmt

type DotAssignStmt struct {
	BaseStmt
	Object Expr
	Field  string
	Value  Expr
}

DotAssignStmt represents obj.field = value.

type DotExpr

type DotExpr struct {
	Object Expr
	Field  string
}

DotExpr represents obj.field (used for namespace.func access).

type ElsifClause

type ElsifClause struct {
	Condition Expr
	Body      []Statement
}

ElsifClause is one elsif branch.

type Expr

type Expr interface {
	Node
	// contains filtered or unexported methods
}

Expr is the interface for expression nodes.

type ExprStmt

type ExprStmt struct {
	BaseStmt
	Expression Expr
}

ExprStmt is a statement that is just an expression.

type FloatLiteral

type FloatLiteral struct {
	Value string
}

FloatLiteral is a floating point literal.

type FnExpr

type FnExpr struct {
	Params []string
	Body   []Statement
}

FnExpr represents fn(params) body end (first-class lambda).

type ForStmt

type ForStmt struct {
	BaseStmt
	Var        string // value variable (or key for hashes)
	IndexVar   string // optional second variable (index for arrays, value for hashes)
	Collection Expr
	Body       []Statement
}

ForStmt represents for var [, var2] in expr body end.

type FuncDef

type FuncDef struct {
	BaseStmt
	Name       string
	Params     []string
	Body       []Statement
	Namespace  string // set during require resolution for namespaced functions
	SourceFile string // original source file for //line directives (set for require'd functions)
}

FuncDef represents def name(params) body end.

type FuncTypeInfo

type FuncTypeInfo struct {
	ParamTypes []RugoType
	ReturnType RugoType
}

FuncTypeInfo holds the inferred signature for a function.

type HashLiteral

type HashLiteral struct {
	Pairs []HashPair
}

HashLiteral is {key => value, ...}.

type HashPair

type HashPair struct {
	Key   Expr
	Value Expr
}

HashPair is a key => value pair.

type IdentExpr

type IdentExpr struct {
	Name string
}

IdentExpr is a variable/function reference.

type IfStmt

type IfStmt struct {
	BaseStmt
	Condition    Expr
	Body         []Statement
	ElsifClauses []ElsifClause
	ElseBody     []Statement
}

IfStmt represents if/elsif/else/end.

type ImportStmt

type ImportStmt struct {
	BaseStmt
	Package string // Go package path (e.g. "strings", "path/filepath")
	Alias   string // optional alias (e.g. "fp" for filepath)
}

ImportStmt represents import "go/pkg" [as alias] (Go stdlib bridge).

type IndexAssignStmt

type IndexAssignStmt struct {
	BaseStmt
	Object Expr
	Index  Expr
	Value  Expr
}

IndexAssignStmt represents obj[index] = value.

type IndexExpr

type IndexExpr struct {
	Object Expr
	Index  Expr
}

IndexExpr represents obj[index].

type IntLiteral

type IntLiteral struct {
	Value string
}

IntLiteral is an integer literal.

type NextStmt

type NextStmt struct{ BaseStmt }

NextStmt represents next (continue).

type NilLiteral

type NilLiteral struct{}

NilLiteral represents nil.

type Node

type Node interface {
	// contains filtered or unexported methods
}

Node is the interface for all AST nodes.

type ParallelExpr

type ParallelExpr struct {
	Body []Statement
}

ParallelExpr represents parallel body end (fan-out concurrency). Each statement in Body runs in its own goroutine; returns an array of results.

type Program

type Program struct {
	Statements []Statement
	SourceFile string // display path of the source file
}

Program is the root node.

type RequireStmt

type RequireStmt struct {
	BaseStmt
	Path  string
	Alias string   // empty means use filename as namespace
	With  []string // selective sub-module names (mutually exclusive with Alias)
}

RequireStmt represents require "path" [as "alias" | with mod1, mod2, ...].

type ReturnStmt

type ReturnStmt struct {
	BaseStmt
	Value Expr // nil if bare return
}

ReturnStmt represents return [expr].

type RugoType

type RugoType int

RugoType represents the inferred type of a Rugo expression or variable.

const (
	// TypeUnknown means inference hasn't resolved the type yet.
	TypeUnknown RugoType = iota
	// TypeInt is an integer type (Go int).
	TypeInt
	// TypeFloat is a floating-point type (Go float64).
	TypeFloat
	// TypeString is a string type.
	TypeString
	// TypeBool is a boolean type.
	TypeBool
	// TypeNil is the nil literal type.
	TypeNil
	// TypeArray is []interface{} (element types not tracked).
	TypeArray
	// TypeHash is map[interface{}]interface{}.
	TypeHash
	// TypeDynamic means the type is explicitly unresolvable (mixed types,
	// external calls, etc.). Falls back to interface{} in codegen.
	TypeDynamic
)

func (RugoType) GoType

func (t RugoType) GoType() string

GoType returns the Go type string for codegen, or "" for untyped.

func (RugoType) IsNumeric

func (t RugoType) IsNumeric() bool

IsNumeric returns true for int and float types.

func (RugoType) IsResolved

func (t RugoType) IsResolved() bool

IsResolved returns true if the type is concrete (not unknown or dynamic).

func (RugoType) IsTyped

func (t RugoType) IsTyped() bool

IsTyped returns true if the type can be used for typed codegen (resolved and not a compound type like array/hash).

func (RugoType) String

func (t RugoType) String() string

type SliceExpr

type SliceExpr struct {
	Object Expr
	Start  Expr
	Length Expr
}

SliceExpr represents obj[start, length].

type SpawnExpr

type SpawnExpr struct {
	Body []Statement // last expression is the task result
}

SpawnExpr represents spawn body end (goroutine-backed concurrency).

type Statement

type Statement interface {
	Node

	StmtLine() int
	// contains filtered or unexported methods
}

Statement is the interface for statement nodes.

type StringLiteral

type StringLiteral struct {
	Value string // raw string content including interpolation markers
	Raw   bool   // true for single-quoted raw strings (no escape processing)
}

StringLiteral is a string literal (with quotes stripped).

type TestDef

type TestDef struct {
	BaseStmt
	Name string
	Body []Statement
}

TestDef represents test "name" body end.

type TryExpr

type TryExpr struct {
	Expr    Expr        // expression to try
	ErrVar  string      // error variable name
	Handler []Statement // handler body; last expression is the result
}

TryExpr represents try expr or err handler end.

type TypeInfo

type TypeInfo struct {
	// ExprTypes maps expressions to their inferred types.
	ExprTypes map[Expr]RugoType
	// FuncTypes maps function names to their inferred signatures.
	FuncTypes map[string]*FuncTypeInfo
	// VarTypes maps (scope, variable name) to their final inferred type.
	// Scope is the function name (or "" for top-level).
	VarTypes map[string]map[string]RugoType
}

TypeInfo holds inferred type information for a program.

func (*TypeInfo) ExprType

func (ti *TypeInfo) ExprType(e Expr) RugoType

ExprType returns the inferred type of an expression, or TypeDynamic if unknown.

func (*TypeInfo) VarType

func (ti *TypeInfo) VarType(scope, name string) RugoType

VarType returns the inferred type of a variable in a given scope.

type UnaryExpr

type UnaryExpr struct {
	Op      string
	Operand Expr
}

UnaryExpr represents op operand.

type UseStmt

type UseStmt struct {
	BaseStmt
	Module string
}

UseStmt represents use "rugo_module" (Rugo stdlib module).

type WhileStmt

type WhileStmt struct {
	BaseStmt
	Condition Expr
	Body      []Statement
}

WhileStmt represents while cond body end.

Directories

Path Synopsis
Package gobridge provides the Go standard library bridge registry for Rugo.
Package gobridge provides the Go standard library bridge registry for Rugo.

Jump to

Keyboard shortcuts

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