compiler

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CoreConsts added in v1.3.0

func CoreConsts() *vm.Consts

CoreConsts returns the global const pool populated during core boot. Used as parent for layered child pools during user code compilation.

func Eval

func Eval(src string) (vm.Value, error)

func IsErrorEOF added in v1.9.0

func IsErrorEOF(err error) bool

IsErrorEOF reports whether err represents end-of-input: a plain io.EOF, or a ReaderError whose (possibly nested) cause is io.EOF. Use this instead of errors.Is(err, io.EOF) for reader output — ReaderError wraps io.EOF in a `cause` field and does not implement Unwrap, so errors.Is never matches it.

func PrecompiledNSChunk added in v1.3.0

func PrecompiledNSChunk(name string) *vm.CodeChunk

PrecompiledNSChunk returns the precompiled main chunk for a namespace, or nil.

func ReadString

func ReadString(s string) (vm.Value, error)

ReadString parses a string into a let-go Value. As a single-form entry point it skips leading no-value forms (comments, #_ discard) so a string that opens with a ';;' comment yields the following form rather than the VOID sentinel.

func SetMatchBbConditional added in v1.10.0

func SetMatchBbConditional(v bool)

SetMatchBbConditional toggles whether reader conditionals match :bb.

func SetMatchCljConditional added in v1.7.3

func SetMatchCljConditional(v bool)

SetMatchCljConditional toggles whether reader conditionals match :clj.

Types

type CompileError

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

func NewCompileError

func NewCompileError(message string) *CompileError

func NewCompileErrorWithSource

func NewCompileErrorWithSource(message string, info *vm.SourceInfo) *CompileError

func (*CompileError) Error

func (r *CompileError) Error() string

func (*CompileError) GetCause

func (r *CompileError) GetCause() error

func (*CompileError) InnermostMessage

func (r *CompileError) InnermostMessage() string

InnermostMessage walks the error chain and returns the deepest error message.

func (*CompileError) InnermostSource

func (r *CompileError) InnermostSource() *vm.SourceInfo

InnermostSource walks the error chain and returns the deepest source info found.

func (*CompileError) Message added in v1.12.0

func (r *CompileError) Message() string

func (*CompileError) Source

func (r *CompileError) Source() *vm.SourceInfo

func (*CompileError) Wrap

func (r *CompileError) Wrap(err error) errors.Error

type Context

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

func NewCompiler

func NewCompiler(consts *vm.Consts, ns *vm.Namespace) *Context

func NewDebugCompiler

func NewDebugCompiler(consts *vm.Consts, ns *vm.Namespace) *Context

func NewTransientCompiler added in v1.12.0

func NewTransientCompiler(parent *vm.Consts, ns *vm.Namespace) *Context

NewTransientCompiler returns a compiler for ONE transient evaluation (a REPL/nREPL input, load-string, eval, a pod or host request): constants the evaluation introduces intern into a CHILD pool layered on parent, so they stay reachable only through the chunks and functions that use them and are collected with them — instead of rooting the parent pool forever, one entry per eval, unbounded in a long-lived session.

Every transient-eval site must build its compiler here; a bare NewCompiler call is reserved for pools that SHOULD live as long as the process (boot, require/ns loading, build tools). Grep for NewCompiler( to audit.

func (*Context) ChildForEval added in v1.12.0

func (c *Context) ChildForEval() *Context

ChildForEval returns a fresh compilation context for one transient top-level evaluation layered on this context's pool: same namespace and debug mode, child constant pool (see NewTransientCompiler).

Field semantics: debug and source are COPIED (user setting + error-report label); the namespace is inherited through the process-global CurrentNS (continuity across evals); everything else (chunk, locals, stack state) is freshly initialized — each eval is independent. Repeated calls produce SIBLING children of this context's pool, not a nested chain: each transient eval's constants live exactly as long as its own chunks, and siblings cannot alias each other's index space (Intern only reuses parent indices below the child's base).

func (*Context) Compile

func (c *Context) Compile(s string) (chunk *vm.CodeChunk, err error)

func (*Context) CompileMultiple

func (c *Context) CompileMultiple(reader io.Reader) (compiled *vm.CodeChunk, result vm.Value, err error)

func (*Context) Consts

func (c *Context) Consts() *vm.Consts

func (*Context) CurrentNS

func (c *Context) CurrentNS() *vm.Namespace

func (*Context) SetCurrentNS

func (c *Context) SetCurrentNS(ns *vm.Namespace)

func (*Context) SetSource

func (c *Context) SetSource(source string) *Context

type LispReader

type LispReader struct {
	Tokens []Token
	// contains filtered or unexported fields
}

func NewLispReader

func NewLispReader(r io.Reader, inputName string) *LispReader

func NewLispReaderTokenizing

func NewLispReaderTokenizing(r io.Reader, inputName string) *LispReader

func (*LispReader) Read

func (r *LispReader) Read() (vm.Value, error)

Read reads a single form. No-value reader macros (line comments, #_ discard, reader conditionals with no matching branch) return the VOID sentinel — this is load-bearing: collection readers (readList/readVector/readMap/readSet) call Read in element/value position and rely on seeing VOID to drop an orphaned map key or splice nothing (e.g. {:a #_ 1 :b 2} => {:b 2}). Callers that want a real form with leading no-value forms skipped use ReadSkipNoValue.

func (*LispReader) ReadSkipNoValue added in v1.11.0

func (r *LispReader) ReadSkipNoValue() (vm.Value, error)

ReadSkipNoValue reads a single form, skipping leading no-value forms (line comments, #_ discard, non-matching reader conditionals) so the result is a real form. It surfaces EOF when the input holds no form at all. This is the single-form entry point used by read-string; unlike Read it never returns VOID. Each no-value macro consumes input, so the loop always makes progress.

type ReaderError

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

func NewReaderError

func NewReaderError(r *LispReader, message string) *ReaderError

func (*ReaderError) Error

func (r *ReaderError) Error() string

func (*ReaderError) GetCause

func (r *ReaderError) GetCause() error

func (*ReaderError) IsEOF

func (r *ReaderError) IsEOF() bool

func (*ReaderError) Wrap

func (r *ReaderError) Wrap(err error) errors.Error

type Token

type Token struct {
	Start int
	End   int
	Kind  TokenKind
}

type TokenKind

type TokenKind int
const (
	TokenString TokenKind = iota
	TokenNumber
	TokenKeyword
	TokenSymbol
	TokenChar
	TokenSpecial
	TokenComment
	TokenPunctuation
)

type TopLevelForm added in v1.12.0

type TopLevelForm struct {
	Form      vm.Value
	Source    string
	Start     int
	End       int
	Line      int
	Column    int
	EndLine   int
	EndColumn int
}

TopLevelForm holds one top-level form plus the exact source slice that produced it.

func SplitTopLevelForms added in v1.12.0

func SplitTopLevelForms(src, inputName string) ([]TopLevelForm, error)

SplitTopLevelForms reads src as a sequence of top-level forms and returns their exact source slices in order. Leading whitespace and no-value reader forms are skipped; each returned Source starts at the first byte of the corresponding real form.

Jump to

Keyboard shortcuts

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