Add asm parser
This commit is contained in:
parent
664eab98d9
commit
d3fb782a8c
@ -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
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user