From: Russ Cox Date: Mon, 6 Jul 2009 22:34:04 +0000 (-0700) Subject: new reflect library data structures and code declarations X-Git-Tag: weekly.2009-11-06~1253 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=4793400bd1a58895075504e5f5fc87654a2c702c;p=gostls13.git new reflect library data structures and code declarations * use structs instead of interfaces * compiler lays out data structures ahead of time, so no more parsing of strings. * unified reflect data structures with interface runtime data structures. * richer data structures should enable reflection on chans and maps, but not implemented here. R=r,iant DELTA=1179 (1179 added, 0 deleted, 0 changed) OCL=31107 CL=31213 --- diff --git a/src/pkg/reflect/ntype.go b/src/pkg/reflect/ntype.go new file mode 100644 index 0000000000..4e10c635d0 --- /dev/null +++ b/src/pkg/reflect/ntype.go @@ -0,0 +1,385 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package reflect + +import ( + "runtime"; + "strconv"; + "strings"; + "unsafe"; +) + +/* + * Copy of data structures from ../runtime/type.go. + * For comments, see the ones in that file. + * + * These data structures are known to the compiler and the runtime. + * + * Putting these types in runtime instead of reflect means that + * reflect doesn't need to be autolinked into every binary, which + * simplifies bootstrapping and package dependencies. + * Unfortunately, it also means that reflect needs its own + * copy in order to access the private fields. + */ + +type uncommonType struct + +type commonType struct { + size uintptr; + hash uint32; + alg uint8; + align uint8; + fieldAlign uint8; + string *string; + *uncommonType; +} + +type method struct { + hash uint32; + name *string; + PkgPath *string; + typ *runtime.Type; + ifn unsafe.Pointer; + tfn unsafe.Pointer; +} + +type uncommonType struct { + name *string; + pkgPath *string; + methods []method; +} + +// BoolType represents a boolean type. +type BoolType struct { + commonType +} + +// Float32Type represents a float32 type. +type Float32Type struct { + commonType +} + +// Float64Type represents a float64 type. +type Float64Type struct { + commonType +} + +// FloatType represents a float type. +type FloatType struct { + commonType +} + +// Int16Type represents an int16 type. +type Int16Type struct { + commonType +} + +// Int32Type represents an int32 type. +type Int32Type struct { + commonType +} + +// Int64Type represents an int64 type. +type Int64Type struct { + commonType +} + +// Int8Type represents an int8 type. +type Int8Type struct { + commonType +} + +// IntType represents an int type. +type IntType struct { + commonType +} + +// Uint16Type represents a uint16 type. +type Uint16Type struct { + commonType +} + +// Uint32Type represents a uint32 type. +type Uint32Type struct { + commonType +} + +// Uint64Type represents a uint64 type. +type Uint64Type struct { + commonType +} + +// Uint8Type represents a uint8 type. +type Uint8Type struct { + commonType +} + +// UintType represents a uint type. +type UintType struct { + commonType +} + +// StringType represents a string type. +type StringType struct { + commonType +} + +// UintptrType represents a uintptr type. +type UintptrType struct { + commonType +} + +// DotDotDotType represents the ... that can +// be used as the type of the final function parameter. +type DotDotDotType struct { + commonType +} + +// UnsafePointerType represents an unsafe.Pointer type. +type UnsafePointerType struct { + commonType +} + +// ArrayType represents a fixed array type. +type ArrayType struct { + commonType; + elem *runtime.Type; + len uintptr; +} + +// SliceType represents a slice type. +type SliceType struct { + commonType; + elem *runtime.Type; +} + +// ChanDir represents a channel type's direction. +type ChanDir int +const ( + RecvDir ChanDir = 1<