fix bug in repeated function calls
This commit is contained in:
parent
93cd5c5a48
commit
81d299aa5e
3 changed files with 20 additions and 11 deletions
13
ast/eval.go
13
ast/eval.go
|
|
@ -43,17 +43,16 @@ func (in *Token) Eval(funcs FuncTable, vars VarTable, cnvtUndefVars bool) *Token
|
||||||
|
|
||||||
switch in.Tag {
|
switch in.Tag {
|
||||||
case BOOL, NUMBER, STRING:
|
case BOOL, NUMBER, STRING:
|
||||||
res = in
|
res = in.Copy()
|
||||||
|
|
||||||
case SYMBOL:
|
case SYMBOL:
|
||||||
res = GetVar(in.Value(), vars)
|
res = GetVar(in.Value(), vars)
|
||||||
if res == nil {
|
if res == nil {
|
||||||
res = in
|
res = in.Copy()
|
||||||
|
|
||||||
if GetFunction(in.Value(), funcs) == nil {
|
if GetFunction(in.Value(), funcs) == nil {
|
||||||
if cnvtUndefVars {
|
if cnvtUndefVars {
|
||||||
in.Tag = STRING
|
res.Tag = STRING
|
||||||
res = in
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,19 +62,17 @@ func (in *Token) Eval(funcs FuncTable, vars VarTable, cnvtUndefVars bool) *Token
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.Next = in.Next
|
|
||||||
|
|
||||||
|
|
||||||
case LIST:
|
case LIST:
|
||||||
inner := in.Expand()
|
inner := in.Expand()
|
||||||
if inner == nil {
|
if inner == nil {
|
||||||
res = in
|
res = in.Copy()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if inner.Tag != SYMBOL {
|
if inner.Tag != SYMBOL {
|
||||||
in.Direct(inner.Eval(funcs, vars, cnvtUndefVars))
|
in.Direct(inner.Eval(funcs, vars, cnvtUndefVars))
|
||||||
res = in
|
res = in.Copy()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
12
ast/token.go
12
ast/token.go
|
|
@ -48,6 +48,18 @@ func (t *Token) Append(arg *Token) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Shallow Copy
|
||||||
|
* in case of a LIST,
|
||||||
|
* inner will point to the same list.
|
||||||
|
*/
|
||||||
|
func (t *Token) Copy() *Token {
|
||||||
|
return &Token{
|
||||||
|
Tag: t.Tag,
|
||||||
|
inner: t.inner,
|
||||||
|
Next: t.Next,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Print function which is better suited for repl.
|
/* Print function which is better suited for repl.
|
||||||
* This one prints the SEXPRs as one would write them.
|
* This one prints the SEXPRs as one would write them.
|
||||||
* Does not evaluate tokens.
|
* Does not evaluate tokens.
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,8 @@ func decl_func(input *ast.Token, vars ast.VarTable, funcs ast.FuncTable) *ast.To
|
||||||
|
|
||||||
ASTSYNCSTATE := ast.SyncTablesWithOSEnviron
|
ASTSYNCSTATE := ast.SyncTablesWithOSEnviron
|
||||||
inner := func(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
inner := func(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||||
in = in.Eval(ft, vt, false)
|
temp := in.Eval(ft, vt, false)
|
||||||
if in == nil {
|
if temp == nil {
|
||||||
log.Log(log.ERR,
|
log.Log(log.ERR,
|
||||||
"error parsing arguments",
|
"error parsing arguments",
|
||||||
name.Value())
|
name.Value())
|
||||||
|
|
@ -70,7 +70,7 @@ func decl_func(input *ast.Token, vars ast.VarTable, funcs ast.FuncTable) *ast.To
|
||||||
|
|
||||||
ast.SyncTablesWithOSEnviron = false
|
ast.SyncTablesWithOSEnviron = false
|
||||||
key_iter := args.Expand()
|
key_iter := args.Expand()
|
||||||
val_iter := in
|
val_iter := temp
|
||||||
|
|
||||||
for key_iter != nil {
|
for key_iter != nil {
|
||||||
if val_iter == nil {
|
if val_iter == nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue