Skip to content

Commit

Permalink
CogVM source as per VMMaker.oscog-eem.3354
Browse files Browse the repository at this point in the history
Get rid of the vile hack that assigned multipleBytecodeSetsActive in the
function imageFormatVersionFromSnapshot: used from the testing readableImage:
(!!, this is really bad pratice ;-) ).

Refactor checkImageVersionFrom:startingAt: into
checkImageVersionFrom:startingAt:assignRawVersion: & bailOutOfImageLoad:,
decoupling the abort exit message from the image load check (the former
assumes a console VM, waiting for a carriage return, which is dubious).
  • Loading branch information
eliotmiranda committed Mar 22, 2024
1 parent 6c62b74 commit 6641c9d
Show file tree
Hide file tree
Showing 39 changed files with 2,063 additions and 2,609 deletions.
173 changes: 76 additions & 97 deletions src/spur32.cog.lowcode/cointerp.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/spur32.cog.lowcode/cointerp.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Automatically generated by
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.3353 uuid: 860ea747-484d-4072-8047-3b45e4687175
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.3354 uuid: 67b625b4-ae15-4b1d-a144-7fd52510caf2
*/


Expand Down
173 changes: 76 additions & 97 deletions src/spur32.cog.lowcode/gcc3x-cointerp.c

Large diffs are not rendered by default.

171 changes: 75 additions & 96 deletions src/spur32.cog/cointerp.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* Automatically generated by
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.3353 uuid: 860ea747-484d-4072-8047-3b45e4687175
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.3354 uuid: 67b625b4-ae15-4b1d-a144-7fd52510caf2
from
CoInterpreter VMMaker.oscog-eem.3353 uuid: 860ea747-484d-4072-8047-3b45e4687175
CoInterpreter VMMaker.oscog-eem.3354 uuid: 67b625b4-ae15-4b1d-a144-7fd52510caf2
*/
static char __buildInfo[] = "CoInterpreter VMMaker.oscog-eem.3353 uuid: 860ea747-484d-4072-8047-3b45e4687175 " __DATE__ ;
static char __buildInfo[] = "CoInterpreter VMMaker.oscog-eem.3354 uuid: 67b625b4-ae15-4b1d-a144-7fd52510caf2 " __DATE__ ;
char *__interpBuildInfo = __buildInfo;


Expand Down Expand Up @@ -1415,7 +1415,7 @@ static sqInt NeverInline checkDeliveryOfLongRunningPrimitiveSignal(void);
extern sqInt checkedIntegerValueOf(sqInt intOop);
static sqInt NoDbgRegParms checkForEventsMayContextSwitch(sqInt mayContextSwitch);
extern sqInt checkImageHeaderFromBytesAndSize(char *bytes, sqInt totalSize);
static sqInt NoDbgRegParms checkImageVersionFromstartingAt(sqImageFile f, squeakFileOffsetType imageOffset);
static sqInt NoDbgRegParms checkImageVersionFromstartingAtassignRawVersion(sqImageFile f, squeakFileOffsetType imageOffset, sqInt *rawVersionPtr);
static sqInt checkInterpreterIntegrity(void);
static sqInt NoDbgRegParms checkIsStillMarriedContextcurrentFP(sqInt aContext, char *currentFP);
extern sqInt checkOkayInterpreterObjects(sqInt writeBack);
Expand Down Expand Up @@ -1489,7 +1489,6 @@ static sqInt getSnapshotScreenSize(void);
extern sqInt * getStackPointer(void);
extern sqInt getThisSessionID(void);
extern FILE * getTranscript(void);
static sqInt NoDbgRegParms getWord32FromFileswap(sqImageFile aFile, sqInt swapFlag);
static sqInt NoDbgRegParms handleForwardedSelectorFaultFor(sqInt selectorOop);
static sqInt NoDbgRegParms handleForwardedSendFaultForTag(sqInt classTag);
static sqInt NoDbgRegParms handleSpecialSelectorSendFaultForfpsp(sqInt obj, char *theFP, char *theSP);
Expand All @@ -1499,7 +1498,6 @@ extern sqInt highBit(usqInt anUnsignedValue);
static sqInt NoDbgRegParms ifCurrentStackPageHasValidHeadPointers(StackPage *thePage);
static usqInt NoDbgRegParms iframeMethod(char *theFP);
static sqInt imageFormatVersionForSnapshot(void);
static sqInt NoDbgRegParms imageFormatVersionFromSnapshot(sqInt imageVersion);
extern sqInt includesBehaviorThatOf(sqInt aClass, sqInt aSuperclass);
extern void ioFilenamefromStringofLengthresolveAliases(char *aCharBuffer, char *aFilenameString, sqInt filenameLength, sqInt aBoolean);
static sqInt NoDbgRegParms isBaseFrame(char *theFP);
Expand Down Expand Up @@ -2678,7 +2676,7 @@ sqInt debugCallbackReturns;
sqInt suppressHeartbeatFlag;
sqInt cannotDeferDisplayUpdates;
sqInt checkedPluginName;
const char *interpreterVersion = "Open Smalltalk Cog[Spur] VM [CoInterpreterPrimitives VMMaker.oscog-eem.3353]";
const char *interpreterVersion = "Open Smalltalk Cog[Spur] VM [CoInterpreterPrimitives VMMaker.oscog-eem.3354]";
sqInt minBackwardJumpCountForCompile = MinBackwardJumpCountForCompile /* 40 */;
char expensiveAsserts = 0;
int (*showSurfaceFn)(sqIntptr_t, int, int, int, int);
Expand Down Expand Up @@ -19158,7 +19156,7 @@ mnuMethodOrNilFor(sqInt rcvr)
{ DECL_MAYBE_SQ_GLOBAL_STRUCT
sqInt currentClass;
sqInt dictionary;
usqInt index;
sqInt index;
usqInt length;
sqInt mask;
sqInt methodArray;
Expand Down Expand Up @@ -19207,7 +19205,7 @@ mnuMethodOrNilFor(sqInt rcvr)
wrapAround = 0;
while (1) {
/* begin fetchPointer:ofObject: */
nextSelector = longAt((dictionary + BaseHeaderSize) + (index << (shiftForWord())));
nextSelector = longAt((dictionary + BaseHeaderSize) + (((sqInt)((usqInt)(index) << (shiftForWord())))));
if (nextSelector == GIV(nilObj)) {
mnuMethod = null;
goto l11;
Expand All @@ -19225,7 +19223,7 @@ mnuMethodOrNilFor(sqInt rcvr)
}
methodArray = objOop;
/* begin followField:ofObject: */
objOop1 = longAt((methodArray + BaseHeaderSize) + ((index - SelectorStart) << (shiftForWord())));
objOop1 = longAt((methodArray + BaseHeaderSize) + (((sqInt)((usqInt)((index - SelectorStart)) << (shiftForWord())))));
if (((!(objOop1 & (tagMask()))))
&& ((!((longAt(objOop1)) & ((classIndexMask()) - (isForwardedObjectClassIndexPun())))))) {
objOop1 = fixFollowedFieldofObjectwithInitialValue(index - SelectorStart, methodArray, objOop1);
Expand Down Expand Up @@ -20892,8 +20890,10 @@ readImageFromFileHeapSizeStartingAt(sqImageFile f, usqInt desiredHeapSize, squea
usqInt numSlots;
sqInt objOop;
sqInt oop;
sqInt rawVersion;
sqInt seed;
sqInt swapBytes;
int swapBytes;
sqInt version;
sqInt w;
int w1;
unsigned short w10;
Expand All @@ -20909,6 +20909,7 @@ readImageFromFileHeapSizeStartingAt(sqImageFile f, usqInt desiredHeapSize, squea
int w8;
unsigned short w9;

rawVersion = 0;

/* stdout is not available at compile time. this is the earliest available point. */
GIV(transcript) = stdout;
Expand All @@ -20918,7 +20919,30 @@ readImageFromFileHeapSizeStartingAt(sqImageFile f, usqInt desiredHeapSize, squea

/* guess (Class instVarIndexFor: 'name' ifAbsent: []) - 1 */
GIV(classNameIndex) = 6;
swapBytes = checkImageVersionFromstartingAt(f, imageOffset);
version = checkImageVersionFromstartingAtassignRawVersion(f, imageOffset, (&rawVersion));
if (version == 0) {
/* begin bailOutOfImageLoad: */
fprintf(GIV(transcript), "This interpreter (vers. ");
/* begin printNum: */
fprintf(GIV(transcript),
"%" PRIdSQINT "",
((sqInt)6521 /* imageFormatVersion */));
/* begin print: */
fprintf(GIV(transcript), ") cannot read image file (vers. ");
/* begin printNum: */
fprintf(GIV(transcript),
"%" PRIdSQINT "",
((sqInt)rawVersion));
/* begin print: */
fprintf(GIV(transcript), ").");
cr();
/* begin print: */
fprintf(GIV(transcript), "Press CR to quit...");
getchar();
ioExitWithErrorCode(1);
}
swapBytes = rawVersion != version;
GIV(multipleBytecodeSetsActive) = ((version & MultipleBytecodeSetsBitmask) != 0);

/* record header start position */
headerStart = (sqImageFilePosition(f)) - 4;
Expand Down Expand Up @@ -33361,7 +33385,7 @@ primitiveInvokeObjectAsMethod(void)
{ DECL_MAYBE_SQ_GLOBAL_STRUCT
sqInt i;
sqInt lookupClassTag;
sqInt runArgs;
usqInt runArgs;
sqInt runReceiver;
char *sp;
char *sp1;
Expand Down Expand Up @@ -51046,12 +51070,12 @@ loadImageSegmentFromoutPointers(sqInt segmentWordArray, sqInt outPointerArray)
return PrimErrBadArgument;
}
segVersion = longAt(segmentWordArray + BaseHeaderSize);
if (!((imageFormatVersionFromSnapshot(segVersion & 0xFFFFFF)) == 6521 /* imageFormatVersion */)) {
if (!(((((segVersion & 0xFFFFFF) | MultipleBytecodeSetsBitmask) - MultipleBytecodeSetsBitmask)) == 6521 /* imageFormatVersion */)) {

/* low 3 bytes */
reverseBytesIn32BitWordsIn(segmentWordArray);
segVersion = longAt(segmentWordArray + BaseHeaderSize);
if (!((imageFormatVersionFromSnapshot(segVersion & 0xFFFFFF)) == 6521 /* imageFormatVersion */)) {
if (!(((((segVersion & 0xFFFFFF) | MultipleBytecodeSetsBitmask) - MultipleBytecodeSetsBitmask)) == 6521 /* imageFormatVersion */)) {

/* low 3 bytes */
reverseBytesIn32BitWordsIn(segmentWordArray);
Expand Down Expand Up @@ -60588,7 +60612,7 @@ updatePointersInsavedFirstFieldPointer(sqInt obj, sqInt firstFieldPtr)
assert((ReceiverIndex + ((sp >> 1))) < (lengthOf(obj)));
contextSize = (sp >> 1);
l6: /* end fetchStackPointerOf: */;
numPointerSlots = CtxtTempFrameStart + contextSize;
numPointerSlots = ((usqInt) (CtxtTempFrameStart + contextSize));
goto l10;
}
/* begin numSlotsOf: */
Expand Down Expand Up @@ -60618,7 +60642,7 @@ updatePointersInsavedFirstFieldPointer(sqInt obj, sqInt firstFieldPtr)
/* begin literalCountOfMethodHeader: */
assert((header & 1));
numLiterals = ((header >> 1)) & AlternateHeaderNumLiteralsMask;
numPointerSlots = numLiterals + LiteralStart;
numPointerSlots = ((usqInt) (numLiterals + LiteralStart));
l10: /* end numPointerSlotsWhileCompactingOf:withFormat:savedFirstFieldPointer: */;
if ((fmt <= 5 /* lastPointerFormat */)
&& (numPointerSlots > 0)) {
Expand Down Expand Up @@ -61170,7 +61194,7 @@ prepareForSnapshot(void)
sqInt limit;
sqInt newEndOfMemory;
sqInt next;
usqInt node;
sqInt node;
SpurSegmentInfo *seg;
sqInt smallChild;
sqInt treeNode;
Expand Down Expand Up @@ -62262,8 +62286,8 @@ checkImageHeaderFromBytesAndSize(char *bytes, sqInt totalSize)
version = long32At(bytes);
headerSize = longAt(bytes + 4);
dataSize = longAt((bytes + 4) + BytesPerWord);
if (!((imageFormatVersionFromSnapshot(version)) == 6521 /* imageFormatVersion */)) {
if (!((imageFormatVersionFromSnapshot(SQ_SWAP_4_BYTES(version))) == 6521 /* imageFormatVersion */)) {
if (!((((version | MultipleBytecodeSetsBitmask) - MultipleBytecodeSetsBitmask)) == 6521 /* imageFormatVersion */)) {
if (!(((((SQ_SWAP_4_BYTES(version)) | MultipleBytecodeSetsBitmask) - MultipleBytecodeSetsBitmask)) == 6521 /* imageFormatVersion */)) {
return 0;
}
/* begin byteSwapped: */
Expand All @@ -62276,38 +62300,41 @@ checkImageHeaderFromBytesAndSize(char *bytes, sqInt totalSize)
}


/* Read and verify the image file version number and return true if the the
given image file needs to be byte-swapped. As a side effect, position the
file stream just after the version number of the image header. This code
prints a warning and does a hard-exit if it cannot find a valid version
number.
*/
/* This code is based on C code by Ian Piumarta. */
/* Read and verify the image file version number and answer it.
Assign through rawVersionPtr the unswapped version number. The caller can
then infer if the given image file needs to be byte-swapped by seeing if
the returned value
equals tha assigned through rawVersionPtr.
0 is answered if no valid version could be found. */

/* StackInterpreter>>#checkImageVersionFrom:startingAt: */
/* StackInterpreter>>#checkImageVersionFrom:startingAt:assignRawVersion: */
static sqInt NoDbgRegParms
checkImageVersionFromstartingAt(sqImageFile f, squeakFileOffsetType imageOffset)
{ DECL_MAYBE_SQ_GLOBAL_STRUCT
sqInt firstVersion;
checkImageVersionFromstartingAtassignRawVersion(sqImageFile f, squeakFileOffsetType imageOffset, sqInt *rawVersionPtr)
{
sqInt version;
int w;
int w1;
int w2;
int w3;


/* check the version number */
sqImageFileSeek(f, imageOffset);
version = (firstVersion = getWord32FromFileswap(f, 0));
if ((imageFormatVersionFromSnapshot(version)) == 6521 /* imageFormatVersion */) {
return 0;
}
sqImageFileSeek(f, imageOffset);
/* begin getWord32FromFile:swap: */
w2 = 0;
sqImageFileRead((&w2), sizeof(int), 1, f);
version = SQ_SWAP_4_BYTES(w2);
if ((imageFormatVersionFromSnapshot(version)) == 6521 /* imageFormatVersion */) {
return 1;
version = w2;
rawVersionPtr[0] = version;
if ((((version | MultipleBytecodeSetsBitmask) - MultipleBytecodeSetsBitmask)) == 6521 /* imageFormatVersion */) {
return version;
}
sqImageFileSeek(f, imageOffset);
/* begin getWord32FromFile:swap: */
w3 = 0;
sqImageFileRead((&w3), sizeof(int), 1, f);
version = SQ_SWAP_4_BYTES(w3);
if ((((version | MultipleBytecodeSetsBitmask) - MultipleBytecodeSetsBitmask)) == 6521 /* imageFormatVersion */) {
return version;
}
if (imageOffset == 0) {

Expand All @@ -62317,37 +62344,19 @@ checkImageVersionFromstartingAt(sqImageFile f, squeakFileOffsetType imageOffset)
w = 0;
sqImageFileRead((&w), sizeof(int), 1, f);
version = w;
if ((imageFormatVersionFromSnapshot(version)) == 6521 /* imageFormatVersion */) {
return 0;
rawVersionPtr[0] = version;
if ((((version | MultipleBytecodeSetsBitmask) - MultipleBytecodeSetsBitmask)) == 6521 /* imageFormatVersion */) {
return version;
}
sqImageFileSeek(f, 0x200);
/* begin getWord32FromFile:swap: */
w1 = 0;
sqImageFileRead((&w1), sizeof(int), 1, f);
version = SQ_SWAP_4_BYTES(w1);
if ((imageFormatVersionFromSnapshot(version)) == 6521 /* imageFormatVersion */) {
return 1;
if ((((version | MultipleBytecodeSetsBitmask) - MultipleBytecodeSetsBitmask)) == 6521 /* imageFormatVersion */) {
return version;
}
}
/* begin print: */
fprintf(GIV(transcript), "This interpreter (vers. ");
/* begin printNum: */
fprintf(GIV(transcript),
"%" PRIdSQINT "",
((sqInt)6521 /* imageFormatVersion */));
/* begin print: */
fprintf(GIV(transcript), ") cannot read image file (vers. ");
/* begin printNum: */
fprintf(GIV(transcript),
"%" PRIdSQINT "",
((sqInt)firstVersion));
/* begin print: */
fprintf(GIV(transcript), ").");
cr();
/* begin print: */
fprintf(GIV(transcript), "Press CR to quit...");
getchar();
ioExitWithErrorCode(1);
return 0;
}

Expand Down Expand Up @@ -65270,24 +65279,6 @@ getTranscript(void)
}


/* Answer the next 32 bit word read from aFile, byte-swapped according to the
swapFlag.
*/

/* StackInterpreter>>#getWord32FromFile:swap: */
static sqInt NoDbgRegParms
getWord32FromFileswap(sqImageFile aFile, sqInt swapFlag)
{
int w;

w = 0;
sqImageFileRead((&w), sizeof(int), 1, aFile);
return (swapFlag
? SQ_SWAP_4_BYTES(w)
: w);
}


/* Handle a send fault that is due to a send using a forwarded selector.
Unforward the selector and follow the current method and special
selectors array to unforward the source of the forwarded selector. */
Expand Down Expand Up @@ -65633,18 +65624,6 @@ imageFormatVersionForSnapshot(void)
}


/* Snapshot image format includes the state of multipleBytecodeSetsActive,
mask it out when checking compatibility with this interpreter */

/* StackInterpreter>>#imageFormatVersionFromSnapshot: */
static sqInt NoDbgRegParms
imageFormatVersionFromSnapshot(sqInt imageVersion)
{ DECL_MAYBE_SQ_GLOBAL_STRUCT
GIV(multipleBytecodeSetsActive) = (imageVersion & MultipleBytecodeSetsBitmask) != 0;
return imageVersion & (-1 - MultipleBytecodeSetsBitmask);
}


/* Return the equivalent of
aClass includesBehavior: aSuperclass.
Note: written for efficiency and better inlining (only 1 temp) */
Expand Down Expand Up @@ -67258,7 +67237,7 @@ lookupSelectorinClass(sqInt selector, sqInt class)
{ DECL_MAYBE_SQ_GLOBAL_STRUCT
sqInt currentClass;
sqInt dictionary;
usqInt index;
sqInt index;
usqInt length;
sqInt mask;
sqInt meth;
Expand Down Expand Up @@ -67302,7 +67281,7 @@ lookupSelectorinClass(sqInt selector, sqInt class)
wrapAround = 0;
while (1) {
/* begin fetchPointer:ofObject: */
nextSelector = longAt((dictionary + BaseHeaderSize) + (index << (shiftForWord())));
nextSelector = longAt((dictionary + BaseHeaderSize) + (((sqInt)((usqInt)(index) << (shiftForWord())))));
if (nextSelector == GIV(nilObj)) {
meth = null;
goto l8;
Expand All @@ -67320,7 +67299,7 @@ lookupSelectorinClass(sqInt selector, sqInt class)
}
methodArray = objOop2;
/* begin followField:ofObject: */
objOop1 = longAt((methodArray + BaseHeaderSize) + ((index - SelectorStart) << (shiftForWord())));
objOop1 = longAt((methodArray + BaseHeaderSize) + (((sqInt)((usqInt)((index - SelectorStart)) << (shiftForWord())))));
if (((!(objOop1 & (tagMask()))))
&& ((!((longAt(objOop1)) & ((classIndexMask()) - (isForwardedObjectClassIndexPun())))))) {
objOop1 = fixFollowedFieldofObjectwithInitialValue(index - SelectorStart, methodArray, objOop1);
Expand Down Expand Up @@ -71545,7 +71524,7 @@ putWord32toFile(int aWord32, sqImageFile aFile)
sqInt
readableFormat(sqInt imageVersion)
{
return (imageFormatVersionFromSnapshot(imageVersion)) == 6521 /* imageFormatVersion */;
return (((imageVersion | MultipleBytecodeSetsBitmask) - MultipleBytecodeSetsBitmask)) == 6521 /* imageFormatVersion */;
}


Expand Down
2 changes: 1 addition & 1 deletion src/spur32.cog/cointerp.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Automatically generated by
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.3353 uuid: 860ea747-484d-4072-8047-3b45e4687175
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.3354 uuid: 67b625b4-ae15-4b1d-a144-7fd52510caf2
*/


Expand Down
Loading

0 comments on commit 6641c9d

Please sign in to comment.