commit e626d4027c4ce30e1917abab896967e3726fd4bb
parent 4bd7742672fc8f9f0bfb75cbf5528098ee7998d9
Author: lash <dev@holbrook.no>
Date: Mon, 2 Sep 2024 03:22:45 +0100
Reimplement all engine constructors in examples
Diffstat:
18 files changed, 112 insertions(+), 151 deletions(-)
diff --git a/dev/interactive/main.go b/dev/interactive/main.go
@@ -7,39 +7,53 @@ import (
"os"
"git.defalsify.org/vise.git/engine"
+ "git.defalsify.org/vise.git/persist"
+ "git.defalsify.org/vise.git/resource"
"git.defalsify.org/vise.git/db"
fsdb "git.defalsify.org/vise.git/db/fs"
)
func main() {
- var store db.Db
var dir string
var root string
var size uint
var sessionId string
- var persist string
+ var persistDir string
flag.StringVar(&dir, "d", ".", "resource dir to read from")
flag.UintVar(&size, "s", 0, "max size of output")
flag.StringVar(&root, "root", "root", "entry point symbol")
flag.StringVar(&sessionId, "session-id", "default", "session id")
- flag.StringVar(&persist, "p", "", "state persistence directory")
+ flag.StringVar(&persistDir, "p", "", "state persistence directory")
flag.Parse()
fmt.Fprintf(os.Stderr, "starting session at symbol '%s' using resource dir: %s\n", root, dir)
ctx := context.Background()
- if persist != "" {
- store = fsdb.NewFsDb()
- err := store.Connect(ctx, persist)
- if err != nil {
- fmt.Fprintf(os.Stderr, "db connect error: %v", err)
- os.Exit(1)
- }
+ cfg := engine.Config{
+ OutputSize: uint32(size),
+ SessionId: sessionId,
}
- en, err := engine.NewSizedEngine(dir, uint32(size), store, &sessionId)
+
+ rsStore := fsdb.NewFsDb()
+ err := rsStore.Connect(ctx, dir)
if err != nil {
- fmt.Fprintf(os.Stderr, "engine create error: %v", err)
+ fmt.Fprintf(os.Stderr, "resource db connect error: %v", err)
os.Exit(1)
}
+
+ rs := resource.NewDbResource(rsStore)
+ rs = rs.With(db.DATATYPE_STATICLOAD)
+ en := engine.NewEngine(cfg, rs)
+ if persistDir != "" {
+ store := fsdb.NewFsDb()
+ err = store.Connect(ctx, persistDir)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "persist db connect error: %v", err)
+ os.Exit(1)
+ }
+ pe := persist.NewPersister(store)
+ en = en.WithPersister(pe)
+ }
+
cont, err := en.Init(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "engine init exited with error: %v\n", err)
diff --git a/engine/config.go b/engine/config.go
@@ -14,4 +14,6 @@ type Config struct {
CacheSize uint32
// Language determines the ISO-639-3 code of the default translation language. If not set, no language translations will be looked up.
Language string
+ // StateDebug activates string translations of flags in output logs if set
+ StateDebug bool
}
diff --git a/engine/db.go b/engine/db.go
@@ -193,6 +193,8 @@ func(en *dbEngine) ensurePersist() error {
if st == nil {
st = en.st
logg.Debugf("using engine state for persister", "state", st)
+ } else {
+ en.st = st
}
ca := en.pe.GetMemory()
cac, ok := ca.(*cache.Cache)
@@ -202,10 +204,20 @@ func(en *dbEngine) ensurePersist() error {
return errors.New("memory MUST be *cache.Cache for now. sorry")
}
logg.Debugf("using engine memory for persister", "memory", cac)
+ } else {
+ en.ca = cac
}
logg.Tracef("set persister", "st", st, "cac", cac)
en.pe = en.pe.WithContent(st, cac)
- return nil
+ err := en.pe.Load(en.cfg.SessionId)
+ if err != nil {
+ logg.Infof("persister load fail. trying save in case new session", "err", err, "session", en.cfg.SessionId)
+ err = en.pe.Save(en.cfg.SessionId)
+ }
+ if en.cfg.StateDebug {
+ en.st.UseDebug()
+ }
+ return err
}
func(en *dbEngine) setupVm() {
diff --git a/examples/db/main.go b/examples/db/main.go
@@ -11,7 +11,6 @@ import (
testdataloader "github.com/peteole/testdata-loader"
"git.defalsify.org/vise.git/asm"
- "git.defalsify.org/vise.git/cache"
"git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/resource"
@@ -132,33 +131,20 @@ func main() {
rs.WithCodeGetter(tg.GetCode)
rs.AddLocalFunc("say", say)
- ca := cache.NewCache()
- if err != nil {
- panic(err)
- }
cfg := engine.Config{
Root: "root",
+ FlagCount: 1,
}
- st := state.NewState(1)
- en, err := engine.NewPersistedEngine(ctx, cfg, pr, rs)
- if err != nil {
- logg.Infof("persisted engine create error. trying again with persisting empty state first...")
- pr = pr.WithContent(&st, ca)
- err = pr.Save(cfg.SessionId)
- if err != nil {
- logg.ErrorCtxf(ctx, "fail state save", "err", err)
- os.Exit(1)
- }
- en, err = engine.NewPersistedEngine(ctx, cfg, pr, rs)
- }
+ en := engine.NewEngine(cfg, rs)
+ en = en.WithPersister(pr)
_, err = en.Init(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
}
- err = engine.Loop(ctx, &en, os.Stdin, os.Stdout)
+ err = engine.Loop(ctx, en, os.Stdin, os.Stdout)
if err != nil {
fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err)
os.Exit(1)
diff --git a/examples/gdbm/main.go b/examples/gdbm/main.go
@@ -9,10 +9,8 @@ import (
testdataloader "github.com/peteole/testdata-loader"
- "git.defalsify.org/vise.git/cache"
"git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/resource"
- "git.defalsify.org/vise.git/state"
"git.defalsify.org/vise.git/db"
gdbmdb "git.defalsify.org/vise.git/db/gdbm"
fsdb "git.defalsify.org/vise.git/db/fs"
@@ -35,7 +33,6 @@ func main() {
root := "root"
fmt.Fprintf(os.Stderr, "starting session at symbol '%s' using resource dir: %s\n", root, scriptDir)
- st := state.NewState(0)
store := gdbmdb.NewGdbmDb()
err := store.Connect(ctx, dbFile)
if err != nil {
@@ -56,23 +53,18 @@ func main() {
rs.WithMenuGetter(rsf.GetMenu)
rs.WithEntryFuncGetter(rsf.FuncFor)
- ca := cache.NewCache()
- if err != nil {
- panic(err)
- }
cfg := engine.Config{
Root: "root",
Language: "nor",
}
- en := engine.NewEngine(ctx, cfg, &st, rs, ca)
-
+ en := engine.NewEngine(cfg, rs)
_, err = en.Init(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
}
- err = engine.Loop(ctx, &en, os.Stdin, os.Stdout)
+ err = engine.Loop(ctx, en, os.Stdin, os.Stdout)
if err != nil {
fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err)
os.Exit(1)
diff --git a/examples/http/main.go b/examples/http/main.go
@@ -11,8 +11,6 @@ import (
"path"
"git.defalsify.org/vise.git/engine"
- "git.defalsify.org/vise.git/state"
- "git.defalsify.org/vise.git/cache"
"git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/resource"
"git.defalsify.org/vise.git/logging"
@@ -20,7 +18,7 @@ import (
)
var (
- Logg logging.Logger = logging.NewVanilla().WithDomain("http")
+ logg logging.Logger = logging.NewVanilla().WithDomain("http")
)
type LocalHandler struct {
@@ -98,32 +96,27 @@ func NewDefaultSessionHandler(ctx context.Context, persistBase string, resourceB
}
}
-func(f *DefaultSessionHandler) GetEngine(ctx context.Context, sessionId string) (engine.EngineIsh, error) {
+func(f *DefaultSessionHandler) GetEngine(ctx context.Context, sessionId string) (engine.Engine, error) {
cfg := f.cfgTemplate
cfg.SessionId = sessionId
- persistPath := path.Join(f.peBase, sessionId)
+ //persistPath := path.Join(f.peBase, sessionId)
+ persistPath := path.Join(f.peBase)
+ if persistPath == "" {
+ persistPath = ".state"
+ }
store := fsdb.NewFsDb()
err := store.Connect(ctx, persistPath)
if err != nil {
return nil, err
}
-
- f.rh.SetSession(sessionId)
+ store.SetSession(cfg.SessionId)
+ f.rh.SetSession(cfg.SessionId)
pe := persist.NewPersister(store)
- en, err := engine.NewPersistedEngine(ctx, cfg, pe, f.rs)
- if err != nil {
- st := state.NewState(cfg.FlagCount)
- ca := cache.NewCache().WithCacheSize(cfg.CacheSize)
- Logg.Infof("persisted engine create error. trying again with persisting empty state first...")
- pe = pe.WithContent(&st, ca)
- err = pe.Save(cfg.SessionId)
- if err != nil {
- return nil, err
- }
- en, err = engine.NewPersistedEngine(ctx, cfg, pe, f.rs)
- }
+ en := engine.NewEngine(cfg, f.rs)
+ en = en.WithPersister(pe)
+
return en, err
}
diff --git a/examples/intro/main.go b/examples/intro/main.go
@@ -71,6 +71,7 @@ func(c *introResource) something(ctx context.Context, sym string, input []byte)
}
func main() {
+ var err error
var dir string
var root string
var size uint
@@ -92,15 +93,17 @@ func main() {
SessionId: sessionId,
OutputSize: uint32(size),
}
- en := engine.NewEngine(ctx, cfg, &st, rs, ca)
- var err error
+ en := engine.NewEngine(cfg, rs)
+ en = en.WithState(&st)
+ en = en.WithMemory(ca)
+
_, err = en.Init(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
}
- err = engine.Loop(ctx, &en, os.Stdin, os.Stdout)
+ err = engine.Loop(ctx, en, os.Stdin, os.Stdout)
if err != nil {
fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err)
os.Exit(1)
diff --git a/examples/languages/main.go b/examples/languages/main.go
@@ -10,7 +10,6 @@ import (
testdataloader "github.com/peteole/testdata-loader"
gotext "gopkg.in/leonelquinteros/gotext.v1"
- "git.defalsify.org/vise.git/cache"
"git.defalsify.org/vise.git/lang"
"git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/engine"
@@ -88,8 +87,6 @@ func empty(ctx context.Context, sym string, input []byte) (resource.Result, erro
}
func main() {
- st := state.NewState(1)
- state.FlagDebugger.Register(USERFLAG_FLIP, "FLIP")
ctx := context.Background()
rsStore := fsdb.NewFsDb()
err := rsStore.Connect(ctx, scriptDir)
@@ -98,10 +95,10 @@ func main() {
}
rs := resource.NewDbResource(rsStore)
- ca := cache.NewCache()
cfg := engine.Config{
Root: "root",
SessionId: "default",
+ FlagCount: 1,
}
dp := path.Join(scriptDir, ".state")
@@ -112,18 +109,8 @@ func main() {
os.Exit(1)
}
pr := persist.NewPersister(store)
- en, err := engine.NewPersistedEngine(ctx, cfg, pr, rs)
- if err != nil {
- logg.Infof("persisted engine create error. trying again with persisting empty state first...")
- pr = pr.WithContent(&st, ca)
- err = pr.Save(cfg.SessionId)
- if err != nil {
- logg.ErrorCtxf(ctx, "fail state save", "err", err)
- os.Exit(1)
- }
- en, err = engine.NewPersistedEngine(ctx, cfg, pr, rs)
- }
- pr.State.UseDebug()
+ en := engine.NewEngine(cfg, rs)
+ en = en.WithPersister(pr)
aux := &langController{
State: pr.State,
@@ -139,7 +126,7 @@ func main() {
os.Exit(1)
}
- err = engine.Loop(ctx, &en, os.Stdin, os.Stdout)
+ err = engine.Loop(ctx, en, os.Stdin, os.Stdout)
if err != nil {
fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err)
os.Exit(1)
diff --git a/examples/longmenu/main.go b/examples/longmenu/main.go
@@ -11,6 +11,7 @@ import (
testdataloader "github.com/peteole/testdata-loader"
"git.defalsify.org/vise.git/engine"
+ "git.defalsify.org/vise.git/resource"
fsdb "git.defalsify.org/vise.git/db/fs"
)
var (
@@ -19,33 +20,23 @@ var (
)
func main() {
- var root string
var size uint
- var sessionId string
- var persist bool
flag.UintVar(&size, "s", 0, "max size of output")
- flag.StringVar(&root, "root", "root", "entry point symbol")
- flag.StringVar(&sessionId, "session-id", "default", "session id")
- flag.BoolVar(&persist, "persist", false, "use state persistence")
flag.Parse()
- dir := scriptDir
- fmt.Fprintf(os.Stderr, "starting session at symbol '%s' using resource dir: %s\n", root, dir)
-
ctx := context.Background()
- dp := path.Join(scriptDir, ".state")
store := fsdb.NewFsDb()
- err := store.Connect(ctx, dp)
+ err := store.Connect(ctx, scriptDir)
if err != nil {
fmt.Fprintf(os.Stderr, "db connect error: %v", err)
os.Exit(1)
}
- defer store.Close()
- en, err := engine.NewSizedEngine(dir, uint32(size), store, &sessionId)
- if err != nil {
- fmt.Fprintf(os.Stderr, "engine create error: %v", err)
- os.Exit(1)
+ rs := resource.NewDbResource(store)
+ defer rs.Close()
+ cfg := engine.Config {
+ OutputSize: uint32(size),
}
+ en := engine.NewEngine(cfg, rs)
cont, err := en.Init(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "engine init exited with error: %v\n", err)
diff --git a/examples/pincheck/main.go b/examples/pincheck/main.go
@@ -89,15 +89,18 @@ func main() {
ca := cache.NewCache()
cfg := engine.Config{
Root: "root",
+ StateDebug: true,
}
- en := engine.NewEngine(ctx, cfg, &st, rs, ca)
+ en := engine.NewEngine(cfg, rs)
+ en = en.WithState(&st)
+ en = en.WithMemory(ca)
_, err = en.Init(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
}
- err = engine.Loop(ctx, &en, os.Stdin, os.Stdout)
+ err = engine.Loop(ctx, en, os.Stdin, os.Stdout)
if err != nil {
fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err)
os.Exit(1)
diff --git a/examples/preprocessor/main.go b/examples/preprocessor/main.go
@@ -92,7 +92,9 @@ func main() {
cfg := engine.Config{
Root: "root",
}
- en := engine.NewEngine(ctx, cfg, &st, rsf, ca)
+ en := engine.NewEngine(cfg, rsf)
+ en = en.WithState(&st)
+ en = en.WithMemory(ca)
_, err = en.Init(ctx)
if err != nil {
@@ -100,7 +102,7 @@ func main() {
os.Exit(1)
}
- err = engine.Loop(ctx, &en, os.Stdin, os.Stdout)
+ err = engine.Loop(ctx, en, os.Stdin, os.Stdout)
if err != nil {
fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err)
os.Exit(1)
diff --git a/examples/profile/main.go b/examples/profile/main.go
@@ -120,14 +120,16 @@ func main() {
SessionId: sessionId,
OutputSize: uint32(size),
}
- en := engine.NewEngine(ctx, cfg, &st, rs, ca)
+ en := engine.NewEngine(cfg, rs)
+ en = en.WithState(&st)
+ en = en.WithMemory(ca)
_, err = en.Init(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
}
- err = engine.Loop(ctx, &en, os.Stdin, os.Stdout)
+ err = engine.Loop(ctx, en, os.Stdin, os.Stdout)
if err != nil {
fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err)
os.Exit(1)
diff --git a/examples/quit/main.go b/examples/quit/main.go
@@ -9,10 +9,8 @@ import (
testdataloader "github.com/peteole/testdata-loader"
- "git.defalsify.org/vise.git/cache"
"git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/resource"
- "git.defalsify.org/vise.git/state"
fsdb "git.defalsify.org/vise.git/db/fs"
)
@@ -28,10 +26,6 @@ func quit(ctx context.Context, sym string, input []byte) (resource.Result, error
}
func main() {
- st := state.NewState(0)
- st.UseDebug()
- ca := cache.NewCache()
-
ctx := context.Background()
store := fsdb.NewFsDb()
err := store.Connect(ctx, scriptDir)
@@ -42,17 +36,17 @@ func main() {
cfg := engine.Config{
Root: "root",
}
- en := engine.NewEngine(ctx, cfg, &st, rs, ca)
-
rs.AddLocalFunc("quitcontent", quit)
+ en := engine.NewEngine(cfg, rs)
+
_, err = en.Init(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
}
- err = engine.Loop(ctx, &en, os.Stdin, os.Stdout)
+ err = engine.Loop(ctx, en, os.Stdin, os.Stdout)
if err != nil {
fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err)
os.Exit(1)
diff --git a/examples/reuse/main.go b/examples/reuse/main.go
@@ -9,17 +9,11 @@ import (
testdataloader "github.com/peteole/testdata-loader"
- "git.defalsify.org/vise.git/cache"
"git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/resource"
- "git.defalsify.org/vise.git/state"
fsdb "git.defalsify.org/vise.git/db/fs"
)
-const (
- USERFLAG = iota + state.FLAG_USERSTART
-)
-
var (
baseDir = testdataloader.GetBasePath()
scriptDir = path.Join(baseDir, "examples", "reuse")
@@ -37,7 +31,6 @@ func main() {
fmt.Fprintf(os.Stderr, "starting session at symbol '%s' using resource dir: %s\n", root, scriptDir)
ctx := context.Background()
- st := state.NewState(0)
store := fsdb.NewFsDb()
err := store.Connect(ctx, scriptDir)
if err != nil {
@@ -47,18 +40,17 @@ func main() {
rs.AddLocalFunc("do_foo", same)
rs.AddLocalFunc("do_bar", same)
- ca := cache.NewCache()
cfg := engine.Config{
Root: "root",
}
- en := engine.NewEngine(ctx, cfg, &st, rs, ca)
+ en := engine.NewEngine(cfg, rs)
_, err = en.Init(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
}
- err = engine.Loop(ctx, &en, os.Stdin, os.Stdout)
+ err = engine.Loop(ctx, en, os.Stdin, os.Stdout)
if err != nil {
fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err)
os.Exit(1)
diff --git a/examples/session/main.go b/examples/session/main.go
@@ -11,10 +11,8 @@ import (
testdataloader "github.com/peteole/testdata-loader"
- "git.defalsify.org/vise.git/cache"
"git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/resource"
- "git.defalsify.org/vise.git/state"
"git.defalsify.org/vise.git/logging"
fsdb "git.defalsify.org/vise.git/db/fs"
)
@@ -64,8 +62,6 @@ func main() {
fmt.Fprintf(os.Stderr, "starting session at symbol '%s' using resource dir: %s\n", root, scriptDir)
ctx := context.Background()
- st := state.NewState(0)
- st.UseDebug()
store := fsdb.NewFsDb()
err := store.Connect(ctx, scriptDir)
if err != nil {
@@ -73,20 +69,20 @@ func main() {
}
rs := resource.NewDbResource(store)
rs.AddLocalFunc("do_save", save)
- ca := cache.NewCache()
cfg := engine.Config{
Root: "root",
SessionId: sessionId,
OutputSize: uint32(size),
+ StateDebug: true,
}
ctx = context.WithValue(ctx, "SessionId", sessionId)
- en := engine.NewEngine(ctx, cfg, &st, rs, ca)
+ en := engine.NewEngine(cfg, rs)
_, err = en.Init(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
}
- err = engine.Loop(ctx, &en, os.Stdin, os.Stdout)
+ err = engine.Loop(ctx, en, os.Stdin, os.Stdout)
if err != nil {
fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err)
os.Exit(1)
diff --git a/examples/state/main.go b/examples/state/main.go
@@ -9,7 +9,6 @@ import (
testdataloader "github.com/peteole/testdata-loader"
- "git.defalsify.org/vise.git/cache"
"git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/resource"
"git.defalsify.org/vise.git/state"
@@ -74,19 +73,15 @@ func main() {
ctx := context.Background()
st := state.NewState(3)
- st.UseDebug()
store := fsdb.NewFsDb()
err := store.Connect(ctx, scriptDir)
if err != nil {
panic(err)
}
rs := resource.NewDbResource(store)
- ca := cache.NewCache()
cfg := engine.Config{
Root: "root",
}
- en := engine.NewEngine(ctx, cfg, &st, rs, ca)
- en.SetDebugger(engine.NewSimpleDebug(nil))
aux := &flagResource{st: &st}
rs.AddLocalFunc("do_foo", aux.do)
@@ -97,12 +92,17 @@ func main() {
state.FlagDebugger.Register(USER_FOO, "FOO")
state.FlagDebugger.Register(USER_BAR, "BAR")
state.FlagDebugger.Register(USER_BAZ, "BAZ")
+
+ en := engine.NewEngine(cfg, rs)
+ en = en.WithState(&st)
+ en = en.WithDebug(nil)
+
_, err = en.Init(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
}
- err = engine.Loop(ctx, &en, os.Stdin, os.Stdout)
+ err = engine.Loop(ctx, en, os.Stdin, os.Stdout)
if err != nil {
fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err)
os.Exit(1)
diff --git a/examples/state_passive/main.go b/examples/state_passive/main.go
@@ -12,7 +12,6 @@ import (
"git.defalsify.org/vise.git/resource"
"git.defalsify.org/vise.git/state"
"git.defalsify.org/vise.git/engine"
- "git.defalsify.org/vise.git/cache"
"git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/logging"
fsdb "git.defalsify.org/vise.git/db/fs"
@@ -89,17 +88,16 @@ func main() {
fmt.Fprintf(os.Stderr, "starting session at symbol '%s' using resource dir: %s\n", root, dir)
ctx := context.Background()
- st := state.NewState(4)
rsStore := fsdb.NewFsDb()
err := rsStore.Connect(ctx, dir)
if err != nil {
panic(err)
}
rs := resource.NewDbResource(rsStore)
- ca := cache.NewCache()
cfg := engine.Config{
Root: "root",
SessionId: sessionId,
+ FlagCount: 4,
}
dp := path.Join(dir, ".state")
@@ -110,17 +108,9 @@ func main() {
os.Exit(1)
}
pr := persist.NewPersister(store)
- en, err := engine.NewPersistedEngine(ctx, cfg, pr, rs)
- if err != nil {
- pr = pr.WithContent(&st, ca)
- err = pr.Save(cfg.SessionId)
- en, err = engine.NewPersistedEngine(ctx, cfg, pr, rs)
- if err != nil {
- fmt.Fprintf(os.Stderr, "engine create exited with error: %v\n", err)
- os.Exit(1)
- }
- }
+ en := engine.NewEngine(cfg, rs)
+ en = en.WithPersister(pr)
fp := path.Join(dp, sessionId)
aux := &fsData{
diff --git a/examples/validate/main.go b/examples/validate/main.go
@@ -10,7 +10,6 @@ import (
testdataloader "github.com/peteole/testdata-loader"
- "git.defalsify.org/vise.git/cache"
"git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/resource"
"git.defalsify.org/vise.git/state"
@@ -69,19 +68,22 @@ func main() {
rs := verifyResource{rsf, &st}
rs.AddLocalFunc("verifyinput", rs.verify)
rs.AddLocalFunc("again", rs.again)
- ca := cache.NewCache()
+
cfg := engine.Config{
Root: "root",
SessionId: sessionId,
OutputSize: uint32(size),
}
- en := engine.NewEngine(ctx, cfg, &st, rs, ca)
+
+ en := engine.NewEngine(cfg, rs)
+ en = en.WithState(&st)
+
_, err = en.Init(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
}
- err = engine.Loop(ctx, &en, os.Stdin, os.Stdout)
+ err = engine.Loop(ctx, en, os.Stdin, os.Stdout)
if err != nil {
fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err)
os.Exit(1)