go-vise

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

commit 83fe049b1519a8ad52015d9d06498b95de868263
parent 1c11e5881a656abdf231d748690cb3f68630e61c
Author: lash <dev@holbrook.no>
Date:   Mon,  3 Apr 2023 09:52:58 +0100

Correct MSIZE args

Diffstat:
Mgo/vm/debug.go | 4++--
Mgo/vm/debug_test.go | 4++--
Mgo/vm/runner.go | 3++-
Mgo/vm/vm.go | 11++++++-----
4 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/go/vm/debug.go b/go/vm/debug.go @@ -84,12 +84,12 @@ func ToString(b []byte) (string, error) { return "", err } case MSIZE: - r, bb, err := ParseMSize(b) + r, v, bb, err := ParseMSize(b) b = bb if err != nil { return "", err } - s = fmt.Sprintf("%s %v", s, r) + s = fmt.Sprintf("%s %v %v", s, r, v) case MOUT: r, v, bb, err := ParseMOut(b) b = bb diff --git a/go/vm/debug_test.go b/go/vm/debug_test.go @@ -121,12 +121,12 @@ func TestToString(t *testing.T) { t.Fatalf("expected:\n\t%v\ngot:\n\t%v", expect, r) } - b = NewLine(nil, MSIZE, nil, nil, []uint8{0x42}) + b = NewLine(nil, MSIZE, nil, nil, []uint8{0x42, 0x2a}) r, err = ToString(b) if err != nil { t.Fatal(err) } - expect = "MSIZE 66\n" + expect = "MSIZE 66 42\n" if r != expect { t.Fatalf("expected:\n\t%v\ngot:\n\t%v", expect, r) } diff --git a/go/vm/runner.go b/go/vm/runner.go @@ -199,7 +199,8 @@ func RunHalt(b []byte, st *state.State, rs resource.Resource, ctx context.Contex // RunMSize func RunMSize(b []byte, st *state.State, rs resource.Resource, ctx context.Context) ([]byte, error) { log.Printf("WARNING MSIZE not yet implemented") - return b, nil + _, _, b, err := ParseMSize(b) + return b, err } // RunMSize diff --git a/go/vm/vm.go b/go/vm/vm.go @@ -55,13 +55,14 @@ func ParseMNext(b []byte) (string, string, []byte, error) { return parseTwoSym(b) } -func ParseMSize(b []byte) (uint32, []byte, error) { - if len(b) < 1 { - return 0, b, fmt.Errorf("zero-length argument") +func ParseMSize(b []byte) (uint32, uint32, []byte, error) { + if len(b) < 2 { + return 0, 0, b, fmt.Errorf("argument too short") } r := uint32(b[0]) - b = b[1:] - return r, b, nil + rr := uint32(b[1]) + b = b[2:] + return r, rr, b, nil } func ParseMOut(b []byte) (string, string, []byte, error) {