add info func
This commit is contained in:
parent
c726520689
commit
de5566b3ec
2 changed files with 45 additions and 1 deletions
|
|
@ -19,6 +19,7 @@ package stdlib
|
|||
|
||||
import (
|
||||
"os"
|
||||
"fmt"
|
||||
"gitlab.com/whom/shs/ast"
|
||||
)
|
||||
|
||||
|
|
@ -196,6 +197,12 @@ func GenFuncTable() ast.FuncTable {
|
|||
Args: 0,
|
||||
},
|
||||
|
||||
"info": &ast.Function{
|
||||
Function: sh_info,
|
||||
Name: "Shell Info",
|
||||
TimesCalled: 0,
|
||||
Args: 1,
|
||||
},
|
||||
}
|
||||
|
||||
return stdlib
|
||||
|
|
@ -205,3 +212,33 @@ func exit_shell(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
|||
os.Exit(0)
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue