Commit dfad8ea6 authored by Russ Cox's avatar Russ Cox

use embedded interface types

R=r
DELTA=205  (1 added, 157 deleted, 47 changed)
OCL=25071
CL=25073
parent b4af09ab
...@@ -24,24 +24,24 @@ type Close interface { ...@@ -24,24 +24,24 @@ type Close interface {
} }
type ReadWrite interface { type ReadWrite interface {
Read(p []byte) (n int, err *os.Error); Read;
Write(p []byte) (n int, err *os.Error); Write;
} }
type ReadClose interface { type ReadClose interface {
Read(p []byte) (n int, err *os.Error); Read;
Close() *os.Error; Close;
} }
type WriteClose interface { type WriteClose interface {
Write(p []byte) (n int, err *os.Error); Write;
Close() *os.Error; Close;
} }
type ReadWriteClose interface { type ReadWriteClose interface {
Read(p []byte) (n int, err *os.Error); Read;
Write(p []byte) (n int, err *os.Error); Write;
Close() *os.Error; Close;
} }
// Convert a string to an array of bytes for easy marshaling. // Convert a string to an array of bytes for easy marshaling.
......
...@@ -108,23 +108,24 @@ func newBasicType(name string, kind int, size int) Type { ...@@ -108,23 +108,24 @@ func newBasicType(name string, kind int, size int) Type {
var ( var (
Missing = newBasicType(missingString, MissingKind, 1); Missing = newBasicType(missingString, MissingKind, 1);
DotDotDot = newBasicType(dotDotDotString, DotDotDotKind, 16); // TODO(r): size of interface? DotDotDot = newBasicType(dotDotDotString, DotDotDotKind, 16); // TODO(r): size of interface?
Bool = newBasicType("bool", BoolKind, 1); // TODO: need to know how big a bool is Bool = newBasicType("bool", BoolKind, unsafe.Sizeof(true));
Int = newBasicType("int", IntKind, 4); // TODO: need to know how big an int is Int = newBasicType("int", IntKind, unsafe.Sizeof(int(0)));
Int8 = newBasicType("int8", Int8Kind, 1); Int8 = newBasicType("int8", Int8Kind, 1);
Int16 = newBasicType("int16", Int16Kind, 2); Int16 = newBasicType("int16", Int16Kind, 2);
Int32 = newBasicType("int32", Int32Kind, 4); Int32 = newBasicType("int32", Int32Kind, 4);
Int64 = newBasicType("int64", Int64Kind, 8); Int64 = newBasicType("int64", Int64Kind, 8);
Uint = newBasicType("uint", UintKind, 4); // TODO: need to know how big a uint is Uint = newBasicType("uint", UintKind, unsafe.Sizeof(uint(0)));
Uint8 = newBasicType("uint8", Uint8Kind, 1); Uint8 = newBasicType("uint8", Uint8Kind, 1);
Uint16 = newBasicType("uint16", Uint16Kind, 2); Uint16 = newBasicType("uint16", Uint16Kind, 2);
Uint32 = newBasicType("uint32", Uint32Kind, 4); Uint32 = newBasicType("uint32", Uint32Kind, 4);
Uint64 = newBasicType("uint64", Uint64Kind, 8); Uint64 = newBasicType("uint64", Uint64Kind, 8);
Uintptr = newBasicType("uintptr", UintptrKind, 8); // TODO: need to know how big a uintptr is Uintptr = newBasicType("uintptr", UintptrKind, unsafe.Sizeof(uintptr(0)));
Float = newBasicType("float", FloatKind, 4); // TODO: need to know how big a float is Float = newBasicType("float", FloatKind, unsafe.Sizeof(float(0)));
Float32 = newBasicType("float32", Float32Kind, 4); Float32 = newBasicType("float32", Float32Kind, 4);
Float64 = newBasicType("float64", Float64Kind, 8); Float64 = newBasicType("float64", Float64Kind, 8);
Float80 = newBasicType("float80", Float80Kind, 10); // TODO: strange size? Float80 = newBasicType("float80", Float80Kind, 10); // TODO: strange size?
String = newBasicType("string", StringKind, 8); // implemented as a pointer // TODO(rsc): Sizeof("") should work, doesn't.
String = newBasicType("string", StringKind, unsafe.Sizeof(string(0)));
) )
// Stub types allow us to defer evaluating type names until needed. // Stub types allow us to defer evaluating type names until needed.
...@@ -149,12 +150,7 @@ func (t *stubType) Get() Type { ...@@ -149,12 +150,7 @@ func (t *stubType) Get() Type {
// -- Pointer // -- Pointer
type PtrType interface { type PtrType interface {
// TODO: Type; Type;
Kind() int;
Name() string;
String() string;
Size() int;
Sub() Type Sub() Type
} }
...@@ -174,12 +170,7 @@ func (t *ptrTypeStruct) Sub() Type { ...@@ -174,12 +170,7 @@ func (t *ptrTypeStruct) Sub() Type {
// -- Array // -- Array
type ArrayType interface { type ArrayType interface {
// TODO: Type; Type;
Kind() int;
Name() string;
String() string;
Size() int;
IsSlice() bool; IsSlice() bool;
Len() int; Len() int;
Elem() Type; Elem() Type;
...@@ -219,12 +210,7 @@ func (t *arrayTypeStruct) Elem() Type { ...@@ -219,12 +210,7 @@ func (t *arrayTypeStruct) Elem() Type {
// -- Map // -- Map
type MapType interface { type MapType interface {
// TODO: Type; Type;
Kind() int;
Name() string;
String() string;
Size() int;
Key() Type; Key() Type;
Elem() Type; Elem() Type;
} }
...@@ -250,12 +236,7 @@ func (t *mapTypeStruct) Elem() Type { ...@@ -250,12 +236,7 @@ func (t *mapTypeStruct) Elem() Type {
// -- Chan // -- Chan
type ChanType interface { type ChanType interface {
// TODO: Type; Type;
Kind() int;
Name() string;
String() string;
Size() int;
Dir() int; Dir() int;
Elem() Type; Elem() Type;
} }
...@@ -287,12 +268,7 @@ func (t *chanTypeStruct) Elem() Type { ...@@ -287,12 +268,7 @@ func (t *chanTypeStruct) Elem() Type {
// -- Struct // -- Struct
type StructType interface { type StructType interface {
// TODO: Type; Type;
Kind() int;
Name() string;
String() string;
Size() int;
Field(int) (name string, typ Type, tag string, offset int); Field(int) (name string, typ Type, tag string, offset int);
Len() int; Len() int;
} }
...@@ -353,12 +329,7 @@ func (t *structTypeStruct) Len() int { ...@@ -353,12 +329,7 @@ func (t *structTypeStruct) Len() int {
// -- Interface // -- Interface
type InterfaceType interface { type InterfaceType interface {
// TODO: Type; Type;
Kind() int;
Name() string;
String() string;
Size() int;
Field(int) (name string, typ Type, tag string, offset int); Field(int) (name string, typ Type, tag string, offset int);
Len() int; Len() int;
} }
...@@ -385,12 +356,7 @@ var nilInterface = newInterfaceTypeStruct("nil", "", make([]structField, 0)); ...@@ -385,12 +356,7 @@ var nilInterface = newInterfaceTypeStruct("nil", "", make([]structField, 0));
// -- Func // -- Func
type FuncType interface { type FuncType interface {
// TODO: Type; Type;
Kind() int;
Name() string;
String() string;
Size() int;
In() StructType; In() StructType;
Out() StructType; Out() StructType;
} }
......
...@@ -66,11 +66,7 @@ type creatorFn func(typ Type, addr Addr) Value ...@@ -66,11 +66,7 @@ type creatorFn func(typ Type, addr Addr) Value
// -- Missing // -- Missing
type MissingValue interface { type MissingValue interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
} }
type missingValueStruct struct { type missingValueStruct struct {
...@@ -84,12 +80,7 @@ func missingCreator(typ Type, addr Addr) Value { ...@@ -84,12 +80,7 @@ func missingCreator(typ Type, addr Addr) Value {
// -- Int // -- Int
type IntValue interface { type IntValue interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Get() int; Get() int;
Set(int); Set(int);
} }
...@@ -113,12 +104,7 @@ func (v *intValueStruct) Set(i int) { ...@@ -113,12 +104,7 @@ func (v *intValueStruct) Set(i int) {
// -- Int8 // -- Int8
type Int8Value interface { type Int8Value interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Get() int8; Get() int8;
Set(int8); Set(int8);
} }
...@@ -142,12 +128,7 @@ func (v *int8ValueStruct) Set(i int8) { ...@@ -142,12 +128,7 @@ func (v *int8ValueStruct) Set(i int8) {
// -- Int16 // -- Int16
type Int16Value interface { type Int16Value interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Get() int16; Get() int16;
Set(int16); Set(int16);
} }
...@@ -171,12 +152,7 @@ func (v *int16ValueStruct) Set(i int16) { ...@@ -171,12 +152,7 @@ func (v *int16ValueStruct) Set(i int16) {
// -- Int32 // -- Int32
type Int32Value interface { type Int32Value interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Get() int32; Get() int32;
Set(int32); Set(int32);
} }
...@@ -200,12 +176,7 @@ func (v *int32ValueStruct) Set(i int32) { ...@@ -200,12 +176,7 @@ func (v *int32ValueStruct) Set(i int32) {
// -- Int64 // -- Int64
type Int64Value interface { type Int64Value interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Get() int64; Get() int64;
Set(int64); Set(int64);
} }
...@@ -229,12 +200,7 @@ func (v *int64ValueStruct) Set(i int64) { ...@@ -229,12 +200,7 @@ func (v *int64ValueStruct) Set(i int64) {
// -- Uint // -- Uint
type UintValue interface { type UintValue interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Get() uint; Get() uint;
Set(uint); Set(uint);
} }
...@@ -258,12 +224,7 @@ func (v *uintValueStruct) Set(i uint) { ...@@ -258,12 +224,7 @@ func (v *uintValueStruct) Set(i uint) {
// -- Uint8 // -- Uint8
type Uint8Value interface { type Uint8Value interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Get() uint8; Get() uint8;
Set(uint8); Set(uint8);
} }
...@@ -287,12 +248,7 @@ func (v *uint8ValueStruct) Set(i uint8) { ...@@ -287,12 +248,7 @@ func (v *uint8ValueStruct) Set(i uint8) {
// -- Uint16 // -- Uint16
type Uint16Value interface { type Uint16Value interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Get() uint16; Get() uint16;
Set(uint16); Set(uint16);
} }
...@@ -316,12 +272,7 @@ func (v *uint16ValueStruct) Set(i uint16) { ...@@ -316,12 +272,7 @@ func (v *uint16ValueStruct) Set(i uint16) {
// -- Uint32 // -- Uint32
type Uint32Value interface { type Uint32Value interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Get() uint32; Get() uint32;
Set(uint32); Set(uint32);
} }
...@@ -345,12 +296,7 @@ func (v *uint32ValueStruct) Set(i uint32) { ...@@ -345,12 +296,7 @@ func (v *uint32ValueStruct) Set(i uint32) {
// -- Uint64 // -- Uint64
type Uint64Value interface { type Uint64Value interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Get() uint64; Get() uint64;
Set(uint64); Set(uint64);
} }
...@@ -374,12 +320,7 @@ func (v *uint64ValueStruct) Set(i uint64) { ...@@ -374,12 +320,7 @@ func (v *uint64ValueStruct) Set(i uint64) {
// -- Uintptr // -- Uintptr
type UintptrValue interface { type UintptrValue interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Get() uintptr; Get() uintptr;
Set(uintptr); Set(uintptr);
} }
...@@ -403,12 +344,7 @@ func (v *uintptrValueStruct) Set(i uintptr) { ...@@ -403,12 +344,7 @@ func (v *uintptrValueStruct) Set(i uintptr) {
// -- Float // -- Float
type FloatValue interface { type FloatValue interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Get() float; Get() float;
Set(float); Set(float);
} }
...@@ -432,12 +368,7 @@ func (v *floatValueStruct) Set(f float) { ...@@ -432,12 +368,7 @@ func (v *floatValueStruct) Set(f float) {
// -- Float32 // -- Float32
type Float32Value interface { type Float32Value interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Get() float32; Get() float32;
Set(float32); Set(float32);
} }
...@@ -461,12 +392,7 @@ func (v *float32ValueStruct) Set(f float32) { ...@@ -461,12 +392,7 @@ func (v *float32ValueStruct) Set(f float32) {
// -- Float64 // -- Float64
type Float64Value interface { type Float64Value interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Get() float64; Get() float64;
Set(float64); Set(float64);
} }
...@@ -490,12 +416,7 @@ func (v *float64ValueStruct) Set(f float64) { ...@@ -490,12 +416,7 @@ func (v *float64ValueStruct) Set(f float64) {
// -- Float80 // -- Float80
type Float80Value interface { type Float80Value interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Get() float80; Get() float80;
Set(float80); Set(float80);
} }
...@@ -522,12 +443,7 @@ func (v *Float80ValueStruct) Set(f float80) { ...@@ -522,12 +443,7 @@ func (v *Float80ValueStruct) Set(f float80) {
// -- String // -- String
type StringValue interface { type StringValue interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Get() string; Get() string;
Set(string); Set(string);
} }
...@@ -551,12 +467,7 @@ func (v *stringValueStruct) Set(s string) { ...@@ -551,12 +467,7 @@ func (v *stringValueStruct) Set(s string) {
// -- Bool // -- Bool
type BoolValue interface { type BoolValue interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Get() bool; Get() bool;
Set(bool); Set(bool);
} }
...@@ -580,12 +491,7 @@ func (v *boolValueStruct) Set(b bool) { ...@@ -580,12 +491,7 @@ func (v *boolValueStruct) Set(b bool) {
// -- Pointer // -- Pointer
type PtrValue interface { type PtrValue interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Sub() Value; Sub() Value;
Get() Addr; Get() Addr;
SetSub(Value); SetSub(Value);
...@@ -621,12 +527,7 @@ func ptrCreator(typ Type, addr Addr) Value { ...@@ -621,12 +527,7 @@ func ptrCreator(typ Type, addr Addr) Value {
// Slices and arrays are represented by the same interface. // Slices and arrays are represented by the same interface.
type ArrayValue interface { type ArrayValue interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
IsSlice() bool; IsSlice() bool;
Len() int; Len() int;
Cap() int; Cap() int;
...@@ -759,12 +660,7 @@ func arrayCreator(typ Type, addr Addr) Value { ...@@ -759,12 +660,7 @@ func arrayCreator(typ Type, addr Addr) Value {
// -- Map TODO: finish and test // -- Map TODO: finish and test
type MapValue interface { type MapValue interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Len() int; Len() int;
Elem(key Value) Value; Elem(key Value) Value;
} }
...@@ -789,11 +685,7 @@ func (v *mapValueStruct) Elem(key Value) Value { ...@@ -789,11 +685,7 @@ func (v *mapValueStruct) Elem(key Value) Value {
// -- Chan // -- Chan
type ChanValue interface { type ChanValue interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
} }
type chanValueStruct struct { type chanValueStruct struct {
...@@ -807,12 +699,7 @@ func chanCreator(typ Type, addr Addr) Value { ...@@ -807,12 +699,7 @@ func chanCreator(typ Type, addr Addr) Value {
// -- Struct // -- Struct
type StructValue interface { type StructValue interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Len() int; Len() int;
Field(i int) Value; Field(i int) Value;
} }
...@@ -846,12 +733,7 @@ func structCreator(typ Type, addr Addr) Value { ...@@ -846,12 +733,7 @@ func structCreator(typ Type, addr Addr) Value {
// -- Interface // -- Interface
type InterfaceValue interface { type InterfaceValue interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
Get() interface {}; Get() interface {};
} }
...@@ -870,11 +752,7 @@ func interfaceCreator(typ Type, addr Addr) Value { ...@@ -870,11 +752,7 @@ func interfaceCreator(typ Type, addr Addr) Value {
// -- Func // -- Func
type FuncValue interface { type FuncValue interface {
// TODO: Value; Value;
Kind() int;
Type() Type;
Addr() Addr;
Interface() interface {};
} }
type funcValueStruct struct { type funcValueStruct struct {
......
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