context

package
v0.0.0-...-2cdba53 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Universe = NewUniverse()

Functions

This section is empty.

Types

type Block

type Block struct {
	Outer   *Block         // The block enclosing this one
	Inner   *Block         // The nested block currently being compiled, or nil.
	Scope   *Scope         // The Scope containing this block.
	Defs    map[string]Def // The Variables, Constants, and Types defined in this block.
	Global  bool           // If Global, do not allocate new vars and consts in the frame;
	NumVars int            // The number of variables defined in this block.
	// contains filtered or unexported fields
}

Block represents a definition context in which a name may not be defined more than once.

The variables offset must be greater than the index of any variable defined in any parent of this block within the same Scope at the time this block is entered.

Global blocks assume that the refs will be compiled in using defs[name].Init.

func (*Block) DefineConst

func (b *Block) DefineConst(name string, pos token.Pos, t vm.Type, v vm.Value) (*Constant, Def)

DefineConst creates a new constant definition.

func (*Block) DefinePackage

func (b *Block) DefinePackage(id, path string, pos token.Pos) (*PkgIdent, Def)

DefinePackage defines a package import in the block.

func (*Block) DefineTemp

func (b *Block) DefineTemp(t vm.Type) *Variable

DefineTemp allocates a anonymous slot in the current scope.

func (*Block) DefineType

func (b *Block) DefineType(name string, pos token.Pos, t vm.Type) vm.Type

DefineType creates a user defined type.

func (*Block) DefineVar

func (b *Block) DefineVar(name string, pos token.Pos, t vm.Type) (*Variable, Def)

DefineVar creates a new variable definition and allocate it in the current scope, or returns the existing definition if the symbol was already defined.

func (*Block) EnterChild

func (b *Block) EnterChild() *Block

EnterChild creates a new block with this one as parent, using the same scope.

func (*Block) EnterChildScope

func (b *Block) EnterChildScope() *Scope

EnterChildScope creates a new block with this one as parent, using a new scope.

func (*Block) Exit

func (b *Block) Exit()

Exit closes this block in it's parent.

func (*Block) Lookup

func (b *Block) Lookup(name string) (bl *Block, level int, def Def)

Lookup search for the definition of the specified symbol by marching up the blocks tree until either the symbol is found, or the scope root is reached.

func (*Block) Undefine

func (b *Block) Undefine(name string)

Undefine removes a symbol definition from this block.

type Constant

type Constant struct {
	ConstPos token.Pos //
	Type     vm.Type   // Static type of this constant
	Value    vm.Value  //
}

func (*Constant) Pos

func (c *Constant) Pos() token.Pos

type Def

type Def interface {
	// Pos returns the position of the definition in the source code
	Pos() token.Pos
}

Def is a definition of a *Variable, *Constant, or Type.

type PkgIdent

type PkgIdent struct {
	PkgPos token.Pos

	Scope *Scope // the scope holding the package definition(s)
	// contains filtered or unexported fields
}

func (*PkgIdent) Pos

func (p *PkgIdent) Pos() token.Pos

type Scope

type Scope struct {
	// The root block of this scope.
	*Block

	// The maximum number of variables required at any point in this Scope.
	// This determines the number of slots needed in the Frame created from this Scope at run-time.
	MaxVars int
}

Scope is the compile-time analogue of a Frame, which captures some subtree of blocks.

func (*Scope) NewFrame

func (s *Scope) NewFrame(outerFrame *vm.Frame) *vm.Frame

NewFrame creates a new child frame to the one specified, with the number of variable slots needed by the current scope.

type UniverseScope

type UniverseScope struct {
	*Scope
	Pkgs map[string]*Scope // a lookup-table for easy retrieval of packages by their "path"
}

UniverseScope contains the global scope for the whole vm.

func NewUniverse

func NewUniverse() *UniverseScope

The universal scope

type Variable

type Variable struct {
	VarPos token.Pos

	// Index of this variable in the Frame
	Index int

	// Static type of this variable
	Type vm.Type

	// Value of this variable.
	// This is only used by Scope.NewFrame; therefore, it is useful for Global scopes
	// but cannot be used in function scopes.
	Init vm.Value
}

func (*Variable) Pos

func (v *Variable) Pos() token.Pos

Jump to

Keyboard shortcuts

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