commit 54865b5e4d5874cce4d6de8e6aafc37ea08c484e
parent 7d788fe1723e78796af64d1772a755d5eb50849b
Author: lash <dev@holbrook.no>
Date: Wed, 5 Apr 2023 08:14:08 +0100
Add parser for double
Diffstat:
2 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/go/asm/asm.go b/go/asm/asm.go
@@ -158,6 +158,35 @@ func writeSize(n uint32, w *bytes.Buffer) (int, error) {
return w.Write(bn[c:])
}
+func parseSingle(op vm.Opcode, arg Arg, w io.Writer) (int, error) {
+ var rn int
+
+ v := arg.ArgSingle
+ if v == nil {
+ return 0, nil
+ }
+
+ b := bytes.NewBuffer(nil)
+
+ n, err := writeOpcode(op, b)
+ rn += n
+ if err != nil {
+ return rn, err
+ }
+
+ n, err = writeSym(v.Sym, b)
+ rn += n
+ if err != nil {
+ return rn, err
+ }
+
+ if w != nil {
+ rn, err = w.Write(b.Bytes())
+ } else {
+ rn = 0
+ }
+ return rn, err
+}
func parseDisplay(op vm.Opcode, arg Arg, w io.Writer) (int, error) {
var rn int
@@ -297,7 +326,14 @@ func Parse(s string, w io.Writer) (int, error) {
rn += n
continue
}
-
+ n, err = parseSingle(op, v.OpArg, w)
+ if err != nil {
+ return n, err
+ }
+ if n > 0 {
+ rn += n
+ continue
+ }
}
return rn, err
}
diff --git a/go/asm/asm_test.go b/go/asm/asm_test.go
@@ -89,3 +89,24 @@ func TestParseDouble(t *testing.T) {
t.Fatalf("expected %x, got %x", expect, rb)
}
}
+
+func TestParseSingle(t *testing.T) {
+ var b []byte
+ b = vm.NewLine(b, vm.MAP, []string{"xyzzy"}, nil, nil)
+ s, err := vm.ToString(b)
+ log.Printf("parsing:\n%s\n", s)
+
+ r := bytes.NewBuffer(nil)
+ n, err := Parse(s, r)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if n != 8 {
+ t.Fatalf("expected 8 byte write count, got %v", n)
+ }
+ rb := r.Bytes()
+ expect := []byte{0x00, vm.MAP, 0x05, 0x78, 0x79, 0x7a, 0x7a, 0x79}
+ if !bytes.Equal(rb, expect) {
+ t.Fatalf("expected %x, got %x", expect, rb)
+ }
+}