fix build from last night
This commit is contained in:
parent
ab340ceb0a
commit
87004ff7fd
6 changed files with 210 additions and 213 deletions
|
|
@ -18,7 +18,6 @@
|
|||
package ast
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gitlab.com/whom/shs/log"
|
||||
)
|
||||
|
||||
|
|
@ -40,7 +39,7 @@ type Function struct {
|
|||
|
||||
// list of types (LIST, NUMBER, STRING, etc) representing args
|
||||
Args []Token_t
|
||||
NumArgs bool // -1 means infinite
|
||||
NumArgs int // -1 means infinite
|
||||
|
||||
// lazy arg checking (use NumArgs instead of args)
|
||||
ArgLazy bool
|
||||
|
|
@ -62,7 +61,7 @@ type FuncTable *map[string]*Function
|
|||
* makes sure correct arguments are passed in
|
||||
*/
|
||||
func (f Function) ParseFunction(args *Token) bool {
|
||||
total = len(f.Args)
|
||||
total := len(f.Args)
|
||||
for iter := args; iter != nil; iter = iter.Next {
|
||||
total -= 1
|
||||
if total <= 0 {
|
||||
|
|
@ -88,7 +87,7 @@ func (f Function) ParseFunction(args *Token) bool {
|
|||
/* same as ParseFunction but only evaluates the number of args
|
||||
*/
|
||||
func (f Function) LazyParseFunction(args *Token) bool {
|
||||
if (f.NumArgs < 0) {
|
||||
if f.NumArgs < 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
@ -118,15 +117,15 @@ func (f Function) LazyParseFunction(args *Token) bool {
|
|||
* calls ParseFunction and increments TimesCalled
|
||||
*/
|
||||
func (f Function) CallFunction(args *Token, vt VarTable, ft FuncTable) *Token {
|
||||
if not f.EvalLazy {
|
||||
if !f.EvalLazy {
|
||||
args = args.Eval(ft, vt, !f.SymLazy)
|
||||
}
|
||||
|
||||
passes := false
|
||||
if f.ArgsLazy {
|
||||
passes = LazyParseFunction(args)
|
||||
if f.ArgLazy {
|
||||
passes = f.LazyParseFunction(args)
|
||||
} else {
|
||||
passes = ParseFunction(args)
|
||||
passes = f.ParseFunction(args)
|
||||
}
|
||||
|
||||
if passes {
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ func main() {
|
|||
}
|
||||
|
||||
dyn_prompt := ast.GetFunction("_SH_PROMPT", funcs)
|
||||
if dyn_prompt == nil || dyn_prompt.Args != 0 {
|
||||
if dyn_prompt == nil || dyn_prompt.NumArgs != 0 {
|
||||
dyn_prompt = nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ func DeclFunc(input *ast.Token, vars ast.VarTable, funcs ast.FuncTable) *ast.Tok
|
|||
Name: name.Value(),
|
||||
TimesCalled: 0,
|
||||
NumArgs: numArgs,
|
||||
LazyArgs: true
|
||||
ArgLazy: true,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ func Len(input *ast.Token, vars ast.VarTable, funcs ast.FuncTable) *ast.Token {
|
|||
}
|
||||
|
||||
length := 0
|
||||
if input.Tag = ast.STRING {
|
||||
if input.Tag == ast.STRING {
|
||||
length = len(input.Value())
|
||||
|
||||
} else {
|
||||
|
|
|
|||
113
stdlib/stdlib.go
113
stdlib/stdlib.go
|
|
@ -20,7 +20,6 @@ package stdlib
|
|||
import (
|
||||
"os"
|
||||
"fmt"
|
||||
"gitlab.com/whom/shs/log"
|
||||
"gitlab.com/whom/shs/ast"
|
||||
"gitlab.com/whom/shs/util"
|
||||
)
|
||||
|
|
@ -35,16 +34,16 @@ func GenFuncTable() ast.FuncTable {
|
|||
Function: ShsIf,
|
||||
Name: "if",
|
||||
NumArgs: 3,
|
||||
EvalLazy true,
|
||||
ArgLazy true
|
||||
EvalLazy: true,
|
||||
ArgLazy: true,
|
||||
},
|
||||
|
||||
"while": &ast.Function{
|
||||
Function: ShsWhile,
|
||||
Name: "while",
|
||||
NumArgs: -1,
|
||||
EvalLazy true,
|
||||
ArgLazy true,
|
||||
EvalLazy: true,
|
||||
ArgLazy: true,
|
||||
},
|
||||
|
||||
"progn": &ast.Function{
|
||||
|
|
@ -61,7 +60,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
Args: []ast.Token_t{
|
||||
ast.STRING,
|
||||
ast.LIST,
|
||||
ast.LIST
|
||||
ast.LIST,
|
||||
},
|
||||
EvalLazy: true,
|
||||
},
|
||||
|
|
@ -77,7 +76,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
Function: Head,
|
||||
Name: "head",
|
||||
Args: []ast.Token_t{
|
||||
ast.LIST
|
||||
ast.LIST,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -85,7 +84,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
Function: Tail,
|
||||
Name: "tail",
|
||||
Args: []ast.Token_t{
|
||||
ast.LIST
|
||||
ast.LIST,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -95,17 +94,17 @@ func GenFuncTable() ast.FuncTable {
|
|||
Args: []ast.Token_t{
|
||||
ast.NUMBER,
|
||||
ast.NUMBER,
|
||||
ast.LIST
|
||||
ast.LIST,
|
||||
},
|
||||
},
|
||||
|
||||
"export": &ast.Function{
|
||||
Function: Export,
|
||||
Name: "export",
|
||||
LazyEval: true,
|
||||
EvalLazy: true,
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING,
|
||||
ast.LIST
|
||||
ast.LIST,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -113,7 +112,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
Function: Input,
|
||||
Name: "input",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING
|
||||
ast.STRING,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -121,7 +120,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
Function: Load,
|
||||
Name: "load",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING
|
||||
ast.STRING,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -129,7 +128,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
Function: BoolCast,
|
||||
Name: "bool",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING
|
||||
ast.STRING,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -143,8 +142,8 @@ func GenFuncTable() ast.FuncTable {
|
|||
"number": &ast.Function{
|
||||
Function: NumCast,
|
||||
Name: "number",
|
||||
Args: []ast.Token{
|
||||
ast.NUMBER
|
||||
Args: []ast.Token_t{
|
||||
ast.NUMBER,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -152,7 +151,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
Function: Expand,
|
||||
Name: "...",
|
||||
Args: []ast.Token_t{
|
||||
ast.LIST
|
||||
ast.LIST,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -168,16 +167,16 @@ func GenFuncTable() ast.FuncTable {
|
|||
Name: "join",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING,
|
||||
ast.LIST
|
||||
ast.LIST,
|
||||
},
|
||||
},
|
||||
|
||||
"split": &ast.Function{
|
||||
Function: Split,
|
||||
Name: "split",
|
||||
Args: ast.Token_t{
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING,
|
||||
ast.STRING,
|
||||
ast.STRING
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -187,7 +186,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
Args: []ast.Token_t{
|
||||
ast.NUMBER,
|
||||
ast.NUMBER,
|
||||
ast.STRING
|
||||
ast.STRING,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -200,14 +199,14 @@ func GenFuncTable() ast.FuncTable {
|
|||
"eq": &ast.Function{
|
||||
Function: Eq,
|
||||
Name: "==",
|
||||
Args: 2,
|
||||
NumArgs: 2,
|
||||
ArgLazy: true,
|
||||
},
|
||||
|
||||
"ne": &ast.Function{
|
||||
Function: Ne,
|
||||
Name: "!=",
|
||||
Args: 2,
|
||||
NumArgs: 2,
|
||||
ArgLazy: true,
|
||||
},
|
||||
|
||||
|
|
@ -216,7 +215,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
Name: "<",
|
||||
Args: []ast.Token_t{
|
||||
ast.NUMBER,
|
||||
ast.NUMBER
|
||||
ast.NUMBER,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -225,7 +224,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
Name: ">",
|
||||
Args: []ast.Token_t{
|
||||
ast.NUMBER,
|
||||
ast.NUMBER
|
||||
ast.NUMBER,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -234,7 +233,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
Name: "<=",
|
||||
Args: []ast.Token_t{
|
||||
ast.NUMBER,
|
||||
ast.NUMBER
|
||||
ast.NUMBER,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -243,7 +242,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
Name: ">=",
|
||||
Args: []ast.Token_t{
|
||||
ast.NUMBER,
|
||||
ast.NUMBER
|
||||
ast.NUMBER,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -251,7 +250,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
Function: Not,
|
||||
Name: "!",
|
||||
Args: []ast.Token_t{
|
||||
ast.Bool
|
||||
ast.BOOL,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -287,7 +286,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
Function: Cd,
|
||||
Name: "changedir",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING
|
||||
ast.STRING,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -302,7 +301,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
Function: PrintStr,
|
||||
Name: "print",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING
|
||||
ast.STRING,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -325,15 +324,15 @@ func GenFuncTable() ast.FuncTable {
|
|||
"fg": &ast.Function{
|
||||
Function: Fg,
|
||||
Name: "foreground",
|
||||
NumArgs: []ast.Token_t{
|
||||
ast.NUMBER
|
||||
Args: []ast.Token_t{
|
||||
ast.NUMBER,
|
||||
},
|
||||
},
|
||||
|
||||
"$": &ast.Function{
|
||||
Function: ReadCmd,
|
||||
Name: "read cmd",
|
||||
NumnArgs: -1,
|
||||
NumArgs: -1,
|
||||
ArgLazy: true,
|
||||
SymLazy: true,
|
||||
},
|
||||
|
|
@ -341,7 +340,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
"?": &ast.Function{
|
||||
Function: GetExit,
|
||||
Name: "get exit code",
|
||||
Args: ast.Token_t{},
|
||||
Args: []ast.Token_t{},
|
||||
},
|
||||
|
||||
/*
|
||||
|
|
@ -356,14 +355,14 @@ func GenFuncTable() ast.FuncTable {
|
|||
"jobs": &ast.Function{
|
||||
Function: Jobs,
|
||||
Name: "list jobs",
|
||||
Args: ast.Token_t{},
|
||||
Args: []ast.Token_t{},
|
||||
},
|
||||
|
||||
"info": &ast.Function{
|
||||
Function: ShInfo,
|
||||
Name: "Shell Info",
|
||||
Args: ast.Token_t{
|
||||
ast.SYMBOL
|
||||
Args: []ast.Token_t{
|
||||
ast.SYMBOL,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -371,7 +370,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
Function: Fexists,
|
||||
Name: "file exists",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING
|
||||
ast.STRING,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -379,7 +378,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
Function: Fread,
|
||||
Name: "read file",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING
|
||||
ast.STRING,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -388,7 +387,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
Name: "write file",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING,
|
||||
ast.STRING
|
||||
ast.STRING,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -397,7 +396,7 @@ func GenFuncTable() ast.FuncTable {
|
|||
Name: "append to file",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING,
|
||||
ast.STRING
|
||||
ast.STRING,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -421,34 +420,32 @@ func ExitShell(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
|||
* Example: (info append)
|
||||
*/
|
||||
func ShInfo(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||
switch in.Tag {
|
||||
case ast.BOOL:
|
||||
fmt.Printf("BOOL LITERAL\nValue: %s\n", in.Value())
|
||||
case ast.STRING:
|
||||
fmt.Printf("STRING LITERAL \nValue: %s\n", in.Value())
|
||||
case ast.NUMBER:
|
||||
fmt.Printf("NUMBER LITERAL \nValue: %s\n", in.Value())
|
||||
case ast.LIST:
|
||||
fmt.Printf("LIST \nString Value: %s, AST:\n", in.String())
|
||||
ast.PrintSExprsIndividually(in)
|
||||
case ast.SYMBOL:
|
||||
repr := ast.GetVar(in.Value(), vt)
|
||||
if repr != nil {
|
||||
fmt.Printf("VARIABLE\nTYPE: %s\nVALUE: %s\n", ast.GetTagAsStr(repr.Tag), repr.Value())
|
||||
break
|
||||
return nil
|
||||
}
|
||||
|
||||
funct := ast.GetFunction(in.Value(), ft)
|
||||
if funct != nil {
|
||||
fmt.Printf("FUNCTION\nNAME: %s\nTIMES CALLED: %s\nNUM ARGS: %d\n", funct.Name, funct.TimesCalled, funct.NumArgs)
|
||||
break
|
||||
fmt.Printf("FUNCTION\nNAME: %s\nTIMES CALLED: %s\n\n", funct.Name, funct.TimesCalled)
|
||||
if funct.ArgLazy {
|
||||
fmt.Printf("function does not evaluate args by type\nARG COUNT: %s\n", funct.NumArgs)
|
||||
} else {
|
||||
fmt.Printf("function evaluates args by type\nARGS: ")
|
||||
for _, i := range(funct.Args) {
|
||||
fmt.Printf(ast.GetTagAsStr(i))
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: print func args
|
||||
fmt.Printf("SYMLAZY: %t\n", funct.SymLazy)
|
||||
fmt.Printf("(can undefined symbols be passed in)\n")
|
||||
fmt.Printf("EVALLAZY: %t\n", funct.EvalLazy)
|
||||
fmt.Printf("(are all forms in evaluated before function call)\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Printf("UNKNOWN SYMBOL\n")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -125,6 +125,7 @@ func Join(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
|||
* Example: (substr 1 5 "Linus Torvalds") -> "inus "
|
||||
*/
|
||||
func Substr(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||
start := in
|
||||
end := start.Next
|
||||
str := end.Next
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue