SimpleFuncStore is now derived from SimpleVarStore

This commit is contained in:
Celestino Amoroso 2024-04-06 01:07:06 +02:00
parent 0ba96e65a5
commit 7f9d7690f9

View File

@ -1,10 +1,10 @@
// simple-var-store.go // simple-func-store.go
package expr package expr
import "fmt" import "fmt"
type SimpleFuncStore struct { type SimpleFuncStore struct {
varStore map[string]any SimpleVarStore
funcStore map[string]*funcInfo funcStore map[string]*funcInfo
} }
@ -33,41 +33,18 @@ func (info *funcInfo) Functor() Functor {
func NewSimpleFuncStore() *SimpleFuncStore { func NewSimpleFuncStore() *SimpleFuncStore {
return &SimpleFuncStore{ return &SimpleFuncStore{
varStore: make(map[string]any), SimpleVarStore: SimpleVarStore{varStore: make(map[string]any)},
funcStore: make(map[string]*funcInfo), funcStore: make(map[string]*funcInfo),
} }
} }
func (ctx *SimpleFuncStore) Clone() exprContext { func (ctx *SimpleFuncStore) Clone() exprContext {
return &SimpleFuncStore{ return &SimpleFuncStore{
varStore: CloneMap(ctx.varStore), SimpleVarStore: SimpleVarStore{varStore: CloneMap(ctx.varStore)},
funcStore: CloneMap(ctx.funcStore), funcStore: CloneMap(ctx.funcStore),
} }
} }
func (ctx *SimpleFuncStore) GetVar(varName string) (v any, exists bool) {
v, exists = ctx.varStore[varName]
return
}
func (ctx *SimpleFuncStore) SetVar(varName string, value any) {
ctx.varStore[varName] = value
}
func (ctx *SimpleFuncStore) EnumVars(acceptor func(name string) (accept bool)) (varNames []string) {
varNames = make([]string, 0)
for name := range ctx.varStore {
if acceptor != nil {
if acceptor(name) {
varNames = append(varNames, name)
}
} else {
varNames = append(varNames, name)
}
}
return
}
func (ctx *SimpleFuncStore) GetFuncInfo(name string) (info exprFunc) { func (ctx *SimpleFuncStore) GetFuncInfo(name string) (info exprFunc) {
info, _ = ctx.funcStore[name] info, _ = ctx.funcStore[name]
return return