-
Notifications
You must be signed in to change notification settings - Fork 1
/
console.go
58 lines (52 loc) · 1.13 KB
/
console.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"os"
"github.com/SHDMT/gravity/platform/smartcontract/vm/lispvm/lisp"
"github.com/SHDMT/gravity/platform/smartcontract/vm/lispvm/lisp/math"
)
var env *lisp.Lisp
//main provides a console program to test lisp
func main() {
l := len(os.Args) - 1
if l > 0 {
for _, f := range os.Args[1:l] {
env.Eval([]byte(`(load "` + f + `")`))
}
if os.Args[l] != "-" {
env.Eval([]byte(`(println (load "` + os.Args[l] + `"))`))
return
}
}
env.Eval([]byte(`
(loop
()
1
(each
(println "==>")
(catch
(error
(println (scan))
)
)
)
)`))
}
func init() {
lisp.Add("sin", math.Sin)
lisp.Add("sinh", math.Sinh)
lisp.Add("asin", math.Asin)
lisp.Add("asinh", math.Asinh)
lisp.Add("cos", math.Cos)
lisp.Add("cosh", math.Cosh)
lisp.Add("acos", math.Acos)
lisp.Add("acosh", math.Acosh)
lisp.Add("tan", math.Tan)
lisp.Add("tanh", math.Tanh)
lisp.Add("atan", math.Atan)
lisp.Add("atanh", math.Atanh)
lisp.Add("exp", math.Exp)
lisp.Add("log", math.Log)
lisp.Add("pow", math.Pow)
lisp.Add("sqrt", math.Sqrt)
env = lisp.NewLisp()
}