add rudimentary control flow

This commit is contained in:
Aidan 2020-06-30 20:27:12 -07:00
parent de5566b3ec
commit a216d9af41
No known key found for this signature in database
GPG key ID: 327711E983899316
3 changed files with 115 additions and 1 deletions

View file

@ -26,7 +26,28 @@ import (
func GenFuncTable() ast.FuncTable {
var stdlib ast.FuncTable
stdlib = &map[string]*ast.Function{
"...": &ast.Function{
"if": &ast.Function{
Function: shs_if,
Name: "if",
TimesCalled: 0,
Args: 3,
},
"while": &ast.Function{
Function: shs_while,
Name: "while",
TimesCalled: 0,
Args: -1,
},
"eval": &ast.Function{
Function: eval,
Name: "eval",
TimesCalled: 0,
Args: -1,
},
"...": &ast.Function{
Function: expand,
Name: "...",
TimesCalled: 0,
@ -242,3 +263,7 @@ func sh_info(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
return nil
}
func eval(in *ast.Token, vt ast.VarTable, ft ast.VarTable) *ast.Token {
return in.Eval(ft, vt, false)
}