/
registry.go
84 lines (66 loc) · 2.39 KB
/
registry.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
74
75
76
77
78
79
80
81
82
83
84
package eval
import (
"github.com/kocircuit/kocircuit/lang/circuit/eval"
"github.com/kocircuit/kocircuit/lang/go/gate"
)
var registry = NewEvalRegistry()
type EvalRegistry struct {
Registry *eval.Registry `ko:"name=registry"`
}
func NewEvalRegistry() *EvalRegistry {
return &EvalRegistry{
Registry: eval.NewRegistry(evalGateMacro{}),
}
}
// evalGateMacro is a helper to create a Macro from a Gate.
type evalGateMacro struct{}
func (evalGateMacro) GateMacro(g gate.Gate) eval.Macro {
return &EvalCallMacro{Gate: g}
}
// RegisterEvalGate registers an evaluation gate with the name and
// package of the given stub.
func (r *EvalRegistry) RegisterEvalGate(stub interface{}) {
r.Registry.RegisterGate(stub)
}
// RegisterNamedEvalGate registers an evaluation gate with the given name in
// the package of the given stub.
func (r *EvalRegistry) RegisterNamedEvalGate(name string, stub interface{}) {
r.Registry.RegisterNamedGate(name, stub)
}
// RegisterEvalGateAt registers an evaluation gate with given name in the given package.
func (r *EvalRegistry) RegisterEvalGateAt(pkg, name string, stub interface{}) {
r.Registry.RegisterGateAt(pkg, name, stub)
}
func (r *EvalRegistry) RegisterEvalMacro(name string, macro eval.Macro) {
r.Registry.RegisterMacro(name, macro)
}
func (r *EvalRegistry) RegisterEvalPkgMacro(pkg, name string, macro eval.Macro) {
r.Registry.RegisterPkgMacro(pkg, name, macro)
}
func (r *EvalRegistry) Snapshot() eval.Faculty {
return r.Registry.Snapshot()
}
func EvalFaculty() eval.Faculty {
return registry.Snapshot()
}
// RegisterEvalGate registers an evaluation gate in the default registry
// with the name and package of the given stub.
func RegisterEvalGate(stub interface{}) {
registry.RegisterEvalGate(stub)
}
// RegisterNamedEvalGate registers an evaluation gate in the default registry
// with the given name in the package of the given stub.
func RegisterNamedEvalGate(name string, stub interface{}) {
registry.RegisterNamedEvalGate(name, stub)
}
// RegisterEvalGateAt registers an evaluation gate in the default registry
// with given name in the given package.
func RegisterEvalGateAt(pkg, name string, stub interface{}) {
registry.RegisterEvalGateAt(pkg, name, stub)
}
func RegisterEvalMacro(name string, macro eval.Macro) {
registry.RegisterEvalMacro(name, macro)
}
func RegisterEvalPkgMacro(pkg, name string, macro eval.Macro) {
registry.RegisterEvalPkgMacro(pkg, name, macro)
}