Skip to content

Commit

Permalink
archive/cs: Fix golint issues.
Browse files Browse the repository at this point in the history
error strings should not end with punctuation
should replace exp += 1 with exp++
should replace exp -= 1 with exp--
comment on exported const CodeHalt should be of the form "CodeHalt ..."
  • Loading branch information
mewmew committed Feb 2, 2015
1 parent c2b868e commit bde9908
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 157 deletions.
2 changes: 1 addition & 1 deletion archive/cs/asm/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Decode(r io.Reader) (insts []interface{}, err error) {
// DecodeSlice decodes and returns the instructions of the byte slice.
func DecodeSlice(p []byte) (insts []interface{}, err error) {
if len(p)%op.InstSize != 0 {
return nil, fmt.Errorf("asm.DecodeSlice: p len (%d) not evenly dividable by %d.", len(p), op.InstSize)
return nil, fmt.Errorf("asm.DecodeSlice: p len (%d) not evenly dividable by %d", len(p), op.InstSize)
}

insts = make([]interface{}, 0, len(p)/op.InstSize)
Expand Down
2 changes: 1 addition & 1 deletion archive/cs/asm/cmd/disasm/disasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func disasm() (insts []interface{}, err error) {
// parseHex parses the provided hexadecimal string into a slice of instructions.
func parseHex(s string) (insts []interface{}, err error) {
if len(s)%4 != 0 {
return nil, fmt.Errorf("parseHex: string len (%d) not evenly dividable by 4.", len(s))
return nil, fmt.Errorf("parseHex: string len (%d) not evenly dividable by 4", len(s))
}

insts = make([]interface{}, 0, len(s)/4)
Expand Down
10 changes: 5 additions & 5 deletions archive/cs/emu/emu.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ func (pc *PC) Inc(n int) (err error) {
case n < 0:
// A negative n value should never make PC larger.
if newPC > oldPC {
return fmt.Errorf("PC.Inc: integer underflow occurred; old PC (%d), new PC (%d), n (%d).", oldPC, newPC, n)
return fmt.Errorf("PC.Inc: integer underflow occurred; old PC (%d), new PC (%d), n (%d)", oldPC, newPC, n)
}
case n > 0:
// A positive n value should never make PC smaller.
if newPC < oldPC {
return fmt.Errorf("PC.Inc: integer overflow occurred; old PC (%d), new PC (%d), n (%d).", oldPC, newPC, n)
return fmt.Errorf("PC.Inc: integer overflow occurred; old PC (%d), new PC (%d), n (%d)", oldPC, newPC, n)
}
}
*pc = newPC
Expand Down Expand Up @@ -71,7 +71,7 @@ func New(r io.Reader) (sys *System, err error) {
// FetchInst fetches the next instruction and increments the program counter.
func (sys *System) FetchInst() (buf uint16, err error) {
if int(sys.PC)+op.InstSize > len(sys.Mem) {
return 0, fmt.Errorf("System.FetchInst: instruction at PC (%d) is outside of Mem.", sys.PC)
return 0, fmt.Errorf("System.FetchInst: instruction at PC (%d) is outside of Mem", sys.PC)
}
buf = binary.BigEndian.Uint16(sys.Mem[sys.PC:])
err = sys.PC.Inc(op.InstSize)
Expand All @@ -83,7 +83,7 @@ func (sys *System) FetchInst() (buf uint16, err error) {

// ErrHalted is returned when trying to execute an instruction while the system
// is halted.
var ErrHalted = errors.New("emu: system is halted.")
var ErrHalted = errors.New("emu: system is halted")

// Step decodes and executes one instruction.
func (sys *System) Step() (err error) {
Expand Down Expand Up @@ -170,7 +170,7 @@ func (sys *System) Exec(inst interface{}) (err error) {
return err
}
default:
return fmt.Errorf("System.Step: instruction (%T) not handled.", inst)
return fmt.Errorf("System.Step: instruction (%T) not handled", inst)
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions archive/cs/float8/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ func Add(x, y Float8) (z Float8, err error) {
// TODO(u): Allow the Float8 value to overflow and underflow?
if pos > 10 {
// exponent overflow.
return 0, fmt.Errorf("float8.Add: exponent overflow; can't represent %v + %v in 8-bit floating-point notation.", x, y)
return 0, fmt.Errorf("float8.Add: exponent overflow; can't represent %v + %v in 8-bit floating-point notation", x, y)
} else if pos < 3 {
// exponent underflow.
return 0, fmt.Errorf("float8.Add: exponent underflow; can't represent %v + %v in 8-bit floating-point notation.", x, y)
return 0, fmt.Errorf("float8.Add: exponent underflow; can't represent %v + %v in 8-bit floating-point notation", x, y)
}

// Encode exponent of z.
Expand Down
10 changes: 5 additions & 5 deletions archive/cs/float8/float8.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ func New(x float32) (f Float8, err error) {
// Exponent.
exp := int(bits & 0x7F800000 >> 23)
exp -= 127 // excess 127 notation.
exp += 1 // adjust exponent for the implicit 1.
exp++ // adjust exponent for the implicit 1.
if exp < -4 {
return 0, fmt.Errorf("float8.New: invalid exponent (%d) for %v; below -4.", exp, x)
return 0, fmt.Errorf("float8.New: invalid exponent (%d) for %v; below -4", exp, x)
} else if exp > 3 {
return 0, fmt.Errorf("float8.New: invalid exponent (%d) for %v; above 3.", exp, x)
return 0, fmt.Errorf("float8.New: invalid exponent (%d) for %v; above 3", exp, x)
}

// Encode exponent.
Expand Down Expand Up @@ -141,7 +141,7 @@ func (f Float8) Float32() float32 {

// Exponent.
exp := f.Exp()
exp -= 1 // adjust exponent for the implicit 1.
exp-- // adjust exponent for the implicit 1.

// Encode exponent.
xexp := uint8(exp)
Expand Down Expand Up @@ -181,7 +181,7 @@ func (f Float8) Mantissa() uint {
mantissa := uint(f & 0xF)
if mantissa != 0 && mantissa&0x8 == 0 {
// The mantissa is not represented in normalized form.
panic(fmt.Sprintf("mantissa (%04b) in f (%08b) is not represented in normalized form.", mantissa, f))
panic(fmt.Sprintf("mantissa (%04b) in f (%08b) is not represented in normalized form", mantissa, f))
}
return mantissa
}
56 changes: 28 additions & 28 deletions archive/cs/risc/op/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func Decode(buf uint16) (inst interface{}, err error) {
// padding.
pad := buf & 0x0FFF
if pad != 0 {
return nil, fmt.Errorf("op.Decode: invalid padding (%X) in %04X (%s).", pad, buf, code)
return nil, fmt.Errorf("op.Decode: invalid padding (%X) in %04X (%s)", pad, buf, code)
}

inst = &Nop{
Expand All @@ -27,7 +27,7 @@ func Decode(buf uint16) (inst interface{}, err error) {
// dst register.
dst := Reg(buf & 0x0F00 >> 8)
if dst >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid dst register (%d) in %04X (%s).", dst, buf, code)
return nil, fmt.Errorf("op.Decode: invalid dst register (%d) in %04X (%s)", dst, buf, code)
}

// src memory address.
Expand All @@ -47,7 +47,7 @@ func Decode(buf uint16) (inst interface{}, err error) {
// dst register.
dst := Reg(buf & 0x0F00 >> 8)
if dst >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid dst register (%d) in %04X (%s).", dst, buf, code)
return nil, fmt.Errorf("op.Decode: invalid dst register (%d) in %04X (%s)", dst, buf, code)
}

// src immediate value.
Expand All @@ -67,7 +67,7 @@ func Decode(buf uint16) (inst interface{}, err error) {
// src register.
src := Reg(buf & 0x0F00 >> 8)
if src >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid src register (%d) in %04X (%s).", src, buf, code)
return nil, fmt.Errorf("op.Decode: invalid src register (%d) in %04X (%s)", src, buf, code)
}

// dst memory address.
Expand All @@ -87,19 +87,19 @@ func Decode(buf uint16) (inst interface{}, err error) {
// padding.
pad := buf & 0x0F00 >> 8
if pad != 0 {
return nil, fmt.Errorf("op.Decode: invalid padding (%X) in %04X (%s).", pad, buf, code)
return nil, fmt.Errorf("op.Decode: invalid padding (%X) in %04X (%s)", pad, buf, code)
}

// src register.
src := Reg(buf & 0x00F0 >> 4)
if src >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid src register (%d) in %04X (%s).", src, buf, code)
return nil, fmt.Errorf("op.Decode: invalid src register (%d) in %04X (%s)", src, buf, code)
}

// dst register.
dst := Reg(buf & 0x000F)
if dst >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid dst register (%d) in %04X (%s).", dst, buf, code)
return nil, fmt.Errorf("op.Decode: invalid dst register (%d) in %04X (%s)", dst, buf, code)
}

inst = &Move{
Expand All @@ -117,19 +117,19 @@ func Decode(buf uint16) (inst interface{}, err error) {
// dst register.
dst := Reg(buf & 0x0F00 >> 8)
if dst >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid dst register (%d) in %04X (%s).", dst, buf, code)
return nil, fmt.Errorf("op.Decode: invalid dst register (%d) in %04X (%s)", dst, buf, code)
}

// src1 register.
src1 := Reg(buf & 0x00F0 >> 4)
if src1 >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid src1 register (%d) in %04X (%s).", src1, buf, code)
return nil, fmt.Errorf("op.Decode: invalid src1 register (%d) in %04X (%s)", src1, buf, code)
}

// src2 register.
src2 := Reg(buf & 0x000F)
if src2 >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid src2 register (%d) in %04X (%s).", src2, buf, code)
return nil, fmt.Errorf("op.Decode: invalid src2 register (%d) in %04X (%s)", src2, buf, code)
}

inst = &Add{
Expand All @@ -148,19 +148,19 @@ func Decode(buf uint16) (inst interface{}, err error) {
// dst register.
dst := Reg(buf & 0x0F00 >> 8)
if dst >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid dst register (%d) in %04X (%s).", dst, buf, code)
return nil, fmt.Errorf("op.Decode: invalid dst register (%d) in %04X (%s)", dst, buf, code)
}

// src1 register.
src1 := Reg(buf & 0x00F0 >> 4)
if src1 >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid src1 register (%d) in %04X (%s).", src1, buf, code)
return nil, fmt.Errorf("op.Decode: invalid src1 register (%d) in %04X (%s)", src1, buf, code)
}

// src2 register.
src2 := Reg(buf & 0x000F)
if src2 >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid src2 register (%d) in %04X (%s).", src2, buf, code)
return nil, fmt.Errorf("op.Decode: invalid src2 register (%d) in %04X (%s)", src2, buf, code)
}

inst = &AddFloat{
Expand All @@ -179,19 +179,19 @@ func Decode(buf uint16) (inst interface{}, err error) {
// dst register.
dst := Reg(buf & 0x0F00 >> 8)
if dst >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid dst register (%d) in %04X (%s).", dst, buf, code)
return nil, fmt.Errorf("op.Decode: invalid dst register (%d) in %04X (%s)", dst, buf, code)
}

// src1 register.
src1 := Reg(buf & 0x00F0 >> 4)
if src1 >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid src1 register (%d) in %04X (%s).", src1, buf, code)
return nil, fmt.Errorf("op.Decode: invalid src1 register (%d) in %04X (%s)", src1, buf, code)
}

// src2 register.
src2 := Reg(buf & 0x000F)
if src2 >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid src2 register (%d) in %04X (%s).", src2, buf, code)
return nil, fmt.Errorf("op.Decode: invalid src2 register (%d) in %04X (%s)", src2, buf, code)
}

inst = &Or{
Expand All @@ -210,19 +210,19 @@ func Decode(buf uint16) (inst interface{}, err error) {
// dst register.
dst := Reg(buf & 0x0F00 >> 8)
if dst >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid dst register (%d) in %04X (%s).", dst, buf, code)
return nil, fmt.Errorf("op.Decode: invalid dst register (%d) in %04X (%s)", dst, buf, code)
}

// src1 register.
src1 := Reg(buf & 0x00F0 >> 4)
if src1 >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid src1 register (%d) in %04X (%s).", src1, buf, code)
return nil, fmt.Errorf("op.Decode: invalid src1 register (%d) in %04X (%s)", src1, buf, code)
}

// src2 register.
src2 := Reg(buf & 0x000F)
if src2 >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid src2 register (%d) in %04X (%s).", src2, buf, code)
return nil, fmt.Errorf("op.Decode: invalid src2 register (%d) in %04X (%s)", src2, buf, code)
}

inst = &And{
Expand All @@ -241,19 +241,19 @@ func Decode(buf uint16) (inst interface{}, err error) {
// dst register.
dst := Reg(buf & 0x0F00 >> 8)
if dst >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid dst register (%d) in %04X (%s).", dst, buf, code)
return nil, fmt.Errorf("op.Decode: invalid dst register (%d) in %04X (%s)", dst, buf, code)
}

// src1 register.
src1 := Reg(buf & 0x00F0 >> 4)
if src1 >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid src1 register (%d) in %04X (%s).", src1, buf, code)
return nil, fmt.Errorf("op.Decode: invalid src1 register (%d) in %04X (%s)", src1, buf, code)
}

// src2 register.
src2 := Reg(buf & 0x000F)
if src2 >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid src2 register (%d) in %04X (%s).", src2, buf, code)
return nil, fmt.Errorf("op.Decode: invalid src2 register (%d) in %04X (%s)", src2, buf, code)
}

inst = &Xor{
Expand All @@ -271,19 +271,19 @@ func Decode(buf uint16) (inst interface{}, err error) {
// register.
reg := Reg(buf & 0x0F00 >> 8)
if reg >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid register (%d) in %04X (%s).", reg, buf, code)
return nil, fmt.Errorf("op.Decode: invalid register (%d) in %04X (%s)", reg, buf, code)
}

// padding.
pad := buf & 0x00F0 >> 4
if pad != 0 {
return nil, fmt.Errorf("op.Decode: invalid padding (%X) in %04X (%s).", pad, buf, code)
return nil, fmt.Errorf("op.Decode: invalid padding (%X) in %04X (%s)", pad, buf, code)
}

// immediate value x.
x := Val(buf & 0x000F)
if x >= RegSize {
return nil, fmt.Errorf("op.Decode: invalid x (%d) in %04X (%s); above %d.", x, buf, code, RegSize-1)
return nil, fmt.Errorf("op.Decode: invalid x (%d) in %04X (%s); above %d", x, buf, code, RegSize-1)
}

inst = &Ror{
Expand All @@ -300,7 +300,7 @@ func Decode(buf uint16) (inst interface{}, err error) {
// cmp register.
cmp := Reg(buf & 0x0F00 >> 8)
if cmp >= RegCount {
return nil, fmt.Errorf("op.Decode: invalid cmp register (%d) in %04X (%s).", cmp, buf, code)
return nil, fmt.Errorf("op.Decode: invalid cmp register (%d) in %04X (%s)", cmp, buf, code)
}

// memory address addr.
Expand All @@ -318,15 +318,15 @@ func Decode(buf uint16) (inst interface{}, err error) {
// padding.
pad := buf & 0x0FFF
if pad != 0 {
return nil, fmt.Errorf("op.Decode: invalid padding (%X) in %04X (%s).", pad, buf, code)
return nil, fmt.Errorf("op.Decode: invalid padding (%X) in %04X (%s)", pad, buf, code)
}

inst = &Halt{
Code: code,
}

default:
return nil, fmt.Errorf("op.Decode: invalid code (%d) in %04X.", code, buf)
return nil, fmt.Errorf("op.Decode: invalid code (%d) in %04X", code, buf)
}

return inst, nil
Expand Down
Loading

0 comments on commit bde9908

Please sign in to comment.