diff --git a/ast/eval.go b/ast/eval.go index e82a89b..cbbae5d 100644 --- a/ast/eval.go +++ b/ast/eval.go @@ -17,7 +17,9 @@ package ast -import "gitlab.com/whom/shs/log" +import ( + "gitlab.com/whom/shs/log" +) /* determines whether or not to execute a system binary * when a function cannot be found in the functable diff --git a/ast/func_table.go b/ast/func_table.go index 0d8fa12..001f149 100644 --- a/ast/func_table.go +++ b/ast/func_table.go @@ -18,7 +18,6 @@ package ast import ( - "fmt" "gitlab.com/whom/shs/log" ) @@ -62,26 +61,26 @@ type FuncTable *map[string]*Function * makes sure correct arguments are passed in */ func (f Function) ParseFunction(args *Token) bool { - total := len(f.Args) + inc := 0 for iter := args; iter != nil; iter = iter.Next { - total -= 1 - if total < 0 { + inc += 1 + if inc > len(f.Args) { log.Log(log.ERR, "too many arguments", "ftable") return false } - if iter.Tag != f.Args[len(f.Args) - total] { + if iter.Tag != f.Args[inc - 1] { log.Log(log.ERR, "argument is " + GetTagAsStr(iter.Tag) + - " should be " + GetTagAsStr(f.Args[len(f.Args) - total]), + " should be " + GetTagAsStr(f.Args[inc - 1]), "ftable") return false } } - if total > 0 { + if inc < len(f.Args) { log.Log(log.ERR, "not enough args given", "ftable") @@ -124,15 +123,18 @@ func (f Function) LazyParseFunction(args *Token) bool { * calls ParseFunction and increments TimesCalled */ func (f Function) CallFunction(args *Token, vt VarTable, ft FuncTable) *Token { + var n_args *Token if !f.EvalLazy { - args = args.Eval(ft, vt, f.SymLazy) + n_args = args.Eval(ft, vt, f.SymLazy) + } else { + n_args = args } passes := false if f.ArgLazy { - passes = f.LazyParseFunction(args) + passes = f.LazyParseFunction(n_args) } else { - passes = f.ParseFunction(args) + passes = f.ParseFunction(n_args) } if !passes { @@ -142,9 +144,8 @@ func (f Function) CallFunction(args *Token, vt VarTable, ft FuncTable) *Token { return nil } - fmt.Printf("ARGS: %+v", *args) f.TimesCalled += 1 - return f.Function(args, vt, ft) + return f.Function(n_args, vt, ft) } /* searches for function mapped to argument in FuncTable diff --git a/ast/lex.go b/ast/lex.go index aa677f5..7c33bac 100644 --- a/ast/lex.go +++ b/ast/lex.go @@ -216,7 +216,7 @@ func StrIsNumber(arg string) bool { dotCount := 0 // negative nums - if len(arg) > 0 && arg[0] == '-' { + if len(arg) > 1 && arg[0] == '-' { arg = arg[1:] } diff --git a/stdlib/stdlib.go b/stdlib/stdlib.go index d76f7e6..dd70b5e 100644 --- a/stdlib/stdlib.go +++ b/stdlib/stdlib.go @@ -58,7 +58,7 @@ func GenFuncTable() ast.FuncTable { Function: DeclFunc, Name: "decl_func", Args: []ast.Token_t{ - ast.STRING, + ast.SYMBOL, ast.LIST, ast.LIST, }, @@ -141,7 +141,7 @@ func GenFuncTable() ast.FuncTable { Function: NumCast, Name: "number", Args: []ast.Token_t{ - ast.NUMBER, + ast.STRING, }, },