Add assembler binary
This commit is contained in:
parent
19d8c66afe
commit
aab804e8ff
@ -104,7 +104,7 @@ var (
|
|||||||
asmLexer = lexer.MustSimple([]lexer.SimpleRule{
|
asmLexer = lexer.MustSimple([]lexer.SimpleRule{
|
||||||
{"Comment", `(?:#)[^\n]*\n?`},
|
{"Comment", `(?:#)[^\n]*\n?`},
|
||||||
{"Ident", `^[A-Z]+`},
|
{"Ident", `^[A-Z]+`},
|
||||||
{"Sym", `[a-zA-Z]+`},
|
{"Sym", `[a-zA-Z0-9_]+`},
|
||||||
{"Size", `[0-9]+`},
|
{"Size", `[0-9]+`},
|
||||||
{"Whitespace", `[ \t\n\r]+`},
|
{"Whitespace", `[ \t\n\r]+`},
|
||||||
{"Quote", `["']`},
|
{"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) {
|
func Parse(s string, w io.Writer) (int, error) {
|
||||||
rd := strings.NewReader(s)
|
rd := strings.NewReader(s)
|
||||||
ast, err := asmParser.Parse("file", rd)
|
ast, err := asmParser.Parse("file", rd)
|
||||||
var rn int
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var rn int
|
||||||
for _, v := range ast.Instructions {
|
for _, v := range ast.Instructions {
|
||||||
op := vm.OpcodeIndex[v.OpCode]
|
op := vm.OpcodeIndex[v.OpCode]
|
||||||
n, err := parseSized(op, v.OpArg, w)
|
n, err := parseSized(op, v.OpArg, w)
|
||||||
|
28
go/dev/asm/asm.go
Normal file
28
go/dev/asm/asm.go
Normal file
@ -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)
|
||||||
|
}
|
7
go/testdata/foo.fst
vendored
Normal file
7
go/testdata/foo.fst
vendored
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user