mirror of
https://github.com/zellyn/go6502.git
synced 2025-04-10 22:37:08 +00:00
Added name to Flavor interface
This commit is contained in:
parent
17d0dc1d69
commit
8e28615be3
@ -48,3 +48,7 @@ func (a *AS65) FixLabel(label string, macroCall int, locals map[string]bool) (st
|
||||
func (a *AS65) LocalMacroLabels() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (a *AS65) String() string {
|
||||
return "as65"
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ type F interface {
|
||||
DefaultOrigin() (uint16, error)
|
||||
ReplaceMacroArgs(line string, args []string, kwargs map[string]string) (string, error)
|
||||
LocalMacroLabels() bool
|
||||
String() string
|
||||
context.Context
|
||||
context.Labeler
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ const macroNameChars = oldschool.Letters + oldschool.Digits + "_"
|
||||
|
||||
func New() *Merlin {
|
||||
m := &Merlin{}
|
||||
m.Name = "merlin"
|
||||
m.LabelChars = oldschool.Letters + oldschool.Digits + ":"
|
||||
m.LabelColons = oldschool.ReqDisallowed
|
||||
m.ExplicitARegister = oldschool.ReqOptional
|
||||
|
@ -40,6 +40,7 @@ const (
|
||||
// Base implements the S-C Macro Assembler-compatible assembler flavor.
|
||||
// See http://www.txbobsc.com/scsc/ and http://stjarnhimlen.se/apple2/
|
||||
type Base struct {
|
||||
Name string
|
||||
Directives map[string]DirectiveInfo
|
||||
Operators map[string]expr.Operator
|
||||
context.SimpleContext
|
||||
@ -65,6 +66,10 @@ type Base struct {
|
||||
MacroArgSep string
|
||||
}
|
||||
|
||||
func (a *Base) String() string {
|
||||
return a.Name
|
||||
}
|
||||
|
||||
// Parse an entire instruction, or return an appropriate error.
|
||||
func (a *Base) ParseInstr(line lines.Line) (inst.I, error) {
|
||||
lp := line.Parse
|
||||
|
@ -15,20 +15,20 @@ type RedBook struct {
|
||||
}
|
||||
|
||||
func NewRedbookA() *RedBook {
|
||||
r := newRedbook()
|
||||
r := newRedbook("redbook-a")
|
||||
return r
|
||||
}
|
||||
|
||||
func NewRedbookB() *RedBook {
|
||||
r := newRedbook()
|
||||
r := newRedbook("redbook-b")
|
||||
r.ExplicitARegister = oldschool.ReqRequired
|
||||
r.SpacesForComment = 3
|
||||
return r
|
||||
}
|
||||
|
||||
func newRedbook() *RedBook {
|
||||
func newRedbook(name string) *RedBook {
|
||||
r := &RedBook{}
|
||||
|
||||
r.Name = name
|
||||
r.LabelChars = oldschool.Letters + oldschool.Digits + "."
|
||||
r.LabelColons = oldschool.ReqOptional
|
||||
r.ExplicitARegister = oldschool.ReqRequired
|
||||
|
@ -20,6 +20,7 @@ type SCMA struct {
|
||||
|
||||
func New() *SCMA {
|
||||
a := &SCMA{}
|
||||
a.Name = "scma"
|
||||
a.LabelChars = oldschool.Letters + oldschool.Digits + ".:"
|
||||
a.LabelColons = oldschool.ReqDisallowed
|
||||
a.ExplicitARegister = oldschool.ReqDisallowed
|
||||
|
@ -293,7 +293,7 @@ func TestMultiline(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
if tt.b == "" && len(tt.ps) == 0 {
|
||||
t.Fatalf(`%d("%s" - %T): test case must specify bytes or pieces`, i, tt.name, tt.a.Flavor)
|
||||
t.Fatalf(`%d("%s" - %s): test case must specify bytes or pieces`, i, tt.name, tt.a.Flavor)
|
||||
}
|
||||
tt.a.Reset()
|
||||
o.Clear()
|
||||
@ -302,40 +302,40 @@ func TestMultiline(t *testing.T) {
|
||||
o[k] = strings.Join(v, "\n")
|
||||
}
|
||||
if err := tt.a.Load("TESTFILE", 0); err != nil {
|
||||
t.Errorf(`%d("%s" - %T): tt.a.Load("TESTFILE") failed: %s`, i, tt.name, tt.a.Flavor, err)
|
||||
t.Errorf(`%d("%s" - %s): tt.a.Load("TESTFILE") failed: %s`, i, tt.name, tt.a.Flavor, err)
|
||||
continue
|
||||
}
|
||||
isFinal, err := tt.a.Pass(true)
|
||||
if err != nil {
|
||||
t.Errorf(`%d("%s" - %T): tt.a.Pass(true) failed: %s`, i, tt.name, tt.a.Flavor, err)
|
||||
t.Errorf(`%d("%s" - %s): tt.a.Pass(true) failed: %s`, i, tt.name, tt.a.Flavor, err)
|
||||
continue
|
||||
}
|
||||
if !isFinal {
|
||||
t.Errorf(`%d("%s" - %T): tt.a.Pass(true) couldn't finalize`, i, tt.name, tt.a.Flavor)
|
||||
t.Errorf(`%d("%s" - %s): tt.a.Pass(true) couldn't finalize`, i, tt.name, tt.a.Flavor)
|
||||
continue
|
||||
}
|
||||
|
||||
if tt.b != "" {
|
||||
bb, err := tt.a.RawBytes()
|
||||
if err != nil {
|
||||
t.Errorf(`%d("%s" - %T): tt.a.RawBytes() failed: %s`, i, tt.name, tt.a.Flavor, err)
|
||||
t.Errorf(`%d("%s" - %s): tt.a.RawBytes() failed: %s`, i, tt.name, tt.a.Flavor, err)
|
||||
continue
|
||||
}
|
||||
hx := hex.EncodeToString(bb)
|
||||
if hx != tt.b {
|
||||
t.Errorf(`%d("%s" - %T): tt.a.RawBytes()=[%s]; want [%s]`, i, tt.name, tt.a.Flavor, hx, tt.b)
|
||||
t.Errorf(`%d("%s" - %s): tt.a.RawBytes()=[%s]; want [%s]`, i, tt.name, tt.a.Flavor, hx, tt.b)
|
||||
continue
|
||||
}
|
||||
}
|
||||
if len(tt.ps) != 0 {
|
||||
m, err := tt.a.Membuf()
|
||||
if err != nil {
|
||||
t.Errorf(`%d("%s" - %T): tt.a.Membuf() failed: %s`, i, tt.name, tt.a.Flavor, err)
|
||||
t.Errorf(`%d("%s" - %s): tt.a.Membuf() failed: %s`, i, tt.name, tt.a.Flavor, err)
|
||||
continue
|
||||
}
|
||||
ps := m.Pieces()
|
||||
if !reflect.DeepEqual(ps, tt.ps) {
|
||||
t.Errorf(`%d("%s" - %T): tt.Membuf().Pieces() = %v; want %v`, i, tt.name, tt.a.Flavor, ps, tt.ps)
|
||||
t.Errorf(`%d("%s" - %s): tt.Membuf().Pieces() = %v; want %v`, i, tt.name, tt.a.Flavor, ps, tt.ps)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ func TestSimpleCommonFunctions(t *testing.T) {
|
||||
|
||||
inst, err := tt.a.ParseInstr(lines.NewSimple(tt.i))
|
||||
if err != nil {
|
||||
t.Errorf(`%d. %T.ParseInstr("%s") => error: %s`, i, tt.a, tt.i, err)
|
||||
t.Errorf(`%d. %s.ParseInstr("%s") => error: %s`, i, tt.a, tt.i, err)
|
||||
continue
|
||||
}
|
||||
if inst.Line.Parse == nil {
|
||||
@ -239,11 +239,11 @@ func TestSimpleCommonFunctions(t *testing.T) {
|
||||
}
|
||||
_, err = inst.Compute(tt.a, true)
|
||||
if err != nil {
|
||||
t.Errorf(`%d. %T.ParseInstr("%s"): %s.Compute(tt.a, true) => error: %s`, i, tt.a, tt.i, inst, err)
|
||||
t.Errorf(`%d. %s.ParseInstr("%s"): %s.Compute(tt.a, true) => error: %s`, i, tt.a, tt.i, inst, err)
|
||||
continue
|
||||
}
|
||||
if inst.String() != tt.p {
|
||||
t.Errorf(`%d. %T.ParseInstr("%s") = %s; want %s`, i, tt.a, tt.i, inst.String(), tt.p)
|
||||
t.Errorf(`%d. %s.ParseInstr("%s") = %s; want %s`, i, tt.a, tt.i, inst.String(), tt.p)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -251,7 +251,7 @@ func TestSimpleCommonFunctions(t *testing.T) {
|
||||
hx := hex.EncodeToString(inst.Data)
|
||||
// xxxxxx sets the width, but doesn't expect actual data
|
||||
if hx != tt.b && (len(tt.b) == 0 || tt.b[0] != 'x') {
|
||||
t.Errorf(`%d. %T.ParseInstr("%s").Data = [%s]; want [%s]`, i, tt.a, tt.i, hx, tt.b)
|
||||
t.Errorf(`%d. %s.ParseInstr("%s").Data = [%s]; want [%s]`, i, tt.a, tt.i, hx, tt.b)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -295,7 +295,7 @@ func TestSimpleErrors(t *testing.T) {
|
||||
}
|
||||
inst, err := tt.a.ParseInstr(lines.NewSimple(tt.i))
|
||||
if err == nil {
|
||||
t.Errorf(`%d. %T.ParseInstr("%s") want err; got %s`, i, tt.a, tt.i, inst)
|
||||
t.Errorf(`%d. %s.ParseInstr("%s") want err; got %s`, i, tt.a, tt.i, inst)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user