fix build from last night

This commit is contained in:
Aidan 2020-08-21 17:37:54 -07:00
parent ab340ceb0a
commit 87004ff7fd
No known key found for this signature in database
GPG key ID: 327711E983899316
6 changed files with 210 additions and 213 deletions

View file

@ -18,7 +18,6 @@
package ast package ast
import ( import (
"fmt"
"gitlab.com/whom/shs/log" "gitlab.com/whom/shs/log"
) )
@ -40,7 +39,7 @@ type Function struct {
// list of types (LIST, NUMBER, STRING, etc) representing args // list of types (LIST, NUMBER, STRING, etc) representing args
Args []Token_t Args []Token_t
NumArgs bool // -1 means infinite NumArgs int // -1 means infinite
// lazy arg checking (use NumArgs instead of args) // lazy arg checking (use NumArgs instead of args)
ArgLazy bool ArgLazy bool
@ -62,7 +61,7 @@ type FuncTable *map[string]*Function
* makes sure correct arguments are passed in * makes sure correct arguments are passed in
*/ */
func (f Function) ParseFunction(args *Token) bool { func (f Function) ParseFunction(args *Token) bool {
total = len(f.Args) total := len(f.Args)
for iter := args; iter != nil; iter = iter.Next { for iter := args; iter != nil; iter = iter.Next {
total -= 1 total -= 1
if total <= 0 { if total <= 0 {
@ -88,7 +87,7 @@ func (f Function) ParseFunction(args *Token) bool {
/* same as ParseFunction but only evaluates the number of args /* same as ParseFunction but only evaluates the number of args
*/ */
func (f Function) LazyParseFunction(args *Token) bool { func (f Function) LazyParseFunction(args *Token) bool {
if (f.NumArgs < 0) { if f.NumArgs < 0 {
return true return true
} }
@ -118,15 +117,15 @@ func (f Function) LazyParseFunction(args *Token) bool {
* calls ParseFunction and increments TimesCalled * calls ParseFunction and increments TimesCalled
*/ */
func (f Function) CallFunction(args *Token, vt VarTable, ft FuncTable) *Token { 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) args = args.Eval(ft, vt, !f.SymLazy)
} }
passes := false passes := false
if f.ArgsLazy { if f.ArgLazy {
passes = LazyParseFunction(args) passes = f.LazyParseFunction(args)
} else { } else {
passes = ParseFunction(args) passes = f.ParseFunction(args)
} }
if passes { if passes {

View file

@ -95,7 +95,7 @@ func main() {
} }
dyn_prompt := ast.GetFunction("_SH_PROMPT", funcs) 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 dyn_prompt = nil
} }

View file

@ -114,7 +114,7 @@ func DeclFunc(input *ast.Token, vars ast.VarTable, funcs ast.FuncTable) *ast.Tok
Name: name.Value(), Name: name.Value(),
TimesCalled: 0, TimesCalled: 0,
NumArgs: numArgs, NumArgs: numArgs,
LazyArgs: true ArgLazy: true,
} }
return nil return nil
} }

View file

@ -82,7 +82,7 @@ func Len(input *ast.Token, vars ast.VarTable, funcs ast.FuncTable) *ast.Token {
} }
length := 0 length := 0
if input.Tag = ast.STRING { if input.Tag == ast.STRING {
length = len(input.Value()) length = len(input.Value())
} else { } else {

View file

@ -20,7 +20,6 @@ package stdlib
import ( import (
"os" "os"
"fmt" "fmt"
"gitlab.com/whom/shs/log"
"gitlab.com/whom/shs/ast" "gitlab.com/whom/shs/ast"
"gitlab.com/whom/shs/util" "gitlab.com/whom/shs/util"
) )
@ -35,16 +34,16 @@ func GenFuncTable() ast.FuncTable {
Function: ShsIf, Function: ShsIf,
Name: "if", Name: "if",
NumArgs: 3, NumArgs: 3,
EvalLazy true, EvalLazy: true,
ArgLazy true ArgLazy: true,
}, },
"while": &ast.Function{ "while": &ast.Function{
Function: ShsWhile, Function: ShsWhile,
Name: "while", Name: "while",
NumArgs: -1, NumArgs: -1,
EvalLazy true, EvalLazy: true,
ArgLazy true, ArgLazy: true,
}, },
"progn": &ast.Function{ "progn": &ast.Function{
@ -61,7 +60,7 @@ func GenFuncTable() ast.FuncTable {
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.STRING, ast.STRING,
ast.LIST, ast.LIST,
ast.LIST ast.LIST,
}, },
EvalLazy: true, EvalLazy: true,
}, },
@ -77,7 +76,7 @@ func GenFuncTable() ast.FuncTable {
Function: Head, Function: Head,
Name: "head", Name: "head",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.LIST ast.LIST,
}, },
}, },
@ -85,7 +84,7 @@ func GenFuncTable() ast.FuncTable {
Function: Tail, Function: Tail,
Name: "tail", Name: "tail",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.LIST ast.LIST,
}, },
}, },
@ -95,17 +94,17 @@ func GenFuncTable() ast.FuncTable {
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.NUMBER, ast.NUMBER,
ast.NUMBER, ast.NUMBER,
ast.LIST ast.LIST,
}, },
}, },
"export": &ast.Function{ "export": &ast.Function{
Function: Export, Function: Export,
Name: "export", Name: "export",
LazyEval: true, EvalLazy: true,
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.STRING, ast.STRING,
ast.LIST ast.LIST,
}, },
}, },
@ -113,7 +112,7 @@ func GenFuncTable() ast.FuncTable {
Function: Input, Function: Input,
Name: "input", Name: "input",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.STRING ast.STRING,
}, },
}, },
@ -121,7 +120,7 @@ func GenFuncTable() ast.FuncTable {
Function: Load, Function: Load,
Name: "load", Name: "load",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.STRING ast.STRING,
}, },
}, },
@ -129,7 +128,7 @@ func GenFuncTable() ast.FuncTable {
Function: BoolCast, Function: BoolCast,
Name: "bool", Name: "bool",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.STRING ast.STRING,
}, },
}, },
@ -143,8 +142,8 @@ func GenFuncTable() ast.FuncTable {
"number": &ast.Function{ "number": &ast.Function{
Function: NumCast, Function: NumCast,
Name: "number", Name: "number",
Args: []ast.Token{ Args: []ast.Token_t{
ast.NUMBER ast.NUMBER,
}, },
}, },
@ -152,7 +151,7 @@ func GenFuncTable() ast.FuncTable {
Function: Expand, Function: Expand,
Name: "...", Name: "...",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.LIST ast.LIST,
}, },
}, },
@ -168,16 +167,16 @@ func GenFuncTable() ast.FuncTable {
Name: "join", Name: "join",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.STRING, ast.STRING,
ast.LIST ast.LIST,
}, },
}, },
"split": &ast.Function{ "split": &ast.Function{
Function: Split, Function: Split,
Name: "split", Name: "split",
Args: ast.Token_t{ Args: []ast.Token_t{
ast.STRING,
ast.STRING, ast.STRING,
ast.STRING
}, },
}, },
@ -187,7 +186,7 @@ func GenFuncTable() ast.FuncTable {
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.NUMBER, ast.NUMBER,
ast.NUMBER, ast.NUMBER,
ast.STRING ast.STRING,
}, },
}, },
@ -200,14 +199,14 @@ func GenFuncTable() ast.FuncTable {
"eq": &ast.Function{ "eq": &ast.Function{
Function: Eq, Function: Eq,
Name: "==", Name: "==",
Args: 2, NumArgs: 2,
ArgLazy: true, ArgLazy: true,
}, },
"ne": &ast.Function{ "ne": &ast.Function{
Function: Ne, Function: Ne,
Name: "!=", Name: "!=",
Args: 2, NumArgs: 2,
ArgLazy: true, ArgLazy: true,
}, },
@ -216,7 +215,7 @@ func GenFuncTable() ast.FuncTable {
Name: "<", Name: "<",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.NUMBER, ast.NUMBER,
ast.NUMBER ast.NUMBER,
}, },
}, },
@ -225,7 +224,7 @@ func GenFuncTable() ast.FuncTable {
Name: ">", Name: ">",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.NUMBER, ast.NUMBER,
ast.NUMBER ast.NUMBER,
}, },
}, },
@ -234,7 +233,7 @@ func GenFuncTable() ast.FuncTable {
Name: "<=", Name: "<=",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.NUMBER, ast.NUMBER,
ast.NUMBER ast.NUMBER,
}, },
}, },
@ -243,7 +242,7 @@ func GenFuncTable() ast.FuncTable {
Name: ">=", Name: ">=",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.NUMBER, ast.NUMBER,
ast.NUMBER ast.NUMBER,
}, },
}, },
@ -251,7 +250,7 @@ func GenFuncTable() ast.FuncTable {
Function: Not, Function: Not,
Name: "!", Name: "!",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.Bool ast.BOOL,
}, },
}, },
@ -287,13 +286,13 @@ func GenFuncTable() ast.FuncTable {
Function: Cd, Function: Cd,
Name: "changedir", Name: "changedir",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.STRING ast.STRING,
}, },
}, },
"concat": &ast.Function{ "concat": &ast.Function{
Function: Concat, Function: Concat,
Name:"concatenate", Name: "concatenate",
NumArgs: -1, NumArgs: -1,
ArgLazy: true, ArgLazy: true,
}, },
@ -302,7 +301,7 @@ func GenFuncTable() ast.FuncTable {
Function: PrintStr, Function: PrintStr,
Name: "print", Name: "print",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.STRING ast.STRING,
}, },
}, },
@ -325,23 +324,23 @@ func GenFuncTable() ast.FuncTable {
"fg": &ast.Function{ "fg": &ast.Function{
Function: Fg, Function: Fg,
Name: "foreground", Name: "foreground",
NumArgs: []ast.Token_t{ Args: []ast.Token_t{
ast.NUMBER ast.NUMBER,
}, },
}, },
"$": &ast.Function{ "$": &ast.Function{
Function: ReadCmd, Function: ReadCmd,
Name: "read cmd", Name: "read cmd",
NumnArgs: -1, NumArgs: -1,
ArgLazy: true, ArgLazy: true,
SymLazy: true, SymLazy: true,
}, },
"?": &ast.Function{ "?": &ast.Function{
Function: GetExit, Function: GetExit,
Name:"get exit code", Name: "get exit code",
Args: ast.Token_t{}, Args: []ast.Token_t{},
}, },
/* /*
@ -356,14 +355,14 @@ func GenFuncTable() ast.FuncTable {
"jobs": &ast.Function{ "jobs": &ast.Function{
Function: Jobs, Function: Jobs,
Name: "list jobs", Name: "list jobs",
Args: ast.Token_t{}, Args: []ast.Token_t{},
}, },
"info": &ast.Function{ "info": &ast.Function{
Function: ShInfo, Function: ShInfo,
Name: "Shell Info", Name: "Shell Info",
Args: ast.Token_t{ Args: []ast.Token_t{
ast.SYMBOL ast.SYMBOL,
}, },
}, },
@ -371,7 +370,7 @@ func GenFuncTable() ast.FuncTable {
Function: Fexists, Function: Fexists,
Name: "file exists", Name: "file exists",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.STRING ast.STRING,
}, },
}, },
@ -379,7 +378,7 @@ func GenFuncTable() ast.FuncTable {
Function: Fread, Function: Fread,
Name: "read file", Name: "read file",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.STRING ast.STRING,
}, },
}, },
@ -388,16 +387,16 @@ func GenFuncTable() ast.FuncTable {
Name: "write file", Name: "write file",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.STRING, ast.STRING,
ast.STRING ast.STRING,
}, },
}, },
"fappend": &ast.Function{ "fappend": &ast.Function{
Function: Fappend, Function: Fappend,
Name:"append to file", Name: "append to file",
Args: []ast.Token_t{ Args: []ast.Token_t{
ast.STRING, 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) * Example: (info append)
*/ */
func ShInfo(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token { 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) repr := ast.GetVar(in.Value(), vt)
if repr != nil { if repr != nil {
fmt.Printf("VARIABLE\nTYPE: %s\nVALUE: %s\n", ast.GetTagAsStr(repr.Tag), repr.Value()) fmt.Printf("VARIABLE\nTYPE: %s\nVALUE: %s\n", ast.GetTagAsStr(repr.Tag), repr.Value())
break return nil
} }
funct := ast.GetFunction(in.Value(), ft) funct := ast.GetFunction(in.Value(), ft)
if funct != nil { if funct != nil {
fmt.Printf("FUNCTION\nNAME: %s\nTIMES CALLED: %s\nNUM ARGS: %d\n", funct.Name, funct.TimesCalled, funct.NumArgs) fmt.Printf("FUNCTION\nNAME: %s\nTIMES CALLED: %s\n\n", funct.Name, funct.TimesCalled)
break 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") fmt.Printf("UNKNOWN SYMBOL\n")
}
return nil return nil
} }

View file

@ -125,6 +125,7 @@ func Join(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
* Example: (substr 1 5 "Linus Torvalds") -> "inus " * Example: (substr 1 5 "Linus Torvalds") -> "inus "
*/ */
func Substr(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token { func Substr(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
start := in
end := start.Next end := start.Next
str := end.Next str := end.Next