Documentation
¶
Overview ¶
Package eval provides evaluation and environment primitives.
Evaluation (R7RS 6.12) ¶
- eval: evaluate expression in given environment
- load: read and evaluate file contents
- current-load-path, current-load-directory, current-load-depth
Environments ¶
- environment: create environment from import sets
- null-environment: create minimal R5RS environment
- scheme-report-environment: create R5RS environment
Expansion and compilation ¶
- expand, expand-once: macro-expand a syntax object or datum
- compile: compile an expression to a callable thunk
- syntax-local-value, syntax-local-value/immediate
- make-compile-time-value
- syntax-local-introduce, syntax-local-identifier-as-binding
Use Extension or AddToRegistry to register all primitives.
Index ¶
- Variables
- func PrimCompile(mc machine.CallContext) error
- func PrimCurrentLoadDepth(mc machine.CallContext) error
- func PrimCurrentLoadDirectory(mc machine.CallContext) error
- func PrimCurrentLoadPath(mc machine.CallContext) error
- func PrimEnvironment(mc machine.CallContext) error
- func PrimEval(cc machine.CallContext) error
- func PrimExpand(cc machine.CallContext) error
- func PrimExpandOnce(cc machine.CallContext) error
- func PrimLoad(cc machine.CallContext) error
- func PrimMakeCompileTimeValue(mc machine.CallContext) error
- func PrimNullEnvironment(mc machine.CallContext) error
- func PrimSchemeReportEnvironment(mc machine.CallContext) error
- func PrimSyntaxLocalIdentifierAsBinding(cc machine.CallContext) error
- func PrimSyntaxLocalIntroduce(cc machine.CallContext) error
- func PrimSyntaxLocalValue(cc machine.CallContext) error
- func PrimSyntaxLocalValueImmediate(mc machine.CallContext) error
Constants ¶
This section is empty.
Variables ¶
var AddToRegistry = Builder.AddToRegistry
AddToRegistry registers all eval primitives.
var Builder = registry.NewRegistryBuilder(addPrimitives)
Builder aggregates all eval registration functions.
var ErrWileProfilesNotRegistered = werr.NewStaticError("wile profiles not registered")
ErrWileProfilesNotRegistered is returned when tryWileProfile dispatches on a (wile <name>) spec but no ProfileFactory has been registered.
var Extension = registry.NewDescribedExtension("eval", "Code evaluation: eval, load, environment constructors, expand/expand-once, compile, syntax-local operations.", AddToRegistry)
Extension is the eval extension.
var ProfileFactory func(ctx context.Context, callerNS *environment.Namespace, profileName, strictName string) (*environment.Namespace, error)
ProfileFactory is the callback used by (environment '(wile <name>)) and (environment '(wile <name> <strictness>)) to construct a namespace for a named Wile profile. It is set by internal/bootstrap at init time (bootstrap cannot be imported here because bootstrap already imports this package). When nil, (wile <name>) specs return ErrWileProfilesNotRegistered.
Both names cross as raw spellings and are validated on the far side: this package cannot name bootstrap's profile or strictness types, and splitting the validation would put half the vocabulary in each package. strictName is "" when the spec omitted it.
Functions ¶
func PrimCompile ¶
func PrimCompile(mc machine.CallContext) error
PrimCompile implements the (compile) primitive. Compiles an expression and returns a zero-argument procedure (thunk) that, when called, executes the compiled code.
(compile expr) -> procedure
The expr can be either a syntax object or a datum (which will be converted to a syntax object automatically).
This is the final phase hook, completing the pipeline:
expand -> compile -> (execute via calling the returned thunk)
func PrimCurrentLoadDepth ¶
func PrimCurrentLoadDepth(mc machine.CallContext) error
PrimCurrentLoadDepth implements the (current-load-depth) primitive. Returns the current load stack depth (number of nested loads). Returns 0 when not inside a load call.
func PrimCurrentLoadDirectory ¶
func PrimCurrentLoadDirectory(mc machine.CallContext) error
PrimCurrentLoadDirectory implements the (current-load-directory) primitive. Returns the directory of the file currently being loaded, or #f if no file is being loaded (e.g., REPL).
func PrimCurrentLoadPath ¶
func PrimCurrentLoadPath(mc machine.CallContext) error
PrimCurrentLoadPath implements the (current-load-path) primitive. Returns the path of the file currently being loaded, or #f if no file is being loaded (e.g., REPL).
func PrimEnvironment ¶
func PrimEnvironment(mc machine.CallContext) error
PrimEnvironment implements the (environment) primitive. Constructs a new environment from import specifiers.
Supports Racket-style phased imports:
- (environment '(scheme base)) ; Phase 0 (runtime)
- (environment '(for-syntax (scheme base))) ; Phase 1 (expand)
- (environment '(for-template (scheme base))) ; Phase -1
- (environment '(for-meta 2 (scheme base))) ; Phase 2
func PrimEval ¶
func PrimEval(cc machine.CallContext) error
PrimEval implements the (eval) primitive. 1-arg form: (eval expr) — uses current namespace (interaction-environment). 2-arg form: (eval expr env) — uses the given environment.
With ParamCount: 1 and IsVariadic: true, all args arrive as a rest list in mc.Arg(0).
func PrimExpand ¶
func PrimExpand(cc machine.CallContext) error
PrimExpand implements the expand primitive. Fully expands a syntax object and returns the expanded syntax. (expand stx) -> expanded-stx
func PrimExpandOnce ¶
func PrimExpandOnce(cc machine.CallContext) error
PrimExpandOnce implements the expand-once primitive. Performs a single step of macro expansion and returns both the expanded syntax and a boolean indicating whether expansion occurred. (expand-once stx) -> (values expanded-stx did-expand?)
func PrimLoad ¶
func PrimLoad(cc machine.CallContext) error
PrimLoad implements the (load) primitive. Loads and evaluates a Scheme source file.
File resolution uses the same FileResolver as include, so load and include share the same search path priority:
current load directory > LibraryRegistry > SCHEME_INCLUDE_PATH > CWD
The current load directory comes from the per-load-chain stack carried on the context, so concurrent loads on separate threads resolve independently.
func PrimMakeCompileTimeValue ¶
func PrimMakeCompileTimeValue(mc machine.CallContext) error
PrimMakeCompileTimeValue implements the make-compile-time-value primitive. Wraps a value for compile-time storage. (make-compile-time-value value) -> compile-time-value
This creates a CompileTimeValue wrapper around the given value. CompileTimeValue is used to distinguish regular runtime values from values that should be stored in the expand phase and accessed during macro expansion.
When syntax-local-value retrieves a CompileTimeValue, it automatically unwraps it to return the underlying value.
func PrimNullEnvironment ¶
func PrimNullEnvironment(mc machine.CallContext) error
PrimNullEnvironment implements the null-environment primitive. Returns an empty R5RS environment with no bindings.
func PrimSchemeReportEnvironment ¶
func PrimSchemeReportEnvironment(mc machine.CallContext) error
PrimSchemeReportEnvironment implements the (scheme-report-environment) primitive. Returns R5RS env.
func PrimSyntaxLocalIdentifierAsBinding ¶
func PrimSyntaxLocalIdentifierAsBinding(cc machine.CallContext) error
PrimSyntaxLocalIdentifierAsBinding implements the syntax-local-identifier-as-binding primitive. Marks an identifier as a binding site by adding the use-site scope. (syntax-local-identifier-as-binding id) -> id
This primitive adds the "use-site scope" to an identifier, marking it as a binding site. This is used in binding forms (like let, lambda) to ensure proper hygiene when the binding form is implemented as a macro.
When a macro introduces a binding form, the bound identifiers need the use-site scope to be properly distinguished from identifiers at the macro's definition site.
Use cases:
- Implementing custom binding forms as macros
- Ensuring proper hygiene for macro-generated bindings
- Creating hygienic versions of anaphoric macros
This primitive can only be called during macro expansion (when an ExpanderContext is set on the MachineContext with a use-site scope).
func PrimSyntaxLocalIntroduce ¶
func PrimSyntaxLocalIntroduce(cc machine.CallContext) error
PrimSyntaxLocalIntroduce implements the syntax-local-introduce primitive. (syntax-local-introduce stx) -> error
NOT IMPLEMENTED: this primitive is registered and callable but always fails with werr.ErrNotImplemented. The scope-flipping branch below is unreachable because ExpanderContext.IntroductionScope() is never set — see the comment at the nil check for why wiring it is not a one-liner.
It is kept registered, rather than deleted, so that a program calling it gets a diagnosis instead of an unbound-variable error, and so the intended semantics stay documented in one place:
Flipping the "introduction scope" on a syntax object makes a macro-introduced identifier behave as if it came from the macro use site (or vice versa) — the mechanism behind anaphoric macros, use-site-visible bindings, and syntax-parameterize.
func PrimSyntaxLocalValue ¶
func PrimSyntaxLocalValue(cc machine.CallContext) error
PrimSyntaxLocalValue implements the syntax-local-value primitive. Retrieves the compile-time value bound to an identifier in the expand phase. (syntax-local-value id) -> value
This primitive can only be called during macro expansion (when an ExpanderContext is set on the MachineContext). It looks up the identifier in the expand phase environment, respecting hygiene scopes.
If the binding is a CompileTimeValue, it returns the unwrapped value. This allows define-for-syntax bindings to be accessed from macro transformers.
func PrimSyntaxLocalValueImmediate ¶
func PrimSyntaxLocalValueImmediate(mc machine.CallContext) error
PrimSyntaxLocalValueImmediate implements (syntax-local-value/immediate id). Like syntax-local-value but does not chase rename-transformer chains. Wile does not currently have rename-transformers, so this behaves identically to syntax-local-value.
When rename-transformers are implemented, this function must NOT chase the transformer chain — it should return the transformer object directly. At that point, PrimSyntaxLocalValue and PrimSyntaxLocalValueImmediate must diverge.
Racket §12.4: syntax-local-value/immediate
Types ¶
This section is empty.