diff options
author | Russ Cox <rsc@golang.org> | 2008-12-19 12:05:22 -0800 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2008-12-19 12:05:22 -0800 |
commit | 81f94fb52eba71ffc3873e5260be33a59457dfa3 (patch) | |
tree | d43976b2cd9eccadecab471683f3248c928480ce /src | |
parent | a56193282819f795ad648ef9df4651661a5e3d71 (diff) | |
download | golang-81f94fb52eba71ffc3873e5260be33a59457dfa3.tar.gz |
chan and map of [] and struct
R=r
DELTA=192 (145 added, 8 deleted, 39 changed)
OCL=21609
CL=21614
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/gc/go.h | 2 | ||||
-rw-r--r-- | src/cmd/gc/subr.c | 6 | ||||
-rw-r--r-- | src/runtime/chan.c | 19 | ||||
-rw-r--r-- | src/runtime/hashmap.c | 37 | ||||
-rw-r--r-- | src/runtime/iface.c | 11 | ||||
-rw-r--r-- | src/runtime/runtime.c | 35 | ||||
-rw-r--r-- | src/runtime/runtime.h | 15 |
7 files changed, 78 insertions, 47 deletions
diff --git a/src/cmd/gc/go.h b/src/cmd/gc/go.h index bd1e34662..6cd2eab5a 100644 --- a/src/cmd/gc/go.h +++ b/src/cmd/gc/go.h @@ -41,6 +41,8 @@ enum ASTRING, APTR, AINTER, + AARRAY, + ASTRUCT, BADWIDTH = -1000000000 }; diff --git a/src/cmd/gc/subr.c b/src/cmd/gc/subr.c index e1fb97d62..90cc9dc0b 100644 --- a/src/cmd/gc/subr.c +++ b/src/cmd/gc/subr.c @@ -301,6 +301,12 @@ algtype(Type *t) if(isptr[t->etype]) a = APTR; // pointer else + if(t->etype == TARRAY) + a = AARRAY; + else + if(t->etype == TSTRUCT) + a = ASTRUCT; + else if(isinter(t)) a = AINTER; // interface // else diff --git a/src/runtime/chan.c b/src/runtime/chan.c index 14b5ce3a6..8296cdc02 100644 --- a/src/runtime/chan.c +++ b/src/runtime/chan.c @@ -86,14 +86,17 @@ sys·newchan(uint32 elemsize, uint32 elemalg, uint32 hint, Hchan *c; int32 i; - if(elemalg >= nelem(algarray)) { - prints("0<="); - sys·printint(elemalg); - prints("<"); - sys·printint(nelem(algarray)); - prints("\n"); - - throw("sys·newchan: elem algorithm out of range"); + switch(elemalg){ + case ASIMP: + case ASTRING: + case APTR: + case AINTER: + case AARRAY: + case ASTRUCT: + break; + default: + printf("chan(alg=%d)\n", elemalg); + throw("sys·newchan: unsupported channel element type"); } c = mal(sizeof(*c)); diff --git a/src/runtime/hashmap.c b/src/runtime/hashmap.c index 5b32fe588..5be990c49 100644 --- a/src/runtime/hashmap.c +++ b/src/runtime/hashmap.c @@ -663,19 +663,30 @@ sys·newmap(uint32 keysize, uint32 valsize, { Hmap *h; - if(keyalg >= 4 || - valalg >= 4) { - prints("0<="); - sys·printint(keyalg); - prints("<"); - sys·printint(nelem(algarray)); - prints("\n0<="); - sys·printint(valalg); - prints("<"); - sys·printint(nelem(algarray)); - prints("\n"); - - throw("sys·newmap: key/val algorithm out of range"); + switch(keyalg) { + case ASIMP: + case ASTRING: + case APTR: + case AINTER: + case AARRAY: + case ASTRUCT: + break; + default: + printf("map(keyalg=%d)\n", keyalg); + throw("sys·newmap: unsupported map key type"); + } + + switch(valalg) { + case ASIMP: + case ASTRING: + case APTR: + case AINTER: + case AARRAY: + case ASTRUCT: + break; + default: + printf("map(valalg=%d)\n", valalg); + throw("sys·newmap: unsupported map value type"); } h = mal(sizeof(*h)); diff --git a/src/runtime/iface.c b/src/runtime/iface.c index 5062075c3..a5259db4f 100644 --- a/src/runtime/iface.c +++ b/src/runtime/iface.c @@ -6,18 +6,13 @@ static int32 debug = 0; -enum -{ - ASIMP = 0, - ASTRING, - APTR, - AINTER, -}; - typedef struct Sigt Sigt; typedef struct Sigi Sigi; typedef struct Map Map; +/* + * the layout of Sigt and Sigi are known to the compiler + */ struct Sigt { byte* name; diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c index c075181a0..708abd4ca 100644 --- a/src/runtime/runtime.c +++ b/src/runtime/runtime.c @@ -580,7 +580,7 @@ memcopy(uint32 s, void *a, void *b) } static uint64 -stringhash(uint32 s, string *a) +strhash(uint32 s, string *a) { USED(s); if(*a == nil) @@ -589,21 +589,21 @@ stringhash(uint32 s, string *a) } static uint32 -stringequal(uint32 s, string *a, string *b) +strequal(uint32 s, string *a, string *b) { USED(s); return cmpstring(*a, *b) == 0; } static void -stringprint(uint32 s, string *a) +strprint(uint32 s, string *a) { USED(s); sys·printstring(*a); } static void -stringcopy(uint32 s, string *a, string *b) +strcopy(uint32 s, string *a, string *b) { USED(s); if(b == nil) { @@ -614,28 +614,28 @@ stringcopy(uint32 s, string *a, string *b) } static uint64 -pointerhash(uint32 s, void **a) +ptrhash(uint32 s, void **a) { return memhash(s, *a); } static uint32 -pointerequal(uint32 s, void **a, void **b) +ptrequal(uint32 s, void **a, void **b) { USED(s, a, b); - prints("pointerequal\n"); + prints("ptrequal\n"); return 0; } static void -pointerprint(uint32 s, void **a) +ptrprint(uint32 s, void **a) { USED(s, a); - prints("pointerprint\n"); + prints("ptrprint\n"); } static void -pointercopy(uint32 s, void **a, void **b) +ptrcopy(uint32 s, void **a, void **b) { USED(s); if(b == nil) { @@ -646,12 +646,13 @@ pointercopy(uint32 s, void **a, void **b) } Alg -algarray[4] = -{ - { memhash, memequal, memprint, memcopy }, // 0 - { stringhash, stringequal, stringprint, stringcopy }, // 1 -// { pointerhash, pointerequal, pointerprint, pointercopy }, // 2 - { memhash, memequal, memprint, memcopy }, // 2 - treat pointers as ints - { memhash, memequal, memprint, memcopy }, // 3 - treat interfaces as memory +algarray[] = +{ +[ASIMP] { memhash, memequal, memprint, memcopy }, +[ASTRING] { strhash, strequal, strprint, strcopy }, +[APTR] { memhash, memequal, memprint, memcopy }, // TODO: ptr routines +[AINTER] { memhash, memequal, memprint, memcopy }, // TODO: interface routines +[ASTRUCT] { memhash, memequal, memprint, memcopy }, // TODO: what goes here? +[AARRAY] { memhash, memequal, memprint, memcopy }, // TODO: what goes here? }; diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h index fc4e5ba46..c0f943abf 100644 --- a/src/runtime/runtime.h +++ b/src/runtime/runtime.h @@ -215,9 +215,22 @@ struct Func #define nil ((void*)0) /* + * known to compiler + */ +enum +{ + ASIMP = 0, + ASTRING, + APTR, + AINTER, + AARRAY, + ASTRUCT, +}; + +/* * external data */ -extern Alg algarray[4]; +extern Alg algarray[]; extern string emptystring; G* allg; int32 goidgen; |