perform arg type checking and evaluation before function call

This commit is contained in:
Aidan 2020-08-21 01:37:04 -07:00
parent 90284f2d06
commit ab340ceb0a
No known key found for this signature in database
GPG key ID: 327711E983899316
9 changed files with 223 additions and 354 deletions

View file

@ -225,11 +225,6 @@ func LaunchProcess(
* Example (l vim file.txt)
*/
func Call(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
in = in.Eval(ft, vt, true)
if in == nil {
return nil
}
if in.Tag == ast.LIST {
log.Log(log.ERR, "couldnt exec, target bin is a list", "call")
return nil
@ -261,11 +256,6 @@ func Call(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
* Example: (bg vim file.txt)
*/
func Bgcall(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
in = in.Eval(ft, vt, true)
if in == nil {
return nil
}
if in.Tag == ast.LIST {
log.Log(log.ERR, "couldnt exec, target bin is a list", "call")
return nil
@ -304,14 +294,6 @@ func Fg(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
return nil
}
in = in.Eval(ft, vt, false)
if in.Tag != ast.NUMBER && in.Tag != ast.STRING {
log.Log(log.ERR,
"must supply a number or string to fg",
"fg")
return nil
}
pid, err := strconv.ParseFloat(in.Value(), 64)
if err != nil {
log.Log(log.ERR,
@ -374,12 +356,6 @@ func Jobs(in *ast.Token, vt ast.VarTable, fg ast.FuncTable) *ast.Token {
* Example: ($ echo hello world)
*/
func ReadCmd(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
in = in.Eval(ft, vt, true)
if in == nil {
return nil
}
if in.Tag == ast.LIST {
log.Log(log.ERR, "couldnt exec, target bin is a list", "call")
return nil
@ -434,13 +410,6 @@ func GetExit(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
* (this function not added to functable in stdlib.go)
*/
func Kill(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
in = in.Eval(ft, vt, true)
if in.Tag == ast.LIST {
log.Log(log.ERR, "non-number argument to kill function", "kill")
return nil
}
pid, err := strconv.ParseInt(in.Value(), 10, 64)
if err != nil {
log.Log(log.ERR, "error parsing arg to kill: " + err.Error(), "kill")