go-vise

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

commit d3fb782a8cb9cd9774b6a442c3ff4af0a21201b0
parent 664eab98d97deacd1d299994275bcca74be7ca3e
Author: lash <dev@holbrook.no>
Date:   Tue,  4 Apr 2023 10:38:01 +0100

Add asm parser

Diffstat:
Mgo/asm/asm.go | 6+++++-
Mgo/vm/opcodes.go | 17+++++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/go/asm/asm.go b/go/asm/asm.go @@ -7,8 +7,11 @@ import ( "github.com/alecthomas/participle/v2" "github.com/alecthomas/participle/v2/lexer" + + "git.defalsify.org/festive/vm" ) + type Asm struct { Instructions []*Instruction `@@*` } @@ -112,7 +115,8 @@ func Parse(s string, w io.Writer) (int, error) { rd := strings.NewReader(s) ast, err := asmParser.Parse("file", rd) for i, v := range ast.Instructions { - fmt.Printf("%v %v\n", i, v) + op := vm.OpcodeIndex[v.OpCode] + fmt.Printf("%v (%v) %v\n", i, op, v) } return 0, err } diff --git a/go/vm/opcodes.go b/go/vm/opcodes.go @@ -38,4 +38,21 @@ var ( MNEXT: "MNEXT", MPREV: "MPREV", } + + OpcodeIndex = map[string]Opcode { + "NOOP": NOOP, + "CATCH": CATCH, + "CROAK": CROAK, + "LOAD": LOAD, + "RELOAD": RELOAD, + "MAP": MAP, + "MOVE": MOVE, + "HALT": HALT, + "INCMP": INCMP, + "MSIZE": MSIZE, + "MOUT": MOUT, + "MNEXT": MNEXT, + "MPREV": MPREV, + } + )