go-vise

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

commit 2ebbcdd27471612cd20f79aaeab825c9ab487dce
parent 9361c0f03fa32573fda3ac7d4b5a7e10f0590a7f
Author: lash <dev@holbrook.no>
Date:   Thu, 10 Oct 2024 02:00:24 +0100

Start probing zero-prefix fix for menus

Diffstat:
Masm/asm.go | 2+-
Masm/asm_test.go | 12++++++++++++
Masm/menu_test.go | 1+
Mdb/db.go | 17+++++++++++------
Mstate/state_test.go | 5+++++
5 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/asm/asm.go b/asm/asm.go @@ -191,7 +191,7 @@ func parseOne(op vm.Opcode, instruction *Instruction, w io.Writer) (int, error) // Catch CATCH, LOAD and twosyms with integer-as-string if a.Size != nil { - log.Printf("have size %v", instruction) + log.Printf("have size %v (%v)", instruction, *a.Size) if a.Sym == nil { n, err := parseFlagged(b, a) n_buf += n diff --git a/asm/asm_test.go b/asm/asm_test.go @@ -271,6 +271,18 @@ INCMP _ 2 } +func TestParseMenuZeroPrefix(t *testing.T) { + s := `INCMP ^ 00 +` + r := bytes.NewBuffer(nil) + n, err := Parse(s, r) + if err != nil { + t.Fatal(err) + } + log.Printf("wrote %v bytes", n) + +} + func TestParseSingle(t *testing.T) { var b []byte b = vm.NewLine(b, vm.MAP, []string{"xyzzy"}, nil, nil) diff --git a/asm/menu_test.go b/asm/menu_test.go @@ -48,3 +48,4 @@ INCMP _ 99 t.Errorf("expected:\n\t%v\ngot:\n\t%v\n", expect, r) } } + diff --git a/db/db.go b/db/db.go @@ -171,6 +171,15 @@ func(bd *DbBase) CheckPut() bool { return bd.baseDb.pfx & bd.baseDb.lock == 0 } +func ToSessionKey(pfx uint8, sessionId []byte, key []byte) []byte { + var b []byte + if (pfx > datatype_sessioned_threshold) { + b = append([]byte(sessionId), key...) + } else { + b = key + } + return b +} // ToKey creates a DbKey within the current session context. // @@ -178,16 +187,12 @@ func(bd *DbBase) CheckPut() bool { func(bd *DbBase) ToKey(ctx context.Context, key []byte) (LookupKey, error) { var ln *lang.Language var lk LookupKey - var b []byte + //var b []byte db := bd.baseDb if db.pfx == DATATYPE_UNKNOWN { return lk, errors.New("datatype prefix cannot be UNKNOWN") } - if (db.pfx > datatype_sessioned_threshold) { - b = append(db.sid, key...) - } else { - b = key - } + b := ToSessionKey(db.pfx, db.sid, key) lk.Default = ToDbKey(db.pfx, b, nil) if db.pfx & (DATATYPE_MENU | DATATYPE_TEMPLATE | DATATYPE_STATICLOAD) > 0 { if db.lang != nil { diff --git a/state/state_test.go b/state/state_test.go @@ -481,3 +481,8 @@ func TestStateLanguage(t *testing.T) { t.Fatal("expected language set") } } + +func TestStateLimit(t *testing.T) { + st := NewState(17) + st.SetFlag(25) +}