changed table types to support implementing 'let', also integrated stdlib into repl

This commit is contained in:
Aidan 2020-06-21 12:46:25 -07:00
parent b01415d786
commit 9c25ac21f9
No known key found for this signature in database
GPG key ID: 327711E983899316
5 changed files with 16 additions and 58 deletions

View file

@ -17,10 +17,10 @@
package ast
type VarTable map[string]*Token
type VarTable *map[string]*Token
func (vt VarTable) GetVar(arg string) *Token {
val, ok := vt[arg]
func GetVar(arg string, vt VarTable) *Token {
val, ok := (*vt)[arg]
if !ok {
return nil
}
@ -30,11 +30,11 @@ func (vt VarTable) GetVar(arg string) *Token {
// Library represents variables defined in inner scope
// It is assumed library is ordered from innermost scope to outermost scope
func GetVar(arg string, library []VarTable) *Token {
func GetVarFromTables(arg string, library []VarTable) *Token {
var res *Token
res = nil
for i := 0; i < len(library); i += 1 {
res = library[i].GetVar(arg)
res = GetVar(arg, library[i])
if res != nil {
// TODO: Log scope res was found in?
break