Correct MSIZE args
This commit is contained in:
parent
1c11e5881a
commit
83fe049b15
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
11
go/vm/vm.go
11
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user