repl

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package repl provides the Effects Inspector for introspecting types and effects.

Package repl provides planning commands for the REPL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateExamplePlan

func CreateExamplePlan() (string, error)

CreateExamplePlan creates an example plan and returns it as JSON

func EffectsCommand

func EffectsCommand(input string) error

EffectsCommand implements the :effects REPL command For now, this is a placeholder that will be implemented once we have proper effect tracking in the type system

func ParseProposeCommand

func ParseProposeCommand(input string) (string, error)

ParseProposeCommand parses the :propose command arguments Format: :propose <filename.json>

func ParseScaffoldCommand

func ParseScaffoldCommand(input string) (planFile, outputDir string, overwrite bool, err error)

ParseScaffoldCommand parses the :scaffold command arguments Format: :scaffold --from-plan <plan.json> [--output <dir>] [--overwrite]

func PrintPlanHelp

func PrintPlanHelp()

PrintPlanHelp prints help text for planning commands

func ProposePlanCommand

func ProposePlanCommand(filename string) error

ProposePlanCommand validates a plan file and prints the result

func SaveExamplePlan

func SaveExamplePlan(filename string) error

SaveExamplePlan saves an example plan to a file

func ScaffoldCommand

func ScaffoldCommand(planFile, outputDir string, overwrite bool) error

ScaffoldCommand generates code from a plan file

func ValidatePlanJSON

func ValidatePlanJSON(jsonData []byte) error

ValidatePlanJSON validates raw JSON against the plan schema

Types

type CachedConstructor

type CachedConstructor struct {
	TypeName       string
	CtorName       string
	Arity          int
	TypeParamCount int
	TypeParamNames []string
	FieldTypes     []types.Type
}

CachedConstructor stores constructor info for cross-module import resolution

type Config

type Config struct {
	TraceDefaulting  bool
	ShowCore         bool
	ShowTyped        bool
	DryLink          bool
	Verbose          bool
	StrictSyntaxMode bool
	ImportedModules  []string
}

Config holds REPL configuration

type EffectsResult

type EffectsResult struct {
	Schema    string   `json:"schema"`
	Type      string   `json:"type"`
	Effects   []string `json:"effects"`
	Decisions []any    `json:"decisions,omitempty"` // from ledger slice when defaulting occurs
}

EffectsResult represents the result of effects introspection

type Export

type Export struct {
	Name   string        // Export name
	Value  interface{}   // Evaluated value (closure, constant, etc.)
	Scheme *types.Scheme // Type signature for type checking
}

Export represents a single exported function or value from a module.

type ModuleRegistry

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

ModuleRegistry stores compiled modules for REPL access. It enables loading AILANG modules in the browser via ailangLoadModule() and makes their exports available for subsequent ailangEval() calls.

func NewModuleRegistry

func NewModuleRegistry() *ModuleRegistry

NewModuleRegistry creates an empty module registry.

func (*ModuleRegistry) CallExport

func (mr *ModuleRegistry) CallExport(moduleName, funcName string, args []eval.Value) (string, error)

CallExport formats a function call expression string for use with the REPL. This returns the expression that can be evaluated via ProcessExpression. Arguments are converted to their AILANG string representation.

func (*ModuleRegistry) GetExport

func (mr *ModuleRegistry) GetExport(moduleName, funcName string) (*Export, error)

GetExport retrieves a specific export from a loaded module.

func (*ModuleRegistry) GetModule

func (mr *ModuleRegistry) GetModule(name string) (*RegisteredModule, bool)

GetModule retrieves a loaded module by name.

func (*ModuleRegistry) InvokeExport

func (mr *ModuleRegistry) InvokeExport(moduleName, funcName string, args []eval.Value) (eval.Value, error)

InvokeExport calls an exported function directly with the provided arguments. This method bypasses REPL string evaluation and calls the function closure directly, ensuring that captured imports (like decode, encode from std/json) are properly resolved from the function's environment.

Returns the result value and any error that occurred during execution.

func (*ModuleRegistry) ListModules

func (mr *ModuleRegistry) ListModules() []string

ListModules returns the names of all loaded modules.

func (*ModuleRegistry) LoadModule

func (mr *ModuleRegistry) LoadModule(name, sourceCode string) ([]string, error)

LoadModule compiles and registers a module from source code. Returns the list of exported names on success.

func (*ModuleRegistry) SetEffContext

func (mr *ModuleRegistry) SetEffContext(ctx *effects.EffContext)

SetEffContext sets the shared effect context used by InvokeExport. This allows WASM-configured effect handlers (AI, IO, etc.) to be available when calling module exports.

type REPL

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

REPL represents the Read-Eval-Print Loop

func New

func New() *REPL

New creates a new REPL instance

func NewWithVersion

func NewWithVersion(version, buildTime string) *REPL

NewWithVersion creates a new REPL with version info

func (*REPL) ApplyClosure

func (r *REPL) ApplyClosure(fn eval.Value, args []eval.Value) (eval.Value, error)

ApplyClosure invokes an AILANG closure (FunctionValue) with the given arguments. For multi-arg closures, it applies arguments one at a time (curried application). This is used by the WASM bridge to invoke AILANG callbacks from JavaScript.

M-WASM-CLOSURE-ENV: When the REPL has a ModuleRegistry, ApplyClosure creates an evaluator with a RegistryResolver so that cross-module VarGlobal references (imported functions) resolve correctly. Without this, only same-module Var references work (via the closure's captured env chain).

func (*REPL) EnableTrace

func (r *REPL) EnableTrace()

EnableTrace enables execution tracing

func (*REPL) GetEffContext

func (r *REPL) GetEffContext() *effects.EffContext

GetEffContext returns the effect context for external configuration (used by WASM)

func (*REPL) GetRegistry

func (r *REPL) GetRegistry() *ModuleRegistry

GetRegistry returns the module registry (nil if not set)

func (*REPL) GrantCapability

func (r *REPL) GrantCapability(name string)

GrantCapability grants a named capability to the effect context

func (*REPL) HandleCommand

func (r *REPL) HandleCommand(cmd string, out io.Writer)

HandleCommand processes REPL commands (exported for WASM)

func (*REPL) ProcessExpression

func (r *REPL) ProcessExpression(input string, out io.Writer)

ProcessExpression runs an expression through the full pipeline (exported for WASM)

func (*REPL) SetAIHandler

func (r *REPL) SetAIHandler(handler effects.AIHandler)

SetAIHandler configures the AI effect handler and grants the AI capability

func (*REPL) SetRegistry

func (r *REPL) SetRegistry(reg *ModuleRegistry)

SetRegistry sets the module registry for import resolution (used by WASM)

func (*REPL) SetStrictSyntaxMode

func (r *REPL) SetStrictSyntaxMode(strict bool)

SetStrictSyntaxMode enables or disables strict syntax mode

func (*REPL) Start

func (r *REPL) Start(in io.Reader, out io.Writer)

Start begins the REPL session (backward compatible wrapper)

func (*REPL) StartWithContext

func (r *REPL) StartWithContext(ctx context.Context, in io.Reader, out io.Writer)

StartWithContext begins the REPL session with OpenTelemetry context

type RegisteredModule

type RegisteredModule struct {
	Name    string             // Module name (e.g., "invoice_processor")
	Source  string             // Original source code
	Exports map[string]*Export // Exported functions and values
}

RegisteredModule represents a compiled and evaluated AILANG module.

type RegistryResolver

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

RegistryResolver resolves global references for module evaluation in WASM. It resolves: 1. Builtin functions ($builtin module or names starting with _) 2. ADT constructor factories ($adt module) 3. Exports from previously loaded modules

func NewRegistryResolver

func NewRegistryResolver(registry *ModuleRegistry, builtins *runtime.BuiltinRegistry) *RegistryResolver

NewRegistryResolver creates a resolver that can access the module registry

func (*RegistryResolver) ResolveValue

func (r *RegistryResolver) ResolveValue(ref core.GlobalRef) (eval.Value, error)

ResolveValue resolves a global reference to a runtime value

Jump to

Keyboard shortcuts

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