gofmt-ify math, expvar, exp/spacewar

R=rsc
http://go/go-review/1018061
This commit is contained in:
Robert Griesemer 2009-11-05 09:08:08 -08:00
parent e57acdca4d
commit 3630bfbe9f
6 changed files with 103 additions and 106 deletions

View File

@ -64,8 +64,8 @@ import (
type Word uint32 type Word uint32
const mask = 0777777; const mask = 0777777
const sign = 0400000; const sign = 0400000
const ( const (
_ = iota; // 00 _ = iota; // 00
@ -109,7 +109,7 @@ const (
// The machine calls the Trap method to implement the // The machine calls the Trap method to implement the
// PDP-1 IOT instruction. // PDP-1 IOT instruction.
type Trapper interface { type Trapper interface {
Trap(y Word) Trap(y Word);
} }
// An M represents the machine state of a PDP-1. // An M represents the machine state of a PDP-1.
@ -235,7 +235,7 @@ func (m *M) run(inst Word, t Trapper) os.Error {
case opMUS: case opMUS:
if m.IO & 1 == 1 { if m.IO & 1 == 1 {
m.AC += m.Mem[y]; m.AC += m.Mem[y];
m.AC = norm(m.AC) m.AC = norm(m.AC);
} }
m.IO = (m.IO >> 1 | m.AC << 17)&mask; m.IO = (m.IO >> 1 | m.AC << 17)&mask;
m.AC >>= 1; m.AC >>= 1;
@ -254,14 +254,14 @@ func (m *M) run(inst Word, t Trapper) os.Error {
m.AC = (m.OV << 17) + m.PC; m.AC = (m.OV << 17) + m.PC;
m.PC = y; m.PC = y;
case opSKP: case opSKP:
cond := y&0100 == 0100 && m.AC == 0 cond := y&0100 == 0100 && m.AC == 0 ||
|| y&0200 == 0200 && m.AC>>17 == 0 y&0200 == 0200 && m.AC >> 17 == 0 ||
|| y&0400 == 0400 && m.AC>>17 == 1 y&0400 == 0400 && m.AC >> 17 == 1 ||
|| y&01000 == 01000 && m.OV == 0 y&01000 == 01000 && m.OV == 0 ||
|| y&02000 == 02000 && m.IO>>17 == 0 y&02000 == 02000 && m.IO >> 17 == 0 ||
|| y&7 != 0 && !m.Flag[y&7] y&7 != 0 && !m.Flag[y&7] ||
|| y&070 != 0 && !m.Sense[(y&070)>>3] y&070 != 0 && !m.Sense[(y&070)>>3] ||
|| y&070 == 010; y&070 == 010;
if (ib == 0) == cond { if (ib == 0) == cond {
m.PC++; m.PC++;
} }
@ -388,4 +388,3 @@ func (m *M) Load(r io.Reader) os.Error {
} }
return nil; return nil;
} }

View File

@ -89,9 +89,9 @@ type SpacewarPDP1 struct {
func min(a, b int) int { func min(a, b int) int {
if a < b { if a < b {
return a return a;
} }
return b return b;
} }
func (m *SpacewarPDP1) Init(ctxt draw.Context) { func (m *SpacewarPDP1) Init(ctxt draw.Context) {

View File

@ -12,16 +12,16 @@ import (
func TestInt(t *testing.T) { func TestInt(t *testing.T) {
reqs := NewInt("requests"); reqs := NewInt("requests");
if reqs.i != 0 { if reqs.i != 0 {
t.Errorf("reqs.i = %v, want 4", reqs.i) t.Errorf("reqs.i = %v, want 4", reqs.i);
} }
if reqs != Get("requests").(*Int) { if reqs != Get("requests").(*Int) {
t.Errorf("Get() failed.") t.Errorf("Get() failed.");
} }
reqs.Add(1); reqs.Add(1);
reqs.Add(3); reqs.Add(3);
if reqs.i != 4 { if reqs.i != 4 {
t.Errorf("reqs.i = %v, want 4", reqs.i) t.Errorf("reqs.i = %v, want 4", reqs.i);
} }
if s := reqs.String(); s != "4" { if s := reqs.String(); s != "4" {
@ -32,12 +32,12 @@ func TestInt(t *testing.T) {
func TestString(t *testing.T) { func TestString(t *testing.T) {
name := NewString("my-name"); name := NewString("my-name");
if name.s != "" { if name.s != "" {
t.Errorf("name.s = %q, want \"\"", name.s) t.Errorf("name.s = %q, want \"\"", name.s);
} }
name.Set("Mike"); name.Set("Mike");
if name.s != "Mike" { if name.s != "Mike" {
t.Errorf("name.s = %q, want \"Mike\"", name.s) t.Errorf("name.s = %q, want \"Mike\"", name.s);
} }
if s := name.String(); s != "\"Mike\"" { if s := name.String(); s != "\"Mike\"" {
@ -52,10 +52,10 @@ func TestMapCounter(t *testing.T) {
colours.Add("red", 2); colours.Add("red", 2);
colours.Add("blue", 4); colours.Add("blue", 4);
if x := colours.m["red"].(*Int).i; x != 3 { if x := colours.m["red"].(*Int).i; x != 3 {
t.Errorf("colours.m[\"red\"] = %v, want 3", x) t.Errorf("colours.m[\"red\"] = %v, want 3", x);
} }
if x := colours.m["blue"].(*Int).i; x != 4 { if x := colours.m["blue"].(*Int).i; x != 4 {
t.Errorf("colours.m[\"blue\"] = %v, want 4", x) t.Errorf("colours.m[\"blue\"] = %v, want 4", x);
} }
// colours.String() should be '{"red":3, "blue":4}', // colours.String() should be '{"red":3, "blue":4}',
@ -63,17 +63,17 @@ func TestMapCounter(t *testing.T) {
s := colours.String(); s := colours.String();
j, ok, errtok := json.StringToJson(s); j, ok, errtok := json.StringToJson(s);
if !ok { if !ok {
t.Errorf("colours.String() isn't valid JSON: %v", errtok) t.Errorf("colours.String() isn't valid JSON: %v", errtok);
} }
if j.Kind() != json.MapKind { if j.Kind() != json.MapKind {
t.Error("colours.String() didn't produce a map.") t.Error("colours.String() didn't produce a map.");
} }
red := j.Get("red"); red := j.Get("red");
if red.Kind() != json.NumberKind { if red.Kind() != json.NumberKind {
t.Error("red.Kind() is not a NumberKind.") t.Error("red.Kind() is not a NumberKind.");
} }
if x := red.Number(); x != 3 { if x := red.Number(); x != 3 {
t.Error("red = %v, want 3", x) t.Error("red = %v, want 3", x);
} }
} }

View File

@ -102,4 +102,3 @@ func Modf(f float64) (int float64, frac float64) {
frac = f-int; frac = f-int;
return; return;
} }

View File

@ -27,4 +27,3 @@ func Float64bits(f float64) uint64 {
func Float64frombits(b uint64) float64 { func Float64frombits(b uint64) float64 {
return *(*float64)(unsafe.Pointer(&b)); return *(*float64)(unsafe.Pointer(&b));
} }