diff options
Diffstat (limited to 'vendor/github.com/d5/tengo/compiler/symbol_table.go')
-rw-r--r-- | vendor/github.com/d5/tengo/compiler/symbol_table.go | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/vendor/github.com/d5/tengo/compiler/symbol_table.go b/vendor/github.com/d5/tengo/compiler/symbol_table.go index da55a826..fb029b31 100644 --- a/vendor/github.com/d5/tengo/compiler/symbol_table.go +++ b/vendor/github.com/d5/tengo/compiler/symbol_table.go @@ -2,12 +2,13 @@ package compiler // SymbolTable represents a symbol table. type SymbolTable struct { - parent *SymbolTable - block bool - store map[string]*Symbol - numDefinition int - maxDefinition int - freeSymbols []*Symbol + parent *SymbolTable + block bool + store map[string]*Symbol + numDefinition int + maxDefinition int + freeSymbols []*Symbol + builtinSymbols []*Symbol } // NewSymbolTable creates a SymbolTable. @@ -37,6 +38,10 @@ func (t *SymbolTable) Define(name string) *Symbol { // DefineBuiltin adds a symbol for builtin function. func (t *SymbolTable) DefineBuiltin(index int, name string) *Symbol { + if t.parent != nil { + return t.parent.DefineBuiltin(index, name) + } + symbol := &Symbol{ Name: name, Index: index, @@ -45,6 +50,8 @@ func (t *SymbolTable) DefineBuiltin(index int, name string) *Symbol { t.store[name] = symbol + t.builtinSymbols = append(t.builtinSymbols, symbol) + return symbol } @@ -101,6 +108,15 @@ func (t *SymbolTable) FreeSymbols() []*Symbol { return t.freeSymbols } +// BuiltinSymbols returns builtin symbols for the scope. +func (t *SymbolTable) BuiltinSymbols() []*Symbol { + if t.parent != nil { + return t.parent.BuiltinSymbols() + } + + return t.builtinSymbols +} + // Names returns the name of all the symbols. func (t *SymbolTable) Names() []string { var names []string |