Documentation
¶
Index ¶
- Constants
- func ComputeMaxStack(instructions []byte) int
- type AssignmentMode
- type Compiler
- func (c *Compiler) Bytecode() *vm.Bytecode
- func (c *Compiler) Compile(node parser.Node) error
- func (c *Compiler) EnableFileImport(enable bool)
- func (c *Compiler) GetAssignmentMode() AssignmentMode
- func (c *Compiler) GetImportFileExt() []string
- func (c *Compiler) SetAssignmentMode(mode AssignmentMode)
- func (c *Compiler) SetImportDir(dir string)
- func (c *Compiler) SetImportFileExt(exts ...string) error
- type CompilerError
Constants ¶
const DefaultSourceFileExt = ".kvn"
DefaultSourceFileExt is the default extension used to resolve file imports.
Variables ¶
This section is empty.
Functions ¶
func ComputeMaxStack ¶
ComputeMaxStack returns the maximum operand-stack depth that the given bytecode instruction stream can reach during execution.
The analysis is a flow-sensitive worklist over the instruction stream that handles control flow precisely (unconditional jumps don't fall through; conditional jumps explore both arms at the correct height; unreachable code is skipped). It relies on the compiler invariant that all paths reaching the same instruction offset do so at equal stack heights. When that invariant holds, the analyzer returns the exact peak.
Pre-calculated result is used by the VM to size per-frame stack requirements precisely so that OpCall can guarantee the callee has enough room without an arbitrary safety margin.
LIMITATION: spread-call expansion (`f(arr...)`) is data-driven and grows the caller's operand stack by `len(arr)-1` slots at runtime. That growth is invisible to this static analysis. The VM bounds-checks the destination before expanding the spread and raises a recoverable stack-overflow error if it would exceed the global stack — see vm/vm.go OpCall/OpMethodCall.
Types ¶
type AssignmentMode ¶
type AssignmentMode int
AssignmentMode controls how plain '=' handles unresolved identifiers.
const ( // AssignmentModeSmart declares a variable in current scope for unresolved '=' assignments. AssignmentModeSmart AssignmentMode = iota // AssignmentModeStrict requires variables to already exist for '=' assignments. AssignmentModeStrict )
type Compiler ¶
type Compiler struct {
// contains filtered or unexported fields
}
Compiler compiles the AST into a bytecode.
func New ¶
func New( alloc *core.Arena, file *parser.SourceFile, symbolTable *vm.SymbolTable, constants []core.Value, modules vm.ModuleGetter, trace io.Writer, ) *Compiler
New creates a Compiler.
func (*Compiler) EnableFileImport ¶
EnableFileImport enables or disables module loading from local files. Local file modules are disabled by default.
func (*Compiler) GetAssignmentMode ¶
func (c *Compiler) GetAssignmentMode() AssignmentMode
GetAssignmentMode returns the active assignment mode.
func (*Compiler) GetImportFileExt ¶
GetImportFileExt returns the current list of extension name. These are the complementary suffix of the source file to search and load local module files.
func (*Compiler) SetAssignmentMode ¶
func (c *Compiler) SetAssignmentMode(mode AssignmentMode)
SetAssignmentMode sets how plain '=' handles unresolved identifiers.
func (*Compiler) SetImportDir ¶
SetImportDir sets the initial import directory path for file imports.
func (*Compiler) SetImportFileExt ¶
SetImportFileExt sets the extension name of the source file for loading local module files. Use this method if you want other source file extension than ".kvn". This function requires at least one argument, since it will replace the current list of extension name.
type CompilerError ¶
type CompilerError struct {
FileSet *parser.SourceFileSet
Node parser.Node
Err error
}
CompilerError represents a compiler error.
func (*CompilerError) Error ¶
func (e *CompilerError) Error() string