go-vise

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

commit aab804e8ffb8c1c7dd4f0de8a6ec72d9717f4697
parent 19d8c66afe6c72d4ea6ef202271e69de08d18314
Author: lash <dev@holbrook.no>
Date:   Wed,  5 Apr 2023 08:38:07 +0100

Add assembler binary

Diffstat:
Mgo/asm/asm.go | 7+++++--
Ago/dev/asm/asm.go | 28++++++++++++++++++++++++++++
Ago/testdata/foo.fst | 7+++++++
3 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/go/asm/asm.go b/go/asm/asm.go @@ -104,7 +104,7 @@ var ( asmLexer = lexer.MustSimple([]lexer.SimpleRule{ {"Comment", `(?:#)[^\n]*\n?`}, {"Ident", `^[A-Z]+`}, - {"Sym", `[a-zA-Z]+`}, + {"Sym", `[a-zA-Z0-9_]+`}, {"Size", `[0-9]+`}, {"Whitespace", `[ \t\n\r]+`}, {"Quote", `["']`}, @@ -315,8 +315,11 @@ func parseNoarg(op vm.Opcode, arg Arg, w io.Writer) (int, error) { func Parse(s string, w io.Writer) (int, error) { rd := strings.NewReader(s) ast, err := asmParser.Parse("file", rd) - var rn int + if err != nil { + return 0, err + } + var rn int for _, v := range ast.Instructions { op := vm.OpcodeIndex[v.OpCode] n, err := parseSized(op, v.OpArg, w) diff --git a/go/dev/asm/asm.go b/go/dev/asm/asm.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "io/ioutil" + "log" + "os" + + "git.defalsify.org/festive/asm" +) + +func main() { + if (len(os.Args) < 2) { + os.Exit(1) + } + fp := os.Args[1] + v, err := ioutil.ReadFile(fp) + if err != nil { + fmt.Fprintf(os.Stderr, "read error: %v", err) + os.Exit(1) + } + n, err := asm.Parse(string(v), os.Stdout) + if err != nil { + fmt.Fprintf(os.Stderr, "parse error: %v", err) + os.Exit(1) + } + log.Printf("parsed total %v bytes", n) +} diff --git a/go/testdata/foo.fst b/go/testdata/foo.fst @@ -0,0 +1,7 @@ +MOUT 0 "to foo" +MOUT 1 "go bar" +LOAD inky 20 +HALT +INCMP 0 _ +INCMP 1 baz +CATCH _catch 1 1