perform arg type checking and evaluation before function call
This commit is contained in:
parent
90284f2d06
commit
ab340ceb0a
9 changed files with 223 additions and 354 deletions
|
|
@ -30,14 +30,6 @@ import (
|
|||
* Example: (bool "F")
|
||||
*/
|
||||
func BoolCast(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||
in = in.Eval(ft, vt, false)
|
||||
if in.Tag == ast.LIST || in.Tag == ast.NUMBER {
|
||||
log.Log(log.ERR,
|
||||
"only strings successfully cast to bool",
|
||||
"bool cast")
|
||||
return nil
|
||||
}
|
||||
|
||||
body := in.Value()
|
||||
if body != ast.TRUE && body != ast.FALSE {
|
||||
log.Log(log.ERR,
|
||||
|
|
@ -52,13 +44,6 @@ func BoolCast(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
|||
}
|
||||
|
||||
func Not(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||
in = in.Eval(ft, vt, false)
|
||||
|
||||
if in.Tag != ast.BOOL {
|
||||
log.Log(log.ERR, "non-bool argument to 'not'", "not")
|
||||
return nil
|
||||
}
|
||||
|
||||
out := ast.TRUE
|
||||
if in.Value() == ast.TRUE {
|
||||
out = ast.FALSE
|
||||
|
|
@ -69,10 +54,9 @@ func Not(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
|||
return t
|
||||
}
|
||||
|
||||
// Lazy args this
|
||||
func Eq(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||
out := ast.TRUE
|
||||
|
||||
in = in.Eval(ft, vt, false)
|
||||
second := in.Next
|
||||
|
||||
if in.Tag != second.Tag {
|
||||
|
|
@ -155,13 +139,6 @@ func Lt(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
|||
out := ast.TRUE
|
||||
second := in.Next
|
||||
|
||||
in = in.Eval(ft, vt, false)
|
||||
|
||||
if in.Tag != ast.NUMBER || second.Tag != ast.NUMBER {
|
||||
log.Log(log.ERR, "non-number argument to numeric boolean operator", ">/<=")
|
||||
return nil
|
||||
}
|
||||
|
||||
l, _ := strconv.ParseInt(in.Value(), 10, 64)
|
||||
r, _ := strconv.ParseInt(second.Value(), 10, 64)
|
||||
|
||||
|
|
@ -178,13 +155,6 @@ func Gt(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
|||
out := ast.TRUE
|
||||
second := in.Next
|
||||
|
||||
in = in.Eval(ft, vt, false)
|
||||
|
||||
if in.Tag != ast.NUMBER || second.Tag != ast.NUMBER {
|
||||
log.Log(log.ERR, "non-number argument to numeric boolean operator", ">/<=")
|
||||
return nil
|
||||
}
|
||||
|
||||
l, _ := strconv.ParseInt(in.Value(), 10, 64)
|
||||
r, _ := strconv.ParseInt(second.Value(), 10, 64)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue