Commit 4f61fc96 authored by Rob Pike's avatar Rob Pike

test: remove semiocolons.

The ken directory is untouched so we have some examples with explicit semis.

R=gri
CC=golang-dev
https://golang.org/cl/2157041
parent cd8f4cd2
This diff is collapsed.
......@@ -9,45 +9,45 @@ package main
import "sync"
type T struct {
int;
sync.Mutex;
int
sync.Mutex
}
func main() {
{
var x, y sync.Mutex;
x = y; // ERROR "assignment.*Mutex"
_ = x;
var x, y sync.Mutex
x = y // ERROR "assignment.*Mutex"
_ = x
}
{
var x, y T;
x = y; // ERROR "assignment.*Mutex"
_ = x;
var x, y T
x = y // ERROR "assignment.*Mutex"
_ = x
}
{
var x, y [2]sync.Mutex;
x = y; // ERROR "assignment.*Mutex"
_ = x;
var x, y [2]sync.Mutex
x = y // ERROR "assignment.*Mutex"
_ = x
}
{
var x, y [2]T;
x = y; // ERROR "assignment.*Mutex"
_ = x;
var x, y [2]T
x = y // ERROR "assignment.*Mutex"
_ = x
}
{
x := sync.Mutex{0, 0}; // ERROR "assignment.*Mutex"
_ = x;
x := sync.Mutex{0, 0} // ERROR "assignment.*Mutex"
_ = x
}
{
x := sync.Mutex{key: 0}; // ERROR "(unknown|assignment).*Mutex"
_ = x;
x := sync.Mutex{key: 0} // ERROR "(unknown|assignment).*Mutex"
_ = x
}
{
x := &sync.Mutex{}; // ok
var y sync.Mutex; // ok
y = *x; // ERROR "assignment.*Mutex"
*x = y; // ERROR "assignment.*Mutex"
_ = x;
_ = y;
x := &sync.Mutex{} // ok
var y sync.Mutex // ok
y = *x // ERROR "assignment.*Mutex"
*x = y // ERROR "assignment.*Mutex"
_ = x
_ = y
}
}
......@@ -7,35 +7,35 @@
package main
type T struct {
a float64;
b int64;
c string;
d byte;
a float64
b int64
c string
d byte
}
var a = []int{ 1, 2, 3 }
var NIL []int;
var NIL []int
func arraycmptest() {
if NIL != nil {
println("fail1:", NIL, "!= nil");
println("fail1:", NIL, "!= nil")
}
if nil != NIL {
println("fail2: nil !=", NIL);
println("fail2: nil !=", NIL)
}
if a == nil || nil == a {
println("fail3:", a, "== nil");
println("fail3:", a, "== nil")
}
}
func SameArray(a, b []int) bool {
if len(a) != len(b) || cap(a) != cap(b) {
return false;
return false
}
if len(a) > 0 && &a[0] != &b[0] {
return false;
return false
}
return true;
return true
}
var t = T{1.5, 123, "hello", 255}
......@@ -43,16 +43,16 @@ var mt = make(map[int]T)
var ma = make(map[int][]int)
func maptest() {
mt[0] = t;
t1 := mt[0];
mt[0] = t
t1 := mt[0]
if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d {
println("fail: map val struct", t1.a, t1.b, t1.c, t1.d);
println("fail: map val struct", t1.a, t1.b, t1.c, t1.d)
}
ma[1] = a;
a1 := ma[1];
ma[1] = a
a1 := ma[1]
if !SameArray(a, a1) {
println("fail: map val array", a, a1);
println("fail: map val array", a, a1)
}
}
......@@ -60,21 +60,21 @@ var ct = make(chan T)
var ca = make(chan []int)
func send() {
ct <- t;
ca <- a;
ct <- t
ca <- a
}
func chantest() {
go send();
go send()
t1 := <-ct;
t1 := <-ct
if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d {
println("fail: map val struct", t1.a, t1.b, t1.c, t1.d);
println("fail: map val struct", t1.a, t1.b, t1.c, t1.d)
}
a1 := <-ca;
a1 := <-ca
if !SameArray(a, a1) {
println("fail: map val array", a, a1);
println("fail: map val array", a, a1)
}
}
......@@ -82,36 +82,36 @@ type E struct { }
var e E
func interfacetest() {
var i interface{};
var i interface{}
i = a;
a1 := i.([]int);
i = a
a1 := i.([]int)
if !SameArray(a, a1) {
println("interface <-> []int", a, a1);
println("interface <-> []int", a, a1)
}
pa := new([]int);
*pa = a;
i = pa;
a1 = *i.(*[]int);
pa := new([]int)
*pa = a
i = pa
a1 = *i.(*[]int)
if !SameArray(a, a1) {
println("interface <-> *[]int", a, a1);
println("interface <-> *[]int", a, a1)
}
i = t;
t1 := i.(T);
i = t
t1 := i.(T)
if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d {
println("interface <-> struct", t1.a, t1.b, t1.c, t1.d);
println("interface <-> struct", t1.a, t1.b, t1.c, t1.d)
}
i = e;
e1 := i.(E);
i = e
e1 := i.(E)
// nothing to check; just verify it doesn't crash
_ = e1;
_ = e1
}
func main() {
arraycmptest();
maptest();
chantest();
interfacetest();
arraycmptest()
maptest()
chantest()
interfacetest()
}
......@@ -11,7 +11,7 @@ import _ "fmt"
var call string
type T struct {
_, _, _ int;
_, _, _ int
}
func (T) _() {
......@@ -21,11 +21,11 @@ func (T) _() {
}
const (
c0 = iota;
_;
_;
_;
c4;
c0 = iota
_
_
_
c4
)
var ints = []string {
......@@ -35,12 +35,12 @@ var ints = []string {
}
func f() (int, int) {
call += "f";
call += "f"
return 1,2
}
func g() (float, float) {
call += "g";
call += "g"
return 3,4
}
......@@ -48,54 +48,54 @@ func h(_ int, _ float) {
}
func i() int {
call += "i";
return 23;
call += "i"
return 23
}
var _ = i();
var _ = i()
func main() {
if call != "i" {panic("init did not run")}
call = "";
_, _ = f();
a, _ := f();
call = ""
_, _ = f()
a, _ := f()
if a != 1 {panic(a)}
b, _ := g();
b, _ := g()
if b != 3 {panic(b)}
_, a = f();
_, a = f()
if a != 2 {panic(a)}
_, b = g();
_, b = g()
if b != 4 {panic(b)}
_ = i();
_ = i()
if call != "ffgfgi" {panic(call)}
if c4 != 4 {panic(c4)}
out := "";
out := ""
for _, s := range ints {
out += s;
out += s
}
if out != "123" {panic(out)}
sum := 0;
sum := 0
for s, _ := range ints {
sum += s;
sum += s
}
if sum != 3 {panic(sum)}
h(a,b);
h(a,b)
}
// useless but legal
var _ int = 1;
var _ = 2;
var _, _ = 3, 4;
const _ = 3;
const _, _ = 4, 5;
type _ int;
var _ int = 1
var _ = 2
var _, _ = 3, 4
const _ = 3
const _, _ = 4, 5
type _ int
func _() {
panic("oops")
}
func ff() {
var _ int = 1;
var _ int = 1
}
......@@ -7,6 +7,6 @@
package _ // ERROR "invalid package name _"
func main() {
_(); // ERROR "cannot use _ as value"
x := _+1; // ERROR "cannot use _ as value"
_() // ERROR "cannot use _ as value"
x := _+1 // ERROR "cannot use _ as value"
}
......@@ -13,20 +13,20 @@ import "os"
const N = 10
func AsynchFifo() {
ch := make(chan int, N);
ch := make(chan int, N)
for i := 0; i < N; i++ {
ch <- i
}
for i := 0; i < N; i++ {
if <-ch != i {
print("bad receive\n");
os.Exit(1);
print("bad receive\n")
os.Exit(1)
}
}
}
func Chain(ch <-chan int, val int, in <-chan int, out chan<- int) {
<-in;
<-in
if <-ch != val {
panic(val)
}
......@@ -35,15 +35,15 @@ func Chain(ch <-chan int, val int, in <-chan int, out chan<- int) {
// thread together a daisy chain to read the elements in sequence
func SynchFifo() {
ch := make(chan int);
in := make(chan int);
start := in;
ch := make(chan int)
in := make(chan int)
start := in
for i := 0; i < N; i++ {
out := make(chan int);
go Chain(ch, i, in, out);
in = out;
out := make(chan int)
go Chain(ch, i, in, out)
in = out
}
start <- 0;
start <- 0
for i := 0; i < N; i++ {
ch <- i
}
......@@ -51,7 +51,7 @@ func SynchFifo() {
}
func main() {
AsynchFifo();
SynchFifo();
AsynchFifo()
SynchFifo()
}
......@@ -10,32 +10,32 @@
package main
import (
"os";
"strconv";
"os"
"strconv"
)
func f(left, right chan int) {
left <- <-right;
left <- <-right
}
func main() {
var n = 10000;
var n = 10000
if len(os.Args) > 1 {
var err os.Error;
n, err = strconv.Atoi(os.Args[1]);
var err os.Error
n, err = strconv.Atoi(os.Args[1])
if err != nil {
print("bad arg\n");
os.Exit(1);
print("bad arg\n")
os.Exit(1)
}
}
leftmost := make(chan int);
right := leftmost;
left := leftmost;
leftmost := make(chan int)
right := leftmost
left := leftmost
for i := 0; i < n; i++ {
right = make(chan int);
go f(left, right);
left = right;
right = make(chan int)
go f(left, right)
left = right
}
go func(c chan int) { c <- 1 }(right);
<-leftmost;
go func(c chan int) { c <- 1 }(right)
<-leftmost
}
......@@ -7,51 +7,51 @@
package main
var (
cr <-chan int;
cs chan<- int;
c chan int;
cr <-chan int
cs chan<- int
c chan int
)
func main() {
cr = c; // ok
cs = c; // ok
c = cr; // ERROR "illegal types|incompatible|cannot"
c = cs; // ERROR "illegal types|incompatible|cannot"
cr = cs; // ERROR "illegal types|incompatible|cannot"
cs = cr; // ERROR "illegal types|incompatible|cannot"
c <- 0; // ok
ok := c <- 0; // ok
_ = ok;
<-c; // ok
x, ok := <-c; // ok
_, _ = x, ok;
cr <- 0; // ERROR "send"
ok = cr <- 0; // ERROR "send"
_ = ok;
<-cr; // ok
x, ok = <-cr; // ok
_, _ = x, ok;
cs <- 0; // ok
ok = cs <- 0; // ok
_ = ok;
<-cs; // ERROR "receive"
x, ok = <-cs; // ERROR "receive"
_, _ = x, ok;
cr = c // ok
cs = c // ok
c = cr // ERROR "illegal types|incompatible|cannot"
c = cs // ERROR "illegal types|incompatible|cannot"
cr = cs // ERROR "illegal types|incompatible|cannot"
cs = cr // ERROR "illegal types|incompatible|cannot"
c <- 0 // ok
ok := c <- 0 // ok
_ = ok
<-c // ok
x, ok := <-c // ok
_, _ = x, ok
cr <- 0 // ERROR "send"
ok = cr <- 0 // ERROR "send"
_ = ok
<-cr // ok
x, ok = <-cr // ok
_, _ = x, ok
cs <- 0 // ok
ok = cs <- 0 // ok
_ = ok
<-cs // ERROR "receive"
x, ok = <-cs // ERROR "receive"
_, _ = x, ok
select {
case c <- 0: // ok
case x := <-c: // ok
_ = x;
_ = x
case cr <- 0: // ERROR "send"
case x := <-cr: // ok
_ = x;
_ = x
case cs <- 0: // ok;
case cs <- 0: // ok
case x := <-cs: // ERROR "receive"
_ = x;
_ = x
}
}
This diff is collapsed.
This diff is collapsed.
......@@ -32,13 +32,12 @@ func main() {
'\ubabe' +
'\U0010FFFF' +
'\U000ebabe'
;
if '\U000ebabe' != 0x000ebabe {
print("ebabe wrong\n");
print("ebabe wrong\n")
os.Exit(1)
}
if i != 0x20e213 {
print("number is ", i, " should be ", 0x20e213, "\n");
print("number is ", i, " should be ", 0x20e213, "\n")
os.Exit(1)
}
}
}
......@@ -12,13 +12,13 @@
package main
type Chan interface {
Send(int);
Nbsend(int) bool;
Recv() int;
Nbrecv() (int, bool);
Close();
Closed() bool;
Impl() string;
Send(int)
Nbsend(int) bool
Recv() int
Nbrecv() (int, bool)
Close()
Closed() bool
Impl() string
}
// direct channel operations
......@@ -28,7 +28,7 @@ func (c XChan) Send(x int) {
}
func (c XChan) Nbsend(x int) bool {
return c <- x;
return c <- x
}
func (c XChan) Recv() int {
......@@ -36,8 +36,8 @@ func (c XChan) Recv() int {
}
func (c XChan) Nbrecv() (int, bool) {
x, ok := <-c;
return x, ok;
x, ok := <-c
return x, ok
}
func (c XChan) Close() {
......@@ -63,29 +63,29 @@ func (c SChan) Send(x int) {
func (c SChan) Nbsend(x int) bool {
select {
case c <- x:
return true;
return true
default:
return false;
return false
}
panic("nbsend");
panic("nbsend")
}
func (c SChan) Recv() int {
select {
case x := <-c:
return x;
return x
}
panic("recv");
panic("recv")
}
func (c SChan) Nbrecv() (int, bool) {
select {
case x := <-c:
return x, true;
return x, true
default:
return 0, false;
return 0, false
}
panic("nbrecv");
panic("nbrecv")
}
func (c SChan) Close() {
......@@ -97,101 +97,101 @@ func (c SChan) Closed() bool {
}
func (c SChan) Impl() string {
return "(select)";
return "(select)"
}
func test1(c Chan) {
// not closed until the close signal (a zero value) has been received.
if c.Closed() {
println("test1: Closed before Recv zero:", c.Impl());
println("test1: Closed before Recv zero:", c.Impl())
}
for i := 0; i < 3; i++ {
// recv a close signal (a zero value)
if x := c.Recv(); x != 0 {
println("test1: recv on closed got non-zero:", x, c.Impl());
println("test1: recv on closed got non-zero:", x, c.Impl())
}
// should now be closed.
if !c.Closed() {
println("test1: not closed after recv zero", c.Impl());
println("test1: not closed after recv zero", c.Impl())
}
// should work with ,ok: received a value without blocking, so ok == true.
x, ok := c.Nbrecv();
x, ok := c.Nbrecv()
if !ok {
println("test1: recv on closed got not ok", c.Impl());
println("test1: recv on closed got not ok", c.Impl())
}
if x != 0 {
println("test1: recv ,ok on closed got non-zero:", x, c.Impl());
println("test1: recv ,ok on closed got non-zero:", x, c.Impl())
}
}
// send should work with ,ok too: sent a value without blocking, so ok == true.
ok := c.Nbsend(1);
ok := c.Nbsend(1)
if !ok {
println("test1: send on closed got not ok", c.Impl());
println("test1: send on closed got not ok", c.Impl())
}
// but the value should have been discarded.
if x := c.Recv(); x != 0 {
println("test1: recv on closed got non-zero after send on closed:", x, c.Impl());
println("test1: recv on closed got non-zero after send on closed:", x, c.Impl())
}
// similarly Send.
c.Send(2);
c.Send(2)
if x := c.Recv(); x != 0 {
println("test1: recv on closed got non-zero after send on closed:", x, c.Impl());
println("test1: recv on closed got non-zero after send on closed:", x, c.Impl())
}
}
func testasync1(c Chan) {
// not closed until the close signal (a zero value) has been received.
if c.Closed() {
println("testasync1: Closed before Recv zero:", c.Impl());
println("testasync1: Closed before Recv zero:", c.Impl())
}
// should be able to get the last value via Recv
if x := c.Recv(); x != 1 {
println("testasync1: Recv did not get 1:", x, c.Impl());
println("testasync1: Recv did not get 1:", x, c.Impl())
}
test1(c);
test1(c)
}
func testasync2(c Chan) {
// not closed until the close signal (a zero value) has been received.
if c.Closed() {
println("testasync2: Closed before Recv zero:", c.Impl());
println("testasync2: Closed before Recv zero:", c.Impl())
}
// should be able to get the last value via Nbrecv
if x, ok := c.Nbrecv(); !ok || x != 1 {
println("testasync2: Nbrecv did not get 1, true:", x, ok, c.Impl());
println("testasync2: Nbrecv did not get 1, true:", x, ok, c.Impl())
}
test1(c);
test1(c)
}
func closedsync() chan int {
c := make(chan int);
close(c);
return c;
c := make(chan int)
close(c)
return c
}
func closedasync() chan int {
c := make(chan int, 2);
c <- 1;
close(c);
return c;
c := make(chan int, 2)
c <- 1
close(c)
return c
}
func main() {
test1(XChan(closedsync()));
test1(SChan(closedsync()));
test1(XChan(closedsync()))
test1(SChan(closedsync()))
testasync1(XChan(closedasync()));
testasync1(SChan(closedasync()));
testasync2(XChan(closedasync()));
testasync2(SChan(closedasync()));
testasync1(XChan(closedasync()))
testasync1(SChan(closedasync()))
testasync2(XChan(closedasync()))
testasync2(SChan(closedasync()))
}
......@@ -9,7 +9,7 @@ package main
func use(bool) { }
func main() {
var a []int;
var ia interface{} = a;
use(ia == ia);
var a []int
var ia interface{} = a
use(ia == ia)
}
......@@ -9,7 +9,7 @@ package main
func use(bool) { }
func main() {
var b []int;
var ib interface{} = b;
use(ib == ib);
var b []int
var ib interface{} = b
use(ib == ib)
}
......@@ -7,8 +7,8 @@
package main
func main() {
var a []int;
var ia interface{} = a;
var m = make(map[interface{}] int);
m[ia] = 1;
var a []int
var ia interface{} = a
var m = make(map[interface{}] int)
m[ia] = 1
}
......@@ -7,8 +7,8 @@
package main
func main() {
var b []int;
var ib interface{} = b;
var m = make(map[interface{}] int);
m[ib] = 1;
var b []int
var ib interface{} = b
var m = make(map[interface{}] int)
m[ib] = 1
}
......@@ -11,9 +11,9 @@ type T struct { i int; f float; s string; next *T }
type R struct { num int }
func itor(a int) *R {
r := new(R);
r.num = a;
return r;
r := new(R)
r.num = a
return r
}
func eq(a []*R) {
......@@ -22,49 +22,49 @@ func eq(a []*R) {
}
}
type P struct { a, b int };
type P struct { a, b int }
func NewP(a, b int) *P {
return &P{a, b}
}
func main() {
var t T;
t = T{0, 7.2, "hi", &t};
var t T
t = T{0, 7.2, "hi", &t}
var tp *T;
tp = &T{0, 7.2, "hi", &t};
var tp *T
tp = &T{0, 7.2, "hi", &t}
a1 := []int{1,2,3};
a1 := []int{1,2,3}
if len(a1) != 3 { panic("a1") }
a2 := [10]int{1,2,3};
a2 := [10]int{1,2,3}
if len(a2) != 10 || cap(a2) != 10 { panic("a2") }
a3 := [10]int{1,2,3,};
a3 := [10]int{1,2,3,}
if len(a3) != 10 || a2[3] != 0 { panic("a3") }
var oai []int;
oai = []int{1,2,3};
var oai []int
oai = []int{1,2,3}
if len(oai) != 3 { panic("oai") }
at := [...]*T{&t, tp, &t};
at := [...]*T{&t, tp, &t}
if len(at) != 3 { panic("at") }
c := make(chan int);
ac := []chan int{c, c, c};
c := make(chan int)
ac := []chan int{c, c, c}
if len(ac) != 3 { panic("ac") }
aat := [][len(at)]*T{at, at};
aat := [][len(at)]*T{at, at}
if len(aat) != 2 || len(aat[1]) != 3 { panic("aat") }
s := string([]byte{'h', 'e', 'l', 'l', 'o'});
s := string([]byte{'h', 'e', 'l', 'l', 'o'})
if s != "hello" { panic("s") }
m := map[string]float{"one":1.0, "two":2.0, "pi":22./7.};
m := map[string]float{"one":1.0, "two":2.0, "pi":22./7.}
if len(m) != 3 { panic("m") }
eq([]*R{itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)});
eq([]*R{itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)})
p1 := NewP(1, 2);
p2 := NewP(1, 2);
p1 := NewP(1, 2)
p2 := NewP(1, 2)
if p1 == p2 { panic("NewP") }
}
......@@ -7,7 +7,7 @@
package main
type T struct {
int;
int
}
func f() *T {
......@@ -15,9 +15,9 @@ func f() *T {
}
func main() {
x := f();
y := f();
x := f()
y := f()
if x == y {
panic("not allocating & composite literals");
panic("not allocating & composite literals")
}
}
......@@ -7,26 +7,26 @@
package main
const (
c0 = 0;
cm1 = -1;
chuge = 1 << 100;
chuge_1 = chuge - 1;
c1 = chuge >> 100;
c3div2 = 3/2;
c1e3 = 1e3;
c0 = 0
cm1 = -1
chuge = 1 << 100
chuge_1 = chuge - 1
c1 = chuge >> 100
c3div2 = 3/2
c1e3 = 1e3
ctrue = true;
cfalse = !ctrue;
ctrue = true
cfalse = !ctrue
)
const (
f0 = 0.0;
fm1 = -1.;
fhuge float64 = 1 << 100;
fhuge_1 float64 = chuge - 1;
f1 float64 = chuge >> 100;
f3div2 = 3./2.;
f1e3 float64 = 1e3;
f0 = 0.0
fm1 = -1.
fhuge float64 = 1 << 100
fhuge_1 float64 = chuge - 1
f1 float64 = chuge >> 100
f3div2 = 3./2.
f1e3 float64 = 1e3
)
func assert(t bool, s string) {
......@@ -36,85 +36,85 @@ func assert(t bool, s string) {
}
func ints() {
assert(c0 == 0, "c0");
assert(c1 == 1, "c1");
assert(chuge > chuge_1, "chuge");
assert(chuge_1 + 1 == chuge, "chuge 1");
assert(chuge + cm1 +1 == chuge, "cm1");
assert(c3div2 == 1, "3/2");
assert(c1e3 == 1000, "c1e3 int");
assert(c1e3 == 1e3, "c1e3 float");
assert(c0 == 0, "c0")
assert(c1 == 1, "c1")
assert(chuge > chuge_1, "chuge")
assert(chuge_1 + 1 == chuge, "chuge 1")
assert(chuge + cm1 +1 == chuge, "cm1")
assert(c3div2 == 1, "3/2")
assert(c1e3 == 1000, "c1e3 int")
assert(c1e3 == 1e3, "c1e3 float")
// verify that all (in range) are assignable as ints
var i int;
i = c0;
assert(i == c0, "i == c0");
i = cm1;
assert(i == cm1, "i == cm1");
i = c1;
assert(i == c1, "i == c1");
i = c3div2;
assert(i == c3div2, "i == c3div2");
i = c1e3;
assert(i == c1e3, "i == c1e3");
var i int
i = c0
assert(i == c0, "i == c0")
i = cm1
assert(i == cm1, "i == cm1")
i = c1
assert(i == c1, "i == c1")
i = c3div2
assert(i == c3div2, "i == c3div2")
i = c1e3
assert(i == c1e3, "i == c1e3")
// verify that all are assignable as floats
var f float64;
f = c0;
assert(f == c0, "f == c0");
f = cm1;
assert(f == cm1, "f == cm1");
f = chuge;
assert(f == chuge, "f == chuge");
f = chuge_1;
assert(f == chuge_1, "f == chuge_1");
f = c1;
assert(f == c1, "f == c1");
f = c3div2;
assert(f == c3div2, "f == c3div2");
f = c1e3;
assert(f == c1e3, "f == c1e3");
var f float64
f = c0
assert(f == c0, "f == c0")
f = cm1
assert(f == cm1, "f == cm1")
f = chuge
assert(f == chuge, "f == chuge")
f = chuge_1
assert(f == chuge_1, "f == chuge_1")
f = c1
assert(f == c1, "f == c1")
f = c3div2
assert(f == c3div2, "f == c3div2")
f = c1e3
assert(f == c1e3, "f == c1e3")
}
func floats() {
assert(f0 == c0, "f0");
assert(f1 == c1, "f1");
assert(fhuge == fhuge_1, "fhuge"); // float64 can't distinguish fhuge, fhuge_1.
assert(fhuge_1 + 1 == fhuge, "fhuge 1");
assert(fhuge + fm1 +1 == fhuge, "fm1");
assert(f3div2 == 1.5, "3./2.");
assert(f1e3 == 1000, "f1e3 int");
assert(f1e3 == 1.e3, "f1e3 float");
assert(f0 == c0, "f0")
assert(f1 == c1, "f1")
assert(fhuge == fhuge_1, "fhuge") // float64 can't distinguish fhuge, fhuge_1.
assert(fhuge_1 + 1 == fhuge, "fhuge 1")
assert(fhuge + fm1 +1 == fhuge, "fm1")
assert(f3div2 == 1.5, "3./2.")
assert(f1e3 == 1000, "f1e3 int")
assert(f1e3 == 1.e3, "f1e3 float")
// verify that all (in range) are assignable as ints
var i int;
i = f0;
assert(i == f0, "i == f0");
i = fm1;
assert(i == fm1, "i == fm1");
var i int
i = f0
assert(i == f0, "i == f0")
i = fm1
assert(i == fm1, "i == fm1")
// verify that all are assignable as floats
var f float64;
f = f0;
assert(f == f0, "f == f0");
f = fm1;
assert(f == fm1, "f == fm1");
f = fhuge;
assert(f == fhuge, "f == fhuge");
f = fhuge_1;
assert(f == fhuge_1, "f == fhuge_1");
f = f1;
assert(f == f1, "f == f1");
f = f3div2;
assert(f == f3div2, "f == f3div2");
f = f1e3;
assert(f == f1e3, "f == f1e3");
var f float64
f = f0
assert(f == f0, "f == f0")
f = fm1
assert(f == fm1, "f == fm1")
f = fhuge
assert(f == fhuge, "f == fhuge")
f = fhuge_1
assert(f == fhuge_1, "f == fhuge_1")
f = f1
assert(f == f1, "f == f1")
f = f3div2
assert(f == f3div2, "f == f3div2")
f = f1e3
assert(f == f1e3, "f == f1e3")
}
func main() {
ints();
floats();
ints()
floats()
assert(ctrue == true, "ctrue == true");
assert(cfalse == false, "cfalse == false");
assert(ctrue == true, "ctrue == true")
assert(cfalse == false, "cfalse == false")
}
......@@ -9,71 +9,71 @@ package main
type I interface {}
const (
// assume all types behave similarly to int8/uint8
Int8 int8 = 101;
Minus1 int8 = -1;
Uint8 uint8 = 102;
Const = 103;
Int8 int8 = 101
Minus1 int8 = -1
Uint8 uint8 = 102
Const = 103
Float32 float32 = 104.5;
Float float = 105.5;
ConstFloat = 106.5;
Big float64 = 1e300;
Float32 float32 = 104.5
Float float = 105.5
ConstFloat = 106.5
Big float64 = 1e300
String = "abc";
Bool = true;
String = "abc"
Bool = true
)
var (
a1 = Int8 * 100; // ERROR "overflow"
a2 = Int8 * -1; // OK
a3 = Int8 * 1000; // ERROR "overflow"
a4 = Int8 * int8(1000); // ERROR "overflow"
a5 = int8(Int8 * 1000); // ERROR "overflow"
a6 = int8(Int8 * int8(1000)); // ERROR "overflow"
a7 = Int8 - 2*Int8 - 2*Int8; // ERROR "overflow"
a8 = Int8 * Const / 100; // ERROR "overflow"
a9 = Int8 * (Const / 100); // OK
a1 = Int8 * 100 // ERROR "overflow"
a2 = Int8 * -1 // OK
a3 = Int8 * 1000 // ERROR "overflow"
a4 = Int8 * int8(1000) // ERROR "overflow"
a5 = int8(Int8 * 1000) // ERROR "overflow"
a6 = int8(Int8 * int8(1000)) // ERROR "overflow"
a7 = Int8 - 2*Int8 - 2*Int8 // ERROR "overflow"
a8 = Int8 * Const / 100 // ERROR "overflow"
a9 = Int8 * (Const / 100) // OK
b1 = Uint8 * Uint8; // ERROR "overflow"
b2 = Uint8 * -1; // ERROR "overflow"
b3 = Uint8 - Uint8; // OK
b4 = Uint8 - Uint8 - Uint8; // ERROR "overflow"
b5 = uint8(^0); // ERROR "overflow"
b6 = ^uint8(0); // OK
b7 = uint8(Minus1); // ERROR "overflow"
b8 = uint8(int8(-1)); // ERROR "overflow"
b8a = uint8(-1); // ERROR "overflow"
b9 byte = (1<<10) >> 8; // OK
b10 byte = (1<<10); // ERROR "overflow"
b11 byte = (byte(1)<<10) >> 8; // ERROR "overflow"
b12 byte = 1000; // ERROR "overflow"
b13 byte = byte(1000); // ERROR "overflow"
b14 byte = byte(100) * byte(100); // ERROR "overflow"
b15 byte = byte(100) * 100; // ERROR "overflow"
b16 byte = byte(0) * 1000; // ERROR "overflow"
b16a byte = 0 * 1000; // OK
b17 byte = byte(0) * byte(1000); // ERROR "overflow"
b18 byte = Uint8/0; // ERROR "division by zero"
b1 = Uint8 * Uint8 // ERROR "overflow"
b2 = Uint8 * -1 // ERROR "overflow"
b3 = Uint8 - Uint8 // OK
b4 = Uint8 - Uint8 - Uint8 // ERROR "overflow"
b5 = uint8(^0) // ERROR "overflow"
b6 = ^uint8(0) // OK
b7 = uint8(Minus1) // ERROR "overflow"
b8 = uint8(int8(-1)) // ERROR "overflow"
b8a = uint8(-1) // ERROR "overflow"
b9 byte = (1<<10) >> 8 // OK
b10 byte = (1<<10) // ERROR "overflow"
b11 byte = (byte(1)<<10) >> 8 // ERROR "overflow"
b12 byte = 1000 // ERROR "overflow"
b13 byte = byte(1000) // ERROR "overflow"
b14 byte = byte(100) * byte(100) // ERROR "overflow"
b15 byte = byte(100) * 100 // ERROR "overflow"
b16 byte = byte(0) * 1000 // ERROR "overflow"
b16a byte = 0 * 1000 // OK
b17 byte = byte(0) * byte(1000) // ERROR "overflow"
b18 byte = Uint8/0 // ERROR "division by zero"
c1 float64 = Big;
c2 float64 = Big*Big; // ERROR "overflow"
c3 float64 = float64(Big)*Big; // ERROR "overflow"
c4 = Big*Big; // ERROR "overflow"
c5 = Big/0; // ERROR "division by zero"
c1 float64 = Big
c2 float64 = Big*Big // ERROR "overflow"
c3 float64 = float64(Big)*Big // ERROR "overflow"
c4 = Big*Big // ERROR "overflow"
c5 = Big/0 // ERROR "division by zero"
)
func f(int);
func f(int)
func main() {
f(Int8); // ERROR "convert|wrong type|cannot"
f(Minus1); // ERROR "convert|wrong type|cannot"
f(Uint8); // ERROR "convert|wrong type|cannot"
f(Const); // OK
f(Float32); // ERROR "convert|wrong type|cannot"
f(Float); // ERROR "convert|wrong type|cannot"
f(ConstFloat); // ERROR "truncate"
f(ConstFloat - 0.5); // OK
f(Big); // ERROR "convert|wrong type|cannot"
f(String); // ERROR "convert|wrong type|cannot|incompatible"
f(Bool); // ERROR "convert|wrong type|cannot|incompatible"
f(Int8) // ERROR "convert|wrong type|cannot"
f(Minus1) // ERROR "convert|wrong type|cannot"
f(Uint8) // ERROR "convert|wrong type|cannot"
f(Const) // OK
f(Float32) // ERROR "convert|wrong type|cannot"
f(Float) // ERROR "convert|wrong type|cannot"
f(ConstFloat) // ERROR "truncate"
f(ConstFloat - 0.5) // OK
f(Big) // ERROR "convert|wrong type|cannot"
f(String) // ERROR "convert|wrong type|cannot|incompatible"
f(Bool) // ERROR "convert|wrong type|cannot|incompatible"
}
......@@ -7,6 +7,6 @@
package main
const (
A int = 1;
A int = 1
B byte; // ERROR "type without expr|expected .=."
)
......@@ -9,31 +9,31 @@ package main
// explicit conversion of constants is work in progress.
// the ERRORs in this block are debatable, but they're what
// the language spec says for now.
var x1 = string(1);
var x2 string = string(1);
var x3 = int(1.5); // ERROR "convert|truncate"
var x4 int = int(1.5); // ERROR "convert|truncate"
var x5 = "a" + string(1);
var x6 = int(1e100); // ERROR "overflow"
var x7 = float(1e1000); // ERROR "overflow"
var x1 = string(1)
var x2 string = string(1)
var x3 = int(1.5) // ERROR "convert|truncate"
var x4 int = int(1.5) // ERROR "convert|truncate"
var x5 = "a" + string(1)
var x6 = int(1e100) // ERROR "overflow"
var x7 = float(1e1000) // ERROR "overflow"
// implicit conversions merit scrutiny
var s string;
var bad1 string = 1; // ERROR "conver|incompatible|invalid|cannot"
var bad2 = s + 1; // ERROR "conver|incompatible|invalid"
var bad3 = s + 'a'; // ERROR "conver|incompatible|invalid"
var bad4 = "a" + 1; // ERROR "literals|incompatible|convert|invalid"
var bad5 = "a" + 'a'; // ERROR "literals|incompatible|convert|invalid"
var s string
var bad1 string = 1 // ERROR "conver|incompatible|invalid|cannot"
var bad2 = s + 1 // ERROR "conver|incompatible|invalid"
var bad3 = s + 'a' // ERROR "conver|incompatible|invalid"
var bad4 = "a" + 1 // ERROR "literals|incompatible|convert|invalid"
var bad5 = "a" + 'a' // ERROR "literals|incompatible|convert|invalid"
var bad6 int = 1.5; // ERROR "convert|truncate"
var bad7 int = 1e100; // ERROR "overflow"
var bad8 float32 = 1e200; // ERROR "overflow"
var bad6 int = 1.5 // ERROR "convert|truncate"
var bad7 int = 1e100 // ERROR "overflow"
var bad8 float32 = 1e200 // ERROR "overflow"
// but these implicit conversions are okay
var good1 string = "a";
var good2 int = 1.0;
var good3 int = 1e9;
var good4 float = 1e20;
var good1 string = "a"
var good2 int = 1.0
var good3 int = 1e9
var good4 float = 1e20
// explicit conversion of string is okay
var _ = []int("abc")
......
......@@ -13,28 +13,28 @@ func f2() (float, int) { return 1, 2 }
func f3() (float, int, string) { return 1, 2, "3" }
func x() (s string) {
a, b, s := f3();
_, _ = a, b;
a, b, s := f3()
_, _ = a, b
return // tests that result var is in scope for redeclaration
}
func main() {
i, f, s := f3();
j, f := f2(); // redeclare f
k := f1();
m, g, s := f3();
m, h, s := f3();
i, f, s := f3()
j, f := f2() // redeclare f
k := f1()
m, g, s := f3()
m, h, s := f3()
{
// new block should be ok.
i, f, s := f3();
j, f := f2(); // redeclare f
k := f1();
m, g, s := f3();
m, h, s := f3();
_, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h;
i, f, s := f3()
j, f := f2() // redeclare f
k := f1()
m, g, s := f3()
m, h, s := f3()
_, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h
}
if x() != "3" {
println("x() failed");
println("x() failed")
}
_, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h;
_, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h
}
......@@ -15,44 +15,44 @@ func f3() (float, int, string) { return 1, 2, "3" }
func main() {
{
// simple redeclaration
i := f1();
i := f1(); // ERROR "redeclared|no new"
_ = i;
i := f1()
i := f1() // ERROR "redeclared|no new"
_ = i
}
{
// change of type for f
i, f, s := f3();
f, g, t := f3(); // ERROR "redeclared|cannot assign|incompatible"
_, _, _, _, _ = i, f, s, g, t;
i, f, s := f3()
f, g, t := f3() // ERROR "redeclared|cannot assign|incompatible"
_, _, _, _, _ = i, f, s, g, t
}
{
// change of type for i
i, f, s := f3();
j, i, t := f3(); // ERROR "redeclared|cannot assign|incompatible"
_, _, _, _, _ = i, f, s, j, t;
i, f, s := f3()
j, i, t := f3() // ERROR "redeclared|cannot assign|incompatible"
_, _, _, _, _ = i, f, s, j, t
}
{
// no new variables
i, f, s := f3();
i, f := f2(); // ERROR "redeclared|no new"
_, _, _ = i, f, s;
i, f, s := f3()
i, f := f2() // ERROR "redeclared|no new"
_, _, _ = i, f, s
}
{
// single redeclaration
i, f, s := f3();
i := f1(); // ERROR "redeclared|no new|incompatible"
_, _, _ = i, f, s;
i, f, s := f3()
i := f1() // ERROR "redeclared|no new|incompatible"
_, _, _ = i, f, s
}
// double redeclaration
{
i, f, s := f3();
i, f := f2(); // ERROR "redeclared|no new"
_, _, _ = i, f, s;
i, f, s := f3()
i, f := f2() // ERROR "redeclared|no new"
_, _, _ = i, f, s
}
{
// triple redeclaration
i, f, s := f3();
i, f, s := f3(); // ERROR "redeclared|no new"
_, _, _ = i, f, s;
i, f, s := f3()
i, f, s := f3() // ERROR "redeclared|no new"
_, _, _ = i, f, s
}
}
......@@ -10,18 +10,18 @@ package main
import os "os"
func main() {
ga, e0 := os.Getenverror("GOARCH");
ga, e0 := os.Getenverror("GOARCH")
if e0 != nil {
print("$GOARCH: ", e0.String(), "\n");
os.Exit(1);
print("$GOARCH: ", e0.String(), "\n")
os.Exit(1)
}
if ga != "amd64" && ga != "386" && ga != "arm" {
print("$GOARCH=", ga, "\n");
os.Exit(1);
print("$GOARCH=", ga, "\n")
os.Exit(1)
}
xxx, e1 := os.Getenverror("DOES_NOT_EXIST");
xxx, e1 := os.Getenverror("DOES_NOT_EXIST")
if e1 != os.ENOENV {
print("$DOES_NOT_EXIST=", xxx, "; err = ", e1.String(), "\n");
os.Exit(1);
print("$DOES_NOT_EXIST=", xxx, "; err = ", e1.String(), "\n")
os.Exit(1)
}
}
......@@ -14,142 +14,142 @@ package main
var bad = false
var allptr = make([]*int, 0, 100);
var allptr = make([]*int, 0, 100)
func noalias(p, q *int, s string) {
n := len(allptr);
*p = -(n+1);
*q = -(n+2);
allptr = allptr[0:n+2];
allptr[n] = p;
allptr[n+1] = q;
n += 2;
n := len(allptr)
*p = -(n+1)
*q = -(n+2)
allptr = allptr[0:n+2]
allptr[n] = p
allptr[n+1] = q
n += 2
for i := 0; i < n; i++ {
if allptr[i] != nil && *allptr[i] != -(i+1) {
println("aliased pointers", -(i+1), *allptr[i], "after", s);
allptr[i] = nil;
bad = true;
println("aliased pointers", -(i+1), *allptr[i], "after", s)
allptr[i] = nil
bad = true
}
}
}
func val(p, q *int, v int, s string) {
if *p != v {
println("wrong value want", v, "got", *p, "after", s);
bad = true;
println("wrong value want", v, "got", *p, "after", s)
bad = true
}
if *q != v+1 {
println("wrong value want", v+1, "got", *q, "after", s);
bad = true;
println("wrong value want", v+1, "got", *q, "after", s)
bad = true
}
}
func chk(p, q *int, v int, s string) {
val(p, q, v, s);
noalias(p, q, s);
val(p, q, v, s)
noalias(p, q, s)
}
func chkalias(p, q *int, v int, s string) {
if p != q {
println("want aliased pointers but got different after", s);
println("want aliased pointers but got different after", s)
}
if *q != v+1 {
println("wrong value want", v+1, "got", *q, "after", s);
println("wrong value want", v+1, "got", *q, "after", s)
}
}
func i_escapes(x int) *int {
var i int;
i = x;
return &i;
var i int
i = x
return &i
}
func j_escapes(x int) *int {
var j int = x;
j = x;
return &j;
var j int = x
j = x
return &j
}
func k_escapes(x int) *int {
k := x;
return &k;
k := x
return &k
}
func in_escapes(x int) *int {
return &x;
return &x
}
func send(c chan int, x int) {
c <- x;
c <- x
}
func select_escapes(x int) *int {
c := make(chan int);
go send(c, x);
c := make(chan int)
go send(c, x)
select {
case req := <-c:
return &req;
return &req
}
return nil;
return nil
}
func select_escapes1(x int, y int) (*int, *int) {
c := make(chan int);
var a [2]int;
var p [2]*int;
a[0] = x;
a[1] = y;
c := make(chan int)
var a [2]int
var p [2]*int
a[0] = x
a[1] = y
for i := 0; i < 2; i++ {
go send(c, a[i]);
go send(c, a[i])
select {
case req := <-c:
p[i] = &req;
p[i] = &req
}
}
return p[0], p[1]
}
func range_escapes(x int) *int {
var a [1]int;
a[0] = x;
var a [1]int
a[0] = x
for _, v := range a {
return &v;
return &v
}
return nil;
return nil
}
// *is* aliased
func range_escapes2(x, y int) (*int, *int) {
var a [2]int;
var p [2]*int;
a[0] = x;
a[1] = y;
var a [2]int
var p [2]*int
a[0] = x
a[1] = y
for k, v := range a {
p[k] = &v;
p[k] = &v
}
return p[0], p[1]
}
// *is* aliased
func for_escapes2(x int, y int) (*int, *int) {
var p [2]*int;
n := 0;
var p [2]*int
n := 0
for i := x; n < 2; i = y {
p[n] = &i;
n++;
p[n] = &i
n++
}
return p[0], p[1]
}
func out_escapes(i int) (x int, p *int) {
x = i
p = &x; // ERROR "address of out parameter"
return;
p = &x // ERROR "address of out parameter"
return
}
func out_escapes_2(i int) (x int, p *int) {
x = i
return x, &x; // ERROR "address of out parameter"
return x, &x // ERROR "address of out parameter"
}
func defer1(i int) (x int) {
......@@ -160,40 +160,40 @@ func defer1(i int) (x int) {
}
func main() {
p, q := i_escapes(1), i_escapes(2);
chk(p, q, 1, "i_escapes");
p, q := i_escapes(1), i_escapes(2)
chk(p, q, 1, "i_escapes")
p, q = j_escapes(3), j_escapes(4);
chk(p, q, 3, "j_escapes");
p, q = j_escapes(3), j_escapes(4)
chk(p, q, 3, "j_escapes")
p, q = k_escapes(5), k_escapes(6);
chk(p, q, 5, "k_escapes");
p, q = k_escapes(5), k_escapes(6)
chk(p, q, 5, "k_escapes")
p, q = in_escapes(7), in_escapes(8);
chk(p, q, 7, "in_escapes");
p, q = in_escapes(7), in_escapes(8)
chk(p, q, 7, "in_escapes")
p, q = select_escapes(9), select_escapes(10);
chk(p, q, 9, "select_escapes");
p, q = select_escapes(9), select_escapes(10)
chk(p, q, 9, "select_escapes")
p, q = select_escapes1(11, 12);
chk(p, q, 11, "select_escapes1");
p, q = select_escapes1(11, 12)
chk(p, q, 11, "select_escapes1")
p, q = range_escapes(13), range_escapes(14);
chk(p, q, 13, "range_escapes");
p, q = range_escapes(13), range_escapes(14)
chk(p, q, 13, "range_escapes")
p, q = range_escapes2(101, 102);
chkalias(p, q, 101, "range_escapes2");
p, q = range_escapes2(101, 102)
chkalias(p, q, 101, "range_escapes2")
p, q = for_escapes2(103, 104);
chkalias(p, q, 103, "for_escapes2");
p, q = for_escapes2(103, 104)
chkalias(p, q, 103, "for_escapes2")
_, p = out_escapes(15)
_, q = out_escapes(16);
chk(p, q, 15, "out_escapes");
_, q = out_escapes(16)
chk(p, q, 15, "out_escapes")
_, p = out_escapes_2(17)
_, q = out_escapes_2(18);
chk(p, q, 17, "out_escapes_2");
_, q = out_escapes_2(18)
chk(p, q, 17, "out_escapes_2")
x := defer1(20)
if x != 20 {
......@@ -202,6 +202,6 @@ func main() {
}
if bad {
panic("BUG: no escape");
panic("BUG: no escape")
}
}
......@@ -24,34 +24,34 @@ func
pow10(pow int) float64 {
if pow < 0 { return 1/pow10(-pow); }
if pow > 0 { return pow10(pow-1)*10; }
return 1;
return 1
}
func
close(da float64, ia, ib int64, pow int) bool {
db := float64(ia) / float64(ib);
db *= pow10(pow);
db := float64(ia) / float64(ib)
db *= pow10(pow)
if da == 0 || db == 0 {
if da == 0 && db == 0 {
return true;
return true
}
return false;
return false
}
de := (da-db) /da;
de := (da-db) /da
if de < 0 {
de = -de;
de = -de
}
if de < deLim {
return true;
return true
}
if !bad {
println("BUG")
bad = true
}
return false;
return false
}
func
......
......@@ -8,49 +8,49 @@ package main
func assertequal(is, shouldbe int, msg string) {
if is != shouldbe {
print("assertion fail", msg, "\n");
panic(1);
print("assertion fail", msg, "\n")
panic(1)
}
}
func main() {
var i, sum int;
var i, sum int
i = 0;
i = 0
for {
i = i + 1;
i = i + 1
if i > 5 {
break;
break
}
}
assertequal(i, 6, "break");
assertequal(i, 6, "break")
sum = 0;
sum = 0
for i := 0; i <= 10; i++ {
sum = sum + i;
sum = sum + i
}
assertequal(sum, 55, "all three");
assertequal(sum, 55, "all three")
sum = 0;
sum = 0
for i := 0; i <= 10; {
sum = sum + i;
i++;
sum = sum + i
i++
}
assertequal(sum, 55, "only two");
assertequal(sum, 55, "only two")
sum = 0;
sum = 0
for sum < 100 {
sum = sum + 9;
sum = sum + 9
}
assertequal(sum, 99 + 9, "only one");
assertequal(sum, 99 + 9, "only one")
sum = 0;
sum = 0
for i := 0; i <= 10; i++ {
if i % 2 == 0 {
continue;
continue
}
sum = sum + i;
sum = sum + i
}
assertequal(sum, 1+3+5+7+9, "continue");
assertequal(sum, 1+3+5+7+9, "continue")
}
......@@ -9,8 +9,8 @@ package main
func assertequal(is, shouldbe int, msg string) {
if is != shouldbe {
print("assertion fail", msg, "\n");
panic(1);
print("assertion fail", msg, "\n")
panic(1)
}
}
......@@ -21,69 +21,69 @@ func f2(a int) {
}
func f3(a, b int) int {
return a+b;
return a+b
}
func f4(a, b int, c float) int {
return (a+b)/2 + int(c);
return (a+b)/2 + int(c)
}
func f5(a int) int {
return 5;
return 5
}
func f6(a int) (r int) {
return 6;
return 6
}
func f7(a int) (x int, y float) {
return 7, 7.0;
return 7, 7.0
}
func f8(a int) (x int, y float) {
return 8, 8.0;
return 8, 8.0
}
type T struct {
x, y int;
x, y int
}
func (t *T) m10(a int, b float) int {
return (t.x+a) * (t.y+int(b));
return (t.x+a) * (t.y+int(b))
}
func f9(a int) (i int, f float) {
i = 9;
f = 9.0;
return;
i = 9
f = 9.0
return
}
func main() {
f1();
f2(1);
r3 := f3(1, 2);
assertequal(r3, 3, "3");
r4 := f4(0, 2, 3.0);
assertequal(r4, 4, "4");
r5 := f5(1);
assertequal(r5, 5, "5");
r6 := f6(1);
assertequal(r6, 6, "6");
r7, s7 := f7(1);
assertequal(r7, 7, "r7");
assertequal(int(s7), 7, "s7");
r8, s8 := f8(1);
assertequal(r8, 8, "r8");
assertequal(int(s8), 8, "s8");
r9, s9 := f9(1);
assertequal(r9, 9, "r9");
assertequal(int(s9), 9, "s9");
var t *T = new(T);
t.x = 1;
t.y = 2;
r10 := t.m10(1, 3.0);
assertequal(r10, 10, "10");
f1()
f2(1)
r3 := f3(1, 2)
assertequal(r3, 3, "3")
r4 := f4(0, 2, 3.0)
assertequal(r4, 4, "4")
r5 := f5(1)
assertequal(r5, 5, "5")
r6 := f6(1)
assertequal(r6, 6, "6")
r7, s7 := f7(1)
assertequal(r7, 7, "r7")
assertequal(int(s7), 7, "s7")
r8, s8 := f8(1)
assertequal(r8, 8, "r8")
assertequal(int(s8), 8, "s8")
r9, s9 := f9(1)
assertequal(r9, 9, "r9")
assertequal(int(s9), 9, "s9")
var t *T = new(T)
t.x = 1
t.y = 2
r10 := t.m10(1, 3.0)
assertequal(r10, 10, "10")
}
......@@ -9,10 +9,10 @@
package main
func f1(a int) (int, float) { // BUG (not caught by compiler): multiple return values must have names
return 7, 7.0;
return 7, 7.0
}
func f2(a int) (a int, b float) { // ERROR "redeclared|definition"
return 8, 8.0;
return 8, 8.0
}
......@@ -5,20 +5,20 @@
// license that can be found in the LICENSE file.
package main
import os "os";
import os "os"
type t1 int;
type t2 int;
type t3 int;
type t1 int
type t2 int
type t3 int
func f1(t1, t2, t3);
func f2(t1, t2, t3 bool);
func f3(t1, t2, x t3);
func f4(t1, *t3);
func (x *t1) f5(y []t2) (t1, *t3);
func f6() (int, *string);
func f7(*t2, t3);
func f8(os int) int;
func f1(t1, t2, t3)
func f2(t1, t2, t3 bool)
func f3(t1, t2, x t3)
func f4(t1, *t3)
func (x *t1) f5(y []t2) (t1, *t3)
func f6() (int, *string)
func f7(*t2, t3)
func f8(os int) int
func f9(os int) int {
return os
......
......@@ -6,12 +6,12 @@
package main
type t1 int;
type t2 int;
type t3 int;
type t1 int
type t2 int
type t3 int
func f1(*t2, x t3); // ERROR "named"
func f2(t1, *t2, x t3); // ERROR "named"
func f3() (x int, *string); // ERROR "named"
func f1(*t2, x t3) // ERROR "named"
func f2(t1, *t2, x t3) // ERROR "named"
func f3() (x int, *string) // ERROR "named"
func f4() (t1 t1); // legal - scope of parameter named t1 starts in body of f4.
func f4() (t1 t1) // legal - scope of parameter named t1 starts in body of f4.
......@@ -9,6 +9,6 @@ package main
var notmain func()
func main() {
var x = &main; // ERROR "address of|invalid"
main = notmain; // ERROR "assign to|invalid"
var x = &main // ERROR "address of|invalid"
main = notmain // ERROR "assign to|invalid"
}
......@@ -11,7 +11,7 @@ import "runtime"
func mk2() {
b := new([10000]byte)
_ = b
// println(b, "stored at", &b);
// println(b, "stored at", &b)
}
func mk1() { mk2() }
......
......@@ -8,7 +8,7 @@ package main
func main() {
for i := 0; i < 1e5; i++ {
x := new([100]byte);
_ = x;
x := new([100]byte)
_ = x
}
}
......@@ -11,7 +11,7 @@ package main
func ASSERT(p bool) {
if !p {
// panic 0;
// panic 0
}
}
......@@ -20,7 +20,7 @@ func ASSERT(p bool) {
// Implementation of the HashMap
type KeyType interface {
Hash() uint32;
Hash() uint32
Match(other *KeyType) bool
}
......@@ -31,31 +31,30 @@ type ValueType interface {
type Entry struct {
key *KeyType;
value *ValueType;
key *KeyType
value *ValueType
}
// Using the Array type below doesn't seem to work
//type Array array [1024] Entry;
type Array [1024]Entry
type HashMap struct {
map_ *[1024] Entry;
log2_capacity_ uint32;
occupancy_ uint32;
map_ *Array
log2_capacity_ uint32
occupancy_ uint32
}
func (m *HashMap) capacity() uint32 {
return 1 << m.log2_capacity_;
return 1 << m.log2_capacity_
}
func (m *HashMap) Clear() {
// Mark all entries as empty.
var i uint32 = m.capacity() - 1;
var i uint32 = m.capacity() - 1
for i > 0 {
m.map_[i].key = nil;
m.map_[i].key = nil
i = i - 1
}
m.occupancy_ = 0
......@@ -63,72 +62,72 @@ func (m *HashMap) Clear() {
func (m *HashMap) Initialize (initial_log2_capacity uint32) {
m.log2_capacity_ = initial_log2_capacity;
m.map_ = new([1024] Entry);
m.Clear();
m.log2_capacity_ = initial_log2_capacity
m.map_ = new(Array)
m.Clear()
}
func (m *HashMap) Probe (key *KeyType) *Entry {
ASSERT(key != nil);
ASSERT(key != nil)
var i uint32 = key.Hash() % m.capacity();
ASSERT(0 <= i && i < m.capacity());
var i uint32 = key.Hash() % m.capacity()
ASSERT(0 <= i && i < m.capacity())
ASSERT(m.occupancy_ < m.capacity()); // guarantees loop termination
ASSERT(m.occupancy_ < m.capacity()) // guarantees loop termination
for m.map_[i].key != nil && !m.map_[i].key.Match(key) {
i++;
i++
if i >= m.capacity() {
i = 0;
i = 0
}
}
return &m.map_[i];
return &m.map_[i]
}
func (m *HashMap) Lookup (key *KeyType, insert bool) *Entry {
// Find a matching entry.
var p *Entry = m.Probe(key);
var p *Entry = m.Probe(key)
if p.key != nil {
return p;
return p
}
// No entry found; insert one if necessary.
if insert {
p.key = key;
p.value = nil;
m.occupancy_++;
p.key = key
p.value = nil
m.occupancy_++
// Grow the map if we reached >= 80% occupancy.
if m.occupancy_ + m.occupancy_/4 >= m.capacity() {
m.Resize();
p = m.Probe(key);
m.Resize()
p = m.Probe(key)
}
return p;
return p
}
// No entry found and none inserted.
return nil;
return nil
}
func (m *HashMap) Resize() {
var hmap *[1024] Entry = m.map_;
var n uint32 = m.occupancy_;
var hmap *Array = m.map_
var n uint32 = m.occupancy_
// Allocate a new map of twice the current size.
m.Initialize(m.log2_capacity_ << 1);
m.Initialize(m.log2_capacity_ << 1)
// Rehash all current entries.
var i uint32 = 0;
var i uint32 = 0
for n > 0 {
if hmap[i].key != nil {
m.Lookup(hmap[i].key, true).value = hmap[i].value;
n = n - 1;
m.Lookup(hmap[i].key, true).value = hmap[i].value
n = n - 1
}
i++;
i++
}
}
......@@ -137,46 +136,46 @@ func (m *HashMap) Resize() {
// Test code
type Number struct {
x uint32;
x uint32
}
func (n *Number) Hash() uint32 {
return n.x * 23;
return n.x * 23
}
func (n *Number) Match(other *KeyType) bool {
// var y *Number = other;
// return n.x == y.x;
return false;
// var y *Number = other
// return n.x == y.x
return false
}
func MakeNumber (x uint32) *Number {
var n *Number = new(Number);
n.x = x;
return n;
var n *Number = new(Number)
n.x = x
return n
}
func main() {
//f unc (n int) int { return n + 1; }(1);
// func (n int) int { return n + 1; }(1)
//print "HashMap - gri 2/8/2008\n";
//print "HashMap - gri 2/8/2008\n"
var hmap *HashMap = new(HashMap);
hmap.Initialize(0);
var hmap *HashMap = new(HashMap)
hmap.Initialize(0)
var x1 *Number = MakeNumber(1001);
var x2 *Number = MakeNumber(2002);
var x3 *Number = MakeNumber(3003);
_, _, _ = x1, x2, x3;
var x1 *Number = MakeNumber(1001)
var x2 *Number = MakeNumber(2002)
var x3 *Number = MakeNumber(3003)
_, _, _ = x1, x2, x3
// this doesn't work I think...
//hmap.Lookup(x1, true);
//hmap.Lookup(x2, true);
//hmap.Lookup(x3, true);
//hmap.Lookup(x1, true)
//hmap.Lookup(x2, true)
//hmap.Lookup(x3, true)
//print "done\n";
//print "done\n"
}
......@@ -7,5 +7,5 @@
package main
func main() {
print("hello, world\n");
print("hello, world\n")
}
......@@ -8,92 +8,92 @@ package main
func assertequal(is, shouldbe int, msg string) {
if is != shouldbe {
print("assertion fail", msg, "\n");
panic(1);
print("assertion fail", msg, "\n")
panic(1)
}
}
func main() {
i5 := 5;
i7 := 7;
i5 := 5
i7 := 7
var count int;
var count int
count = 0;
count = 0
if true {
count = count + 1;
count = count + 1
}
assertequal(count, 1, "if true");
assertequal(count, 1, "if true")
count = 0;
count = 0
if false {
count = count + 1;
count = count + 1
}
assertequal(count, 0, "if false");
assertequal(count, 0, "if false")
count = 0;
count = 0
if one := 1; true {
count = count + one;
count = count + one
}
assertequal(count, 1, "if true one");
assertequal(count, 1, "if true one")
count = 0;
count = 0
if one := 1; false {
count = count + 1;
_ = one;
count = count + 1
_ = one
}
assertequal(count, 0, "if false one");
assertequal(count, 0, "if false one")
count = 0;
count = 0
if {
count = count + 1;
count = count + 1
}
assertequal(count, 1, "if empty");
assertequal(count, 1, "if empty")
count = 0;
count = 0
if one := 1; true {
count = count + one;
count = count + one
}
assertequal(count, 1, "if empty one");
assertequal(count, 1, "if empty one")
count = 0;
count = 0
if i5 < i7 {
count = count + 1;
count = count + 1
}
assertequal(count, 1, "if cond");
assertequal(count, 1, "if cond")
count = 0;
count = 0
if true {
count = count + 1;
count = count + 1
} else
count = count - 1;
assertequal(count, 1, "if else true");
count = count - 1
assertequal(count, 1, "if else true")
count = 0;
count = 0
if false {
count = count + 1;
count = count + 1
} else
count = count - 1;
assertequal(count, -1, "if else false");
count = count - 1
assertequal(count, -1, "if else false")
count = 0;
count = 0
if t:=1; false {
count = count + 1;
_ = t;
t := 7;
_ = t;
count = count + 1
_ = t
t := 7
_ = t
} else
count = count - t;
assertequal(count, -1, "if else false var");
count = count - t
assertequal(count, -1, "if else false var")
count = 0;
t := 1;
count = 0
t := 1
if false {
count = count + 1;
t := 7;
_ = t;
count = count + 1
t := 7
_ = t
} else
count = count - t;
_ = t;
assertequal(count, -1, "if else false var outside");
count = count - t
_ = t
assertequal(count, -1, "if else false var outside")
}
......@@ -9,12 +9,12 @@ package main
import "os"
func main() {
count := 7;
count := 7
if one := 1; {
count = count + one
}
if count != 8 {
print(count, " should be 8\n");
print(count, " should be 8\n")
os.Exit(1)
}
}
......@@ -16,10 +16,10 @@ import . "os"
func f(e os.Error)
func main() {
var _e_ _os_.Error;
var dot Error;
var _e_ _os_.Error
var dot Error
f(_e_);
f(dot);
f(_e_)
f(dot)
}
......@@ -12,6 +12,6 @@ import "bufio" // GCCGO_ERROR "previous|not used"
import bufio "os" // ERROR "redeclared|redefinition|incompatible"
import (
"fmt"; // GCCGO_ERROR "previous|not used"
fmt "math"; // ERROR "redeclared|redefinition|incompatible"
"fmt" // GCCGO_ERROR "previous|not used"
fmt "math" // ERROR "redeclared|redefinition|incompatible"
)
......@@ -64,5 +64,5 @@ func f() {
cap(b1)+ // ERROR "illegal|invalid|must be"
cap(b2)+ // ERROR "illegal|invalid|must be"
cap(b3)+
cap(b4); // ERROR "illegal|invalid|must be"
cap(b4) // ERROR "illegal|invalid|must be"
}
......@@ -10,11 +10,11 @@ import "fmt"
import "reflect"
type S struct {
A, B, C, X, Y, Z int;
A, B, C, X, Y, Z int
}
type T struct {
S;
S
}
var a1 = S { 0, 0, 0, 1, 2, 3 }
......@@ -49,14 +49,14 @@ var same = []Same {
}
func main() {
ok := true;
ok := true
for _, s := range same {
if !reflect.DeepEqual(s.a, s.b) {
ok = false;
fmt.Printf("not same: %v and %v\n", s.a, s.b);
ok = false
fmt.Printf("not same: %v and %v\n", s.a, s.b)
}
}
if !ok {
fmt.Println("BUG: test/initialize");
fmt.Println("BUG: test/initialize")
}
}
......@@ -7,17 +7,17 @@
package main
type S struct {
A, B, C, X, Y, Z int;
A, B, C, X, Y, Z int
}
type T struct {
S;
S
}
var x = 1
var a1 = S { 0, X: 1 }; // ERROR "mixture|undefined"
var a2 = S { Y: 3, Z: 2, Y: 3 }; // ERROR "duplicate"
var a3 = T { 1, 2, 3, 4, 5, 6 }; // ERROR "convert|too many"
var a1 = S { 0, X: 1 } // ERROR "mixture|undefined"
var a2 = S { Y: 3, Z: 2, Y: 3 } // ERROR "duplicate"
var a3 = T { 1, 2, 3, 4, 5, 6 } // ERROR "convert|too many"
var a4 = [5]byte{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } // ERROR "index|too many"
var a5 = []byte { x: 2 } // ERROR "index"
......
......@@ -18,8 +18,8 @@ func f() {
}
func init() {
go f();
time.Nanoseconds();
go f()
time.Nanoseconds()
}
func main() {
......
......@@ -16,9 +16,9 @@ func main() {
0x0 +
0x123 +
0X0 +
0X123;
0X123
if s != 788 {
print("s is ", s, "; should be 788\n");
os.Exit(1);
print("s is ", s, "; should be 788\n")
os.Exit(1)
}
}
......@@ -23,24 +23,24 @@ func (z *IntPtr) M() int64 { return int64(*z) }
var bad bool
func test(name string, i I) {
m := i.M();
m := i.M()
if m != 12345 {
println(name, m);
bad = true;
println(name, m)
bad = true
}
}
func ptrs() {
var bigptr BigPtr = BigPtr{ 10000, 2000, 300, 45 };
var smallptr SmallPtr = SmallPtr{ 12345 };
var intptr IntPtr = 12345;
// test("bigptr", bigptr);
test("&bigptr", &bigptr);
// test("smallptr", smallptr);
test("&smallptr", &smallptr);
// test("intptr", intptr);
test("&intptr", &intptr);
var bigptr BigPtr = BigPtr{ 10000, 2000, 300, 45 }
var smallptr SmallPtr = SmallPtr{ 12345 }
var intptr IntPtr = 12345
// test("bigptr", bigptr)
test("&bigptr", &bigptr)
// test("smallptr", smallptr)
test("&smallptr", &smallptr)
// test("intptr", intptr)
test("&intptr", &intptr)
}
type Big struct { a, b, c, d int64 }
......@@ -53,23 +53,23 @@ type Int int32
func (z Int) M() int64 { return int64(z) }
func nonptrs() {
var big Big = Big{ 10000, 2000, 300, 45 };
var small Small = Small{ 12345 };
var int Int = 12345;
test("big", big);
test("&big", &big);
test("small", small);
test("&small", &small);
test("int", int);
test("&int", &int);
var big Big = Big{ 10000, 2000, 300, 45 }
var small Small = Small{ 12345 }
var int Int = 12345
test("big", big)
test("&big", &big)
test("small", small)
test("&small", &small)
test("int", int)
test("&int", &int)
}
func main() {
ptrs();
nonptrs();
ptrs()
nonptrs()
if bad {
println("BUG: interface4");
println("BUG: interface4")
}
}
......@@ -9,17 +9,17 @@
package main
type R interface { R(); }
type RW interface { R(); W(); }
type R interface { R() }
type RW interface { R(); W() }
var e interface {}
var r R;
var rw RW;
var r R
var rw RW
func main() {
r = r;
r = rw;
e = r;
e = rw;
rw = rw;
r = r
r = rw
e = r
e = rw
rw = rw
}
......@@ -9,17 +9,17 @@
package main
type R interface { R(); }
type RW interface { R(); W(); }
type R interface { R() }
type RW interface { R(); W() }
var e interface {}
var r R;
var rw RW;
var r R
var rw RW
func main() {
r = r;
r = rw;
e = r;
e = rw;
rw = rw;
r = r
r = rw
e = r
e = rw
rw = rw
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -18,8 +18,8 @@ type I1 interface { Name() int8 }
type I2 interface { Name() int64 }
func main() {
var i1 I1;
var s *S;
i1 = s;
var i1 I1
var s *S
i1 = s
print(i1.(I2).Name())
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment