evaldo

package
v0.2.57 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: BSD-3-Clause Imports: 27 Imported by: 3

Documentation

Overview

evaldo_rye0.go - A simplified interpreter for the Rye language

evaldo_rye00.go - A highly simplified interpreter for the Rye language This version only handles builtins and integers for performance optimization experiments

Index

Constants

This section is empty.

Variables

View Source
var BatteryConvertHook func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object) env.Object = func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object) env.Object {
	return MakeBuiltinError(ps, "Conversion requires the batteries package (call batteries.RegisterBatteries first).", "convert")
}

BatteryConvertHook is called by base builtins that perform Kind-based conversion. Batteries set this to batteries.BuiConvert.

View Source
var BatteryDialectMathHook func(ps *env.ProgramState, arg0 env.Object) env.Object = func(ps *env.ProgramState, arg0 env.Object) env.Object {
	return MakeBuiltinError(ps, "Math dialect requires the batteries package.", "math")
}

BatteryDialectMathHook is called by the REPL when the dialect is "math". Batteries set this to DialectMath.

View Source
var BatteryEvalInPersistentCtxHook func(ps *env.ProgramState, ctx PersistentCtxInterface) = func(ps *env.ProgramState, ctx PersistentCtxInterface) {

}

BatteryEvalInPersistentCtxHook is called by "do\inside" when the context is a PersistentCtx. Batteries set this to their EvalBlockInPersistentCtx.

View Source
var BatteryEyrEvalBlockHook func(ps *env.ProgramState, full bool) = func(ps *env.ProgramState, full bool) {

}

BatteryEyrEvalBlockHook is called by the REPL when the dialect is "eyr". Batteries set this to Eyr_EvalBlock.

View Source
var BatteryEyrEvalBlockInsideHook func(ps *env.ProgramState, inj env.Object, injnow bool) = func(ps *env.ProgramState, inj env.Object, injnow bool) {

}

BatteryEyrEvalBlockInsideHook is called by EvalBlockInj when the dialect is EyrDialect. Batteries set this to Eyr_EvalBlockInside.

View Source
var BatteryMarkdownDisplayHook func(source string) []interface{} = func(source string) []interface{} {
	return nil
}

BatteryMarkdownDisplayHook is called by the base printing builtins to render markdown blocks in the REPL. Batteries set this to their markdown renderer. The returned []interface{} should be the converted display items.

View Source
var BatteryValidateHook func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object) env.Object = func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object) env.Object {
	return MakeBuiltinError(ps, "Validation requires the batteries package (call batteries.RegisterBatteries first).", "validate")
}

BatteryValidateHook is called by base builtins (e.g. "_<<", "assure-kind") that need to validate a Dict/RyeCtx against a spec block. Batteries set this to batteries.BuiValidate.

View Source
var BuiltinNames map[string]int // TODO --- this looks like some hanging global ... it should move to ProgramState, it doesn't even really work with contrib and external probably
View Source
var NoInspectMode bool

NoInspectMode controls whether to exit immediately on error without showing debugging options

View Source
var OfferDebuggingOptionsHook func(es *env.ProgramState, genv *env.Idxs, tag string) = func(es *env.ProgramState, genv *env.Idxs, tag string) {}

OfferDebuggingOptionsHook is a function variable that can be set by the console package to provide interactive debugging options. It defaults to a no-op, which is the correct behaviour for embedded/WASM/b_norepl builds that never import the console package.

View Source
var ShowResults bool
View Source
var VarBuiltins_demo = map[string]*env.VarBuiltin{

	"var-not": {
		Argsn: 1,
		Doc:   "Performs logical negation on boolean values only.",
		Pure:  true,
		Fn: func(env1 *env.ProgramState, args ...env.Object) env.Object {
			switch b := args[0].(type) {
			case env.Boolean:
				return *env.NewBoolean(!b.Value)
			default:
				return MakeArgError(env1, 1, []env.Type{env.BooleanType}, "not")
			}
		},
	},

	"var-and": {
		Argsn: 2,
		Doc:   "Performs a logical AND operation between two boolean values, or a bitwise AND operation between two integer values.",
		Pure:  true,
		Fn: func(ps *env.ProgramState, args ...env.Object) env.Object {
			switch s1 := args[0].(type) {
			case env.Boolean:
				switch s2 := args[1].(type) {
				case env.Boolean:
					return *env.NewBoolean(s1.Value && s2.Value)
				default:
					return MakeArgError(ps, 2, []env.Type{env.BooleanType}, "and")
				}
			case env.Integer:
				switch s2 := args[1].(type) {
				case env.Integer:
					return *env.NewInteger(s1.Value & s2.Value)
				default:
					return MakeArgError(ps, 2, []env.Type{env.IntegerType}, "and")
				}
			default:
				return MakeArgError(ps, 1, []env.Type{env.BooleanType, env.IntegerType}, "and")
			}
		},
	},
}

Functions

func CallBuiltin_CollectArgs added in v0.0.90

func CallBuiltin_CollectArgs(bi env.Builtin, ps *env.ProgramState, arg0_ env.Object, toLeft bool, pipeSecond bool, firstVal env.Object, opword bool, dotword bool)

CallBuiltin_CollectArgs calls a builtin by collecting up to 5 arguments from the code stream. Called from: EvalExpression_DispatchType, EvalObject Purpose: Main builtin caller - collects arguments, handles failure flags, calls builtin function

func CallCurriedCaller added in v0.0.82

func CallCurriedCaller(cc env.CurriedCaller, ps *env.ProgramState, arg0_ env.Object, toLeft bool, pipeSecond bool, firstVal env.Object, opword bool, dotword bool)

CallCurriedCaller handles calling a curried caller (partially applied function or builtin). Called from: EvalExpression_DispatchType, EvalObject Purpose: Executes curried callers by filling in remaining arguments and calling the underlying builtin/function

func CallCurriedCallerArgsN added in v0.2.0

func CallCurriedCallerArgsN(cc env.CurriedCaller, ps *env.ProgramState, args ...env.Object)

CallCurriedCallerArgsN calls a curried caller with N provided arguments (not collected from code stream). Called from: builtins that need to call curried callers with specific arguments (e.g., HTTP handlers) Purpose: Fills curried caller's nil slots with provided arguments and executes the underlying function/builtin

func CallFunctionArgs1 added in v0.2.7

func CallFunctionArgs1(fn env.Function, ps *env.ProgramState, arg0 env.Object, ctx *env.RyeCtx)

CallFunctionArgs1 calls a function with exactly 1 argument provided. Called from: CallFunctionWithArgs, builtins needing to call 1-arg functions Purpose: Optimized path for 1-argument function calls from builtins

func CallFunctionArgs2

func CallFunctionArgs2(fn env.Function, ps *env.ProgramState, arg0 env.Object, arg1 env.Object, ctx *env.RyeCtx)

CallFunctionArgs2 calls a function with exactly 2 arguments provided. Called from: CallFunctionWithArgs, builtins needing to call 2-arg functions Purpose: Optimized path for 2-argument function calls from builtins

func CallFunctionArgs4

func CallFunctionArgs4(fn env.Function, ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, ctx *env.RyeCtx)

CallFunctionArgs4 calls a function with exactly 4 arguments provided. Called from: CallFunctionWithArgs, builtins needing to call 4-arg functions Purpose: Optimized path for 4-argument function calls from builtins

func CallFunctionArgsN added in v0.0.21

func CallFunctionArgsN(fn env.Function, ps *env.ProgramState, ctx *env.RyeCtx, args ...env.Object)

CallFunctionArgsN calls a function with a variable number of arguments (N arguments). Called from: CallFunctionWithArgs, CallCurriedCaller, builtins with variable args Purpose: Generic function caller for any number of arguments provided as a slice

func CallFunctionWithArgs added in v0.0.81

func CallFunctionWithArgs(fn env.Function, ps *env.ProgramState, ctx *env.RyeCtx, args ...env.Object)

CallFunctionWithArgs is a consolidated function caller that dispatches based on argument count. Called from: Various builtins that need to call user functions Purpose: Dispatcher that routes to specialized function callers based on number of arguments (0,1,2,4,N) Note: Context creation is handled by the subfunctions, not here

func CallFunction_CollectArgs added in v0.0.90

func CallFunction_CollectArgs(fn env.Function, ps *env.ProgramState, arg0_ env.Object, toLeft bool, ctx *env.RyeCtx, pipeSecond ...interface{})

CallFunction_CollectArgs calls a function by collecting arguments from the code stream. Called from: EvalObject, CallFunctionWithArgs (0 arg case) Purpose: Main function caller in evaluator - collects args from code, sets up context, executes function body

func CallVarBuiltin added in v0.0.40

func CallVarBuiltin(bi env.VarBuiltin, ps *env.ProgramState, arg0_ env.Object, toLeft bool, pipeSecond bool, firstVal env.Object, opword bool, dotword bool)

CallVarBuiltin calls a variadic builtin by collecting all required arguments into a slice. Called from: EvalExpression_DispatchType, EvalObject Purpose: Handles builtins with variable number of arguments, collecting them into a slice

func CheckForFailureWithBuiltin added in v0.2.50

func CheckForFailureWithBuiltin(bi env.Builtin, ps *env.ProgramState, n int) bool

CheckForFailureWithBuiltin is an exported wrapper around checkForFailureWithBuiltin, exposed for use by the batteries package.

func CompileRyeToEyr added in v0.0.21

func CompileRyeToEyr(block *env.Block, ps *env.ProgramState, eyrBlock *env.Block) *env.Block

func CompileStepRyeToEyr added in v0.0.21

func CompileStepRyeToEyr(block *env.Block, ps *env.ProgramState, eyrBlock *env.Block) *env.Block

func CompileWord added in v0.0.21

func CompileWord(block *env.Block, ps *env.ProgramState, word env.Word, eyrBlock *env.Block)

func DetermineContext added in v0.0.22

func DetermineContext(fn env.Function, ps *env.ProgramState, ctx *env.RyeCtx) (*env.RyeCtx, bool)

DetermineContext determines the appropriate context for a function call. Called from: CallFunctionWithArgs, CallFunctionArgs1, CallFunctionArgs2, CallFunctionArgs4, CallFunctionArgsN Purpose: Sets up function execution context based on pure/impure, defined context, and parent context Returns: The context to use and a boolean indicating if it was obtained from the pool (and can be returned)

func DirectlyCallBuiltin

func DirectlyCallBuiltin(ps *env.ProgramState, bi env.Builtin, a0 env.Object, a1 env.Object) env.Object

DirectlyCallBuiltin directly calls a builtin with provided arguments (no collection from code). Called from: Builtins that need to call other builtins directly Purpose: Direct builtin invocation helper for inter-builtin calls

func DisplayEnhancedError added in v0.0.86

func DisplayEnhancedError(es *env.ProgramState, genv *env.Idxs, tag string, topLevel bool)

DisplayEnhancedError displays a formatted error with source location and block context. Called from: MaybeDisplayFailureOrError2 Purpose: Main error display - shows red banner, error message, block location, and <here> marker

func DisplayRyeValue added in v0.2.50

func DisplayRyeValue(ps *env.ProgramState, arg0 env.Object, interactive bool) (env.Object, string)

DisplayRyeValue handles the display of Rye values, supporting both interactive and non-interactive modes. Exported so the console package can reference it via evaldo.DisplayRyeValue.

func Eval added in v0.2.3

func Eval(ps *env.ProgramState)

EvalBlock is the main entry point for evaluating a block of code. Called from: Throughout the codebase - main evaluation loops, builtins, function calls Purpose: Dispatches to the appropriate dialect-specific evaluator (Rye2, Eyr, Rye0, Rye00) HOTCODE: Performance-critical function called frequently during execution

func EvalBlock

func EvalBlock(ps *env.ProgramState, blk *env.Block)

EvalBlock sets the block as the current series and evaluates it. This is the idiomatic entry point for embedders - combining ps.SetBlock and Eval into a single call:

blk := loader.LoadString(src, false, ps)
evaldo.EvalBlock(ps, &blk.(env.Block))

func EvalBlockInCtxInj

func EvalBlockInCtxInj(ps *env.ProgramState, ctx *env.RyeCtx, inj env.Object, injnow bool)

EvalBlockInCtxInj evaluates a block in a specific context with value injection. Called from: Builtins that need to evaluate code in a different context Purpose: Temporarily switches to specified context, evaluates block, then restores original context

func EvalBlockInj

func EvalBlockInj(ps *env.ProgramState, inj env.Object, injnow bool)

EvalBlockInj evaluates a block with value injection support across multiple dialects. Called from: EvalBlock, EvalExpression_DispatchType (for OPGROUP/OPBLOCK modes), observer execution, builtins Purpose: Main multi-dialect block evaluator with optional value injection into the first expression HOTCODE: Performance-critical function called frequently during execution

func EvalBlockInj_Rye2 added in v0.2.0

func EvalBlockInj_Rye2(ps *env.ProgramState, inj env.Object, injnow bool)

EvalBlockInj_Rye2 evaluates a block of code with optional value injection for Rye2 dialect. Called from: EvalBlockInj (multi-dialect dispatcher), CallFunction_CollectArgs, ExecuteDeferredBlocks Purpose: Core Rye2 evaluator - loops through expressions, handling injection, commas, and error/failure flags

func EvalExpression added in v0.0.81

func EvalExpression(ps *env.ProgramState, inj env.Object, injnow bool, limited bool, opword bool, dotword bool) bool

EvalExpression is the consolidated expression evaluator handling both regular and injected evaluation. Called from: EvalExpressionInj, EvalExpression_CollectArg, EvalExpressionInjLimited (wrapper functions) Purpose: Evaluates left side via DispatchType, then optionally evaluates right side (opwords/pipewords)

func EvalExpressionInj

func EvalExpressionInj(ps *env.ProgramState, inj env.Object, injnow bool) bool

EvalExpressionInj evaluates an expression with optional value injection. Called from: EvalBlockInj, EvalExpression_DispatchType (OPBBLOCK mode), EvalSetword, EvalModword Purpose: Wrapper for EvalExpression that allows injecting a value into the expression

func EvalExpressionInjLimited

func EvalExpressionInjLimited(ps *env.ProgramState, inj env.Object, injnow bool) bool

EvalExpressionInjLimited evaluates an expression with injection in limited mode (stops at setwords/pipewords). Called from: Various places where expression evaluation should not consume setwords or pipewords Purpose: Limited expression evaluation that prevents consuming certain right-side constructs

func EvalExpression_CollectArg added in v0.0.90

func EvalExpression_CollectArg(ps *env.ProgramState, limited bool, opword bool)

EvalExpression_CollectArg evaluates an expression without injection (for collecting function arguments). Called from: CallFunction_CollectArgs, CallBuiltin_CollectArgs, CallVarBuiltin, EvalWord Purpose: Wrapper for EvalExpression used when collecting arguments from code Note: dotword=false here - callers that need dotword blocking use EvalExpression directly with dotword=true

func EvalExpression_DispatchType added in v0.0.90

func EvalExpression_DispatchType(ps *env.ProgramState)

EvalExpression_DispatchType is the core type dispatcher that evaluates individual Rye values. Called from: EvalExpression, EvalWord, EvalGenword Purpose: Main type switch - handles all Rye value types and dispatches to appropriate handlers Note: This is the heart of the evaluator - if Rye were fully Polish notation, this would be most of it It handles the case when there is no value on the left, so we are starting a fresh expression

func EvalGenword

func EvalGenword(ps *env.ProgramState, word env.Genword, leftVal env.Object, toLeft bool)

EvalGenword evaluates a generic word (explicitly declared generic). Called from: EvalExpression_DispatchType Purpose: Handles words explicitly marked as generic - evaluates next expression and dispatches on its type

func EvalGetword

func EvalGetword(ps *env.ProgramState, word env.Getword, leftVal env.Object, toLeft bool)

EvalGetword evaluates a get-word (prefixed with ?) which retrieves a value without calling it. Called from: EvalExpression_DispatchType Purpose: Returns the raw value associated with a word without evaluating it (like quoting)

func EvalModword added in v0.0.20

func EvalModword(ps *env.ProgramState, word env.Modword)

EvalModword evaluates a mod-word (word::) which modifies an existing word in the context. Called from: EvalExpression_DispatchType Purpose: Evaluates the expression to the right and modifies an existing word's value, triggers observers

func EvalObject

func EvalObject(ps *env.ProgramState, object env.Object, leftVal env.Object, toLeft bool, ctx *env.RyeCtx, pipeSecond bool, firstVal env.Object, opword bool, dotword bool)

EvalObject evaluates a Rye object, particularly handling callable types (builtins, functions). Called from: EvalWord, EvalGenword Purpose: Evaluates found objects - dispatches builtins/functions/cpaths to their callers, returns other types

func EvalSetword

func EvalSetword(ps *env.ProgramState, word env.Setword)

EvalSetword evaluates a set-word (word:) which sets a new word in the context. Called from: EvalExpression_DispatchType Purpose: Evaluates the expression to the right and binds the result to a word (creating new binding)

func EvalWord

func EvalWord(ps *env.ProgramState, word env.Object, leftVal env.Object, toLeft bool, pipeSecond bool, opword bool, dotword bool)

EvalWord evaluates a word by looking up its value and potentially dispatching to generic words. Called from: EvalExpression_DispatchType, OptionallyEvalExpressionRight, EvalObject Purpose: Main word evaluator - looks up in context, tries generic words if not found, handles getcpath mode

when there is a left value

func EvaluateLoadedValue added in v0.0.20

func EvaluateLoadedValue(ps *env.ProgramState, block_ env.Object, script_ string, allowMod bool) env.Object

func ExecuteDeferredBlocks added in v0.0.40

func ExecuteDeferredBlocks(ps *env.ProgramState)

ExecuteDeferredBlocks executes all deferred blocks in LIFO order (last in, first out). Called from: CallFunction_CollectArgs, CallFunctionArgs1, CallFunctionArgs2, CallFunctionArgs4, CallFunctionArgsN (via defer) Purpose: Executes cleanup blocks registered with defer, similar to Go's defer statement

func ExtractFunctionName added in v0.0.93

func ExtractFunctionName(doc string) (name string, found bool)

ExtractFunctionName extracts the function name from a docstring that ends with "(name)" If the pattern is found, returns the name; otherwise returns the full docstring

func FastCallBuiltin added in v0.0.44

func FastCallBuiltin(ps *env.ProgramState, bi env.Builtin, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object

FastCallBuiltin is an optimized version of CallBuiltin for the common case where all arguments are already available. It skips the argument evaluation, error checking, and currying logic that makes CallBuiltin slower.

This function should be used when: 1. All arguments are already available (no need to evaluate from program state) 2. No currying is needed 3. The builtin function has a fixed number of arguments

func FastCallFunction added in v0.0.80

func FastCallFunction(fn env.Function, ps *env.ProgramState, args []env.Object, ctx *env.RyeCtx) *env.ProgramState

FastCallFunction is an optimized version of Rye0_CallFunction for the common case where all arguments are already available. It skips the complex context determination, argument evaluation, and error checking that makes Rye0_CallFunction slower.

This function should be used when: 1. All arguments are already available (no need to evaluate from program state) 2. The function has a fixed number of arguments (typically small, like 0-3) 3. No complex context path resolution is needed

func FastCallFunctionWithArgs added in v0.0.80

func FastCallFunctionWithArgs(fn env.Function, ps *env.ProgramState, ctx *env.RyeCtx, args ...env.Object) *env.ProgramState

FastCallFunctionWithArgs is an optimized version of Rye0_CallFunctionWithArgs It's similar to FastCallFunction but follows the signature of Rye0_CallFunctionWithArgs

func FindWordValue added in v0.2.50

func FindWordValue(ps *env.ProgramState, word1 env.Object) (bool, env.Object, *env.RyeCtx)

FindWordValue is an exported wrapper around findWordValue, exposed for use by the batteries package.

func FormatBacktickQuotes added in v0.0.93

func FormatBacktickQuotes(message string) string

FormatBacktickQuotes processes an error message and highlights text within backticks with a special background color for terminal display. Called from: DisplayEnhancedError Purpose: Converts `word` to highlighted word for better error readability

func FormatBuiltinReference added in v0.0.93

func FormatBuiltinReference(doc string) string

FormatBuiltinReference formats a builtin reference for error display If a name can be extracted from the docstring, it returns the emphasized name Otherwise returns the full docstring Uses backticks to quote the name - the display function will highlight them

func GreaterThanNew added in v0.2.50

func GreaterThanNew(arg0 env.Object, arg1 env.Object) bool

GreaterThanNew is an exported wrapper around greaterThanNew, exposed for use by the batteries package.

func IntersectBlocksCustom added in v0.0.34

func IntersectBlocksCustom(a env.Block, b env.Block, ps *env.ProgramState, fn env.Function) []env.Object

func IntersectStringsCustom added in v0.0.34

func IntersectStringsCustom(a env.String, b env.String, ps *env.ProgramState, fn env.Function) string

func LesserThanNew added in v0.2.50

func LesserThanNew(arg0 env.Object, arg1 env.Object) bool

LesserThanNew is an exported wrapper around lesserThanNew, exposed for use by the batteries package.

func LoadScriptLocalFile added in v0.0.20

func LoadScriptLocalFile(ps *env.ProgramState, s1 env.Uri) (env.Object, string)

func MakeArgError

func MakeArgError(env1 *env.ProgramState, N int, typ []env.Type, fn string) *env.Error

func MakeArgErrorMessage added in v0.0.25

func MakeArgErrorMessage(N int, allowedTypes []env.Type, fn string) string

func MakeBuiltinError

func MakeBuiltinError(env1 *env.ProgramState, msg string, fn string) *env.Error

func MakeError

func MakeError(env1 *env.ProgramState, msg string) *env.Error

func MakeNativeArgError added in v0.0.19

func MakeNativeArgError(env1 *env.ProgramState, N int, knd []string, fn string) *env.Error

func MakeNeedsThawedArgError added in v0.0.25

func MakeNeedsThawedArgError(env1 *env.ProgramState, fn string) *env.Error

func MakeRyeError

func MakeRyeError(env1 *env.ProgramState, val env.Object, er *env.Error) *env.Error

func MaybeAcceptComma

func MaybeAcceptComma(ps *env.ProgramState, inj env.Object, injnow bool) bool

MaybeAcceptComma handles comma expression guards between block-level expressions. Called from: EvalBlockInj, EvalExpression_DispatchType (OPBBLOCK mode) Purpose: Checks for and consumes comma separators; re-enables injection if comma found HOTPATH: Called frequently during block evaluation

func MaybeDisplayFailureOrError

func MaybeDisplayFailureOrError(es *env.ProgramState, genv *env.Idxs, tag string)

MaybeDisplayFailureOrError displays errors/failures if error flag is set (wrapper). Called from: Throughout the codebase after evaluation operations Purpose: Wrapper that calls MaybeDisplayFailureOrError2 with default parameters

func MaybeDisplayFailureOrError2 added in v0.0.87

func MaybeDisplayFailureOrError2(es *env.ProgramState, genv *env.Idxs, tag string, topLevel bool, fileMode bool)

MaybeDisplayFailureOrError2 displays errors/failures and optionally offers debugging options. Called from: MaybeDisplayFailureOrError, main REPL/file execution code Purpose: Main error display coordinator - shows enhanced errors and offers debugging in file mode

func MaybeDisplayFailureOrErrorWASM added in v0.0.13

func MaybeDisplayFailureOrErrorWASM(es *env.ProgramState, genv *env.Idxs, printfn func(string), tag string)

MaybeDisplayFailureOrErrorWASM displays errors/failures in WASM environment using custom print function. Called from: WASM build code (main_wasm.go) Purpose: WASM-specific error display that uses provided print function instead of fmt.Println

func Mth_EvalDirect added in v0.2.0

func Mth_EvalDirect(ps *env.ProgramState) env.Object

Mth_EvalDirect is the fast single-pass math evaluator. It reads tokens from ps.Ser using the Shunting-yard algorithm and computes the result inline. No builtin lookup, no global state, no init.

func NameOfRyeType added in v0.0.25

func NameOfRyeType(t env.Type) string

func OptionallyEvalExpressionRight added in v0.0.90

func OptionallyEvalExpressionRight(nextObj env.Object, ps *env.ProgramState, limited bool, allowOpwords bool, allowDotwords bool)

OptionallyEvalExpressionRight evaluates right-side constructs like opwords, pipewords, and setwords. Called from: EvalExpression, recursively from itself Purpose: Handles operator precedence by evaluating opwords/pipewords/setwords/modwords to the right allowOpwords=false: prevents nested opwords from being consumed as arguments (set when collecting opword/dotword args) allowDotwords=false: prevents nested dotwords from being consumed as arguments (set when collecting dotword args)

func RegisterBaseBuiltins added in v0.2.50

func RegisterBaseBuiltins(ps *env.ProgramState)

RegisterBaseBuiltins registers only the pure-computation builtins that have no OS / file-system / shell dependency. This is the right choice for embedding Rye inside a Go application when you want to keep the sandbox free of host-OS access. Call RegisterBaseIOBuiltins afterwards if you also want file, shell, args, and exit support.

func RegisterBaseIOBuiltins added in v0.2.50

func RegisterBaseIOBuiltins(ps *env.ProgramState)

RegisterBaseIOBuiltins adds the OS / file / shell / args builtins from builtins_baseio.go on top of an already-initialised program state. It must be called AFTER RegisterBaseBuiltins (or RegisterBuiltins).

func RegisterBuiltin added in v0.2.6

func RegisterBuiltin(ps *env.ProgramState, word string, builtin env.Builtin)

TODO -- remove registerBuiltin

func RegisterBuiltinGroups added in v0.2.3

func RegisterBuiltinGroups(ps *env.ProgramState, groups ...string)

RegisterBuiltinGroups registers all builtins belonging to the named groups. Group names match the identifiers used in RegisterBuiltins (e.g. "base", "io", "http", "math"). Multiple groups may be passed; each is registered in order.

Example:

evaldo.RegisterBuiltinGroups(ps, "base", "io", "http")

func RegisterBuiltins

func RegisterBuiltins(ps *env.ProgramState)

RegisterBuiltins registers the full base set: pure-computation builtins plus all OS / IO builtins. This is what the CLI runner uses. For the full standard set including batteries, also call batteries.RegisterBatteries(ps).

func RegisterBuiltins2

func RegisterBuiltins2(builtins map[string]*env.Builtin, ps *env.ProgramState, name string)

func RegisterBuiltinsFilter added in v0.2.3

func RegisterBuiltinsFilter(ps *env.ProgramState, names []string)

RegisterBuiltinsFilter registers only the specific named builtins from the full builtin set. Each entry in names must be the plain word as it appears in Rye code (e.g. "add", "print", "http-get"). For context-namespaced groups (math, os, crypto, …) the word is still given without the context prefix; the function creates the child context automatically and places the word there.

Example:

evaldo.RegisterBuiltinsFilter(ps, []string{"add", "subtract", "print", "if", "fn", "either"})

func RegisterBuiltinsInContext added in v0.0.16

func RegisterBuiltinsInContext(builtins map[string]*env.Builtin, ps *env.ProgramState, name string) *env.RyeCtx

func RegisterBuiltinsInSubContext added in v0.0.23

func RegisterBuiltinsInSubContext(builtins map[string]*env.Builtin, ps *env.ProgramState, parent *env.RyeCtx, name string) *env.RyeCtx

func RegisterVarBuiltins added in v0.0.40

func RegisterVarBuiltins(ps *env.ProgramState)

func RegisterVarBuiltins2 added in v0.0.40

func RegisterVarBuiltins2(builtins map[string]*env.VarBuiltin, ps *env.ProgramState, name string)

func ReturnContextToPool added in v0.2.50

func ReturnContextToPool(fnCtx *env.RyeCtx, fromPool bool)

ReturnContextToPool is an exported wrapper around returnContextToPool, exposed for use by the batteries package.

func Rye0_CallBuiltin added in v0.0.36

func Rye0_CallBuiltin(bi env.Builtin, ps *env.ProgramState, arg0_ env.Object, toLeft bool, pipeSecond bool, firstVal env.Object) *env.ProgramState

Rye0_CallBuiltin calls a builtin function. Parameters:

  • bi: The builtin to call
  • ps: The program state
  • arg0_: The first argument (if any)
  • toLeft: Whether the call is to the left
  • pipeSecond: Whether this is a pipe second call
  • firstVal: The first value (if any)

Returns:

  • The updated program state

func Rye0_CallFunction added in v0.0.36

func Rye0_CallFunction(fn env.Function, ps *env.ProgramState, arg0 env.Object, toLeft bool, ctx *env.RyeCtx) *env.ProgramState

Rye0_CallFunction calls a function. Parameters:

  • fn: The function to call
  • ps: The program state
  • arg0: The first argument (if any)
  • toLeft: Whether the call is to the left
  • ctx: The context (if any)

Returns:

  • The updated program state

func Rye0_CallFunctionWithArgs added in v0.0.37

func Rye0_CallFunctionWithArgs(fn env.Function, ps *env.ProgramState, ctx *env.RyeCtx, args ...env.Object) *env.ProgramState

Rye0_CallFunctionWithArgs calls a function with the given arguments. This consolidates the functionality of Rye0_CallFunctionArgs2, Rye0_CallFunctionArgs4, and Rye0_CallFunctionArgsN. Parameters:

  • fn: The function to call
  • ps: The program state
  • ctx: The context (if any)
  • args: The arguments to pass to the function

Returns:

  • The updated program state

func Rye0_CallFunction_Optimized added in v0.0.80

func Rye0_CallFunction_Optimized(fn env.Function, ps *env.ProgramState, arg0 env.Object, toLeft bool, ctx *env.RyeCtx) *env.ProgramState

Modified version of Rye0_CallFunction that uses FastCallFunction for common cases

func Rye0_DetermineContext added in v0.0.36

func Rye0_DetermineContext(fn env.Function, ps *env.ProgramState, ctx *env.RyeCtx) *env.RyeCtx

Rye0_DetermineContext determines the appropriate context for a function call. Parameters:

  • fn: The function
  • ps: The program state
  • ctx: The context (if any)

Returns:

  • The determined context

func Rye0_EvalBlockInj added in v0.0.36

func Rye0_EvalBlockInj(ps *env.ProgramState, inj env.Object, injnow bool) *env.ProgramState

Rye0_EvalBlockInj evaluates a block with an optional injected value.

func Rye0_EvalExpressionInj added in v0.0.36

func Rye0_EvalExpressionInj(ps *env.ProgramState, inj env.Object, injnow bool) (*env.ProgramState, bool)

Rye0_EvalExpressionInj evaluates an expression with an optional injected value.

func Rye0_EvalExpression_CollectArg added in v0.0.90

func Rye0_EvalExpression_CollectArg(ps *env.ProgramState, limited bool) *env.ProgramState

Rye0_EvalExpression_CollectArg evaluates an expression with optional limitations.

func Rye0_EvalExpression_DispatchType added in v0.0.90

func Rye0_EvalExpression_DispatchType(ps *env.ProgramState) *env.ProgramState

Rye0_EvalExpression_DispatchType evaluates a concrete expression. This is the main part of the evaluator that handles all Rye value types.

func Rye0_EvalGenword added in v0.0.36

func Rye0_EvalGenword(ps *env.ProgramState, word env.Genword, leftVal env.Object, toLeft bool) *env.ProgramState

Rye0_EvalGenword evaluates a generic word.

func Rye0_EvalGetword added in v0.0.36

func Rye0_EvalGetword(ps *env.ProgramState, word env.Getword, leftVal env.Object, toLeft bool) *env.ProgramState

Rye0_EvalGetword evaluates a get-word.

func Rye0_EvalModword added in v0.0.36

func Rye0_EvalModword(ps *env.ProgramState, word env.Modword) *env.ProgramState

Rye0_EvalModword evaluates a mod-word.

func Rye0_EvalObject added in v0.0.36

func Rye0_EvalObject(ps *env.ProgramState, object env.Object, leftVal env.Object, toLeft bool, ctx *env.RyeCtx, pipeSecond bool, firstVal env.Object) *env.ProgramState

Rye0_EvalObject evaluates a Rye object.

func Rye0_EvalSetword added in v0.0.36

func Rye0_EvalSetword(ps *env.ProgramState, word env.Setword) *env.ProgramState

Rye0_EvalSetword evaluates a set-word.

func Rye0_EvalWord added in v0.0.36

func Rye0_EvalWord(ps *env.ProgramState, word env.Object, leftVal env.Object, toLeft bool, pipeSecond bool) *env.ProgramState

Rye0_EvalWord evaluates a word in the current context.

func Rye0_EvaluateBlock added in v0.0.37

func Rye0_EvaluateBlock(ps *env.ProgramState, block env.Block) *env.ProgramState

Rye0_EvaluateBlock handles the evaluation of a block object.

func Rye0_FastEvalBlock added in v0.0.43

func Rye0_FastEvalBlock(ps *env.ProgramState) *env.ProgramState

Rye0_FastEvalBlock evaluates a block of code using the fast evaluator

func Rye0_MaybeDisplayFailureOrError added in v0.0.36

func Rye0_MaybeDisplayFailureOrError(es *env.ProgramState, genv *env.Idxs, tag string)

Rye0_MaybeDisplayFailureOrError displays failure or error information if present. Parameters:

  • es: The program state
  • genv: The index environment
  • tag: A tag for the error message

func Rye0_MaybeDisplayFailureOrErrorWASM added in v0.0.36

func Rye0_MaybeDisplayFailureOrErrorWASM(es *env.ProgramState, genv *env.Idxs, printfn func(string), tag string)

Rye0_MaybeDisplayFailureOrErrorWASM displays failure or error information for WASM environment. Parameters:

  • es: The program state
  • genv: The index environment
  • printfn: The print function to use
  • tag: A tag for the error message

func Rye0_checkContextErrorHandler added in v0.0.36

func Rye0_checkContextErrorHandler(ps *env.ProgramState) bool

Rye0_checkContextErrorHandler checks if there is an error handler defined in the context. Parameters:

  • ps: The program state

Returns:

  • Whether an error handler was found and executed

func Rye0_checkErrorFlag added in v0.0.81

func Rye0_checkErrorFlag(ps *env.ProgramState) bool

Rye0_checkErrorFlag checks if there are error or return flags.

func Rye0_checkFlagsAfterExpression added in v0.0.81

func Rye0_checkFlagsAfterExpression(ps *env.ProgramState) bool

Rye00_checkFlagsAfterExpression checks if there are failure flags after evaluating a block.

func Rye0_checkForFailureWithBuiltin added in v0.0.81

func Rye0_checkForFailureWithBuiltin(bi env.Builtin, ps *env.ProgramState, n int) bool

Rye0_checkForFailureWithBuiltin checks if there are failure flags and handles them appropriately.

func Rye0_findCPathValue added in v0.0.37

func Rye0_findCPathValue(ps *env.ProgramState, word env.CPath) (bool, env.Object, *env.RyeCtx)

Rye0_findCPathValue handles the lookup of context path values.

func Rye0_findWordValue added in v0.0.36

func Rye0_findWordValue(ps *env.ProgramState, word1 env.Object) (bool, env.Object, *env.RyeCtx)

Rye0_findWordValue returns the value associated with a word in the current context. It also checks if the word refers to a builtin in a parent context, and if so, it can replace the word with the builtin directly in the series for faster future lookups.

func Rye00_CallBuiltin added in v0.0.81

func Rye00_CallBuiltin(bi env.Builtin, ps *env.ProgramState, arg0_ env.Object, toLeft bool, pipeSecond bool, firstVal env.Object)

Rye00_CallBuiltin calls a builtin function. Optimized version that focuses on performance.

func Rye00_EvalBlockInj added in v0.0.81

func Rye00_EvalBlockInj(ps *env.ProgramState, inj env.Object, injnow bool) *env.ProgramState

Rye00_EvalBlockInj evaluates a block with an optional injected value.

func Rye00_EvalExpression_DispatchType added in v0.0.90

func Rye00_EvalExpression_DispatchType(ps *env.ProgramState)

Rye00_EvalExpression_DispatchType evaluates a concrete expression. This is the main part of the evaluator that handles only integers and builtins.

func Rye00_EvalObject added in v0.0.81

func Rye00_EvalObject(ps *env.ProgramState, object env.Object, leftVal env.Object, toLeft bool, ctx *env.RyeCtx, pipeSecond bool, firstVal env.Object)

Rye00_EvalObject evaluates a Rye object. Simplified version that only handles builtins.

func Rye00_EvalWord added in v0.0.81

func Rye00_EvalWord(ps *env.ProgramState, word env.Object, leftVal env.Object, toLeft bool, pipeSecond bool)

Rye00_EvalWord evaluates a word in the current context. Simplified version that only handles builtins.

func Rye00_MaybeDisplayFailureOrError added in v0.0.81

func Rye00_MaybeDisplayFailureOrError(es *env.ProgramState, genv *env.Idxs, tag string)

Rye00_MaybeDisplayFailureOrError displays failure or error information if present.

func Rye00_checkFlagsAfterExpression added in v0.0.81

func Rye00_checkFlagsAfterExpression(ps *env.ProgramState) bool

Rye00_checkFlagsAfterExpression checks if there are failure flags after evaluating a block.

func Rye00_checkForFailureWithBuiltin added in v0.0.81

func Rye00_checkForFailureWithBuiltin(bi env.Builtin, ps *env.ProgramState, n int) bool

Rye00_checkForFailureWithBuiltin checks if there are failure flags and handles them appropriately.

func Rye00_findWordValue added in v0.0.81

func Rye00_findWordValue(ps *env.ProgramState, word1 env.Object) (bool, env.Object, *env.RyeCtx)

Rye00_findWordValue returns the value associated with a word in the current context. Simplified version that only looks for builtins.

func Trace added in v0.2.50

func Trace(s string)

Trace is an exported wrapper around trace, exposed for use by the batteries package.

func TriggerObservers added in v0.0.88

func TriggerObservers(ps *env.ProgramState, ctx *env.RyeCtx, wordIndex int, oldValue, newValue env.Object)

TriggerObservers triggers all observers watching a variable that has changed. Called from: EvalModword, OptionallyEvalExpressionRight (LModword case) Purpose: Notifies observers when a variable's value changes, executing their observer blocks

func TryHandleFailure added in v0.2.50

func TryHandleFailure(ps *env.ProgramState) bool

TryHandleFailure is an exported wrapper around tryHandleFailure, exposed for use by the batteries package.

Types

type Instruction added in v0.0.43

type Instruction func(vm *Rye0VM) int

Instruction is a function that executes a single instruction in the VM

func Rye0_CompileExpression added in v0.0.43

func Rye0_CompileExpression(ps *env.ProgramState) Instruction

Rye0_CompileExpression compiles a single expression into an Instruction

type PersistentCtxInterface added in v0.2.50

type PersistentCtxInterface interface {
	env.Context
}

PersistentCtxInterface is the interface evaldo's base builtins use to interact with a PersistentCtx without depending on its concrete type. The batteries package's PersistentCtx struct satisfies this interface.

type Program added in v0.0.43

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

Program represents a compiled Rye0 program

func Rye0_CompileBlock added in v0.0.43

func Rye0_CompileBlock(ps *env.ProgramState) *Program

Rye0_CompileBlock compiles a block of code into a Program

type Rye0VM added in v0.0.43

type Rye0VM struct {
	Sp int // Exported for use in benchmarks
	// contains filtered or unexported fields
}

Rye0VM represents a virtual machine for executing compiled Rye0 code

func NewRye0VM added in v0.0.43

func NewRye0VM(ctx *env.RyeCtx, pctx *env.RyeCtx, gen *env.Gen, idx *env.Idxs) *Rye0VM

NewRye0VM creates a new virtual machine for executing compiled Rye0 code

func (*Rye0VM) Execute added in v0.0.43

func (vm *Rye0VM) Execute(p *Program) (env.Object, error)

Execute executes a compiled program

func (*Rye0VM) Pop added in v0.0.43

func (vm *Rye0VM) Pop() env.Object

Pop pops a value from the stack

func (*Rye0VM) Push added in v0.0.43

func (vm *Rye0VM) Push(val env.Object)

Push pushes a value onto the stack

type RyeBlockCustomSort added in v0.0.34

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

Custom Sort object interface

func (RyeBlockCustomSort) Len added in v0.0.34

func (s RyeBlockCustomSort) Len() int

func (RyeBlockCustomSort) Less added in v0.0.34

func (s RyeBlockCustomSort) Less(i, j int) bool

func (RyeBlockCustomSort) Swap added in v0.0.34

func (s RyeBlockCustomSort) Swap(i, j int)

type RyeBlockSort

type RyeBlockSort []env.Object

Sort object interface

func (RyeBlockSort) Len

func (s RyeBlockSort) Len() int

func (RyeBlockSort) Less

func (s RyeBlockSort) Less(i, j int) bool

func (RyeBlockSort) Swap

func (s RyeBlockSort) Swap(i, j int)

type RyeListCustomSort added in v0.0.34

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

Custom Sort object interface

func (RyeListCustomSort) Len added in v0.0.34

func (s RyeListCustomSort) Len() int

func (RyeListCustomSort) Less added in v0.0.34

func (s RyeListCustomSort) Less(i, j int) bool

func (RyeListCustomSort) Swap added in v0.0.34

func (s RyeListCustomSort) Swap(i, j int)

type RyeListSort

type RyeListSort []any

Sort list interface

func (RyeListSort) Len

func (s RyeListSort) Len() int

func (RyeListSort) Less

func (s RyeListSort) Less(i, j int) bool

func (RyeListSort) Swap

func (s RyeListSort) Swap(i, j int)

type RyeStringSort added in v0.0.35

type RyeStringSort []rune

Sort list interface

func (RyeStringSort) Len added in v0.0.35

func (s RyeStringSort) Len() int

func (RyeStringSort) Less added in v0.0.35

func (s RyeStringSort) Less(i, j int) bool

func (RyeStringSort) Swap added in v0.0.35

func (s RyeStringSort) Swap(i, j int)

Jump to

Keyboard shortcuts

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