mirror of
https://github.com/hymkor/lispect.git
synced 2026-08-28 04:46:59 -04:00
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/hymkor/gmnlisp"
|
|
)
|
|
|
|
func mains(args []string) error {
|
|
term, err := NewTerm()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer term.Close()
|
|
|
|
watcher := NewWatcher(term)
|
|
|
|
g := &Global{
|
|
term: term,
|
|
w: watcher,
|
|
}
|
|
defer g.Close()
|
|
|
|
lisp := gmnlisp.New()
|
|
|
|
lisp = lisp.Flet(
|
|
gmnlisp.Functions{
|
|
gmnlisp.NewSymbol("send"): gmnlisp.Function1(g.send),
|
|
gmnlisp.NewSymbol("sendln"): gmnlisp.Function1(g.sendln),
|
|
gmnlisp.NewSymbol("spawn"): &gmnlisp.Function{Min: 1, F: g.spawn},
|
|
gmnlisp.NewSymbol("expect*"): gmnlisp.SpecialF(g.expectX),
|
|
gmnlisp.NewSymbol("expect"): gmnlisp.SpecialF(g.expect),
|
|
gmnlisp.NewSymbol("getenv"): gmnlisp.Function1(g.getenv),
|
|
})
|
|
|
|
if len(args) <= 0 {
|
|
return errors.New("script path required")
|
|
}
|
|
script, err := os.ReadFile(args[0])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
posixArgv := []gmnlisp.Node{}
|
|
for _, s := range args {
|
|
posixArgv = append(posixArgv, gmnlisp.String(s))
|
|
}
|
|
lisp = lisp.Let(&gmnlisp.Pair{Key: gmnlisp.NewSymbol("args"), Value: gmnlisp.List(posixArgv...)})
|
|
|
|
_, err = lisp.Interpret(context.Background(), string(script))
|
|
return err
|
|
}
|
|
|
|
func main() {
|
|
if err := mains(os.Args[1:]); err != nil {
|
|
fmt.Fprintln(os.Stderr, err.Error())
|
|
os.Exit(1)
|
|
}
|
|
}
|