scope

package
v0.0.0-...-1d296a1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package scope defines helpers and operators for Arbor's Compiler Scope

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Scope

type Scope map[string]*SymbolData

Scope Represents the current scope in the language

type SymbolData

type SymbolData struct {
	// Type is the type of the node
	Type TypeData
	// Location is where the symbol is stored in the program
	Location string
	// Lexeme is the lexeme where this type was defined
	Lexeme lexer.Lexeme
	// IsConstant denotes if this symbol can be reassigned
	IsConstant bool
	// Methods are the methods on the type
	Methods map[string][]*types.FnType
	// The Constructors of the Type
	Constructors []*types.FnType
	// IsType is weather this symbol is a type
	IsType bool
}

SymbolData is the data related to the symbol.

func (*SymbolData) IsSatisfiedBy

func (s *SymbolData) IsSatisfiedBy(t types.TypeNode) bool

IsSatisfiedBy checks if the symbol is satisfied by this type

func (*SymbolData) String

func (s *SymbolData) String() string

type SymbolTable

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

SymbolTable is a comprehensive list of symbols currently in scope

func NewTable

func NewTable() *SymbolTable

NewTable generates and returns a new symbole table

func (*SymbolTable) AddToScope

func (s *SymbolTable) AddToScope(name string, sym *SymbolData)

AddToScope adds the variable to the scope

func (*SymbolTable) GetCurrentLevel

func (s *SymbolTable) GetCurrentLevel() int

GetCurrentLevel gets the current level of scope

func (*SymbolTable) LookupSymbol

func (s *SymbolTable) LookupSymbol(name string) (*SymbolData, int)

LookupSymbol looks up the symbol in our table. returns the symboldata and the scope level (0 is the current scope). if symbol is not found, returns nil and -1

func (*SymbolTable) LookupSymbolInAllScopes

func (s *SymbolTable) LookupSymbolInAllScopes(name string) (*SymbolData, int)

func (*SymbolTable) PopScope

func (s *SymbolTable) PopScope() error

PopScope pops the global state

func (*SymbolTable) PushNewScope

func (s *SymbolTable) PushNewScope()

PushNewScope Pushes a new scope on to the ScopeStack

func (*SymbolTable) ResetStackAndLockScope

func (s *SymbolTable) ResetStackAndLockScope()

ResetStackAndLockScope resets the stack so we are looking at the global scope again, and then prevents the scope from growing again

func (*SymbolTable) ResolveType

func (s *SymbolTable) ResolveType(sym *SymbolData) *SymbolData

func (*SymbolTable) String

func (s *SymbolTable) String() string

type TypeData

type TypeData struct {
	IsSealed bool
	Adds     []types.TypeNode
	Name     string
	Type     types.TypeNode
}

TypeData represents some information about a type

func (*TypeData) IsSatisfiedBy

func (t *TypeData) IsSatisfiedBy(tp types.TypeNode) bool

IsSatisfiedBy checks if the symbol is satisfied by this type

Jump to

Keyboard shortcuts

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