diff --git a/mps/code/mpm.h b/mps/code/mpm.h index ac2ce21891c..39c871233e3 100644 --- a/mps/code/mpm.h +++ b/mps/code/mpm.h @@ -290,8 +290,8 @@ extern PoolDebugMixin PoolNoDebugMixin(Pool pool); extern BufferClass PoolNoBufferClass(void); extern Size PoolNoSize(Pool pool); -#define ClassOfPool(pool) ((PoolClass)(pool)->instStruct.class) -#define SetClassOfPool(pool, _class) BEGIN (pool)->instStruct.class = (InstClass)(_class); END +#define ClassOfPool(pool) ((PoolClass)ClassOfPoly(pool)) +#define SetClassOfPool SetClassOfPoly #define SuperclassOfPool(pool) \ ((PoolClass)InstClassSuperclassPoly(ClassOfPool(pool))) @@ -684,8 +684,8 @@ DECLARE_CLASS(Seg, Seg); DECLARE_CLASS(Seg, GCSeg); extern void SegClassMixInNoSplitMerge(SegClass class); -#define ClassOfSeg(seg) ((SegClass)(seg)->instStruct.class) -#define SetClassOfSeg(seg, _class) BEGIN (seg)->instStruct.class = (InstClass)(_class); END +#define ClassOfSeg(seg) ((SegClass)ClassOfPoly(seg)) +#define SetClassOfSeg SetClassOfPoly extern Size SegSize(Seg seg); extern Addr (SegBase)(Seg seg); @@ -796,8 +796,8 @@ DECLARE_CLASS(Buffer, Buffer); DECLARE_CLASS(Buffer, SegBuf); DECLARE_CLASS(Buffer, RankBuf); -#define ClassOfBuffer(buffer) ((BufferClass)(buffer)->instStruct.class) -#define SetClassOfBuffer(buffer, class) BEGIN (buffer)->instStruct.class = (InstClass)(class); END +#define ClassOfBuffer(buffer) ((BufferClass)ClassOfPoly(buffer)) +#define SetClassOfBuffer SetClassOfPoly extern AllocPattern AllocPatternRamp(void); extern AllocPattern AllocPatternRampCollectAll(void); @@ -991,8 +991,8 @@ extern Bool LandFlush(Land dest, Land src); extern Size LandSlowSize(Land land); extern Bool LandClassCheck(LandClass class); DECLARE_CLASS(Land, Land); -#define ClassOfLand(land) ((LandClass)(land)->instStruct.class) -#define SetClassOfLand(land, _class) BEGIN (land)->instStruct.class = (InstClass)(_class); END +#define ClassOfLand(land) ((LandClass)ClassOfPoly(land)) +#define SetClassOfLand SetClassOfPoly /* STATISTIC -- gather statistics (in some varieties) diff --git a/mps/code/protocol.h b/mps/code/protocol.h index 2a031e2fec8..44d8962a217 100644 --- a/mps/code/protocol.h +++ b/mps/code/protocol.h @@ -80,7 +80,12 @@ typedef enum ClassIdEnum { ClassIdLIMIT } ClassIdEnum; -/* ClassLevelEnum -- depth of class in hierarchy */ + +/* ClassLevelEnum -- depth of class in hierarchy + * + * This defines enum constants like ClassLevelLand equal to the + * distance from the root of the class hierarchy. + */ #define CLASS_LEVEL_ENUM(prefix, ident, kind, super) prefix ## ident = prefix ## super + 1, typedef enum ClassLevelEnum { @@ -90,7 +95,12 @@ typedef enum ClassLevelEnum { } ClassLevelEnum; -/* INHERIT_CLASS -- the standard macro for inheriting from a superclass */ +/* INHERIT_CLASS -- inheriting from a superclass + * + * This macro is used at the start of a class definition to inherit + * the superclass and override the fields essential to the + * workings of the protocol. + */ #define INHERIT_CLASS(this, _class, super) \ BEGIN \ @@ -104,11 +114,13 @@ typedef enum ClassLevelEnum { END -#define InstClassSig ((Sig)0x519B60C7) /* SIGnature PROtocol CLass */ -#define InstSig ((Sig)0x519B6014) /* SIGnature PROtocol INst */ - - -/* Inst -- the instance structure for support of the protocol */ +/* Inst -- the instance structure for support of the protocol + * + * An InstStruct named instStruct must be the first field of any + * instance structure using the protocol, because the protocol uses + * casting between structures with common prefixes to implement + * polymorphism. + */ typedef struct InstStruct *Inst; typedef struct InstClassStruct *InstClass; @@ -120,15 +132,16 @@ typedef struct InstStruct { /* InstClass -- the class containing the support for the protocol */ -typedef const char *InstClassName; -typedef unsigned long ProtocolTypeId; +typedef const char *ClassName; typedef unsigned char ClassId; typedef unsigned char ClassLevel; #define ClassDEPTH 8 /* maximum depth of class hierarchy */ +#define InstClassSig ((Sig)0x519B60C7) /* SIGnature PROtocol CLass */ + typedef struct InstClassStruct { Sig sig; /* */ - InstClassName name; /* human readable name such as "Land" */ + ClassName name; /* human readable name such as "Land" */ InstClass superclass; /* pointer to direct superclass */ ClassLevel level; /* distance from root of class hierarchy */ ClassId display[ClassDEPTH]; /* ids of classes at this level and above */ @@ -156,7 +169,10 @@ extern Bool InstCheck(Inst pro); #define InstClassSuperclassPoly(class) \ (((InstClass)(class))->superclass) -#define ClassOfPoly(inst) (MustBeA(Inst, inst)->class) +/* FIXME: Try MustBeA here. */ +#define ClassOfPoly(inst) (CouldBeA(Inst, inst)->class) +#define SetClassOfPoly(inst, _class) \ + BEGIN CouldBeA(Inst, inst)->class = (InstClass)(_class); END /* SUPERCLASS - get the superclass object, given a class name