Documentation
¶
Overview ¶
Package forms provides a unified registry for special form handlers.
The package maps Scheme keywords (if, lambda, define, etc.) to their validation and compilation functions. This decouples the validate and machine packages by providing a shared dispatch table.
Registration ¶
forms.RegisterValidator("if", validateIf)
forms.RegisterCompiler("if", compileIf)
Lookup ¶
spec := forms.Lookup("if")
if spec != nil && spec.Validate != nil {
result := spec.Validate(ctx, env, pair, validationResult)
}
The registry uses [any] for function parameter types to break circular import cycles. Type safety is enforced at call sites via runtime assertions.
Package forms provides a unified registry for special form handlers. It maps keywords to their validation and compilation functions, allowing both the validate and machine packages to share the same dispatch table.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
func Register(spec *FormSpec)
Register adds a FormSpec to the registry. If a spec with the same name exists, it is replaced.
func RegisterCompiler ¶
func RegisterCompiler(name string, fn CompilerFunc)
RegisterCompiler sets the compiler for an existing form or creates a new entry.
func RegisterValidator ¶
func RegisterValidator(name string, fn ValidatorFunc)
RegisterValidator sets the validator for an existing form or creates a new entry.
Types ¶
type CompilerFunc ¶
CompilerFunc is the signature for compilation functions. Parameters:
- ctc: *machine.CompileTimeContinuation - compiler state
- ctctx: machine.CompileTimeCallContext - call context
- expr: validate.ValidatedExpr - the validated expression
Returns: error
type FormSpec ¶
type FormSpec struct {
// Name is the keyword that triggers this form (e.g., "if", "lambda").
Name string
// Validate is called during the validation phase to produce a ValidatedExpr.
// If nil, the form passes through as ValidatedLiteral.
Validate ValidatorFunc
// Compile is called during compilation to emit bytecode.
// If nil, the form cannot be compiled (error).
Compile CompilerFunc
}
FormSpec defines how a special form is validated and compiled.
type ValidatorFunc ¶
ValidatorFunc is the signature for validation functions. Parameters:
- ctx: context for cancellation
- env: *environment.EnvironmentFrame - for checking local variable shadowing
- pair: *syntax.SyntaxPair - the form to validate
- result: *validate.ValidationResult - collects errors
Returns: validate.ValidatedExpr