export var functions

This commit is contained in:
Aidan 2020-07-03 16:27:02 -07:00
parent a08677b4f4
commit 4865c7ce92
No known key found for this signature in database
GPG key ID: 327711E983899316
5 changed files with 33 additions and 3 deletions

View file

@ -65,6 +65,15 @@ We also have functioning implementations of map and reduce in the stdlib
- `SHS_SH_PROMPT` Sets the prompt
- `SH_HIST_FILE` Sets the history file
- `SH_DEBUG_MODE` Adds additional debug output for the lexer
Here is an example of a shs configuration file:
```lisp
(export "GOPATH" (concat HOME "/go"))
(export "GOBIN" (concat GOPATH "/bin"))
(export "PATH" (concat PATH ":" GOBIN))
(export "GIT_TERMINAL_PROMPT" 1)
(export "SH_HIST_FILE" (concat HOME "/.shs_hist"))
(export "SH_LOGGING" 3)
```
## Contributing
- Any contribution to this software is welcome as long as it adheres to the conduct guidelines specified in the `Contributing.md` file in this repository.

View file

@ -43,7 +43,7 @@ func (f Function) ParseFunction(args *Token) bool {
}
if i != 0 {
log.Log(log.ERR,
log.Log(log.ERR,
"Incorrect number of arguments",
"eval")
return false
@ -69,7 +69,7 @@ func GetFunction(arg string, table FuncTable) *Function {
if !ok {
log.Log(log.DEBUG,
"function " + arg + " not found",
"eval")
"ftable")
return nil
}

View file

@ -56,7 +56,6 @@ func GetVar(arg string, vt VarTable) *Token {
}
// TODO: this could be much more optimal
// TODO: Make sure variables are evaluated before being set
// probably a stdlib thing
func SetVar(variable string, value *Token, vt VarTable) {
(*vt)[variable] = value

View file

@ -48,6 +48,13 @@ func GenFuncTable() ast.FuncTable {
Args: -1,
},
"export": &ast.Function{
Function: export,
Name: "export",
TimesCalled: 0,
Args: 2,
},
"input": &ast.Function{
Function: input,
Name: "input",

View file

@ -22,4 +22,19 @@ import (
"gitlab.com/whom/shs/log"
)
func export(input *ast.Token, vars ast.VarTable, funcs ast.FuncTable) *ast.Token {
input = input.Eval(funcs, vars, false)
name := input
form := name.Next
if name.Tag != ast.STRING {
log.Log(log.ERR,
"non string handed to name arg",
"export")
return nil
}
ast.SetVar(name.Value(), form, vars)
return nil
}