compiler

package
v0.0.0-...-02c006d Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteCode

type ByteCode struct {
	Instructions []code.Instruction
	ObjectPool   []object.Object
}

representa el bytecode para la vm

type CompiledFrame

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

Para gestionar los ámbitos de compilación

type Compiler

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

Compiler se encarga de recorrer el AST y emitir el bytecode

func New

func New() *Compiler

Creamos una instancia del compilador

func NewWithState

func NewWithState(s *SymbolTable, objectPool []object.Object) *Compiler

Crea un nuevo Compiler pero con SymbolTable

func (*Compiler) Compile

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

compilador

func (*Compiler) GetByteCode

func (c *Compiler) GetByteCode() *ByteCode

Genera y devuelve el objeto Bytecode final.

func (*Compiler) GetInstructions

func (c *Compiler) GetInstructions() []code.Instruction

Delvuelve el conjunto de instrucciones

func (*Compiler) PrintInstructions

func (c *Compiler) PrintInstructions(instructions []code.Instruction) string

*************************INICIO DEBUG***********************

type Symbol

type Symbol struct {
	Name  string
	Scope SymbolScope
	Index int
}

contiene la información necesaria acerca del símbolo que el compilador se encuentre.

type SymbolScope

type SymbolScope string

Alias para el tipo de alcance el valor no es muy importante siempre y cuando sea único porque necesitaremos diferenciar entre distintos ámbitos. es mejor usar int pero string nos ayuda para el debug.

const (
	LocalScope   SymbolScope = "LOCAL"
	GlobalScope  SymbolScope = "GLOBAL"
	BuiltinScope SymbolScope = "BUILTIN"
	FreeScope    SymbolScope = "FREE"
)

Lista de ámbitos

type SymbolTable

type SymbolTable struct {
	Outer *SymbolTable

	FreeSymbols []Symbol
	// contains filtered or unexported fields
}

asocia keys con símbolos y mantiene rastro de su definición numérica. Las keys son realmente los nombres literales del identificador.

func NewEnclosedSymbolTable

func NewEnclosedSymbolTable(outer *SymbolTable) *SymbolTable

func NewSymbolTable

func NewSymbolTable() *SymbolTable

Crea una tabla de símbolos

func (*SymbolTable) Define

func (s *SymbolTable) Define(name string) Symbol

define un símbolo

func (*SymbolTable) DefineBuiltin

func (s *SymbolTable) DefineBuiltin(index int, name string) Symbol

define un builtin

func (*SymbolTable) Resolve

func (s *SymbolTable) Resolve(name string) (Symbol, bool)

resuelve un símbolo

Jump to

Keyboard shortcuts

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