module support
Some checks failed
Build / build (push) Successful in 10m22s
Test / build (push) Failing after 15m54s

This commit is contained in:
Chuck Smith
2024-03-26 16:49:38 -04:00
parent 6d234099d1
commit 110152a139
21 changed files with 541 additions and 100 deletions

View File

@@ -19,7 +19,7 @@ type Symbol struct {
type SymbolTable struct {
Outer *SymbolTable
store map[string]Symbol
Store map[string]Symbol
numDefinitions int
FreeSymbols []Symbol
@@ -34,7 +34,7 @@ func NewEnclosedSymbolTable(outer *SymbolTable) *SymbolTable {
func NewSymbolTable() *SymbolTable {
s := make(map[string]Symbol)
free := []Symbol{}
return &SymbolTable{store: s, FreeSymbols: free}
return &SymbolTable{Store: s, FreeSymbols: free}
}
func (s *SymbolTable) Define(name string) Symbol {
@@ -45,13 +45,13 @@ func (s *SymbolTable) Define(name string) Symbol {
symbol.Scope = LocalScope
}
s.store[name] = symbol
s.Store[name] = symbol
s.numDefinitions++
return symbol
}
func (s *SymbolTable) Resolve(name string) (Symbol, bool) {
obj, ok := s.store[name]
obj, ok := s.Store[name]
if !ok && s.Outer != nil {
obj, ok = s.Outer.Resolve(name)
if !ok {
@@ -72,7 +72,7 @@ func (s *SymbolTable) Resolve(name string) (Symbol, bool) {
func (s *SymbolTable) DefineBuiltin(index int, name string) Symbol {
symbol := Symbol{Name: name, Index: index, Scope: BuiltinScope}
s.store[name] = symbol
s.Store[name] = symbol
return symbol
}
@@ -82,12 +82,12 @@ func (s *SymbolTable) DefineFree(original Symbol) Symbol {
symbol := Symbol{Name: original.Name, Index: len(s.FreeSymbols) - 1}
symbol.Scope = FreeScope
s.store[original.Name] = symbol
s.Store[original.Name] = symbol
return symbol
}
func (s *SymbolTable) DefineFunctionName(name string) Symbol {
symbol := Symbol{Name: name, Index: 0, Scope: FunctionScope}
s.store[name] = symbol
s.Store[name] = symbol
return symbol
}