1
0
mirror of https://github.com/zellyn/go6502.git synced 2024-06-06 20:29:34 +00:00

More simplifying: address is always known

This commit is contained in:
Zellyn Hunter 2014-08-08 20:49:42 -07:00
parent 8e28615be3
commit 88ef7feee5
8 changed files with 11 additions and 40 deletions

View File

@ -184,11 +184,7 @@ func (a *Assembler) readMacro(in inst.I, ls lines.LineSource) error {
func (a *Assembler) initPass() {
a.Flavor.SetLastLabel("") // No last label (yet)
a.Flavor.RemoveChanged() // Remove any variables whose value ever changed.
if org, err := a.Flavor.DefaultOrigin(); err == nil {
a.Flavor.SetAddr(org)
} else {
a.Flavor.ClearAddr("beginning of assembly")
}
a.Flavor.SetAddr(a.Flavor.DefaultOrigin())
}
// passInst performs a pass on a single instruction. It forces the
@ -204,17 +200,9 @@ func (a *Assembler) passInst(in *inst.I, final bool) (isFinal bool, err error) {
}
// Update address
if a.Flavor.AddrKnown() {
addr, _ := a.Flavor.GetAddr()
in.Addr = addr
in.AddrKnown = true
if in.WidthKnown {
a.Flavor.SetAddr(addr + in.Width)
} else {
a.Flavor.ClearAddr(in.Sprintf("lost known address"))
}
}
addr, _ := a.Flavor.GetAddr()
in.Addr = addr
a.Flavor.SetAddr(addr + in.Width)
return isFinal, nil
}
@ -267,9 +255,6 @@ func (a *Assembler) Membuf() (*membuf.Membuf, error) {
if !in.Final {
return nil, in.Errorf("cannot finalize value: %s", in)
}
if !in.AddrKnown {
return nil, in.Errorf("address unknown: %s", in)
}
if in.Width > 0 {
m.Write(int(in.Addr), in.Data)
}
@ -282,9 +267,6 @@ func (a *Assembler) GenerateListing(w io.Writer, width int) error {
if !in.Final {
return in.Errorf("cannot finalize value: %s", in)
}
if !in.AddrKnown {
return in.Errorf("address unknown: %s", in)
}
for i := 0; i < len(in.Data) || i < width; i++ {
if i%width == 0 {

View File

@ -11,7 +11,6 @@ type Context interface {
GetAddr() (uint16, bool)
Zero() (uint16, error) // type ZeroFunc
RemoveChanged()
AddrKnown() bool
Clear()
SettingOn(name string) error
SettingOff(name string) error
@ -76,10 +75,6 @@ func (sc *SimpleContext) GetAddr() (uint16, bool) {
return uint16(sc.addr), true
}
func (sc *SimpleContext) AddrKnown() bool {
return sc.addr != -1
}
func (sc *SimpleContext) Set(name string, value uint16) {
sc.fix()
s, found := sc.symbols[name]

View File

@ -118,11 +118,6 @@ func (e *E) Eval(ctx context.Context, ln *lines.Line) (uint16, error) {
if val, ok := ctx.Get(e.Text); ok {
return val, nil
}
if e.Text == "*" && !ctx.AddrKnown() {
e := ln.Errorf("address unknown due to %v", ctx.ClearMesg())
return 0, UnknownLabelError{Err: e}
}
return 0, UnknownLabelError{Err: ln.Errorf("unknown label: %s", e.Text)}
case OpMinus:
l, err := e.Left.Eval(ctx, ln)

View File

@ -29,8 +29,8 @@ func (a *AS65) Zero() (uint16, error) {
return 0, errors.New("Division by zero.")
}
func (a *AS65) DefaultOrigin() (uint16, error) {
return 0, nil
func (a *AS65) DefaultOrigin() uint16 {
return 0
}
func (a *AS65) ReplaceMacroArgs(line string, args []string, kwargs map[string]string) (string, error) {

View File

@ -8,7 +8,7 @@ import (
type F interface {
ParseInstr(Line lines.Line) (inst.I, error)
DefaultOrigin() (uint16, error)
DefaultOrigin() uint16
ReplaceMacroArgs(line string, args []string, kwargs map[string]string) (string, error)
LocalMacroLabels() bool
String() string

View File

@ -160,8 +160,8 @@ func (m *Merlin) Zero() (uint16, error) {
return 0, errors.New("Division by zero.")
}
func (m *Merlin) DefaultOrigin() (uint16, error) {
return 0x8000, nil
func (m *Merlin) DefaultOrigin() uint16 {
return 0x8000
}
func (m *Merlin) ParseInclude(in inst.I, lp *lines.Parse) (inst.I, error) {

View File

@ -129,8 +129,8 @@ func (a *Base) ParseInstr(line lines.Line) (inst.I, error) {
return a.ParseCmd(in, lp)
}
func (a *Base) DefaultOrigin() (uint16, error) {
return 0x0800, nil
func (a *Base) DefaultOrigin() uint16 {
return 0x0800
}
// ParseCmd parses the "command" part of an instruction: we expect to be

View File

@ -73,7 +73,6 @@ type I struct {
DeclaredLine uint16 // Line number listed in file
Line *lines.Line // Line object for this line
Addr uint16 // Current memory address
AddrKnown bool // Whether the current memory address is known
Var int // Variant of instruction type
}