go-vise

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

commit feaab793b2664d77de2f0120ff6647e0e6f6131e
parent 845380fd7ab5d9a44df023ae158a2d7d3dd549a6
Author: lash <dev@holbrook.no>
Date:   Tue, 18 Apr 2023 15:03:18 +0100

Replace compile bash script with makefiles

Diffstat:
MMakefile | 12+++++-------
Masm/asm.go | 22++++++++++------------
Dexamples/compile.bash | 13-------------
Aexamples/helloworld/Makefile | 10++++++++++
Aexamples/profile/Makefile | 10++++++++++
Aexamples/session/Makefile | 10++++++++++
Aexamples/validate/Makefile | 10++++++++++
7 files changed, 55 insertions(+), 32 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,15 +1,13 @@ -examples: profile session helloworld validate - -.PHONY: examples +all: profile session helloworld validate profile: - bash examples/compile.bash examples/profile + make -C examples/profile session: - bash examples/compile.bash examples/session + make -C examples/session helloworld: - bash examples/compile.bash examples/helloworld + make -C examples/session validate: - bash examples/compile.bash examples/validate + make -C examples/validate diff --git a/asm/asm.go b/asm/asm.go @@ -5,6 +5,7 @@ import ( "encoding/binary" "fmt" "io" + "log" "math" "strconv" "strings" @@ -23,11 +24,11 @@ type Asm struct { // Arg holds all parsed argument elements of a single line of assembly code. type Arg struct { - Sym *string `((@SpecialSym | @Sym) Whitespace?)?` + Sym *string `(@Sym Whitespace?)?` Size *uint32 `(@Size Whitespace?)?` Flag *uint8 `(@Size Whitespace?)?` - Selector *string `((@SpecialSym | @SpecialSelector | @Sym) Whitespace?)?` - Desc *string `(Quote (@Sym @Whitespace?)+ Quote Whitespace?)?` + Selector *string `(@Sym Whitespace?)?` + Desc *string `(Quote ((@Sym | @Size) @Whitespace?)+ Quote Whitespace?)?` } func flush(b *bytes.Buffer, w io.Writer) (int, error) { @@ -183,7 +184,7 @@ func parseOne(op vm.Opcode, instruction *Instruction, w io.Writer) (int, error) // Catch if a.Selector != nil { - Logg.Tracef("entring twosym", "op", op) + log.Printf("entering twosym for %v", op) n, err := parseTwoSym(b, a) n_buf += n if err != nil { @@ -246,7 +247,7 @@ func (a Arg) String() string { type Instruction struct { OpCode string `@Ident` OpArg Arg `(Whitespace @@)?` - Comment string `Whitespace? Comment? EOL` + Comment string `Comment? EOL` } // String implement the String interface. @@ -259,10 +260,7 @@ var ( {"Comment", `(?:#)[^\n]*`}, {"Ident", `^[A-Z]+`}, {"Size", `[0-9]+`}, - {"Cap", `[A-Z]`}, - {"Sym", `[a-zA-Z0-9_]+`}, - {"SpecialSym", `_`}, - {"SpecialSelector", `[\*\.]`}, + {"Sym", `[a-zA-Z_\*\.][a-zA-Z0-9_]*`}, {"Whitespace", `[ \t]+`}, {"EOL", `[\n\r]+`}, {"Quote", `["']`}, @@ -357,7 +355,7 @@ func(bt *Batcher) MenuAdd(w io.Writer, code string, arg Arg) (int, error) { } else if arg.Sym != nil { sym = *arg.Sym } - Logg.Debugf("menu processor add", "code", code, "selector", selector, "desc", *arg.Desc, "sym", sym) //%v '%v' '%v' '%v'", code, selector, *arg.Desc, sym) + log.Printf("menu processor add %v '%v' '%v' '%v'", code, selector, *arg.Desc, sym) err := bt.menuProcessor.Add(code, selector, *arg.Desc, sym) return 0, err } @@ -381,7 +379,7 @@ func Parse(s string, w io.Writer) (int, error) { var rn int for _, v := range ast.Instructions { - Logg.Debugf("parsing line", "opcode", v.OpCode, "args", v.OpArg) + log.Printf("parsing line %v: %v", v.OpCode, v.OpArg) op, ok := vm.OpcodeIndex[v.OpCode] if !ok { n, err := batch.MenuAdd(w, v.OpCode, v.OpArg) @@ -400,7 +398,7 @@ func Parse(s string, w io.Writer) (int, error) { if err != nil { return rn, err } - Logg.Debugf("wrote bytecode", "bytes", n, "args", v.OpArg) + log.Printf("wrote %v bytes for %v", n, v.OpArg) } } n, err := batch.Exit(w) diff --git a/examples/compile.bash b/examples/compile.bash @@ -1,13 +0,0 @@ -for f in $(ls $1/*.vis); do - b=$(basename $f) - b=${b%.*} - go run ./dev/asm $1/$b.vis > $1/$b.bin -done - -for f in $(ls $1/*.txt.orig); do - b=$(basename $f) - b=${b%.*} - #go run ./dev/asm $1/$b.vis > $1/$b.bin - echo $b - cp -v $f $1/$b -done diff --git a/examples/helloworld/Makefile b/examples/helloworld/Makefile @@ -0,0 +1,10 @@ +INPUTS = $(wildcard ./*.vis) +TXTS = $(wildcard ./*.txt.orig) + +%.vis: + go run ../../dev/asm $(basename $@).vis > $(basename $@).bin + +all: $(INPUTS) $(TXTS) + +%.txt.orig: + cp -v $(basename $@).orig $(basename $@) diff --git a/examples/profile/Makefile b/examples/profile/Makefile @@ -0,0 +1,10 @@ +INPUTS = $(wildcard ./*.vis) +TXTS = $(wildcard ./*.txt.orig) + +%.vis: + go run ../../dev/asm $(basename $@).vis > $(basename $@).bin + +all: $(INPUTS) $(TXTS) + +%.txt.orig: + cp -v $(basename $@).orig $(basename $@) diff --git a/examples/session/Makefile b/examples/session/Makefile @@ -0,0 +1,10 @@ +INPUTS = $(wildcard ./*.vis) +TXTS = $(wildcard ./*.txt.orig) + +%.vis: + go run ../../dev/asm $(basename $@).vis > $(basename $@).bin + +all: $(INPUTS) $(TXTS) + +%.txt.orig: + cp -v $(basename $@).orig $(basename $@) diff --git a/examples/validate/Makefile b/examples/validate/Makefile @@ -0,0 +1,10 @@ +INPUTS = $(wildcard ./*.vis) +TXTS = $(wildcard ./*.txt.orig) + +%.vis: + go run ../../dev/asm $(basename $@).vis > $(basename $@).bin + +all: $(INPUTS) $(TXTS) + +%.txt.orig: + cp -v $(basename $@).orig $(basename $@)