go-vise

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

commit c0e3f8e01d51655fb6511967db15186f9148ad34
parent 45e0e16239111401e9999da722e182248c78d3b2
Author: lash <dev@holbrook.no>
Date:   Sat, 29 Apr 2023 14:17:03 +0100

Sort mixed-up order of MOUT assemble, add batch example longmenu

Diffstat:
MREADME.md | 19+++++++++++++++++++
Masm/asm.go | 13+++++++------
Masm/asm_test.go | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
Aexamples/longmenu/batch.vis | 11+++++++++++
4 files changed, 105 insertions(+), 12 deletions(-)

diff --git a/README.md b/README.md @@ -193,6 +193,7 @@ This repository provides a `golang` reference implementation for the `vise` conc - `state`: Holds the bytecode buffer, error states and navigation states. - `vm`: Defines instructions, and applies transformations according to the instructions. - `lang`: Validation and specification of language context. +- `logging`: Logging interface and build tags for loglevels. ### Template rendering @@ -245,6 +246,24 @@ This is used to identify the caller, and thus defines a top-level storage key un See `testdata/*.vis` +## Logging + +Loglevels are set at compile-time using the following build tags: + +* `lognone` +* `logerror` +* `logwarn` +* `loginfo` +* `logdebug` +* `logtrace` + +Only use **ONE** of these tags. + +The default tag is `lognone` which disables logging completely. + +`logging/logging.go:Logger` defines the logging interface. It is faintly inspired by the experimental [slog](https://pkg.go.dev/golang.org/x/exp/slog) package, in that it differentiates explicit context logging. + + ## Development tools Located in the `dev/` directory. diff --git a/asm/asm.go b/asm/asm.go @@ -106,6 +106,7 @@ func parseTwoSym(b *bytes.Buffer, arg Arg) (int, error) { } } + n, err := writeSym(b, sym) rn += n if err != nil { @@ -117,7 +118,6 @@ func parseTwoSym(b *bytes.Buffer, arg Arg) (int, error) { if err != nil { return rn, err } - return rn, nil } @@ -208,14 +208,14 @@ func parseOne(op vm.Opcode, instruction *Instruction, w io.Writer) (int, error) // Catch if a.Selector != nil { - log.Printf("entering twosym for %v", op) + log.Printf("have selector %v", instruction) var n int var err error -// if op == vm.MOUT { -// n, err = parseTwoSymReverse(b, a) -// } else { + if op == vm.MOUT { + n, err = parseTwoSymReverse(b, a) + } else { n, err = parseTwoSym(b, a) -// } + } n_buf += n if err != nil { return n_out, err @@ -225,6 +225,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) if a.Flag != nil { n, err := parseSig(b, a) n_buf += n diff --git a/asm/asm_test.go b/asm/asm_test.go @@ -23,15 +23,47 @@ func TestParserRoute(t *testing.T) { Parse(s, b) expect = vm.NewLine(nil, vm.MSINK, nil, nil, nil) if !bytes.Equal(b.Bytes(), expect) { + log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) + } + + b = bytes.NewBuffer(nil) + s = "MAP tinkywinky\n" + Parse(s, b) + expect = vm.NewLine(nil, vm.MAP, []string{"tinkywinky"}, nil, nil) + if !bytes.Equal(b.Bytes(), expect) { log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) } b = bytes.NewBuffer(nil) + s = "MOVE dipsy\n" + Parse(s, b) + expect = vm.NewLine(nil, vm.MOVE, []string{"dipsy"}, nil, nil) + if !bytes.Equal(b.Bytes(), expect) { + log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) + } + + b = bytes.NewBuffer(nil) + s = "RELOAD lalapu\n" + Parse(s, b) + expect = vm.NewLine(nil, vm.RELOAD, []string{"lalapu"}, nil, nil) + if !bytes.Equal(b.Bytes(), expect) { + log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) + } + + b = bytes.NewBuffer(nil) + s = "LOAD foo 42\n" + Parse(s, b) + expect = vm.NewLine(nil, vm.LOAD, []string{"foo"}, []byte{0x2a}, nil) + if !bytes.Equal(b.Bytes(), expect) { + log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) + } + + b = bytes.NewBuffer(nil) s = "MOUT foo bar\n" Parse(s, b) expect = vm.NewLine(nil, vm.MOUT, []string{"foo", "bar"}, nil, nil) if !bytes.Equal(b.Bytes(), expect) { - log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) + log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) } b = bytes.NewBuffer(nil) @@ -39,7 +71,7 @@ func TestParserRoute(t *testing.T) { Parse(s, b) expect = vm.NewLine(nil, vm.MOUT, []string{"baz", "42"}, nil, nil) if !bytes.Equal(b.Bytes(), expect) { - log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) + log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) } b = bytes.NewBuffer(nil) @@ -47,7 +79,7 @@ func TestParserRoute(t *testing.T) { Parse(s, b) expect = vm.NewLine(nil, vm.INCMP, []string{"foo", "bar"}, nil, nil) if !bytes.Equal(b.Bytes(), expect) { - log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) + log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) } b = bytes.NewBuffer(nil) @@ -55,7 +87,7 @@ func TestParserRoute(t *testing.T) { Parse(s, b) expect = vm.NewLine(nil, vm.INCMP, []string{"baz", "42"}, nil, nil) if !bytes.Equal(b.Bytes(), expect) { - log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) + log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) } b = bytes.NewBuffer(nil) @@ -63,7 +95,7 @@ func TestParserRoute(t *testing.T) { Parse(s, b) expect = vm.NewLine(nil, vm.INCMP, []string{"xyzzy", "*"}, nil, nil) if !bytes.Equal(b.Bytes(), expect) { - log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) + log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) } b = bytes.NewBuffer(nil) @@ -73,7 +105,37 @@ func TestParserRoute(t *testing.T) { expect = vm.NewLine(expect, vm.HALT, nil, nil, nil) expect = vm.NewLine(expect, vm.INCMP, []string{"foo", "2"}, nil, nil) if !bytes.Equal(b.Bytes(), expect) { - log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) + log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) + } + + b = bytes.NewBuffer(nil) + s = "UP 3 bar\n" + Parse(s, b) + expect = vm.NewLine(nil, vm.MOUT, []string{"bar", "3"}, nil, nil) + expect = vm.NewLine(expect, vm.HALT, nil, nil, nil) + expect = vm.NewLine(expect, vm.INCMP, []string{"_", "3"}, nil, nil) + if !bytes.Equal(b.Bytes(), expect) { + log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) + } + + b = bytes.NewBuffer(nil) + s = "NEXT 4 baz\n" + Parse(s, b) + expect = vm.NewLine(nil, vm.MNEXT, []string{"baz", "4"}, nil, nil) + expect = vm.NewLine(expect, vm.HALT, nil, nil, nil) + expect = vm.NewLine(expect, vm.INCMP, []string{">", "4"}, nil, nil) + if !bytes.Equal(b.Bytes(), expect) { + log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) + } + + b = bytes.NewBuffer(nil) + s = "PREVIOUS 5 xyzzy\n" + Parse(s, b) + expect = vm.NewLine(nil, vm.MPREV, []string{"xyzzy", "5"}, nil, nil) + expect = vm.NewLine(expect, vm.HALT, nil, nil, nil) + expect = vm.NewLine(expect, vm.INCMP, []string{"<", "5"}, nil, nil) + if !bytes.Equal(b.Bytes(), expect) { + log.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, b) } } diff --git a/examples/longmenu/batch.vis b/examples/longmenu/batch.vis @@ -0,0 +1,11 @@ +MSINK +DOWN poke 0 inky +DOWN poke 1 pinky +DOWN poke 2 blinky +DOWN poke 3 clyde +DOWN poke 4 tinkywinky +DOWN poke 5 dipsy +DOWN poke 6 lala +DOWN poke 7 pu +NEXT 11 fwdmenu +PREVIOUS 1234 backmenu