go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

commit 26fc82a76ede6275877016318c986fcab6354a12
parent af1d15258dc5ba821420a5de649a83bfe13ed784
Author: lash <dev@holbrook.no>
Date:   Mon,  9 Dec 2024 19:47:29 +0000

Add back move detection in state

Diffstat:
Mdb/postgres/pg_test.go | 4+++-
Mstate/state.go | 19++++++++++++-------
2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/db/postgres/pg_test.go b/db/postgres/pg_test.go @@ -55,7 +55,9 @@ func TestPutGetPg(t *testing.T) { typMap := pgtype.NewMap() k := []byte("foo") - ks := append([]byte{db.DATATYPE_USERDATA}, []byte("foo")...) + ks := append([]byte{db.DATATYPE_USERDATA}, []byte(ses)...) + ks = append(ks, []byte(".")...) + ks = append(ks, k...) v := []byte("bar") resInsert := pgxmock.NewResult("UPDATE", 1) mock.ExpectBegin() diff --git a/state/state.go b/state/state.go @@ -42,7 +42,7 @@ type State struct { input []byte // Last input debug bool // Make string representation more human friendly invalid bool - lateral bool + lastMove uint8 } // number of bytes necessary to represent a bitfield of the given size. @@ -214,7 +214,12 @@ func(st *State) Where() (string, uint16) { // Lateral returns true if the last state move was Next() or Previous() func(st *State) Lateral() bool { - return st.lateral + return st.lastMove & 6 > 0 +} + +// Back returns true if the last state move was Up() +func(st *State) Back() bool { + return st.lastMove & 1 > 0 } // Next moves to the next sink page index. @@ -226,7 +231,7 @@ func(st *State) Next() (uint16, error) { s, idx := st.Where() logg.Debugf("next page", "location", s, "index", idx) st.Moves += 1 - st.lateral = true + st.lastMove = 2 return st.SizeIdx, nil } @@ -248,7 +253,7 @@ func(st *State) Previous() (uint16, error) { s, idx := st.Where() logg.Debugf("previous page", "location", s, "index", idx) st.Moves += 1 - st.lateral = true + st.lastMove = 4 return st.SizeIdx, nil } @@ -296,7 +301,7 @@ func(st *State) Down(input string) error { st.ExecPath = append(st.ExecPath, input) st.SizeIdx = 0 st.Moves += 1 - st.lateral = false + st.lastMove = 0 return nil } @@ -321,7 +326,7 @@ func(st *State) Up() (string, error) { st.SizeIdx = 0 logg.Tracef("execpath after", "path", st.ExecPath) st.Moves += 1 - st.lateral = false + st.lastMove = 1 return sym, nil } @@ -379,7 +384,7 @@ func(st *State) Restart() error { st.SizeIdx = 0 st.input = []byte{} st.ExecPath = st.ExecPath[:1] - st.lateral = false + st.lastMove = 0 return err }