1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-13 09:30:24 -08:00

Implementing nextmethod and replacing all uses of superclass with it.

Copied from Perforce
 Change: 190935
 ServerID: perforce.ravenbrook.com
This commit is contained in:
Richard Brooksby 2016-04-11 16:54:39 +01:00
parent bfa333b5c0
commit 309fb8ec64
15 changed files with 70 additions and 63 deletions

View file

@ -284,7 +284,7 @@ static Res ClientArenaCreate(Arena *arenaReturn, ArgList args)
arena = CouldBeA(AbstractArena, clientArena);
/* <code/arena.c#init.caller> */
res = SUPERCLASS(Arena, ClientArena)->init(arena, grainSize, args);
res = NextMethod(Arena, ClientArena, init)(arena, grainSize, args);
if (res != ResOK)
goto failSuperInit;
SetClassOfArena(arena, CLASS(ClientArena));
@ -311,7 +311,7 @@ static Res ClientArenaCreate(Arena *arenaReturn, ArgList args)
return ResOK;
failChunkCreate:
SUPERCLASS(Arena, ClientArena)->finish(arena);
NextMethod(Arena, ClientArena, finish)(arena);
failSuperInit:
AVER(res != ResOK);
return res;
@ -336,7 +336,7 @@ static void ClientArenaDestroy(Arena arena)
AVER(arena->reserved == 0);
AVER(arena->committed == 0);
SUPERCLASS(Arena, ClientArena)->finish(arena); /* <code/arena.c#finish.caller> */
NextMethod(Arena, ClientArena, finish)(arena); /* <code/arena.c#finish.caller> */
}

View file

@ -206,7 +206,7 @@ static Res VMArenaDescribe(Arena arena, mps_lib_FILE *stream, Count depth)
/* ...but the next method is ArenaTrivDescribe, so don't call it;
* see impl.c.arena#describe.triv.dont-upcall.
*
res = SUPERCLASS(Arena, VMArena)->describe(arena, stream);
res = NextMethod(Arena, VMArena, describe)(arena, stream);
if (res != ResOK)
return res;
*
@ -554,7 +554,7 @@ static Res VMArenaCreate(Arena *arenaReturn, ArgList args)
arena = VMArena2Arena(vmArena);
/* <code/arena.c#init.caller> */
res = SUPERCLASS(Arena, VMArena)->init(arena, grainSize, args);
res = NextMethod(Arena, VMArena, init)(arena, grainSize, args);
if (res != ResOK)
goto failArenaInit;
SetClassOfArena(arena, CLASS(VMArena));
@ -608,7 +608,7 @@ static Res VMArenaCreate(Arena *arenaReturn, ArgList args)
return ResOK;
failChunkCreate:
SUPERCLASS(Arena, VMArena)->finish(arena);
NextMethod(Arena, VMArena, finish)(arena);
failArenaInit:
VMUnmap(vm, VMBase(vm), VMLimit(vm));
failVMMap:
@ -646,7 +646,7 @@ static void VMArenaDestroy(Arena arena)
vmArena->sig = SigInvalid;
SUPERCLASS(Arena, VMArena)->finish(arena); /* <code/global.c#finish.caller> */
NextMethod(Arena, VMArena, finish)(arena); /* <code/global.c#finish.caller> */
/* Copy VM descriptor to stack-local storage so that we can continue
* using the descriptor after the VM has been unmapped. */

View file

@ -1233,7 +1233,7 @@ static Res segBufInit(Buffer buffer, Pool pool, Bool isMutator, ArgList args)
Res res;
/* Initialize the superclass fields first via next-method call */
res = SUPERCLASS(Buffer, SegBuf)->init(buffer, pool, isMutator, args);
res = NextMethod(Buffer, SegBuf, init)(buffer, pool, isMutator, args);
if (res != ResOK)
return res;
SetClassOfBuffer(buffer, CLASS(SegBuf));
@ -1257,7 +1257,7 @@ static void segBufFinish(Buffer buffer)
SegBuf segbuf = MustBeA(SegBuf, buffer);
AVER(BufferIsReset(buffer));
segbuf->sig = SigInvalid;
SUPERCLASS(Buffer, SegBuf)->finish(buffer);
NextMethod(Buffer, SegBuf, finish)(buffer);
}
@ -1365,7 +1365,7 @@ static Res segBufDescribe(Buffer buffer, mps_lib_FILE *stream, Count depth)
return ResPARAM;
/* Describe the superclass fields first via next-method call */
res = SUPERCLASS(Buffer, SegBuf)->describe(buffer, stream, depth);
res = NextMethod(Buffer, SegBuf, describe)(buffer, stream, depth);
if (res != ResOK)
return res;
@ -1424,7 +1424,7 @@ static Res rankBufInit(Buffer buffer, Pool pool, Bool isMutator, ArgList args)
AVERT(Rank, rank);
/* Initialize the superclass fields first via next-method call */
res = SUPERCLASS(Buffer, RankBuf)->init(buffer, pool, isMutator, args);
res = NextMethod(Buffer, RankBuf, init)(buffer, pool, isMutator, args);
if (res != ResOK)
return res;
SetClassOfBuffer(buffer, CLASS(RankBuf));

View file

@ -226,7 +226,7 @@ static Res cbsInitComm(Land land, LandClass class,
Pool blockPool = NULL;
AVER(land != NULL);
res = SUPERCLASS(Land, CBS)->init(land, arena, alignment, args);
res = NextMethod(Land, CBS, init)(land, arena, alignment, args);
if (res != ResOK)
return res;
@ -302,7 +302,7 @@ static void cbsFinish(Land land)
if (cbs->ownPool)
PoolDestroy(cbsBlockPool(cbs));
SUPERCLASS(Land, CBS)->finish(land); /* FIXME: Method call */
NextMethod(Land, CBS, finish)(land); /* FIXME: Method call */
}
@ -1101,7 +1101,7 @@ static Res cbsDescribe(Land land, mps_lib_FILE *stream, Count depth)
if (stream == NULL)
return ResPARAM;
res = SUPERCLASS(Land, CBS)->describe(land, stream, depth);
res = NextMethod(Land, CBS, describe)(land, stream, depth);
if (res != ResOK)
return res;

View file

@ -35,7 +35,7 @@ static Res failoverInit(Land land, Arena arena, Align alignment, ArgList args)
Res res;
AVER(land != NULL);
res = SUPERCLASS(Land, Failover)->init(land, arena, alignment, args);
res = NextMethod(Land, Failover, init)(land, arena, alignment, args);
if (res != ResOK)
return res;
@ -59,7 +59,7 @@ static void failoverFinish(Land land)
{
Failover fo = MustBeA(Failover, land);
fo->sig = SigInvalid;
SUPERCLASS(Land, Failover)->finish(land); /* FIXME: Method call */
NextMethod(Land, Failover, finish)(land); /* FIXME: Method call */
}
@ -253,7 +253,7 @@ static Res failoverDescribe(Land land, mps_lib_FILE *stream, Count depth)
if (stream == NULL)
return ResPARAM;
res = SUPERCLASS(Land, Failover)->describe(land, stream, depth);
res = NextMethod(Land, Failover, describe)(land, stream, depth);
if (res != ResOK)
return res;

View file

@ -192,7 +192,7 @@ static Res freelistInit(Land land, Arena arena, Align alignment, ArgList args)
Res res;
AVER(land != NULL);
res = SUPERCLASS(Land, Freelist)->init(land, arena, alignment, args);
res = NextMethod(Land, Freelist, init)(land, arena, alignment, args);
if (res != ResOK)
return res;
@ -217,7 +217,7 @@ static void freelistFinish(Land land)
Freelist fl = MustBeA(Freelist, land);
fl->sig = SigInvalid;
fl->list = freelistEND;
SUPERCLASS(Land, Freelist)->finish(land); /* FIXME: Method call */
NextMethod(Land, Freelist, finish)(land); /* FIXME: Method call */
}
@ -758,7 +758,7 @@ static Res freelistDescribe(Land land, mps_lib_FILE *stream, Count depth)
return ResPARAM;
/* FIXME: Should use the class from the land itself. */
res = SUPERCLASS(Land, Freelist)->describe(land, stream, depth);
res = NextMethod(Land, Freelist, describe)(land, stream, depth);
if (res != ResOK)
return res;

View file

@ -137,7 +137,7 @@ static Res AMCSegInit(Seg seg, Pool pool, Addr base, Size size, ArgList args)
amcgen = arg.val.p;
/* Initialize the superclass fields first via next-method call */
res = SUPERCLASS(Seg, amcSeg)->init(seg, pool, base, size, args);
res = NextMethod(Seg, amcSeg, init)(seg, pool, base, size, args);
if(res != ResOK)
return res;
SetClassOfSeg(seg, CLASS(amcSeg));
@ -251,7 +251,7 @@ static Res AMCSegDescribe(Seg seg, mps_lib_FILE *stream, Count depth)
return ResFAIL;
/* Describe the superclass fields first via next-method call */
res = SUPERCLASS(Seg, amcSeg)->describe(seg, stream, depth);
res = NextMethod(Seg, amcSeg, describe)(seg, stream, depth);
if(res != ResOK)
return res;
@ -494,7 +494,7 @@ static Res AMCBufInit(Buffer buffer, Pool pool, Bool isMutator, ArgList args)
forHashArrays = arg.val.b;
/* call next method */
res = SUPERCLASS(Buffer, amcBuf)->init(buffer, pool, isMutator, args);
res = NextMethod(Buffer, amcBuf, init)(buffer, pool, isMutator, args);
if(res != ResOK)
return res;
SetClassOfBuffer(buffer, CLASS(amcBuf));
@ -524,7 +524,7 @@ static void AMCBufFinish(Buffer buffer)
{
amcBuf amcbuf = MustBeA(amcBuf, buffer);
amcbuf->sig = SigInvalid;
SUPERCLASS(Buffer, amcBuf)->finish(buffer);
NextMethod(Buffer, amcBuf, finish)(buffer);
}

View file

@ -223,7 +223,7 @@ static Res AMSSegInit(Seg seg, Pool pool, Addr base, Size size, ArgList args)
AMS ams;
/* Initialize the superclass fields first via next-method call */
res = SUPERCLASS(Seg, AMSSeg)->init(seg, pool, base, size, args);
res = NextMethod(Seg, AMSSeg, init)(seg, pool, base, size, args);
if (res != ResOK)
goto failNextMethod;
SetClassOfSeg(seg, CLASS(AMSSeg));
@ -264,7 +264,7 @@ static Res AMSSegInit(Seg seg, Pool pool, Addr base, Size size, ArgList args)
return ResOK;
failCreateTables:
SUPERCLASS(Seg, AMSSeg)->finish(seg);
NextMethod(Seg, AMSSeg, finish)(seg);
failNextMethod:
AVER(res != ResOK);
return res;
@ -297,7 +297,7 @@ static void AMSSegFinish(Seg seg)
amsseg->sig = SigInvalid;
/* finish the superclass fields last */
SUPERCLASS(Seg, AMSSeg)->finish(seg);
NextMethod(Seg, AMSSeg, finish)(seg);
}
@ -359,7 +359,7 @@ static Res AMSSegMerge(Seg seg, Seg segHi,
goto failCreateTables;
/* Merge the superclass fields via next-method call */
res = SUPERCLASS(Seg, AMSSeg)->merge(seg, segHi, base, mid, limit);
res = NextMethod(Seg, AMSSeg, merge)(seg, segHi, base, mid, limit);
if (res != ResOK)
goto failSuper;
@ -450,7 +450,7 @@ static Res AMSSegSplit(Seg seg, Seg segHi,
/* Split the superclass fields via next-method call */
res = SUPERCLASS(Seg, AMSSeg)->split(seg, segHi, base, mid, limit);
res = NextMethod(Seg, AMSSeg, split)(seg, segHi, base, mid, limit);
if (res != ResOK)
goto failSuper;
@ -536,7 +536,7 @@ static Res AMSSegDescribe(Seg seg, mps_lib_FILE *stream, Count depth)
return ResFAIL;
/* Describe the superclass fields first via next-method call */
res = SUPERCLASS(Seg, AMSSeg)->describe(seg, stream, depth);
res = NextMethod(Seg, AMSSeg, describe)(seg, stream, depth);
if (res != ResOK)
return res;

View file

@ -195,7 +195,7 @@ static Res AWLSegInit(Seg seg, Pool pool, Addr base, Size size, ArgList args)
|| RankSetSingle(RankWEAK) == rankSet);
/* Initialize the superclass fields first via next-method call */
res = SUPERCLASS(Seg, AWLSeg)->init(seg, pool, base, size, args);
res = NextMethod(Seg, AWLSeg, init)(seg, pool, base, size, args);
if (res != ResOK)
goto failSuperInit;
SetClassOfSeg(seg, CLASS(AWLSeg));
@ -240,7 +240,7 @@ failControlAllocAlloc:
failControlAllocScanned:
ControlFree(arena, awlseg->mark, tableSize);
failControlAllocMark:
SUPERCLASS(Seg, AWLSeg)->finish(seg);
NextMethod(Seg, AWLSeg, finish)(seg);
failSuperInit:
AVER(res != ResOK);
return res;
@ -279,7 +279,7 @@ static void AWLSegFinish(Seg seg)
awlseg->sig = SigInvalid;
/* finish the superclass fields last */
SUPERCLASS(Seg, AWLSeg)->finish(seg);
NextMethod(Seg, AWLSeg, finish)(seg);
}

View file

@ -110,7 +110,7 @@ static Res loSegInit(Seg seg, Pool pool, Addr base, Size size, ArgList args)
void *p;
/* Initialize the superclass fields first via next-method call */
res = SUPERCLASS(Seg, LOSeg)->init(seg, pool, base, size, args);
res = NextMethod(Seg, LOSeg, init)(seg, pool, base, size, args);
if(res != ResOK)
goto failSuperInit;
SetClassOfSeg(seg, CLASS(LOSeg));
@ -146,7 +146,7 @@ static Res loSegInit(Seg seg, Pool pool, Addr base, Size size, ArgList args)
failAllocTable:
ControlFree(arena, loseg->mark, tablebytes);
failMarkTable:
SUPERCLASS(Seg, LOSeg)->finish(seg);
NextMethod(Seg, LOSeg, finish)(seg);
failSuperInit:
AVER(res != ResOK);
return res;
@ -179,7 +179,7 @@ static void loSegFinish(Seg seg)
loseg->sig = SigInvalid;
/* finish the superclass fields last */
SUPERCLASS(Seg, LOSeg)->finish(seg);
NextMethod(Seg, LOSeg, finish)(seg);
}

View file

@ -227,7 +227,7 @@ static Res MRGLinkSegInit(Seg seg, Pool pool, Addr base, Size size,
Res res;
/* Initialize the superclass fields first via next-method call */
res = SUPERCLASS(Seg, MRGLinkSeg)->init(seg, pool, base, size, args);
res = NextMethod(Seg, MRGLinkSeg, init)(seg, pool, base, size, args);
if (res != ResOK)
return res;
SetClassOfSeg(seg, CLASS(MRGLinkSeg));
@ -267,7 +267,7 @@ static Res MRGRefSegInit(Seg seg, Pool pool, Addr base, Size size, ArgList args)
linkseg = arg.val.p;
/* Initialize the superclass fields first via next-method call */
res = SUPERCLASS(Seg, MRGRefSeg)->init(seg, pool, base, size, args);
res = NextMethod(Seg, MRGRefSeg, init)(seg, pool, base, size, args);
if (res != ResOK)
return res;
SetClassOfSeg(seg, CLASS(MRGRefSeg));

View file

@ -119,7 +119,7 @@ static Res SNCBufInit(Buffer buffer, Pool pool, Bool isMutator, ArgList args)
Res res;
/* call next method */
res = SUPERCLASS(Buffer, SNCBuf)->init(buffer, pool, isMutator, args);
res = NextMethod(Buffer, SNCBuf, init)(buffer, pool, isMutator, args);
if (res != ResOK)
return res;
SetClassOfBuffer(buffer, CLASS(SNCBuf));
@ -145,7 +145,7 @@ static void SNCBufFinish(Buffer buffer)
sncbuf->sig = SigInvalid;
SUPERCLASS(Buffer, SNCBuf)->finish(buffer);
NextMethod(Buffer, SNCBuf, finish)(buffer);
}
@ -205,7 +205,7 @@ static Res sncSegInit(Seg seg, Pool pool, Addr base, Size size, ArgList args)
Res res;
/* Initialize the superclass fields first via next-method call */
res = SUPERCLASS(Seg, SNCSeg)->init(seg, pool, base, size, args);
res = NextMethod(Seg, SNCSeg, init)(seg, pool, base, size, args);
if (res != ResOK)
return res;
SetClassOfSeg(seg, CLASS(SNCSeg));

View file

@ -189,26 +189,32 @@ extern void InstFinish(Inst inst);
BEGIN MustBeA(Inst, inst)->class = (InstClass)(_class); END
/* SUPERCLASS - get the superclass object, given a class name
/* NextMethod -- call a method in the superclass
*
* See design.mps.protocol.int.static-superclass.
*
* TODO: Several experiments with statically generating some kind of
* SUPERCLASS lookup have failed because the names of types, classes,
* and the hierarchy are inconsistent. Revisit this later.
*
* FIXME: Most uses of SUPERCLASS compile to constant expressions, but
* not that the compiler can tell.
* TODO: All uses of NextMethod are statically known, but several
* experiments with statically generating some kind of SUPERCLASS
* lookup have failed because the names of types, classes, and the
* hierarchy are inconsistent. Revisit this later.
*/
#define SUPERCLASS(kind, ident) \
((CLASS_TYPE(kind))((InstClass)CLASS(ident))->superclass)
#define NextMethod(kind, ident, meth) (SUPERCLASS(kind, ident)->meth)
/* IsA, CouldBeA, MustBeA -- coerce instances safely
/* IsA, CouldBeA, MustBeA -- coerce instances
*
* FIXME: Wrap mps_lib_assert_fail_expr in check.h so that it is
* elided from some varieties.
* CouldBeA converts an instance to another class without checking.
* It is intended to be equivalent to the C++ "static_cast", although
* since this is C there is no actual static checking, so in fact it's
* more like "reinterpret_cast".
*
* MustBeA converts an instance to another class, but checks that the
* object is a subclass, causing an assertion if not (depending on
* build variety). It is like C++ "dynamic_cast" with an assert.
*/
#define CouldBeA(class, inst) ((INST_TYPE(class))inst)
@ -230,6 +236,7 @@ extern void InstFinish(Inst inst);
#define MustBeA_CRITICAL(_class, inst) \
CouldBeA(_class, AVERP_CRITICAL(IsNonNullAndA(_class, inst), inst))
/* ClassOf* -- get the class of an instance */
#define CLASS_DECLARE_CLASSOF(prefix, ident, kind, super) \

View file

@ -1067,7 +1067,7 @@ static Res gcSegInit(Seg seg, Pool pool, Addr base, Size size, ArgList args)
Res res;
/* Initialize the superclass fields first via next-method call */
res = SUPERCLASS(Seg, GCSeg)->init(seg, pool, base, size, args);
res = NextMethod(Seg, GCSeg, init)(seg, pool, base, size, args);
if (ResOK != res)
return res;
SetClassOfSeg(seg, CLASS(GCSeg));
@ -1108,7 +1108,7 @@ static void gcSegFinish(Seg seg)
RingFinish(&gcseg->greyRing);
/* finish the superclass fields last */
SUPERCLASS(Seg, GCSeg)->finish(seg);
NextMethod(Seg, GCSeg, finish)(seg);
}
@ -1443,7 +1443,7 @@ static Res gcSegMerge(Seg seg, Seg segHi,
}
/* Merge the superclass fields via next-method call */
res = SUPERCLASS(Seg, GCSeg)->merge(seg, segHi, base, mid, limit);
res = NextMethod(Seg, GCSeg, merge)(seg, segHi, base, mid, limit);
if (res != ResOK)
goto failSuper;
@ -1503,7 +1503,7 @@ static Res gcSegSplit(Seg seg, Seg segHi,
}
/* Split the superclass fields via next-method call */
res = SUPERCLASS(Seg, GCSeg)->split(seg, segHi, base, mid, limit);
res = NextMethod(Seg, GCSeg, split)(seg, segHi, base, mid, limit);
if (res != ResOK)
goto failSuper;
@ -1547,7 +1547,7 @@ static Res gcSegDescribe(Seg seg, mps_lib_FILE *stream, Count depth)
return ResFAIL;
/* Describe the superclass fields first via next-method call */
res = SUPERCLASS(Seg, GCSeg)->describe(seg, stream, depth);
res = NextMethod(Seg, GCSeg, describe)(seg, stream, depth);
if (res != ResOK)
return res;

View file

@ -119,7 +119,7 @@ static Res amstSegInit(Seg seg, Pool pool, Addr base, Size size, ArgList args)
Res res;
/* Initialize the superclass fields first via next-method call */
res = SUPERCLASS(Seg, AMSTSeg)->init(seg, pool, base, size, args);
res = NextMethod(Seg, AMSTSeg, init)(seg, pool, base, size, args);
if (res != ResOK)
return res;
SetClassOfSeg(seg, CLASS(AMSTSeg));
@ -157,7 +157,7 @@ static void amstSegFinish(Seg seg)
amstseg->sig = SigInvalid;
/* finish the superclass fields last */
SUPERCLASS(Seg, AMSTSeg)->finish(seg);
NextMethod(Seg, AMSTSeg, finish)(seg);
}
@ -187,7 +187,7 @@ static Res amstSegMerge(Seg seg, Seg segHi,
amst = PoolAMST(SegPool(seg));
/* Merge the superclass fields via direct next-method call */
res = SUPERCLASS(Seg, AMSTSeg)->merge(seg, segHi, base, mid, limit);
res = NextMethod(Seg, AMSTSeg, merge)(seg, segHi, base, mid, limit);
if (res != ResOK)
goto failSuper;
@ -206,7 +206,7 @@ static Res amstSegMerge(Seg seg, Seg segHi,
failDeliberate:
/* Call the anti-method (see .fail) */
res = SUPERCLASS(Seg, AMSTSeg)->split(seg, segHi, base, mid, limit);
res = NextMethod(Seg, AMSTSeg, split)(seg, segHi, base, mid, limit);
AVER(res == ResOK);
res = ResFAIL;
failSuper:
@ -233,7 +233,7 @@ static Res amstSegSplit(Seg seg, Seg segHi,
amst = PoolAMST(SegPool(seg));
/* Split the superclass fields via direct next-method call */
res = SUPERCLASS(Seg, AMSTSeg)->split(seg, segHi, base, mid, limit);
res = NextMethod(Seg, AMSTSeg, split)(seg, segHi, base, mid, limit);
if (res != ResOK)
goto failSuper;
@ -256,7 +256,7 @@ static Res amstSegSplit(Seg seg, Seg segHi,
failDeliberate:
/* Call the anti-method. (see .fail) */
res = SUPERCLASS(Seg, AMSTSeg)->merge(seg, segHi, base, mid, limit);
res = NextMethod(Seg, AMSTSeg, merge)(seg, segHi, base, mid, limit);
AVER(res == ResOK);
res = ResFAIL;
failSuper:
@ -536,7 +536,7 @@ static Res AMSTBufferFill(Addr *baseReturn, Addr *limitReturn,
amst = PoolAMST(pool);
/* call next method */
res = SUPERCLASS(Pool, AMSTPool)->bufferFill(&base, &limit, pool, buffer, size);
res = NextMethod(Pool, AMSTPool, bufferFill)(&base, &limit, pool, buffer, size);
if (res != ResOK)
return res;