finish fixing things

This commit is contained in:
Aidan 2020-08-26 21:36:06 -07:00
parent 6afd01da2a
commit 591402b428
No known key found for this signature in database
GPG key ID: 327711E983899316
4 changed files with 19 additions and 16 deletions

View file

@ -17,7 +17,9 @@
package ast package ast
import "gitlab.com/whom/shs/log" import (
"gitlab.com/whom/shs/log"
)
/* determines whether or not to execute a system binary /* determines whether or not to execute a system binary
* when a function cannot be found in the functable * when a function cannot be found in the functable

View file

@ -18,7 +18,6 @@
package ast package ast
import ( import (
"fmt"
"gitlab.com/whom/shs/log" "gitlab.com/whom/shs/log"
) )
@ -62,26 +61,26 @@ type FuncTable *map[string]*Function
* makes sure correct arguments are passed in * makes sure correct arguments are passed in
*/ */
func (f Function) ParseFunction(args *Token) bool { func (f Function) ParseFunction(args *Token) bool {
total := len(f.Args) inc := 0
for iter := args; iter != nil; iter = iter.Next { for iter := args; iter != nil; iter = iter.Next {
total -= 1 inc += 1
if total < 0 { if inc > len(f.Args) {
log.Log(log.ERR, log.Log(log.ERR,
"too many arguments", "too many arguments",
"ftable") "ftable")
return false return false
} }
if iter.Tag != f.Args[len(f.Args) - total] { if iter.Tag != f.Args[inc - 1] {
log.Log(log.ERR, log.Log(log.ERR,
"argument is " + GetTagAsStr(iter.Tag) + "argument is " + GetTagAsStr(iter.Tag) +
" should be " + GetTagAsStr(f.Args[len(f.Args) - total]), " should be " + GetTagAsStr(f.Args[inc - 1]),
"ftable") "ftable")
return false return false
} }
} }
if total > 0 { if inc < len(f.Args) {
log.Log(log.ERR, log.Log(log.ERR,
"not enough args given", "not enough args given",
"ftable") "ftable")
@ -124,15 +123,18 @@ func (f Function) LazyParseFunction(args *Token) bool {
* calls ParseFunction and increments TimesCalled * calls ParseFunction and increments TimesCalled
*/ */
func (f Function) CallFunction(args *Token, vt VarTable, ft FuncTable) *Token { func (f Function) CallFunction(args *Token, vt VarTable, ft FuncTable) *Token {
var n_args *Token
if !f.EvalLazy { if !f.EvalLazy {
args = args.Eval(ft, vt, f.SymLazy) n_args = args.Eval(ft, vt, f.SymLazy)
} else {
n_args = args
} }
passes := false passes := false
if f.ArgLazy { if f.ArgLazy {
passes = f.LazyParseFunction(args) passes = f.LazyParseFunction(n_args)
} else { } else {
passes = f.ParseFunction(args) passes = f.ParseFunction(n_args)
} }
if !passes { if !passes {
@ -142,9 +144,8 @@ func (f Function) CallFunction(args *Token, vt VarTable, ft FuncTable) *Token {
return nil return nil
} }
fmt.Printf("ARGS: %+v", *args)
f.TimesCalled += 1 f.TimesCalled += 1
return f.Function(args, vt, ft) return f.Function(n_args, vt, ft)
} }
/* searches for function mapped to argument in FuncTable /* searches for function mapped to argument in FuncTable

View file

@ -216,7 +216,7 @@ func StrIsNumber(arg string) bool {
dotCount := 0 dotCount := 0
// negative nums // negative nums
if len(arg) > 0 && arg[0] == '-' { if len(arg) > 1 && arg[0] == '-' {
arg = arg[1:] arg = arg[1:]
} }

View file

@ -58,7 +58,7 @@ func GenFuncTable() ast.FuncTable {
Function: DeclFunc, Function: DeclFunc,
Name: "decl_func", Name: "decl_func",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.STRING, ast.SYMBOL,
ast.LIST, ast.LIST,
ast.LIST, ast.LIST,
}, },
@ -141,7 +141,7 @@ func GenFuncTable() ast.FuncTable {
Function: NumCast, Function: NumCast,
Name: "number", Name: "number",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.NUMBER, ast.STRING,
}, },
}, },