Documentation
¶
Index ¶
- type Compiler
- type ExecutableContent
- type ExecutableUnit
- func (exe *ExecutableUnit) GetCompiler() Compiler
- func (exe *ExecutableUnit) GetContent() ExecutableContent
- func (exe *ExecutableUnit) GetCreatedAt() time.Time
- func (exe *ExecutableUnit) GetDataProvider() data.Provider
- func (exe *ExecutableUnit) GetID() string
- func (exe *ExecutableUnit) GetLoader() loader.Loader
- func (exe *ExecutableUnit) GetMachineType() machineTypes.Type
- func (exe *ExecutableUnit) String() string
- type MockCompiler
- type MockExecutableContent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Compiler ¶
type Compiler interface { // Compile checks if a script is valid and returns it as executable content. // The returned ExecutableContent contains the validated and possibly compiled // script ready for execution. // // Parameters: // - script: A pointer to the script content string // // Returns: // - ExecutableContent: The validated script // - error: Details about validation failures (syntax errors, undefined globals) Compile(scriptReader io.ReadCloser) (ExecutableContent, error) }
Compiler defines the interface for validating scripts before execution. It checks syntax and semantics, and may perform parsing, compilation, and optimization. A valid script is returned as ExecutableContent.
Example usage:
var comp Compiler = NewRisorCompiler(globals) executableContent, err := comp.Compile(&scriptContent) if err != nil { // Handle validation error } // Use executableContent for execution
type ExecutableContent ¶
type ExecutableContent interface { // GetSource returns the original script content as a string. // This is the source code before any compilation or execution. GetSource() string // GetByteCode returns the compiled bytecode of the script in a runtime-specific format. // This bytecode object is asserted into the type the target engine requires. If the // target engine is unable to assert the bytecode into the correct type, it will return // an error at runtime, so the engine type and ByteCode must be compatible. GetByteCode() any // GetMachineType returns the engine type this script is intended to run on. GetMachineType() machineTypes.Type }
ExecutableContent represents validated script content that is ready for execution or compilation. It provides access to the script's source code and its compiled bytecode. Implementations like [`risor.Executable`](../../engines/risor/compiler/executable.go) store the script content and the compiled bytecode for execution.
type ExecutableUnit ¶
type ExecutableUnit struct { // ID is a unique identifier for this executable unit, typically derived from a hash of the script content. ID string // CreatedAt records when this executable unit was instantiated. CreatedAt time.Time // ScriptLoader loads the script content to local memory from various places (file, string, etc.). ScriptLoader loader.Loader // Compiler is the script language-specific compiler that was used to compile this unit. Compiler Compiler // Content holds the compiled bytecode and source representation of the script. Content ExecutableContent // DataProvider provides access to both static compile-time data and variable runtime data // during script evaluation. Enabling the "compile once, run many times" design. // When created with NewExecutableUnit, this is typically a CompositeProvider containing // a StaticProvider (for compile-time data) and another provider (for runtime data). DataProvider data.Provider // contains filtered or unexported fields }
ExecutableUnit represents a specific version of a script, including its content and creation time. It holds the compiled script content and provides access to evaluation facilities.
func NewExecutableUnit ¶
func NewExecutableUnit( handler slog.Handler, versionID string, scriptLoader loader.Loader, compiler Compiler, dataProvider data.Provider, ) (*ExecutableUnit, error)
NewExecutableUnit creates a new ExecutableUnit from the provided loader and compiler. The dataProvider parameter provides runtime data for script evaluation.
func (*ExecutableUnit) GetCompiler ¶
func (exe *ExecutableUnit) GetCompiler() Compiler
GetCompiler returns the compiler used to validate the script and convert it into runnable bytecode.
func (*ExecutableUnit) GetContent ¶
func (exe *ExecutableUnit) GetContent() ExecutableContent
GetContent returns the validated & compiled script content as ExecutableContent
func (*ExecutableUnit) GetCreatedAt ¶
func (exe *ExecutableUnit) GetCreatedAt() time.Time
CreatedAt returns the timestamp when the version was created.
func (*ExecutableUnit) GetDataProvider ¶
func (exe *ExecutableUnit) GetDataProvider() data.Provider
GetDataProvider returns the data provider for this executable unit.
func (*ExecutableUnit) GetID ¶
func (exe *ExecutableUnit) GetID() string
GetID returns the unique identifier (version number, or name) for this script version.
func (*ExecutableUnit) GetLoader ¶
func (exe *ExecutableUnit) GetLoader() loader.Loader
GetLoader returns the loader used to load the script.
func (*ExecutableUnit) GetMachineType ¶
func (exe *ExecutableUnit) GetMachineType() machineTypes.Type
GetMachineType returns the machine type this script is intended to run on.
func (*ExecutableUnit) String ¶
func (exe *ExecutableUnit) String() string
type MockCompiler ¶
MockCompiler is a mock implementation of the Compiler interface.
func (*MockCompiler) Compile ¶
func (m *MockCompiler) Compile(scriptReader io.ReadCloser) (ExecutableContent, error)
Compile mocks the Compile method of the Compiler interface.
type MockExecutableContent ¶
MockExecutableContent is a mock implementation of the ExecutableContent interface for testing.
func (*MockExecutableContent) GetByteCode ¶
func (m *MockExecutableContent) GetByteCode() any
func (*MockExecutableContent) GetMachineType ¶
func (m *MockExecutableContent) GetMachineType() machineTypes.Type
func (*MockExecutableContent) GetSource ¶
func (m *MockExecutableContent) GetSource() string
Directories
¶
Path | Synopsis |
---|---|
Package loader provides implementations of the Loader interface for various source types.
|
Package loader provides implementations of the Loader interface for various source types. |
httpauth
Package httpauth provides authentication strategies for HTTP requests in go-polyscript.
|
Package httpauth provides authentication strategies for HTTP requests in go-polyscript. |