compiler

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: Apache-2.0 Imports: 7 Imported by: 10

Documentation

Overview

Package compiler is used to compile an Abstract Syntax Tree (AST) into its corresponding bytecode.

Index

Constants

View Source
const (
	// MaxArgs is the maximum number of arguments a function can have.
	MaxArgs = 255

	// Placeholder is a temporary value written during compilation, which is
	// always replaced before compilation is complete.
	Placeholder = uint16(math.MaxUint16)
)

Variables

This section is empty.

Functions

func Compile

func Compile(node ast.Node, options ...Option) (*object.Code, error)

Compile the given AST node and return the compiled code object. This is a shorthand for compiler.New(options).Compile(node).

func MakeInstruction

func MakeInstruction(opcode op.Code, operands ...uint16) []op.Code

Types

type Compiler

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

Compiler is used to compile Risor AST into its corresponding bytecode. This implements the ICompiler interface.

func New

func New(options ...Option) (*Compiler, error)

New creates and returns a new Compiler. Any supplied options are used to configure the compilation process.

func (*Compiler) Compile

func (c *Compiler) Compile(node ast.Node) (*object.Code, error)

Compile the given AST node and return the compiled code object.

func (*Compiler) CurrentInstructions

func (c *Compiler) CurrentInstructions() []op.Code

CurrentInstructions returns the compiled instructions for the code that is currently being compiled. This may be the main code object, or it may be a function that is being compiled.

func (*Compiler) MainInstructions

func (c *Compiler) MainInstructions() []op.Code

MainInstructions returns the compiled instructions for the main code object.

type Option

type Option func(*Compiler)

Option is a configuration function for a Compiler.

func WithBuiltins

func WithBuiltins(builtins map[string]object.Object) Option

WithBuiltins configures the compiler with the given built-in objects.

func WithCode

func WithCode(code *object.Code) Option

WithCode configures the compiler to compile into the given code object.

Jump to

Keyboard shortcuts

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