runtime

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: EPL-1.0 Imports: 33 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SymbolUnquote       = lang.NewSymbol("clojure.core/unquote")
	SymbolSpliceUnquote = lang.NewSymbol("splice-unquote")
	SymbolNamespace     = lang.NewSymbol("ns")
	SymbolInNamespace   = lang.NewSymbol("in-ns")
	SymbolUserNamespace = lang.NewSymbol("user")
	SymbolDot           = lang.NewSymbol(".")
)
View Source
var (
	Debug = false

	SymNS   = lang.NewSymbol("ns")
	SymInNS = lang.NewSymbol("in-ns")
)
View Source
var (
	Compiler = &evalCompiler{}
)
View Source
var (
	// TODO: don't use a global RT instance; incurs overhead from dynamic lookup
	// of methods. Instead, generate direct calls to functions in this package.
	RT = &RTMethods{}
)
View Source
var (
	// The current version of Glojure
	Version = func() string {
		if version != "" {
			return strings.TrimPrefix(version, "v")
		}
		info, ok := debug.ReadBuildInfo()
		if !ok {
			return "0.0.0"
		}
		if info.Main.Version == "" || info.Main.Version == "(devel)" {
			return "0.0.0"
		}
		return strings.TrimPrefix(info.Main.Version, "v")
	}()
)

Functions

func AddLoadPath

func AddLoadPath(fs fs.FS)

AddLoadPath adds a filesystem to the load path.

func GetNSLoader added in v0.4.0

func GetNSLoader(nsResource string) func()

GetNSLoader retrieves the loader function for a namespace given its resource name.

func GetUseAOT added in v0.5.0

func GetUseAOT() bool

func IsDefaultCoreVar added in v0.7.0

func IsDefaultCoreVar(vr *lang.Var) bool

IsDefaultCoreVar reports whether vr still has the standard root installed during runtime initialization. Generated optimizations use this guard before replacing higher-order core operations whose Vars remain redefinable.

func NewEnvironment

func NewEnvironment(opts ...EvalOption) lang.Environment

func OpenURL added in v0.7.0

func OpenURL(u *url.URL) (io.ReadCloser, error)

OpenURL opens a non-file URL using the registered implementation.

func RTReadString

func RTReadString(s string) any

func ReadEval

func ReadEval(code string, options ...ReadEvalOption) interface{}

ReadEval reads and evaluates a string that may contain one or more forms in the global environment.

func ReduceInt64Pipeline added in v0.7.0

func ReduceInt64Pipeline(
	initial int64,
	coll interface{},
	transforms []ReducePipelineTransformKind,
	takeLimit int64,
) interface{}

ReduceInt64Pipeline applies an ephemeral, proven-int64 sequence pipeline directly while summing its source. The analyzer calls it only for a constant integer range after guarding every participating core Var.

func RegisterNSLoader added in v0.4.0

func RegisterNSLoader(nsResource string, loader func())

RegisterNSLoader registers a loader function for a namespace given its resource name (i.e. root path with slashes, no extension).

func RegisterURLOpener added in v0.7.0

func RegisterURLOpener(opener URLOpener)

RegisterURLOpener installs the process-wide implementation used by glojure.go.io for non-file URLs. The most recent registration wins.

Types

type EvalOption

type EvalOption func(*evalOptions)

func WithLoadPath

func WithLoadPath(path []string) EvalOption

func WithStderr

func WithStderr(w io.Writer) EvalOption

func WithStdout

func WithStdout(w io.Writer) EvalOption

type Fn

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

func NewFn

func NewFn(astNode *ast.Node, env lang.Environment) *Fn

func (*Fn) ASTNode added in v0.4.0

func (fn *Fn) ASTNode() *ast.Node

func (*Fn) ApplyTo

func (fn *Fn) ApplyTo(args lang.ISeq) interface{}

func (*Fn) GetEnvironment added in v0.4.0

func (fn *Fn) GetEnvironment() lang.Environment

GetEnvironment returns the captured environment for this function. This is used by the codegen system to access captured values.

func (*Fn) Invoke

func (fn *Fn) Invoke(args ...interface{}) interface{}

func (*Fn) Invoke0 added in v0.7.0

func (fn *Fn) Invoke0() interface{}

func (*Fn) Invoke1 added in v0.7.0

func (fn *Fn) Invoke1(a0 interface{}) interface{}

func (*Fn) Invoke2 added in v0.7.0

func (fn *Fn) Invoke2(a0, a1 interface{}) interface{}

func (*Fn) Invoke3 added in v0.7.0

func (fn *Fn) Invoke3(a0, a1, a2 interface{}) interface{}

func (*Fn) Invoke4 added in v0.7.0

func (fn *Fn) Invoke4(a0, a1, a2, a3 interface{}) interface{}

func (*Fn) Meta

func (fn *Fn) Meta() lang.IPersistentMap

func (*Fn) WithMeta

func (fn *Fn) WithMeta(meta lang.IPersistentMap) interface{}

type Generator added in v0.4.0

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

Generator handles the conversion of AST nodes to Go code

func NewGenerator added in v0.4.0

func NewGenerator(w io.Writer) *Generator

NewGenerator creates a new code generator

func (*Generator) Generate added in v0.4.0

func (g *Generator) Generate(ns *lang.Namespace) error

Generate takes a namespace and generates Go code that populates the same namespace

type Promise added in v0.6.5

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

Promise implements Clojure's promise semantics using Go sync primitives.

func NewPromise added in v0.6.5

func NewPromise() *Promise

func (*Promise) ApplyTo added in v0.6.5

func (p *Promise) ApplyTo(args lang.ISeq) any

func (*Promise) Deref added in v0.6.5

func (p *Promise) Deref() any

func (*Promise) DerefWithTimeout added in v0.6.5

func (p *Promise) DerefWithTimeout(timeoutMs int64, timeoutVal any) any

func (*Promise) Invoke added in v0.6.5

func (p *Promise) Invoke(args ...any) any

func (*Promise) IsRealized added in v0.6.5

func (p *Promise) IsRealized() bool

type RTEvalError added in v0.4.0

type RTEvalError struct {
	Err      error
	GLJStack []string
	GoStack  string
}

func (*RTEvalError) Error added in v0.4.0

func (e *RTEvalError) Error() string

func (*RTEvalError) Is added in v0.4.0

func (e *RTEvalError) Is(err error) bool

func (*RTEvalError) Unwrap added in v0.4.0

func (e *RTEvalError) Unwrap() error

type RTMethods

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

RT is a struct with methods that map to Clojure's RT class' static methods. This approach is used to make translation of core.clj to Glojure easier.

func (*RTMethods) Aclone added in v0.6.0

func (rt *RTMethods) Aclone(x any) any

func (*RTMethods) Alength

func (rt *RTMethods) Alength(x any) int

func (*RTMethods) BooleanCast

func (rt *RTMethods) BooleanCast(x any) bool

func (*RTMethods) ByteCast

func (rt *RTMethods) ByteCast(x any) int8

func (*RTMethods) CharCast

func (rt *RTMethods) CharCast(x any) Char

func (*RTMethods) Contains

func (rt *RTMethods) Contains(coll, key any) bool

func (*RTMethods) Dissoc

func (rt *RTMethods) Dissoc(x any, k any) any

func (*RTMethods) Find

func (rt *RTMethods) Find(coll, key any) any

func (*RTMethods) FindVar

func (rt *RTMethods) FindVar(qualifiedSym *Symbol) *Var

func (*RTMethods) Get added in v0.7.0

func (rt *RTMethods) Get(coll, key any, notFound ...any) any

Get provides the clojure.lang.RT-compatible entry point referenced by the inherited inline definition of clojure.core/get.

func (*RTMethods) IntCast

func (rt *RTMethods) IntCast(x any) int

func (*RTMethods) Load

func (rt *RTMethods) Load(scriptBase string)

func (*RTMethods) Munge

func (rt *RTMethods) Munge(name string) string

func (*RTMethods) NextID

func (rt *RTMethods) NextID() int

func (*RTMethods) Nth

func (rt *RTMethods) Nth(x any, i int) any

func (*RTMethods) NthDefault

func (rt *RTMethods) NthDefault(x any, i int, def any) any

func (*RTMethods) ObjectArray added in v0.6.0

func (rt *RTMethods) ObjectArray(sizeOrSeq any) any

ObjectArray creates an array of objects ([]any)

func (*RTMethods) Peek added in v0.2.1

func (rt *RTMethods) Peek(x any) any

func (*RTMethods) Pop

func (rt *RTMethods) Pop(x any) any

func (*RTMethods) ResolveFieldOrMethod added in v0.7.0

func (rt *RTMethods) ResolveFieldOrMethod(name string) (interface{}, bool)

ResolveFieldOrMethod keeps the collection accessors used by rewritten clojure.core forms on direct Go calls instead of reflected bound methods.

func (*RTMethods) Subs added in v0.6.5

func (rt *RTMethods) Subs(s string, start int) string

func (*RTMethods) SubsEnd added in v0.6.5

func (rt *RTMethods) SubsEnd(s string, start, end int) string

func (*RTMethods) Subvec

func (rt *RTMethods) Subvec(v IPersistentVector, start, end any) IPersistentVector

func (*RTMethods) ToArray

func (rt *RTMethods) ToArray(coll any) any

func (*RTMethods) UncheckedCharCast

func (rt *RTMethods) UncheckedCharCast(x any) Char

type ReadEvalOption

type ReadEvalOption func(*readEvalOptions)

ReadEvalOption is an option for ReadEval.

func WithEnv

func WithEnv(env lang.Environment) ReadEvalOption

WithEnv sets the environment to use for evaluation.

func WithFilename

func WithFilename(filename string) ReadEvalOption

WithFilename sets the filename to use for evaluation.

type ReducePipelineTransformKind added in v0.7.0

type ReducePipelineTransformKind uint8
const (
	ReducePipelineMapIdentity ReducePipelineTransformKind = iota
	ReducePipelineMapInc
	ReducePipelineMapDec
	ReducePipelineMapSquare
	ReducePipelineFilterOdd
	ReducePipelineFilterEven
	ReducePipelineFilterPos
	ReducePipelineFilterNeg
	ReducePipelineFilterZero
)

type URLOpener added in v0.7.0

type URLOpener func(*url.URL) (io.ReadCloser, error)

URLOpener opens a non-file URL for reading.

Jump to

Keyboard shortcuts

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