sigcmp(Sig *a, Sig *b)
{
int i;
-
+
i = strcmp(a->name, b->name);
if(i != 0)
return i;
else
last->link = a;
last = a;
-
+
// Compiler can only refer to wrappers for
// named interface types.
if(t->sym == S)
continue;
-
+
// NOTE(rsc): Perhaps an oversight that
// IfaceType.Method is not in the reflect data.
// Generate the method body, so that compiled
static Pkg *gopkg;
char *nam;
Node *n;
-
+
if(p->pathsym != S)
return;
n->class = PEXTERN;
n->xoffset = 0;
p->pathsym = n->sym;
-
+
gdatastring(n, p->path);
ggloblsym(n->sym, types[TSTRING]->width, 1);
}
// that imports this one directly defines the symbol.
if(pkg == localpkg) {
static Sym *ns;
-
+
if(ns == nil)
ns = pkglookup("importpath.\"\".", mkpkg(strlit("go")));
return dsymptr(s, ot, ns, 0);
m = methods(t);
if(t->sym == nil && m == nil)
return off;
-
+
// fill in *extraType pointer in header
dsymptr(sym, ptroff, sym, off);
KindString,
KindStruct,
KindUnsafePointer,
-
+
KindNoPointers = 1<<7,
};
ot = duintptr(s, ot, t->width);
ot = duint32(s, ot, typehash(t));
ot = duint8(s, ot, 0); // unused
+
+ // runtime (and common sense) expects alignment to be a power of two.
+ i = t->align;
+ if(i == 0)
+ i = 1;
+ if((i&(i-1)) != 0)
+ fatal("invalid alignment %d for %T", t->align, t);
ot = duint8(s, ot, t->align); // align
ot = duint8(s, ot, t->align); // fieldAlign
+
i = kinds[t->etype];
if(t->etype == TARRAY && t->bound < 0)
i = KindSlice;
//print("dcommontype: %s\n", p);
ot = dgostringptr(s, ot, p); // string
free(p);
-
+
// skip pointer to extraType,
// which follows the rest of this type structure.
// caller will fill in if needed.
tbase = t->type;
dupok = tbase->sym == S;
- if(compiling_runtime &&
+ if(compiling_runtime &&
(tbase == types[tbase->etype] ||
tbase == bytetype ||
tbase == runetype ||
// emit type structs for error and func(error) string.
// The latter is the type of an auto-generated wrapper.
dtypesym(ptrto(errortype));
- dtypesym(functype(nil,
+ dtypesym(functype(nil,
list1(nod(ODCLFIELD, N, typenod(errortype))),
list1(nod(ODCLFIELD, N, typenod(types[TSTRING])))));
-
+
// add paths for runtime and main, which 6l imports implicitly.
dimportpath(runtimepkg);
dimportpath(mkpkg(strlit("main")));
Hchan *c;
int32 n;
Type *elem;
-
+
elem = t->elem;
if(hint < 0 || (int32)hint != hint || (elem->size > 0 && hint > ((uintptr)-1) / elem->size))
sg = dequeue(&c->recvq);
if(sg != nil) {
runtime·unlock(c);
-
+
gp = sg->g;
gp->param = sg;
if(sg->elem != nil)
byte *ae, *ap;
ae = (byte*)(&c + 1);
- ap = ae + runtime·rnd(t->elem->size, Structrnd);
+ ap = ae + ROUND(t->elem->size, Structrnd);
runtime·chansend(t, c, ae, ap);
}
runtime·selectnbrecv(ChanType *t, byte *v, Hchan *c, bool selected)
{
runtime·chanrecv(t, c, v, &selected, nil);
-}
+}
// func selectnbrecv2(elem *any, ok *bool, c chan any) bool
//
runtime·selectnbrecv2(ChanType *t, byte *v, bool *received, Hchan *c, bool selected)
{
runtime·chanrecv(t, c, v, &selected, received);
-}
+}
// For reflect:
// func chansend(c chan, val iword, nb bool) (selected bool)
{
bool *sp;
byte *vp;
-
+
if(nb) {
selected = false;
sp = (bool*)&selected;
int32 o;
Select **selp;
- o = runtime·rnd(sizeof(size), Structrnd);
+ o = ROUND(sizeof(size), Structrnd);
selp = (Select**)((byte*)&size + o);
newselect(size, selp);
}
// nil cases do not compete
if(c == nil)
return;
-
+
selectsend(sel, c, runtime·getcallerpc(&sel), elem, (byte*)&selected - (byte*)&sel);
}
{
int32 i;
Scase *cas;
-
+
i = sel->ncase;
if(i >= sel->tcase)
runtime·throw("selectsend: too many cases");
case CaseRecv:
enqueue(&c->recvq, sg);
break;
-
+
case CaseSend:
enqueue(&c->sendq, sg);
break;
if(datasize < sizeof (void *))
datasize = sizeof (void *);
- datasize = runtime·rnd(datasize, sizeof (void *));
+ datasize = ROUND(datasize, sizeof (void *));
init_sizes (hint, &init_power);
h->datasize = datasize;
assert (h->datasize == datasize);
struct hash_entry *end_e;
void *key;
bool eq;
-
+
hash = h->hash0;
(*t->key->alg->hash) (&hash, t->key->size, data);
hash &= ~HASH_MASK;
{
uintptr hash;
int32 rc;
-
+
hash = h->hash0;
(*t->key->alg->hash) (&hash, t->key->size, data);
rc = hash_insert_internal (t, &h->st, 0, hash, h, data, pres);
it->subtable_state[0].e = h->st->entry;
it->subtable_state[0].start = h->st->entry;
it->subtable_state[0].last = h->st->last;
-
+
// fastrand1 returns 31 useful bits.
// We don't care about not having a bottom bit but we
// do want top bits.
Hmap *h;
Type *key, *val;
uintptr ksize, vsize;
-
+
key = typ->key;
val = typ->elem;
h = runtime·mal(sizeof(*h));
h->flag |= CanFreeTable; /* until reflect gets involved, free is okay */
- ksize = runtime·rnd(key->size, sizeof(void*));
- vsize = runtime·rnd(val->size, sizeof(void*));
+ ksize = ROUND(key->size, sizeof(void*));
+ vsize = ROUND(val->size, sizeof(void*));
if(ksize > MaxData || vsize > MaxData || ksize+vsize > MaxData) {
// Either key is too big, or value is, or combined they are.
// Prefer to keep the key if possible, because we look at
bool pres;
ak = (byte*)(&h + 1);
- av = ak + runtime·rnd(t->key->size, Structrnd);
+ av = ak + ROUND(t->key->size, Structrnd);
runtime·mapaccess(t, h, ak, av, &pres);
byte *ak, *av, *ap;
ak = (byte*)(&h + 1);
- av = ak + runtime·rnd(t->key->size, Structrnd);
+ av = ak + ROUND(t->key->size, Structrnd);
ap = av + t->elem->size;
runtime·mapaccess(t, h, ak, av, ap);
runtime·panicstring("assignment to entry in nil map");
ak = (byte*)(&h + 1);
- av = ak + runtime·rnd(t->key->size, t->elem->align);
+ av = ak + ROUND(t->key->size, t->elem->align);
runtime·mapassign(t, h, ak, av);
}
t = it->t;
ak = (byte*)(&it + 1);
- av = ak + runtime·rnd(t->key->size, t->elem->align);
+ av = ak + ROUND(t->key->size, t->elem->align);
res = it->data;
if(res == nil)
elem = (byte*)(&inter+1);
wid = t->size;
- ret = (Iface*)(elem + runtime·rnd(wid, Structrnd));
+ ret = (Iface*)(elem + ROUND(wid, Structrnd));
ret->tab = itab(inter, t, 0);
copyin(t, elem, &ret->data);
}
elem = (byte*)(&t+1);
wid = t->size;
- ret = (Eface*)(elem + runtime·rnd(wid, Structrnd));
+ ret = (Eface*)(elem + ROUND(wid, Structrnd));
ret->type = t;
copyin(t, elem, &ret->data);
}
runtime·convI2I(InterfaceType* inter, Iface i, Iface ret)
{
Itab *tab;
-
+
ret.data = i.data;
if((tab = i.tab) == nil)
ret.tab = nil;
// We know that the pointer to the original
// type structure sits before the data pointer.
t = (Type*)((Eface*)typ.data-1);
-
+
size = n*t->size;
if(t->kind&KindNoPointers)
ret = runtime·mallocgc(size, FlagNoPointers, 1, 1);
runtime·write(2, v, n);
return;
}
-
+
if(g->writenbuf == 0)
return;
-
+
if(n > g->writenbuf)
n = g->writenbuf;
runtime·memmove(g->writebuf, v, n);
break;
case 'd': // 32-bit
case 'x':
- arg = runtime·rnd(arg, 4);
+ arg = ROUND(arg, 4);
narg = arg + 4;
break;
case 'D': // 64-bit
case 'U':
case 'X':
case 'f':
- arg = runtime·rnd(arg, sizeof(uintptr));
+ arg = ROUND(arg, sizeof(uintptr));
narg = arg + 8;
break;
case 'C':
- arg = runtime·rnd(arg, sizeof(uintptr));
+ arg = ROUND(arg, sizeof(uintptr));
narg = arg + 16;
break;
case 'p': // pointer-sized
case 's':
- arg = runtime·rnd(arg, sizeof(uintptr));
+ arg = ROUND(arg, sizeof(uintptr));
narg = arg + sizeof(uintptr);
break;
case 'S': // pointer-aligned but bigger
- arg = runtime·rnd(arg, sizeof(uintptr));
+ arg = ROUND(arg, sizeof(uintptr));
narg = arg + sizeof(String);
break;
case 'a': // pointer-aligned but bigger
- arg = runtime·rnd(arg, sizeof(uintptr));
+ arg = ROUND(arg, sizeof(uintptr));
narg = arg + sizeof(Slice);
break;
case 'i': // pointer-aligned but bigger
case 'e':
- arg = runtime·rnd(arg, sizeof(uintptr));
+ arg = ROUND(arg, sizeof(uintptr));
narg = arg + sizeof(Eface);
break;
}
return nil;
}
-uint32
-runtime·rnd(uint32 n, uint32 m)
-{
- uint32 r;
-
- if(m > maxround)
- m = maxround;
- r = n % m;
- if(r)
- n += m-r;
- return n;
-}
-
static int32 argc;
static uint8** argv;
#define nelem(x) (sizeof(x)/sizeof((x)[0]))
#define nil ((void*)0)
#define offsetof(s,m) (uint32)(&(((s*)0)->m))
+#define ROUND(x, n) (((x)+(n)-1)&~((n)-1)) /* all-caps to mark as macro: it evaluates n twice */
/*
* known to compiler
void* runtime·getu(void);
void runtime·throw(int8*);
void runtime·panicstring(int8*);
-uint32 runtime·rnd(uint32, uint32);
void runtime·prints(int8*);
void runtime·printf(int8*, ...);
byte* runtime·mchr(byte*, byte, byte*);