Commit e5d9a5c9 authored by Russ Cox's avatar Russ Cox

runtime support for interface ok,

whatever the final syntax ends up being.

R=ken
OCL=18414
CL=18414
parent 47caf642
......@@ -30,7 +30,9 @@ export func arraystring(*[]byte) string;
export func ifaceT2I(sigi *byte, sigt *byte, elem any) (ret any);
export func ifaceI2T(sigt *byte, iface any) (ret any);
export func ifaceI2T2(sigt *byte, iface any) (ret any, ok bool);
export func ifaceI2I(sigi *byte, iface any) (ret any);
export func ifaceI2I2(sigi *byte, iface any) (ret any, ok bool);
export func ifaceeq(i1 any, i2 any) (ret bool);
export func reflect(i interface { }) (uint64, string);
export func unreflect(uint64, string) (ret interface { });
......
......@@ -22,7 +22,9 @@ char *sysimport =
"export func sys.arraystring (? *[]uint8) (? string)\n"
"export func sys.ifaceT2I (sigi *uint8, sigt *uint8, elem any) (ret any)\n"
"export func sys.ifaceI2T (sigt *uint8, iface any) (ret any)\n"
"export func sys.ifaceI2T2 (sigt *uint8, iface any) (ret any, ok bool)\n"
"export func sys.ifaceI2I (sigi *uint8, iface any) (ret any)\n"
"export func sys.ifaceI2I2 (sigi *uint8, iface any) (ret any, ok bool)\n"
"export func sys.ifaceeq (i1 any, i2 any) (ret bool)\n"
"export func sys.reflect (i interface { }) (? uint64, ? string)\n"
"export func sys.unreflect (? uint64, ? string) (ret interface { })\n"
......
......@@ -238,8 +238,6 @@ sys·ifaceT2I(Sigi *si, Sigt *st, void *elem, Map *retim, void *retit)
void
sys·ifaceI2T(Sigt *st, Map *im, void *it, void *ret)
{
// int32 alg, wid;
if(debug) {
prints("I2T sigt=");
printsigt(st);
......@@ -250,22 +248,44 @@ sys·ifaceI2T(Sigt *st, Map *im, void *it, void *ret)
if(im == nil)
throw("ifaceI2T: nil map");
if(im->sigt != st)
throw("ifaceI2T: wrong type");
// alg = st->hash;
// wid = st->offset;
// algarray[alg].copy(wid, &ret, &it);
ret = it;
if(debug) {
prints("I2T ret=");
sys·printpointer(ret);
prints("\n");
}
FLUSH(&ret);
}
// ifaceI2T2(sigt *byte, iface any) (ret any, ok bool);
void
sys·ifaceI2T2(Sigt *st, Map *im, void *it, void *ret, bool ok)
{
if(debug) {
prints("I2T2 sigt=");
printsigt(st);
prints(" iface=");
printiface(im, it);
prints("\n");
}
if(im == nil || im->sigt != st) {
ret = 0;
ok = 0;
} else {
ret = it;
ok = 1;
}
if(debug) {
prints("I2T2 ret=");
sys·printpointer(ret);
sys·printbool(ok);
prints("\n");
}
FLUSH(&ret);
FLUSH(&ok);
}
// ifaceI2I(sigi *byte, iface any) (ret any);
......@@ -302,6 +322,49 @@ sys·ifaceI2I(Sigi *si, Map *im, void *it, Map *retim, void *retit)
FLUSH(&retit);
}
// ifaceI2I2(sigi *byte, iface any) (ret any, ok bool);
void
sys·ifaceI2I2(Sigi *si, Map *im, void *it, Map *retim, void *retit, bool ok)
{
if(debug) {
prints("I2I2 sigi=");
printsigi(si);
prints(" iface=");
printiface(im, it);
prints("\n");
}
if(im == nil) {
// If incoming interface is uninitialized (zeroed)
// make the outgoing interface zeroed as well.
retim = nil;
retit = nil;
ok = 1;
} else {
retit = it;
retim = im;
ok = 1;
if(im->sigi != si) {
retim = hashmap(si, im->sigt, 1);
if(retim == nil) {
retit = nil;
retim = nil;
ok = 0;
}
}
}
if(debug) {
prints("I2I ret=");
printiface(retim, retit);
prints("\n");
}
FLUSH(&retim);
FLUSH(&retit);
FLUSH(&ok);
}
// ifaceeq(i1 any, i2 any) (ret bool);
void
sys·ifaceeq(Map *im1, void *it1, Map *im2, void *it2, byte ret)
......
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