static uint32 fastrand1(void);
static uint32 fastrand2(void);
+enum {
+ Structrnd = sizeof(uintptr)
+};
+
// newchan(elemsize uint32, elemalg uint32, hint uint32) (hchan *chan any);
void
sys·newchan(uint32 elemsize, uint32 elemalg, uint32 hint,
o = rnd(sizeof(c), c->elemsize);
ae = (byte*)&c + o;
- o = rnd(o+c->elemsize, 1);
+ o = rnd(o+c->elemsize, Structrnd);
ap = (byte*)&c + o;
sendchan(c, ae, ap);
int32 o;
byte *ae;
- o = rnd(sizeof(c), c->elemsize);
+ o = rnd(sizeof(c), Structrnd);
ae = (byte*)&c + o;
chanrecv(c, ae, nil);
int32 o;
byte *ae, *ap;
- o = rnd(sizeof(c), c->elemsize);
+ o = rnd(sizeof(c), Structrnd);
ae = (byte*)&c + o;
o = rnd(o+c->elemsize, 1);
ap = (byte*)&c + o;
// newselect(size uint32) (sel *byte);
void
-sys·newselect(int32 size, Select *sel)
+sys·newselect(int32 size, ...)
{
- int32 n;
+ int32 n, o;
+ Select **selp;
+ Select *sel;
+ o = rnd(sizeof(size), Structrnd);
+ selp = (Select**)((byte*)&size + o);
n = 0;
if(size > 1)
n = size-1;
sel->tcase = size;
sel->ncase = 0;
- FLUSH(&sel);
+ *selp = sel;
if(debug) {
prints("newselect s=");
sys·printpointer(sel);
eo = rnd(sizeof(sel), sizeof(c));
eo = rnd(eo+sizeof(c), c->elemsize);
- cas->so = rnd(eo+c->elemsize, 1);
+ cas->so = rnd(eo+c->elemsize, Structrnd);
cas->send = 1;
ae = (byte*)&sel + eo;
eo = rnd(sizeof(sel), sizeof(c));
eo = rnd(eo+sizeof(c), sizeof(byte*));
- cas->so = rnd(eo+sizeof(byte*), 1);
+ cas->so = rnd(eo+sizeof(byte*), Structrnd);
cas->send = 0;
cas->u.elemp = *(byte**)((byte*)&sel + eo);
cas->pc = sys·getcallerpc(&sel);
cas->chan = nil;
- cas->so = rnd(sizeof(sel), 1);
+ cas->so = rnd(sizeof(sel), Structrnd);
cas->send = 2;
cas->u.elemp = nil;
uint32 keysize;
uint32 valsize;
uint32 datavo;
- uint32 ko;
- uint32 vo;
- uint32 po;
+
+ // three sets of offsets: the digit counts how many
+ // of key, value are passed as inputs:
+ // 0 = func() (key, value)
+ // 1 = func(key) (value)
+ // 2 = func(key, value)
+ uint32 ko0;
+ uint32 vo0;
+ uint32 ko1;
+ uint32 vo1;
+ uint32 po1;
+ uint32 ko2;
+ uint32 vo2;
+ uint32 po2;
Alg* keyalg;
Alg* valalg;
};
typedef struct hash Hmap;
static int32 debug = 0;
+enum {
+ Structrnd = sizeof(uintptr)
+};
+
// newmap(keysize uint32, valsize uint32,
// keyalg uint32, valalg uint32,
// hint uint32) (hmap *map[any]any);
}
h = mal(sizeof(*h));
-
+
// align value inside data so that mark-sweep gc can find it.
// might remove in the future and just assume datavo == keysize.
h->datavo = keysize;
h->valsize = valsize;
h->keyalg = &algarray[keyalg];
h->valalg = &algarray[valalg];
-
+
// these calculations are compiler dependent.
// figure out offsets of map call arguments.
- h->ko = rnd(sizeof(h), keysize);
- h->vo = rnd(h->ko+keysize, valsize);
- h->po = rnd(h->vo+valsize, 1);
+
+ // func() (key, val)
+ h->ko0 = rnd(sizeof(h), Structrnd);
+ h->vo0 = rnd(h->ko0+keysize, valsize);
+
+ // func(key) (val[, pres])
+ h->ko1 = rnd(sizeof(h), keysize);
+ h->vo1 = rnd(h->ko1+keysize, Structrnd);
+ h->po1 = rnd(h->vo1+valsize, 1);
+
+ // func(key, val[, pres])
+ h->ko2 = rnd(sizeof(h), keysize);
+ h->vo2 = rnd(h->ko2+keysize, valsize);
+ h->po2 = rnd(h->vo2+valsize, 1);
ret = h;
FLUSH(&ret);
if(debug) {
- prints("newmap: map=");
- sys·printpointer(h);
- prints("; keysize=");
- sys·printint(keysize);
- prints("; valsize=");
- sys·printint(valsize);
- prints("; keyalg=");
- sys·printint(keyalg);
- prints("; valalg=");
- sys·printint(valalg);
- prints("; ko=");
- sys·printint(h->ko);
- prints("; vo=");
- sys·printint(h->vo);
- prints("; po=");
- sys·printint(h->po);
- prints("\n");
+ printf("newmap: map=%p; keysize=%d; valsize=%d; keyalg=%d; valalg=%d; offsets=%d,%d; %d,%d,%d; %d,%d,%d\n",
+ h, keysize, valsize, keyalg, valalg, h->ko0, h->vo0, h->ko1, h->vo1, h->po1, h->ko2, h->vo2, h->po2);
}
}
byte *res;
int32 hit;
- ak = (byte*)&h + h->ko;
- av = (byte*)&h + h->vo;
+ ak = (byte*)&h + h->ko1;
+ av = (byte*)&h + h->vo1;
res = nil;
hit = hash_lookup(h, ak, (void**)&res);
byte *res;
int32 hit;
- ak = (byte*)&h + h->ko;
- av = (byte*)&h + h->vo;
- ap = (byte*)&h + h->po;
+ ak = (byte*)&h + h->ko1;
+ av = (byte*)&h + h->vo1;
+ ap = (byte*)&h + h->po1;
res = nil;
hit = hash_lookup(h, ak, (void**)&res);
{
byte *ak, *av;
- ak = (byte*)&h + h->ko;
- av = (byte*)&h + h->vo;
+ ak = (byte*)&h + h->ko2;
+ av = (byte*)&h + h->vo2;
mapassign(h, ak, av);
}
byte *res;
int32 hit;
- ak = (byte*)&h + h->ko;
- av = (byte*)&h + h->vo;
- ap = (byte*)&h + h->po;
+ ak = (byte*)&h + h->ko2;
+ av = (byte*)&h + h->vo2;
+ ap = (byte*)&h + h->po2;
if(*ap == true) {
// assign
byte *ak, *res;
h = it->h;
- ak = (byte*)&it + h->ko;
+ ak = (byte*)&it + h->ko0;
res = it->data;
if(res == nil)
byte *ak, *av, *res;
h = it->h;
- ak = (byte*)&it + h->ko;
- av = (byte*)&it + h->vo;
+ ak = (byte*)&it + h->ko0;
+ av = (byte*)&it + h->vo0;
res = it->data;
if(res == nil)