Commit 325cf8ef authored by Rob Pike's avatar Rob Pike

delete all uses of panicln by rewriting them using panic or,

in the tests, println+panic.
gofmt some tests too.

R=rsc
CC=golang-dev
https://golang.org/cl/741041
parent acfd6d5f
...@@ -3090,7 +3090,7 @@ func ungetrune(f *bufio.Reader, c int) { ...@@ -3090,7 +3090,7 @@ func ungetrune(f *bufio.Reader, c int) {
} }
func write(f *bufio.Writer, b []byte, n int) int { func write(f *bufio.Writer, b []byte, n int) int {
println("write") panic("write")
return 0 return 0
} }
......
...@@ -26,7 +26,7 @@ type cfbCipher struct { ...@@ -26,7 +26,7 @@ type cfbCipher struct {
func newCFB(c Cipher, s int, iv []byte) *cfbCipher { func newCFB(c Cipher, s int, iv []byte) *cfbCipher {
if s == 0 || s%8 != 0 { if s == 0 || s%8 != 0 {
panicln("crypto/block: invalid CFB mode", s) panic("crypto/block: invalid CFB mode")
} }
b := c.BlockSize() b := c.BlockSize()
x := new(cfbCipher) x := new(cfbCipher)
......
...@@ -36,7 +36,7 @@ func (e *EAXTagError) String() string { ...@@ -36,7 +36,7 @@ func (e *EAXTagError) String() string {
func setupEAX(c Cipher, iv, hdr []byte, tagBytes int) (ctrIV, tag []byte, cmac hash.Hash) { func setupEAX(c Cipher, iv, hdr []byte, tagBytes int) (ctrIV, tag []byte, cmac hash.Hash) {
n := len(iv) n := len(iv)
if n != c.BlockSize() { if n != c.BlockSize() {
panicln("crypto/block: EAX: iv length", n, "!=", c.BlockSize()) panic(fmt.Sprintln("crypto/block: EAX: iv length", n, "!=", c.BlockSize()))
} }
buf := make([]byte, n) // zeroed buf := make([]byte, n) // zeroed
......
...@@ -24,10 +24,10 @@ func (c *IncCipher) BlockSize() int { return c.blockSize } ...@@ -24,10 +24,10 @@ func (c *IncCipher) BlockSize() int { return c.blockSize }
func (c *IncCipher) Encrypt(src, dst []byte) { func (c *IncCipher) Encrypt(src, dst []byte) {
if !c.encrypting { if !c.encrypting {
panicln("encrypt: not encrypting") panic("encrypt: not encrypting")
} }
if len(src) != c.blockSize || len(dst) != c.blockSize { if len(src) != c.blockSize || len(dst) != c.blockSize {
panicln("encrypt: wrong block size", c.blockSize, len(src), len(dst)) panic(fmt.Sprintln("encrypt: wrong block size", c.blockSize, len(src), len(dst)))
} }
c.delta++ c.delta++
for i, b := range src { for i, b := range src {
...@@ -37,10 +37,10 @@ func (c *IncCipher) Encrypt(src, dst []byte) { ...@@ -37,10 +37,10 @@ func (c *IncCipher) Encrypt(src, dst []byte) {
func (c *IncCipher) Decrypt(src, dst []byte) { func (c *IncCipher) Decrypt(src, dst []byte) {
if c.encrypting { if c.encrypting {
panicln("decrypt: not decrypting") panic("decrypt: not decrypting")
} }
if len(src) != c.blockSize || len(dst) != c.blockSize { if len(src) != c.blockSize || len(dst) != c.blockSize {
panicln("decrypt: wrong block size", c.blockSize, len(src), len(dst)) panic(fmt.Sprintln("decrypt: wrong block size ", c.blockSize, " ", len(src), " ", len(dst)))
} }
c.delta-- c.delta--
for i, b := range src { for i, b := range src {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
package block package block
import ( import (
"fmt"
"io" "io"
) )
...@@ -26,7 +27,7 @@ func newOFBStream(c Cipher, iv []byte) *ofbStream { ...@@ -26,7 +27,7 @@ func newOFBStream(c Cipher, iv []byte) *ofbStream {
x.c = c x.c = c
n := len(iv) n := len(iv)
if n != c.BlockSize() { if n != c.BlockSize() {
panicln("crypto/block: newOFBStream: invalid iv size", n, "!=", c.BlockSize()) panic(fmt.Sprintln("crypto/block: newOFBStream: invalid iv size", n, "!=", c.BlockSize()))
} }
x.iv = copy(iv) x.iv = copy(iv)
return x return x
......
...@@ -99,7 +99,7 @@ func (d0 *digest) Sum() []byte { ...@@ -99,7 +99,7 @@ func (d0 *digest) Sum() []byte {
d.Write(tmp[0:8]) d.Write(tmp[0:8])
if d.nx != 0 { if d.nx != 0 {
panicln("oops") panic("d.nx != 0")
} }
p := make([]byte, 16) p := make([]byte, 16)
......
...@@ -99,7 +99,7 @@ func (d0 *digest) Sum() []byte { ...@@ -99,7 +99,7 @@ func (d0 *digest) Sum() []byte {
d.Write(tmp[0:8]) d.Write(tmp[0:8])
if d.nx != 0 { if d.nx != 0 {
panicln("oops") panic("d.nx != 0")
} }
p := make([]byte, 16) p := make([]byte, 16)
......
...@@ -103,7 +103,7 @@ func (d0 *digest) Sum() []byte { ...@@ -103,7 +103,7 @@ func (d0 *digest) Sum() []byte {
d.Write(tmp[0:8]) d.Write(tmp[0:8])
if d.nx != 0 { if d.nx != 0 {
panicln("oops") panic("d.nx != 0")
} }
p := make([]byte, 20) p := make([]byte, 20)
......
...@@ -101,7 +101,7 @@ func (d0 *digest) Sum() []byte { ...@@ -101,7 +101,7 @@ func (d0 *digest) Sum() []byte {
d.Write(tmp[0:8]) d.Write(tmp[0:8])
if d.nx != 0 { if d.nx != 0 {
panicln("oops") panic("d.nx != 0")
} }
p := make([]byte, 20) p := make([]byte, 20)
......
...@@ -143,7 +143,7 @@ func (d0 *digest) Sum() []byte { ...@@ -143,7 +143,7 @@ func (d0 *digest) Sum() []byte {
d.Write(tmp[0:8]) d.Write(tmp[0:8])
if d.nx != 0 { if d.nx != 0 {
panicln("oops") panic("d.nx != 0")
} }
p := make([]byte, 32) p := make([]byte, 32)
......
...@@ -143,7 +143,7 @@ func (d0 *digest) Sum() []byte { ...@@ -143,7 +143,7 @@ func (d0 *digest) Sum() []byte {
d.Write(tmp[0:16]) d.Write(tmp[0:16])
if d.nx != 0 { if d.nx != 0 {
panicln("oops") panic("d.nx != 0")
} }
p := make([]byte, 64) p := make([]byte, 64)
......
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
// causing the innermost Try to return err. // causing the innermost Try to return err.
func (t *Thread) Abort(err os.Error) { func (t *Thread) Abort(err os.Error) {
if t.abort == nil { if t.abort == nil {
panicln("abort:", err.String()) panic("abort: " + err.String())
} }
t.abort <- err t.abort <- err
runtime.Goexit() runtime.Goexit()
......
...@@ -6,6 +6,7 @@ package eval ...@@ -6,6 +6,7 @@ package eval
import ( import (
"bignum" "bignum"
"fmt"
"go/ast" "go/ast"
"go/token" "go/token"
"log" "log"
...@@ -340,7 +341,7 @@ func (a *assignCompiler) compile(b *block, lt Type) func(Value, *Thread) { ...@@ -340,7 +341,7 @@ func (a *assignCompiler) compile(b *block, lt Type) func(Value, *Thread) {
temp := b.DefineTemp(a.rmt) temp := b.DefineTemp(a.rmt)
tempIdx := temp.Index tempIdx := temp.Index
if tempIdx < 0 { if tempIdx < 0 {
panicln("tempidx", tempIdx) panic(fmt.Sprintln("tempidx", tempIdx))
} }
if a.isMapUnpack { if a.isMapUnpack {
rf := a.rs[0].evalMapValue rf := a.rs[0].evalMapValue
...@@ -1374,12 +1375,12 @@ func (a *exprInfo) compileBuiltinCallExpr(b *block, ft *FuncType, as []*expr) *e ...@@ -1374,12 +1375,12 @@ func (a *exprInfo) compileBuiltinCallExpr(b *block, ft *FuncType, as []*expr) *e
expr.eval = func(*Thread) Value { return t.Zero() } expr.eval = func(*Thread) Value { return t.Zero() }
return expr return expr
case panicType, paniclnType, printType, printlnType: case panicType, printType, printlnType:
evals := make([]func(*Thread) interface{}, len(as)) evals := make([]func(*Thread) interface{}, len(as))
for i, x := range as { for i, x := range as {
evals[i] = x.asInterface() evals[i] = x.asInterface()
} }
spaces := ft == paniclnType || ft == printlnType spaces := ft == printlnType
newline := ft != printType newline := ft != printType
printer := func(t *Thread) { printer := func(t *Thread) {
for i, eval := range evals { for i, eval := range evals {
...@@ -1413,7 +1414,7 @@ func (a *exprInfo) compileBuiltinCallExpr(b *block, ft *FuncType, as []*expr) *e ...@@ -1413,7 +1414,7 @@ func (a *exprInfo) compileBuiltinCallExpr(b *block, ft *FuncType, as []*expr) *e
} }
expr := a.newExpr(EmptyType, "print") expr := a.newExpr(EmptyType, "print")
expr.exec = printer expr.exec = printer
if ft == panicType || ft == paniclnType { if ft == panicType {
expr.exec = func(t *Thread) { expr.exec = func(t *Thread) {
printer(t) printer(t)
t.Abort(os.NewError("panic")) t.Abort(os.NewError("panic"))
......
...@@ -702,7 +702,6 @@ var ( ...@@ -702,7 +702,6 @@ var (
makeType = &FuncType{builtin: "make"} makeType = &FuncType{builtin: "make"}
newType = &FuncType{builtin: "new"} newType = &FuncType{builtin: "new"}
panicType = &FuncType{builtin: "panic"} panicType = &FuncType{builtin: "panic"}
paniclnType = &FuncType{builtin: "panicln"}
printType = &FuncType{builtin: "print"} printType = &FuncType{builtin: "print"}
printlnType = &FuncType{builtin: "println"} printlnType = &FuncType{builtin: "println"}
) )
...@@ -1237,7 +1236,6 @@ func init() { ...@@ -1237,7 +1236,6 @@ func init() {
universe.DefineConst("make", universePos, makeType, nil) universe.DefineConst("make", universePos, makeType, nil)
universe.DefineConst("new", universePos, newType, nil) universe.DefineConst("new", universePos, newType, nil)
universe.DefineConst("panic", universePos, panicType, nil) universe.DefineConst("panic", universePos, panicType, nil)
universe.DefineConst("panicln", universePos, paniclnType, nil)
universe.DefineConst("print", universePos, printType, nil) universe.DefineConst("print", universePos, printType, nil)
universe.DefineConst("println", universePos, printlnType, nil) universe.DefineConst("println", universePos, printlnType, nil)
} }
...@@ -399,7 +399,7 @@ func encOpFor(rt reflect.Type) (encOp, int, os.Error) { ...@@ -399,7 +399,7 @@ func encOpFor(rt reflect.Type) (encOp, int, os.Error) {
func compileEnc(rt reflect.Type) (*encEngine, os.Error) { func compileEnc(rt reflect.Type) (*encEngine, os.Error) {
srt, ok := rt.(*reflect.StructType) srt, ok := rt.(*reflect.StructType)
if !ok { if !ok {
panicln("can't happen: non-struct") panic("can't happen: non-struct")
} }
engine := new(encEngine) engine := new(encEngine)
engine.instr = make([]encInstr, srt.NumField()+1) // +1 for terminator engine.instr = make([]encInstr, srt.NumField()+1) // +1 for terminator
......
...@@ -114,7 +114,7 @@ func init() { ...@@ -114,7 +114,7 @@ func init() {
// Move the id space upwards to allow for growth in the predefined world // Move the id space upwards to allow for growth in the predefined world
// without breaking existing files. // without breaking existing files.
if nextId > firstUserId { if nextId > firstUserId {
panicln("nextId too large:", nextId) panic(fmt.Sprintln("nextId too large:", nextId))
} }
nextId = firstUserId nextId = firstUserId
} }
...@@ -303,7 +303,7 @@ func getType(name string, rt reflect.Type) (gobType, os.Error) { ...@@ -303,7 +303,7 @@ func getType(name string, rt reflect.Type) (gobType, os.Error) {
func checkId(want, got typeId) { func checkId(want, got typeId) {
if want != got { if want != got {
panicln("bootstrap type wrong id:", got.Name(), got, "not", want) panic("bootstrap type wrong id: " + got.Name() + " " + got.string() + " not " + want.string())
} }
} }
...@@ -312,7 +312,7 @@ func bootstrapType(name string, e interface{}, expect typeId) typeId { ...@@ -312,7 +312,7 @@ func bootstrapType(name string, e interface{}, expect typeId) typeId {
rt := reflect.Typeof(e) rt := reflect.Typeof(e)
_, present := types[rt] _, present := types[rt]
if present { if present {
panicln("bootstrap type already present:", name) panic("bootstrap type already present: " + name)
} }
typ := &commonType{name: name} typ := &commonType{name: name}
types[rt] = typ types[rt] = typ
...@@ -356,7 +356,7 @@ var typeInfoMap = make(map[reflect.Type]*typeInfo) // protected by typeLock ...@@ -356,7 +356,7 @@ var typeInfoMap = make(map[reflect.Type]*typeInfo) // protected by typeLock
// typeLock must be held. // typeLock must be held.
func getTypeInfo(rt reflect.Type) (*typeInfo, os.Error) { func getTypeInfo(rt reflect.Type) (*typeInfo, os.Error) {
if _, ok := rt.(*reflect.PtrType); ok { if _, ok := rt.(*reflect.PtrType); ok {
panicln("pointer type in getTypeInfo:", rt.String()) panic("pointer type in getTypeInfo: " + rt.String())
} }
info, ok := typeInfoMap[rt] info, ok := typeInfoMap[rt]
if !ok { if !ok {
...@@ -388,7 +388,7 @@ func getTypeInfo(rt reflect.Type) (*typeInfo, os.Error) { ...@@ -388,7 +388,7 @@ func getTypeInfo(rt reflect.Type) (*typeInfo, os.Error) {
func mustGetTypeInfo(rt reflect.Type) *typeInfo { func mustGetTypeInfo(rt reflect.Type) *typeInfo {
t, err := getTypeInfo(rt) t, err := getTypeInfo(rt)
if err != nil { if err != nil {
panicln("getTypeInfo:", err.String()) panic("getTypeInfo: " + err.String())
} }
return t return t
} }
...@@ -28,7 +28,7 @@ func getTypeUnlocked(name string, rt reflect.Type) gobType { ...@@ -28,7 +28,7 @@ func getTypeUnlocked(name string, rt reflect.Type) gobType {
defer typeLock.Unlock() defer typeLock.Unlock()
t, err := getType(name, rt) t, err := getType(name, rt)
if err != nil { if err != nil {
panicln("getTypeUnlocked:", err.String()) panic("getTypeUnlocked: " + err.String())
} }
return t return t
} }
......
...@@ -511,7 +511,7 @@ func (mux *ServeMux) ServeHTTP(c *Conn, req *Request) { ...@@ -511,7 +511,7 @@ func (mux *ServeMux) ServeHTTP(c *Conn, req *Request) {
// Handle registers the handler for the given pattern. // Handle registers the handler for the given pattern.
func (mux *ServeMux) Handle(pattern string, handler Handler) { func (mux *ServeMux) Handle(pattern string, handler Handler) {
if pattern == "" || pattern[0] != '/' { if pattern == "" || pattern[0] != '/' {
panicln("http: invalid pattern", pattern) panic("http: invalid pattern " + pattern)
} }
mux.m[pattern] = handler mux.m[pattern] = handler
......
...@@ -128,7 +128,7 @@ func (s *pollServer) AddFD(fd *netFD, mode int) { ...@@ -128,7 +128,7 @@ func (s *pollServer) AddFD(fd *netFD, mode int) {
return return
} }
if err := s.poll.AddFD(intfd, mode, false); err != nil { if err := s.poll.AddFD(intfd, mode, false); err != nil {
panicln("pollServer AddFD ", intfd, ": ", err.String(), "\n") panic("pollServer AddFD " + err.String())
return return
} }
......
...@@ -111,7 +111,7 @@ func valueToString(val Value) string { ...@@ -111,7 +111,7 @@ func valueToString(val Value) string {
v := val v := val
return typ.String() + "(" + strconv.Itoa64(int64(v.Get())) + ")" return typ.String() + "(" + strconv.Itoa64(int64(v.Get())) + ")"
default: default:
panicln("valueToString: can't print type ", typ.String()) panic("valueToString: can't print type " + typ.String())
} }
return "valueToString: can't happen" return "valueToString: can't happen"
} }
...@@ -649,7 +649,7 @@ func toType(i interface{}) Type { ...@@ -649,7 +649,7 @@ func toType(i interface{}) Type {
case *runtime.StructType: case *runtime.StructType:
return (*StructType)(unsafe.Pointer(v)) return (*StructType)(unsafe.Pointer(v))
} }
panicln("toType", i) panic("toType")
} }
// ArrayOrSliceType is the common interface implemented // ArrayOrSliceType is the common interface implemented
......
...@@ -503,7 +503,7 @@ func (v *UnsafePointerValue) SetValue(x Value) { ...@@ -503,7 +503,7 @@ func (v *UnsafePointerValue) SetValue(x Value) {
func typesMustMatch(t1, t2 Type) { func typesMustMatch(t1, t2 Type) {
if t1 != t2 { if t1 != t2 {
panicln("type mismatch:", t1.String(), "!=", t2.String()) panic("type mismatch: " + t1.String() + " != " + t2.String())
} }
} }
...@@ -612,7 +612,7 @@ func (v *SliceValue) addr() addr { return addr(v.slice().Data) } ...@@ -612,7 +612,7 @@ func (v *SliceValue) addr() addr { return addr(v.slice().Data) }
func (v *SliceValue) SetLen(n int) { func (v *SliceValue) SetLen(n int) {
s := v.slice() s := v.slice()
if n < 0 || n > int(s.Cap) { if n < 0 || n > int(s.Cap) {
panicln("SetLen", n, "with capacity", s.Cap) panic("reflect: slice length out of range in SetLen")
} }
s.Len = n s.Len = n
} }
...@@ -657,7 +657,7 @@ func (v *SliceValue) Elem(i int) Value { ...@@ -657,7 +657,7 @@ func (v *SliceValue) Elem(i int) Value {
typ := v.typ.(*SliceType).Elem() typ := v.typ.(*SliceType).Elem()
n := v.Len() n := v.Len()
if i < 0 || i >= n { if i < 0 || i >= n {
panicln("index", i, "in array of length", n) panic("reflect: slice index out of range")
} }
p := addr(uintptr(v.addr()) + uintptr(i)*typ.Size()) p := addr(uintptr(v.addr()) + uintptr(i)*typ.Size())
return newValue(typ, p, v.canSet) return newValue(typ, p, v.canSet)
...@@ -1346,7 +1346,7 @@ func newValue(typ Type, addr addr, canSet bool) Value { ...@@ -1346,7 +1346,7 @@ func newValue(typ Type, addr addr, canSet bool) Value {
case *UnsafePointerType: case *UnsafePointerType:
return (*UnsafePointerValue)(v) return (*UnsafePointerValue)(v)
} }
panicln("newValue", typ.String()) panic("newValue" + typ.String())
} }
// MakeZero returns a zero Value for the specified Type. // MakeZero returns a zero Value for the specified Type.
......
...@@ -673,7 +673,7 @@ func Compile(str string) (regexp *Regexp, error os.Error) { ...@@ -673,7 +673,7 @@ func Compile(str string) (regexp *Regexp, error os.Error) {
func MustCompile(str string) *Regexp { func MustCompile(str string) *Regexp {
regexp, error := Compile(str) regexp, error := Compile(str)
if error != nil { if error != nil {
panicln(`regexp: compiling "`, str, `": `, error.String()) panic(`regexp: compiling "` + str + `": ` + error.String())
} }
return regexp return regexp
} }
......
...@@ -61,7 +61,7 @@ func (client *Client) send(c *Call) { ...@@ -61,7 +61,7 @@ func (client *Client) send(c *Call) {
client.enc.Encode(request) client.enc.Encode(request)
err := client.enc.Encode(c.Args) err := client.enc.Encode(c.Args)
if err != nil { if err != nil {
panicln("rpc: client encode error:", err.String()) panic("rpc: client encode error: " + err.String())
} }
client.sending.Unlock() client.sending.Unlock()
} }
......
...@@ -49,7 +49,7 @@ func (t *Arith) Div(args *Args, reply *Reply) os.Error { ...@@ -49,7 +49,7 @@ func (t *Arith) Div(args *Args, reply *Reply) os.Error {
} }
func (t *Arith) Error(args *Args, reply *Reply) os.Error { func (t *Arith) Error(args *Args, reply *Reply) os.Error {
panicln("ERROR") panic("ERROR")
} }
func startServer() { func startServer() {
......
...@@ -96,7 +96,7 @@ func myatof32(s string) (f float32, ok bool) { ...@@ -96,7 +96,7 @@ func myatof32(s string) (f float32, ok bool) {
func TestFp(t *testing.T) { func TestFp(t *testing.T) {
f, err := os.Open("testfp.txt", os.O_RDONLY, 0) f, err := os.Open("testfp.txt", os.O_RDONLY, 0)
if err != nil { if err != nil {
panicln("testfp: open testfp.txt:", err.String()) t.Fatal("testfp: open testfp.txt:", err.String())
} }
defer f.Close() defer f.Close()
...@@ -109,7 +109,7 @@ func TestFp(t *testing.T) { ...@@ -109,7 +109,7 @@ func TestFp(t *testing.T) {
break break
} }
if err2 != nil { if err2 != nil {
panicln("testfp: read testfp.txt:", err2.String()) t.Fatal("testfp: read testfp.txt: " + err2.String())
} }
line = line[0 : len(line)-1] line = line[0 : len(line)-1]
lineno++ lineno++
......
...@@ -31,7 +31,7 @@ func (b *buffer) Write(buf []byte) (written int, err os.Error) { ...@@ -31,7 +31,7 @@ func (b *buffer) Write(buf []byte) (written int, err os.Error) {
b.a[n+i] = buf[i] b.a[n+i] = buf[i]
} }
} else { } else {
panicln("buffer.Write: buffer too small", n, m, cap(b.a)) panic("buffer.Write: buffer too small")
} }
return len(buf), nil return len(buf), nil
} }
......
...@@ -624,7 +624,7 @@ func CompileRegexp(str string) (regexp *Regexp, error string) { ...@@ -624,7 +624,7 @@ func CompileRegexp(str string) (regexp *Regexp, error string) {
func MustCompile(str string) *Regexp { func MustCompile(str string) *Regexp {
regexp, error := CompileRegexp(str) regexp, error := CompileRegexp(str)
if error != "" { if error != "" {
panicln(`regexp: compiling "`, str, `": `, error) panic(`regexp: compiling "` + str + `": ` + error)
} }
return regexp return regexp
} }
......
...@@ -10,43 +10,47 @@ var counter uint ...@@ -10,43 +10,47 @@ var counter uint
var shift uint var shift uint
func GetValue() uint { func GetValue() uint {
counter++; counter++
return 1 << shift return 1 << shift
} }
func Send(a, b chan uint) int { func Send(a, b chan uint) int {
var i int; var i int
LOOP: LOOP:
for { for {
select { select {
case a <- GetValue(): case a <- GetValue():
i++; i++
a = nil; a = nil
case b <- GetValue(): case b <- GetValue():
i++; i++
b = nil; b = nil
default: default:
break LOOP; break LOOP
} }
shift++; shift++
} }
return i; return i
} }
func main() { func main() {
a := make(chan uint, 1); a := make(chan uint, 1)
b := make(chan uint, 1); b := make(chan uint, 1)
if v := Send(a, b); v != 2 { if v := Send(a, b); v != 2 {
panicln("Send returned", v, "!= 2"); println("Send returned", v, "!= 2")
panic("fail")
} }
if av, bv := <- a, <- b; av | bv != 3 { if av, bv := <-a, <-b; av|bv != 3 {
panicln("bad values", av, bv); println("bad values", av, bv)
panic("fail")
} }
if v := Send(a, nil); v != 1 { if v := Send(a, nil); v != 1 {
panicln("Send returned", v, "!= 1"); println("Send returned", v, "!= 1")
panic("fail")
} }
if counter != 10 { if counter != 10 {
panicln("counter is", counter, "!= 10"); println("counter is", counter, "!= 10")
panic("fail")
} }
} }
...@@ -7,21 +7,23 @@ ...@@ -7,21 +7,23 @@
package main package main
func main() { func main() {
c := make(chan int, 10); c := make(chan int, 10)
if len(c) != 0 || cap(c) != 10 { if len(c) != 0 || cap(c) != 10 {
panicln("chan len/cap ", len(c), cap(c), " want 0 10"); println("chan len/cap ", len(c), cap(c), " want 0 10")
panic("fail")
} }
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
c <- i; c <- i
} }
if len(c) != 3 || cap(c) != 10 { if len(c) != 3 || cap(c) != 10 {
panicln("chan len/cap ", len(c), cap(c), " want 3 10"); println("chan len/cap ", len(c), cap(c), " want 3 10")
panic("fail")
} }
c = make(chan int); c = make(chan int)
if len(c) != 0 || cap(c) != 0 { if len(c) != 0 || cap(c) != 0 {
panicln("chan len/cap ", len(c), cap(c), " want 0 0"); println("chan len/cap ", len(c), cap(c), " want 0 0")
panic("fail")
} }
} }
...@@ -6,95 +6,96 @@ ...@@ -6,95 +6,96 @@
package main package main
var c = make(chan int); var c = make(chan int)
func check(a []int) { func check(a []int) {
for i := 0; i < len(a); i++ { for i := 0; i < len(a); i++ {
n := <-c; n := <-c
if n != a[i] { if n != a[i] {
panicln("want", a[i], "got", n, "at", i); println("want", a[i], "got", n, "at", i)
panic("fail")
} }
} }
} }
func f() { func f() {
var i, j int; var i, j int
i = 1; i = 1
j = 2; j = 2
f := func() { f := func() {
c <- i; c <- i
i = 4; i = 4
g := func() { g := func() {
c <- i; c <- i
c <- j; c <- j
}; }
g(); g()
c <- i; c <- i
}; }
j = 5; j = 5
f(); f()
} }
// Accumulator generator // Accumulator generator
func accum(n int) (func(int) int) { func accum(n int) func(int) int {
return func(i int) int { return func(i int) int {
n += i; n += i
return n; return n
} }
} }
func g(a, b func(int) int) { func g(a, b func(int) int) {
c <- a(2); c <- a(2)
c <- b(3); c <- b(3)
c <- a(4); c <- a(4)
c <- b(5); c <- b(5)
} }
func h() { func h() {
var x8 byte = 100; var x8 byte = 100
var x64 int64 = 200; var x64 int64 = 200
c <- int(x8); c <- int(x8)
c <- int(x64); c <- int(x64)
f := func(z int) { f := func(z int) {
g := func() { g := func() {
c <- int(x8); c <- int(x8)
c <- int(x64); c <- int(x64)
c <- z; c <- z
}; }
g(); g()
c <- int(x8); c <- int(x8)
c <- int(x64); c <- int(x64)
c <- int(z); c <- int(z)
}; }
x8 = 101; x8 = 101
x64 = 201; x64 = 201
f(500); f(500)
} }
func newfunc() (func(int) int) { func newfunc() func(int) int { return func(x int) int { return x } }
return func(x int) int { return x }
}
func main() { func main() {
go f(); go f()
check([]int{1,4,5,4}); check([]int{1, 4, 5, 4})
a := accum(0); a := accum(0)
b := accum(1); b := accum(1)
go g(a, b); go g(a, b)
check([]int{2,4,6,9}); check([]int{2, 4, 6, 9})
go h(); go h()
check([]int{100,200,101,201,500,101,201,500}); check([]int{100, 200, 101, 201, 500, 101, 201, 500})
x, y := newfunc(), newfunc(); x, y := newfunc(), newfunc()
if x == y { if x == y {
panicln("newfunc returned same func"); println("newfunc returned same func")
panic("fail")
} }
if x(1) != 1 || y(2) != 2 { if x(1) != 1 || y(2) != 2 {
panicln("newfunc returned broken funcs"); println("newfunc returned broken funcs")
panic("fail")
} }
} }
...@@ -8,65 +8,68 @@ package main ...@@ -8,65 +8,68 @@ package main
import "unsafe" import "unsafe"
func use(bool) { } func use(bool) {}
func stringptr(s string) uintptr { func stringptr(s string) uintptr { return *(*uintptr)(unsafe.Pointer(&s)) }
return *(*uintptr)(unsafe.Pointer(&s));
}
func isfalse(b bool) { func isfalse(b bool) {
if b { panicln("wanted false, got true") } // stack will explain where if b {
// stack will explain where
panic("wanted false, got true")
}
} }
func istrue(b bool) { func istrue(b bool) {
if !b { panicln("wanted true, got false") } // stack will explain where if !b {
// stack will explain where
panic("wanted true, got false")
}
} }
func main() { func main() {
var a []int; var a []int
var b map[string]int; var b map[string]int
var c string = "hello"; var c string = "hello"
var d string = "hel"; // try to get different pointer var d string = "hel" // try to get different pointer
d = d + "lo"; d = d + "lo"
if stringptr(c) == stringptr(d) { if stringptr(c) == stringptr(d) {
panic("compiler too smart -- got same string") panic("compiler too smart -- got same string")
} }
var e = make(chan int); var e = make(chan int)
var ia interface{} = a
var ib interface{} = b
var ic interface{} = c
var id interface{} = d
var ie interface{} = e
var ia interface{} = a;
var ib interface{} = b;
var ic interface{} = c;
var id interface{} = d;
var ie interface{} = e;
// these comparisons are okay because // these comparisons are okay because
// string compare is okay and the others // string compare is okay and the others
// are comparisons where the types differ. // are comparisons where the types differ.
isfalse(ia == ib); isfalse(ia == ib)
isfalse(ia == ic); isfalse(ia == ic)
isfalse(ia == id); isfalse(ia == id)
isfalse(ib == ic); isfalse(ib == ic)
isfalse(ib == id); isfalse(ib == id)
istrue(ic == id); istrue(ic == id)
istrue(ie == ie); istrue(ie == ie)
// 6g used to let this go through as true. // 6g used to let this go through as true.
var g uint64 = 123; var g uint64 = 123
var h int64 = 123; var h int64 = 123
var ig interface{} = g; var ig interface{} = g
var ih interface{} = h; var ih interface{} = h
isfalse(ig == ih); isfalse(ig == ih)
// map of interface should use == on interface values, // map of interface should use == on interface values,
// not memory. // not memory.
// TODO: should m[c], m[d] be valid here? // TODO: should m[c], m[d] be valid here?
var m = make(map[interface{}] int); var m = make(map[interface{}]int)
m[ic] = 1; m[ic] = 1
m[id] = 2; m[id] = 2
if m[ic] != 2 { if m[ic] != 2 {
panic("m[ic] = ", m[ic]); panic("m[ic] = ", m[ic])
} }
} }
...@@ -9,21 +9,21 @@ package main ...@@ -9,21 +9,21 @@ package main
import "fmt" import "fmt"
type T int type T int
func (t T) String() string {
return fmt.Sprintf("T%d", t); func (t T) String() string { return fmt.Sprintf("T%d", t) }
}
const ( const (
A T = 1<<(1<<iota); A T = 1 << (1 << iota)
B; B
C; C
D; D
E; E
) )
func main() { func main() {
s := fmt.Sprintf("%v %v %v %v %v", A, B, C, D, E); s := fmt.Sprintf("%v %v %v %v %v", A, B, C, D, E)
if s != "T2 T4 T16 T256 T65536" { if s != "T2 T4 T16 T256 T65536" {
panicln("type info didn't propagate in const: got", s); println("type info didn't propagate in const: got", s)
panic("fail")
} }
} }
...@@ -8,40 +8,37 @@ package main ...@@ -8,40 +8,37 @@ package main
import "reflect" import "reflect"
func typeof(x interface{}) string { func typeof(x interface{}) string { return reflect.Typeof(x).String() }
return reflect.Typeof(x).String();
}
func f() int { func f() int { return 0 }
return 0;
}
func g() int { func g() int { return 0 }
return 0;
}
type T func() int type T func() int
var m = map[string] T { "f": f } var m = map[string]T{"f": f}
type A int type A int
type B int type B int
var a A = 1; var a A = 1
var b B = 2; var b B = 2
var x int; var x int
func main() { func main() {
want := typeof(g); want := typeof(g)
if t := typeof(f); t != want { if t := typeof(f); t != want {
panicln("type of f is", t, "want", want); println("type of f is", t, "want", want)
panic("fail")
} }
want = typeof(a); want = typeof(a)
if t := typeof(+a); t != want { if t := typeof(+a); t != want {
panicln("type of +a is", t, "want", want); println("type of +a is", t, "want", want)
panic("fail")
} }
if t := typeof(a+0); t != want { if t := typeof(a + 0); t != want {
panicln("type of a+0 is", t, "want", want); println("type of a+0 is", t, "want", want)
panic("fail")
} }
} }
...@@ -14,13 +14,11 @@ func sum(args ...int) int { ...@@ -14,13 +14,11 @@ func sum(args ...int) int {
return s return s
} }
func sumC(args ...int) int { func sumC(args ...int) int { return func() int { return sum(args) }() }
return func() int { return sum(args) } ()
}
var sumD = func(args ...int) int { return sum(args) } var sumD = func(args ...int) int { return sum(args) }
var sumE = func() func(...int) int { return func(args ...int) int { return sum(args) } } () var sumE = func() func(...int) int { return func(args ...int) int { return sum(args) } }()
var sumF = func(args ...int) func() int { return func() int { return sum(args) } } var sumF = func(args ...int) func() int { return func() int { return sum(args) } }
...@@ -50,9 +48,7 @@ func ln(args ...T) int { return len(args) } ...@@ -50,9 +48,7 @@ func ln(args ...T) int { return len(args) }
func ln2(args ...T) int { return 2 * ln(args) } func ln2(args ...T) int { return 2 * ln(args) }
func (*T) Sum(args ...int) int { func (*T) Sum(args ...int) int { return sum(args) }
return sum(args)
}
type U struct { type U struct {
*T *T
...@@ -60,108 +56,143 @@ type U struct { ...@@ -60,108 +56,143 @@ type U struct {
func main() { func main() {
if x := sum(1, 2, 3); x != 6 { if x := sum(1, 2, 3); x != 6 {
panicln("sum 6", x) println("sum 6", x)
panic("fail")
} }
if x := sum(); x != 0 { if x := sum(); x != 0 {
panicln("sum 0", x) println("sum 0", x)
panic("fail")
} }
if x := sum(10); x != 10 { if x := sum(10); x != 10 {
panicln("sum 10", x) println("sum 10", x)
panic("fail")
} }
if x := sum(1, 8); x != 9 { if x := sum(1, 8); x != 9 {
panicln("sum 9", x) println("sum 9", x)
panic("fail")
} }
if x := sumC(4, 5, 6); x != 15 { if x := sumC(4, 5, 6); x != 15 {
panicln("sumC 15", x) println("sumC 15", x)
panic("fail")
} }
if x := sumD(4, 5, 7); x != 16 { if x := sumD(4, 5, 7); x != 16 {
panicln("sumD 16", x) println("sumD 16", x)
panic("fail")
} }
if x := sumE(4, 5, 8); x != 17 { if x := sumE(4, 5, 8); x != 17 {
panicln("sumE 17", x) println("sumE 17", x)
panic("fail")
} }
if x := sumF(4, 5, 9)(); x != 18 { if x := sumF(4, 5, 9)(); x != 18 {
panicln("sumF 18", x) println("sumF 18", x)
panic("fail")
} }
if x := sum2(1, 2, 3); x != 2*6 { if x := sum2(1, 2, 3); x != 2*6 {
panicln("sum 6", x) println("sum 6", x)
panic("fail")
} }
if x := sum2(); x != 2*0 { if x := sum2(); x != 2*0 {
panicln("sum 0", x) println("sum 0", x)
panic("fail")
} }
if x := sum2(10); x != 2*10 { if x := sum2(10); x != 2*10 {
panicln("sum 10", x) println("sum 10", x)
panic("fail")
} }
if x := sum2(1, 8); x != 2*9 { if x := sum2(1, 8); x != 2*9 {
panicln("sum 9", x) println("sum 9", x)
panic("fail")
} }
if x := sum3(1, 2, 3); x != 3*6 { if x := sum3(1, 2, 3); x != 3*6 {
panicln("sum 6", x) println("sum 6", x)
panic("fail")
} }
if x := sum3(); x != 3*0 { if x := sum3(); x != 3*0 {
panicln("sum 0", x) println("sum 0", x)
panic("fail")
} }
if x := sum3(10); x != 3*10 { if x := sum3(10); x != 3*10 {
panicln("sum 10", x) println("sum 10", x)
panic("fail")
} }
if x := sum3(1, 8); x != 3*9 { if x := sum3(1, 8); x != 3*9 {
panicln("sum 9", x) println("sum 9", x)
panic("fail")
} }
if x := intersum(1, 2, 3); x != 6 { if x := intersum(1, 2, 3); x != 6 {
panicln("intersum 6", x) println("intersum 6", x)
panic("fail")
} }
if x := intersum(); x != 0 { if x := intersum(); x != 0 {
panicln("intersum 0", x) println("intersum 0", x)
panic("fail")
} }
if x := intersum(10); x != 10 { if x := intersum(10); x != 10 {
panicln("intersum 10", x) println("intersum 10", x)
panic("fail")
} }
if x := intersum(1, 8); x != 9 { if x := intersum(1, 8); x != 9 {
panicln("intersum 9", x) println("intersum 9", x)
panic("fail")
} }
if x := ln(nil, nil, nil); x != 3 { if x := ln(nil, nil, nil); x != 3 {
panicln("ln 3", x) println("ln 3", x)
panic("fail")
} }
if x := ln([]T{}); x != 1 { if x := ln([]T{}); x != 1 {
panicln("ln 1", x) println("ln 1", x)
panic("fail")
} }
if x := ln2(nil, nil, nil); x != 2*3 { if x := ln2(nil, nil, nil); x != 2*3 {
panicln("ln2 3", x) println("ln2 3", x)
panic("fail")
} }
if x := ln2([]T{}); x != 2*1 { if x := ln2([]T{}); x != 2*1 {
panicln("ln2 1", x) println("ln2 1", x)
panic("fail")
} }
if x := ((*T)(nil)).Sum(1,3,5,7); x != 16 { if x := ((*T)(nil)).Sum(1, 3, 5, 7); x != 16 {
panicln("(*T)(nil).Sum", x) println("(*T)(nil).Sum", x)
panic("fail")
} }
if x := (*T).Sum(nil, 1, 3, 5, 6); x != 15 { if x := (*T).Sum(nil, 1, 3, 5, 6); x != 15 {
panicln("(*T).Sum", x) println("(*T).Sum", x)
panic("fail")
} }
if x := (&U{}).Sum(1,3,5,5); x != 14 { if x := (&U{}).Sum(1, 3, 5, 5); x != 14 {
panicln("(&U{}).Sum", x) println("(&U{}).Sum", x)
panic("fail")
} }
var u U var u U
if x := u.Sum(1,3,5,4); x != 13 { if x := u.Sum(1, 3, 5, 4); x != 13 {
panicln("u.Sum", x) println("u.Sum", x)
panic("fail")
} }
if x := (&u).Sum(1,3,5,3); x != 12 { if x := (&u).Sum(1, 3, 5, 3); x != 12 {
panicln("(&u).Sum", x) println("(&u).Sum", x)
panic("fail")
} }
var i interface { Sum(...int) int } = &u var i interface {
if x := i.Sum(2,3,5,7); x != 17 { Sum(...int) int
panicln("i(=&u).Sum", x) } = &u
if x := i.Sum(2, 3, 5, 7); x != 17 {
println("i(=&u).Sum", x)
panic("fail")
} }
i = u i = u
if x := i.Sum(2,3,5,6); x != 16 { if x := i.Sum(2, 3, 5, 6); x != 16 {
panicln("i(=u).Sum", x) println("i(=u).Sum", x)
panic("fail")
} }
/* TODO(rsc): Enable once nested method expressions work. /* TODO(rsc): Enable once nested method expressions work.
if x := (*U).Sum(&U{}, 1, 3, 5, 2); x != 11 { if x := (*U).Sum(&U{}, 1, 3, 5, 2); x != 11 {
panicln("(*U).Sum", x) println("(*U).Sum", x)
panic("fail")
} }
if x := U.Sum(U{}, 1, 3, 5, 1); x != 10 { if x := U.Sum(U{}, 1, 3, 5, 1); x != 10 {
panicln("U.Sum", x) println("U.Sum", x)
panic("fail")
} }
*/ */
} }
...@@ -10,15 +10,19 @@ import "./ddd2" ...@@ -10,15 +10,19 @@ import "./ddd2"
func main() { func main() {
if x := ddd.Sum(1, 2, 3); x != 6 { if x := ddd.Sum(1, 2, 3); x != 6 {
panicln("ddd.Sum 6", x) println("ddd.Sum 6", x)
panic("fail")
} }
if x := ddd.Sum(); x != 0 { if x := ddd.Sum(); x != 0 {
panicln("ddd.Sum 0", x) println("ddd.Sum 0", x)
panic("fail")
} }
if x := ddd.Sum(10); x != 10 { if x := ddd.Sum(10); x != 10 {
panicln("ddd.Sum 10", x) println("ddd.Sum 10", x)
panic("fail")
} }
if x := ddd.Sum(1, 8); x != 9 { if x := ddd.Sum(1, 8); x != 9 {
panicln("ddd.Sum 9", x) println("ddd.Sum 9", x)
panic("fail")
} }
} }
...@@ -5,16 +5,24 @@ ...@@ -5,16 +5,24 @@
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package main package main
type I interface { };
func foo1(i int) int { return i } type I interface{}
func foo1(i int) int { return i }
func foo2(i int32) int32 { return i } func foo2(i int32) int32 { return i }
func main() { func main() {
var i I; var i I
i = 1; i = 1
var v1 = i.(int); var v1 = i.(int)
if foo1(v1) != 1 { panicln(1) } if foo1(v1) != 1 {
var v2 = int32(i.(int)); panic(1)
if foo2(v2) != 1 { panicln(2) } }
var v3 = i.(int32); // This type conversion should fail at runtime. var v2 = int32(i.(int))
if foo2(v3) != 1 { panicln(3) } if foo2(v2) != 1 {
panic(2)
}
var v3 = i.(int32) // This type conversion should fail at runtime.
if foo2(v3) != 1 {
panic(3)
}
} }
...@@ -7,17 +7,20 @@ ...@@ -7,17 +7,20 @@
package main package main
const B32 = 1<<32 - 1 const B32 = 1<<32 - 1
const C32 = (-1) & ((1<<32) - 1) const C32 = (-1) & ((1 << 32) - 1)
const D32 = ^0 const D32 = ^0
func main() { func main() {
if B32 != 0xFFFFFFFF { if B32 != 0xFFFFFFFF {
panicln("1<<32 - 1 is", B32, "should be", 0xFFFFFFFF) println("1<<32 - 1 is", B32, "should be", 0xFFFFFFFF)
panic("fail")
} }
if C32 != 0xFFFFFFFF { if C32 != 0xFFFFFFFF {
panicln("(-1) & ((1<<32) - 1) is", C32, "should be", 0xFFFFFFFF) println("(-1) & ((1<<32) - 1) is", C32, "should be", 0xFFFFFFFF)
panic("fail")
} }
if D32 != -1 { if D32 != -1 {
panicln("^0 is", D32, "should be", -1) println("^0 is", D32, "should be", -1)
panic("fail")
} }
} }
...@@ -7,28 +7,29 @@ ...@@ -7,28 +7,29 @@
package main package main
func main() { func main() {
bad := false; bad := false
if (-5>>1) != -3 { if (-5 >> 1) != -3 {
println("-5>>1 =", -5>>1, "want -3"); println("-5>>1 =", -5>>1, "want -3")
bad = true; bad = true
} }
if (-4>>1) != -2 { if (-4 >> 1) != -2 {
println("-4>>1 =", -4>>1, "want -2"); println("-4>>1 =", -4>>1, "want -2")
bad = true; bad = true
} }
if (-3>>1) != -2 { if (-3 >> 1) != -2 {
println("-3>>1 =", -3>>1, "want -2"); println("-3>>1 =", -3>>1, "want -2")
bad = true; bad = true
} }
if (-2>>1) != -1 { if (-2 >> 1) != -1 {
println("-2>>1 =", -2>>1, "want -1"); println("-2>>1 =", -2>>1, "want -1")
bad = true; bad = true
} }
if (-1>>1) != -1 { if (-1 >> 1) != -1 {
println("-1>>1 =", -1>>1, "want -1"); println("-1>>1 =", -1>>1, "want -1")
bad = true; bad = true
} }
if bad { if bad {
panicln("errors"); println("errors")
panic("fail")
} }
} }
...@@ -7,13 +7,18 @@ ...@@ -7,13 +7,18 @@
package main package main
func foo(a []int) int { func foo(a []int) int {
return a[0] // this seems to do the wrong thing return a[0] // this seems to do the wrong thing
} }
func main() { func main() {
a := &[]int{12}; a := &[]int{12}
if x := (*a)[0]; x != 12 { panicln(2) } if x := (*a)[0]; x != 12 {
if x := foo(*a) ; x != 12 { panicln(3) } // fails (x is incorrect) panic(2)
}
if x := foo(*a); x != 12 {
// fails (x is incorrect)
panic(3)
}
} }
/* /*
......
...@@ -7,20 +7,20 @@ ...@@ -7,20 +7,20 @@
package main package main
import "os" import "os"
import "strconv"; import "strconv"
type Test struct { type Test struct {
f float64; f float64
in string; in string
out string; out string
} }
var tests = []Test { var tests = []Test{
Test{ 123.5, "123.5", "123.5" }, Test{123.5, "123.5", "123.5"},
Test{ 456.7, "456.7", "456.7" }, Test{456.7, "456.7", "456.7"},
Test{ 1e23+8.5e6, "1e23+8.5e6", "1.0000000000000001e+23" }, Test{1e23 + 8.5e6, "1e23+8.5e6", "1.0000000000000001e+23"},
Test{ 100000000000000008388608, "100000000000000008388608", "1.0000000000000001e+23" }, Test{100000000000000008388608, "100000000000000008388608", "1.0000000000000001e+23"},
Test{ 1e23+8388609, "1e23+8388609", "1.0000000000000001e+23" }, Test{1e23 + 8388609, "1e23+8388609", "1.0000000000000001e+23"},
// "x" = the floating point value from converting the string x. // "x" = the floating point value from converting the string x.
// These are exactly representable in 64-bit floating point: // These are exactly representable in 64-bit floating point:
...@@ -33,27 +33,28 @@ var tests = []Test { ...@@ -33,27 +33,28 @@ var tests = []Test {
// The correct answer, of course, would be "1e23+8388608" = 1e23+8388608. // The correct answer, of course, would be "1e23+8388608" = 1e23+8388608.
// This is not going to be correct until 6g has multiprecision floating point. // This is not going to be correct until 6g has multiprecision floating point.
// A simpler case is "1e23+1", which should also round to 1e23+8388608. // A simpler case is "1e23+1", which should also round to 1e23+8388608.
Test{ 1e23+8.388608e6, "1e23+8.388608e6", "1.0000000000000001e+23" }, Test{1e23 + 8.388608e6, "1e23+8.388608e6", "1.0000000000000001e+23"},
Test{ 1e23+1, "1e23+1", "1.0000000000000001e+23" }, Test{1e23 + 1, "1e23+1", "1.0000000000000001e+23"},
} }
func main() { func main() {
ok := true; ok := true
for i := 0; i < len(tests); i++ { for i := 0; i < len(tests); i++ {
t := tests[i]; t := tests[i]
v := strconv.Ftoa64(t.f, 'g', -1); v := strconv.Ftoa64(t.f, 'g', -1)
if v != t.out { if v != t.out {
println("Bad float64 const:", t.in, "want", t.out, "got", v); println("Bad float64 const:", t.in, "want", t.out, "got", v)
x, err := strconv.Atof64(t.out); x, err := strconv.Atof64(t.out)
if err != nil { if err != nil {
panicln("bug120: strconv.Atof64", t.out); println("bug120: strconv.Atof64", t.out)
panic("fail")
} }
println("\twant exact:", strconv.Ftoa64(x, 'g', 1000)); println("\twant exact:", strconv.Ftoa64(x, 'g', 1000))
println("\tgot exact: ", strconv.Ftoa64(t.f, 'g', 1000)); println("\tgot exact: ", strconv.Ftoa64(t.f, 'g', 1000))
ok = false; ok = false
} }
} }
if !ok { if !ok {
os.Exit(1); os.Exit(1)
} }
} }
...@@ -5,18 +5,22 @@ ...@@ -5,18 +5,22 @@
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package main package main
import "time" import "time"
func main() { func main() {
var count int; var count int
c := make(chan byte); c := make(chan byte)
go func(c chan byte) { go func(c chan byte) {
<-c; <-c
count++; count++
time.Sleep(1000000); time.Sleep(1000000)
count++; count++
<-c; <-c
} (c); }(c)
c <- 1; c <- 1
c <- 2; c <- 2
if count != 2 { panicln("synchronous send did not wait") } if count != 2 {
panic("synchronous send did not wait")
}
} }
...@@ -6,12 +6,11 @@ ...@@ -6,12 +6,11 @@
package main package main
func shift(x int) int { func shift(x int) int { return 1 << (1 << (1 << (uint(x)))) }
return 1<<(1<<(1<<(uint(x))));
}
func main() { func main() {
if n := shift(2); n != 1<<(1<<(1<<2)) { if n := shift(2); n != 1<<(1<<(1<<2)) {
panicln("bad shift", n); println("bad shift", n)
panic("fail")
} }
} }
...@@ -9,45 +9,41 @@ package main ...@@ -9,45 +9,41 @@ package main
import "fmt" import "fmt"
type Buffer int type Buffer int
func (*Buffer) Read() {
}
type Reader interface { Read() } func (*Buffer) Read() {}
func f() *Buffer { type Reader interface {
return nil Read()
} }
func f() *Buffer { return nil }
func g() Reader { func g() Reader {
// implicit interface conversion in assignment during return // implicit interface conversion in assignment during return
return f() return f()
} }
func h() (b *Buffer, ok bool) { func h() (b *Buffer, ok bool) { return }
return
}
func i() (r Reader, ok bool) { func i() (r Reader, ok bool) {
// implicit interface conversion in multi-assignment during return // implicit interface conversion in multi-assignment during return
return h(); return h()
} }
func fmter() (s string, i int, t string) { func fmter() (s string, i int, t string) { return "%#x %q", 100, "hello" }
return "%#x %q", 100, "hello"
}
func main() { func main() {
b := g(); b := g()
bb, ok := b.(*Buffer); bb, ok := b.(*Buffer)
_, _, _ = b, bb, ok; _, _, _ = b, bb, ok
b, ok = i(); b, ok = i()
bb, ok = b.(*Buffer); bb, ok = b.(*Buffer)
_, _, _ = b, bb, ok; _, _, _ = b, bb, ok
s := fmt.Sprintf(fmter()); s := fmt.Sprintf(fmter())
if s != "0x64 \"hello\"" { if s != "0x64 \"hello\"" {
panicln(s); println(s)
panic("fail")
} }
} }
...@@ -6,28 +6,30 @@ ...@@ -6,28 +6,30 @@
package main package main
func g() { } func g() {}
func f1() (a, b int) { func f1() (a, b int) {
a, b = 2, 1; a, b = 2, 1
g(); // defeat optimizer g() // defeat optimizer
return a, b; return a, b
} }
func f2() (a, b int) { func f2() (a, b int) {
a, b = 1, 2; a, b = 1, 2
g(); // defeat optimizer g() // defeat optimizer
return b, a; return b, a
} }
func main() { func main() {
x, y := f1(); x, y := f1()
if x != 2 || y != 1 { if x != 2 || y != 1 {
panicln("f1", x, y); println("f1", x, y)
panic("fail")
} }
x, y = f2(); x, y = f2()
if x != 2 || y != 1 { if x != 2 || y != 1 {
panicln("f2", x, y); println("f2", x, y)
panic("fail")
} }
} }
...@@ -6,46 +6,45 @@ ...@@ -6,46 +6,45 @@
package main package main
var m = map[int]int{ 0: 0, 1: 0 } var m = map[int]int{0: 0, 1: 0}
var nf = 0 var nf = 0
var i int var i int
func multi() (int, int) { func multi() (int, int) { return 1, 2 }
return 1,2
}
func xxx() { func xxx() {
var c chan int; var c chan int
x, ok := <-c; x, ok := <-c
var m map[int]int; var m map[int]int
x, ok = m[1]; x, ok = m[1]
var i interface{}; var i interface{}
var xx int; var xx int
xx, ok = i.(int); xx, ok = i.(int)
a,b := multi(); a, b := multi()
_, _, _, _, _ = x, ok, xx, a, b; _, _, _, _, _ = x, ok, xx, a, b
} }
func f() map[int]int { func f() map[int]int {
nf++; nf++
return m; return m
} }
func g() *int { func g() *int {
nf++; nf++
return &i return &i
} }
func main() { func main() {
f()[0]++; f()[0]++
f()[1] += 2; f()[1] += 2
*g() %= 2; *g() %= 2
if nf != 3 { if nf != 3 {
panicln("too many calls:", nf); println("too many calls:", nf)
panic("fail")
} }
} }
...@@ -7,19 +7,21 @@ ...@@ -7,19 +7,21 @@
package main package main
type S struct { type S struct {
a []int; a []int
} }
var s = &S{make([]int, 10)} var s = &S{make([]int, 10)}
func main() { func main() {
s.a[f()] = 1 // 6g used to call f twice here s.a[f()] = 1 // 6g used to call f twice here
} }
var n int var n int
func f() int{
func f() int {
if n++; n > 1 { if n++; n > 1 {
panicln("f twice"); println("f twice")
panic("fail")
} }
return 0 return 0
} }
...@@ -6,31 +6,43 @@ ...@@ -6,31 +6,43 @@
package main package main
type T1 struct { x, y int; } type T1 struct {
type T2 struct { z, w byte; } x, y int
}
type T2 struct {
z, w byte
}
type T3 T1 type T3 T1
type MyInt int type MyInt int
func (MyInt) m(*T1) { }
func (MyInt) m(*T1) {}
func main() { func main() {
{ {
var i interface{} = new(T1); var i interface{} = new(T1)
_, ok1 := i.(*T1); _, ok1 := i.(*T1)
_, ok2 := i.(*T2); _, ok2 := i.(*T2)
_, ok3 := i.(*T3); _, ok3 := i.(*T3)
if !ok1 || ok2 || ok3 { if !ok1 || ok2 || ok3 {
panicln("*T1", ok1, ok2, ok3); println("*T1", ok1, ok2, ok3)
panic("fail")
} }
} }
{ {
var i interface{} = MyInt(0); var i interface{} = MyInt(0)
_, ok1 := i.(interface{ m(*T1) }); _, ok1 := i.(interface {
_, ok2 := i.(interface{ m(*T2) }); m(*T1)
_, ok3 := i.(interface{ m(*T3) }); })
_, ok2 := i.(interface {
m(*T2)
})
_, ok3 := i.(interface {
m(*T3)
})
if !ok1 || ok2 || ok3 { if !ok1 || ok2 || ok3 {
panicln("T", ok1, ok2, ok3); println("T", ok1, ok2, ok3)
panic("fail")
} }
} }
} }
...@@ -10,6 +10,7 @@ package main ...@@ -10,6 +10,7 @@ package main
var i byte = 0 var i byte = 0
var a [30]byte var a [30]byte
func f() *byte { func f() *byte {
i++ i++
return &a[i-1] return &a[i-1]
...@@ -28,35 +29,39 @@ func x() (byte, byte) { ...@@ -28,35 +29,39 @@ func x() (byte, byte) {
} }
func e1(c chan byte, expected byte) chan byte { func e1(c chan byte, expected byte) chan byte {
if i != expected { if i != expected {
panicln("e1: got", i, "expected", expected) println("e1: got", i, "expected", expected)
panic("fail")
} }
i++ i++
return c return c
} }
type Empty interface {} type Empty interface{}
type I interface { type I interface {
Get() byte Get() byte
} }
type S1 struct { type S1 struct {
i byte i byte
} }
func (p S1) Get() byte {
return p.i func (p S1) Get() byte { return p.i }
}
type S2 struct { type S2 struct {
i byte i byte
} }
func e2(p Empty, expected byte) Empty { func e2(p Empty, expected byte) Empty {
if i != expected { if i != expected {
panicln("e2: got", i, "expected", expected) println("e2: got", i, "expected", expected)
panic("fail")
} }
i++ i++
return p return p
} }
func e3(p *I, expected byte) *I { func e3(p *I, expected byte) *I {
if i != expected { if i != expected {
panicln("e3: got", i, "expected", expected) println("e3: got", i, "expected", expected)
panic("fail")
} }
i++ i++
return p return p
...@@ -67,55 +72,60 @@ func main() { ...@@ -67,55 +72,60 @@ func main() {
a[i] = ' ' a[i] = ' '
} }
// 0 1 2 3 4 5 // 0 1 2 3 4 5
*f(), *f(), *f() = gbyte(), gbyte(), gbyte() *f(), *f(), *f() = gbyte(), gbyte(), gbyte()
// 6 7 8 // 6 7 8
*f(), *f() = x() *f(), *f() = x()
m := make(map[byte]byte) m := make(map[byte]byte)
m[10] = 'A' m[10] = 'A'
var p1, p2 bool var p1, p2 bool
// 9 10 // 9 10
*f(), p1 = m[gint()] *f(), p1 = m[gint()]
// 11 12 // 11 12
*f(), p2 = m[gint()] *f(), p2 = m[gint()]
a[11] += '0' a[11] += '0'
if !p1 || p2 { if !p1 || p2 {
panicln("bad map check", i, p1, p2) println("bad map check", i, p1, p2)
panic("fail")
} }
m[13] = 'B' m[13] = 'B'
// 13 14 // 13 14
m[gint()] = gbyte(), false m[gint()] = gbyte(), false
if _, present := m[13]; present { if _, present := m[13]; present {
panicln("bad map removal") println("bad map removal")
panic("fail")
} }
c := make(chan byte, 1) c := make(chan byte, 1)
c <- 'C' c <- 'C'
// 15 16 // 15 16
*f(), p1 = <-e1(c, 16) *f(), p1 = <-e1(c, 16)
// 17 18 // 17 18
*f(), p2 = <-e1(c, 18) *f(), p2 = <-e1(c, 18)
a[17] += '0' a[17] += '0'
if !p1 || p2 { if !p1 || p2 {
panicln("bad chan check", i, p1, p2) println("bad chan check", i, p1, p2)
panic("fail")
} }
s1 := S1{'D'} s1 := S1{'D'}
s2 := S2{'E'} s2 := S2{'E'}
var iv I var iv I
// 19 20 // 19 20
*e3(&iv, 19), p1 = e2(s1, 20).(I) *e3(&iv, 19), p1 = e2(s1, 20).(I)
// 21 22 // 21 22
*e3(&iv, 21), p2 = e2(s2, 22).(I) *e3(&iv, 21), p2 = e2(s2, 22).(I)
if !p1 || p2 { if !p1 || p2 {
panicln("bad interface check", i, p1, p2) println("bad interface check", i, p1, p2)
panic("fail")
} }
s := string(a[0:i]) s := string(a[0:i])
if s != "def ii A 0 C 0 " { if s != "def ii A 0 C 0 " {
panicln("bad array results:", s) println("bad array results:", s)
panic("fail")
} }
} }
...@@ -15,8 +15,9 @@ func main() { ...@@ -15,8 +15,9 @@ func main() {
// fails // fails
x2 := (*int)(unsafe.Pointer(uintptr(0x234))) x2 := (*int)(unsafe.Pointer(uintptr(0x234)))
if x1 != x2 { if x1 != x2 {
panicln("mismatch", x1, x2) println("mismatch", x1, x2)
panic("fail")
} }
} }
...@@ -15,6 +15,7 @@ func main() { ...@@ -15,6 +15,7 @@ func main() {
var i interface{} = Count var i interface{} = Count
j := i.(int) j := i.(int)
if j != Count { if j != Count {
panicln("j=", j) println("j=", j)
panic("fail")
} }
} }
...@@ -39,27 +39,33 @@ func main() { ...@@ -39,27 +39,33 @@ func main() {
// path is full (rooted) path name. check suffix for gc, prefix for gccgo // path is full (rooted) path name. check suffix for gc, prefix for gccgo
if s := reflect.Typeof(v0).PkgPath(); !strings.HasSuffix(s, "/bug0") && !strings.HasPrefix(s, "bug0") { if s := reflect.Typeof(v0).PkgPath(); !strings.HasSuffix(s, "/bug0") && !strings.HasPrefix(s, "bug0") {
panicln("bad v0 path", len(s), s) println("bad v0 path", len(s), s)
panic("fail")
} }
if s := reflect.Typeof(v1).PkgPath(); !strings.HasSuffix(s, "/bug1") && !strings.HasPrefix(s, "bug1") { if s := reflect.Typeof(v1).PkgPath(); !strings.HasSuffix(s, "/bug1") && !strings.HasPrefix(s, "bug1") {
panicln("bad v1 path", s) println("bad v1 path", s)
panic("fail")
} }
// check that dynamic interface check doesn't get confused // check that dynamic interface check doesn't get confused
var i interface{} = t0(0) var i interface{} = t0(0)
if _, ok := i.(I1); ok { if _, ok := i.(I1); ok {
panicln("used t0 as i1") println("used t0 as i1")
panic("fail")
} }
if _, ok := i.(p1.I); ok { if _, ok := i.(p1.I); ok {
panicln("used t0 as p1.I") println("used t0 as p1.I")
panic("fail")
} }
i = t1(1) i = t1(1)
if _, ok := i.(I0); ok { if _, ok := i.(I0); ok {
panicln("used t1 as i0") println("used t1 as i0")
panic("fail")
} }
if _, ok := i.(p0.I); ok { if _, ok := i.(p0.I); ok {
panicln("used t1 as p0.I") println("used t1 as p0.I")
panic("fail")
} }
// check that type switch works. // check that type switch works.
...@@ -77,15 +83,18 @@ func main() { ...@@ -77,15 +83,18 @@ func main() {
switch k := i.(type) { switch k := i.(type) {
case p0.T: case p0.T:
if j != 0 { if j != 0 {
panicln("type switch p0.T") println("type switch p0.T")
panic("fail")
} }
case p1.T: case p1.T:
if j != 1 { if j != 1 {
panicln("type switch p1.T") println("type switch p1.T")
panic("fail")
} }
default: default:
if j != 2 { if j != 2 {
panicln("type switch default", j) println("type switch default", j)
panic("fail")
} }
} }
} }
......
...@@ -11,6 +11,7 @@ var b [1e1]int ...@@ -11,6 +11,7 @@ var b [1e1]int
func main() { func main() {
if len(a) != 10 || len(b) != 10 { if len(a) != 10 || len(b) != 10 {
panicln("len", len(a), len(b)) println("len", len(a), len(b))
panic("fail")
} }
} }
...@@ -60,7 +60,8 @@ func parseDir(dirpath string) map[string]*ast.Package { ...@@ -60,7 +60,8 @@ func parseDir(dirpath string) map[string]*ast.Package {
// get package AST // get package AST
pkgs, err := parser.ParseDir(dirpath, filter, parser.ParseComments) pkgs, err := parser.ParseDir(dirpath, filter, parser.ParseComments)
if err != nil { if err != nil {
panicln("parse", dirpath, err.String()) println("parse", dirpath, err.String())
panic("fail")
} }
return pkgs return pkgs
} }
......
...@@ -32,7 +32,7 @@ func crash() { ...@@ -32,7 +32,7 @@ func crash() {
// these uses of nil pointers // these uses of nil pointers
// would crash but should type check // would crash but should type check
println("crash", println("crash",
len(a1) + cap(a1)); len(a1)+cap(a1))
} }
func nocrash() { func nocrash() {
...@@ -42,41 +42,44 @@ func nocrash() { ...@@ -42,41 +42,44 @@ func nocrash() {
// it decides there are type errors. // it decides there are type errors.
// it might also help in the traceback. // it might also help in the traceback.
x := x :=
len(m0)+ len(m0) +
len(m3); len(m3)
if x != 1 { if x != 1 {
panicln("wrong maplen"); println("wrong maplen")
panic("fail")
} }
x = x =
len(s0)+ len(s0) +
len(s3); len(s3)
if x != 1 { if x != 1 {
panicln("wrong stringlen"); println("wrong stringlen")
panic("fail")
} }
x = x =
len(a0)+ len(a0) +
len(a2); len(a2)
if x != 20 { if x != 20 {
panicln("wrong arraylen"); println("wrong arraylen")
panic("fail")
} }
x = x =
len(b0)+ len(b0) +
len(b3); len(b3)
if x != 3 { if x != 3 {
panicln("wrong slicelen"); println("wrong slicelen")
panic("fail")
} }
x = x =
cap(b0)+ cap(b0) +
cap(b3); cap(b3)
if x != 3 { if x != 3 {
panicln("wrong slicecap"); println("wrong slicecap")
panic("fail")
} }
} }
func main() { func main() { nocrash() }
nocrash();
}
...@@ -6,29 +6,74 @@ ...@@ -6,29 +6,74 @@
package main package main
var a = []int { 1,2, } var a = []int{1, 2}
var b = [5]int { 1,2,3 } var b = [5]int{1, 2, 3}
var c = []int { 1 } var c = []int{1}
var d = [...]int { 1,2,3 } var d = [...]int{1, 2, 3}
func main() { func main() {
if len(a) != 2 { panicln("len a", len(a)) } if len(a) != 2 {
if len(b) != 5 { panicln("len b", len(b)) } println("len a", len(a))
if len(c) != 1 { panicln("len d", len(c)) } panic("fail")
if len(d) != 3 { panicln("len c", len(d)) } }
if len(b) != 5 {
println("len b", len(b))
panic("fail")
}
if len(c) != 1 {
println("len d", len(c))
panic("fail")
}
if len(d) != 3 {
println("len c", len(d))
panic("fail")
}
if a[0] != 1 { panicln("a[0]", a[0]) } if a[0] != 1 {
if a[1] != 2 { panicln("a[1]", a[1]) } println("a[0]", a[0])
panic("fail")
}
if a[1] != 2 {
println("a[1]", a[1])
panic("fail")
}
if b[0] != 1 { panicln("b[0]", b[0]) } if b[0] != 1 {
if b[1] != 2 { panicln("b[1]", b[1]) } println("b[0]", b[0])
if b[2] != 3 { panicln("b[2]", b[2]) } panic("fail")
if b[3] != 0 { panicln("b[3]", b[3]) } }
if b[4] != 0 { panicln("b[4]", b[4]) } if b[1] != 2 {
println("b[1]", b[1])
panic("fail")
}
if b[2] != 3 {
println("b[2]", b[2])
panic("fail")
}
if b[3] != 0 {
println("b[3]", b[3])
panic("fail")
}
if b[4] != 0 {
println("b[4]", b[4])
panic("fail")
}
if c[0] != 1 { panicln("c[0]", c[0]) } if c[0] != 1 {
println("c[0]", c[0])
panic("fail")
}
if d[0] != 1 { panicln("d[0]", d[0]) } if d[0] != 1 {
if d[1] != 2 { panicln("d[1]", d[1]) } println("d[0]", d[0])
if d[2] != 3 { panicln("d[2]", d[2]) } panic("fail")
}
if d[1] != 2 {
println("d[1]", d[1])
panic("fail")
}
if d[2] != 3 {
println("d[2]", d[2])
panic("fail")
}
} }
...@@ -7,133 +7,173 @@ ...@@ -7,133 +7,173 @@
package main package main
const ( const (
ci8 = -1<<7; ci8 = -1 << 7
ci16 = -1<<15 + 100; ci16 = -1<<15 + 100
ci32 = -1<<31 + 100000; ci32 = -1<<31 + 100000
ci64 = -1<<63 + 10000000001; ci64 = -1<<63 + 10000000001
cu8 = 1<<8 - 1; cu8 = 1<<8 - 1
cu16 = 1<<16 - 1234; cu16 = 1<<16 - 1234
cu32 = 1<<32 - 1234567; cu32 = 1<<32 - 1234567
cu64 = 1<<64 - 1234567890123; cu64 = 1<<64 - 1234567890123
cf32 = 1e8 + 0.5; cf32 = 1e8 + 0.5
cf64 = -1e8 + 0.5; cf64 = -1e8 + 0.5
) )
var ( var (
i8 int8 = ci8; i8 int8 = ci8
i16 int16 = ci16; i16 int16 = ci16
i32 int32 = ci32; i32 int32 = ci32
i64 int64 = ci64; i64 int64 = ci64
u8 uint8 = cu8; u8 uint8 = cu8
u16 uint16 = cu16; u16 uint16 = cu16
u32 uint32 = cu32; u32 uint32 = cu32
u64 uint64 = cu64; u64 uint64 = cu64
// f32 float32 = 1e8 + 0.5; // f32 float32 = 1e8 + 0.5
// f64 float64 = -1e8 + 0.5; // f64 float64 = -1e8 + 0.5
) )
func chki8(i, v int8) { if i != v { panicln(i, "!=", v) } } func chki8(i, v int8) {
func chki16(i, v int16) { if i != v { panicln(i, "!=", v) } } if i != v {
func chki32(i, v int32) { if i != v { panicln(i, "!=", v) } } println(i, "!=", v)
func chki64(i, v int64) { if i != v { panicln(i, "!=", v) } } panic("fail")
func chku8(i, v uint8) { if i != v { panicln(i, "!=", v) } } }
func chku16(i, v uint16) { if i != v { panicln(i, "!=", v) } } }
func chku32(i, v uint32) { if i != v { panicln(i, "!=", v) } } func chki16(i, v int16) {
func chku64(i, v uint64) { if i != v { panicln(i, "!=", v) } } if i != v {
//func chkf32(f, v float32) { if f != v { panicln(f, "!=", v) } } println(i, "!=", v)
//func chkf64(f, v float64) { if f != v { panicln(f, "!=", v) } } panic("fail")
}
}
func chki32(i, v int32) {
if i != v {
println(i, "!=", v)
panic("fail")
}
}
func chki64(i, v int64) {
if i != v {
println(i, "!=", v)
panic("fail")
}
}
func chku8(i, v uint8) {
if i != v {
println(i, "!=", v)
panic("fail")
}
}
func chku16(i, v uint16) {
if i != v {
println(i, "!=", v)
panic("fail")
}
}
func chku32(i, v uint32) {
if i != v {
println(i, "!=", v)
panic("fail")
}
}
func chku64(i, v uint64) {
if i != v {
println(i, "!=", v)
panic("fail")
}
}
//func chkf32(f, v float32) { if f != v { println(f, "!=", v); panic("fail") } }
//func chkf64(f, v float64) { if f != v { println(f, "!=", v); panic("fail") } }
func main() { func main() {
chki8(int8(i8), ci8 & 0xff - 1<<8); chki8(int8(i8), ci8&0xff-1<<8)
chki8(int8(i16), ci16 & 0xff); chki8(int8(i16), ci16&0xff)
chki8(int8(i32), ci32 & 0xff - 1<<8); chki8(int8(i32), ci32&0xff-1<<8)
chki8(int8(i64), ci64 & 0xff); chki8(int8(i64), ci64&0xff)
chki8(int8(u8), cu8 & 0xff - 1<<8); chki8(int8(u8), cu8&0xff-1<<8)
chki8(int8(u16), cu16 & 0xff); chki8(int8(u16), cu16&0xff)
chki8(int8(u32), cu32 & 0xff); chki8(int8(u32), cu32&0xff)
chki8(int8(u64), cu64 & 0xff); chki8(int8(u64), cu64&0xff)
// chki8(int8(f32), 0); // chki8(int8(f32), 0)
// chki8(int8(f64), 0); // chki8(int8(f64), 0)
chki16(int16(i8), ci8 & 0xffff - 1<<16); chki16(int16(i8), ci8&0xffff-1<<16)
chki16(int16(i16), ci16 & 0xffff - 1<<16); chki16(int16(i16), ci16&0xffff-1<<16)
chki16(int16(i32), ci32 & 0xffff - 1<<16); chki16(int16(i32), ci32&0xffff-1<<16)
chki16(int16(i64), ci64 & 0xffff - 1<<16); chki16(int16(i64), ci64&0xffff-1<<16)
chki16(int16(u8), cu8 & 0xffff); chki16(int16(u8), cu8&0xffff)
chki16(int16(u16), cu16 & 0xffff - 1<<16); chki16(int16(u16), cu16&0xffff-1<<16)
chki16(int16(u32), cu32 & 0xffff); chki16(int16(u32), cu32&0xffff)
chki16(int16(u64), cu64 & 0xffff - 1<<16); chki16(int16(u64), cu64&0xffff-1<<16)
// chki16(int16(f32), 0); // chki16(int16(f32), 0)
// chki16(int16(f64), 0); // chki16(int16(f64), 0)
chki32(int32(i8), ci8 & 0xffffffff - 1<<32); chki32(int32(i8), ci8&0xffffffff-1<<32)
chki32(int32(i16), ci16 & 0xffffffff - 1<<32); chki32(int32(i16), ci16&0xffffffff-1<<32)
chki32(int32(i32), ci32 & 0xffffffff - 1<<32); chki32(int32(i32), ci32&0xffffffff-1<<32)
chki32(int32(i64), ci64 & 0xffffffff); chki32(int32(i64), ci64&0xffffffff)
chki32(int32(u8), cu8 & 0xffffffff); chki32(int32(u8), cu8&0xffffffff)
chki32(int32(u16), cu16 & 0xffffffff); chki32(int32(u16), cu16&0xffffffff)
chki32(int32(u32), cu32 & 0xffffffff - 1<<32); chki32(int32(u32), cu32&0xffffffff-1<<32)
chki32(int32(u64), cu64 & 0xffffffff - 1<<32); chki32(int32(u64), cu64&0xffffffff-1<<32)
// chki32(int32(f32), 0); // chki32(int32(f32), 0)
// chki32(int32(f64), 0); // chki32(int32(f64), 0)
chki64(int64(i8), ci8 & 0xffffffffffffffff - 1<<64); chki64(int64(i8), ci8&0xffffffffffffffff-1<<64)
chki64(int64(i16), ci16 & 0xffffffffffffffff - 1<<64); chki64(int64(i16), ci16&0xffffffffffffffff-1<<64)
chki64(int64(i32), ci32 & 0xffffffffffffffff - 1<<64); chki64(int64(i32), ci32&0xffffffffffffffff-1<<64)
chki64(int64(i64), ci64 & 0xffffffffffffffff - 1<<64); chki64(int64(i64), ci64&0xffffffffffffffff-1<<64)
chki64(int64(u8), cu8 & 0xffffffffffffffff); chki64(int64(u8), cu8&0xffffffffffffffff)
chki64(int64(u16), cu16 & 0xffffffffffffffff); chki64(int64(u16), cu16&0xffffffffffffffff)
chki64(int64(u32), cu32 & 0xffffffffffffffff); chki64(int64(u32), cu32&0xffffffffffffffff)
chki64(int64(u64), cu64 & 0xffffffffffffffff - 1<<64); chki64(int64(u64), cu64&0xffffffffffffffff-1<<64)
// chki64(int64(f32), 0); // chki64(int64(f32), 0)
// chki64(int64(f64), 0); // chki64(int64(f64), 0)
chku8(uint8(i8), ci8 & 0xff); chku8(uint8(i8), ci8&0xff)
chku8(uint8(i16), ci16 & 0xff); chku8(uint8(i16), ci16&0xff)
chku8(uint8(i32), ci32 & 0xff); chku8(uint8(i32), ci32&0xff)
chku8(uint8(i64), ci64 & 0xff); chku8(uint8(i64), ci64&0xff)
chku8(uint8(u8), cu8 & 0xff); chku8(uint8(u8), cu8&0xff)
chku8(uint8(u16), cu16 & 0xff); chku8(uint8(u16), cu16&0xff)
chku8(uint8(u32), cu32 & 0xff); chku8(uint8(u32), cu32&0xff)
chku8(uint8(u64), cu64 & 0xff); chku8(uint8(u64), cu64&0xff)
// chku8(uint8(f32), 0); // chku8(uint8(f32), 0)
// chku8(uint8(f64), 0); // chku8(uint8(f64), 0)
chku16(uint16(i8), ci8 & 0xffff); chku16(uint16(i8), ci8&0xffff)
chku16(uint16(i16), ci16 & 0xffff); chku16(uint16(i16), ci16&0xffff)
chku16(uint16(i32), ci32 & 0xffff); chku16(uint16(i32), ci32&0xffff)
chku16(uint16(i64), ci64 & 0xffff); chku16(uint16(i64), ci64&0xffff)
chku16(uint16(u8), cu8 & 0xffff); chku16(uint16(u8), cu8&0xffff)
chku16(uint16(u16), cu16 & 0xffff); chku16(uint16(u16), cu16&0xffff)
chku16(uint16(u32), cu32 & 0xffff); chku16(uint16(u32), cu32&0xffff)
chku16(uint16(u64), cu64 & 0xffff); chku16(uint16(u64), cu64&0xffff)
// chku16(uint16(f32), 0); // chku16(uint16(f32), 0)
// chku16(uint16(f64), 0); // chku16(uint16(f64), 0)
chku32(uint32(i8), ci8 & 0xffffffff); chku32(uint32(i8), ci8&0xffffffff)
chku32(uint32(i16), ci16 & 0xffffffff); chku32(uint32(i16), ci16&0xffffffff)
chku32(uint32(i32), ci32 & 0xffffffff); chku32(uint32(i32), ci32&0xffffffff)
chku32(uint32(i64), ci64 & 0xffffffff); chku32(uint32(i64), ci64&0xffffffff)
chku32(uint32(u8), cu8 & 0xffffffff); chku32(uint32(u8), cu8&0xffffffff)
chku32(uint32(u16), cu16 & 0xffffffff); chku32(uint32(u16), cu16&0xffffffff)
chku32(uint32(u32), cu32 & 0xffffffff); chku32(uint32(u32), cu32&0xffffffff)
chku32(uint32(u64), cu64 & 0xffffffff); chku32(uint32(u64), cu64&0xffffffff)
// chku32(uint32(f32), 0); // chku32(uint32(f32), 0)
// chku32(uint32(f64), 0); // chku32(uint32(f64), 0)
chku64(uint64(i8), ci8 & 0xffffffffffffffff); chku64(uint64(i8), ci8&0xffffffffffffffff)
chku64(uint64(i16), ci16 & 0xffffffffffffffff); chku64(uint64(i16), ci16&0xffffffffffffffff)
chku64(uint64(i32), ci32 & 0xffffffffffffffff); chku64(uint64(i32), ci32&0xffffffffffffffff)
chku64(uint64(i64), ci64 & 0xffffffffffffffff); chku64(uint64(i64), ci64&0xffffffffffffffff)
chku64(uint64(u8), cu8 & 0xffffffffffffffff); chku64(uint64(u8), cu8&0xffffffffffffffff)
chku64(uint64(u16), cu16 & 0xffffffffffffffff); chku64(uint64(u16), cu16&0xffffffffffffffff)
chku64(uint64(u32), cu32 & 0xffffffffffffffff); chku64(uint64(u32), cu32&0xffffffffffffffff)
chku64(uint64(u64), cu64 & 0xffffffffffffffff); chku64(uint64(u64), cu64&0xffffffffffffffff)
// chku64(uint64(f32), 0); // chku64(uint64(f32), 0)
// chku64(uint64(f64), 0); // chku64(uint64(f64), 0)
} }
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
package main package main
type T int type T int
var nv, np int var nv, np int
func (t T) V() { func (t T) V() {
...@@ -26,87 +27,94 @@ func (t *T) P() { ...@@ -26,87 +27,94 @@ func (t *T) P() {
np++ np++
} }
type V interface { V() } type V interface {
type P interface { P(); V() } V()
}
type P interface {
P()
V()
}
type S struct { type S struct {
T; T
} }
type SP struct { type SP struct {
*T; *T
} }
func main() { func main() {
var t T; var t T
var v V; var v V
var p P; var p P
t = 42; t = 42
t.P(); t.P()
t.V(); t.V()
v = t; v = t
v.V(); v.V()
p = &t; p = &t
p.P(); p.P()
p.V(); p.V()
v = &t; v = &t
v.V(); v.V()
// p = t; // ERROR // p = t; // ERROR
var i interface{} = t; var i interface{} = t
if _, ok := i.(P); ok { if _, ok := i.(P); ok {
panicln("dynamic i.(P) succeeded incorrectly"); println("dynamic i.(P) succeeded incorrectly")
panic("fail")
} }
// println("--struct--"); // println("--struct--");
var s S; var s S
s.T = 42; s.T = 42
s.P(); s.P()
s.V(); s.V()
v = s; v = s
s.V(); s.V()
p = &s; p = &s
p.P(); p.P()
p.V(); p.V()
v = &s; v = &s
v.V(); v.V()
// p = s; // ERROR // p = s; // ERROR
var j interface{} = s; var j interface{} = s
if _, ok := j.(P); ok { if _, ok := j.(P); ok {
panicln("dynamic j.(P) succeeded incorrectly"); println("dynamic j.(P) succeeded incorrectly")
panic("fail")
} }
// println("--struct pointer--"); // println("--struct pointer--");
var sp SP; var sp SP
sp.T = &t; sp.T = &t
sp.P(); sp.P()
sp.V(); sp.V()
v = sp; v = sp
sp.V(); sp.V()
p = &sp; p = &sp
p.P(); p.P()
p.V(); p.V()
v = &sp; v = &sp
v.V(); v.V()
p = sp; // not error p = sp // not error
p.P(); p.P()
p.V(); p.V()
if nv != 13 || np != 7 { if nv != 13 || np != 7 {
panicln("bad count", nv, np) println("bad count", nv, np)
panic("fail")
} }
} }
...@@ -8,47 +8,46 @@ package main ...@@ -8,47 +8,46 @@ package main
import "runtime" import "runtime"
const N = 1000; // sent messages const N = 1000 // sent messages
const M = 10; // receiving goroutines const M = 10 // receiving goroutines
const W = 2; // channel buffering const W = 2 // channel buffering
var h [N]int; // marking of send/recv var h [N]int // marking of send/recv
func func r(c chan int, m int) {
r(c chan int, m int) {
for { for {
select { select {
case r := <- c: case r := <-c:
if h[r] != 1 { if h[r] != 1 {
panicln("r", println("r",
"m=", m, "m=", m,
"r=", r, "r=", r,
"h=", h[r]); "h=", h[r])
panic("fail")
} }
h[r] = 2; h[r] = 2
} }
} }
} }
func func s(c chan int) {
s(c chan int) { for n := 0; n < N; n++ {
for n:=0; n<N; n++ { r := n
r := n;
if h[r] != 0 { if h[r] != 0 {
panicln("s"); println("s")
panic("fail")
} }
h[r] = 1; h[r] = 1
c <- r; c <- r
} }
} }
func func main() {
main() { c := make(chan int, W)
c := make(chan int, W); for m := 0; m < M; m++ {
for m:=0; m<M; m++ { go r(c, m)
go r(c, m); runtime.Gosched()
runtime.Gosched();
} }
runtime.Gosched(); runtime.Gosched()
runtime.Gosched(); runtime.Gosched()
s(c); s(c)
} }
...@@ -19,22 +19,26 @@ func main() { ...@@ -19,22 +19,26 @@ func main() {
// constants // constants
b = (5 + 6i) == C1 b = (5 + 6i) == C1
if !b { if !b {
panicln("const bool 1", b) println("const bool 1", b)
panic("fail")
} }
b = (5 + 6i) != C1 b = (5 + 6i) != C1
if b { if b {
panicln("const bool 2", b) println("const bool 2", b)
panic("fail")
} }
b = C1 == (5 + 6i) b = C1 == (5 + 6i)
if !b { if !b {
panicln("const bool 3", b) println("const bool 3", b)
panic("fail")
} }
b = C1 != (5 + 6i) b = C1 != (5 + 6i)
if b { if b {
panicln("const bool 4", b) println("const bool 4", b)
panic("fail")
} }
// vars passed through parameters // vars passed through parameters
...@@ -49,37 +53,45 @@ func booltest(a complex, r bool) { ...@@ -49,37 +53,45 @@ func booltest(a complex, r bool) {
b = a == C1 b = a == C1
if b != r { if b != r {
panicln("param bool 1", a, b, r) println("param bool 1", a, b, r)
panic("fail")
} }
b = a != C1 b = a != C1
if b == r { if b == r {
panicln("param bool 2", a, b, r) println("param bool 2", a, b, r)
panic("fail")
} }
b = C1 == a b = C1 == a
if b != r { if b != r {
panicln("param bool 3", a, b, r) println("param bool 3", a, b, r)
panic("fail")
} }
b = C1 != a b = C1 != a
if b == r { if b == r {
panicln("param bool 4", a, b, r) println("param bool 4", a, b, r)
panic("fail")
} }
if r { if r {
if a != C1 { if a != C1 {
panicln("param bool 5", a, b, r) println("param bool 5", a, b, r)
panic("fail")
} }
if C1 != a { if C1 != a {
panicln("param bool 6", a, b, r) println("param bool 6", a, b, r)
panic("fail")
} }
} else { } else {
if a == C1 { if a == C1 {
panicln("param bool 6", a, b, r) println("param bool 6", a, b, r)
panic("fail")
} }
if C1 == a { if C1 == a {
panicln("param bool 7", a, b, r) println("param bool 7", a, b, r)
panic("fail")
} }
} }
} }
...@@ -30,66 +30,79 @@ func main() { ...@@ -30,66 +30,79 @@ func main() {
r := 5 + 0i r := 5 + 0i
if r != R { if r != R {
panicln("opcode 1", r, R) println("opcode 1", r, R)
panic("fail")
} }
i := 6i i := 6i
if i != I { if i != I {
panicln("opcode 2", i, I) println("opcode 2", i, I)
panic("fail")
} }
c1 := r + i c1 := r + i
if c1 != C1 { if c1 != C1 {
panicln("opcode x", c1, C1) println("opcode x", c1, C1)
panic("fail")
} }
c2 := r - i c2 := r - i
if c2 != C2 { if c2 != C2 {
panicln("opcode x", c2, C2) println("opcode x", c2, C2)
panic("fail")
} }
c3 := -(r + i) c3 := -(r + i)
if c3 != C3 { if c3 != C3 {
panicln("opcode x", c3, C3) println("opcode x", c3, C3)
panic("fail")
} }
c4 := -(r - i) c4 := -(r - i)
if c4 != C4 { if c4 != C4 {
panicln("opcode x", c4, C4) println("opcode x", c4, C4)
panic("fail")
} }
c5 := c1 + r c5 := c1 + r
if c5 != C5 { if c5 != C5 {
panicln("opcode x", c5, C5) println("opcode x", c5, C5)
panic("fail")
} }
c6 := c1 + i c6 := c1 + i
if c6 != C6 { if c6 != C6 {
panicln("opcode x", c6, C6) println("opcode x", c6, C6)
panic("fail")
} }
ca := c5 + c6 ca := c5 + c6
if ca != Ca { if ca != Ca {
panicln("opcode x", ca, Ca) println("opcode x", ca, Ca)
panic("fail")
} }
cb := c5 - c6 cb := c5 - c6
if cb != Cb { if cb != Cb {
panicln("opcode x", cb, Cb) println("opcode x", cb, Cb)
panic("fail")
} }
cc := c5 * c6 cc := c5 * c6
if cc != Cc { if cc != Cc {
panicln("opcode x", cc, Cc) println("opcode x", cc, Cc)
panic("fail")
} }
cd := c5 / c6 cd := c5 / c6
if cd != Cd { if cd != Cd {
panicln("opcode x", cd, Cd) println("opcode x", cd, Cd)
panic("fail")
} }
ce := cd * c6 ce := cd * c6
if ce != Ce { if ce != Ce {
panicln("opcode x", ce, Ce) println("opcode x", ce, Ce)
panic("fail")
} }
} }
This diff is collapsed.
...@@ -6,205 +6,242 @@ ...@@ -6,205 +6,242 @@
package main package main
const const (
(
// example from the spec // example from the spec
n1 = +5; n1 = +5
n2 = -5; n2 = -5
d1 = +3; d1 = +3
d2 = -3; d2 = -3
q1 = +1; q1 = +1
q2 = -1; q2 = -1
q3 = -1; q3 = -1
q4 = +1; q4 = +1
r1 = +2; r1 = +2
r2 = -2; r2 = -2
r3 = +2; r3 = +2
r4 = -2; r4 = -2
) )
func func main() {
main() {
/* ideals */ /* ideals */
if n1/d1 != q1 || n1%d1 != r1 { if n1/d1 != q1 || n1%d1 != r1 {
panicln("ideal-1", n1, d1, n1/d1, n1%d1); println("ideal-1", n1, d1, n1/d1, n1%d1)
panic("fail")
} }
if n2/d1 != q2 || n2%d1 != r2 { if n2/d1 != q2 || n2%d1 != r2 {
panicln("ideal-2", n2, d1, n2/d1, n2%d1); println("ideal-2", n2, d1, n2/d1, n2%d1)
panic("fail")
} }
if n1/d2 != q3 || n1%d2 != r3 { if n1/d2 != q3 || n1%d2 != r3 {
panicln("ideal-3", n1, d2, n1/d2, n1%d2); println("ideal-3", n1, d2, n1/d2, n1%d2)
panic("fail")
} }
if n2/d2 != q4 || n2%d2 != r4 { if n2/d2 != q4 || n2%d2 != r4 {
panicln("ideal-4", n2, d2, n2/d2, n2%d2); println("ideal-4", n2, d2, n2/d2, n2%d2)
panic("fail")
} }
/* int */ /* int */
var in1 int = +5; var in1 int = +5
var in2 int = -5; var in2 int = -5
var id1 int = +3; var id1 int = +3
var id2 int = -3; var id2 int = -3
if in1/id1 != q1 || in1%id1 != r1 { if in1/id1 != q1 || in1%id1 != r1 {
panicln("int-1", in1, id1, in1/id1, in1%id1); println("int-1", in1, id1, in1/id1, in1%id1)
panic("fail")
} }
if in2/id1 != q2 || in2%id1 != r2 { if in2/id1 != q2 || in2%id1 != r2 {
panicln("int-2", in2, id1, in2/id1, in2%id1); println("int-2", in2, id1, in2/id1, in2%id1)
panic("fail")
} }
if in1/id2 != q3 || in1%id2 != r3 { if in1/id2 != q3 || in1%id2 != r3 {
panicln("int-3", in1, id2, in1/id2, in1%id2); println("int-3", in1, id2, in1/id2, in1%id2)
panic("fail")
} }
if in2/id2 != q4 || in2%id2 != r4 { if in2/id2 != q4 || in2%id2 != r4 {
panicln("int-4", in2, id2, in2/id2, in2%id2); println("int-4", in2, id2, in2/id2, in2%id2)
panic("fail")
} }
/* int8 */ /* int8 */
var bn1 int8 = +5; var bn1 int8 = +5
var bn2 int8 = -5; var bn2 int8 = -5
var bd1 int8 = +3; var bd1 int8 = +3
var bd2 int8 = -3; var bd2 int8 = -3
if bn1/bd1 != q1 || bn1%bd1 != r1 { if bn1/bd1 != q1 || bn1%bd1 != r1 {
panicln("int8-1", bn1, bd1, bn1/bd1, bn1%bd1); println("int8-1", bn1, bd1, bn1/bd1, bn1%bd1)
panic("fail")
} }
if bn2/bd1 != q2 || bn2%bd1 != r2 { if bn2/bd1 != q2 || bn2%bd1 != r2 {
panicln("int8-2", bn2, bd1, bn2/bd1, bn2%bd1); println("int8-2", bn2, bd1, bn2/bd1, bn2%bd1)
panic("fail")
} }
if bn1/bd2 != q3 || bn1%bd2 != r3 { if bn1/bd2 != q3 || bn1%bd2 != r3 {
panicln("int8-3", bn1, bd2, bn1/bd2, bn1%bd2); println("int8-3", bn1, bd2, bn1/bd2, bn1%bd2)
panic("fail")
} }
if bn2/bd2 != q4 || bn2%bd2 != r4 { if bn2/bd2 != q4 || bn2%bd2 != r4 {
panicln("int8-4", bn2, bd2, bn2/bd2, bn2%bd2); println("int8-4", bn2, bd2, bn2/bd2, bn2%bd2)
panic("fail")
} }
/* int16 */ /* int16 */
var sn1 int16 = +5; var sn1 int16 = +5
var sn2 int16 = -5; var sn2 int16 = -5
var sd1 int16 = +3; var sd1 int16 = +3
var sd2 int16 = -3; var sd2 int16 = -3
if sn1/sd1 != q1 || sn1%sd1 != r1 { if sn1/sd1 != q1 || sn1%sd1 != r1 {
panicln("int16-1", sn1, sd1, sn1/sd1, sn1%sd1); println("int16-1", sn1, sd1, sn1/sd1, sn1%sd1)
panic("fail")
} }
if sn2/sd1 != q2 || sn2%sd1 != r2 { if sn2/sd1 != q2 || sn2%sd1 != r2 {
panicln("int16-2", sn2, sd1, sn2/sd1, sn2%sd1); println("int16-2", sn2, sd1, sn2/sd1, sn2%sd1)
panic("fail")
} }
if sn1/sd2 != q3 || sn1%sd2 != r3 { if sn1/sd2 != q3 || sn1%sd2 != r3 {
panicln("int16-3", sn1, sd2, sn1/sd2, sn1%sd2); println("int16-3", sn1, sd2, sn1/sd2, sn1%sd2)
panic("fail")
} }
if sn2/sd2 != q4 || sn2%sd2 != r4 { if sn2/sd2 != q4 || sn2%sd2 != r4 {
panicln("int16-4", sn2, sd2, sn2/sd2, sn2%sd2); println("int16-4", sn2, sd2, sn2/sd2, sn2%sd2)
panic("fail")
} }
/* int32 */ /* int32 */
var ln1 int32 = +5; var ln1 int32 = +5
var ln2 int32 = -5; var ln2 int32 = -5
var ld1 int32 = +3; var ld1 int32 = +3
var ld2 int32 = -3; var ld2 int32 = -3
if ln1/ld1 != q1 || ln1%ld1 != r1 { if ln1/ld1 != q1 || ln1%ld1 != r1 {
panicln("int32-1", ln1, ld1, ln1/ld1, ln1%ld1); println("int32-1", ln1, ld1, ln1/ld1, ln1%ld1)
panic("fail")
} }
if ln2/ld1 != q2 || ln2%ld1 != r2 { if ln2/ld1 != q2 || ln2%ld1 != r2 {
panicln("int32-2", ln2, ld1, ln2/ld1, ln2%ld1); println("int32-2", ln2, ld1, ln2/ld1, ln2%ld1)
panic("fail")
} }
if ln1/ld2 != q3 || ln1%ld2 != r3 { if ln1/ld2 != q3 || ln1%ld2 != r3 {
panicln("int32-3", ln1, ld2, ln1/ld2, ln1%ld2); println("int32-3", ln1, ld2, ln1/ld2, ln1%ld2)
panic("fail")
} }
if ln2/ld2 != q4 || ln2%ld2 != r4 { if ln2/ld2 != q4 || ln2%ld2 != r4 {
panicln("int32-4", ln2, ld2, ln2/ld2, ln2%ld2); println("int32-4", ln2, ld2, ln2/ld2, ln2%ld2)
panic("fail")
} }
/* int64 */ /* int64 */
var qn1 int64 = +5; var qn1 int64 = +5
var qn2 int64 = -5; var qn2 int64 = -5
var qd1 int64 = +3; var qd1 int64 = +3
var qd2 int64 = -3; var qd2 int64 = -3
if qn1/qd1 != q1 || qn1%qd1 != r1 { if qn1/qd1 != q1 || qn1%qd1 != r1 {
panicln("int64-1", qn1, qd1, qn1/qd1, qn1%qd1); println("int64-1", qn1, qd1, qn1/qd1, qn1%qd1)
panic("fail")
} }
if qn2/qd1 != q2 || qn2%qd1 != r2 { if qn2/qd1 != q2 || qn2%qd1 != r2 {
panicln("int64-2", qn2, qd1, qn2/qd1, qn2%qd1); println("int64-2", qn2, qd1, qn2/qd1, qn2%qd1)
panic("fail")
} }
if qn1/qd2 != q3 || qn1%qd2 != r3 { if qn1/qd2 != q3 || qn1%qd2 != r3 {
panicln("int64-3", qn1, qd2, qn1/qd2, qn1%qd2); println("int64-3", qn1, qd2, qn1/qd2, qn1%qd2)
panic("fail")
} }
if qn2/qd2 != q4 || qn2%qd2 != r4 { if qn2/qd2 != q4 || qn2%qd2 != r4 {
panicln("int64-4", qn2, qd2, qn2/qd2, qn2%qd2); println("int64-4", qn2, qd2, qn2/qd2, qn2%qd2)
panic("fail")
} }
if n1/qd1 != q1 || n1%qd1 != r1 { if n1/qd1 != q1 || n1%qd1 != r1 {
panicln("mixed int64-1", n1, qd1, n1/qd1, n1%qd1); println("mixed int64-1", n1, qd1, n1/qd1, n1%qd1)
panic("fail")
} }
if n2/qd1 != q2 || n2%qd1 != r2 { if n2/qd1 != q2 || n2%qd1 != r2 {
panicln("mixed int64-2", n2, qd1, n2/qd1, n2%qd1); println("mixed int64-2", n2, qd1, n2/qd1, n2%qd1)
panic("fail")
} }
if n1/qd2 != q3 || n1%qd2 != r3 { if n1/qd2 != q3 || n1%qd2 != r3 {
panicln("mixed int64-3", n1, qd2, n1/qd2, n1%qd2); println("mixed int64-3", n1, qd2, n1/qd2, n1%qd2)
panic("fail")
} }
if n2/qd2 != q4 || n2%qd2 != r4 { if n2/qd2 != q4 || n2%qd2 != r4 {
panicln("mixed int64-4", n2, qd2, n2/qd2, n2%qd2); println("mixed int64-4", n2, qd2, n2/qd2, n2%qd2)
panic("fail")
} }
if qn1/d1 != q1 || qn1%d1 != r1 { if qn1/d1 != q1 || qn1%d1 != r1 {
panicln("mixed int64-5", qn1, d1, qn1/d1, qn1%d1); println("mixed int64-5", qn1, d1, qn1/d1, qn1%d1)
panic("fail")
} }
if qn2/d1 != q2 || qn2%d1 != r2 { if qn2/d1 != q2 || qn2%d1 != r2 {
panicln("mixed int64-6", qn2, d1, qn2/d1, qn2%d1); println("mixed int64-6", qn2, d1, qn2/d1, qn2%d1)
panic("fail")
} }
if qn1/d2 != q3 || qn1%d2 != r3 { if qn1/d2 != q3 || qn1%d2 != r3 {
panicln("mixed int64-7", qn1, d2, qn1/d2, qn1%d2); println("mixed int64-7", qn1, d2, qn1/d2, qn1%d2)
panic("fail")
} }
if qn2/d2 != q4 || qn2%d2 != r4 { if qn2/d2 != q4 || qn2%d2 != r4 {
panicln("mixed int64-8", qn2, d2, qn2/d2, qn2%d2); println("mixed int64-8", qn2, d2, qn2/d2, qn2%d2)
panic("fail")
} }
/* uint */ /* uint */
var uin1 uint = +5; var uin1 uint = +5
var uid1 uint = +3; var uid1 uint = +3
if uin1/uid1 != q1 || uin1%uid1 != r1 { if uin1/uid1 != q1 || uin1%uid1 != r1 {
panicln("uint", uin1, uid1, uin1/uid1, uin1%uid1); println("uint", uin1, uid1, uin1/uid1, uin1%uid1)
panic("fail")
} }
/* uint8 */ /* uint8 */
var ubn1 uint8 = +5; var ubn1 uint8 = +5
var ubd1 uint8 = +3; var ubd1 uint8 = +3
if ubn1/ubd1 != q1 || ubn1%ubd1 != r1 { if ubn1/ubd1 != q1 || ubn1%ubd1 != r1 {
panicln("uint8", ubn1, ubd1, ubn1/ubd1, ubn1%ubd1); println("uint8", ubn1, ubd1, ubn1/ubd1, ubn1%ubd1)
panic("fail")
} }
/* uint16 */ /* uint16 */
var usn1 uint16 = +5; var usn1 uint16 = +5
var usd1 uint16 = +3; var usd1 uint16 = +3
if usn1/usd1 != q1 || usn1%usd1 != r1 { if usn1/usd1 != q1 || usn1%usd1 != r1 {
panicln("uint16", usn1, usd1, usn1/usd1, usn1%usd1); println("uint16", usn1, usd1, usn1/usd1, usn1%usd1)
panic("fail")
} }
/* uint32 */ /* uint32 */
var uln1 uint32 = +5; var uln1 uint32 = +5
var uld1 uint32 = +3; var uld1 uint32 = +3
if uln1/uld1 != q1 || uln1%uld1 != r1 { if uln1/uld1 != q1 || uln1%uld1 != r1 {
panicln("uint32", uln1, uld1, uln1/uld1, uln1%uld1); println("uint32", uln1, uld1, uln1/uld1, uln1%uld1)
panic("fail")
} }
/* uint64 */ /* uint64 */
var uqn1 uint64 = +5; var uqn1 uint64 = +5
var uqd1 uint64 = +3; var uqd1 uint64 = +3
if uqn1/uqd1 != q1 || uqn1%uqd1 != r1 { if uqn1/uqd1 != q1 || uqn1%uqd1 != r1 {
panicln("uint64", uqn1, uqd1, uqn1/uqd1, uqn1%uqd1); println("uint64", uqn1, uqd1, uqn1/uqd1, uqn1%uqd1)
panic("fail")
} }
if n1/uqd1 != q1 || n1%uqd1 != r1 { if n1/uqd1 != q1 || n1%uqd1 != r1 {
panicln("mixed uint64-1", n1, uqd1, n1/uqd1, n1%uqd1); println("mixed uint64-1", n1, uqd1, n1/uqd1, n1%uqd1)
panic("fail")
} }
if uqn1/d1 != q1 || uqn1%d1 != r1 { if uqn1/d1 != q1 || uqn1%d1 != r1 {
panicln("mixed uint64-2", uqn1, d1, uqn1/d1, uqn1%d1); println("mixed uint64-2", uqn1, d1, uqn1/d1, uqn1%d1)
panic("fail")
} }
} }
...@@ -7,63 +7,67 @@ ...@@ -7,63 +7,67 @@
package main package main
type type I interface {
I interface { test1() int
test1() int; test2() int
test2() int; test3() int
test3() int; test4() int
test4() int; test5() int
test5() int; test6() int
test6() int; test7() int
test7() int; }
};
/****** /******
****** ******
******/ ******/
type type SubpSubp struct {
SubpSubp struct { a7 int
a7 int; a int
a int;
} }
func (p *SubpSubp) test7() int { func (p *SubpSubp) test7() int {
if p.a != p.a7 { panicln("SubpSubp", p, p.a7) } if p.a != p.a7 {
println("SubpSubp", p, p.a7)
panic("fail")
}
return p.a return p.a
} }
func (p *SubpSubp) testx() { func (p *SubpSubp) testx() { println("SubpSubp", p, p.a7) }
println("SubpSubp", p, p.a7);
}
/****** /******
****** ******
******/ ******/
type type SubpSub struct {
SubpSub struct { a6 int
a6 int; SubpSubp
SubpSubp; a int
a int;
} }
func (p *SubpSub) test6() int { func (p *SubpSub) test6() int {
if p.a != p.a6 { panicln("SubpSub", p, p.a6) } if p.a != p.a6 {
println("SubpSub", p, p.a6)
panic("fail")
}
return p.a return p.a
} }
func (p *SubpSub) testx() { func (p *SubpSub) testx() { println("SubpSub", p, p.a6) }
println("SubpSub", p, p.a6);
}
/****** /******
****** ******
******/ ******/
type type SubSubp struct {
SubSubp struct { a5 int
a5 int; a int
a int;
} }
func (p *SubSubp) test5() int { func (p *SubSubp) test5() int {
if p.a != p.a5 { panicln("SubpSub", p, p.a5) } if p.a != p.a5 {
println("SubpSub", p, p.a5)
panic("fail")
}
return p.a return p.a
} }
...@@ -71,13 +75,16 @@ func (p *SubSubp) test5() int { ...@@ -71,13 +75,16 @@ func (p *SubSubp) test5() int {
****** ******
******/ ******/
type type SubSub struct {
SubSub struct { a4 int
a4 int; a int
a int;
} }
func (p *SubSub) test4() int { func (p *SubSub) test4() int {
if p.a != p.a4 { panicln("SubpSub", p, p.a4) } if p.a != p.a4 {
println("SubpSub", p, p.a4)
panic("fail")
}
return p.a return p.a
} }
...@@ -85,15 +92,18 @@ func (p *SubSub) test4() int { ...@@ -85,15 +92,18 @@ func (p *SubSub) test4() int {
****** ******
******/ ******/
type type Subp struct {
Subp struct { a3 int
a3 int; *SubpSubp
*SubpSubp; SubpSub
SubpSub; a int
a int;
} }
func (p *Subp) test3() int { func (p *Subp) test3() int {
if p.a != p.a3 { panicln("SubpSub", p, p.a3) } if p.a != p.a3 {
println("SubpSub", p, p.a3)
panic("fail")
}
return p.a return p.a
} }
...@@ -101,16 +111,18 @@ func (p *Subp) test3() int { ...@@ -101,16 +111,18 @@ func (p *Subp) test3() int {
****** ******
******/ ******/
type type Sub struct {
Sub struct a2 int
{ *SubSubp
a2 int; SubSub
*SubSubp; a int
SubSub;
a int;
} }
func (p *Sub) test2() int { func (p *Sub) test2() int {
if p.a != p.a2 { panicln("SubpSub", p, p.a2) } if p.a != p.a2 {
println("SubpSub", p, p.a2)
panic("fail")
}
return p.a return p.a
} }
...@@ -118,15 +130,18 @@ func (p *Sub) test2() int { ...@@ -118,15 +130,18 @@ func (p *Sub) test2() int {
****** ******
******/ ******/
type type S struct {
S struct { a1 int
a1 int; Sub
Sub; *Subp
*Subp; a int
a int;
} }
func (p *S) test1() int { func (p *S) test1() int {
if p.a != p.a1 { panicln("SubpSub", p, p.a1) } if p.a != p.a1 {
println("SubpSub", p, p.a1)
panic("fail")
}
return p.a return p.a
} }
...@@ -134,77 +149,169 @@ func (p *S) test1() int { ...@@ -134,77 +149,169 @@ func (p *S) test1() int {
****** ******
******/ ******/
func func main() {
main() { var i I
var i I; var s *S
var s *S;
// allocate // allocate
s = new(S); s = new(S)
s.Subp = new(Subp); s.Subp = new(Subp)
s.Sub.SubSubp = new(SubSubp); s.Sub.SubSubp = new(SubSubp)
s.Subp.SubpSubp = new(SubpSubp); s.Subp.SubpSubp = new(SubpSubp)
// explicit assignment // explicit assignment
s.a = 1; s.a = 1
s.Sub.a = 2; s.Sub.a = 2
s.Subp.a = 3; s.Subp.a = 3
s.Sub.SubSub.a = 4; s.Sub.SubSub.a = 4
s.Sub.SubSubp.a = 5; s.Sub.SubSubp.a = 5
s.Subp.SubpSub.a = 6; s.Subp.SubpSub.a = 6
s.Subp.SubpSubp.a = 7; s.Subp.SubpSubp.a = 7
// embedded (unique) assignment // embedded (unique) assignment
s.a1 = 1; s.a1 = 1
s.a2 = 2; s.a2 = 2
s.a3 = 3; s.a3 = 3
s.a4 = 4; s.a4 = 4
s.a5 = 5; s.a5 = 5
s.a6 = 6; s.a6 = 6
s.a7 = 7; s.a7 = 7
// unique calls with explicit & // unique calls with explicit &
if s.test1() != 1 { panicln("t1", 1) } if s.test1() != 1 {
if (&s.Sub).test2() != 2 { panicln("t1", 2) } println("t1", 1)
if s.Subp.test3() != 3 { panicln("t1", 3) } panic("fail")
if (&s.Sub.SubSub).test4() != 4 { panicln("t1", 4) } }
if s.Sub.SubSubp.test5() != 5 { panicln("t1", 5) } if (&s.Sub).test2() != 2 {
if (&s.Subp.SubpSub).test6() != 6 { panicln("t1", 6) } println("t1", 2)
if s.Subp.SubpSubp.test7() != 7 { panicln("t1", 7) } panic("fail")
}
if s.Subp.test3() != 3 {
println("t1", 3)
panic("fail")
}
if (&s.Sub.SubSub).test4() != 4 {
println("t1", 4)
panic("fail")
}
if s.Sub.SubSubp.test5() != 5 {
println("t1", 5)
panic("fail")
}
if (&s.Subp.SubpSub).test6() != 6 {
println("t1", 6)
panic("fail")
}
if s.Subp.SubpSubp.test7() != 7 {
println("t1", 7)
panic("fail")
}
// automatic & // automatic &
if s.Sub.test2() != 2 { panicln("t2", 2) } if s.Sub.test2() != 2 {
if s.Sub.SubSub.test4() != 4 { panicln("t2", 4) } println("t2", 2)
if s.Subp.SubpSub.test6() != 6 { panicln("t2", 6) } panic("fail")
}
if s.Sub.SubSub.test4() != 4 {
println("t2", 4)
panic("fail")
}
if s.Subp.SubpSub.test6() != 6 {
println("t2", 6)
panic("fail")
}
// embedded calls // embedded calls
if s.test1() != s.a1 { panicln("t3", 1) } if s.test1() != s.a1 {
if s.test2() != s.a2 { panicln("t3", 2) } println("t3", 1)
if s.test3() != s.a3 { panicln("t3", 3) } panic("fail")
if s.test4() != s.a4 { panicln("t3", 4) } }
if s.test5() != s.a5 { panicln("t3", 5) } if s.test2() != s.a2 {
if s.test6() != s.a6 { panicln("t3", 6) } println("t3", 2)
if s.test7() != s.a7 { panicln("t3", 7) } panic("fail")
}
if s.test3() != s.a3 {
println("t3", 3)
panic("fail")
}
if s.test4() != s.a4 {
println("t3", 4)
panic("fail")
}
if s.test5() != s.a5 {
println("t3", 5)
panic("fail")
}
if s.test6() != s.a6 {
println("t3", 6)
panic("fail")
}
if s.test7() != s.a7 {
println("t3", 7)
panic("fail")
}
// run it thru an interface // run it thru an interface
i = s; i = s
s = i.(*S); s = i.(*S)
// same as t3 // same as t3
if s.test1() != s.a1 { panicln("t4", 1) } if s.test1() != s.a1 {
if s.test2() != s.a2 { panicln("t4", 2) } println("t4", 1)
if s.test3() != s.a3 { panicln("t4", 3) } panic("fail")
if s.test4() != s.a4 { panicln("t4", 4) } }
if s.test5() != s.a5 { panicln("t4", 5) } if s.test2() != s.a2 {
if s.test6() != s.a6 { panicln("t4", 6) } println("t4", 2)
if s.test7() != s.a7 { panicln("t4", 7) } panic("fail")
}
if s.test3() != s.a3 {
println("t4", 3)
panic("fail")
}
if s.test4() != s.a4 {
println("t4", 4)
panic("fail")
}
if s.test5() != s.a5 {
println("t4", 5)
panic("fail")
}
if s.test6() != s.a6 {
println("t4", 6)
panic("fail")
}
if s.test7() != s.a7 {
println("t4", 7)
panic("fail")
}
// call interface // call interface
if i.test1() != s.test1() { panicln("t5", 1) } if i.test1() != s.test1() {
if i.test2() != s.test2() { panicln("t5", 2) } println("t5", 1)
if i.test3() != s.test3() { panicln("t5", 3) } panic("fail")
if i.test4() != s.test4() { panicln("t5", 4) } }
if i.test5() != s.test5() { panicln("t5", 5) } if i.test2() != s.test2() {
if i.test6() != s.test6() { panicln("t5", 6) } println("t5", 2)
if i.test7() != s.test7() { panicln("t5", 7) } panic("fail")
}
if i.test3() != s.test3() {
println("t5", 3)
panic("fail")
}
if i.test4() != s.test4() {
println("t5", 4)
panic("fail")
}
if i.test5() != s.test5() {
println("t5", 5)
panic("fail")
}
if i.test6() != s.test6() {
println("t5", 6)
panic("fail")
}
if i.test7() != s.test7() {
println("t5", 7)
panic("fail")
}
} }
...@@ -6,98 +6,177 @@ ...@@ -6,98 +6,177 @@
package main package main
type myint int; type myint int
type mystring string; type mystring string
type I0 interface {}; type I0 interface{}
func func f() {
f() { var ia, ib I0
var ia, ib I0; var i myint
var i myint; var s mystring
var s mystring;
if ia != ib {
if ia != ib { panicln("1"); } panic("1")
}
i = 1;
ia = i; i = 1
ib = i; ia = i
if ia != ib { panicln("2"); } ib = i
if ia == nil { panicln("3"); } if ia != ib {
panic("2")
i = 2; }
ia = i; if ia == nil {
if ia == ib { panicln("4"); } panic("3")
}
ia = nil;
if ia == ib { panicln("5"); } i = 2
ia = i
ib = nil; if ia == ib {
if ia != ib { panicln("6"); } panic("4")
}
if ia != nil { panicln("7"); }
ia = nil
s = "abc"; if ia == ib {
ia = s; panic("5")
ib = nil; }
if ia == ib { panicln("8"); }
ib = nil
s = "def"; if ia != ib {
ib = s; panic("6")
if ia == ib { panicln("9"); } }
s = "abc"; if ia != nil {
ib = s; panic("7")
if ia != ib { panicln("a"); } }
s = "abc"
ia = s
ib = nil
if ia == ib {
panic("8")
}
s = "def"
ib = s
if ia == ib {
panic("9")
}
s = "abc"
ib = s
if ia != ib {
panic("a")
}
} }
func func main() {
main() { var ia [20]I0
var ia [20]I0; var b bool
var b bool; var s string
var s string; var i8 int8
var i8 int8; var i16 int16
var i16 int16; var i32 int32
var i32 int32; var i64 int64
var i64 int64; var u8 uint8
var u8 uint8; var u16 uint16
var u16 uint16; var u32 uint32
var u32 uint32; var u64 uint64
var u64 uint64;
f()
f();
ia[0] = "xxx"
ia[0] = "xxx"; ia[1] = 12345
ia[1] = 12345; ia[2] = true
ia[2] = true;
s = "now is"
s = "now is"; ia[3] = s; ia[3] = s
b = false; ia[4] = b; b = false
ia[4] = b
i8 = 29; ia[5] = i8;
i16 = 994; ia[6] = i16; i8 = 29
i32 = 3434; ia[7] = i32; ia[5] = i8
i64 = 1234567; ia[8] = i64; i16 = 994
ia[6] = i16
u8 = 12; ia[9] = u8; i32 = 3434
u16 = 799; ia[10] = u16; ia[7] = i32
u32 = 4455; ia[11] = u32; i64 = 1234567
u64 = 765432; ia[12] = u64; ia[8] = i64
s = ia[0].(string); if s != "xxx" { panicln(0,s); } u8 = 12
i32 = int32(ia[1].(int)); ia[9] = u8
if i32 != 12345 { panicln(1,i32); } u16 = 799
b = ia[2].(bool); if b != true { panicln(2,b); } ia[10] = u16
u32 = 4455
s = ia[3].(string); if s != "now is" { panicln(3,s); } ia[11] = u32
b = ia[4].(bool); if b != false { panicln(4,b); } u64 = 765432
ia[12] = u64
i8 = ia[5].(int8); if i8 != 29 { panicln(5,i8); }
i16 = ia[6].(int16); if i16 != 994 { panicln(6,i16); } s = ia[0].(string)
i32 = ia[7].(int32); if i32 != 3434 { panicln(7,i32); } if s != "xxx" {
i64 = ia[8].(int64); if i64 != 1234567 { panicln(8,i64); } println(0, s)
panic("fail")
u8 = ia[9].(uint8); if u8 != 12 { panicln(5,u8); } }
u16 = ia[10].(uint16); if u16 != 799 { panicln(6,u16); } i32 = int32(ia[1].(int))
u32 = ia[11].(uint32); if u32 != 4455 { panicln(7,u32); } if i32 != 12345 {
u64 = ia[12].(uint64); if u64 != 765432 { panicln(8,u64); } println(1, i32)
panic("fail")
}
b = ia[2].(bool)
if b != true {
println(2, b)
panic("fail")
}
s = ia[3].(string)
if s != "now is" {
println(3, s)
panic("fail")
}
b = ia[4].(bool)
if b != false {
println(4, b)
panic("fail")
}
i8 = ia[5].(int8)
if i8 != 29 {
println(5, i8)
panic("fail")
}
i16 = ia[6].(int16)
if i16 != 994 {
println(6, i16)
panic("fail")
}
i32 = ia[7].(int32)
if i32 != 3434 {
println(7, i32)
panic("fail")
}
i64 = ia[8].(int64)
if i64 != 1234567 {
println(8, i64)
panic("fail")
}
u8 = ia[9].(uint8)
if u8 != 12 {
println(5, u8)
panic("fail")
}
u16 = ia[10].(uint16)
if u16 != 799 {
println(6, u16)
panic("fail")
}
u32 = ia[11].(uint32)
if u32 != 4455 {
println(7, u32)
panic("fail")
}
u64 = ia[12].(uint64)
if u64 != 765432 {
println(8, u64)
panic("fail")
}
} }
This diff is collapsed.
...@@ -6,105 +6,114 @@ ...@@ -6,105 +6,114 @@
package main package main
const size = 16; const size = 16
var a [size]byte; var a [size]byte
var p []byte; var p []byte
var m map[int]byte; var m map[int]byte
func func f(k int) byte {
f(k int) byte { return byte(k * 10007 % size)
return byte(k*10007 % size);
} }
func func init() {
init() { p = make([]byte, size)
p = make([]byte, size); m = make(map[int]byte)
m = make(map[int]byte); for k := 0; k < size; k++ {
for k:=0; k<size; k++ { v := f(k)
v := f(k); a[k] = v
a[k] = v; p[k] = v
p[k] = v; m[k] = v
m[k] = v;
} }
} }
func func main() {
main() { var i int
var i int;
/* /*
* key only * key only
*/ */
i = 0; i = 0
for k := range a { for k := range a {
v := a[k]; v := a[k]
if v != f(k) { if v != f(k) {
panicln("key array range", k, v, a[k]); println("key array range", k, v, a[k])
panic("fail")
} }
i++; i++
} }
if i != size { if i != size {
panicln("key array size", i); println("key array size", i)
panic("fail")
} }
i = 0; i = 0
for k := range p { for k := range p {
v := p[k]; v := p[k]
if v != f(k) { if v != f(k) {
panicln("key pointer range", k, v, p[k]); println("key pointer range", k, v, p[k])
panic("fail")
} }
i++; i++
} }
if i != size { if i != size {
panicln("key pointer size", i); println("key pointer size", i)
panic("fail")
} }
i = 0; i = 0
for k := range m { for k := range m {
v := m[k]; v := m[k]
if v != f(k) { if v != f(k) {
panicln("key map range", k, v, m[k]); println("key map range", k, v, m[k])
panic("fail")
} }
i++; i++
} }
if i != size { if i != size {
panicln("key map size", i); println("key map size", i)
panic("fail")
} }
/* /*
* key,value * key,value
*/ */
i = 0; i = 0
for k,v := range a { for k, v := range a {
if v != f(k) { if v != f(k) {
panicln("key:value array range", k, v, a[k]); println("key:value array range", k, v, a[k])
panic("fail")
} }
i++; i++
} }
if i != size { if i != size {
panicln("key:value array size", i); println("key:value array size", i)
panic("fail")
} }
i = 0; i = 0
for k,v := range p { for k, v := range p {
if v != f(k) { if v != f(k) {
panicln("key:value pointer range", k, v, p[k]); println("key:value pointer range", k, v, p[k])
panic("fail")
} }
i++; i++
} }
if i != size { if i != size {
panicln("key:value pointer size", i); println("key:value pointer size", i)
panic("fail")
} }
i = 0; i = 0
for k,v := range m { for k, v := range m {
if v != f(k) { if v != f(k) {
panicln("key:value map range", k, v, m[k]); println("key:value map range", k, v, m[k])
panic("fail")
} }
i++; i++
} }
if i != size { if i != size {
panicln("key:value map size", i); println("key:value map size", i)
panic("fail")
} }
} }
This diff is collapsed.
This diff is collapsed.
...@@ -27,14 +27,16 @@ var final [N]int ...@@ -27,14 +27,16 @@ var final [N]int
func finalA(a *A) { func finalA(a *A) {
if final[a.n] != 0 { if final[a.n] != 0 {
panicln("finalA", a.n, final[a.n]) println("finalA", a.n, final[a.n])
panic("fail")
} }
final[a.n] = 1 final[a.n] = 1
} }
func finalB(b *B) { func finalB(b *B) {
if final[b.n] != 1 { if final[b.n] != 1 {
panicln("finalB", b.n, final[b.n]) println("finalB", b.n, final[b.n])
panic("fail")
} }
final[b.n] = 2 final[b.n] = 2
nfinal++ nfinal++
......
...@@ -27,7 +27,8 @@ func bigger() { ...@@ -27,7 +27,8 @@ func bigger() {
println("Footprint", footprint, " for ", allocated) println("Footprint", footprint, " for ", allocated)
} }
if footprint > 1e9 { if footprint > 1e9 {
panicln("too big") println("too big")
panic("fail")
} }
} }
} }
...@@ -77,7 +78,8 @@ func main() { ...@@ -77,7 +78,8 @@ func main() {
// ptr := uintptr(syscall.BytePtr(base))+uintptr(siz/2); // ptr := uintptr(syscall.BytePtr(base))+uintptr(siz/2);
// obj, size, ref, ok := allocator.find(ptr); // obj, size, ref, ok := allocator.find(ptr);
// if obj != base || *ref != 0 || !ok { // if obj != base || *ref != 0 || !ok {
// panicln("find", siz, obj, ref, ok); // println("find", siz, obj, ref, ok)
// panic("fail")
// } // }
blocks[b].base = base blocks[b].base = base
blocks[b].siz = siz blocks[b].siz = siz
......
...@@ -24,7 +24,8 @@ func bigger() { ...@@ -24,7 +24,8 @@ func bigger() {
println(st.Sys, " system bytes for ", st.Alloc, " Go bytes") println(st.Sys, " system bytes for ", st.Alloc, " Go bytes")
} }
if st.Sys > 1e9 { if st.Sys > 1e9 {
panicln("too big") println("too big")
panic("fail")
} }
} }
} }
...@@ -39,7 +40,8 @@ func main() { ...@@ -39,7 +40,8 @@ func main() {
println("First alloc:", j) println("First alloc:", j)
} }
if a := runtime.MemStats.Alloc; a != 0 { if a := runtime.MemStats.Alloc; a != 0 {
panicln("no allocations but stats report", a, "bytes allocated") println("no allocations but stats report", a, "bytes allocated")
panic("fail")
} }
b := runtime.Alloc(uintptr(j)) b := runtime.Alloc(uintptr(j))
during := runtime.MemStats.Alloc during := runtime.MemStats.Alloc
......
...@@ -47,10 +47,12 @@ func AllocAndFree(size, count int) { ...@@ -47,10 +47,12 @@ func AllocAndFree(size, count int) {
b[i] = runtime.Alloc(uintptr(size)) b[i] = runtime.Alloc(uintptr(size))
base, n := runtime.Lookup(b[i]) base, n := runtime.Lookup(b[i])
if base != b[i] || !OkAmount(uintptr(size), n) { if base != b[i] || !OkAmount(uintptr(size), n) {
panicln("lookup failed: got", base, n, "for", b[i]) println("lookup failed: got", base, n, "for", b[i])
panic("fail")
} }
if runtime.MemStats.Sys > 1e9 { if runtime.MemStats.Sys > 1e9 {
panicln("too much memory allocated") println("too much memory allocated")
panic("fail")
} }
} }
n2 := stats.Alloc n2 := stats.Alloc
...@@ -66,14 +68,17 @@ func AllocAndFree(size, count int) { ...@@ -66,14 +68,17 @@ func AllocAndFree(size, count int) {
alloc := uintptr(stats.Alloc) alloc := uintptr(stats.Alloc)
base, n := runtime.Lookup(b[i]) base, n := runtime.Lookup(b[i])
if base != b[i] || !OkAmount(uintptr(size), n) { if base != b[i] || !OkAmount(uintptr(size), n) {
panicln("lookup failed: got", base, n, "for", b[i]) println("lookup failed: got", base, n, "for", b[i])
panic("fail")
} }
runtime.Free(b[i]) runtime.Free(b[i])
if stats.Alloc != uint64(alloc-n) { if stats.Alloc != uint64(alloc-n) {
panicln("free alloc got", stats.Alloc, "expected", alloc-n, "after free of", n) println("free alloc got", stats.Alloc, "expected", alloc-n, "after free of", n)
panic("fail")
} }
if runtime.MemStats.Sys > 1e9 { if runtime.MemStats.Sys > 1e9 {
panicln("too much memory allocated") println("too much memory allocated")
panic("fail")
} }
} }
n4 := stats.Alloc n4 := stats.Alloc
...@@ -82,7 +87,8 @@ func AllocAndFree(size, count int) { ...@@ -82,7 +87,8 @@ func AllocAndFree(size, count int) {
fmt.Printf("size=%d count=%d stats=%+v\n", size, count, *stats) fmt.Printf("size=%d count=%d stats=%+v\n", size, count, *stats)
} }
if n2-n1 != n3-n4 { if n2-n1 != n3-n4 {
panicln("wrong alloc count: ", n2-n1, n3-n4) println("wrong alloc count: ", n2-n1, n3-n4)
panic("fail")
} }
} }
......
...@@ -10,12 +10,14 @@ type S string ...@@ -10,12 +10,14 @@ type S string
type S1 string type S1 string
type I int type I int
type I1 int type I1 int
type T struct { x int } type T struct {
x int
}
type T1 T type T1 T
func (s S) val() int { return 1 } func (s S) val() int { return 1 }
func (s *S1) val() int { return 2 } func (s *S1) val() int { return 2 }
func (i I) val() int { return 3 } func (i I) val() int { return 3 }
func (i *I1) val() int { return 4 } func (i *I1) val() int { return 4 }
//func (t T) val() int { return 7 } //func (t T) val() int { return 7 }
func (t *T1) val() int { return 8 } func (t *T1) val() int { return 8 }
...@@ -24,37 +26,86 @@ type Val interface { ...@@ -24,37 +26,86 @@ type Val interface {
val() int val() int
} }
func val(v Val) int { func val(v Val) int { return v.val() }
return v.val()
}
func main() { func main() {
var s S; var s S
var ps *S1; var ps *S1
var i I; var i I
var pi *I1; var pi *I1
var pt *T1; var pt *T1
if s.val() != 1 { panicln("s.val:", s.val()) } if s.val() != 1 {
if S.val(s) != 1 { panicln("S.val(s):", S.val(s)) } println("s.val:", s.val())
if (*S).val(&s) != 1 { panicln("(*S).val(s):", (*S).val(&s)) } panic("fail")
if ps.val() != 2 { panicln("ps.val:", ps.val()) } }
if (*S1).val(ps) != 2 { panicln("(*S1).val(ps):", (*S1).val(ps)) } if S.val(s) != 1 {
if i.val() != 3 { panicln("i.val:", i.val()) } println("S.val(s):", S.val(s))
if I.val(i) != 3 { panicln("I.val(i):", I.val(i)) } panic("fail")
if (*I).val(&i) != 3 { panicln("(*I).val(&i):", (*I).val(&i)) } }
if pi.val() != 4 { panicln("pi.val:", pi.val()) } if (*S).val(&s) != 1 {
if (*I1).val(pi) != 4 { panicln("(*I1).val(pi):", (*I1).val(pi)) } println("(*S).val(s):", (*S).val(&s))
// if t.val() != 7 { panicln("t.val:", t.val()) } panic("fail")
if pt.val() != 8 { panicln("pt.val:", pt.val()) } }
if (*T1).val(pt) != 8 { panicln("(*T1).val(pt):", (*T1).val(pt)) } if ps.val() != 2 {
println("ps.val:", ps.val())
if val(s) != 1 { panicln("s.val:", val(s)) } panic("fail")
if val(ps) != 2 { panicln("ps.val:", val(ps)) } }
if val(i) != 3 { panicln("i.val:", val(i)) } if (*S1).val(ps) != 2 {
if val(pi) != 4 { panicln("pi.val:", val(pi)) } println("(*S1).val(ps):", (*S1).val(ps))
// if val(t) != 7 { panicln("t.val:", val(t)) } panic("fail")
if val(pt) != 8 { panicln("pt.val:", val(pt)) } }
if i.val() != 3 {
// if Val.val(i) != 3 { panicln("Val.val(i):", Val.val(i)) } println("i.val:", i.val())
panic("fail")
}
if I.val(i) != 3 {
println("I.val(i):", I.val(i))
panic("fail")
}
if (*I).val(&i) != 3 {
println("(*I).val(&i):", (*I).val(&i))
panic("fail")
}
if pi.val() != 4 {
println("pi.val:", pi.val())
panic("fail")
}
if (*I1).val(pi) != 4 {
println("(*I1).val(pi):", (*I1).val(pi))
panic("fail")
}
// if t.val() != 7 { prinln("t.val:", t.val()); panic("fail") }
if pt.val() != 8 {
println("pt.val:", pt.val())
panic("fail")
}
if (*T1).val(pt) != 8 {
println("(*T1).val(pt):", (*T1).val(pt))
panic("fail")
}
if val(s) != 1 {
println("s.val:", val(s))
panic("fail")
}
if val(ps) != 2 {
println("ps.val:", val(ps))
panic("fail")
}
if val(i) != 3 {
println("i.val:", val(i))
panic("fail")
}
if val(pi) != 4 {
println("pi.val:", val(pi))
panic("fail")
}
// if val(t) != 7 { println("t.val:", val(t)); panic("fail") }
if val(pt) != 8 {
println("pt.val:", val(pt))
panic("fail")
}
// if Val.val(i) != 3 { println("Val.val(i):", Val.val(i)); panic("fail") }
} }
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