add info func

This commit is contained in:
Aidan 2020-06-29 21:21:30 -07:00
parent c726520689
commit de5566b3ec
No known key found for this signature in database
GPG key ID: 327711E983899316
2 changed files with 45 additions and 1 deletions

View file

@ -31,7 +31,14 @@ import (
var bgProcs = make([]*exec.Cmd, 0) var bgProcs = make([]*exec.Cmd, 0)
var LastExitCode int var LastExitCode int
var sigs = []os.Signal{os.Interrupt, syscall.SIGTERM, syscall.SIGTSTP, syscall.SIGTTIN, syscall.SIGTTOU, syscall.SIGCONT} 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 { func call(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {

View file

@ -19,6 +19,7 @@ package stdlib
import ( import (
"os" "os"
"fmt"
"gitlab.com/whom/shs/ast" "gitlab.com/whom/shs/ast"
) )
@ -196,6 +197,12 @@ func GenFuncTable() ast.FuncTable {
Args: 0, Args: 0,
}, },
"info": &ast.Function{
Function: sh_info,
Name: "Shell Info",
TimesCalled: 0,
Args: 1,
},
} }
return stdlib return stdlib
@ -205,3 +212,33 @@ func exit_shell(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
os.Exit(0) os.Exit(0)
return nil // I hope execution doesnt get here return nil // I hope execution doesnt get here
} }
func sh_info(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.Args)
break
}
fmt.Printf("UNKNOWN SYMBOL\n")
}
return nil
}