retrofit call functions for new eval alg
This commit is contained in:
parent
ea99142b3a
commit
2ae1145a50
9 changed files with 384 additions and 25 deletions
20
ast/eval.go
20
ast/eval.go
|
|
@ -17,9 +17,7 @@
|
||||||
|
|
||||||
package ast
|
package ast
|
||||||
|
|
||||||
import (
|
import "gitlab.com/whom/shs/log"
|
||||||
"gitlab.com/whom/shs/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
/* determines whether or not to execute a system call
|
/* determines whether or not to execute a system call
|
||||||
* when a function cannot be found in the functable
|
* when a function cannot be found in the functable
|
||||||
|
|
@ -36,7 +34,7 @@ var ExecFunc = "l"
|
||||||
* canFunc determines whether a symbol could be a function to call
|
* canFunc determines whether a symbol could be a function to call
|
||||||
* (true when first elem of a list)
|
* (true when first elem of a list)
|
||||||
*/
|
*/
|
||||||
func (in *Token) Eval(funcs FuncTable, vars VarTable) *Token {
|
func (in *Token) Eval(funcs FuncTable, vars VarTable, cnvtUndefVars bool) *Token {
|
||||||
if in == nil {
|
if in == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -53,6 +51,12 @@ func (in *Token) Eval(funcs FuncTable, vars VarTable) *Token {
|
||||||
res = in
|
res = in
|
||||||
|
|
||||||
if GetFunction(in.Value(), funcs) == nil {
|
if GetFunction(in.Value(), funcs) == nil {
|
||||||
|
if cnvtUndefVars {
|
||||||
|
in.Tag = STRING
|
||||||
|
res = in
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
log.Log(log.ERR,
|
log.Log(log.ERR,
|
||||||
"undefined symbol: "+in.Value(),
|
"undefined symbol: "+in.Value(),
|
||||||
"eval")
|
"eval")
|
||||||
|
|
@ -70,7 +74,7 @@ func (in *Token) Eval(funcs FuncTable, vars VarTable) *Token {
|
||||||
}
|
}
|
||||||
|
|
||||||
if inner.Tag != SYMBOL {
|
if inner.Tag != SYMBOL {
|
||||||
in.Direct(inner.Eval(funcs, vars))
|
in.Direct(inner.Eval(funcs, vars, cnvtUndefVars))
|
||||||
res = in
|
res = in
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -86,9 +90,9 @@ func (in *Token) Eval(funcs FuncTable, vars VarTable) *Token {
|
||||||
|
|
||||||
if funct != nil {
|
if funct != nil {
|
||||||
if makeHead {
|
if makeHead {
|
||||||
inner = &Token{inner: inner}
|
inner = &Token{Next: inner}
|
||||||
}
|
}
|
||||||
res = funct.CallFunction(inner.Next, vars, funcs).Eval(funcs, vars)
|
res = funct.CallFunction(inner.Next, vars, funcs).Eval(funcs, vars, false)
|
||||||
if res == nil {
|
if res == nil {
|
||||||
// function failed. logging is its responsibility
|
// function failed. logging is its responsibility
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -111,7 +115,7 @@ func (in *Token) Eval(funcs FuncTable, vars VarTable) *Token {
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.Next != nil {
|
if res.Next != nil {
|
||||||
res.Next = res.Next.Eval(funcs, vars)
|
res.Next = res.Next.Eval(funcs, vars, cnvtUndefVars)
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ func main() {
|
||||||
|
|
||||||
ast.InitVarTable(vars)
|
ast.InitVarTable(vars)
|
||||||
ast.SyncTablesWithOSEnviron = true
|
ast.SyncTablesWithOSEnviron = true
|
||||||
ast.ExecWhenFuncUndef = false
|
ast.ExecWhenFuncUndef = true
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
|
@ -96,7 +96,7 @@ func main() {
|
||||||
ast.PrintSExprsIndividually(userInput)
|
ast.PrintSExprsIndividually(userInput)
|
||||||
}
|
}
|
||||||
|
|
||||||
result := userInput.Eval(funcs, vars)
|
result := userInput.Eval(funcs, vars, false)
|
||||||
if result != nil {
|
if result != nil {
|
||||||
for i := result; i != nil; i = i.Next {
|
for i := result; i != nil; i = i.Next {
|
||||||
fmt.Printf(i.String() + " ")
|
fmt.Printf(i.String() + " ")
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ import (
|
||||||
func add(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
|
func add(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
|
||||||
var res float64
|
var res float64
|
||||||
|
|
||||||
in = in.Eval(f, a)
|
in = in.Eval(f, a, false)
|
||||||
|
|
||||||
for i := in; i != nil; i = i.Next {
|
for i := in; i != nil; i = i.Next {
|
||||||
if i.Tag != ast.NUMBER {
|
if i.Tag != ast.NUMBER {
|
||||||
|
|
@ -75,7 +75,7 @@ func sub(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
|
||||||
var res float64
|
var res float64
|
||||||
var sub float64
|
var sub float64
|
||||||
|
|
||||||
in = in.Eval(f, a)
|
in = in.Eval(f, a, false)
|
||||||
|
|
||||||
for i := in; i != nil; i = i.Next {
|
for i := in; i != nil; i = i.Next {
|
||||||
if i.Tag != ast.NUMBER {
|
if i.Tag != ast.NUMBER {
|
||||||
|
|
@ -124,7 +124,7 @@ func sub(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
|
||||||
func mult(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
|
func mult(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
|
||||||
res := 1.0
|
res := 1.0
|
||||||
|
|
||||||
in = in.Eval(f, a)
|
in = in.Eval(f, a, false)
|
||||||
|
|
||||||
for i := in; i != nil; i = i.Next {
|
for i := in; i != nil; i = i.Next {
|
||||||
if i.Tag != ast.NUMBER {
|
if i.Tag != ast.NUMBER {
|
||||||
|
|
@ -166,7 +166,7 @@ func mult(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
|
||||||
func div(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
|
func div(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
|
||||||
var res float64
|
var res float64
|
||||||
|
|
||||||
in = in.Eval(f, a)
|
in = in.Eval(f, a, false)
|
||||||
|
|
||||||
for i := in; i != nil; i = i.Next {
|
for i := in; i != nil; i = i.Next {
|
||||||
inner := 0.0
|
inner := 0.0
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func not(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)
|
in = in.Eval(ft, vt, false)
|
||||||
|
|
||||||
if in.Tag != ast.BOOL {
|
if in.Tag != ast.BOOL {
|
||||||
log.Log(log.ERR, "non-bool argument to 'not'", "not")
|
log.Log(log.ERR, "non-bool argument to 'not'", "not")
|
||||||
|
|
@ -45,8 +45,7 @@ func eq(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||||
out := "T"
|
out := "T"
|
||||||
second := in.Next
|
second := in.Next
|
||||||
|
|
||||||
in = in.Eval(ft, vt)
|
in = in.Eval(ft, vt, false)
|
||||||
second = second.Eval(ft, vt)
|
|
||||||
|
|
||||||
if in.Tag != second.Tag {
|
if in.Tag != second.Tag {
|
||||||
out = "F"
|
out = "F"
|
||||||
|
|
@ -128,8 +127,7 @@ func lt(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||||
out := "T"
|
out := "T"
|
||||||
second := in.Next
|
second := in.Next
|
||||||
|
|
||||||
in = in.Eval(ft, vt)
|
in = in.Eval(ft, vt, false)
|
||||||
second = second.Eval(ft, vt)
|
|
||||||
|
|
||||||
if in.Tag != ast.NUMBER || second.Tag != ast.NUMBER {
|
if in.Tag != ast.NUMBER || second.Tag != ast.NUMBER {
|
||||||
log.Log(log.ERR, "non-number argument to numeric boolean operator", ">/<=")
|
log.Log(log.ERR, "non-number argument to numeric boolean operator", ">/<=")
|
||||||
|
|
@ -152,8 +150,7 @@ func gt(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||||
out := "T"
|
out := "T"
|
||||||
second := in.Next
|
second := in.Next
|
||||||
|
|
||||||
in = in.Eval(ft, vt)
|
in = in.Eval(ft, vt, false)
|
||||||
second = second.Eval(ft, vt)
|
|
||||||
|
|
||||||
if in.Tag != ast.NUMBER || second.Tag != ast.NUMBER {
|
if in.Tag != ast.NUMBER || second.Tag != ast.NUMBER {
|
||||||
log.Log(log.ERR, "non-number argument to numeric boolean operator", ">/<=")
|
log.Log(log.ERR, "non-number argument to numeric boolean operator", ">/<=")
|
||||||
|
|
|
||||||
305
stdlib/call.go
Normal file
305
stdlib/call.go
Normal file
|
|
@ -0,0 +1,305 @@
|
||||||
|
/* SHS: Syntactically Homogeneous Shell
|
||||||
|
* Copyright (C) 2019 Aidan Hahn
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package stdlib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"fmt"
|
||||||
|
"bytes"
|
||||||
|
"strconv"
|
||||||
|
"os/exec"
|
||||||
|
"syscall"
|
||||||
|
"os/signal"
|
||||||
|
"gitlab.com/whom/shs/ast"
|
||||||
|
"gitlab.com/whom/shs/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
var bgProcs = make([]*exec.Cmd, 0)
|
||||||
|
var LastExitCode int
|
||||||
|
var sigs = []os.Signal{os.Interrupt, syscall.SIGTERM, syscall.SIGTSTP, syscall.SIGTTIN, syscall.SIGTTOU, syscall.SIGCONT}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
path, err := exec.LookPath(in.Value())
|
||||||
|
if err != nil {
|
||||||
|
log.Log(log.ERR, "Couldnt exec " + in.Value() + ", file not found", "call")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
args := []string{}
|
||||||
|
for i := in.Next; i != nil; i = i.Next {
|
||||||
|
if i.Tag == ast.LIST {
|
||||||
|
log.Log(log.ERR, "Couldnt exec " + path + ", element in arguments is a list", "call")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
args = append(args, i.Value())
|
||||||
|
}
|
||||||
|
|
||||||
|
var cmd *exec.Cmd
|
||||||
|
if len(args) > 0 {
|
||||||
|
cmd = exec.Command(path, args...)
|
||||||
|
} else {
|
||||||
|
cmd = exec.Command(path)
|
||||||
|
}
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
|
||||||
|
signalChan := make(chan os.Signal, 2)
|
||||||
|
signal.Notify(signalChan, sigs...)
|
||||||
|
go func() {
|
||||||
|
sig := <-signalChan
|
||||||
|
cmd.Process.Signal(sig)
|
||||||
|
}()
|
||||||
|
|
||||||
|
err = cmd.Run()
|
||||||
|
close(signalChan)
|
||||||
|
signal.Reset(sigs...)
|
||||||
|
if err != nil {
|
||||||
|
if exitError, ok := err.(*exec.ExitError); ok {
|
||||||
|
LastExitCode = exitError.ExitCode()
|
||||||
|
} else {
|
||||||
|
log.Log(log.ERR, "Execution step returned unparsable error: " + err.Error(), "call")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func bgcall(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if in.Tag == ast.LIST {
|
||||||
|
log.Log(log.ERR, "couldnt exec, target bin is a list", "call")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
path, err := exec.LookPath(in.Value())
|
||||||
|
if err != nil {
|
||||||
|
log.Log(log.ERR, "Couldnt exec " + in.Value() + ", file not found", "call")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
args := []string{}
|
||||||
|
for i := in.Next; i != nil; i = i.Next {
|
||||||
|
if i.Tag == ast.LIST {
|
||||||
|
log.Log(log.ERR, "Couldnt exec " + path + ", element in arguments is a list", "call")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
args = append(args, i.Value())
|
||||||
|
}
|
||||||
|
|
||||||
|
var cmd *exec.Cmd
|
||||||
|
if len(args) > 0 {
|
||||||
|
cmd = exec.Command(path, args...)
|
||||||
|
} else {
|
||||||
|
cmd = exec.Command(path)
|
||||||
|
}
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
bgProcs = append(bgProcs, cmd)
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
cmd.Start()
|
||||||
|
cmd.Process.Signal(syscall.SIGTSTP)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func fg(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||||
|
if len(bgProcs) < 1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := bgProcs[0]
|
||||||
|
bgProcs = bgProcs[1:]
|
||||||
|
|
||||||
|
signalChan := make(chan os.Signal, 2)
|
||||||
|
signal.Notify(signalChan, sigs...)
|
||||||
|
go func() {
|
||||||
|
sig := <-signalChan
|
||||||
|
cmd.Process.Signal(sig)
|
||||||
|
}()
|
||||||
|
|
||||||
|
cmd.Process.Signal(syscall.SIGCONT)
|
||||||
|
err := cmd.Wait()
|
||||||
|
close(signalChan)
|
||||||
|
signal.Reset(sigs...)
|
||||||
|
if err != nil {
|
||||||
|
if exitError, ok := err.(*exec.ExitError); ok {
|
||||||
|
LastExitCode = exitError.ExitCode()
|
||||||
|
} else {
|
||||||
|
log.Log(log.ERR, "Execution step returned error: " + err.Error(), "call")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func jobs(in *ast.Token, vt ast.VarTable, fg ast.FuncTable) *ast.Token {
|
||||||
|
ret := &ast.Token{
|
||||||
|
Tag: ast.LIST,
|
||||||
|
}
|
||||||
|
|
||||||
|
_inner := &ast.Token{
|
||||||
|
Tag: ast.STRING,
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.Direct(_inner)
|
||||||
|
_inner.Set(fmt.Sprintf("Total: %d", len(bgProcs)))
|
||||||
|
|
||||||
|
iter := &_inner
|
||||||
|
for i := 0; i < len(bgProcs); i += 1 {
|
||||||
|
(*iter).Next = &ast.Token{
|
||||||
|
Tag: ast.STRING,
|
||||||
|
}
|
||||||
|
(*iter).Next.Set(fmt.Sprintf("[%d]: %d", i, bgProcs[i].Process.Pid))
|
||||||
|
iter = &(*iter).Next
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func read_cmd(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
|
||||||
|
}
|
||||||
|
|
||||||
|
var out bytes.Buffer
|
||||||
|
path, err := exec.LookPath(in.Value())
|
||||||
|
if err != nil {
|
||||||
|
log.Log(log.ERR, "Couldnt exec " + in.Value() + ", file not found", "call")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
args := []string{}
|
||||||
|
for i := in.Next; i != nil; i = i.Next {
|
||||||
|
if i.Tag == ast.LIST {
|
||||||
|
log.Log(log.ERR, "Couldnt exec " + path + ", element in arguments is a list", "call")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
args = append(args, i.Value())
|
||||||
|
}
|
||||||
|
|
||||||
|
var cmd *exec.Cmd
|
||||||
|
if len(args) > 0 {
|
||||||
|
cmd = exec.Command(path, args...)
|
||||||
|
} else {
|
||||||
|
cmd = exec.Command(path)
|
||||||
|
}
|
||||||
|
cmd.Stdout = &out
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
|
||||||
|
signalChan := make(chan os.Signal, 2)
|
||||||
|
signal.Notify(signalChan, sigs...)
|
||||||
|
go func() {
|
||||||
|
sig := <-signalChan
|
||||||
|
cmd.Process.Signal(sig)
|
||||||
|
}()
|
||||||
|
|
||||||
|
err = cmd.Run()
|
||||||
|
close(signalChan)
|
||||||
|
signal.Reset(sigs...)
|
||||||
|
if err != nil {
|
||||||
|
if exitError, ok := err.(*exec.ExitError); ok {
|
||||||
|
LastExitCode = exitError.ExitCode()
|
||||||
|
} else {
|
||||||
|
log.Log(log.ERR, "Execution step returned error: " + err.Error(), "$")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret := &ast.Token{Tag: ast.STRING}
|
||||||
|
ret.Set(out.String())
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func get_exit(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||||
|
ret := &ast.Token{Tag: ast.NUMBER}
|
||||||
|
ret.Set(fmt.Sprintf("%d", LastExitCode))
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
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")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
found := false
|
||||||
|
newBgProcs := []*exec.Cmd{}
|
||||||
|
for _, i := range bgProcs {
|
||||||
|
if i.Process.Pid != int(pid) {
|
||||||
|
newBgProcs = append(newBgProcs, i)
|
||||||
|
} else {
|
||||||
|
found = true
|
||||||
|
err = i.Process.Kill()
|
||||||
|
if err != nil {
|
||||||
|
log.Log(log.ERR, fmt.Sprintf("error killing process %d: %s",
|
||||||
|
int(pid), err.Error()), "kill")
|
||||||
|
newBgProcs = append(newBgProcs, i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bgProcs = newBgProcs
|
||||||
|
|
||||||
|
if !found {
|
||||||
|
// docs say no error on unix systems
|
||||||
|
proc, _ := os.FindProcess(int(pid))
|
||||||
|
err = proc.Kill()
|
||||||
|
if err != nil {
|
||||||
|
log.Log(log.ERR, fmt.Sprintf("error killing process %d: %s",
|
||||||
|
int(pid), err.Error()), "kill")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func cd(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
func cd(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||||
in = in.Eval(ft, vt)
|
in = in.Eval(ft, vt, false)
|
||||||
if in.Tag == ast.LIST {
|
if in.Tag == ast.LIST {
|
||||||
log.Log(log.ERR, "Couldnt change dir to a list", "cd")
|
log.Log(log.ERR, "Couldnt change dir to a list", "cd")
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ func expand(input *ast.Token, vars ast.VarTable, funcs ast.FuncTable) *ast.Token
|
||||||
return input
|
return input
|
||||||
}
|
}
|
||||||
|
|
||||||
return input.Eval(funcs, vars).Expand()
|
return input.Eval(funcs, vars, false).Expand()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* L_APPEND (append from repl)
|
/* L_APPEND (append from repl)
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,59 @@ func GenFuncTable() ast.FuncTable {
|
||||||
TimesCalled: 0,
|
TimesCalled: 0,
|
||||||
Args: 1,
|
Args: 1,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"l": &ast.Function{
|
||||||
|
Function: call,
|
||||||
|
Name: "call",
|
||||||
|
TimesCalled: 0,
|
||||||
|
Args: -1,
|
||||||
|
},
|
||||||
|
|
||||||
|
"bg": &ast.Function{
|
||||||
|
Function: bgcall,
|
||||||
|
Name: "background call",
|
||||||
|
TimesCalled: 0,
|
||||||
|
Args: -1,
|
||||||
|
},
|
||||||
|
|
||||||
|
"fg": &ast.Function{
|
||||||
|
Function: fg,
|
||||||
|
Name: "foreground",
|
||||||
|
TimesCalled: 0,
|
||||||
|
Args: 0,
|
||||||
|
},
|
||||||
|
|
||||||
|
"$": &ast.Function{
|
||||||
|
Function: read_cmd,
|
||||||
|
Name: "read cmd",
|
||||||
|
TimesCalled: 0,
|
||||||
|
Args: -1,
|
||||||
|
},
|
||||||
|
|
||||||
|
"?": &ast.Function{
|
||||||
|
Function: get_exit,
|
||||||
|
Name:"get exit code",
|
||||||
|
TimesCalled: 0,
|
||||||
|
Args: 0,
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
USE NATIVE KILL COMMAND.
|
||||||
|
"kill": &ast.Function{
|
||||||
|
Function: kill,
|
||||||
|
Name: "kill job",
|
||||||
|
TimesCalled: 0,
|
||||||
|
Args: 1,
|
||||||
|
},
|
||||||
|
*/
|
||||||
|
|
||||||
|
"jobs": &ast.Function{
|
||||||
|
Function: jobs,
|
||||||
|
Name: "list jobs",
|
||||||
|
TimesCalled: 0,
|
||||||
|
Args: 0,
|
||||||
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return stdlib
|
return stdlib
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func concat(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
func concat(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||||
in = in.Eval(ft, vt)
|
in = in.Eval(ft, vt, false)
|
||||||
|
|
||||||
var res string
|
var res string
|
||||||
for i := in; i != nil; i = i.Next {
|
for i := in; i != nil; i = i.Next {
|
||||||
|
|
@ -43,6 +43,6 @@ func concat(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||||
}
|
}
|
||||||
|
|
||||||
func print_str(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
func print_str(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||||
fmt.Println(in.Eval(ft, vt))
|
fmt.Println(in.Eval(ft, vt, false))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue