summaryrefslogtreecommitdiff
path: root/libgo/runtime/go-reflect-map.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/runtime/go-reflect-map.c')
-rw-r--r--libgo/runtime/go-reflect-map.c178
1 files changed, 42 insertions, 136 deletions
diff --git a/libgo/runtime/go-reflect-map.c b/libgo/runtime/go-reflect-map.c
index 1ae7c96adc0..ab116e85950 100644
--- a/libgo/runtime/go-reflect-map.c
+++ b/libgo/runtime/go-reflect-map.c
@@ -16,112 +16,55 @@
/* This file implements support for reflection on maps. These
functions are called from reflect/value.go. */
-struct mapaccess_ret
-{
- uintptr_t val;
- _Bool pres;
-};
-
-extern struct mapaccess_ret mapaccess (struct __go_map_type *, uintptr_t,
- uintptr_t)
+extern void *mapaccess (struct __go_map_type *, void *, void *)
__asm__ (GOSYM_PREFIX "reflect.mapaccess");
-struct mapaccess_ret
-mapaccess (struct __go_map_type *mt, uintptr_t m, uintptr_t key_i)
+void *
+mapaccess (struct __go_map_type *mt, void *m, void *key)
{
struct __go_map *map = (struct __go_map *) m;
- void *key;
- const struct __go_type_descriptor *key_descriptor;
- void *p;
- const struct __go_type_descriptor *val_descriptor;
- struct mapaccess_ret ret;
- void *val;
- void *pv;
__go_assert (mt->__common.__code == GO_MAP);
-
- key_descriptor = mt->__key_type;
- if (__go_is_pointer_type (key_descriptor))
- key = &key_i;
- else
- key = (void *) key_i;
-
if (map == NULL)
- p = NULL;
+ return NULL;
else
- p = __go_map_index (map, key, 0);
-
- val_descriptor = mt->__val_type;
- if (__go_is_pointer_type (val_descriptor))
- {
- val = NULL;
- pv = &val;
- }
- else
- {
- val = __go_alloc (val_descriptor->__size);
- pv = val;
- }
-
- if (p == NULL)
- ret.pres = 0;
- else
- {
- __builtin_memcpy (pv, p, val_descriptor->__size);
- ret.pres = 1;
- }
-
- ret.val = (uintptr_t) val;
- return ret;
+ return __go_map_index (map, key, 0);
}
-extern void mapassign (struct __go_map_type *, uintptr_t, uintptr_t,
- uintptr_t, _Bool)
+extern void mapassign (struct __go_map_type *, void *, void *, void *)
__asm__ (GOSYM_PREFIX "reflect.mapassign");
void
-mapassign (struct __go_map_type *mt, uintptr_t m, uintptr_t key_i,
- uintptr_t val_i, _Bool pres)
+mapassign (struct __go_map_type *mt, void *m, void *key, void *val)
{
struct __go_map *map = (struct __go_map *) m;
- const struct __go_type_descriptor *key_descriptor;
- void *key;
+ void *p;
__go_assert (mt->__common.__code == GO_MAP);
-
if (map == NULL)
runtime_panicstring ("assignment to entry in nil map");
+ p = __go_map_index (map, key, 1);
+ __builtin_memcpy (p, val, mt->__val_type->__size);
+}
- key_descriptor = mt->__key_type;
- if (__go_is_pointer_type (key_descriptor))
- key = &key_i;
- else
- key = (void *) key_i;
+extern void mapdelete (struct __go_map_type *, void *, void *)
+ __asm__ (GOSYM_PREFIX "reflect.mapdelete");
- if (!pres)
- __go_map_delete (map, key);
- else
- {
- void *p;
- const struct __go_type_descriptor *val_descriptor;
- void *pv;
-
- p = __go_map_index (map, key, 1);
-
- val_descriptor = mt->__val_type;
- if (__go_is_pointer_type (val_descriptor))
- pv = &val_i;
- else
- pv = (void *) val_i;
- __builtin_memcpy (p, pv, val_descriptor->__size);
- }
+void
+mapdelete (struct __go_map_type *mt, void *m, void *key)
+{
+ struct __go_map *map = (struct __go_map *) m;
+
+ __go_assert (mt->__common.__code == GO_MAP);
+ if (map == NULL)
+ return;
+ __go_map_delete (map, key);
}
-extern int32_t maplen (uintptr_t)
- __asm__ (GOSYM_PREFIX "reflect.maplen");
+extern int32_t maplen (void *) __asm__ (GOSYM_PREFIX "reflect.maplen");
int32_t
-maplen (uintptr_t m)
+maplen (void *m)
{
struct __go_map *map = (struct __go_map *) m;
@@ -130,11 +73,11 @@ maplen (uintptr_t m)
return (int32_t) map->__element_count;
}
-extern unsigned char *mapiterinit (struct __go_map_type *, uintptr_t)
+extern unsigned char *mapiterinit (struct __go_map_type *, void *)
__asm__ (GOSYM_PREFIX "reflect.mapiterinit");
unsigned char *
-mapiterinit (struct __go_map_type *mt, uintptr_t m)
+mapiterinit (struct __go_map_type *mt, void *m)
{
struct __go_hash_iter *it;
@@ -144,78 +87,45 @@ mapiterinit (struct __go_map_type *mt, uintptr_t m)
return (unsigned char *) it;
}
-extern void mapiternext (unsigned char *)
- __asm__ (GOSYM_PREFIX "reflect.mapiternext");
+extern void mapiternext (void *) __asm__ (GOSYM_PREFIX "reflect.mapiternext");
void
-mapiternext (unsigned char *it)
+mapiternext (void *it)
{
__go_mapiternext ((struct __go_hash_iter *) it);
}
-struct mapiterkey_ret
-{
- uintptr_t key;
- _Bool ok;
-};
-
-extern struct mapiterkey_ret mapiterkey (unsigned char *)
- __asm__ (GOSYM_PREFIX "reflect.mapiterkey");
+extern void *mapiterkey (void *) __asm__ (GOSYM_PREFIX "reflect.mapiterkey");
-struct mapiterkey_ret
-mapiterkey (unsigned char *ita)
+void *
+mapiterkey (void *ita)
{
struct __go_hash_iter *it = (struct __go_hash_iter *) ita;
- struct mapiterkey_ret ret;
+ const struct __go_type_descriptor *key_descriptor;
+ void *key;
if (it->entry == NULL)
- {
- ret.key = 0;
- ret.ok = 0;
- }
- else
- {
- const struct __go_type_descriptor *key_descriptor;
- void *key;
- void *pk;
-
- key_descriptor = it->map->__descriptor->__map_descriptor->__key_type;
- if (__go_is_pointer_type (key_descriptor))
- {
- key = NULL;
- pk = &key;
- }
- else
- {
- key = __go_alloc (key_descriptor->__size);
- pk = key;
- }
-
- __go_mapiter1 (it, pk);
-
- ret.key = (uintptr_t) key;
- ret.ok = 1;
- }
-
- return ret;
+ return NULL;
+
+ key_descriptor = it->map->__descriptor->__map_descriptor->__key_type;
+ key = __go_alloc (key_descriptor->__size);
+ __go_mapiter1 (it, key);
+ return key;
}
/* Make a new map. We have to build our own map descriptor. */
-extern uintptr_t makemap (const struct __go_map_type *)
+extern struct __go_map *makemap (const struct __go_map_type *)
__asm__ (GOSYM_PREFIX "reflect.makemap");
-uintptr_t
+struct __go_map *
makemap (const struct __go_map_type *t)
{
struct __go_map_descriptor *md;
unsigned int o;
const struct __go_type_descriptor *kt;
const struct __go_type_descriptor *vt;
- struct __go_map* map;
- void *ret;
- /* FIXME: Reference count. */
md = (struct __go_map_descriptor *) __go_alloc (sizeof (*md));
md->__map_descriptor = t;
o = sizeof (void *);
@@ -232,11 +142,7 @@ makemap (const struct __go_map_type *t)
o = (o + vt->__field_align - 1) & ~ (vt->__field_align - 1);
md->__entry_size = o;
- map = __go_new_map (md, 0);
-
- ret = __go_alloc (sizeof (void *));
- __builtin_memcpy (ret, &map, sizeof (void *));
- return (uintptr_t) ret;
+ return __go_new_map (md, 0);
}
extern _Bool ismapkey (const struct __go_type_descriptor *)