-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevie.go
73 lines (57 loc) · 1.67 KB
/
evie.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// contains package level state which means you cannot have multiple instance of evie running at the same time,
// this was done for performance reasons and for a lack of a better way to make concurrency work with struct level state
package evie
import (
"github.com/hk-32/evie/internal/ast"
"github.com/hk-32/evie/internal/core"
"github.com/hk-32/evie/internal/parser"
"github.com/hk-32/evie/std"
"github.com/hk-32/evie/std/builtin"
"github.com/hk-32/evie/std/fs"
"github.com/hk-32/evie/std/time"
)
type Options struct {
Optimise bool // use specialised instructions
PrintCode bool // print the resulting byte-code
TimeIt bool // measure the execution time
ObserveIt bool // collect metrics (affects performance)
TopLevelLogic bool // whether to only allow declarations at top level
Exports map[string]core.Value // what should be made available to the user
}
var Defaults = Options{Optimise: true, Exports: DefaultExports()}
func DefaultExports() map[string]core.Value {
std.Exports = map[string]core.Value{}
fs.Export()
time.Export()
builtin.Export()
return std.Exports
}
func Setup(opts Options) {
ast.Setup(opts.Optimise, opts.Exports)
if opts.ObserveIt {
core.WrapInstructions(func(rt *core.CoRoutine) {
}, func(rt *core.CoRoutine) {
})
}
}
func Reset() {
}
func FeedCode(input []byte) (core.Value, error) {
output, err := parser.Parse(input)
if err != nil {
return core.Value{}, err
}
return ast.Feed(output)
}
func GetGlobal(name string) *core.Value {
return ast.GetGlobal(name)
}
func WaitForNoActivity() {
core.WaitForNoActivity()
}
func DumpCode() {
core.DumpCode()
}
func PrintInstructionStats() {
core.PrintInstructionRuns()
}