changed table types to support implementing 'let', also integrated stdlib into repl
This commit is contained in:
parent
b01415d786
commit
9c25ac21f9
5 changed files with 16 additions and 58 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue