Documentation
¶
Overview ¶
Package expr is the runner's expression engine: model.Expr compiles to a chain of typed Go closures (direct.go) that call the PHP-semantic helpers directly and read variables by slot from the Env carrier. It grew as the seam in front of github.com/expr-lang/expr and replaced it engine-first: the closure-chain technique is guamoko995/expr-cls's, applied to the model AST once the transpile round-trip had nothing left to do.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BoundClosure ¶
BoundClosure is one compiled closure literal: the synthetic identifier, the declaration Eval binds a callable for, and its slot.
type BoundVar ¶
BoundVar is one variable the compiled expression reads: the PHP name, the bare-name flag Eval's resolution needs, and the slot the value lands in.
type Compiled ¶
type Compiled struct {
Program *Program
Vars []BoundVar
Calls []string
Closures []BoundClosure
// Exprs holds the marked sub-expressions (`++`/`--`, include) the
// compiled closures evaluate through the __eval base helper, keyed by
// the mark id, the same contract the transpiler's marks use.
Exprs map[string]model.Expr
}
Compiled is a model.Expr compiled straight to a closure chain, with the bindings Eval fills before running: variables by slot, closure literals by slot, and the registered-function names to install into the base env. It carries no bytecode; the string round-trip through the transpiler and expr-lang's parser never happens for an expression compiled here.
func CompileExpr ¶
CompileExpr compiles a model.Expr directly to a closure chain. It covers the whole expression vocabulary the runtime evaluates; an expression shape outside it is an error, spelled the way the transpiler spelled it when it was the compiler.
type Env ¶
Env is the engine's evaluation environment. Per-expression values (PHP variables, bare-name constants, closure literals) live in Vars, indexed by the slot the compiler assigned to their identifier; everything persistent (the PHP-semantic helpers, installed functions) stays in Base.
type Helpers ¶
type Helpers struct {
Truthy func(v any) bool
Concat func(a, b any) string
Pair func(key, val any) model.ArrayItemValue
Array func(items ...model.ArrayItemValue) *model.Array
Index func(base, idx any) any
Cast func(typ string, v any) any
Arith func(op string, a, b any) any
Compare func(op string, a, b any) bool
Bitwise func(op string, a, b any) (any, error)
BitNot func(v any) any
InstanceOf func(value, class any) bool
Negate func(v any) any
// PanicError converts a recovered panic into the error the runner's own
// call boundary would have produced, so a host panic stays catchable as
// the same PHP exception on both engines.
PanicError func(recovered any) error
// Slotted reports whether an identifier is a per-evaluation value: a
// PHP variable, a bare name, a closure literal. Those compile to slot
// reads; everything else (function names) stays a Base lookup.
Slotted func(name string) bool
}
Helpers carries the typed implementations of the PHP-semantic helper functions. The engine calls them directly, without the []any argument slice or a per-call panic guard. Only the pure helpers belong here; anything that re-enters the interpreter (__call, __get, __new, registered functions) stays an env lookup, because those are per-runtime closures.