fix build from last night
This commit is contained in:
parent
ab340ceb0a
commit
87004ff7fd
6 changed files with 210 additions and 213 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
401
stdlib/stdlib.go
401
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"
|
||||
)
|
||||
|
|
@ -32,316 +31,316 @@ func GenFuncTable() ast.FuncTable {
|
|||
var stdlib ast.FuncTable
|
||||
stdlib = &map[string]*ast.Function{
|
||||
"if": &ast.Function{
|
||||
Function: ShsIf,
|
||||
Function: ShsIf,
|
||||
Name: "if",
|
||||
NumArgs: 3,
|
||||
EvalLazy true,
|
||||
ArgLazy true
|
||||
NumArgs: 3,
|
||||
EvalLazy: true,
|
||||
ArgLazy: true,
|
||||
},
|
||||
|
||||
"while": &ast.Function{
|
||||
Function: ShsWhile,
|
||||
Function: ShsWhile,
|
||||
Name: "while",
|
||||
NumArgs: -1,
|
||||
EvalLazy true,
|
||||
ArgLazy true,
|
||||
NumArgs: -1,
|
||||
EvalLazy: true,
|
||||
ArgLazy: true,
|
||||
},
|
||||
|
||||
"progn": &ast.Function{
|
||||
Function: ShsProgn,
|
||||
Name: "shs_progn",
|
||||
NumArgs: -1,
|
||||
EvalLazy: true,
|
||||
ArgLazy: true,
|
||||
Name: "shs_progn",
|
||||
NumArgs: -1,
|
||||
EvalLazy: true,
|
||||
ArgLazy: true,
|
||||
},
|
||||
|
||||
"func": &ast.Function{
|
||||
Function: DeclFunc,
|
||||
Name: "decl_func",
|
||||
Args: []ast.Token_t{
|
||||
Function: DeclFunc,
|
||||
Name: "decl_func",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING,
|
||||
ast.LIST,
|
||||
ast.LIST
|
||||
ast.LIST,
|
||||
},
|
||||
EvalLazy: true,
|
||||
EvalLazy: true,
|
||||
},
|
||||
|
||||
"len": &ast.Function{
|
||||
Function: Len,
|
||||
Name: "len",
|
||||
NumArgs: 1,
|
||||
ArgLazy: true,
|
||||
Function: Len,
|
||||
Name: "len",
|
||||
NumArgs: 1,
|
||||
ArgLazy: true,
|
||||
},
|
||||
|
||||
"head": &ast.Function{
|
||||
Function: Head,
|
||||
Function: Head,
|
||||
Name: "head",
|
||||
Args: []ast.Token_t{
|
||||
ast.LIST
|
||||
Args: []ast.Token_t{
|
||||
ast.LIST,
|
||||
},
|
||||
},
|
||||
|
||||
"tail": &ast.Function{
|
||||
Function: Tail,
|
||||
Name: "tail",
|
||||
Args: []ast.Token_t{
|
||||
ast.LIST
|
||||
Name: "tail",
|
||||
Args: []ast.Token_t{
|
||||
ast.LIST,
|
||||
},
|
||||
},
|
||||
|
||||
"slice": &ast.Function{
|
||||
Function: Slice,
|
||||
Name: "slice",
|
||||
Args: []ast.Token_t{
|
||||
Name: "slice",
|
||||
Args: []ast.Token_t{
|
||||
ast.NUMBER,
|
||||
ast.NUMBER,
|
||||
ast.LIST
|
||||
ast.LIST,
|
||||
},
|
||||
},
|
||||
|
||||
"export": &ast.Function{
|
||||
Function: Export,
|
||||
Name: "export",
|
||||
LazyEval: true,
|
||||
Args: []ast.Token_t{
|
||||
Function: Export,
|
||||
Name: "export",
|
||||
EvalLazy: true,
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING,
|
||||
ast.LIST
|
||||
ast.LIST,
|
||||
},
|
||||
},
|
||||
|
||||
"input": &ast.Function{
|
||||
Function: Input,
|
||||
Name: "input",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING
|
||||
Function: Input,
|
||||
Name: "input",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING,
|
||||
},
|
||||
},
|
||||
|
||||
"load": &ast.Function{
|
||||
Function: Load,
|
||||
Name: "load",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING
|
||||
Function: Load,
|
||||
Name: "load",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING,
|
||||
},
|
||||
},
|
||||
|
||||
"bool": &ast.Function{
|
||||
Function: BoolCast,
|
||||
Name: "bool",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING
|
||||
Function: BoolCast,
|
||||
Name: "bool",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING,
|
||||
},
|
||||
},
|
||||
|
||||
"string": &ast.Function{
|
||||
Function: StrCast,
|
||||
Name: "string",
|
||||
NumArgs: 1,
|
||||
ArgLazy: true,
|
||||
Function: StrCast,
|
||||
Name: "string",
|
||||
NumArgs: 1,
|
||||
ArgLazy: true,
|
||||
},
|
||||
|
||||
"number": &ast.Function{
|
||||
Function: NumCast,
|
||||
Name: "number",
|
||||
Args: []ast.Token{
|
||||
ast.NUMBER
|
||||
Function: NumCast,
|
||||
Name: "number",
|
||||
Args: []ast.Token_t{
|
||||
ast.NUMBER,
|
||||
},
|
||||
},
|
||||
|
||||
"...": &ast.Function{
|
||||
Function: Expand,
|
||||
Name: "...",
|
||||
Args: []ast.Token_t{
|
||||
ast.LIST
|
||||
Function: Expand,
|
||||
Name: "...",
|
||||
Args: []ast.Token_t{
|
||||
ast.LIST,
|
||||
},
|
||||
},
|
||||
|
||||
"append": &ast.Function{
|
||||
Function: L_append,
|
||||
Name: "append",
|
||||
NumArgs: -1,
|
||||
ArgLazy: true,
|
||||
Function: L_append,
|
||||
Name: "append",
|
||||
NumArgs: -1,
|
||||
ArgLazy: true,
|
||||
},
|
||||
|
||||
"join": &ast.Function{
|
||||
Function: Join,
|
||||
Name: "join",
|
||||
Args: []ast.Token_t{
|
||||
Function: Join,
|
||||
Name: "join",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING,
|
||||
ast.LIST
|
||||
ast.LIST,
|
||||
},
|
||||
},
|
||||
|
||||
"split": &ast.Function{
|
||||
Function: Split,
|
||||
Name: "split",
|
||||
Args: ast.Token_t{
|
||||
Name: "split",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING,
|
||||
ast.STRING,
|
||||
ast.STRING
|
||||
},
|
||||
},
|
||||
|
||||
"substr": &ast.Function{
|
||||
Function: Substr,
|
||||
Name: "substr",
|
||||
Args: []ast.Token_t{
|
||||
Function: Substr,
|
||||
Name: "substr",
|
||||
Args: []ast.Token_t{
|
||||
ast.NUMBER,
|
||||
ast.NUMBER,
|
||||
ast.STRING
|
||||
ast.STRING,
|
||||
},
|
||||
},
|
||||
|
||||
"exit": &ast.Function{
|
||||
Function: ExitShell,
|
||||
Name: "exit",
|
||||
Args: []ast.Token_t{},
|
||||
Function: ExitShell,
|
||||
Name: "exit",
|
||||
Args: []ast.Token_t{},
|
||||
},
|
||||
|
||||
"eq": &ast.Function{
|
||||
Function: Eq,
|
||||
Name: "==",
|
||||
Args: 2,
|
||||
ArgLazy: true,
|
||||
Function: Eq,
|
||||
Name: "==",
|
||||
NumArgs: 2,
|
||||
ArgLazy: true,
|
||||
},
|
||||
|
||||
"ne": &ast.Function{
|
||||
Function: Ne,
|
||||
Name: "!=",
|
||||
Args: 2,
|
||||
ArgLazy: true,
|
||||
Function: Ne,
|
||||
Name: "!=",
|
||||
NumArgs: 2,
|
||||
ArgLazy: true,
|
||||
},
|
||||
|
||||
"<": &ast.Function{
|
||||
Function: Lt,
|
||||
Name: "<",
|
||||
Args: []ast.Token_t{
|
||||
Function: Lt,
|
||||
Name: "<",
|
||||
Args: []ast.Token_t{
|
||||
ast.NUMBER,
|
||||
ast.NUMBER,
|
||||
ast.NUMBER
|
||||
},
|
||||
},
|
||||
|
||||
">": &ast.Function{
|
||||
Function: Gt,
|
||||
Name: ">",
|
||||
Args: []ast.Token_t{
|
||||
Function: Gt,
|
||||
Name: ">",
|
||||
Args: []ast.Token_t{
|
||||
ast.NUMBER,
|
||||
ast.NUMBER,
|
||||
ast.NUMBER
|
||||
},
|
||||
},
|
||||
|
||||
"<=": &ast.Function{
|
||||
Function: Lte,
|
||||
Name: "<=",
|
||||
Args: []ast.Token_t{
|
||||
Function: Lte,
|
||||
Name: "<=",
|
||||
Args: []ast.Token_t{
|
||||
ast.NUMBER,
|
||||
ast.NUMBER,
|
||||
ast.NUMBER
|
||||
},
|
||||
},
|
||||
|
||||
">=": &ast.Function{
|
||||
Function: Gte,
|
||||
Name: ">=",
|
||||
Args: []ast.Token_t{
|
||||
Function: Gte,
|
||||
Name: ">=",
|
||||
Args: []ast.Token_t{
|
||||
ast.NUMBER,
|
||||
ast.NUMBER,
|
||||
ast.NUMBER
|
||||
},
|
||||
},
|
||||
|
||||
"!": &ast.Function{
|
||||
Function: Not,
|
||||
Name: "!",
|
||||
Args: []ast.Token_t{
|
||||
ast.Bool
|
||||
Function: Not,
|
||||
Name: "!",
|
||||
Args: []ast.Token_t{
|
||||
ast.BOOL,
|
||||
},
|
||||
},
|
||||
|
||||
"+": &ast.Function{
|
||||
Function: Add,
|
||||
Name: "add",
|
||||
NumArgs: -1,
|
||||
ArgLazy: true,
|
||||
Function: Add,
|
||||
Name: "add",
|
||||
NumArgs: -1,
|
||||
ArgLazy: true,
|
||||
},
|
||||
|
||||
"-": &ast.Function{
|
||||
Function: Sub,
|
||||
Name: "sub",
|
||||
NumArgs: -1,
|
||||
ArgLazy: true,
|
||||
Function: Sub,
|
||||
Name: "sub",
|
||||
NumArgs: -1,
|
||||
ArgLazy: true,
|
||||
},
|
||||
|
||||
"*": &ast.Function{
|
||||
Function: Mult,
|
||||
Function: Mult,
|
||||
Name: "mult",
|
||||
NumArgs: -1,
|
||||
ArgLazy: true,
|
||||
NumArgs: -1,
|
||||
ArgLazy: true,
|
||||
},
|
||||
|
||||
"/": &ast.Function{
|
||||
Function: Div,
|
||||
Name: "div",
|
||||
NumArgs: -1,
|
||||
ArgLazy: true,
|
||||
Function: Div,
|
||||
Name: "div",
|
||||
NumArgs: -1,
|
||||
ArgLazy: true,
|
||||
},
|
||||
|
||||
"cd": &ast.Function{
|
||||
Function: Cd,
|
||||
Name: "changedir",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING
|
||||
Function: Cd,
|
||||
Name: "changedir",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING,
|
||||
},
|
||||
},
|
||||
|
||||
"concat": &ast.Function{
|
||||
Function: Concat,
|
||||
Name:"concatenate",
|
||||
NumArgs: -1,
|
||||
ArgLazy: true,
|
||||
Name: "concatenate",
|
||||
NumArgs: -1,
|
||||
ArgLazy: true,
|
||||
},
|
||||
|
||||
"print": &ast.Function{
|
||||
Function: PrintStr,
|
||||
Name: "print",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING
|
||||
Function: PrintStr,
|
||||
Name: "print",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING,
|
||||
},
|
||||
},
|
||||
|
||||
"l": &ast.Function{
|
||||
Function: Call,
|
||||
Function: Call,
|
||||
Name: "call",
|
||||
NumArgs: -1,
|
||||
ArgLazy: true,
|
||||
SymLazy: true,
|
||||
NumArgs: -1,
|
||||
ArgLazy: true,
|
||||
SymLazy: true,
|
||||
},
|
||||
|
||||
"bg": &ast.Function{
|
||||
Function: Bgcall,
|
||||
Name: "background call",
|
||||
NumArgs: -1,
|
||||
ArgLazy: true,
|
||||
SymLazy: true,
|
||||
Function: Bgcall,
|
||||
Name: "background call",
|
||||
NumArgs: -1,
|
||||
ArgLazy: true,
|
||||
SymLazy: true,
|
||||
},
|
||||
|
||||
"fg": &ast.Function{
|
||||
Function: Fg,
|
||||
Name: "foreground",
|
||||
NumArgs: []ast.Token_t{
|
||||
ast.NUMBER
|
||||
Function: Fg,
|
||||
Name: "foreground",
|
||||
Args: []ast.Token_t{
|
||||
ast.NUMBER,
|
||||
},
|
||||
},
|
||||
|
||||
"$": &ast.Function{
|
||||
Function: ReadCmd,
|
||||
Name: "read cmd",
|
||||
NumnArgs: -1,
|
||||
ArgLazy: true,
|
||||
SymLazy: true,
|
||||
Function: ReadCmd,
|
||||
Name: "read cmd",
|
||||
NumArgs: -1,
|
||||
ArgLazy: true,
|
||||
SymLazy: true,
|
||||
},
|
||||
|
||||
"?": &ast.Function{
|
||||
Function: GetExit,
|
||||
Name:"get exit code",
|
||||
Args: ast.Token_t{},
|
||||
Function: GetExit,
|
||||
Name: "get exit code",
|
||||
Args: []ast.Token_t{},
|
||||
},
|
||||
|
||||
/*
|
||||
|
|
@ -354,50 +353,50 @@ func GenFuncTable() ast.FuncTable {
|
|||
*/
|
||||
|
||||
"jobs": &ast.Function{
|
||||
Function: Jobs,
|
||||
Name: "list jobs",
|
||||
Args: ast.Token_t{},
|
||||
Function: Jobs,
|
||||
Name: "list jobs",
|
||||
Args: []ast.Token_t{},
|
||||
},
|
||||
|
||||
"info": &ast.Function{
|
||||
Function: ShInfo,
|
||||
Name: "Shell Info",
|
||||
Args: ast.Token_t{
|
||||
ast.SYMBOL
|
||||
Function: ShInfo,
|
||||
Name: "Shell Info",
|
||||
Args: []ast.Token_t{
|
||||
ast.SYMBOL,
|
||||
},
|
||||
},
|
||||
|
||||
"fexists": &ast.Function{
|
||||
Function: Fexists,
|
||||
Name: "file exists",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING
|
||||
Function: Fexists,
|
||||
Name: "file exists",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING,
|
||||
},
|
||||
},
|
||||
|
||||
"fread": &ast.Function{
|
||||
Function: Fread,
|
||||
Name: "read file",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING
|
||||
Function: Fread,
|
||||
Name: "read file",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING,
|
||||
},
|
||||
},
|
||||
|
||||
"fwrite": &ast.Function{
|
||||
Function: Fwrite,
|
||||
Name: "write file",
|
||||
Args: []ast.Token_t{
|
||||
Function: Fwrite,
|
||||
Name: "write file",
|
||||
Args: []ast.Token_t{
|
||||
ast.STRING,
|
||||
ast.STRING,
|
||||
ast.STRING
|
||||
},
|
||||
},
|
||||
|
||||
"fappend": &ast.Function{
|
||||
Function: Fappend,
|
||||
Name:"append to file",
|
||||
Args: []ast.Token_t{
|
||||
Function: Fappend,
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// TODO: print func args
|
||||
|
||||
fmt.Printf("UNKNOWN SYMBOL\n")
|
||||
repr := ast.GetVar(in.Value(), vt)
|
||||
if repr != nil {
|
||||
fmt.Printf("VARIABLE\nTYPE: %s\nVALUE: %s\n", ast.GetTagAsStr(repr.Tag), repr.Value())
|
||||
return nil
|
||||
}
|
||||
|
||||
funct := ast.GetFunction(in.Value(), ft)
|
||||
if funct != nil {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
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