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

@ -34,7 +34,7 @@ func (t *Token) Eval(funcs FuncTable, vars VarTable) *Token {
switch (t_.Tag) {
case SYMBOL:
maybeToken := vars.GetVar(t_.Inner.(string))
maybeToken := GetVar(t_.Inner.(string), vars)
if maybeToken != nil {
tok := maybeToken.Eval(funcs, vars)
if tok.Tag == LIST {
@ -52,7 +52,7 @@ func (t *Token) Eval(funcs FuncTable, vars VarTable) *Token {
ret := reduce(t)
if ret.Tag == SYMBOL {
f := funcs.GetFunction(ret.Inner.(string))
f := GetFunction(ret.Inner.(string), funcs)
if f == nil {
if !eligibleForSystemCall {
log.Log(log.DEBUG,

View file

@ -28,7 +28,7 @@ type Function struct {
Args int // TODO: Make this a list of expected types (TAGs)
}
type FuncTable map[string]*Function
type FuncTable *map[string]*Function
// TODO: Currently only checks arg list length
func (f Function) ParseFunction(args *Token) bool {
@ -64,8 +64,8 @@ func (f Function) CallFunction(args *Token, vt VarTable, ft FuncTable) *Token {
return f.Function(args, vt, ft)
}
func (table FuncTable) GetFunction(arg string) *Function {
target, ok := table[arg]
func GetFunction(arg string, table FuncTable) *Function {
target, ok := (*table)[arg]
if !ok {
log.Log(log.DEBUG,
"function " + arg + " not found",

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