commit 292f8c31ba56e271fd6f3a0e77ae31a4a9bc3afc
parent e9267c22cf90e505139335e2f6a7b08aa32d6ee2
Author: lash <dev@holbrook.no>
Date: Thu, 20 Apr 2023 19:22:14 +0100
Apply control symbol resolution for MOVE, revert renderer persist
Diffstat:
6 files changed, 26 insertions(+), 43 deletions(-)
diff --git a/engine/default.go b/engine/default.go
@@ -39,7 +39,7 @@ func NewDefaultEngine(dir string, persisted bool, session *string) (EngineIsh, e
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, nil)
+ err = pr.Save(cfg.SessionId)
if err != nil {
return nil, err
}
@@ -80,7 +80,7 @@ func NewSizedEngine(dir string, size uint32, persisted bool, session *string) (E
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, nil)
+ err = pr.Save(cfg.SessionId)
if err != nil {
return nil, err
}
diff --git a/engine/persist.go b/engine/persist.go
@@ -38,15 +38,13 @@ func(pe PersistedEngine) Exec(input []byte, ctx context.Context) (bool, error) {
if err != nil {
return v, err
}
- renderer := pe.Engine.vm.Renderer()
- err = pe.pr.Save(pe.Engine.session, renderer)
+ err = pe.pr.Save(pe.Engine.session)
return v, err
}
// Finish implements EngineIsh interface
func(pe PersistedEngine) Finish() error {
- renderer := pe.Engine.vm.Renderer()
- return pe.pr.Save(pe.Engine.session, renderer)
+ return pe.pr.Save(pe.Engine.session)
}
// RunPersisted performs a single vm execution from client input using a persisted state.
@@ -71,8 +69,7 @@ func RunPersisted(cfg Config, rs resource.Resource, pr persist.Persister, input
if err != nil {
return err
}
- renderer := en.vm.Renderer()
- err = pr.Save(cfg.SessionId, renderer)
+ err = pr.Save(cfg.SessionId)
if err != nil {
return err
}
@@ -89,6 +86,5 @@ func RunPersisted(cfg Config, rs resource.Resource, pr persist.Persister, input
return err
}
en.Finish()
- renderer = en.vm.Renderer()
- return pr.Save(cfg.SessionId, renderer)
+ return pr.Save(cfg.SessionId)
}
diff --git a/persist/fs.go b/persist/fs.go
@@ -7,7 +7,6 @@ import (
"github.com/fxamacker/cbor/v2"
"git.defalsify.org/vise.git/cache"
- "git.defalsify.org/vise.git/render"
"git.defalsify.org/vise.git/state"
)
@@ -15,7 +14,6 @@ import (
type FsPersister struct {
State *state.State
Memory *cache.Cache
- MapKeys []string
dir string
}
@@ -41,12 +39,6 @@ func(p *FsPersister) WithContent(st *state.State, ca *cache.Cache) *FsPersister
return p
}
-// WithRenderer extracts the mapped keys to add to serialization.
-func(p *FsPersister) WithRenderer(pg render.Renderer) *FsPersister {
- p.MapKeys = pg.Keys()
- return p
-}
-
// GetState implements the Persister interface.
func(p *FsPersister) GetState() *state.State {
return p.State
@@ -69,16 +61,13 @@ func(p *FsPersister) Deserialize(b []byte) error {
}
// GetState implements the Persister interface.
-func(p *FsPersister) Save(key string, renderer render.Renderer) error {
- if renderer != nil {
- p = p.WithRenderer(renderer)
- }
+func(p *FsPersister) Save(key string) error {
b, err := p.Serialize()
if err != nil {
return err
}
fp := path.Join(p.dir, key)
- Logg.Debugf("saved state and cache", "key", key, "bytecode", p.State.Code, "map", p.MapKeys)
+ Logg.Debugf("saved state and cache", "key", key, "bytecode", p.State.Code, "map")
return ioutil.WriteFile(fp, b, 0600)
}
@@ -90,10 +79,6 @@ func(p *FsPersister) Load(key string) error {
return err
}
err = p.Deserialize(b)
- Logg.Debugf("loaded state and cache", "key", key, "bytecode", p.State.Code, "map", p.MapKeys)
+ Logg.Debugf("loaded state and cache", "key", key, "bytecode", p.State.Code)
return err
}
-
-func(p *FsPersister) GetKeys() []string {
- return p.MapKeys
-}
diff --git a/persist/persist.go b/persist/persist.go
@@ -2,7 +2,6 @@ package persist
import (
"git.defalsify.org/vise.git/cache"
- "git.defalsify.org/vise.git/render"
"git.defalsify.org/vise.git/state"
)
@@ -10,10 +9,9 @@ import (
type Persister interface {
Serialize() ([]byte, error) // Output serializes representation of the state.
Deserialize(b []byte) error // Restore state from a serialized state.
- Save(key string, renderer render.Renderer) error // Serialize and commit the state representation to persisted storage.
+ Save(key string) error // Serialize and commit the state representation to persisted storage.
Load(key string) error // Load the state representation from persisted storage and Deserialize.
GetState() *state.State // Get the currently loaded State object.
GetMemory() cache.Memory // Get the currently loaded Cache object.
- GetKeys() []string // Get all mapped keys for renderer.
}
diff --git a/vm/input.go b/vm/input.go
@@ -1,6 +1,7 @@
package vm
import (
+ "bytes"
"context"
"fmt"
"regexp"
@@ -37,6 +38,9 @@ func validControl(input []byte) error {
// CheckSym validates the given byte string as a node symbol.
func ValidSym(input []byte) error {
+ if bytes.Equal(input, []byte("_catch")) {
+ return nil
+ }
if !symRegex.Match(input) {
return fmt.Errorf("Input '%s' does not match 'sym' format /%s/", input, symRegexStr)
}
@@ -57,6 +61,7 @@ func valid(target []byte) bool {
if !ok {
err = validControl(target)
+ Logg.Debugf("ouf", "err", err)
if err == nil {
ok = true
}
@@ -97,11 +102,11 @@ func applyTarget(target []byte, st *state.State, ca cache.Memory, ctx context.Co
ok := valid(target)
if !ok {
- return sym, idx, fmt.Errorf("invalid input: %x", target)
+ return sym, idx, fmt.Errorf("invalid input: %s", target)
}
- switch target[0] {
- case '_':
+ switch string(target) {
+ case "_":
sym, err = st.Up()
if err != nil {
return sym, idx, err
@@ -111,17 +116,17 @@ func applyTarget(target []byte, st *state.State, ca cache.Memory, ctx context.Co
return sym, idx, err
}
- case '>':
+ case ">":
idx, err = st.Next()
if err != nil {
return sym, idx, err
}
- case '<':
+ case "<":
idx, err = st.Previous()
if err != nil {
return sym, idx, err
}
- case '^':
+ case "^":
notTop := true
for notTop {
notTop, err := st.Top()
@@ -137,7 +142,7 @@ func applyTarget(target []byte, st *state.State, ca cache.Memory, ctx context.Co
return sym, idx, err
}
}
- case '.':
+ case ".":
st.Same()
location, idx := st.Where()
return location, idx, nil
@@ -152,6 +157,7 @@ func applyTarget(target []byte, st *state.State, ca cache.Memory, ctx context.Co
return sym, idx, err
}
idx = 0
+ Logg.Debugf("inputsss", "sym", sym)
}
return sym, idx, nil
}
diff --git a/vm/runner.go b/vm/runner.go
@@ -34,11 +34,6 @@ func NewVm(st *state.State, rs resource.Resource, ca cache.Memory, sizer *render
return vmi
}
-// Renderer returns the current state of the renderer operated on by the vm.
-func(vmi *Vm) Renderer() render.Renderer {
- return vmi.pg
-}
-
// Reset re-initializes sub-components for output rendering.
func(vmi *Vm) Reset() {
vmi.mn = render.NewMenu()
@@ -287,6 +282,9 @@ func(vm *Vm) RunMove(b []byte, ctx context.Context) ([]byte, error) {
return b, err
}
sym, _, err = applyTarget([]byte(sym), vm.st, vm.ca, ctx)
+ if err != nil {
+ return b, err
+ }
code, err := vm.rs.GetCode(sym)
if err != nil {
return b, err