diff --git a/src/plugins/ADPCMCodecPlugin/ADPCMCodecPlugin.c b/src/plugins/ADPCMCodecPlugin/ADPCMCodecPlugin.c index c8b1d3afd6..243eaa0bc0 100644 --- a/src/plugins/ADPCMCodecPlugin/ADPCMCodecPlugin.c +++ b/src/plugins/ADPCMCodecPlugin/ADPCMCodecPlugin.c @@ -1,10 +1,10 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - ADPCMCodecPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + ADPCMCodecPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 ADPCMCodec * Sound-mt.97 uuid: 122e8e23-da9c-9b48-b787-b6478bd54df7 */ -static char __buildInfo[] = "ADPCMCodecPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f\n\ +static char __buildInfo[] = "ADPCMCodecPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3\n\ ADPCMCodec * Sound-mt.97 uuid: 122e8e23-da9c-9b48-b787-b6478bd54df7 " __DATE__ ; @@ -67,7 +67,7 @@ extern sqInt success(sqInt aBoolean); extern #endif struct VirtualMachine* interpreterProxy; -static const char *moduleName = "ADPCMCodecPlugin VMMaker.oscog-eem.3455 " INT_EXT; +static const char *moduleName = "ADPCMCodecPlugin VMMaker.oscog-eem.3456 " INT_EXT; /*** Methods ***/ @@ -108,16 +108,15 @@ primitiveDecodeMono(void) sqInt predictedDelta; sqInt rcvr; sqInt remaining; - sqInt remaining1; - sqInt remaining2; + sqInt remainingSqInt; sqInt result; sqInt result1; - sqInt result2; + sqInt resultSqInt; sqInt sampleIndex; short int *samples; sqInt shift; sqInt shift1; - sqInt shift2; + sqInt shiftSqInt; short int step; short int *stepSizeTable; @@ -148,6 +147,7 @@ primitiveDecodeMono(void) delta = 0; for (i = 1; i <= count; i += 1) { if ((i & frameSizeMask) == 1) { + /* start of frame; read frame header */ /* begin nextBits: */ result = 0; @@ -155,15 +155,18 @@ primitiveDecodeMono(void) while (1) { shift = remaining - bitPosition; if (shift > 0) { + /* consumed currentByte buffer; fetch next byte */ - result += ((sqInt)((usqInt)(currentByte) << shift)); + result += (((usqInt)(currentByte) << shift)); remaining -= bitPosition; currentByte = encodedBytes[(byteIndex += 1)]; bitPosition = 8; } else { + /* still some bits left in currentByte buffer */ result += ((usqInt)(currentByte)) >> (0 - shift); + /* mask out the consumed bits: */ bitPosition -= remaining; currentByte = currentByte & (((usqInt)(0xFF)) >> (8 - bitPosition)); @@ -171,59 +174,66 @@ primitiveDecodeMono(void) goto l1; } } - l1: /* end nextBits: */; +l1: /* end nextBits: */; if (predicted > 0x7FFF) { predicted -= 0x10000; } + /* begin nextBits: */ - result1 = 0; - remaining1 = 6; + resultSqInt = 0; + remainingSqInt = 6; while (1) { - shift1 = remaining1 - bitPosition; - if (shift1 > 0) { + shiftSqInt = remainingSqInt - bitPosition; + if (shiftSqInt > 0) { + /* consumed currentByte buffer; fetch next byte */ - result1 += ((sqInt)((usqInt)(currentByte) << shift1)); - remaining1 -= bitPosition; + resultSqInt += (((usqInt)(currentByte) << shiftSqInt)); + remainingSqInt -= bitPosition; currentByte = encodedBytes[(byteIndex += 1)]; bitPosition = 8; } else { + /* still some bits left in currentByte buffer */ - result1 += ((usqInt)(currentByte)) >> (0 - shift1); + resultSqInt += ((usqInt)(currentByte)) >> (0 - shiftSqInt); + /* mask out the consumed bits: */ - bitPosition -= remaining1; + bitPosition -= remainingSqInt; currentByte = currentByte & (((usqInt)(0xFF)) >> (8 - bitPosition)); - index = result1; + index = resultSqInt; goto l2; } } - l2: /* end nextBits: */; +l2: /* end nextBits: */; samples[(sampleIndex += 1)] = predicted; } else { /* begin nextBits: */ - result2 = 0; - remaining2 = bitsPerSample; + result1 = 0; + remainingSqInt = bitsPerSample; while (1) { - shift2 = remaining2 - bitPosition; - if (shift2 > 0) { + shift1 = remainingSqInt - bitPosition; + if (shift1 > 0) { + /* consumed currentByte buffer; fetch next byte */ - result2 += ((sqInt)((usqInt)(currentByte) << shift2)); - remaining2 -= bitPosition; + result1 += (((usqInt)(currentByte) << shift1)); + remainingSqInt -= bitPosition; currentByte = encodedBytes[(byteIndex += 1)]; bitPosition = 8; } else { + /* still some bits left in currentByte buffer */ - result2 += ((usqInt)(currentByte)) >> (0 - shift2); + result1 += ((usqInt)(currentByte)) >> (0 - shift1); + /* mask out the consumed bits: */ - bitPosition -= remaining2; + bitPosition -= remainingSqInt; currentByte = currentByte & (((usqInt)(0xFF)) >> (8 - bitPosition)); - delta = result2; + delta = result1; goto l3; } } - l3: /* end nextBits: */; +l3: /* end nextBits: */; step = stepSizeTable[index + 1]; predictedDelta = 0; bit = deltaValueHighBit; @@ -302,26 +312,16 @@ primitiveDecodeStereo(void) sqInt predictedRight; sqInt rcvr; sqInt remaining; - sqInt remaining1; - sqInt remaining2; - sqInt remaining3; - sqInt remaining4; - sqInt remaining5; + sqInt remainingSqInt; sqInt result; sqInt result1; - sqInt result2; - sqInt result3; - sqInt result4; - sqInt result5; + sqInt resultSqInt; short int *rightSamples; sqInt sampleIndex; short int *samples; sqInt shift; sqInt shift1; - sqInt shift2; - sqInt shift3; - sqInt shift4; - sqInt shift5; + sqInt shiftSqInt; short int stepLeft; short int stepRight; short int *stepSizeTable; @@ -364,6 +364,7 @@ primitiveDecodeStereo(void) indexRight = index[2]; for (i = 1; i <= count; i += 1) { if ((i & frameSizeMask) == 1) { + /* start of frame; read frame header */ /* begin nextBits: */ result = 0; @@ -371,15 +372,18 @@ primitiveDecodeStereo(void) while (1) { shift = remaining - bitPosition; if (shift > 0) { + /* consumed currentByte buffer; fetch next byte */ - result += ((sqInt)((usqInt)(currentByte) << shift)); + result += (((usqInt)(currentByte) << shift)); remaining -= bitPosition; currentByte = encodedBytes[(byteIndex += 1)]; bitPosition = 8; } else { + /* still some bits left in currentByte buffer */ result += ((usqInt)(currentByte)) >> (0 - shift); + /* mask out the consumed bits: */ bitPosition -= remaining; currentByte = currentByte & (((usqInt)(0xFF)) >> (8 - bitPosition)); @@ -387,76 +391,88 @@ primitiveDecodeStereo(void) goto l1; } } - l1: /* end nextBits: */; +l1: /* end nextBits: */; + /* begin nextBits: */ - result1 = 0; - remaining1 = 6; + resultSqInt = 0; + remainingSqInt = 6; while (1) { - shift1 = remaining1 - bitPosition; - if (shift1 > 0) { + shiftSqInt = remainingSqInt - bitPosition; + if (shiftSqInt > 0) { + /* consumed currentByte buffer; fetch next byte */ - result1 += ((sqInt)((usqInt)(currentByte) << shift1)); - remaining1 -= bitPosition; + resultSqInt += (((usqInt)(currentByte) << shiftSqInt)); + remainingSqInt -= bitPosition; currentByte = encodedBytes[(byteIndex += 1)]; bitPosition = 8; } else { + /* still some bits left in currentByte buffer */ - result1 += ((usqInt)(currentByte)) >> (0 - shift1); + resultSqInt += ((usqInt)(currentByte)) >> (0 - shiftSqInt); + /* mask out the consumed bits: */ - bitPosition -= remaining1; + bitPosition -= remainingSqInt; currentByte = currentByte & (((usqInt)(0xFF)) >> (8 - bitPosition)); - indexLeft = result1; + indexLeft = resultSqInt; goto l2; } } - l2: /* end nextBits: */; +l2: /* end nextBits: */; + /* begin nextBits: */ - result2 = 0; - remaining2 = 16; + result1 = 0; + remainingSqInt = 16; while (1) { - shift2 = remaining2 - bitPosition; - if (shift2 > 0) { + shift1 = remainingSqInt - bitPosition; + if (shift1 > 0) { + /* consumed currentByte buffer; fetch next byte */ - result2 += ((sqInt)((usqInt)(currentByte) << shift2)); - remaining2 -= bitPosition; + result1 += (((usqInt)(currentByte) << shift1)); + remainingSqInt -= bitPosition; currentByte = encodedBytes[(byteIndex += 1)]; bitPosition = 8; } else { + /* still some bits left in currentByte buffer */ - result2 += ((usqInt)(currentByte)) >> (0 - shift2); + result1 += ((usqInt)(currentByte)) >> (0 - shift1); + /* mask out the consumed bits: */ - bitPosition -= remaining2; + bitPosition -= remainingSqInt; currentByte = currentByte & (((usqInt)(0xFF)) >> (8 - bitPosition)); - predictedRight = result2; + predictedRight = result1; goto l3; } } - l3: /* end nextBits: */; +l3: /* end nextBits: */; + /* begin nextBits: */ - result3 = 0; - remaining3 = 6; + result1 = 0; + remainingSqInt = 6; while (1) { - shift3 = remaining3 - bitPosition; - if (shift3 > 0) { + shift1 = remainingSqInt - bitPosition; + if (shift1 > 0) { + /* consumed currentByte buffer; fetch next byte */ - result3 += ((sqInt)((usqInt)(currentByte) << shift3)); - remaining3 -= bitPosition; + result1 += (((usqInt)(currentByte) << shift1)); + remainingSqInt -= bitPosition; currentByte = encodedBytes[(byteIndex += 1)]; bitPosition = 8; } else { + /* still some bits left in currentByte buffer */ - result3 += ((usqInt)(currentByte)) >> (0 - shift3); + result1 += ((usqInt)(currentByte)) >> (0 - shift1); + /* mask out the consumed bits: */ - bitPosition -= remaining3; + bitPosition -= remainingSqInt; currentByte = currentByte & (((usqInt)(0xFF)) >> (8 - bitPosition)); - indexRight = result3; + indexRight = result1; goto l4; } } - l4: /* end nextBits: */; +l4: /* end nextBits: */; if (predictedLeft > 0x7FFF) { predictedLeft -= 0x10000; } @@ -468,51 +484,58 @@ primitiveDecodeStereo(void) } else { /* begin nextBits: */ - result4 = 0; - remaining4 = bitsPerSample; + result1 = 0; + remainingSqInt = bitsPerSample; while (1) { - shift4 = remaining4 - bitPosition; - if (shift4 > 0) { + shift1 = remainingSqInt - bitPosition; + if (shift1 > 0) { + /* consumed currentByte buffer; fetch next byte */ - result4 += ((sqInt)((usqInt)(currentByte) << shift4)); - remaining4 -= bitPosition; + result1 += (((usqInt)(currentByte) << shift1)); + remainingSqInt -= bitPosition; currentByte = encodedBytes[(byteIndex += 1)]; bitPosition = 8; } else { + /* still some bits left in currentByte buffer */ - result4 += ((usqInt)(currentByte)) >> (0 - shift4); + result1 += ((usqInt)(currentByte)) >> (0 - shift1); + /* mask out the consumed bits: */ - bitPosition -= remaining4; + bitPosition -= remainingSqInt; currentByte = currentByte & (((usqInt)(0xFF)) >> (8 - bitPosition)); - deltaLeft = result4; + deltaLeft = result1; goto l5; } } - l5: /* end nextBits: */; +l5: /* end nextBits: */; + /* begin nextBits: */ - result5 = 0; - remaining5 = bitsPerSample; + result1 = 0; + remainingSqInt = bitsPerSample; while (1) { - shift5 = remaining5 - bitPosition; - if (shift5 > 0) { + shift1 = remainingSqInt - bitPosition; + if (shift1 > 0) { + /* consumed currentByte buffer; fetch next byte */ - result5 += ((sqInt)((usqInt)(currentByte) << shift5)); - remaining5 -= bitPosition; + result1 += (((usqInt)(currentByte) << shift1)); + remainingSqInt -= bitPosition; currentByte = encodedBytes[(byteIndex += 1)]; bitPosition = 8; } else { + /* still some bits left in currentByte buffer */ - result5 += ((usqInt)(currentByte)) >> (0 - shift5); + result1 += ((usqInt)(currentByte)) >> (0 - shift1); + /* mask out the consumed bits: */ - bitPosition -= remaining5; + bitPosition -= remainingSqInt; currentByte = currentByte & (((usqInt)(0xFF)) >> (8 - bitPosition)); - deltaRight = result5; + deltaRight = result1; goto l6; } } - l6: /* end nextBits: */; +l6: /* end nextBits: */; stepLeft = stepSizeTable[indexLeft + 1]; stepRight = stepSizeTable[indexRight + 1]; predictedDeltaLeft = (predictedDeltaRight = 0); @@ -603,14 +626,12 @@ primitiveEncodeMono(void) sqInt bitPosition; sqInt bitsAvailable; sqInt bitsAvailable1; - sqInt bitsAvailable2; + sqInt bitsAvailableSqInt; sqInt bitsPerSample; sqInt buf; - sqInt buf1; - sqInt buf2; sqInt bufBits; - sqInt bufBits1; - sqInt bufBits2; + sqInt bufBitsSqInt; + sqInt bufSqInt; sqInt byteIndex; sqInt count; sqInt currentByte; @@ -618,7 +639,7 @@ primitiveEncodeMono(void) sqInt deltaSignMask; sqInt deltaValueHighBit; sqInt diff; - sqInt diff1; + sqInt diffSqInt; unsigned char *encodedBytes; sqInt frameSizeMask; sqInt i; @@ -633,7 +654,7 @@ primitiveEncodeMono(void) short int *samples; sqInt shift; sqInt shift1; - sqInt shift2; + sqInt shiftSqInt; sqInt sign; short int step; short int *stepSizeTable; @@ -668,76 +689,87 @@ primitiveEncodeMono(void) if (((p = predicted)) < 0) { p += 0x10000; } + /* begin nextBits:put: */ buf = p; bufBits = 16; while (1) { bitsAvailable = 8 - bitPosition; + /* either left or right shift */ /* append high bits of buf to end of currentByte: */ shift = bitsAvailable - bufBits; if (shift < 0) { + /* currentByte buffer filled; output it */ currentByte += ((usqInt)(buf)) >> (0 - shift); encodedBytes[(byteIndex += 1)] = currentByte; bitPosition = 0; + /* clear saved high bits of buf: */ currentByte = 0; buf = buf & ((1U << (0 - shift)) - 1); bufBits -= bitsAvailable; } else { + /* still some bits available in currentByte buffer */ - currentByte += ((sqInt)((usqInt)(buf) << shift)); + currentByte += (((usqInt)(buf) << shift)); bitPosition += bufBits; goto l1; } } - l1: /* end nextBits:put: */; +l1: /* end nextBits:put: */; if (i < count) { /* begin indexForDeltaFrom:to: */ - diff1 = (samples[sampleIndex + 1]) - predicted; - if (diff1 < 0) { - diff1 = 0 - diff1; + diffSqInt = (samples[sampleIndex + 1]) - predicted; + if (diffSqInt < 0) { + diffSqInt = 0 - diffSqInt; } bestIndex = 0x3F; for (j = 1; j <= 0x3E; j += 1) { if (bestIndex == 0x3F) { - if ((stepSizeTable[j]) >= diff1) { + if ((stepSizeTable[j]) >= diffSqInt) { bestIndex = j; } } } index = bestIndex; } + /* begin nextBits:put: */ - buf1 = index; - bufBits1 = 6; + bufSqInt = index; + bufBitsSqInt = 6; while (1) { - bitsAvailable1 = 8 - bitPosition; + bitsAvailableSqInt = 8 - bitPosition; + /* either left or right shift */ /* append high bits of buf to end of currentByte: */ - shift1 = bitsAvailable1 - bufBits1; - if (shift1 < 0) { + shiftSqInt = bitsAvailableSqInt - bufBitsSqInt; + if (shiftSqInt < 0) { + /* currentByte buffer filled; output it */ - currentByte += ((usqInt)(buf1)) >> (0 - shift1); + currentByte += ((usqInt)(bufSqInt)) >> (0 - shiftSqInt); encodedBytes[(byteIndex += 1)] = currentByte; bitPosition = 0; + /* clear saved high bits of buf: */ currentByte = 0; - buf1 = buf1 & ((1U << (0 - shift1)) - 1); - bufBits1 -= bitsAvailable1; + bufSqInt = bufSqInt & ((1U << (0 - shiftSqInt)) - 1); + bufBitsSqInt -= bitsAvailableSqInt; } else { + /* still some bits available in currentByte buffer */ - currentByte += ((sqInt)((usqInt)(buf1) << shift1)); - bitPosition += bufBits1; - goto l3; + currentByte += (((usqInt)(bufSqInt) << shiftSqInt)); + bitPosition += bufBitsSqInt; + goto l2; } } - l3: /* end nextBits:put: */; +l2: /* end nextBits:put: */; } else { + /* compute sign and magnitude of difference from the predicted sample */ sign = 0; diff = (samples[(sampleIndex += 1)]) - predicted; @@ -757,6 +789,7 @@ primitiveEncodeMono(void) step = (((usqInt)(step)) >> 1); bit = (((usqInt)(bit)) >> 1); } + /* compute and clamp new prediction */ predictedDelta += step; if (sign > 0) { @@ -782,37 +815,44 @@ primitiveEncodeMono(void) index = 88; } } + /* output encoded, signed delta */ step = stepSizeTable[index + 1]; + /* begin nextBits:put: */ - buf2 = sign | delta; - bufBits2 = bitsPerSample; + bufSqInt = sign | delta; + bufBitsSqInt = bitsPerSample; while (1) { - bitsAvailable2 = 8 - bitPosition; + bitsAvailable1 = 8 - bitPosition; + /* either left or right shift */ /* append high bits of buf to end of currentByte: */ - shift2 = bitsAvailable2 - bufBits2; - if (shift2 < 0) { + shift1 = bitsAvailable1 - bufBitsSqInt; + if (shift1 < 0) { + /* currentByte buffer filled; output it */ - currentByte += ((usqInt)(buf2)) >> (0 - shift2); + currentByte += ((usqInt)(bufSqInt)) >> (0 - shift1); encodedBytes[(byteIndex += 1)] = currentByte; bitPosition = 0; + /* clear saved high bits of buf: */ currentByte = 0; - buf2 = buf2 & ((1U << (0 - shift2)) - 1); - bufBits2 -= bitsAvailable2; + bufSqInt = bufSqInt & ((1U << (0 - shift1)) - 1); + bufBitsSqInt -= bitsAvailable1; } else { + /* still some bits available in currentByte buffer */ - currentByte += ((sqInt)((usqInt)(buf2) << shift2)); - bitPosition += bufBits2; - goto l4; + currentByte += (((usqInt)(bufSqInt) << shift1)); + bitPosition += bufBitsSqInt; + goto l3; } } - l4: /* end nextBits:put: */; +l3: /* end nextBits:put: */; } } if (bitPosition > 0) { + /* flush the last output byte, if necessary */ encodedBytes[(byteIndex += 1)] = currentByte; } @@ -859,12 +899,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -881,8 +920,8 @@ setInterpreter(struct VirtualMachine *anInterpreter) return ok; } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "ADPCMCodecPlugin"; diff --git a/src/plugins/AioPlugin/AioPlugin.c b/src/plugins/AioPlugin/AioPlugin.c index 9615548474..64961ee018 100644 --- a/src/plugins/AioPlugin/AioPlugin.c +++ b/src/plugins/AioPlugin/AioPlugin.c @@ -1,5 +1,5 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from UnixAioPlugin VMConstruction-Plugins-AioPlugin.oscog-eem.26 uuid: 9d32c4ef-9646-4ce2-b069-44fe86a2dbfb */ @@ -70,7 +70,7 @@ static sqInt (*failed)(void); static sqInt (*getThisSessionID)(void); static sqInt (*isBytes)(sqInt oop); static sqInt (*methodReturnInteger)(sqInt integer); -static sqInt (*methodReturnString)(char *aCString); +static sqInt (*methodReturnString)(const char *aCString); static sqInt (*primitiveFail)(void); static sqInt (*signalSemaphoreWithIndex)(sqInt semaIndex); static sqInt (*stackIntegerValue)(sqInt offset); @@ -83,7 +83,7 @@ extern sqInt failed(void); extern sqInt getThisSessionID(void); extern sqInt isBytes(sqInt oop); extern sqInt methodReturnInteger(sqInt integer); -extern sqInt methodReturnString(char *aCString); +extern sqInt methodReturnString(const char *aCString); extern sqInt primitiveFail(void); extern sqInt signalSemaphoreWithIndex(sqInt semaIndex); extern sqInt stackIntegerValue(sqInt offset); @@ -132,7 +132,7 @@ aioForwardwithDataandFlags(int fd, void *data, int flags) static int fileDescriptorFrom(sqInt aSQFileByteArray) { - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(aSQFileByteArray)) && ((byteSizeOf(aSQFileByteArray)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(aSQFileByteArray))))) @@ -182,7 +182,7 @@ isNonNullSQFile(sqInt objectPointer) sqFileBytes = arrayValueOf(objectPointer); idx = 0; while (idx < (sizeof(SQFile))) { - if ((sqFileBytes[idx]) != 0) { + if (sqFileBytes[idx]) { return 1; } idx += 1; @@ -203,7 +203,7 @@ isNullSQSocket(sqInt objectPointer) sqSocketBytes = arrayValueOf(objectPointer); idx = 0; while (idx < (sizeof(SQSocket))) { - if ((sqSocketBytes[idx]) != 0) { + if (sqSocketBytes[idx]) { return 0; } idx += 1; @@ -261,8 +261,8 @@ primitiveAioEnable(void) } eventSemaphoreIndices[semaIndex] = semaIndex; flags = (externalNotification - ? AIO_EXT - : 0); + ? AIO_EXT + : 0); aioEnable(fd, (&(eventSemaphoreIndices[semaIndex])), flags); methodReturnInteger(semaIndex); return 0; @@ -383,7 +383,7 @@ primitiveOSFileHandle(void) sqInt sqFileOop; sqFileOop = stackValue(0); - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(sqFileOop)) && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop))))) @@ -407,7 +407,7 @@ primitiveOSSocketHandle(void) sqInt sqSocketOop; sqSocketOop = stackValue(0); - if (!(( /* begin isSQSocketObject: */ + if (!((/* isSQSocketObject: */ ((isBytes(sqSocketOop)) && ((byteSizeOf(sqSocketOop)) == (sizeof(SQSocket)))) && (!(isNullSQSocket(sqSocketOop)))) @@ -438,12 +438,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -484,11 +483,10 @@ socketDescriptorFrom(sqInt sqSocketOop) void *privateSocketStruct; SQSocket *sqSocket; - /* begin socketValueOf: */ sqSocket = arrayValueOf(sqSocketOop); privateSocketStruct = sqSocket->privateSocketPtr; - if (privateSocketStruct == 0) { + if (!privateSocketStruct) { return -1; } return * (int *) privateSocketStruct; @@ -513,8 +511,8 @@ versionString(void) return version; } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "AioPlugin"; diff --git a/src/plugins/B3DAcceleratorPlugin/B3DAcceleratorPlugin.c b/src/plugins/B3DAcceleratorPlugin/B3DAcceleratorPlugin.c index cae66f175d..cf3f69b794 100644 --- a/src/plugins/B3DAcceleratorPlugin/B3DAcceleratorPlugin.c +++ b/src/plugins/B3DAcceleratorPlugin/B3DAcceleratorPlugin.c @@ -1,9 +1,9 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - B3DAcceleratorPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + B3DAcceleratorPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 */ -static char __buildInfo[] = "B3DAcceleratorPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f " __DATE__ ; +static char __buildInfo[] = "B3DAcceleratorPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 " __DATE__ ; #include "config.h" @@ -143,7 +143,7 @@ extern sqInt topRemappableOop(void); extern #endif struct VirtualMachine* interpreterProxy; -static const char *moduleName = "B3DAcceleratorPlugin VMMaker.oscog-eem.3455 " INT_EXT; +static const char *moduleName = "B3DAcceleratorPlugin VMMaker.oscog-eem.3456 " INT_EXT; /*** Methods ***/ @@ -186,11 +186,13 @@ loadClientStateverticescolorsnormalstexCoords(sqInt handle, sqInt vertices, sqIn sqInt vtxSize; colorPtr = (normalPtr = (txPtr = (vertexPtr = null))); + /* Verify vertex data */ sz = 0; if (!(isWords(vertices))) { return primitiveFail(); } + /* Verify assumptions of color, normal, texCoords data */ vtxSize = (slotSizeOf(vertices)) / 3; nilOop = nilObject(); @@ -209,16 +211,16 @@ loadClientStateverticescolorsnormalstexCoords(sqInt handle, sqInt vertices, sqIn return primitiveFail(); } if (!(colors == nilOop)) { - colorPtr = ((void *) (firstIndexableField(colors))); + colorPtr = firstIndexableField(colors); } if (!(normals == nilOop)) { - normalPtr = ((void *) (firstIndexableField(normals))); + normalPtr = firstIndexableField(normals); } if (!(texCoords == nilOop)) { sz = (slotSizeOf(texCoords)) / vtxSize; - txPtr = ((void *) (firstIndexableField(texCoords))); + txPtr = firstIndexableField(texCoords); } - vertexPtr = ((void *) (firstIndexableField(vertices))); + vertexPtr = firstIndexableField(vertices); if (!(failed())) { ok = b3dLoadClientState(handle, vertexPtr, 3, colorPtr, 4, normalPtr, 3, txPtr, sz); if (!ok) { @@ -470,7 +472,7 @@ primitiveDrawArrays(void) sqInt vertices; float *vtxPtr; sqInt vtxSize; - sqInt vtxSize1; + sqInt vtxSizeSqInt; if (!((methodArgumentCount()) == 8)) { return primitiveFail(); @@ -488,18 +490,19 @@ primitiveDrawArrays(void) return null; } if (doRangeChecks) { + /* Verify the vertex data itself */ /* begin checkVertexData: */ - vtxSize1 = slotSizeOf(vertices); - vtxPtr = ((float *) (firstIndexableField(vertices))); - for (i = 0; i < vtxSize1; i += 1) { + vtxSizeSqInt = slotSizeOf(vertices); + vtxPtr = firstIndexableField(vertices); + for (i = 0; i < vtxSizeSqInt; i += 1) { f = vtxPtr[i]; if (isnan(f - f)) { primitiveFail(); goto l1; } } - l1: /* end checkVertexData: */; +l1: /* end checkVertexData: */; vtxSize = (slotSizeOf(vertices)) / 3; if ((minIdx < 0) || ((minIdx > maxIdx) @@ -531,7 +534,6 @@ primitiveDrawElements(void) sqInt faces; sqInt handle; sqInt i; - sqInt i1; sqInt mode; sqInt normals; sqInt ok; @@ -539,7 +541,6 @@ primitiveDrawElements(void) sqInt vertices; float *vtxPtr; sqInt vtxSize; - sqInt vtxSize1; if (!((methodArgumentCount()) == 7)) { return primitiveFail(); @@ -549,7 +550,7 @@ primitiveDrawElements(void) return primitiveFail(); } faceSize = slotSizeOf(faces); - facePtr = ((unsigned int *) (firstIndexableField(faces))); + facePtr = firstIndexableField(faces); mode = stackIntegerValue(1); texCoords = stackValue(2); normals = stackValue(3); @@ -561,10 +562,11 @@ primitiveDrawElements(void) return null; } if (doRangeChecks) { + /* Verify the vertex data itself */ /* begin checkVertexData: */ vtxSize = slotSizeOf(vertices); - vtxPtr = ((float *) (firstIndexableField(vertices))); + vtxPtr = firstIndexableField(vertices); for (i = 0; i < vtxSize; i += 1) { f = vtxPtr[i]; if (isnan(f - f)) { @@ -572,16 +574,17 @@ primitiveDrawElements(void) goto l1; } } - l1: /* end checkVertexData: */; +l1: /* end checkVertexData: */; + /* begin checkBoundsRange:faces:count: */ - vtxSize1 = (slotSizeOf(vertices)) / 3; - for (i1 = 0; i1 < faceSize; i1 += 1) { - if ((facePtr[i1]) > vtxSize1) { + vtxSize = (slotSizeOf(vertices)) / 3; + for (i = 0; i < faceSize; i += 1) { + if ((facePtr[i]) > vtxSize) { primitiveFail(); goto l2; } } - l2: /* end checkBoundsRange:faces:count: */; +l2: /* end checkBoundsRange:faces:count: */; } if (!(failed())) { ok = b3dDrawElements(handle, mode, faceSize, facePtr); @@ -609,7 +612,6 @@ primitiveDrawRangeElements(void) sqInt faces; sqInt handle; sqInt i; - sqInt i1; sqInt maxIdx; sqInt minIdx; sqInt mode; @@ -619,8 +621,7 @@ primitiveDrawRangeElements(void) sqInt vertices; float *vtxPtr; sqInt vtxSize; - sqInt vtxSize1; - sqInt vtxSize2; + sqInt vtxSizeSqInt; if (!((methodArgumentCount()) == 9)) { return primitiveFail(); @@ -630,7 +631,7 @@ primitiveDrawRangeElements(void) return primitiveFail(); } faceSize = slotSizeOf(faces); - facePtr = ((unsigned int *) (firstIndexableField(faces))); + facePtr = firstIndexableField(faces); maxIdx = stackIntegerValue(1); minIdx = stackIntegerValue(2); mode = stackIntegerValue(3); @@ -644,27 +645,29 @@ primitiveDrawRangeElements(void) return null; } if (doRangeChecks) { + /* Verify the vertex data itself */ /* begin checkVertexData: */ - vtxSize1 = slotSizeOf(vertices); - vtxPtr = ((float *) (firstIndexableField(vertices))); - for (i = 0; i < vtxSize1; i += 1) { + vtxSizeSqInt = slotSizeOf(vertices); + vtxPtr = firstIndexableField(vertices); + for (i = 0; i < vtxSizeSqInt; i += 1) { f = vtxPtr[i]; if (isnan(f - f)) { primitiveFail(); goto l1; } } - l1: /* end checkVertexData: */; +l1: /* end checkVertexData: */; + /* begin checkBoundsRange:faces:count: */ - vtxSize2 = (slotSizeOf(vertices)) / 3; - for (i1 = 0; i1 < faceSize; i1 += 1) { - if ((facePtr[i1]) > vtxSize2) { + vtxSizeSqInt = (slotSizeOf(vertices)) / 3; + for (i = 0; i < faceSize; i += 1) { + if ((facePtr[i]) > vtxSizeSqInt) { primitiveFail(); goto l2; } } - l2: /* end checkBoundsRange:faces:count: */; +l2: /* end checkBoundsRange:faces:count: */; vtxSize = (slotSizeOf(vertices)) / 3; if ((minIdx < 0) || ((minIdx > maxIdx) @@ -690,7 +693,7 @@ primitiveEnableDrawRangeChecks(void) { sqInt enabled; - if ((methodArgumentCount()) == 0) { + if (!(methodArgumentCount())) { pop(1); return pushBool(doRangeChecks); } @@ -905,7 +908,7 @@ primitiveIsOverlayRenderer(void) EXPORT(sqInt) primitiveRendererVersion(void) { - if (!((methodArgumentCount()) == 0)) { + if (methodArgumentCount()) { return primitiveFail(); } pop(1); @@ -1068,6 +1071,7 @@ primitiveSetLights(void) if (!lightArray) { return null; } + /* For each enabled light source */ lightCount = slotSizeOf(lightArray); for (i = 0; i < lightCount; i += 1) { @@ -1111,12 +1115,12 @@ primitiveSetTransform(void) sqInt handle; float *modelViewMatrix; sqInt oop; - sqInt oop1; float *projectionMatrix; if (!((methodArgumentCount()) == 3)) { return primitiveFail(); } + /* begin stackMatrix: */ oop = stackValue(0); if ((isWords(oop)) @@ -1126,17 +1130,18 @@ primitiveSetTransform(void) } primitiveFail(); projectionMatrix = ((void *) null); - l1: /* end stackMatrix: */; +l1: /* end stackMatrix: */; + /* begin stackMatrix: */ - oop1 = stackValue(1); - if ((isWords(oop1)) - && ((slotSizeOf(oop1)) == 16)) { - modelViewMatrix = firstIndexableField(oop1); + oop = stackValue(1); + if ((isWords(oop)) + && ((slotSizeOf(oop)) == 16)) { + modelViewMatrix = firstIndexableField(oop); goto l2; } primitiveFail(); modelViewMatrix = ((void *) null); - l2: /* end stackMatrix: */; +l2: /* end stackMatrix: */; handle = stackIntegerValue(2); if (!(failed())) { b3dxSetTransform(handle, modelViewMatrix, projectionMatrix); @@ -1349,7 +1354,7 @@ primitiveTextureUpload(void) if (!((slotSizeOf(bits)) == ((((w + ppw) - 1) / ppw) * h))) { return primitiveFail(); } - bitsPtr = ((void *) (firstIndexableField(bits))); + bitsPtr = firstIndexableField(bits); handle = stackIntegerValue(1); renderer = stackIntegerValue(2); if (failed()) { @@ -1371,12 +1376,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -1458,7 +1462,7 @@ stackMaterialValue(sqInt stackIndex) sqInt oop; oop = stackObjectValue(stackIndex); - if (oop == null) { + if (!oop) { return null; } if (oop == (nilObject())) { @@ -1489,7 +1493,7 @@ stackPrimitiveIndexArrayofSizevalidateforVertexSize(sqInt stackIndex, sqInt nIte sqInt oopSize; oop = stackObjectValue(stackIndex); - if (oop == null) { + if (!oop) { return null; } if (!(isWords(oop))) { @@ -1499,7 +1503,7 @@ stackPrimitiveIndexArrayofSizevalidateforVertexSize(sqInt stackIndex, sqInt nIte if (oopSize < nItems) { return null; } - idxPtr = ((int *) (firstIndexableField(oop))); + idxPtr = firstIndexableField(oop); if (aBool) { for (i = 0; i < nItems; i += 1) { index = idxPtr[i]; @@ -1524,7 +1528,7 @@ stackPrimitiveVertexArrayofSize(sqInt index, sqInt nItems) sqInt oopSize; oop = stackObjectValue(index); - if (oop == null) { + if (!oop) { return null; } if (isWords(oop)) { @@ -1537,8 +1541,8 @@ stackPrimitiveVertexArrayofSize(sqInt index, sqInt nItems) return null; } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "B3DAcceleratorPlugin"; diff --git a/src/plugins/CameraPlugin/CameraPlugin.c b/src/plugins/CameraPlugin/CameraPlugin.c index ca8d945eb3..b90bf68b2b 100644 --- a/src/plugins/CameraPlugin/CameraPlugin.c +++ b/src/plugins/CameraPlugin/CameraPlugin.c @@ -1,9 +1,9 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - CameraPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + CameraPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 */ -static char __buildInfo[] = "CameraPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f " __DATE__ ; +static char __buildInfo[] = "CameraPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 " __DATE__ ; #include "config.h" @@ -77,7 +77,7 @@ static sqInt (*methodArgumentCount)(void); static sqInt (*methodReturnBool)(sqInt boolean); static sqInt (*methodReturnInteger)(sqInt integer); static sqInt (*methodReturnReceiver)(void); -static sqInt (*methodReturnString)(char *aCString); +static sqInt (*methodReturnString)(const char *aCString); static sqInt (*methodReturnValue)(sqInt oop); static sqInt (*nilObject)(void); static sqInt (*primitiveFail)(void); @@ -107,7 +107,7 @@ extern sqInt methodArgumentCount(void); extern sqInt methodReturnBool(sqInt boolean); extern sqInt methodReturnInteger(sqInt integer); extern sqInt methodReturnReceiver(void); -extern sqInt methodReturnString(char *aCString); +extern sqInt methodReturnString(const char *aCString); extern sqInt methodReturnValue(sqInt oop); extern sqInt nilObject(void); extern sqInt primitiveFail(void); @@ -119,7 +119,7 @@ extern sqInt success(sqInt aBoolean); extern #endif struct VirtualMachine* interpreterProxy; -static const char *moduleName = "CameraPlugin VMMaker.oscog-eem.3455 " INT_EXT; +static const char *moduleName = "CameraPlugin VMMaker.oscog-eem.3456 " INT_EXT; /*** Methods ***/ @@ -256,11 +256,11 @@ primGetCameraSemaphore(void) cameraNum = stackIntegerValue(0); if (!(failed())) { index = CameraGetSemaphore(cameraNum); - if (index == null) { - primitiveFail(); + if (index) { + methodReturnInteger(index); } else { - methodReturnInteger(index); + primitiveFail(); } } return 0; @@ -290,7 +290,7 @@ primGetFrame(void) if (failed()) { return 0; } - bitmap = ((unsigned char *) (firstIndexableField(bitmapOop))); + bitmap = firstIndexableField(bitmapOop); pixCount = stSizeOf(bitmapOop); result = CameraGetFrame(cameraNum, bitmap, pixCount); if (result < 0) { @@ -318,10 +318,7 @@ primGetLatestBufferIndex(void) return primitiveFailFor(PrimErrBadArgument); } result = CameraGetLatestBufferIndex(integerValueOf(cameraNum)); - if (result == null) { - methodReturnValue(nilObject()); - } - else { + if (result) { if (result < 0) { primitiveFailFor(-result); } @@ -329,6 +326,9 @@ primGetLatestBufferIndex(void) methodReturnInteger(result); } } + else { + methodReturnValue(nilObject()); + } return 0; } @@ -439,11 +439,12 @@ primSetCameraBuffers(void) && (isPinned(bufferTwo))))))))) { return primitiveFailFor(PrimErrBadArgument); } + /* coerce nilObject to nil */ failCode = CameraSetFrameBuffers(integerValueOf(cameraNum), bufferOne, (!(bufferTwo == (nilObject())) - ? bufferTwo - : 0)); - if (failCode != 0) { + ? bufferTwo + : 0)); + if (failCode) { return primitiveFailFor(failCode); } methodReturnReceiver(); @@ -471,7 +472,7 @@ primSetCameraSemaphore(void) return 0; } failCode = CameraSetSemaphore(cameraNum, semaphoreIndex); - if (failCode != 0) { + if (failCode) { return primitiveFailFor(failCode); } methodReturnReceiver(); @@ -498,8 +499,8 @@ primSetParam(void) paramNum = stackIntegerValue(1); paramValue = stackValue(0); paramValue = (isIntegerObject(paramValue) - ? integerValueOf(paramValue) - : booleanValueOf(paramValue)); + ? integerValueOf(paramValue) + : booleanValueOf(paramValue)); if (failed()) { primitiveFailFor(PrimErrBadArgument); } @@ -529,12 +530,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -581,8 +581,8 @@ shutdownModule(void) return cameraShutdown(); } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "CameraPlugin"; diff --git a/src/plugins/CroquetPlugin/CroquetPlugin.c b/src/plugins/CroquetPlugin/CroquetPlugin.c index 2a30ec9c08..16c7e48fb5 100644 --- a/src/plugins/CroquetPlugin/CroquetPlugin.c +++ b/src/plugins/CroquetPlugin/CroquetPlugin.c @@ -1,9 +1,9 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - CroquetPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + CroquetPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 */ -static char __buildInfo[] = "CroquetPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f " __DATE__ ; +static char __buildInfo[] = "CroquetPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 " __DATE__ ; #include "config.h" @@ -106,7 +106,7 @@ extern sqInt storePointerofObjectwithValue(sqInt index, sqInt oop, sqInt valuePo extern #endif struct VirtualMachine* interpreterProxy; -static const char *moduleName = "CroquetPlugin VMMaker.oscog-eem.3455 " INT_EXT; +static const char *moduleName = "CroquetPlugin VMMaker.oscog-eem.3456 " INT_EXT; /*** Methods ***/ @@ -166,9 +166,10 @@ primitiveAdj3(void) if (failed()) { return null; } - src = ((float *) (firstIndexableField(srcOop))); + src = firstIndexableField(srcOop); + /* read in the source matrix 3x3, which contains the encoded rotation and scale factors */ - dst = ((float *) (firstIndexableField(dstOop))); + dst = firstIndexableField(dstOop); m11 = src[c11]; m12 = src[c12]; m13 = src[c13]; @@ -177,6 +178,7 @@ primitiveAdj3(void) m23 = src[c23]; m31 = src[c31]; m32 = src[c32]; + /* do the actual work */ /* compute our cofactors and transpose. adj = transpose of cofactors */ m33 = src[c33]; @@ -227,6 +229,7 @@ primitiveARC4Transform(void) sqInt y; sqInt yOop; + bufSize = 0; if (!((methodArgumentCount()) == 6)) { return primitiveFail(); } @@ -248,8 +251,8 @@ primitiveARC4Transform(void) && (stopIndex <= bufSize)))))))) { return primitiveFail(); } - m = ((unsigned char *) (firstIndexableField(mOop))); - buffer = ((unsigned char *) (firstIndexableField(bufOop))); + m = firstIndexableField(mOop); + buffer = firstIndexableField(bufOop); for (i = (startIndex - 1); i < stopIndex; i += 1) { x = (x + 1) & 0xFF; a = m[x]; @@ -314,7 +317,7 @@ primitiveDet3(void) if (failed()) { return null; } - src = ((float *) (firstIndexableField(srcOop))); + src = firstIndexableField(srcOop); m11 = src[0]; m12 = src[1]; m13 = src[2]; @@ -365,13 +368,12 @@ primitiveInplaceHouseHolderInvert(void) double sum; double x[4][4] = { {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1} }; - /* begin stackMatrix: */ oop = stackValue(0); rcvr = ((isWords(oop)) - && ((slotSizeOf(oop)) == 16) - ? firstIndexableField(oop) - : 0); + && ((slotSizeOf(oop)) == 16) + ? firstIndexableField(oop) + : 0); if (!rcvr) { return primitiveFail(); } @@ -484,9 +486,10 @@ primitiveInverseByAdjoint(void) if (failed()) { return null; } - src = ((float *) (firstIndexableField(srcOop))); + src = firstIndexableField(srcOop); + /* read in the source matrix 3x3, which contains the encoded rotation and scale factors */ - dst = ((float *) (firstIndexableField(dstOop))); + dst = firstIndexableField(dstOop); m11 = src[c11]; m12 = src[c12]; m13 = src[c13]; @@ -495,16 +498,20 @@ primitiveInverseByAdjoint(void) m23 = src[c23]; m31 = src[c31]; m32 = src[c32]; + /* read in the source translation vector */ m33 = src[c33]; x = src[c14]; y = src[c24]; + /* do the actual work */ /* first, compute the determinant of the upper 3x3 of the source */ z = src[c34]; + /* Compute the classical adjunct of the source, and divide by the source determinant storing in the destination. adjoint = transpose of cofactors, so we'll transpose as we store. */ det = ((m11 * ((m22 * m33) - (m23 * m32))) + (m12 * ((m23 * m31) - (m21 * m33)))) + (m13 * ((m21 * m32) - (m22 * m31))); + /* let's make div by det a multiply */ det = 1 / det; dst[c11] = (((m22 * m33) - (m23 * m32)) * det); @@ -580,7 +587,7 @@ primitiveOptimizeVertexIndicesForCacheLocality(void) if (!((triCount * 12) == byteSize)) { return primitiveFail(); } - if ((optimizeVertexIndices(firstIndexableField(indicesOop), triCount)) != 0) { + if (optimizeVertexIndices(firstIndexableField(indicesOop), triCount)) { return primitiveFail(); } return methodReturnReceiver(); @@ -614,10 +621,11 @@ primitiveOrthoNormInverseMatrix(void) srcOop = stackValue(0); # endif - src = ((float *) (firstIndexableField(srcOop))); + src = firstIndexableField(srcOop); + /* Transpose upper 3x3 matrix */ /* dst at: 0 put: (src at: 0). */ - dst = ((float *) (firstIndexableField(dstOop))); + dst = firstIndexableField(dstOop); dst[1] = (src[4]); dst[2] = (src[8]); dst[4] = (src[1]); @@ -651,20 +659,19 @@ primitiveTransformDirection(void) double y; double z; - /* begin stackMatrix: */ oop = stackValue(1); matrix = ((isWords(oop)) - && ((slotSizeOf(oop)) == 16) - ? firstIndexableField(oop) - : 0); + && ((slotSizeOf(oop)) == 16) + ? firstIndexableField(oop) + : 0); v3Oop = stackValue(0); if (!((matrix) && ((isWords(v3Oop)) && ((slotSizeOf(v3Oop)) == 3)))) { return primitiveFail(); } - vertex = ((float *) (firstIndexableField(v3Oop))); + vertex = firstIndexableField(v3Oop); x = vertex[0]; y = vertex[1]; z = vertex[2]; @@ -675,7 +682,7 @@ primitiveTransformDirection(void) if (!v3Oop) { return primitiveFailFor(PrimErrNoMemory); } - vertex = ((float *) (firstIndexableField(v3Oop))); + vertex = firstIndexableField(v3Oop); vertex[0] = rx; vertex[1] = ry; vertex[2] = rz; @@ -701,43 +708,45 @@ primitiveTransformMatrixWithInto(void) float *m3; float *m31; sqInt oop; - sqInt oop1; - sqInt oop2; - /* begin stackMatrix: */ oop = stackValue(0); m3 = ((isWords(oop)) - && ((slotSizeOf(oop)) == 16) - ? firstIndexableField(oop) - : 0); + && ((slotSizeOf(oop)) == 16) + ? firstIndexableField(oop) + : 0); + /* begin stackMatrix: */ - oop1 = stackValue(1); - m2 = ((isWords(oop1)) - && ((slotSizeOf(oop1)) == 16) - ? firstIndexableField(oop1) - : 0); + oop = stackValue(1); + m2 = ((isWords(oop)) + && ((slotSizeOf(oop)) == 16) + ? firstIndexableField(oop) + : 0); + /* begin stackMatrix: */ - oop2 = stackValue(2); - m1 = ((isWords(oop2)) - && ((slotSizeOf(oop2)) == 16) - ? firstIndexableField(oop2) - : 0); + oop = stackValue(2); + m1 = ((isWords(oop)) + && ((slotSizeOf(oop)) == 16) + ? firstIndexableField(oop) + : 0); if ((!m1) || ((!m2) || ((!m3) || (m2 == m3)))) { return primitiveFail(); } + /* begin transformMatrix:with:into: */ m11 = ((float *) m1); m21 = ((float *) m2); m31 = ((float *) m3); for (i = 0; i <= 3; i += 1) { + /* Compute next row */ c1 = ((((m11[0]) * (m21[0])) + ((m11[1]) * (m21[4]))) + ((m11[2]) * (m21[8]))) + ((m11[3]) * (m21[12])); c2 = ((((m11[0]) * (m21[1])) + ((m11[1]) * (m21[5]))) + ((m11[2]) * (m21[9]))) + ((m11[3]) * (m21[13])); c3 = ((((m11[0]) * (m21[2])) + ((m11[1]) * (m21[6]))) + ((m11[2]) * (m21[10]))) + ((m11[3]) * (m21[14])); + /* Store result */ c4 = ((((m11[0]) * (m21[3])) + ((m11[1]) * (m21[7]))) + ((m11[2]) * (m21[11]))) + ((m11[3]) * (m21[15])); m31[0] = c1; @@ -766,20 +775,19 @@ primitiveTransformVector3(void) double y; double z; - /* begin stackMatrix: */ oop = stackValue(1); matrix = ((isWords(oop)) - && ((slotSizeOf(oop)) == 16) - ? firstIndexableField(oop) - : 0); + && ((slotSizeOf(oop)) == 16) + ? firstIndexableField(oop) + : 0); v3Oop = stackValue(0); if (!((matrix) && ((isWords(v3Oop)) && ((slotSizeOf(v3Oop)) == 3)))) { return primitiveFail(); } - vertex = ((float *) (firstIndexableField(v3Oop))); + vertex = firstIndexableField(v3Oop); x = vertex[0]; y = vertex[1]; z = vertex[2]; @@ -791,7 +799,7 @@ primitiveTransformVector3(void) if (!v3Oop) { return primitiveFailFor(PrimErrNoMemory); } - vertex = ((float *) (firstIndexableField(v3Oop))); + vertex = firstIndexableField(v3Oop); if (rw == 1.0) { vertex[0] = rx; vertex[1] = ry; @@ -830,13 +838,15 @@ primitiveTransposeMatrix(void) return primitiveFailFor(PrimErrNoMemory); } # if !SPURVM + /* reload srcOop in case of GC */ srcOop = stackValue(0); # endif - src = ((float *) (firstIndexableField(srcOop))); + src = firstIndexableField(srcOop); + /* dst at: 0 put: (src at: 0). */ - dst = ((float *) (firstIndexableField(dstOop))); + dst = firstIndexableField(dstOop); dst[1] = (src[4]); dst[2] = (src[8]); dst[3] = (src[12]); @@ -863,46 +873,45 @@ primitiveTriBoxIntersects(void) float *maxCorner; float *minCorner; sqInt oop; - sqInt oop1; - sqInt oop2; - sqInt oop3; - sqInt oop4; sqInt result; float *v0; float *v1; float *v2; - /* begin stackVector3: */ oop = stackValue(0); v2 = ((isWords(oop)) - && ((slotSizeOf(oop)) == 3) - ? firstIndexableField(oop) - : 0); + && ((slotSizeOf(oop)) == 3) + ? firstIndexableField(oop) + : 0); + /* begin stackVector3: */ - oop1 = stackValue(1); - v1 = ((isWords(oop1)) - && ((slotSizeOf(oop1)) == 3) - ? firstIndexableField(oop1) - : 0); + oop = stackValue(1); + v1 = ((isWords(oop)) + && ((slotSizeOf(oop)) == 3) + ? firstIndexableField(oop) + : 0); + /* begin stackVector3: */ - oop2 = stackValue(2); - v0 = ((isWords(oop2)) - && ((slotSizeOf(oop2)) == 3) - ? firstIndexableField(oop2) - : 0); + oop = stackValue(2); + v0 = ((isWords(oop)) + && ((slotSizeOf(oop)) == 3) + ? firstIndexableField(oop) + : 0); + /* begin stackVector3: */ - oop3 = stackValue(3); - maxCorner = ((isWords(oop3)) - && ((slotSizeOf(oop3)) == 3) - ? firstIndexableField(oop3) - : 0); + oop = stackValue(3); + maxCorner = ((isWords(oop)) + && ((slotSizeOf(oop)) == 3) + ? firstIndexableField(oop) + : 0); + /* begin stackVector3: */ - oop4 = stackValue(4); - minCorner = ((isWords(oop4)) - && ((slotSizeOf(oop4)) == 3) - ? firstIndexableField(oop4) - : 0); + oop = stackValue(4); + minCorner = ((isWords(oop)) + && ((slotSizeOf(oop)) == 3) + ? firstIndexableField(oop) + : 0); if ((!v0) || ((!v1) || ((!v2) @@ -926,12 +935,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -963,8 +971,8 @@ setInterpreter(struct VirtualMachine *anInterpreter) return ok; } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "CroquetPlugin"; diff --git a/src/plugins/DESPlugin/DESPlugin.c b/src/plugins/DESPlugin/DESPlugin.c index a8068e26ba..39086233a9 100644 --- a/src/plugins/DESPlugin/DESPlugin.c +++ b/src/plugins/DESPlugin/DESPlugin.c @@ -1,5 +1,5 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from DESPlugin CryptographyPlugins-eem.30 uuid: 53c9140e-9395-49f1-acb1-539c6fb29813 */ @@ -321,35 +321,39 @@ primitiveDESTransform(void) && ((stSizeOf(cookedOop)) == 32))))) { return primitiveFailFor(PrimErrBadArgument); } - data = ((unsigned char *) (firstIndexableField(dataOop))); + data = firstIndexableField(dataOop); + /* begin scrunch:to: */ - work[0] = ((((((usqInt)((data[0])) << 24)) + (((usqInt)((data[1])) << 16))) + (((usqInt)((data[2])) << 8))) + (data[3])); - work[1] = ((((((usqInt)((data[4])) << 24)) + (((usqInt)((data[5])) << 16))) + (((usqInt)((data[6])) << 8))) + (data[7])); + work[0] = (((((((usqInt)((data[0])) << 24))) + ((((usqInt)((data[1])) << 16)))) + ((((usqInt)((data[2])) << 8)))) + (data[3])); + work[1] = (((((((usqInt)((data[4])) << 24))) + ((((usqInt)((data[5])) << 16)))) + ((((usqInt)((data[6])) << 8)))) + (data[7])); key = firstIndexableField(cookedOop); + /* begin encrypt:with: */ left = work[0]; + /* perform required but otherwise pointless bit twizzling */ right = work[1]; work1 = ((((usqInt)(left)) >> 4) ^ right) & 0xF0F0F0F; right = right ^ work1; - left = left ^ (((usqInt)(work1) << 4)); + left = left ^ ((((usqInt)(work1) << 4))); work1 = ((((usqInt)(left)) >> 16) ^ right) & 0xFFFF; right = right ^ work1; - left = left ^ (((usqInt)(work1) << 16)); + left = left ^ ((((usqInt)(work1) << 16))); work1 = ((((usqInt)(right)) >> 2) ^ left) & 0x33333333; left = left ^ work1; - right = right ^ (((usqInt)(work1) << 2)); + right = right ^ ((((usqInt)(work1) << 2))); work1 = ((((usqInt)(right)) >> 8) ^ left) & 0xFF00FF; left = left ^ work1; - right = right ^ (((usqInt)(work1) << 8)); - right = ((((usqInt)(right) << 1)) | ((((usqInt)(right)) >> 0x1F) & 1)) & 0xFFFFFFFFU; + right = right ^ ((((usqInt)(work1) << 8))); + right = (((((usqInt)(right) << 1))) | ((((usqInt)(right)) >> 0x1F) & 1)) & 0xFFFFFFFFU; work1 = (left ^ right) & 0xAAAAAAAAU; left = left ^ work1; right = right ^ work1; + /* perform the 8 rounds of real encryption */ - left = ((((usqInt)(left) << 1)) | ((((usqInt)(left)) >> 0x1F) & 1)) & 0xFFFFFFFFU; + left = (((((usqInt)(left) << 1))) | ((((usqInt)(left)) >> 0x1F) & 1)) & 0xFFFFFFFFU; for (round = 0; round <= 28; round += 4) { - work1 = (((usqInt)(right) << 28)) | (((usqInt)(right)) >> 4); + work1 = ((((usqInt)(right) << 28))) | (((usqInt)(right)) >> 4); work1 = work1 ^ (key[round]); fVal = sp7[work1 & 0x3F]; fVal = fVal | (sp5[(((usqInt)(work1)) >> 8) & 0x3F]); @@ -361,7 +365,7 @@ primitiveDESTransform(void) fVal = fVal | (sp4[(((usqInt)(work1)) >> 16) & 0x3F]); fVal = fVal | (sp2[(((usqInt)(work1)) >> 24) & 0x3F]); left = left ^ fVal; - work1 = (((usqInt)(left) << 28)) | (((usqInt)(left)) >> 4); + work1 = ((((usqInt)(left) << 28))) | (((usqInt)(left)) >> 4); work1 = work1 ^ (key[round + 2]); fVal = sp7[work1 & 0x3F]; fVal = fVal | (sp5[(((usqInt)(work1)) >> 8) & 0x3F]); @@ -374,25 +378,26 @@ primitiveDESTransform(void) fVal = fVal | (sp2[(((usqInt)(work1)) >> 24) & 0x3F]); right = right ^ fVal; } - right = (((usqInt)(right) << 0x1F)) | (((usqInt)(right)) >> 1); + right = ((((usqInt)(right) << 0x1F))) | (((usqInt)(right)) >> 1); work1 = (left ^ right) & 0xAAAAAAAAU; left = left ^ work1; right = right ^ work1; - left = (((usqInt)(left) << 0x1F)) | (((usqInt)(left)) >> 1); + left = ((((usqInt)(left) << 0x1F))) | (((usqInt)(left)) >> 1); work1 = ((((usqInt)(left)) >> 8) ^ right) & 0xFF00FF; right = right ^ work1; - left = left ^ (((usqInt)(work1) << 8)); + left = left ^ ((((usqInt)(work1) << 8))); work1 = ((((usqInt)(left)) >> 2) ^ right) & 0x33333333; right = right ^ work1; - left = left ^ (((usqInt)(work1) << 2)); + left = left ^ ((((usqInt)(work1) << 2))); work1 = ((((usqInt)(right)) >> 16) ^ left) & 0xFFFF; left = left ^ work1; - right = right ^ (((usqInt)(work1) << 16)); + right = right ^ ((((usqInt)(work1) << 16))); work1 = ((((usqInt)(right)) >> 4) ^ left) & 0xF0F0F0F; left = left ^ work1; - right = right ^ (((usqInt)(work1) << 4)); + right = right ^ ((((usqInt)(work1) << 4))); work[0] = right; work[1] = left; + /* begin unscrunch:to: */ data[0] = ((((usqInt)((work[0]))) >> 24) & 0xFF); data[1] = ((((usqInt)((work[0]))) >> 16) & 0xFF); @@ -412,7 +417,7 @@ processKeymodeto(unsigned char *keyPtr, sqInt encode, unsigned int *cookedPtr) { unsigned int cook; sqInt i; - sqInt i1; + sqInt iSqInt; sqInt j; unsigned char l; sqInt m; @@ -427,7 +432,7 @@ processKeymodeto(unsigned char *keyPtr, sqInt encode, unsigned int *cookedPtr) for (j = 0; j <= 55; j += 1) { l = pc1[j]; m = l & 7; - if (((keyPtr[((usqInt)(l)) >> 3]) & (byteBit[m])) != 0) { + if ((keyPtr[((usqInt)(l)) >> 3]) & (byteBit[m])) { pc1m[j] = 1; } else { @@ -462,28 +467,29 @@ processKeymodeto(unsigned char *keyPtr, sqInt encode, unsigned int *cookedPtr) } } for (j = 0; j <= 23; j += 1) { - if ((pcr[pc2[j]]) != 0) { + if (pcr[pc2[j]]) { rawKey[m] = ((rawKey[m]) | (bigByte[j])); } - if ((pcr[pc2[j + 24]]) != 0) { + if (pcr[pc2[j + 24]]) { rawKey[n] = ((rawKey[n]) | (bigByte[j])); } } } + /* begin cookKey:to: */ - for (i1 = 0; i1 <= 15; i1 += 1) { - raw0 = rawKey[i1 * 2]; - raw1 = rawKey[(i1 * 2) + 1]; - cook = ((usqInt)((raw0 & 0xFC0000)) << 6); - cook = cook | (((usqInt)((raw0 & 0xFC0)) << 10)); + for (iSqInt = 0; iSqInt <= 15; iSqInt += 1) { + raw0 = rawKey[iSqInt * 2]; + raw1 = rawKey[(iSqInt * 2) + 1]; + cook = (((usqInt)((raw0 & 0xFC0000)) << 6)); + cook = cook | ((((usqInt)((raw0 & 0xFC0)) << 10))); cook = cook | (((usqInt)((raw1 & 0xFC0000))) >> 10); cook = cook | (((usqInt)((raw1 & 0xFC0))) >> 6); - cookedPtr[i1 * 2] = cook; - cook = ((usqInt)((raw0 & 0x3F000)) << 12); - cook = cook | (((usqInt)((raw0 & 0x3F)) << 16)); + cookedPtr[iSqInt * 2] = cook; + cook = (((usqInt)((raw0 & 0x3F000)) << 12)); + cook = cook | ((((usqInt)((raw0 & 0x3F)) << 16))); cook = cook | (((usqInt)((raw1 & 0x3F000))) >> 4); cook = cook | (raw1 & 0x3F); - cookedPtr[(i1 * 2) + 1] = cook; + cookedPtr[(iSqInt * 2) + 1] = cook; } return 0; } @@ -497,12 +503,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -526,8 +531,8 @@ setInterpreter(struct VirtualMachine *anInterpreter) return ok; } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "DESPlugin"; diff --git a/src/plugins/DSAPrims/DSAPrims.c b/src/plugins/DSAPrims/DSAPrims.c index df526a17dd..cb75ff105a 100644 --- a/src/plugins/DSAPrims/DSAPrims.c +++ b/src/plugins/DSAPrims/DSAPrims.c @@ -1,5 +1,5 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from DSAPlugin CryptographyPlugins-eem.30 uuid: 53c9140e-9395-49f1-acb1-539c6fb29813 */ @@ -119,16 +119,16 @@ primitiveBigDivide(void) unsigned char firstDigit; sqInt firstTwoDigits; sqInt i; - sqInt i1; + sqInt iSqInt; sqInt j; sqInt prod; sqInt q; sqInt qTooBig; sqInt quo; sqInt rem; - sqInt resultDigit; + int resultDigit; sqInt rIndex; - sqInt rIndex1; + sqInt rIndexSqInt; sqInt sum; unsigned char thirdDigit; @@ -148,18 +148,22 @@ primitiveBigDivide(void) dsaDivisor = firstIndexableField(div); dsaQuotient = firstIndexableField(quo); divisorDigitCount = stSizeOf(div); + /* adjust pointers for base-1 indexing */ remainderDigitCount = stSizeOf(rem); dsaRemainder -= 1; dsaDivisor -= 1; dsaQuotient -= 1; + /* begin bigDivideLoop */ d1 = dsaDivisor[divisorDigitCount]; d2 = dsaDivisor[divisorDigitCount - 1]; for (j = remainderDigitCount; j >= (divisorDigitCount + 1); j += -1) { + /* extract the top several digits of remainder. */ firstDigit = dsaRemainder[j]; - firstTwoDigits = ((((usqInt)(firstDigit) << 8))) + (dsaRemainder[j - 1]); + firstTwoDigits = (((((usqInt)(firstDigit) << 8)))) + (dsaRemainder[j - 1]); + /* estimate q, the next digit of the quotient */ thirdDigit = dsaRemainder[j - 2]; if (firstDigit == d1) { @@ -168,9 +172,9 @@ primitiveBigDivide(void) else { q = firstTwoDigits / d1; } - if ((d2 * q) > (((((sqInt)((usqInt)((firstTwoDigits - (q * d1))) << 8)))) + thirdDigit)) { + if ((d2 * q) > ((((((usqInt)((firstTwoDigits - (q * d1))) << 8)))) + thirdDigit)) { q -= 1; - if ((d2 * q) > (((((sqInt)((usqInt)((firstTwoDigits - (q * d1))) << 8)))) + thirdDigit)) { + if ((d2 * q) > ((((((usqInt)((firstTwoDigits - (q * d1))) << 8)))) + thirdDigit)) { q -= 1; } } @@ -184,6 +188,7 @@ primitiveBigDivide(void) borrow = (((usqInt)(prod)) >> 8); resultDigit = (dsaRemainder[rIndex]) - (prod & 0xFF); if (resultDigit < 0) { + /* borrow from the next digit */ resultDigit += 0x100; borrow += 1; @@ -191,12 +196,13 @@ primitiveBigDivide(void) dsaRemainder[rIndex] = resultDigit; rIndex += 1; } - if (borrow == 0) { + if (!borrow) { qTooBig = 0; goto l1; } resultDigit = (dsaRemainder[rIndex]) - borrow; if (resultDigit < 0) { + /* digit was too large (this case is quite rare) */ dsaRemainder[rIndex] = (resultDigit + 0x100); qTooBig = 1; @@ -205,20 +211,21 @@ primitiveBigDivide(void) dsaRemainder[rIndex] = resultDigit; qTooBig = 0; } - l1: /* end subtractDivisorMultipliedByDigit:digitShift: */; +l1: /* end subtractDivisorMultipliedByDigit:digitShift: */; if (qTooBig) { + /* this case is extremely rare */ /* begin addBackDivisorDigitShift: */ carry = 0; - rIndex1 = digitShift + 1; - for (i1 = 1; i1 <= divisorDigitCount; i1 += 1) { - sum = ((dsaRemainder[rIndex1]) + (dsaDivisor[i1])) + carry; - dsaRemainder[rIndex1] = (sum & 0xFF); + rIndexSqInt = digitShift + 1; + for (iSqInt = 1; iSqInt <= divisorDigitCount; iSqInt += 1) { + sum = ((dsaRemainder[rIndexSqInt]) + (dsaDivisor[iSqInt])) + carry; + dsaRemainder[rIndexSqInt] = (sum & 0xFF); carry = (((usqInt)(sum)) >> 8); - rIndex1 += 1; + rIndexSqInt += 1; } - sum = (dsaRemainder[rIndex1]) + carry; - dsaRemainder[rIndex1] = (sum & 0xFF); + sum = (dsaRemainder[rIndexSqInt]) + carry; + dsaRemainder[rIndexSqInt] = (sum & 0xFF); q -= 1; } } @@ -274,12 +281,13 @@ primitiveBigMultiply(void) if (!(prodLen == (f1Len + f2Len))) { return primitiveFailFor(PrimErrBadArgument); } - prodPtr = ((unsigned char *) (firstIndexableField(prod))); - f2Ptr = ((unsigned char *) (firstIndexableField(f2))); - f1Ptr = ((unsigned char *) (firstIndexableField(f1))); + prodPtr = firstIndexableField(prod); + f2Ptr = firstIndexableField(f2); + f1Ptr = firstIndexableField(f1); for (i = 0; i < f1Len; i += 1) { - if (((digit = f1Ptr[i])) != 0) { + if ((digit = f1Ptr[i])) { carry = 0; + /* Loop invariants: 0 <= carry <= 16rFF, k = i + j - 1 */ k = i; for (j = 0; j < f2Len; j += 1) { @@ -325,17 +333,17 @@ primitiveExpandBlock(void) && ((stSizeOf(buf)) == 64))))) { return primitiveFailFor(PrimErrBadArgument); } - wordPtr = ((unsigned int *) (firstIndexableField(expanded))); - bytePtr = ((unsigned char *) (firstIndexableField(buf))); + wordPtr = firstIndexableField(expanded); + bytePtr = firstIndexableField(buf); src = 0; for (i = 0; i <= 15; i += 1) { - v = (((((usqInt)((bytePtr[src])) << 24)) + (((usqInt)((bytePtr[src + 1])) << 16))) + (((usqInt)((bytePtr[src + 2])) << 8))) + (bytePtr[src + 3]); + v = ((((((usqInt)((bytePtr[src])) << 24))) + ((((usqInt)((bytePtr[src + 1])) << 16)))) + ((((usqInt)((bytePtr[src + 2])) << 8)))) + (bytePtr[src + 3]); wordPtr[i] = v; src += 4; } for (i = 16; i <= 79; i += 1) { v = (((wordPtr[i - 3]) ^ (wordPtr[i - 8])) ^ (wordPtr[i - 14])) ^ (wordPtr[i - 16]); - v = (v << 1) | ((v) >> (0x1F)); + v = ((v << 1)) | ((v) >> (0x1F)); wordPtr[i] = v; } methodReturnReceiver(); @@ -374,42 +382,42 @@ primitiveHashBlock(void) && ((stSizeOf(buf)) == 80))))) { return primitiveFailFor(PrimErrBadArgument); } - statePtr = ((unsigned int *) (firstIndexableField(state))); - bufPtr = ((unsigned int *) (firstIndexableField(buf))); + statePtr = firstIndexableField(state); + bufPtr = firstIndexableField(buf); a = statePtr[0]; b = statePtr[1]; c = statePtr[2]; d = statePtr[3]; e = statePtr[4]; for (i = 0; i <= 19; i += 1) { - tmp = (((0x5A827999 + ((b & c) | (((unsigned int)~b) & d))) + ((((usqInt)(a) << 5)) | (((usqInt)(a)) >> (27)))) + e) + (bufPtr[i]); + tmp = (((0x5A827999 + ((b & c) | (((unsigned int)~b) & d))) + (((((usqInt)(a) << 5))) | (((usqInt)(a)) >> (27)))) + e) + (bufPtr[i]); e = d; d = c; - c = (((usqInt)(b) << 30)) | (((usqInt)(b)) >> (2)); + c = ((((usqInt)(b) << 30))) | (((usqInt)(b)) >> (2)); b = a; a = tmp; } for (i = 20; i <= 39; i += 1) { - tmp = (((1859775393 + ((b ^ c) ^ d)) + ((((usqInt)(a) << 5)) | (((usqInt)(a)) >> (27)))) + e) + (bufPtr[i]); + tmp = (((1859775393 + ((b ^ c) ^ d)) + (((((usqInt)(a) << 5))) | (((usqInt)(a)) >> (27)))) + e) + (bufPtr[i]); e = d; d = c; - c = (((usqInt)(b) << 30)) | (((usqInt)(b)) >> (2)); + c = ((((usqInt)(b) << 30))) | (((usqInt)(b)) >> (2)); b = a; a = tmp; } for (i = 40; i <= 59; i += 1) { - tmp = (((2400959708U + (((b & c) | (b & d)) | (c & d))) + ((((usqInt)(a) << 5)) | (((usqInt)(a)) >> (27)))) + e) + (bufPtr[i]); + tmp = (((2400959708U + (((b & c) | (b & d)) | (c & d))) + (((((usqInt)(a) << 5))) | (((usqInt)(a)) >> (27)))) + e) + (bufPtr[i]); e = d; d = c; - c = (((usqInt)(b) << 30)) | (((usqInt)(b)) >> (2)); + c = ((((usqInt)(b) << 30))) | (((usqInt)(b)) >> (2)); b = a; a = tmp; } for (i = 60; i <= 79; i += 1) { - tmp = (((3395469782U + ((b ^ c) ^ d)) + ((((usqInt)(a) << 5)) | (((usqInt)(a)) >> (27)))) + e) + (bufPtr[i]); + tmp = (((3395469782U + ((b ^ c) ^ d)) + (((((usqInt)(a) << 5))) | (((usqInt)(a)) >> (27)))) + e) + (bufPtr[i]); e = d; d = c; - c = (((usqInt)(b) << 30)) | (((usqInt)(b)) >> (2)); + c = ((((usqInt)(b) << 30))) | (((usqInt)(b)) >> (2)); b = a; a = tmp; } @@ -453,7 +461,7 @@ primitiveHighestNonZeroDigitIndex(void) if (!((fetchClassOf(arg)) == (classLargePositiveInteger()))) { return primitiveFailFor(PrimErrBadArgument); } - bigIntPtr = ((unsigned char *) (firstIndexableField(arg))); + bigIntPtr = firstIndexableField(arg); i = stSizeOf(arg); while ((i > 0) && ((bigIntPtr[(i -= 1)]) == 0)) { @@ -471,12 +479,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -497,8 +504,8 @@ setInterpreter(struct VirtualMachine *anInterpreter) return ok; } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "DSAPrims"; diff --git a/src/plugins/DropPlugin/DropPlugin.c b/src/plugins/DropPlugin/DropPlugin.c index f243718fac..1ff9f2336d 100644 --- a/src/plugins/DropPlugin/DropPlugin.c +++ b/src/plugins/DropPlugin/DropPlugin.c @@ -1,9 +1,9 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3444 uuid: 2a902a4a-be82-4097-91a4-28da2fa623c8 + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - DropPlugin VMMaker.oscog-eem.3444 uuid: 2a902a4a-be82-4097-91a4-28da2fa623c8 + DropPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 */ -static char __buildInfo[] = "DropPlugin VMMaker.oscog-eem.3444 uuid: 2a902a4a-be82-4097-91a4-28da2fa623c8 " __DATE__ ; +static char __buildInfo[] = "DropPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 " __DATE__ ; #include "config.h" @@ -49,21 +49,21 @@ EXPORT(sqInt) shutdownModule(void); #if !defined(SQUEAK_BUILTIN_PLUGIN) static sqInt (*failed)(void); static sqInt (*methodArgumentCount)(void); -static sqInt (*methodReturnString)(char *aCString); +static sqInt (*methodReturnString)(const char *aCString); static sqInt (*methodReturnValue)(sqInt oop); static sqInt (*primitiveFail)(void); static sqInt (*stackIntegerValue)(sqInt offset); #else /* !defined(SQUEAK_BUILTIN_PLUGIN) */ extern sqInt failed(void); extern sqInt methodArgumentCount(void); -extern sqInt methodReturnString(char *aCString); +extern sqInt methodReturnString(const char *aCString); extern sqInt methodReturnValue(sqInt oop); extern sqInt primitiveFail(void); extern sqInt stackIntegerValue(sqInt offset); extern #endif struct VirtualMachine* interpreterProxy; -static const char *moduleName = "DropPlugin VMMaker.oscog-eem.3444 " INT_EXT; +static const char *moduleName = "DropPlugin VMMaker.oscog-eem.3456 " INT_EXT; /*** Methods ***/ @@ -127,6 +127,7 @@ primitiveDropRequestFileName(void) if (!((methodArgumentCount()) == 1)) { return primitiveFail(); } + /* dropRequestFileName returns name or NULL on error; methodReturnString: fails for nil */ dropIndex = stackIntegerValue(0); if (!(failed())) { @@ -149,6 +150,7 @@ primitiveDropRequestURI(void) if (!((methodArgumentCount()) == 1)) { return primitiveFail(); } + /* dropRequestURI returns name or NULL on error; methodReturnString: fails for nil */ dropIndex = stackIntegerValue(0); if (!(failed())) { @@ -166,12 +168,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -193,8 +194,8 @@ shutdownModule(void) return dropShutdown(); } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "DropPlugin"; diff --git a/src/plugins/FFTPlugin/FFTPlugin.c b/src/plugins/FFTPlugin/FFTPlugin.c index a8e24d9577..3904820de7 100644 --- a/src/plugins/FFTPlugin/FFTPlugin.c +++ b/src/plugins/FFTPlugin/FFTPlugin.c @@ -1,9 +1,9 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - FFTPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + FFTPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 */ -static char __buildInfo[] = "FFTPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f " __DATE__ ; +static char __buildInfo[] = "FFTPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 " __DATE__ ; #include "config.h" @@ -76,7 +76,7 @@ extern sqInt success(sqInt aBoolean); extern #endif struct VirtualMachine* interpreterProxy; -static const char *moduleName = "FFTPlugin VMMaker.oscog-eem.3455 " INT_EXT; +static const char *moduleName = "FFTPlugin VMMaker.oscog-eem.3456 " INT_EXT; static sqInt nu; static unsigned int * permTable; static sqInt permTableSize; @@ -119,39 +119,43 @@ loadFFTFrom(sqInt fftOop) fftSize = fetchIntegerofObject(1, fftOop); oop = fetchPointerofObject(2, fftOop); sinTableSize = stSizeOf(oop); + /* begin checkedFloatPtrOf: */ success(isWords(oop)); if (failed()) { sinTable = 0; goto l1; } - sinTable = ((float *) (firstIndexableField(oop))); - l1: /* end checkedFloatPtrOf: */; + sinTable = firstIndexableField(oop); +l1: /* end checkedFloatPtrOf: */; oop = fetchPointerofObject(3, fftOop); permTableSize = stSizeOf(oop); + /* begin checkedWordPtrOf: */ success(isWords(oop)); - permTable = ((unsigned int *) (firstIndexableField(oop))); + permTable = firstIndexableField(oop); oop = fetchPointerofObject(4, fftOop); realDataSize = stSizeOf(oop); + /* begin checkedFloatPtrOf: */ success(isWords(oop)); if (failed()) { realData = 0; - goto l3; + goto l2; } - realData = ((float *) (firstIndexableField(oop))); - l3: /* end checkedFloatPtrOf: */; + realData = firstIndexableField(oop); +l2: /* end checkedFloatPtrOf: */; oop = fetchPointerofObject(5, fftOop); imagDataSize = stSizeOf(oop); + /* begin checkedFloatPtrOf: */ success(isWords(oop)); if (failed()) { imagData = 0; - goto l4; + goto l3; } - imagData = ((float *) (firstIndexableField(oop))); - l4: /* end checkedFloatPtrOf: */; + imagData = firstIndexableField(oop); +l3: /* end checkedFloatPtrOf: */; success((((((1U << nu) == fftSize) && (((fftSize / 4) + 1) == sinTableSize)) && (fftSize == realDataSize)) && (fftSize == imagDataSize)) && (realDataSize == imagDataSize)); return (failed()) == 0; } @@ -160,8 +164,8 @@ loadFFTFrom(sqInt fftOop) static sqInt permuteData(void) { - unsigned int a; - unsigned int b; + int a; + int b; sqInt end; sqInt i; float tmp; @@ -195,6 +199,7 @@ primitiveFFTPermuteData(void) } permuteData(); if (failed()) { + /* permuteData went wrong. Do the permutation again -- this will restore the original order */ permuteData(); } @@ -237,13 +242,16 @@ primitiveFFTTransformData(void) if (!(loadFFTFrom(stackValue(1)))) { return null; } + /* begin transformData: */ permuteData(); if (failed()) { + /* permuteData went wrong. Do the permutation again -- this will restore the original order */ permuteData(); goto l1; } + /* begin transformForward: */ fftSize2 = fftSize / 2; fftSize4 = fftSize / 4; @@ -255,6 +263,7 @@ primitiveFFTTransformData(void) /* pi * (j-1) / lev1 mapped onto 0..n/2 */ theta = (j - 1) * fftScale; if (theta < fftSize4) { + /* Compute U, the complex multiplier for each level */ realU = sinTable[(sinTableSize - theta) - 1]; imagU = sinTable[theta]; @@ -283,7 +292,7 @@ primitiveFFTTransformData(void) if (!forward) { scaleData(); } - l1: /* end transformData: */; +l1: /* end transformData: */; if (!(failed())) { pop(1); } @@ -320,12 +329,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -345,8 +353,8 @@ setInterpreter(struct VirtualMachine *anInterpreter) return ok; } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "FFTPlugin"; diff --git a/src/plugins/FileAttributesPlugin/FileAttributesPlugin.c b/src/plugins/FileAttributesPlugin/FileAttributesPlugin.c index eb89126393..11ce43d597 100644 --- a/src/plugins/FileAttributesPlugin/FileAttributesPlugin.c +++ b/src/plugins/FileAttributesPlugin/FileAttributesPlugin.c @@ -1,9 +1,9 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - FileAttributesPlugin FileAttributesPlugin.oscog-eem.64 uuid: 7d40fd5c-6db1-4e27-9c56-5ca0b0ce4e14 + FileAttributesPlugin FileAttributesPlugin.oscog-eem.65 uuid: 4277ac8e-9085-40a2-aa02-739557859437 */ -static char __buildInfo[] = "FileAttributesPlugin FileAttributesPlugin.oscog-eem.64 uuid: 7d40fd5c-6db1-4e27-9c56-5ca0b0ce4e14 " __DATE__ ; +static char __buildInfo[] = "FileAttributesPlugin FileAttributesPlugin.oscog-eem.65 uuid: 4277ac8e-9085-40a2-aa02-739557859437 " __DATE__ ; #include "config.h" @@ -105,7 +105,7 @@ static void * (*ioLoadFunctionFrom)(char *functionName, char *moduleName); static sqInt (*isBytes)(sqInt oop); static sqInt (*methodReturnBool)(sqInt boolean); static sqInt (*methodReturnInteger)(sqInt integer); -static sqInt (*methodReturnString)(char *aCString); +static sqInt (*methodReturnString)(const char *aCString); static sqInt (*methodReturnValue)(sqInt oop); static sqInt (*nilObject)(void); static sqInt (*popthenPush)(sqInt nItems, sqInt oop); @@ -140,7 +140,7 @@ extern void * ioLoadFunctionFrom(char *functionName, char *moduleName); extern sqInt isBytes(sqInt oop); extern sqInt methodReturnBool(sqInt boolean); extern sqInt methodReturnInteger(sqInt integer); -extern sqInt methodReturnString(char *aCString); +extern sqInt methodReturnString(const char *aCString); extern sqInt methodReturnValue(sqInt oop); extern sqInt nilObject(void); extern sqInt popthenPush(sqInt nItems, sqInt oop); @@ -163,7 +163,7 @@ extern sqInt storePointerofObjectwithValue(sqInt index, sqInt oop, sqInt valuePo extern #endif struct VirtualMachine* interpreterProxy; -static const char *moduleName = "FileAttributesPlugin FileAttributesPlugin.oscog-eem.64 " INT_EXT; +static const char *moduleName = "FileAttributesPlugin FileAttributesPlugin.oscog-eem.65 " INT_EXT; static void * sCLPfn; static void * sCOFfn; static int hasSecurityPlugin = 1; @@ -200,16 +200,17 @@ attributeArrayformask(sqInt *attributeArrayPtr, fapath *faPath, sqInt attributeM getAccess = ((attributeMask & 2) != 0); if (!(getStats || (getAccess))) { + /* No information has been requested, which doesn't make sense */ - primitiveFailForOSError(-6 /* begin invalidArguments */); - return -6 /* begin invalidArguments */; + primitiveFailForOSError(-6 /* invalidArguments */); + return -6 /* invalidArguments */; } getLinkStats = ((attributeMask & 4) != 0); if (getStats) { attributeArray = instantiateClassindexableSize(classArray(), 13); if (!attributeArray) { primitiveFailFor(PrimErrNoMemory); - return -15 /* begin interpreterError */; + return -15 /* interpreterError */; } #if SPURVM @@ -219,7 +220,7 @@ attributeArrayformask(sqInt *attributeArrayPtr, fapath *faPath, sqInt attributeM status = faFileStatAttributes(faPath, getLinkStats, attributeArray); attributeArray = popRemappableOop(); #endif /* SPURVM */ - if (status != 0) { + if (status) { return status; } resultOop = attributeArray; @@ -235,11 +236,12 @@ attributeArrayformask(sqInt *attributeArrayPtr, fapath *faPath, sqInt attributeM #endif /* SPURVM */ if (!accessArray) { primitiveFailFor(PrimErrNoMemory); - /* begin interpreterError */ + + /* interpreterError */ } faAccessAttributes(faPath, accessArray, 0); if (failed()) { - return -15 /* begin interpreterError */; + return -15 /* interpreterError */; } resultOop = accessArray; } @@ -257,13 +259,14 @@ attributeArrayformask(sqInt *attributeArrayPtr, fapath *faPath, sqInt attributeM #endif /* SPURVM */ if (!resultOop) { primitiveFailFor(PrimErrNoMemory); - /* begin interpreterError */ + + /* interpreterError */ } storePointerofObjectwithValue(0, resultOop, attributeArray); storePointerofObjectwithValue(1, resultOop, accessArray); } attributeArrayPtr[0] = resultOop; - return 0 /* begin faSuccess */; + return 0 /* faSuccess */; } @@ -277,10 +280,10 @@ attributeArrayformask(sqInt *attributeArrayPtr, fapath *faPath, sqInt attributeM static sqInt canOpenDirectoryStreamForlength(char *aPathCString, sqInt length) { - if (hasSecurityPlugin == 0) { + if (!hasSecurityPlugin) { return 1; } - if (sCLPfn != 0) { + if (sCLPfn) { return ((int (*) (char *, int)) sCLPfn)(aPathCString, length); } else { @@ -336,13 +339,13 @@ primitiveChangeMode(void) return primitiveFailureCode(); } status = chmod(faGetPlatPath((&faPath)), newMode); - if (status != 0) { + if (status) { return primitiveFailForOSError(errno); } return methodReturnValue(nilObject()); # endif // HAVE_CHMOD - primitiveFailForOSError(-13 /* begin unsupportedOperation */); + primitiveFailForOSError(-13 /* unsupportedOperation */); return 0; } @@ -372,13 +375,13 @@ primitiveChangeOwner(void) return primitiveFailureCode(); } status = chown(faGetPlatPath((&faPath)), ownerId, groupId); - if (status != 0) { + if (status) { return primitiveFailForOSError(errno); } return methodReturnValue(nilObject()); # endif // HAVE_CHOWN - primitiveFailForOSError(-13 /* begin unsupportedOperation */); + primitiveFailForOSError(-13 /* unsupportedOperation */); return 0; } @@ -402,6 +405,7 @@ primitiveClosedir(void) dirPointerOop = stackValue(0); structSize = sizeof(FAPathPtr); + /* begin structFromObject:size: */ if (!((stSizeOf(dirPointerOop)) == structSize)) { primitiveFailFor(PrimErrBadArgument); @@ -409,24 +413,24 @@ primitiveClosedir(void) goto l1; } buffer = alloca(structSize); - if (buffer == 0) { - primitiveFailFor(PrimErrNoCMemory); + if (buffer) { + memcpy(buffer, arrayValueOf(dirPointerOop), structSize); } else { - memcpy(buffer, arrayValueOf(dirPointerOop), structSize); + primitiveFailFor(PrimErrNoCMemory); } faPathPtr = buffer; - l1: /* end structFromObject:size: */; - if (faPathPtr == 0) { +l1: /* end structFromObject:size: */; + if (!faPathPtr) { return primitiveFailFor(PrimErrBadArgument); } if (!(faValidateSessionId((faPathPtr->sessionId)))) { - return primitiveFailForOSError(-17 /* begin badSessionId */); + return primitiveFailForOSError(-17 /* badSessionId */); } faPath = (faPathPtr->faPath); result = faCloseDirectory(faPath); faInvalidateSessionId(&faPathPtr->sessionId); - if (!(result == 0)) { + if (result) { return primitiveFailForOSError(result); } free(faPath); @@ -471,12 +475,13 @@ primitiveFileAttribute(void) if (failed()) { return primitiveFailureCode(); } - if (resultOop == 0) { - /* It shouldn't be possible to get here */ - primitiveFailForOSError(-14 /* begin unexpectedError */); + if (resultOop) { + methodReturnValue(resultOop); } else { - methodReturnValue(resultOop); + + /* It shouldn't be possible to get here */ + primitiveFailForOSError(-14 /* unexpectedError */); } return 0; } @@ -513,7 +518,7 @@ primitiveFileAttributes(void) return primitiveFailureCode(); } status = attributeArrayformask((&resultOop), (&faPath), attributeMask); - if (status != 0) { + if (status) { return primitiveFailForOSError(status); } methodReturnValue(resultOop); @@ -586,7 +591,7 @@ primitiveFileMasks(void) # endif methodReturnValue(masksArray); - l1: /* end primitiveFileMasksAsArray */; +l1: /* end primitiveFileMasksAsArray */; } else { /* begin primitiveFileMasksAsWordArrayUsing: */ @@ -617,7 +622,7 @@ primitiveFileMasks(void) # endif methodReturnValue(masksObj); - l2: /* end primitiveFileMasksAsWordArrayUsing: */; +l2: /* end primitiveFileMasksAsWordArrayUsing: */; } return 0; } @@ -634,7 +639,7 @@ primitiveLogicalDrives(void) # if defined(_WIN32) mask = GetLogicalDrives(); - if (mask != 0) { + if (mask) { return popthenPush(1, positive32BitIntegerFor(mask)); } # endif @@ -655,7 +660,6 @@ primitiveOpendir(void) { sqInt addressOop; unsigned char *addressOopArrayPointer; - void *aMachineAddress; sqInt dirName; sqInt dirOop; fapath *faPath; @@ -672,7 +676,7 @@ primitiveOpendir(void) } faPath = (fapath *) calloc(1, sizeof(fapath)); if (!faPath) { - return primitiveFailForOSError(-10 /* begin cantAllocateMemory */); + return primitiveFailForOSError(-10 /* cantAllocateMemory */); } faSetStDirOop(faPath, dirName); if (failed()) { @@ -680,10 +684,10 @@ primitiveOpendir(void) } if (!(canOpenDirectoryStreamForlength(faGetStPath(faPath), faGetStPathLen(faPath)))) { free(faPath); - primitiveFailForOSError(-9 /* begin cantOpenDir */); + primitiveFailForOSError(-9 /* cantOpenDir */); } status = faOpenDirectory(faPath); - if (status == 1 /* begin noMoreData */) { + if (status == 1 /* noMoreData */) { free(faPath); return methodReturnValue(nilObject()); } @@ -700,8 +704,8 @@ primitiveOpendir(void) (faPathPtr.faPath = faPath); #if SPURVM - aMachineAddress = (&faPathPtr); structSize = sizeof(FAPathPtr); + /* begin objectFromStruct:size: */ addressOop = instantiateClassindexableSize(classByteArray(), structSize); if (!addressOop) { @@ -709,13 +713,13 @@ primitiveOpendir(void) goto l1; } addressOopArrayPointer = arrayValueOf(addressOop); - memcpy(addressOopArrayPointer, aMachineAddress, structSize); + memcpy(addressOopArrayPointer, (&faPathPtr), structSize); dirOop = addressOop; - l1: /* end objectFromStruct:size: */; +l1: /* end objectFromStruct:size: */; #else /* SPURVM */ pushRemappableOop(resultOop); - aMachineAddress = (&faPathPtr); structSize = sizeof(FAPathPtr); + /* begin objectFromStruct:size: */ addressOop = instantiateClassindexableSize(classByteArray(), structSize); if (!addressOop) { @@ -723,9 +727,9 @@ primitiveOpendir(void) goto l1; } addressOopArrayPointer = arrayValueOf(addressOop); - memcpy(addressOopArrayPointer, aMachineAddress, structSize); + memcpy(addressOopArrayPointer, (&faPathPtr), structSize); dirOop = addressOop; - l1: /* end objectFromStruct:size: */; +l1: /* end objectFromStruct:size: */; resultOop = popRemappableOop(); #endif /* SPURVM */ storePointerofObjectwithValue(2, resultOop, dirOop); @@ -740,7 +744,7 @@ primitiveOpendir(void) EXPORT(sqInt) primitivePathMax(void) { - return methodReturnInteger(FA_PATH_MAX /* begin faPathMax */); + return methodReturnInteger(FA_PATH_MAX /* faPathMax */); } @@ -796,6 +800,7 @@ primitiveReaddir(void) dirPointerOop = stackValue(0); structSize = sizeof(FAPathPtr); + /* begin structFromObject:size: */ if (!((stSizeOf(dirPointerOop)) == structSize)) { primitiveFailFor(PrimErrBadArgument); @@ -803,28 +808,29 @@ primitiveReaddir(void) goto l1; } buffer = alloca(structSize); - if (buffer == 0) { - primitiveFailFor(PrimErrNoCMemory); + if (buffer) { + memcpy(buffer, arrayValueOf(dirPointerOop), structSize); } else { - memcpy(buffer, arrayValueOf(dirPointerOop), structSize); + primitiveFailFor(PrimErrNoCMemory); } faPathPtr = buffer; - l1: /* end structFromObject:size: */; - if (faPathPtr == 0) { +l1: /* end structFromObject:size: */; + if (!faPathPtr) { return primitiveFailFor(PrimErrBadArgument); } if (!(faValidateSessionId((faPathPtr->sessionId)))) { - return primitiveFailForOSError(-17 /* begin badSessionId */); + return primitiveFailForOSError(-17 /* badSessionId */); } faPath = (faPathPtr->faPath); status = faReadDirectory(faPath); - if (status == 1 /* begin noMoreData */) { + if (status == 1 /* noMoreData */) { return methodReturnValue(nilObject()); } if (status < 0) { return primitiveFailForOSError(status); } + /* no need to check the status of #processDirectory: as it will have flagged an error with interpreterProxy */ resultArray = processDirectory(faPath); methodReturnValue(resultArray); @@ -848,6 +854,7 @@ primitiveRewinddir(void) dirPointerOop = stackValue(0); structSize = sizeof(FAPathPtr); + /* begin structFromObject:size: */ if (!((stSizeOf(dirPointerOop)) == structSize)) { primitiveFailFor(PrimErrBadArgument); @@ -855,25 +862,26 @@ primitiveRewinddir(void) goto l1; } buffer = alloca(structSize); - if (buffer == 0) { - primitiveFailFor(PrimErrNoCMemory); + if (buffer) { + memcpy(buffer, arrayValueOf(dirPointerOop), structSize); } else { - memcpy(buffer, arrayValueOf(dirPointerOop), structSize); + primitiveFailFor(PrimErrNoCMemory); } faPathPtr = buffer; - l1: /* end structFromObject:size: */; - if (faPathPtr == 0) { +l1: /* end structFromObject:size: */; + if (!faPathPtr) { return primitiveFailFor(PrimErrBadArgument); } if (!(faValidateSessionId((faPathPtr->sessionId)))) { - return primitiveFailForOSError(-17 /* begin badSessionId */); + return primitiveFailForOSError(-17 /* badSessionId */); } faPath = (faPathPtr->faPath); status = faRewindDirectory(faPath); if (status < 0) { return primitiveFailForOSError(status); } + /* no need to check the status of #processDirectory: as it will have flagged an error with interpreterProxy */ resultOop = processDirectory(faPath); methodReturnValue(resultOop); @@ -939,13 +947,13 @@ primitiveSymlinkChangeOwner(void) return primitiveFailureCode(); } status = lchown(faGetPlatPath((&faPath)), ownerId, groupId); - if (status != 0) { + if (status) { return primitiveFailForOSError(errno); } return methodReturnValue(nilObject()); # endif // HAVE_CHOWN - primitiveFailForOSError(-13 /* begin unsupportedOperation */); + primitiveFailForOSError(-13 /* unsupportedOperation */); return 0; } @@ -956,7 +964,7 @@ primitiveSymlinkChangeOwner(void) EXPORT(sqInt) primitiveVersionString(void) { - methodReturnString("2.0.9" /* begin versionString */); + methodReturnString("2.0.9" /* versionString */); return 0; } @@ -979,13 +987,14 @@ processDirectory(fapath *faPath) attributeArray = 0; entryName = 0; status = faCharToByteArray(faGetStFile(faPath), (&entryName)); - if (status != 0) { + if (status) { return primitiveFailForOSError(status); } + /* If the stat() fails, still return the filename, just no attributes */ status = attributeArrayformask((&attributeArray), faPath, 1); - if (status != 0) { - if (status == -3 /* begin cantStatPath */) { + if (status) { + if (status == -3 /* cantStatPath */) { attributeArray = nilObject(); } else { @@ -1019,12 +1028,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -1075,8 +1083,8 @@ setInterpreter(struct VirtualMachine *anInterpreter) return ok; } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "FileAttributesPlugin"; diff --git a/src/plugins/FileDialogPlugin/FileDialogPlugin.c b/src/plugins/FileDialogPlugin/FileDialogPlugin.c index aa3617fce8..371fdfb0ab 100644 --- a/src/plugins/FileDialogPlugin/FileDialogPlugin.c +++ b/src/plugins/FileDialogPlugin/FileDialogPlugin.c @@ -1,9 +1,9 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3444 uuid: 2a902a4a-be82-4097-91a4-28da2fa623c8 + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - FileDialogPlugin VMMaker.oscog-eem.3444 uuid: 2a902a4a-be82-4097-91a4-28da2fa623c8 + FileDialogPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 */ -static char __buildInfo[] = "FileDialogPlugin VMMaker.oscog-eem.3444 uuid: 2a902a4a-be82-4097-91a4-28da2fa623c8 " __DATE__ ; +static char __buildInfo[] = "FileDialogPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 " __DATE__ ; #include "config.h" @@ -67,7 +67,7 @@ static sqInt (*methodArgumentCount)(void); static sqInt (*methodReturnBool)(sqInt boolean); static sqInt (*methodReturnInteger)(sqInt integer); static sqInt (*methodReturnReceiver)(void); -static sqInt (*methodReturnString)(char *aCString); +static sqInt (*methodReturnString)(const char *aCString); static sqInt (*methodReturnValue)(sqInt oop); static sqInt (*nilObject)(void); static usqInt (*positive32BitValueOf)(sqInt oop); @@ -85,7 +85,7 @@ extern sqInt methodArgumentCount(void); extern sqInt methodReturnBool(sqInt boolean); extern sqInt methodReturnInteger(sqInt integer); extern sqInt methodReturnReceiver(void); -extern sqInt methodReturnString(char *aCString); +extern sqInt methodReturnString(const char *aCString); extern sqInt methodReturnValue(sqInt oop); extern sqInt nilObject(void); extern usqInt positive32BitValueOf(sqInt oop); @@ -96,7 +96,7 @@ extern sqInt stackValue(sqInt offset); extern #endif struct VirtualMachine* interpreterProxy; -static const char *moduleName = "FileDialogPlugin VMMaker.oscog-eem.3444 " INT_EXT; +static const char *moduleName = "FileDialogPlugin VMMaker.oscog-eem.3456 " INT_EXT; /*** Methods ***/ @@ -135,17 +135,15 @@ primitiveFileDialogAddFilter(void) { int dlgHandle; char *dstPtr; - char *dstPtr1; char *filterDesc; char *filterPattern; sqInt obj; - sqInt obj1; sqInt sz; - sqInt sz1; if (!((methodArgumentCount()) == 3)) { return primitiveFail(); } + /* begin stackEphemeralStringValue: */ obj = stackValue(0); if (!(isBytes(obj))) { @@ -163,25 +161,26 @@ primitiveFileDialogAddFilter(void) memcpy(dstPtr, firstIndexableField(obj), sz); dstPtr[sz] = 0; filterPattern = dstPtr; - l1: /* end stackEphemeralStringValue: */; +l1: /* end stackEphemeralStringValue: */; + /* begin stackEphemeralStringValue: */ - obj1 = stackValue(1); - if (!(isBytes(obj1))) { + obj = stackValue(1); + if (!(isBytes(obj))) { primitiveFailFor(PrimErrBadArgument); filterDesc = null; goto l2; } - sz1 = byteSizeOf(obj1); - dstPtr1 = alloca(sz1 + 1); - if (!dstPtr1) { + sz = byteSizeOf(obj); + dstPtr = alloca(sz + 1); + if (!dstPtr) { primitiveFailFor(PrimErrNoCMemory); filterDesc = null; goto l2; } - memcpy(dstPtr1, firstIndexableField(obj1), sz1); - dstPtr1[sz1] = 0; - filterDesc = dstPtr1; - l2: /* end stackEphemeralStringValue: */; + memcpy(dstPtr, firstIndexableField(obj), sz); + dstPtr[sz] = 0; + filterDesc = dstPtr; +l2: /* end stackEphemeralStringValue: */; dlgHandle = ((int) (positive32BitValueOf(stackValue(2)))); if (failed()) { return primitiveFailFor(PrimErrBadArgument); @@ -216,7 +215,7 @@ primitiveFileDialogCreate(void) { sqInt dlgHandle; - if (!((methodArgumentCount()) == 0)) { + if (methodArgumentCount()) { return primitiveFailFor(PrimErrBadNumArgs); } dlgHandle = fileDialogCreate(); @@ -250,6 +249,7 @@ primitiveFileDialogDestroy(void) if (failed()) { return null; } + /* inSmalltalk: false */ ok = fileDialogDestroy(dlgHandle); if (!ok) { @@ -328,9 +328,10 @@ primitiveFileDialogGetFilterIndex(void) if (failed()) { return null; } + /* inSmalltalk: 0 */ result = fileDialogGetFilterIndex(dlgHandle); - if (result == 0) { + if (!result) { return primitiveFail(); } methodReturnInteger(result); @@ -358,21 +359,21 @@ primitiveFileDialogGetResult(void) dlgHandle = ((int) (positive32BitValueOf(stackValue(0)))); if (!(failed())) { results = fileDialogGetResults(dlgHandle); - if (results == null) { + if (results) { + methodReturnValue(results); + } + else { cString = fileDialogGetResult(dlgHandle); if (!(failed())) { /* begin methodReturnStringOrNil: */ - if (cString == null) { - methodReturnValue(nilObject()); + if (cString) { + methodReturnString(cString); } else { - methodReturnString(cString); + methodReturnValue(nilObject()); } } } - else { - methodReturnValue(results); - } } return 0; } @@ -410,6 +411,7 @@ primitiveFileDialogSetFile(void) if (!((methodArgumentCount()) == 2)) { return primitiveFail(); } + /* begin stackEphemeralStringValue: */ obj = stackValue(0); if (!(isBytes(obj))) { @@ -427,7 +429,7 @@ primitiveFileDialogSetFile(void) memcpy(dstPtr, firstIndexableField(obj), sz); dstPtr[sz] = 0; filePath = dstPtr; - l1: /* end stackEphemeralStringValue: */; +l1: /* end stackEphemeralStringValue: */; dlgHandle = ((int) (positive32BitValueOf(stackValue(1)))); if (failed()) { return primitiveFailFor(PrimErrBadArgument); @@ -483,6 +485,7 @@ primitiveFileDialogSetLabel(void) if (!((methodArgumentCount()) == 2)) { return primitiveFail(); } + /* begin stackEphemeralStringValue: */ obj = stackValue(0); if (!(isBytes(obj))) { @@ -500,7 +503,7 @@ primitiveFileDialogSetLabel(void) memcpy(dstPtr, firstIndexableField(obj), sz); dstPtr[sz] = 0; dlgLabel = dstPtr; - l1: /* end stackEphemeralStringValue: */; +l1: /* end stackEphemeralStringValue: */; dlgHandle = ((int) (positive32BitValueOf(stackValue(1)))); if (failed()) { return primitiveFailFor(PrimErrBadArgument); @@ -533,6 +536,7 @@ primitiveFileDialogSetProperty(void) return primitiveFail(); } dlgHandle = ((int) (positive32BitValueOf(stackValue(2)))); + /* begin stackEphemeralStringValue: */ obj = stackValue(1); if (!(isBytes(obj))) { @@ -550,7 +554,7 @@ primitiveFileDialogSetProperty(void) memcpy(dstPtr, firstIndexableField(obj), sz); dstPtr[sz] = 0; propName = dstPtr; - l1: /* end stackEphemeralStringValue: */; +l1: /* end stackEphemeralStringValue: */; propValue = booleanValueOf(stackValue(0)); if (failed()) { return primitiveFailFor(PrimErrBadArgument); @@ -621,6 +625,7 @@ primitiveGetFileLocation(void) if (!((methodArgumentCount()) == 1)) { return primitiveFail(); } + /* begin stackEphemeralStringValue: */ obj = stackValue(0); if (!(isBytes(obj))) { @@ -638,17 +643,18 @@ primitiveGetFileLocation(void) memcpy(dstPtr, firstIndexableField(obj), sz); dstPtr[sz] = 0; location = dstPtr; - l1: /* end stackEphemeralStringValue: */; +l1: /* end stackEphemeralStringValue: */; if (failed()) { return primitiveFailFor(PrimErrBadArgument); } cString = ((char *) (fileDialogGetLocation(location))); + /* begin methodReturnStringOrNil: */ - if (cString == null) { - methodReturnValue(nilObject()); + if (cString) { + methodReturnString(cString); } else { - methodReturnString(cString); + methodReturnValue(nilObject()); } return 0; } @@ -662,12 +668,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -693,8 +698,8 @@ setInterpreter(struct VirtualMachine *anInterpreter) return ok; } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "FileDialogPlugin"; diff --git a/src/plugins/FilePlugin/FilePlugin.c b/src/plugins/FilePlugin/FilePlugin.c index 41f96208e4..35007fa9ad 100644 --- a/src/plugins/FilePlugin/FilePlugin.c +++ b/src/plugins/FilePlugin/FilePlugin.c @@ -1,9 +1,9 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - FilePlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + FilePlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 */ -static char __buildInfo[] = "FilePlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f " __DATE__ ; +static char __buildInfo[] = "FilePlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 " __DATE__ ; #include "config.h" @@ -199,7 +199,7 @@ extern sqInt trueObject(void); extern #endif struct VirtualMachine* interpreterProxy; -static const char *moduleName = "FilePlugin VMMaker.oscog-eem.3455 " INT_EXT; +static const char *moduleName = "FilePlugin VMMaker.oscog-eem.3456 " INT_EXT; static void * sCCPfn; static void * sCDFfn; static void * sCDPfn; @@ -226,6 +226,7 @@ fileOpenNamesizewritesecure(char *nameIndex, sqInt nameSize, sqInt writeFlag, sq sqInt okToOpen; fileOop = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); + /* begin fileValueOf: */ if (!((isBytes(fileOop)) && ((byteSizeOf(fileOop)) == (sizeof(SQFile))))) { @@ -234,12 +235,13 @@ fileOpenNamesizewritesecure(char *nameIndex, sqInt nameSize, sqInt writeFlag, sq goto l1; } file = firstIndexableField(fileOop); - l1: /* end fileValueOf: */; +l1: /* end fileValueOf: */; if (!(failed())) { if (secureFlag) { + /* If the security plugin can be loaded, use it to check for permission. If not, assume it's ok */ - if (sCOFfn != 0) { + if (sCOFfn) { okToOpen = ((sqInt (*) (char *, sqInt, sqInt)) sCOFfn)(nameIndex, nameSize, writeFlag); if (!okToOpen) { return primitiveFailFor(PrimErrOperationFailed); @@ -264,6 +266,7 @@ fileOpenNewNamesizesecure(char *nameIndex, sqInt nameSize, sqInt secureFlag) sqInt okToOpen; fileOop = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); + /* begin fileValueOf: */ if (!((isBytes(fileOop)) && ((byteSizeOf(fileOop)) == (sizeof(SQFile))))) { @@ -272,12 +275,13 @@ fileOpenNewNamesizesecure(char *nameIndex, sqInt nameSize, sqInt secureFlag) goto l1; } file = firstIndexableField(fileOop); - l1: /* end fileValueOf: */; +l1: /* end fileValueOf: */; if (!(failed())) { if (secureFlag) { + /* If the security plugin can be loaded, use it to check for permission. If not, assume it's ok */ - if (sCOFfn != 0) { + if (sCOFfn) { okToOpen = ((sqInt (*) (char *, sqInt, sqInt)) sCOFfn)(nameIndex, nameSize, true); if (!okToOpen) { return primitiveFailFor(PrimErrOperationFailed); @@ -288,6 +292,7 @@ fileOpenNewNamesizesecure(char *nameIndex, sqInt nameSize, sqInt secureFlag) sqFileOpenNew(file, nameIndex, nameSize, (&exists)); if ((failed()) || (exists)) { + /* worry not; it is sqFileOpenNew's responsibility to close the file if it exists */ primitiveFailFor(PrimErrInappropriate); } @@ -339,7 +344,7 @@ getModuleName(void) EXPORT(sqInt) initialiseModule(void) { - if (!( /* begin interpreterProxyHasCharacterObjectOf */ + if (!(/* interpreterProxyHasCharacterObjectOf */ ((interpreterProxy->majorVersion()) > 1) || ((interpreterProxy->minorVersion()) >= 13))) { return 0; @@ -393,7 +398,7 @@ makeDirEntryNamesizecreateDatemodDateisDirfileSize(char *entryName, sqInt entryN nameString = popRemappableOop(); results = popRemappableOop(); #endif /* SPURVM */ - stringPtr = ((char *) (firstIndexableField(nameString))); + stringPtr = firstIndexableField(nameString); for (i = 0; i < entryNameSize; i += 1) { stringPtr[i] = (entryName[i]); } @@ -401,8 +406,8 @@ makeDirEntryNamesizecreateDatemodDateisDirfileSize(char *entryName, sqInt entryN storePointerofObjectwithValue(1, results, createDateOop); storePointerofObjectwithValue(2, results, modDateOop); storePointerofObjectwithValue(3, results, (dirFlag - ? trueObject() - : falseObject())); + ? trueObject() + : falseObject())); storePointerofObjectwithValue(4, results, fileSizeOop); return results; } @@ -449,7 +454,7 @@ makeDirEntryNamesizecreateDatemodDateisDirfileSizeposixPermissionsisSymlink(char nameString = popRemappableOop(); results = popRemappableOop(); #endif /* SPURVM */ - stringPtr = ((char *) (firstIndexableField(nameString))); + stringPtr = firstIndexableField(nameString); for (i = 0; i < entryNameSize; i += 1) { stringPtr[i] = (entryName[i]); } @@ -457,13 +462,13 @@ makeDirEntryNamesizecreateDatemodDateisDirfileSizeposixPermissionsisSymlink(char storePointerofObjectwithValue(1, results, createDateOop); storePointerofObjectwithValue(2, results, modDateOop); storePointerofObjectwithValue(3, results, (dirFlag - ? trueObject() - : falseObject())); + ? trueObject() + : falseObject())); storePointerofObjectwithValue(4, results, fileSizeOop); storePointerofObjectwithValue(5, results, posixPermissionsOop); storePointerofObjectwithValue(6, results, (symlinkFlag - ? trueObject() - : falseObject())); + ? trueObject() + : falseObject())); return results; } #endif /* PharoVM */ @@ -476,7 +481,8 @@ makeDirEntryNamesizecreateDatemodDateisDirfileSizeposixPermissionsisSymlink(char EXPORT(sqInt) moduleUnloaded(char *aModuleName) { - if ((strcmp(aModuleName, "SecurityPlugin")) == 0) { + if (!(strcmp(aModuleName, "SecurityPlugin"))) { + /* The security plugin just shut down. How odd. */ sCCPfn = (sCDPfn = (sCGFTfn = (sCLPfn = (sCSFTfn = (sDFAfn = (sCDFfn = (sCOFfn = (sCRFfn = (sHFAfn = 0))))))))); } @@ -497,7 +503,6 @@ primitiveConnectToFile(void) void *cfile; sqInt cfileOop; SQFile *file; - sqInt fileOop; sqInt filePointer; sqInt writeFlag; @@ -508,20 +513,20 @@ primitiveConnectToFile(void) return primitiveFailFor(PrimErrBadArgument); } cfile = (*((void **) (firstIndexableField(cfileOop)))); + /* begin connectToFile:write: */ - fileOop = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); - if (!((isBytes(fileOop)) - && ((byteSizeOf(fileOop)) == (sizeof(SQFile))))) { + filePointer = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); + if (!((isBytes(filePointer)) + && ((byteSizeOf(filePointer)) == (sizeof(SQFile))))) { primitiveFailFor(PrimErrBadArgument); file = null; goto l1; } - file = firstIndexableField(fileOop); - l1: /* end fileValueOf: */; + file = firstIndexableField(filePointer); +l1: /* end fileValueOf: */; if (!(failed())) { sqConnectToFile(file, cfile, writeFlag); } - filePointer = fileOop; if (!(failed())) { methodReturnValue(filePointer); } @@ -541,7 +546,6 @@ primitiveConnectToFileDescriptor(void) { sqInt fdPointer; SQFile *file; - sqInt fileOop; sqInt filePointer; sqInt writeFlag; @@ -551,20 +555,20 @@ primitiveConnectToFileDescriptor(void) && (isIntegerObject(fdPointer)))) { return primitiveFailFor(PrimErrBadArgument); } + /* begin connectToFd:write: */ - fileOop = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); - if (!((isBytes(fileOop)) - && ((byteSizeOf(fileOop)) == (sizeof(SQFile))))) { + filePointer = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); + if (!((isBytes(filePointer)) + && ((byteSizeOf(filePointer)) == (sizeof(SQFile))))) { primitiveFailFor(PrimErrBadArgument); file = null; goto l1; } - file = firstIndexableField(fileOop); - l1: /* end fileValueOf: */; + file = firstIndexableField(filePointer); +l1: /* end fileValueOf: */; if (!(failed())) { sqConnectToFileDescriptor(file, ((int) (integerValueOf(fdPointer))), writeFlag); } - filePointer = fileOop; if (!(failed())) { methodReturnValue(filePointer); } @@ -584,11 +588,12 @@ primitiveDirectoryCreate(void) if (!(isBytes(dirName))) { return primitiveFail(); } - dirNameIndex = ((char *) (firstIndexableField(dirName))); + dirNameIndex = firstIndexableField(dirName); + /* If the security plugin can be loaded, use it to check for permission. If not, assume it's ok */ dirNameSize = byteSizeOf(dirName); - if (sCCPfn != 0) { + if (sCCPfn) { okToCreate = ((sqInt (*)(char *, sqInt))sCCPfn)(dirNameIndex, dirNameSize); if (!okToCreate) { return primitiveFail(); @@ -614,11 +619,12 @@ primitiveDirectoryDelete(void) if (!(isBytes(dirName))) { return primitiveFail(); } - dirNameIndex = ((char *) (firstIndexableField(dirName))); + dirNameIndex = firstIndexableField(dirName); + /* If the security plugin can be loaded, use it to check for permission. If not, assume it's ok */ dirNameSize = byteSizeOf(dirName); - if (sCDPfn != 0) { + if (sCDPfn) { okToDelete = ((sqInt (*)(char *, sqInt))sCDPfn)(dirNameIndex, dirNameSize); if (!okToDelete) { return primitiveFail(); @@ -691,20 +697,21 @@ primitiveDirectoryEntry(void) if (!(isBytes(pathName))) { return primitiveFail(); } - pathNameIndex = ((char *) (firstIndexableField(pathName))); + pathNameIndex = firstIndexableField(pathName); pathNameSize = byteSizeOf(pathName); - reqNameIndex = ((char *) (firstIndexableField(requestedName))); + reqNameIndex = firstIndexableField(requestedName); reqNameSize = byteSizeOf(requestedName); - okToList = (sCLPfn != 0 - ? ((sqInt (*)(char *, sqInt))sCLPfn)(pathNameIndex, pathNameSize) - : 1); + okToList = (sCLPfn + ? ((sqInt (*)(char *, sqInt))sCLPfn)(pathNameIndex, pathNameSize) + : 1); status = (okToList - ? dir_EntryLookup(pathNameIndex, pathNameSize, reqNameIndex, reqNameSize, entryName, (&entryNameSize), (&createDate), (&modifiedDate), (&dirFlag), (&fileSize), (&posixPermissions), (&symlinkFlag)) - : DirNoMoreEntries); + ? dir_EntryLookup(pathNameIndex, pathNameSize, reqNameIndex, reqNameSize, entryName, (&entryNameSize), (&createDate), (&modifiedDate), (&dirFlag), (&fileSize), (&posixPermissions), (&symlinkFlag)) + : DirNoMoreEntries); if (failed()) { return null; } if (status == DirNoMoreEntries) { + /* no entry; return nil */ /* pop pathName, index, rcvr */ popthenPush(3, nilObject()); @@ -750,13 +757,14 @@ primitiveDirectoryGetMacTypeAndCreator(void) if (!(isBytes(fileName))) { return primitiveFail(); } - creatorStringIndex = ((char *) (firstIndexableField(creatorString))); - typeStringIndex = ((char *) (firstIndexableField(typeString))); - fileNameIndex = ((char *) (firstIndexableField(fileName))); + creatorStringIndex = firstIndexableField(creatorString); + typeStringIndex = firstIndexableField(typeString); + fileNameIndex = firstIndexableField(fileName); + /* If the security plugin can be loaded, use it to check for permission. If not, assume it's ok */ fileNameSize = byteSizeOf(fileName); - if (sCGFTfn != 0) { + if (sCGFTfn) { okToGet = ((sqInt (*)(char *, sqInt))sCGFTfn)(fileNameIndex, fileNameSize); if (!okToGet) { return primitiveFail(); @@ -819,18 +827,19 @@ primitiveDirectoryLookup(void) if (!(isBytes(pathName))) { return primitiveFail(); } - pathNameIndex = ((char *) (firstIndexableField(pathName))); + pathNameIndex = firstIndexableField(pathName); pathNameSize = byteSizeOf(pathName); - okToList = (sCLPfn != 0 - ? ((sqInt (*)(char *, sqInt))sCLPfn)(pathNameIndex, pathNameSize) - : 1); + okToList = (sCLPfn + ? ((sqInt (*)(char *, sqInt))sCLPfn)(pathNameIndex, pathNameSize) + : 1); status = (okToList - ? dir_Lookup(pathNameIndex, pathNameSize, index, entryName, (&entryNameSize), (&createDate), (&modifiedDate), (&dirFlag), (&fileSize), (&posixPermissions), (&symlinkFlag)) - : DirNoMoreEntries); + ? dir_Lookup(pathNameIndex, pathNameSize, index, entryName, (&entryNameSize), (&createDate), (&modifiedDate), (&dirFlag), (&fileSize), (&posixPermissions), (&symlinkFlag)) + : DirNoMoreEntries); if (failed()) { return null; } if (status == DirNoMoreEntries) { + /* no more entries; return nil */ /* pop pathName, index, rcvr */ popthenPush(3, nilObject()); @@ -872,13 +881,14 @@ primitiveDirectorySetMacTypeAndCreator(void) && ((byteSizeOf(typeString)) == 4)))))) { return primitiveFail(); } - creatorStringIndex = ((char *) (firstIndexableField(creatorString))); - typeStringIndex = ((char *) (firstIndexableField(typeString))); - fileNameIndex = ((char *) (firstIndexableField(fileName))); + creatorStringIndex = firstIndexableField(creatorString); + typeStringIndex = firstIndexableField(typeString); + fileNameIndex = firstIndexableField(fileName); + /* If the security plugin can be loaded, use it to check for permission. If not, assume it's ok */ fileNameSize = byteSizeOf(fileName); - if (sCSFTfn != 0) { + if (sCSFTfn) { okToSet = ((sqInt (*)(char *, sqInt))sCSFTfn)(fileNameIndex, fileNameSize); if (!okToSet) { return primitiveFail(); @@ -899,7 +909,7 @@ primitiveDirectorySetMacTypeAndCreator(void) EXPORT(sqInt) primitiveDisableFileAccess(void) { - if (sDFAfn != 0) { + if (sDFAfn) { ((sqInt (*)(void))sDFAfn)(); } return 0; @@ -914,6 +924,7 @@ primitiveFileAtEnd(void) sqInt objectPointer; objectPointer = stackValue(0); + /* begin fileValueOf: */ if (!((isBytes(objectPointer)) && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))) { @@ -922,7 +933,7 @@ primitiveFileAtEnd(void) goto l1; } file = firstIndexableField(objectPointer); - l1: /* end fileValueOf: */; +l1: /* end fileValueOf: */; if (!(failed())) { atEnd = sqFileAtEnd(file); if (!(failed())) { @@ -940,6 +951,7 @@ primitiveFileClose(void) sqInt objectPointer; objectPointer = stackValue(0); + /* begin fileValueOf: */ if (!((isBytes(objectPointer)) && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))) { @@ -948,7 +960,7 @@ primitiveFileClose(void) goto l1; } file = firstIndexableField(objectPointer); - l1: /* end fileValueOf: */; +l1: /* end fileValueOf: */; if (!(failed())) { sqFileClose(file); if (!(failed())) { @@ -971,11 +983,12 @@ primitiveFileDelete(void) if (!(isBytes(namePointer))) { return primitiveFailFor(PrimErrBadArgument); } - nameIndex = ((char *) (firstIndexableField(namePointer))); + nameIndex = firstIndexableField(namePointer); + /* If the security plugin can be loaded, use it to check for permission. If not, assume it's ok */ nameSize = byteSizeOf(namePointer); - if (sCDFfn != 0) { + if (sCDFfn) { okToDelete = ((sqInt (*)(char *, sqInt))sCDFfn)(nameIndex, nameSize); if (!okToDelete) { return primitiveFail(); @@ -1020,6 +1033,7 @@ primitiveFileFlush(void) sqInt objectPointer; objectPointer = stackValue(0); + /* begin fileValueOf: */ if (!((isBytes(objectPointer)) && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))) { @@ -1028,7 +1042,7 @@ primitiveFileFlush(void) goto l1; } file = firstIndexableField(objectPointer); - l1: /* end fileValueOf: */; +l1: /* end fileValueOf: */; if (!(failed())) { sqFileFlush(file); if (!(failed())) { @@ -1047,6 +1061,7 @@ primitiveFileGetPosition(void) squeakFileOffsetType position; objectPointer = stackValue(0); + /* begin fileValueOf: */ if (!((isBytes(objectPointer)) && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))) { @@ -1055,7 +1070,7 @@ primitiveFileGetPosition(void) goto l1; } file = firstIndexableField(objectPointer); - l1: /* end fileValueOf: */; +l1: /* end fileValueOf: */; if (!(failed())) { position = sqFileGetPosition(file); if (!(failed())) { @@ -1080,7 +1095,7 @@ primitiveFileOpen(void) if (!(isBytes(namePointer))) { return primitiveFail(); } - nameIndex = ((char *) (firstIndexableField(namePointer))); + nameIndex = firstIndexableField(namePointer); nameSize = byteSizeOf(namePointer); filePointer = fileOpenNamesizewritesecure(nameIndex, nameSize, writeFlag, 1); if (!(failed())) { @@ -1102,7 +1117,7 @@ primitiveFileOpenNew(void) if (!(isBytes(namePointer))) { return primitiveFail(); } - nameIndex = ((char *) (firstIndexableField(namePointer))); + nameIndex = firstIndexableField(namePointer); nameSize = byteSizeOf(namePointer); filePointer = fileOpenNewNamesizesecure(nameIndex, nameSize, 1); if (!(failed())) { @@ -1116,29 +1131,14 @@ EXPORT(sqInt) primitiveFileRead(void) { sqInt array; - sqInt array1; - sqInt array2; sqInt bytesRead; - sqInt bytesRead1; - sqInt bytesRead2; size_t count; - size_t count1; - size_t count2; size_t elementSize; - size_t elementSize1; - size_t elementSize2; SQFile *file; - SQFile *file1; - SQFile *file2; sqInt objectPointer; - sqInt objectPointer1; - sqInt objectPointer2; sqInt retryCount; size_t slotSize; - size_t slotSize1; size_t startIndex; - size_t startIndex1; - size_t startIndex2; void *vmHandle; @@ -1149,6 +1149,7 @@ primitiveFileRead(void) startIndex = positiveMachineIntegerValueOf(stackValue(1)); array = stackValue(2); objectPointer = stackValue(3); + /* begin fileValueOf: */ if (!((isBytes(objectPointer)) && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))) { @@ -1157,7 +1158,7 @@ primitiveFileRead(void) goto l1; } file = firstIndexableField(objectPointer); - l1: /* end fileValueOf: */; +l1: /* end fileValueOf: */; vmHandle = null; if ((failed()) || (!(isWordsOrBytes(array)))) { @@ -1170,7 +1171,7 @@ primitiveFileRead(void) primitiveFailFor(PrimErrBadIndex); goto l2; } - if (slotSize == 0) { + if (!slotSize) { methodReturnInteger(0); goto l2; } @@ -1179,85 +1180,89 @@ primitiveFileRead(void) vmHandle = disownVM(DisownVMForThreading); } bytesRead = sqFileReadIntoAt(file, count * elementSize, ((char *) (firstIndexableField(array))), (startIndex - 1) * elementSize); - if (!(vmHandle == null)) { + if (vmHandle) { ownVM(vmHandle); } if (!(failed())) { methodReturnInteger(bytesRead / elementSize); } - l2: /* end primitiveFileReadPinningAndDisowning */; +l2: /* end primitiveFileReadPinningAndDisowning */; # else // COGMTVM /* begin primitiveFileReadWithPinning */ - count1 = positiveMachineIntegerValueOf(stackValue(0)); - startIndex1 = positiveMachineIntegerValueOf(stackValue(1)); - array1 = stackValue(2); - objectPointer1 = stackValue(3); + count = positiveMachineIntegerValueOf(stackValue(0)); + startIndex = positiveMachineIntegerValueOf(stackValue(1)); + array = stackValue(2); + objectPointer = stackValue(3); + /* begin fileValueOf: */ - if (!((isBytes(objectPointer1)) - && ((byteSizeOf(objectPointer1)) == (sizeof(SQFile))))) { + if (!((isBytes(objectPointer)) + && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))) { primitiveFailFor(PrimErrBadArgument); - file1 = null; + file = null; goto l3; } - file1 = firstIndexableField(objectPointer1); - l3: /* end fileValueOf: */; + file = firstIndexableField(objectPointer); +l3: /* end fileValueOf: */; if ((failed()) - || (!(isWordsOrBytes(array1)))) { + || (!(isWordsOrBytes(array)))) { primitiveFailFor(PrimErrBadArgument); goto l4; } - slotSize1 = slotSizeOf(array1); - if (!((startIndex1 >= 1) - && (((startIndex1 + count1) - 1) <= slotSize1))) { + slotSize = slotSizeOf(array); + if (!((startIndex >= 1) + && (((startIndex + count) - 1) <= slotSize))) { primitiveFailFor(PrimErrBadIndex); goto l4; } - if (slotSize1 == 0) { + if (!slotSize) { methodReturnInteger(0); goto l4; } + /* Note: adjust startIndex for zero-origin byte indexing */ - elementSize1 = (byteSizeOf(array1)) / slotSize1; - bytesRead1 = sqFileReadIntoAt(file1, count1 * elementSize1, ((char *) (firstIndexableField(array1))), (startIndex1 - 1) * elementSize1); + elementSize = (byteSizeOf(array)) / slotSize; + bytesRead = sqFileReadIntoAt(file, count * elementSize, ((char *) (firstIndexableField(array))), (startIndex - 1) * elementSize); if (!(failed())) { - methodReturnInteger(bytesRead1 / elementSize1); + methodReturnInteger(bytesRead / elementSize); } - l4: /* end primitiveFileReadWithPinning */; +l4: /* end primitiveFileReadWithPinning */; # endif // COGMTVM # else // SPURVM /* begin primitiveFileReadWithoutPinning */ retryCount = 0; - count2 = positive32BitValueOf(stackValue(0)); - startIndex2 = positive32BitValueOf(stackValue(1)); - array2 = stackValue(2); - objectPointer2 = stackValue(3); + count = positive32BitValueOf(stackValue(0)); + startIndex = positive32BitValueOf(stackValue(1)); + array = stackValue(2); + objectPointer = stackValue(3); + /* begin fileValueOf: */ - if (!((isBytes(objectPointer2)) - && ((byteSizeOf(objectPointer2)) == (sizeof(SQFile))))) { + if (!((isBytes(objectPointer)) + && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))) { primitiveFailFor(PrimErrBadArgument); - file2 = null; + file = null; goto l5; } - file2 = firstIndexableField(objectPointer2); - l5: /* end fileValueOf: */; + file = firstIndexableField(objectPointer); +l5: /* end fileValueOf: */; if ((failed()) - || (!(isWordsOrBytes(array2)))) { + || (!(isWordsOrBytes(array)))) { primitiveFailFor(PrimErrBadArgument); goto l6; } - if (!((startIndex2 >= 1) - && (((startIndex2 + count2) - 1) <= (slotSizeOf(array2))))) { + if (!((startIndex >= 1) + && (((startIndex + count) - 1) <= (slotSizeOf(array))))) { primitiveFailFor(PrimErrBadIndex); goto l6; } + /* Note: adjust startIndex for zero-origin indexing */ - elementSize2 = bytesPerElement(array2); - bytesRead2 = sqFileReadIntoAt(file2, count2 * elementSize2, ((char *) (firstIndexableField(array2))), (startIndex2 - 1) * elementSize2); + elementSize = bytesPerElement(array); + bytesRead = sqFileReadIntoAt(file, count * elementSize, ((char *) (firstIndexableField(array))), (startIndex - 1) * elementSize); if (!(failed())) { - methodReturnInteger(bytesRead2 / elementSize2); + methodReturnInteger(bytesRead / elementSize); } - l6: /* end primitiveFileReadWithoutPinning */; +l6: /* end primitiveFileReadWithoutPinning */; # endif // SPURVM return 0; @@ -1281,13 +1286,14 @@ primitiveFileRename(void) && (isBytes(oldNamePointer)))) { return primitiveFail(); } - newNameIndex = ((char *) (firstIndexableField(newNamePointer))); + newNameIndex = firstIndexableField(newNamePointer); newNameSize = byteSizeOf(newNamePointer); - oldNameIndex = ((char *) (firstIndexableField(oldNamePointer))); + oldNameIndex = firstIndexableField(oldNamePointer); + /* If the security plugin can be loaded, use it to check for rename permission. If not, assume it's ok */ oldNameSize = byteSizeOf(oldNamePointer); - if (sCRFfn != 0) { + if (sCRFfn) { okToRename = ((sqInt (*)(char *, sqInt))sCRFfn)(oldNameIndex, oldNameSize); if (!okToRename) { return primitiveFail(); @@ -1313,6 +1319,7 @@ primitiveFileSetPosition(void) } newPosition = positive64BitValueOf(stackValue(0)); objectPointer = stackValue(1); + /* begin fileValueOf: */ if (!((isBytes(objectPointer)) && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))) { @@ -1321,7 +1328,7 @@ primitiveFileSetPosition(void) goto l1; } file = firstIndexableField(objectPointer); - l1: /* end fileValueOf: */; +l1: /* end fileValueOf: */; if (!(failed())) { sqFileSetPosition(file, newPosition); if (!(failed())) { @@ -1340,6 +1347,7 @@ primitiveFileSize(void) squeakFileOffsetType size; objectPointer = stackValue(0); + /* begin fileValueOf: */ if (!((isBytes(objectPointer)) && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))) { @@ -1348,7 +1356,7 @@ primitiveFileSize(void) goto l1; } file = firstIndexableField(objectPointer); - l1: /* end fileValueOf: */; +l1: /* end fileValueOf: */; if (!(failed())) { size = sqFileSize(file); } @@ -1374,7 +1382,7 @@ primitiveFileStdioHandles(void) sqInt result; sqInt validMask; - if (sHFAfn != 0) { + if (sHFAfn) { if (!( ((sqInt (*)(void))sHFAfn)())) { return primitiveFailFor(PrimErrUnsupported); } @@ -1384,14 +1392,14 @@ primitiveFileStdioHandles(void) return primitiveFailForOSError(validMask); } result = instantiateClassindexableSize(classArray(), 3); - if (result == null) { + if (!result) { return primitiveFailFor(PrimErrNoMemory); } pushRemappableOop(result); for (index = 0; index <= 2; index += 1) { - if ((validMask & (1U << index)) != 0) { + if (validMask & (1U << index)) { result = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); - if (result == null) { + if (!result) { popRemappableOop(); return primitiveFailFor(PrimErrNoMemory); } @@ -1419,6 +1427,7 @@ primitiveFileSync(void) sqInt objectPointer; objectPointer = stackValue(0); + /* begin fileValueOf: */ if (!((isBytes(objectPointer)) && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))) { @@ -1427,7 +1436,7 @@ primitiveFileSync(void) goto l1; } file = firstIndexableField(objectPointer); - l1: /* end fileValueOf: */; +l1: /* end fileValueOf: */; if (!(failed())) { sqFileSync(file); } @@ -1457,6 +1466,7 @@ primitiveFileTruncate(void) } truncatePosition = positive64BitValueOf(stackValue(0)); objectPointer = stackValue(1); + /* begin fileValueOf: */ if (!((isBytes(objectPointer)) && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))) { @@ -1465,7 +1475,7 @@ primitiveFileTruncate(void) goto l1; } file = firstIndexableField(objectPointer); - l1: /* end fileValueOf: */; +l1: /* end fileValueOf: */; if (!(failed())) { sqFileTruncate(file, truncatePosition); } @@ -1492,6 +1502,7 @@ primitiveFileWrite(void) startIndex = positiveMachineIntegerValueOf(stackValue(1)); array = stackValue(2); objectPointer = stackValue(3); + /* begin fileValueOf: */ if (!((isBytes(objectPointer)) && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))) { @@ -1500,7 +1511,7 @@ primitiveFileWrite(void) goto l1; } file = firstIndexableField(objectPointer); - l1: /* end fileValueOf: */; +l1: /* end fileValueOf: */; if ((failed()) || (!(isWordsOrBytes(array)))) { return primitiveFailFor(PrimErrBadArgument); @@ -1510,9 +1521,10 @@ primitiveFileWrite(void) && (((startIndex + count) - 1) <= slotSize))) { return primitiveFailFor(PrimErrBadIndex); } - if (slotSize == 0) { + if (!slotSize) { return methodReturnInteger(0); } + /* Note: adjust startIndex for zero-origin byte indexing */ elementSize = (byteSizeOf(array)) / slotSize; bytesWritten = sqFileWriteFromAt(file, count * elementSize, ((char *) (firstIndexableField(array))), (startIndex - 1) * elementSize); @@ -1531,7 +1543,7 @@ primitiveHasFileAccess(void) /* If the security plugin can be loaded, use it to check . If not, assume it's ok */ - if (sHFAfn != 0) { + if (sHFAfn) { hasAccess = ((sqInt (*)(void))sHFAfn)(); } else { @@ -1550,12 +1562,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -1653,8 +1664,8 @@ shutdownModule(void) return sqFileShutdown(); } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "FilePlugin"; diff --git a/src/plugins/FloatMathPlugin/FloatMathPlugin.c b/src/plugins/FloatMathPlugin/FloatMathPlugin.c index b23cd8fdaf..55f2756756 100644 --- a/src/plugins/FloatMathPlugin/FloatMathPlugin.c +++ b/src/plugins/FloatMathPlugin/FloatMathPlugin.c @@ -1,9 +1,9 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - FloatMathPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + FloatMathPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 */ -static char __buildInfo[] = "FloatMathPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f " __DATE__ ; +static char __buildInfo[] = "FloatMathPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 " __DATE__ ; #include "config.h" @@ -78,7 +78,7 @@ extern sqInt stackIntegerValue(sqInt offset); extern #endif struct VirtualMachine* interpreterProxy; -static const char *moduleName = "FloatMathPlugin VMMaker.oscog-eem.3455 " INT_EXT; +static const char *moduleName = "FloatMathPlugin VMMaker.oscog-eem.3456 " INT_EXT; /*** Methods ***/ @@ -571,6 +571,7 @@ primitiveTimesTwoPower(void) return null; } if (BytesPerOop > 4) { + /* clip arg to at most int range; ldexp's last arg is of type int */ twiceMaxExponent = 0x1000; if (arg < (-twiceMaxExponent)) { @@ -598,12 +599,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -617,8 +617,8 @@ setInterpreter(struct VirtualMachine *anInterpreter) return ok; } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "FloatMathPlugin"; diff --git a/src/plugins/IA32ABI/IA32ABI.c b/src/plugins/IA32ABI/IA32ABI.c index f963e82105..bca29aff4d 100644 --- a/src/plugins/IA32ABI/IA32ABI.c +++ b/src/plugins/IA32ABI/IA32ABI.c @@ -1,9 +1,9 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - IA32ABIPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + IA32ABIPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 */ -static char __buildInfo[] = "IA32ABIPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f " __DATE__ ; +static char __buildInfo[] = "IA32ABIPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 " __DATE__ ; #include "config.h" @@ -276,7 +276,7 @@ extern sqInt trueObject(void); extern #endif struct VirtualMachine* interpreterProxy; -static const char *moduleName = "IA32ABI VMMaker.oscog-eem.3455 " INT_EXT; +static const char *moduleName = "IA32ABI VMMaker.oscog-eem.3456 " INT_EXT; /*** Methods ***/ @@ -337,10 +337,10 @@ primAddressField(void) rcvr = stackValue(0); value = longAt((rcvr + BaseHeaderSize) + BytesPerOop); - return methodReturnValue( /* begin positiveMachineIntegerFor: */ + return methodReturnValue(/* positiveMachineIntegerFor: */ (BytesPerWord == 8 - ? positive64BitIntegerFor(value) - : positive32BitIntegerFor(value))); + ? positive64BitIntegerFor(value) + : positive32BitIntegerFor(value))); } @@ -399,7 +399,6 @@ primAlienCopyInto(void) sqInt stop; sqInt totalLength; - /* Unchecked! */ alien = stackValue(4); start = stackValue(3); @@ -416,22 +415,23 @@ primAlienCopyInto(void) stop = integerValueOf(stop); destStart = integerValueOf(destStart); myLength = longAt(alien + BaseHeaderSize); - src = ((/* begin startOfData:withSize: */ + src = ((/* startOfData:withSize: */ (myLength > 0 - ? (alien + BaseHeaderSize) + BytesPerOop - : longAt((alien + BaseHeaderSize) + BytesPerOop))) + start) - 1; + ? (alien + BaseHeaderSize) + BytesPerOop + : longAt((alien + BaseHeaderSize) + BytesPerOop))) + start) - 1; if (isKindOfClass(dest, classAlien())) { totalLength = longAt(dest + BaseHeaderSize); - destAddr = ((/* begin startOfData:withSize: */ + destAddr = ((/* startOfData:withSize: */ (totalLength > 0 - ? (dest + BaseHeaderSize) + BytesPerOop - : longAt((dest + BaseHeaderSize) + BytesPerOop))) + destStart) - 1; - if (totalLength == 0) { - /* no bounds checks for zero-sized (pointer) Aliens */ - totalLength = stop; + ? (dest + BaseHeaderSize) + BytesPerOop + : longAt((dest + BaseHeaderSize) + BytesPerOop))) + destStart) - 1; + if (totalLength) { + totalLength = SQABS(totalLength); } else { - totalLength = SQABS(totalLength); + + /* no bounds checks for zero-sized (pointer) Aliens */ + totalLength = stop; } } else { @@ -487,7 +487,6 @@ primAlienReplace(void) sqInt stop; sqInt totalLength; - /* Unchecked! */ array = stackValue(4); start = stackValue(3); @@ -505,16 +504,17 @@ primAlienReplace(void) replStart = integerValueOf(replStart); if (isKindOfClass(array, classAlien())) { totalLength = longAt(array + BaseHeaderSize); - dest = ((/* begin startOfData:withSize: */ + dest = ((/* startOfData:withSize: */ (totalLength > 0 - ? (array + BaseHeaderSize) + BytesPerOop - : longAt((array + BaseHeaderSize) + BytesPerOop))) + start) - 1; - if (totalLength == 0) { - /* no bounds checks for zero-sized (pointer) Aliens */ - totalLength = stop; + ? (array + BaseHeaderSize) + BytesPerOop + : longAt((array + BaseHeaderSize) + BytesPerOop))) + start) - 1; + if (totalLength) { + totalLength = SQABS(totalLength); } else { - totalLength = SQABS(totalLength); + + /* no bounds checks for zero-sized (pointer) Aliens */ + totalLength = stop; } } else { @@ -535,16 +535,17 @@ primAlienReplace(void) else { if (isKindOfClass(repl, classAlien())) { totalLength = longAt(repl + BaseHeaderSize); - src = ((/* begin startOfData:withSize: */ + src = ((/* startOfData:withSize: */ (totalLength > 0 - ? (repl + BaseHeaderSize) + BytesPerOop - : longAt((repl + BaseHeaderSize) + BytesPerOop))) + replStart) - 1; - if (totalLength == 0) { - /* no bounds checks for zero-sized (pointer) Aliens */ - totalLength = (stop - start) + replStart; + ? (repl + BaseHeaderSize) + BytesPerOop + : longAt((repl + BaseHeaderSize) + BytesPerOop))) + replStart) - 1; + if (totalLength) { + totalLength = SQABS(totalLength); } else { - totalLength = SQABS(totalLength); + + /* no bounds checks for zero-sized (pointer) Aliens */ + totalLength = (stop - start) + replStart; } } else { @@ -562,6 +563,7 @@ primAlienReplace(void) if (isOopImmutable(array)) { return primitiveFailFor(PrimErrNoModification); } + /* Use memmove to allow source and destination to overlap */ isOnExecutablePage = ifIsWithinExecutablePageMakePageWritable(((void *)dest)); memmove(((void *)dest), ((void *)src), (stop - start) + 1); @@ -597,10 +599,20 @@ primAllocateExecutablePage(void) theClassAlien = null; } mem = allocateExecutablePage((&byteSize)); - if (mem == 0) { + if (!mem) { return primitiveFailFor(PrimErrNoCMemory); } - if (theClassAlien == null) { + if (theClassAlien) { + result = instantiateClassindexableSize(theClassAlien, 2 * BytesPerWord); + if ((!result) + || (failed())) { + return primitiveFailFor(PrimErrNoMemory); + } + ptr = firstIndexableField(result); + ptr[0] = (0 - byteSize); + ptr[1] = (((sqIntptr_t) mem)); + } + else { result = instantiateClassindexableSize(classArray(), 2); if ((!result) || (failed())) { @@ -608,18 +620,16 @@ primAllocateExecutablePage(void) } #if SPURVM - memInteger = - /* begin positiveMachineIntegerFor: */ -(BytesPerWord == 8 - ? positive64BitIntegerFor(((usqInt)mem)) - : positive32BitIntegerFor(((usqInt)mem))); + memInteger = /* positiveMachineIntegerFor: */ + (BytesPerWord == 8 + ? positive64BitIntegerFor(((usqInt)mem)) + : positive32BitIntegerFor(((usqInt)mem))); #else /* SPURVM */ pushRemappableOop(result); - memInteger = - /* begin positiveMachineIntegerFor: */ -(BytesPerWord == 8 - ? positive64BitIntegerFor(((usqInt)mem)) - : positive32BitIntegerFor(((usqInt)mem))); + memInteger = /* positiveMachineIntegerFor: */ + (BytesPerWord == 8 + ? positive64BitIntegerFor(((usqInt)mem)) + : positive32BitIntegerFor(((usqInt)mem))); result = popRemappableOop(); #endif /* SPURVM */ if ((!memInteger) @@ -629,16 +639,6 @@ primAllocateExecutablePage(void) storePointerofObjectwithValue(0, result, memInteger); storePointerofObjectwithValue(1, result, integerObjectOf(byteSize)); } - else { - result = instantiateClassindexableSize(theClassAlien, 2 * BytesPerWord); - if ((!result) - || (failed())) { - return primitiveFailFor(PrimErrNoMemory); - } - ptr = ((sqIntptr_t *) (firstIndexableField(result))); - ptr[0] = (0 - byteSize); - ptr[1] = (((sqIntptr_t) mem)); - } methodReturnValue(result); return 0; } @@ -661,8 +661,9 @@ primBoxedFree(void) if (!((byteSizeOf(rcvr)) >= (2 * BytesPerOop))) { return primitiveFailFor(PrimErrBadReceiver); } - ptr = ((sqIntptr_t *) (firstIndexableField(rcvr))); + ptr = firstIndexableField(rcvr); sizeField = ptr[0]; + /* Don't you dare to free Squeak's memory! */ addr = ptr[1]; if ((sizeField >= 0) @@ -698,6 +699,7 @@ primCallOutDoubleReturn(void) mac = methodArgumentCount(); # if STACKVM + /* In the STACKVM stacks grow down */ /* ptr to 0th arg */ /* nargs negated to imply stack direction */ @@ -712,7 +714,7 @@ primCallOutDoubleReturn(void) errCode = callIA32DoubleReturn(((getStackPointer()) - mac) + 2, mac - 1, mac, mac - 1); # endif // STACKVM - if (errCode != 0) { + if (errCode) { return primitiveFailFor(errCode); } result = stackValue(mac - 1); @@ -742,6 +744,7 @@ primCallOutFloatReturn(void) mac = methodArgumentCount(); # if STACKVM + /* In the STACKVM stacks grow down */ /* ptr to 0th arg */ /* nargs negated to imply stack direction */ @@ -756,7 +759,7 @@ primCallOutFloatReturn(void) errCode = callIA32FloatReturn(((getStackPointer()) - mac) + 2, mac - 1, mac, mac - 1); # endif // STACKVM - if (errCode != 0) { + if (errCode) { return primitiveFailFor(errCode); } result = stackValue(mac - 1); @@ -786,6 +789,7 @@ primCallOutIntegralReturn(void) mac = methodArgumentCount(); # if STACKVM + /* In the STACKVM stacks grow down */ /* ptr to 0th arg */ /* nargs negated to imply stack direction */ @@ -800,7 +804,7 @@ primCallOutIntegralReturn(void) errCode = callIA32IntegralReturn(((getStackPointer()) - mac) + 2, mac - 1, mac, mac - 1); # endif // STACKVM - if (errCode != 0) { + if (errCode) { return primitiveFailFor(errCode); } result = stackValue(mac - 1); @@ -826,13 +830,13 @@ primCalloc(void) return primitiveFailFor(PrimErrBadArgument); } addr = ((usqInt)(calloc(1, byteSize))); - if (addr == 0) { + if (!addr) { return primitiveFailFor(PrimErrNoCMemory); } - methodReturnValue( /* begin positiveMachineIntegerFor: */ + methodReturnValue(/* positiveMachineIntegerFor: */ (BytesPerWord == 8 - ? positive64BitIntegerFor(addr) - : positive32BitIntegerFor(addr))); + ? positive64BitIntegerFor(addr) + : positive32BitIntegerFor(addr))); return 0; } @@ -847,13 +851,11 @@ primCalloc(void) EXPORT(sqInt) primDoubleAt(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; double floatValue; sqInt rcvr; sqInt startAddr; - sqInt v; - v = 0; byteOffset = (stackPositiveMachineIntegerValue(0)) - 1; rcvr = stackObjectValue(1); if (failed()) { @@ -862,11 +864,10 @@ primDoubleAt(void) if (!(indexlengthinRange(byteOffset, 8, rcvr))) { return primitiveFailFor(PrimErrBadIndex); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } memcpy((&floatValue), ((void *)(startAddr + byteOffset)), sizeof(floatValue)); @@ -885,7 +886,7 @@ primDoubleAt(void) EXPORT(sqInt) primDoubleAtPut(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; double floatValue; sqInt rcvr; sqInt startAddr; @@ -909,11 +910,10 @@ primDoubleAtPut(void) if (isOopImmutable(rcvr)) { return primitiveFailFor(PrimErrNoModification); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } memcpy(((void *)(startAddr + byteOffset)), (&floatValue), sizeof(floatValue)); @@ -942,13 +942,11 @@ primDrainOSEventQueue(void) EXPORT(sqInt) primFloatAt(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; float floatValue; sqInt rcvr; sqInt startAddr; - sqInt v; - v = 0; byteOffset = (stackPositiveMachineIntegerValue(0)) - 1; rcvr = stackObjectValue(1); if (failed()) { @@ -957,11 +955,10 @@ primFloatAt(void) if (!(indexlengthinRange(byteOffset, 4, rcvr))) { return primitiveFailFor(PrimErrBadIndex); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } memcpy((&floatValue), ((void *)(startAddr + byteOffset)), sizeof(floatValue)); @@ -980,7 +977,7 @@ primFloatAt(void) EXPORT(sqInt) primFloatAtPut(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; float floatValue; sqInt rcvr; sqInt startAddr; @@ -1004,11 +1001,10 @@ primFloatAtPut(void) if (isOopImmutable(rcvr)) { return primitiveFailFor(PrimErrNoModification); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } memcpy(((void *)(startAddr + byteOffset)), (&floatValue), sizeof(floatValue)); @@ -1051,10 +1047,10 @@ primInIOProcessEventsFlagAddress(void) { extern int inIOProcessEvents; - methodReturnValue( /* begin positiveMachineIntegerFor: */ + methodReturnValue(/* positiveMachineIntegerFor: */ (BytesPerWord == 8 - ? positive64BitIntegerFor(((usqInt)((&inIOProcessEvents)))) - : positive32BitIntegerFor(((usqInt)((&inIOProcessEvents)))))); + ? positive64BitIntegerFor(((usqInt)((&inIOProcessEvents)))) + : positive32BitIntegerFor(((usqInt)((&inIOProcessEvents)))))); return 0; } @@ -1088,10 +1084,10 @@ primInLibraryFindSymbol(void) || (address == 0)) { return primitiveFailFor(PrimErrNotFound); } - methodReturnValue( /* begin positiveMachineIntegerFor: */ + methodReturnValue(/* positiveMachineIntegerFor: */ (BytesPerWord == 8 - ? positive64BitIntegerFor(((usqInt)address)) - : positive32BitIntegerFor(((usqInt)address)))); + ? positive64BitIntegerFor(((usqInt)address)) + : positive32BitIntegerFor(((usqInt)address)))); return 0; } @@ -1113,13 +1109,13 @@ primLoadLibrary(void) return primitiveFailFor(PrimErrBadArgument); } libraryHandle = ioLoadModuleOfLength(((sqInt) (firstIndexableField(libraryName))), byteSizeOf(libraryName)); - if (libraryHandle == 0) { + if (!libraryHandle) { return primitiveFailFor(PrimErrNotFound); } - methodReturnValue( /* begin positiveMachineIntegerFor: */ + methodReturnValue(/* positiveMachineIntegerFor: */ (BytesPerWord == 8 - ? positive64BitIntegerFor(((usqInt)libraryHandle)) - : positive32BitIntegerFor(((usqInt)libraryHandle)))); + ? positive64BitIntegerFor(((usqInt)libraryHandle)) + : positive32BitIntegerFor(((usqInt)libraryHandle)))); return 0; } @@ -1141,13 +1137,13 @@ primMalloc(void) return primitiveFailFor(PrimErrBadArgument); } addr = ((usqInt)(malloc(byteSize))); - if (addr == 0) { + if (!addr) { return primitiveFailFor(PrimErrNoCMemory); } - methodReturnValue( /* begin positiveMachineIntegerFor: */ + methodReturnValue(/* positiveMachineIntegerFor: */ (BytesPerWord == 8 - ? positive64BitIntegerFor(addr) - : positive32BitIntegerFor(addr))); + ? positive64BitIntegerFor(addr) + : positive32BitIntegerFor(addr))); return 0; } @@ -1160,10 +1156,10 @@ primMalloc(void) EXPORT(sqInt) primMostRecentCallbackContext(void) { - methodReturnValue( /* begin positiveMachineIntegerFor: */ + methodReturnValue(/* positiveMachineIntegerFor: */ (BytesPerWord == 8 - ? positive64BitIntegerFor(((usqInt)(getMostRecentCallbackContext()))) - : positive32BitIntegerFor(((usqInt)(getMostRecentCallbackContext()))))); + ? positive64BitIntegerFor(((usqInt)(getMostRecentCallbackContext()))) + : positive32BitIntegerFor(((usqInt)(getMostRecentCallbackContext()))))); return 0; } @@ -1180,7 +1176,7 @@ EXPORT(sqInt) primOopAt(void) { sqInt *addr; - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; @@ -1195,13 +1191,13 @@ primOopAt(void) if (isOopImmutable(rcvr)) { return primitiveFailFor(PrimErrNoModification); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } + /* WE SHOULD DO VALIDATION HERE! FOR NOW WE PUNT, BUT THIS REALLY DOES REQUIRE A GOOD ANSWER!! */ addr = ((sqInt *) (startAddr + byteOffset)); return methodReturnValue(addr[0]); @@ -1220,7 +1216,7 @@ EXPORT(sqInt) primOopAtPut(void) { sqInt *addr; - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt oop; sqInt rcvr; sqInt startAddr; @@ -1237,11 +1233,10 @@ primOopAtPut(void) if (isOopImmutable(rcvr)) { return primitiveFailFor(PrimErrNoModification); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } addr = ((sqInt *) (startAddr + byteOffset)); @@ -1280,6 +1275,7 @@ primReturnAsFromContextThrough(void) vmCallbackContext = ((VMCallbackContext *) (startOfData(stackValue(argCount)))); isMostRecentCallback = vmCallbackContext == (getMostRecentCallbackContext()); if (argCount == 3) { + /* More error checking is done in StackInterpreter>>#returnAs:ThroughCallback:Context: below... */ lifoCallbackSemaphore = stackValue(2); if (!((fetchClassOf(lifoCallbackSemaphore)) == (classSemaphore()))) { @@ -1362,7 +1358,7 @@ primReturnFromContextThrough(void) EXPORT(sqInt) primSignedByteAt(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; signed char value; @@ -1375,11 +1371,10 @@ primSignedByteAt(void) if (!(indexlengthinRange(byteOffset, 1, rcvr))) { return primitiveFailFor(PrimErrBadIndex); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } value = byteAt(startAddr + byteOffset); @@ -1397,7 +1392,7 @@ primSignedByteAt(void) EXPORT(sqInt) primSignedByteAtPut(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; int value; @@ -1418,11 +1413,10 @@ primSignedByteAtPut(void) if (isOopImmutable(rcvr)) { return primitiveFailFor(PrimErrNoModification); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } byteAtput(startAddr + byteOffset, value); @@ -1440,7 +1434,7 @@ primSignedByteAtPut(void) EXPORT(sqInt) primSignedLongAt(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; int value; @@ -1453,11 +1447,10 @@ primSignedLongAt(void) if (!(indexlengthinRange(byteOffset, 4, rcvr))) { return primitiveFailFor(PrimErrBadIndex); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } value = long32At(startAddr + byteOffset); @@ -1475,7 +1468,7 @@ primSignedLongAt(void) EXPORT(sqInt) primSignedLongAtPut(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; int value; @@ -1494,11 +1487,10 @@ primSignedLongAtPut(void) if (isOopImmutable(rcvr)) { return primitiveFailFor(PrimErrNoModification); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } long32Atput(startAddr + byteOffset, value); @@ -1516,7 +1508,7 @@ primSignedLongAtPut(void) EXPORT(sqInt) primSignedLongLongAt(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; long long value; @@ -1529,11 +1521,10 @@ primSignedLongLongAt(void) if (!(indexlengthinRange(byteOffset, 8, rcvr))) { return primitiveFailFor(PrimErrBadIndex); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } value = (*((long long *) (startAddr + byteOffset))); @@ -1551,7 +1542,7 @@ primSignedLongLongAt(void) EXPORT(sqInt) primSignedLongLongAtPut(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; sqLong value; @@ -1570,11 +1561,10 @@ primSignedLongLongAtPut(void) if (isOopImmutable(rcvr)) { return primitiveFailFor(PrimErrNoModification); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } (*((long long *) (startAddr + byteOffset)) = value); @@ -1592,7 +1582,7 @@ primSignedLongLongAtPut(void) EXPORT(sqInt) primSignedShortAt(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; short value; @@ -1605,11 +1595,10 @@ primSignedShortAt(void) if (!(indexlengthinRange(byteOffset, 2, rcvr))) { return primitiveFailFor(PrimErrBadIndex); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } value = shortAt(startAddr + byteOffset); @@ -1627,7 +1616,7 @@ primSignedShortAt(void) EXPORT(sqInt) primSignedShortAtPut(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; int value; @@ -1648,11 +1637,10 @@ primSignedShortAtPut(void) if (isOopImmutable(rcvr)) { return primitiveFailFor(PrimErrNoModification); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } shortAtput(startAddr + byteOffset, value); @@ -1668,8 +1656,8 @@ primSignedShortAtPut(void) EXPORT(sqInt) primSignedWordAt(void) { - usqIntptr_t addr; - usqIntptr_t byteOffset; + sqInt addr; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; sqInt value; @@ -1683,11 +1671,10 @@ primSignedWordAt(void) if (!(indexlengthinRange(byteOffset, BytesPerOop, rcvr))) { return primitiveFailFor(PrimErrBadIndex); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } addr = startAddr + byteOffset; @@ -1707,8 +1694,8 @@ primSignedWordAt(void) EXPORT(sqInt) primSignedWordAtPut(void) { - usqIntptr_t addr; - usqIntptr_t byteOffset; + sqInt addr; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; sqIntptr_t value; @@ -1727,11 +1714,10 @@ primSignedWordAtPut(void) if (isOopImmutable(rcvr)) { return primitiveFailFor(PrimErrNoModification); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } addr = startAddr + byteOffset; @@ -1755,8 +1741,8 @@ primSizeField(void) rcvr = stackValue(0); valueOop = (BytesPerWord == 8 - ? signed64BitIntegerFor(((sqLong) (longAt(rcvr + BaseHeaderSize)))) - : signed32BitIntegerFor(((int) (longAt(rcvr + BaseHeaderSize))))); + ? signed64BitIntegerFor(((sqLong) (longAt(rcvr + BaseHeaderSize)))) + : signed32BitIntegerFor(((int) (longAt(rcvr + BaseHeaderSize))))); return methodReturnValue(valueOop); } @@ -1802,7 +1788,7 @@ primSizeFieldPut(void) EXPORT(sqInt) primStrlenFromStartIndex(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt index; sqInt limit; char *ptr; @@ -1817,14 +1803,11 @@ primStrlenFromStartIndex(void) return primitiveFailFor(PrimErrBadIndex); } limit = longAt(rcvr + BaseHeaderSize); - ptr = ((char *) ((/* begin startOfData:withSize: */ + ptr = ((char *) ((/* startOfData:withSize: */ (limit > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop))) + byteOffset)); - if (limit == 0) { - index = strlen(ptr); - } - else { + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))) + byteOffset)); + if (limit) { limit = SQABS(limit); index = 0; while ((index < limit) @@ -1832,6 +1815,9 @@ primStrlenFromStartIndex(void) index += 1; } } + else { + index = strlen(ptr); + } methodReturnInteger(index); return 0; } @@ -1848,8 +1834,8 @@ primStrlenFromStartIndex(void) EXPORT(sqInt) primStrlenThroughPointerAtIndex(void) { - usqIntptr_t addr; - usqIntptr_t byteOffset; + sqInt addr; + sqIntptr_t byteOffset; sqInt rcvr; byteOffset = (stackPositiveMachineIntegerValue(0)) - 1; @@ -1860,10 +1846,10 @@ primStrlenThroughPointerAtIndex(void) if (!(indexlengthinRange(byteOffset, BytesPerOop, rcvr))) { return primitiveFailFor(PrimErrBadIndex); } - addr = (/* begin startOfData: */ + addr = (/* startOfData: */ ((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop))) + byteOffset; + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))) + byteOffset; return methodReturnInteger(strlen(((char *) (longAt(addr))))); } @@ -1880,10 +1866,10 @@ primThunkEntryAddress(void) sqIntptr_t address; address = ((sqIntptr_t)thunkEntry); - methodReturnValue( /* begin positiveMachineIntegerFor: */ + methodReturnValue(/* positiveMachineIntegerFor: */ (BytesPerWord == 8 - ? positive64BitIntegerFor(address) - : positive32BitIntegerFor(address))); + ? positive64BitIntegerFor(address) + : positive32BitIntegerFor(address))); return 0; } @@ -1898,7 +1884,7 @@ primThunkEntryAddress(void) EXPORT(sqInt) primUnsignedByteAt(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; unsigned char value; @@ -1911,11 +1897,10 @@ primUnsignedByteAt(void) if (!(indexlengthinRange(byteOffset, 1, rcvr))) { return primitiveFailFor(PrimErrBadIndex); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } value = byteAt(startAddr + byteOffset); @@ -1933,7 +1918,7 @@ primUnsignedByteAt(void) EXPORT(sqInt) primUnsignedByteAtPut(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; usqInt value; @@ -1953,11 +1938,10 @@ primUnsignedByteAtPut(void) if (isOopImmutable(rcvr)) { return primitiveFailFor(PrimErrNoModification); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } byteAtput(startAddr + byteOffset, value); @@ -1975,7 +1959,7 @@ primUnsignedByteAtPut(void) EXPORT(sqInt) primUnsignedLongAt(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; int value; @@ -1988,11 +1972,10 @@ primUnsignedLongAt(void) if (!(indexlengthinRange(byteOffset, 4, rcvr))) { return primitiveFailFor(PrimErrBadIndex); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } value = long32At(startAddr + byteOffset); @@ -2010,7 +1993,7 @@ primUnsignedLongAt(void) EXPORT(sqInt) primUnsignedLongAtPut(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; usqInt value; @@ -2029,11 +2012,10 @@ primUnsignedLongAtPut(void) if (isOopImmutable(rcvr)) { return primitiveFailFor(PrimErrNoModification); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } long32Atput(startAddr + byteOffset, value); @@ -2051,7 +2033,7 @@ primUnsignedLongAtPut(void) EXPORT(sqInt) primUnsignedLongLongAt(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; unsigned long long value; @@ -2064,11 +2046,10 @@ primUnsignedLongLongAt(void) if (!(indexlengthinRange(byteOffset, 8, rcvr))) { return primitiveFailFor(PrimErrBadIndex); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } value = (*((unsigned long long *) (startAddr + byteOffset))); @@ -2087,7 +2068,7 @@ primUnsignedLongLongAt(void) EXPORT(sqInt) primUnsignedLongLongAtPut(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; usqLong value; @@ -2106,11 +2087,10 @@ primUnsignedLongLongAtPut(void) if (isOopImmutable(rcvr)) { return primitiveFailFor(PrimErrNoModification); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } (*((unsigned long long *) (startAddr + byteOffset)) = value); @@ -2128,7 +2108,7 @@ primUnsignedLongLongAtPut(void) EXPORT(sqInt) primUnsignedShortAt(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; unsigned short value; @@ -2141,11 +2121,10 @@ primUnsignedShortAt(void) if (!(indexlengthinRange(byteOffset, 2, rcvr))) { return primitiveFailFor(PrimErrBadIndex); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } value = shortAt(startAddr + byteOffset); @@ -2163,7 +2142,7 @@ primUnsignedShortAt(void) EXPORT(sqInt) primUnsignedShortAtPut(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; usqInt value; @@ -2183,11 +2162,10 @@ primUnsignedShortAtPut(void) if (isOopImmutable(rcvr)) { return primitiveFailFor(PrimErrNoModification); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } shortAtput(startAddr + byteOffset, value); @@ -2205,7 +2183,7 @@ primUnsignedShortAtPut(void) EXPORT(sqInt) primUnsignedWordAt(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; sqInt value; @@ -2218,18 +2196,17 @@ primUnsignedWordAt(void) if (!(indexlengthinRange(byteOffset, BytesPerOop, rcvr))) { return primitiveFailFor(PrimErrBadIndex); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } value = longAt(startAddr + byteOffset); - return methodReturnValue( /* begin positiveMachineIntegerFor: */ + return methodReturnValue(/* positiveMachineIntegerFor: */ (BytesPerWord == 8 - ? positive64BitIntegerFor(value) - : positive32BitIntegerFor(value))); + ? positive64BitIntegerFor(value) + : positive32BitIntegerFor(value))); } @@ -2243,7 +2220,7 @@ primUnsignedWordAt(void) EXPORT(sqInt) primUnsignedWordAtPut(void) { - usqIntptr_t byteOffset; + sqIntptr_t byteOffset; sqInt rcvr; sqInt startAddr; usqIntptr_t value; @@ -2262,11 +2239,10 @@ primUnsignedWordAtPut(void) if (isOopImmutable(rcvr)) { return primitiveFailFor(PrimErrNoModification); } - if (((startAddr = - /* begin startOfData: */ -((longAt(rcvr + BaseHeaderSize)) > 0 - ? (rcvr + BaseHeaderSize) + BytesPerOop - : longAt((rcvr + BaseHeaderSize) + BytesPerOop)))) == 0) { + if (!((startAddr = /* startOfData: */ + ((longAt(rcvr + BaseHeaderSize)) > 0 + ? (rcvr + BaseHeaderSize) + BytesPerOop + : longAt((rcvr + BaseHeaderSize) + BytesPerOop))))) { return primitiveFailFor(PrimErrBadReceiver); } longAtput(startAddr + byteOffset, value); @@ -2299,12 +2275,13 @@ primVarArgsCallOutDoubleReturn(void) return primitiveFailFor(PrimErrBadArgument); } mac = methodArgumentCount(); + /* ptr to 0th arg */ /* nargs */ /* func stackValue */ /* result stackValue */ errCode = callIA32DoubleReturn(firstIndexableField(array), stSizeOf(array), 2, 1); - if (errCode != 0) { + if (errCode) { return primitiveFailFor(errCode); } result = stackValue(1); @@ -2338,12 +2315,13 @@ primVarArgsCallOutFloatReturn(void) return primitiveFailFor(PrimErrBadArgument); } mac = methodArgumentCount(); + /* ptr to 0th arg */ /* nargs */ /* func stackValue */ /* result stackValue */ errCode = callIA32FloatReturn(firstIndexableField(array), stSizeOf(array), 2, 1); - if (errCode != 0) { + if (errCode) { return primitiveFailFor(errCode); } result = stackValue(1); @@ -2377,12 +2355,13 @@ primVarArgsCallOutIntegralReturn(void) return primitiveFailFor(PrimErrBadArgument); } mac = methodArgumentCount(); + /* ptr to 0th arg */ /* nargs */ /* func stackValue */ /* result stackValue */ errCode = callIA32IntegralReturn(firstIndexableField(array), stSizeOf(array), 2, 1); - if (errCode != 0) { + if (errCode) { return primitiveFailFor(errCode); } result = stackValue(1); @@ -2400,9 +2379,10 @@ setInterpreter(struct VirtualMachine *anInterpreter) sqInt ok; interpreterProxy = anInterpreter; + /* There was no version 0 */ ok = ((interpreterProxy->majorVersion()) > 1) - || ((interpreterProxy->minorVersion()) >= 12); + || ((interpreterProxy->minorVersion()) >= 12); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -2487,12 +2467,12 @@ static sqInt startOfData(sqInt alienOop) { return ((longAt(alienOop + BaseHeaderSize)) > 0 - ? (alienOop + BaseHeaderSize) + BytesPerOop - : longAt((alienOop + BaseHeaderSize) + BytesPerOop)); + ? (alienOop + BaseHeaderSize) + BytesPerOop + : longAt((alienOop + BaseHeaderSize) + BytesPerOop)); } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "IA32ABI"; diff --git a/src/plugins/JPEGReaderPlugin/JPEGReaderPlugin.c b/src/plugins/JPEGReaderPlugin/JPEGReaderPlugin.c index 868e96f035..c476ce6d73 100644 --- a/src/plugins/JPEGReaderPlugin/JPEGReaderPlugin.c +++ b/src/plugins/JPEGReaderPlugin/JPEGReaderPlugin.c @@ -1,9 +1,9 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - JPEGReaderPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + JPEGReaderPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 */ -static char __buildInfo[] = "JPEGReaderPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f " __DATE__ ; +static char __buildInfo[] = "JPEGReaderPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 " __DATE__ ; #include "config.h" @@ -81,7 +81,6 @@ static sqInt colorComponentfrom(int *aColorComponent, sqInt oop); static sqInt crColorComponentFrom(sqInt oop); EXPORT(const char*) getModuleName(void); static int jpegDecodeValueFromsize(int *table, sqInt tableSize); -static sqInt loadJPEGStreamFrom(sqInt streamOop); EXPORT(sqInt) primitiveColorConvertGrayscaleMCU(void); EXPORT(sqInt) primitiveColorConvertMCU(void); EXPORT(sqInt) primitiveDecodeMCU(void); @@ -155,7 +154,7 @@ static sqInt jsBitCount; static unsigned char *jsCollection; static sqInt jsPosition; static sqInt jsReadLimit; -static const char *moduleName = "JPEGReaderPlugin VMMaker.oscog-eem.3455 " INT_EXT; +static const char *moduleName = "JPEGReaderPlugin VMMaker.oscog-eem.3456 " INT_EXT; static int *residuals; static int *yBlocks[128]; static int yComponent[11]; @@ -257,19 +256,19 @@ static int jpegDecodeValueFromsize(int *table, sqInt tableSize) { sqInt bits; - sqInt bitsNeeded; + unsigned int bitsNeeded; unsigned char byte; sqInt index; - int tableIndex; + unsigned int tableIndex; int value; - sqInt value1; - + sqInt valueSqInt; /* Initial bits needed */ bitsNeeded = ((usqInt)((table[0]))) >> 24; if (bitsNeeded > MaxBits) { return -1; } + /* First real table */ tableIndex = 2; while (1) { @@ -283,6 +282,7 @@ jpegDecodeValueFromsize(int *table, sqInt tableSize) byte = jsCollection[jsPosition]; jsPosition += 1; if (byte == 0xFF) { + /* peek for 00 */ if (!((jsPosition < jsReadLimit) && ((jsCollection[jsPosition]) == 0))) { @@ -291,20 +291,20 @@ jpegDecodeValueFromsize(int *table, sqInt tableSize) } jsPosition += 1; } - jsBitBuffer = ((((sqInt)((usqInt)(jsBitBuffer) << 8)))) | byte; + jsBitBuffer = (((((usqInt)(jsBitBuffer) << 8)))) | byte; jsBitCount += 8; } - l1: /* end fillBuffer */; +l1: /* end fillBuffer */; if (bitsNeeded > jsBitCount) { bits = -1; goto l2; } } jsBitCount -= bitsNeeded; - value1 = ((usqInt)(jsBitBuffer)) >> jsBitCount; + valueSqInt = ((usqInt)(jsBitBuffer)) >> jsBitCount; jsBitBuffer = jsBitBuffer & ((1U << jsBitCount) - 1); - bits = value1; - l2: /* end getBits: */; + bits = valueSqInt; +l2: /* end getBits: */; if (bits < 0) { return -1; } @@ -312,13 +312,16 @@ jpegDecodeValueFromsize(int *table, sqInt tableSize) if (index >= tableSize) { return -1; } + /* Lookup entry in table */ value = table[index]; - if ((value & 0x3F000000) == 0) { + if (!(value & 0x3F000000)) { return value; } + /* Table offset in low 16 bit */ tableIndex = value & 0xFFFF; + /* Additional bits in high 8 bit */ bitsNeeded = (((usqInt)(value)) >> 24) & 0xFF; if (bitsNeeded > MaxBits) { @@ -328,42 +331,6 @@ jpegDecodeValueFromsize(int *table, sqInt tableSize) return -1; } - /* JPEGReaderPlugin>>#loadJPEGStreamFrom: */ -static sqInt -loadJPEGStreamFrom(sqInt streamOop) -{ - sqInt oop; - sqInt sz; - - if (!(isPointers(streamOop))) { - return 0; - } - if ((slotSizeOf(streamOop)) < 5) { - return 0; - } - oop = fetchPointerofObject(0, streamOop); - if (!(isBytes(oop))) { - return 0; - } - jsCollection = firstIndexableField(oop); - sz = byteSizeOf(oop); - jsPosition = fetchIntegerofObject(1, streamOop); - jsReadLimit = fetchIntegerofObject(2, streamOop); - jsBitBuffer = fetchIntegerofObject(3, streamOop); - jsBitCount = fetchIntegerofObject(4, streamOop); - if (failed()) { - return 0; - } - if (sz < jsReadLimit) { - return 0; - } - if ((jsPosition < 0) - || (jsPosition >= jsReadLimit)) { - return 0; - } - return 1; -} - /* Requires: JPEGColorComponent @@ -382,7 +349,6 @@ primitiveColorConvertGrayscaleMCU(void) int dx; int dy; sqInt i; - int sample; sqInt sampleIndex; int sx; int sy; @@ -408,11 +374,12 @@ primitiveColorConvertGrayscaleMCU(void) jpegBitsSize = slotSizeOf(arrayOop); jpegBits = firstIndexableField(arrayOop); arrayOop = stackValue(3); - if (!( /* begin yColorComponentFrom: */ + if (!(/* yColorComponentFrom: */ (colorComponentfrom(yComponent, arrayOop)) && (colorComponentBlocksfrom(yBlocks, arrayOop)))) { return primitiveFail(); } + /* begin colorConvertGrayscaleMCU */ yComponent[CurrentXIndex] = 0; yComponent[CurrentYIndex] = 0; @@ -428,8 +395,8 @@ primitiveColorConvertGrayscaleMCU(void) dy = dy / sy; } blockIndex = (((((usqInt)(dy)) >> 3)) * (yComponent[BlockWidthIndex])) + ((((usqInt)(dx)) >> 3)); - sampleIndex = ((((sqInt)((usqInt)((dy & 7)) << 3)))) + (dx & 7); - sample = (yBlocks[blockIndex])[sampleIndex]; + sampleIndex = (((((usqInt)((dy & 7)) << 3)))) + (dx & 7); + y = (yBlocks[blockIndex])[sampleIndex]; curX += 1; if (curX < ((yComponent[MCUWidthIndex]) * 8)) { yComponent[CurrentXIndex] = curX; @@ -438,13 +405,12 @@ primitiveColorConvertGrayscaleMCU(void) yComponent[CurrentXIndex] = 0; yComponent[CurrentYIndex] = ((yComponent[CurrentYIndex]) + 1); } - y = sample; y += residuals[GreenIndex]; y = ((y < MaxSample) ? y : MaxSample); residuals[GreenIndex] = (y & ditherMask); y = y & (MaxSample - ditherMask); y = ((y < 1) ? 1 : y); - jpegBits[i] = (((0xFF000000U + (((sqInt)((usqInt)(y) << 16)))) + (((sqInt)((usqInt)(y) << 8)))) + y); + jpegBits[i] = (((0xFF000000U + ((((usqInt)(y) << 16)))) + ((((usqInt)(y) << 8)))) + y); } pop(4); return 0; @@ -465,34 +431,26 @@ primitiveColorConvertMCU(void) sqInt arrayOop; sqInt blockIndex; sqInt blockIndex1; - sqInt blockIndex2; + sqInt blockIndexSqInt; int blue; int cb; int cr; int curX; - int curX1; - int curX2; + int curXInt; int dx; - int dx1; - int dx2; + int dxInt; int dy; - int dy1; - int dy2; + int dyInt; int green; sqInt i; int red; - int sample; - int sample1; - int sample2; sqInt sampleIndex; sqInt sampleIndex1; - sqInt sampleIndex2; + sqInt sampleIndexSqInt; int sx; - int sx1; - int sx2; + int sxInt; int sy; - int sy1; - int sy2; + int syInt; int y; if (!((methodArgumentCount()) == 4)) { @@ -528,6 +486,7 @@ primitiveColorConvertMCU(void) if (!(crColorComponentFrom(fetchPointerofObject(2, arrayOop)))) { return primitiveFail(); } + /* begin colorConvertMCU */ yComponent[CurrentXIndex] = 0; yComponent[CurrentYIndex] = 0; @@ -547,8 +506,8 @@ primitiveColorConvertMCU(void) dy = dy / sy; } blockIndex = (((((usqInt)(dy)) >> 3)) * (yComponent[BlockWidthIndex])) + ((((usqInt)(dx)) >> 3)); - sampleIndex = ((((sqInt)((usqInt)((dy & 7)) << 3)))) + (dx & 7); - sample = (yBlocks[blockIndex])[sampleIndex]; + sampleIndex = (((((usqInt)((dy & 7)) << 3)))) + (dx & 7); + y = (yBlocks[blockIndex])[sampleIndex]; curX += 1; if (curX < ((yComponent[MCUWidthIndex]) * 8)) { yComponent[CurrentXIndex] = curX; @@ -557,52 +516,51 @@ primitiveColorConvertMCU(void) yComponent[CurrentXIndex] = 0; yComponent[CurrentYIndex] = ((yComponent[CurrentYIndex]) + 1); } - y = sample; + /* begin nextSampleCb */ - dx1 = (curX1 = cbComponent[CurrentXIndex]); - dy1 = cbComponent[CurrentYIndex]; - sx1 = cbComponent[HScaleIndex]; - sy1 = cbComponent[VScaleIndex]; - if (!((sx1 == 0) - && (sy1 == 0))) { - dx1 = dx1 / sx1; - dy1 = dy1 / sy1; + dxInt = (curXInt = cbComponent[CurrentXIndex]); + dyInt = cbComponent[CurrentYIndex]; + sxInt = cbComponent[HScaleIndex]; + syInt = cbComponent[VScaleIndex]; + if (!((sxInt == 0) + && (syInt == 0))) { + dxInt = dxInt / sxInt; + dyInt = dyInt / syInt; } - blockIndex1 = (((((usqInt)(dy1)) >> 3)) * (cbComponent[BlockWidthIndex])) + ((((usqInt)(dx1)) >> 3)); - sampleIndex1 = ((((sqInt)((usqInt)((dy1 & 7)) << 3)))) + (dx1 & 7); - sample1 = (cbBlocks[blockIndex1])[sampleIndex1]; - curX1 += 1; - if (curX1 < ((cbComponent[MCUWidthIndex]) * 8)) { - cbComponent[CurrentXIndex] = curX1; + blockIndexSqInt = (((((usqInt)(dyInt)) >> 3)) * (cbComponent[BlockWidthIndex])) + ((((usqInt)(dxInt)) >> 3)); + sampleIndexSqInt = (((((usqInt)((dyInt & 7)) << 3)))) + (dxInt & 7); + cb = (cbBlocks[blockIndexSqInt])[sampleIndexSqInt]; + curXInt += 1; + if (curXInt < ((cbComponent[MCUWidthIndex]) * 8)) { + cbComponent[CurrentXIndex] = curXInt; } else { cbComponent[CurrentXIndex] = 0; cbComponent[CurrentYIndex] = ((cbComponent[CurrentYIndex]) + 1); } - cb = sample1; cb -= SampleOffset; + /* begin nextSampleCr */ - dx2 = (curX2 = crComponent[CurrentXIndex]); - dy2 = crComponent[CurrentYIndex]; - sx2 = crComponent[HScaleIndex]; - sy2 = crComponent[VScaleIndex]; - if (!((sx2 == 0) - && (sy2 == 0))) { - dx2 = dx2 / sx2; - dy2 = dy2 / sy2; + dxInt = (curXInt = crComponent[CurrentXIndex]); + dyInt = crComponent[CurrentYIndex]; + sxInt = crComponent[HScaleIndex]; + syInt = crComponent[VScaleIndex]; + if (!((sxInt == 0) + && (syInt == 0))) { + dxInt = dxInt / sxInt; + dyInt = dyInt / syInt; } - blockIndex2 = (((((usqInt)(dy2)) >> 3)) * (crComponent[BlockWidthIndex])) + ((((usqInt)(dx2)) >> 3)); - sampleIndex2 = ((((sqInt)((usqInt)((dy2 & 7)) << 3)))) + (dx2 & 7); - sample2 = (crBlocks[blockIndex2])[sampleIndex2]; - curX2 += 1; - if (curX2 < ((crComponent[MCUWidthIndex]) * 8)) { - crComponent[CurrentXIndex] = curX2; + blockIndex1 = (((((usqInt)(dyInt)) >> 3)) * (crComponent[BlockWidthIndex])) + ((((usqInt)(dxInt)) >> 3)); + sampleIndex1 = (((((usqInt)((dyInt & 7)) << 3)))) + (dxInt & 7); + cr = (crBlocks[blockIndex1])[sampleIndex1]; + curXInt += 1; + if (curXInt < ((crComponent[MCUWidthIndex]) * 8)) { + crComponent[CurrentXIndex] = curXInt; } else { crComponent[CurrentXIndex] = 0; crComponent[CurrentYIndex] = ((crComponent[CurrentYIndex]) + 1); } - cr = sample2; cr -= SampleOffset; red = (y + ((FIXn1n40200 * cr) / 0x10000)) + (residuals[RedIndex]); red = ((red < MaxSample) ? red : MaxSample); @@ -622,7 +580,7 @@ primitiveColorConvertMCU(void) residuals[BlueIndex] = (blue & ditherMask); blue = blue & (MaxSample - ditherMask); blue = ((blue < 1) ? 1 : blue); - jpegBits[i] = (((0xFF000000U + ((((sqInt)((usqInt)(red) << 16))))) + ((((sqInt)((usqInt)(green) << 8))))) + blue); + jpegBits[i] = (((0xFF000000U + (((((usqInt)(red) << 16))))) + (((((usqInt)(green) << 8))))) + blue); } pop(4); return 0; @@ -646,20 +604,45 @@ primitiveDecodeMCU(void) sqInt bits; sqInt byte; unsigned char byte1; - unsigned char byte2; sqInt i; sqInt index; sqInt oop; + sqInt oopSqInt; sqInt streamOop; + sqInt sz; sqInt value; - sqInt value1; sqInt zeroCount; if (!((methodArgumentCount()) == 5)) { return primitiveFail(); } oop = stackValue(0); - if (!(loadJPEGStreamFrom(oop))) { + + /* begin loadJPEGStreamFrom: */ + if (!(isPointers(oop))) { + return primitiveFail(); + } + if ((slotSizeOf(oop)) < 5) { + return primitiveFail(); + } + oopSqInt = fetchPointerofObject(0, oop); + if (!(isBytes(oopSqInt))) { + return primitiveFail(); + } + jsCollection = firstIndexableField(oopSqInt); + sz = byteSizeOf(oopSqInt); + jsPosition = fetchIntegerofObject(1, oop); + jsReadLimit = fetchIntegerofObject(2, oop); + jsBitBuffer = fetchIntegerofObject(3, oop); + jsBitCount = fetchIntegerofObject(4, oop); + if (failed()) { + return primitiveFail(); + } + if (sz < jsReadLimit) { + return primitiveFail(); + } + if ((jsPosition < 0) + || (jsPosition >= jsReadLimit)) { return primitiveFail(); } arrayOop = stackValue(1); @@ -683,49 +666,52 @@ primitiveDecodeMCU(void) && ((slotSizeOf(arrayOop)) == DCTSize2))) { return primitiveFail(); } - anArray = ((int *) (firstIndexableField(arrayOop))); + anArray = firstIndexableField(arrayOop); if (failed()) { return null; } + /* begin decodeBlockInto:component: */ byte = jpegDecodeValueFromsize(dcTable, dcTableSize); if (byte < 0) { primitiveFail(); - goto l7; + goto l5; } - if (byte != 0) { + if (byte) { /* begin getBits: */ if (byte > jsBitCount) { /* begin fillBuffer */ while (jsBitCount <= 16) { if (!(jsPosition < jsReadLimit)) { - goto l3; + goto l1; } byte1 = jsCollection[jsPosition]; jsPosition += 1; if (byte1 == 0xFF) { + /* peek for 00 */ if (!((jsPosition < jsReadLimit) && ((jsCollection[jsPosition]) == 0))) { jsPosition -= 1; - goto l3; + goto l1; } jsPosition += 1; } - jsBitBuffer = ((((sqInt)((usqInt)(jsBitBuffer) << 8)))) | byte1; + jsBitBuffer = (((((usqInt)(jsBitBuffer) << 8)))) | byte1; jsBitCount += 8; } - l3: /* end fillBuffer */; +l1: /* end fillBuffer */; if (byte > jsBitCount) { bits = -1; - goto l4; + goto l2; } } jsBitCount -= byte; value = ((usqInt)(jsBitBuffer)) >> jsBitCount; jsBitBuffer = jsBitBuffer & ((1U << jsBitCount) - 1); bits = value; - l4: /* end getBits: */; +l2: /* end getBits: */; + /* begin scaleAndSignExtend:inFieldWidth: */ if (bits < (1U << (byte - 1))) { byte = (bits - (1U << byte)) + 1; @@ -744,44 +730,47 @@ primitiveDecodeMCU(void) byte = jpegDecodeValueFromsize(acTable, acTableSize); if (byte < 0) { primitiveFail(); - goto l7; + goto l5; } zeroCount = ((usqInt)(byte)) >> 4; byte = byte & 15; - if (byte != 0) { + if (byte) { index += zeroCount; + /* begin getBits: */ if (byte > jsBitCount) { /* begin fillBuffer */ while (jsBitCount <= 16) { if (!(jsPosition < jsReadLimit)) { - goto l5; + goto l3; } - byte2 = jsCollection[jsPosition]; + byte1 = jsCollection[jsPosition]; jsPosition += 1; - if (byte2 == 0xFF) { + if (byte1 == 0xFF) { + /* peek for 00 */ if (!((jsPosition < jsReadLimit) && ((jsCollection[jsPosition]) == 0))) { jsPosition -= 1; - goto l5; + goto l3; } jsPosition += 1; } - jsBitBuffer = ((((sqInt)((usqInt)(jsBitBuffer) << 8)))) | byte2; + jsBitBuffer = (((((usqInt)(jsBitBuffer) << 8)))) | byte1; jsBitCount += 8; } - l5: /* end fillBuffer */; +l3: /* end fillBuffer */; if (byte > jsBitCount) { bits = -1; - goto l6; + goto l4; } } jsBitCount -= byte; - value1 = ((usqInt)(jsBitBuffer)) >> jsBitCount; + value = ((usqInt)(jsBitBuffer)) >> jsBitCount; jsBitBuffer = jsBitBuffer & ((1U << jsBitCount) - 1); - bits = value1; - l6: /* end getBits: */; + bits = value; +l4: /* end getBits: */; + /* begin scaleAndSignExtend:inFieldWidth: */ if (bits < (1U << (byte - 1))) { byte = (bits - (1U << byte)) + 1; @@ -792,7 +781,7 @@ primitiveDecodeMCU(void) if ((index < 0) || (index >= DCTSize2)) { primitiveFail(); - goto l7; + goto l5; } anArray[jpegNaturalOrder[index]] = byte; } @@ -801,16 +790,17 @@ primitiveDecodeMCU(void) index += zeroCount; } else { - goto l7; + goto l5; } } index += 1; } - l7: /* end decodeBlockInto:component: */; +l5: /* end decodeBlockInto:component: */; if (failed()) { return null; } streamOop = stackValue(0); + /* begin storeJPEGStreamOn: */ storeIntegerofObjectwithValue(1, streamOop, jsPosition); storeIntegerofObjectwithValue(3, streamOop, jsBitBuffer); @@ -834,7 +824,7 @@ primitiveIdctInt(void) int *anArray; sqInt arrayOop; sqInt dcval; - sqInt i; + int i; sqInt j; int *qt; sqInt row; @@ -862,19 +852,20 @@ primitiveIdctInt(void) && ((slotSizeOf(arrayOop)) == DCTSize2))) { return primitiveFail(); } - qt = ((int *) (firstIndexableField(arrayOop))); + qt = firstIndexableField(arrayOop); arrayOop = stackValue(1); if (!((isWords(arrayOop)) && ((slotSizeOf(arrayOop)) == DCTSize2))) { return primitiveFail(); } - anArray = ((int *) (firstIndexableField(arrayOop))); + anArray = firstIndexableField(arrayOop); + /* begin idctBlockInt:qt: */ for (i = 0; i < DCTSize; i += 1) { anACTerm = -1; for (row = 1; row < DCTSize; row += 1) { if (anACTerm == -1) { - if (!((anArray[(row * DCTSize) + i]) == 0)) { + if (anArray[(row * DCTSize) + i]) { anACTerm = row; } } @@ -1013,12 +1004,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -1050,8 +1040,8 @@ yColorComponentFrom(sqInt oop) && (colorComponentBlocksfrom(yBlocks, oop)); } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "JPEGReaderPlugin"; diff --git a/src/plugins/Klatt/Klatt.c b/src/plugins/Klatt/Klatt.c index fb1ca291b7..aa5b09aa9c 100644 --- a/src/plugins/Klatt/Klatt.c +++ b/src/plugins/Klatt/Klatt.c @@ -1,9 +1,9 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - KlattSynthesizerPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + KlattSynthesizerPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 */ -static char __buildInfo[] = "KlattSynthesizerPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f " __DATE__ ; +static char __buildInfo[] = "KlattSynthesizerPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 " __DATE__ ; #include "config.h" @@ -116,6 +116,7 @@ static char __buildInfo[] = "KlattSynthesizerPlugin VMMaker.oscog-eem.3455 uuid: static void antiResonatorfrequencybandwidth(sqInt index, float freq, float bw); EXPORT(const char*) getModuleName(void); static float linearFromdB(double aNumber); +static sqInt loadFrom(sqInt klattOop); static sqInt nextRandom(void); static float parallelFrictionBranch(float source); static float parallelVoicedBranch(float source); @@ -127,6 +128,7 @@ static float resonatorP1(sqInt index); static float resonatorP2(sqInt index); static void resonatorfrequencybandwidth(sqInt index, float freq, float bw); static float resonatorvalue(sqInt index, float aFloat); +static sqInt saveTo(sqInt origKlattOop); EXPORT(sqInt) setInterpreter(struct VirtualMachine *anInterpreter); @@ -175,7 +177,7 @@ extern sqInt success(sqInt aBoolean); extern #endif struct VirtualMachine* interpreterProxy; -static const char *moduleName = "Klatt VMMaker.oscog-eem.3455 " INT_EXT; +static const char *moduleName = "Klatt VMMaker.oscog-eem.3456 " INT_EXT; static sqInt nmod; static sqInt nopen; static sqInt nper; @@ -222,6 +224,7 @@ antiResonatorfrequencybandwidth(sqInt index, float freq, float bw) a = 1.0 / a; b = (0.0 - b) * a; c = (0.0 - c) * a; + /* begin resonatorA:put: */ resonators[(index * 5) - 5] = a; resonators[(index * 5) - 4] = b; @@ -248,6 +251,49 @@ linearFromdB(double aNumber) return (pow(2.0,((aNumber - 87.0) / 6.0))) * 32.767; } + /* KlattSynthesizerPlugin>>#loadFrom: */ +static sqInt +loadFrom(sqInt klattOop) +{ + sqInt oop; + + success((slotSizeOf(klattOop)) == 22); + if (failed()) { + return 0; + } + oop = fetchPointerofObject(0, klattOop); + + /* begin checkedFloatPtrOf: */ + success(isWords(oop)); + if (failed()) { + resonators = 0; + goto l1; + } + resonators = firstIndexableField(oop); +l1: /* end checkedFloatPtrOf: */; + pitch = fetchFloatofObject(2, klattOop); + t0 = fetchIntegerofObject(3, klattOop); + nper = fetchIntegerofObject(4, klattOop); + nopen = fetchIntegerofObject(5, klattOop); + nmod = fetchIntegerofObject(6, klattOop); + a1 = fetchFloatofObject(7, klattOop); + a2 = fetchFloatofObject(8, klattOop); + x1 = fetchFloatofObject(9, klattOop); + x2 = fetchFloatofObject(10, klattOop); + b1 = fetchFloatofObject(11, klattOop); + c1 = fetchFloatofObject(12, klattOop); + glast = fetchFloatofObject(13, klattOop); + vlast = fetchFloatofObject(14, klattOop); + nlast = fetchFloatofObject(15, klattOop); + periodCount = fetchIntegerofObject(16, klattOop); + samplesCount = fetchIntegerofObject(17, klattOop); + seed = fetchIntegerofObject(18, klattOop); + cascade = fetchIntegerofObject(19, klattOop); + samplesPerFrame = fetchIntegerofObject(20, klattOop); + samplingRate = fetchIntegerofObject(21, klattOop); + return (failed()) == 0; +} + /* Answer a random number between 0 and 65535. */ @@ -286,20 +332,8 @@ parallelVoicedBranch(float source) EXPORT(sqInt) primitiveSynthesizeFrameIntoStartingAt(void) { - sqInt a1Oop; - sqInt a2Oop; float aFloat; - float aFloat1; - float aFloat10; - float aFloat11; - float aFloat2; - float aFloat3; - float aFloat4; - float aFloat5; - float aFloat6; - float aFloat7; - float aFloat8; - float aFloat9; + float aFloatFloat; float *aKlattFrame; float ampF1V; float ampF2F; @@ -314,71 +348,39 @@ primitiveSynthesizeFrameIntoStartingAt(void) float ampFTV; float ampGain; float answer; - float answer1; - float answer10; - float answer11; - double answer12; - double answer2; - float answer3; - float answer4; - float answer5; - float answer6; - float answer7; - float answer8; - float answer9; + double answerDouble; + float answerFloat; float asin; float aspiration; float aspirationNoise; - sqInt b1Oop; float bsin; short *buffer; sqInt bufferOop; + float bw; float bypass; - sqInt c1Oop; float cosphi; float csin; float d; double deltaF0; float expuphi; - float expuphi1; - float expuphi2; - float expuphi3; - float expuphi4; - float expuphi5; float friction; float frictionNoise; float gain; float gamma; float gammapwr; - sqInt glastOop; float glotout; sqInt index; sqInt ingore; - sqInt klattOop; - sqInt nlastOop; float noise; sqInt oop; - sqInt oop1; - sqInt oop2; float out; - float out1; + float outFloat; float p1; - float p11; - float p110; - float p111; - double p112; - double p12; - float p13; - float p14; - float p15; - float p16; - float p17; - float p18; - float p19; + double p1Double; + float p1Float; float parGlotout; float parVoicing; float phi; - sqInt pitchOop; float qa; float qb; float qc; @@ -406,109 +408,84 @@ primitiveSynthesizeFrameIntoStartingAt(void) float ua; float ub; float uc; - sqInt vlastOop; float voice; float voicing; float x0; - sqInt x1Oop; - sqInt x2Oop; oop = stackValue(2); + /* begin checkedFloatPtrOf: */ success(isWords(oop)); if (failed()) { aKlattFrame = 0; goto l1; } - aKlattFrame = ((float *) (firstIndexableField(oop))); - l1: /* end checkedFloatPtrOf: */; - oop1 = (bufferOop = stackValue(1)); + aKlattFrame = firstIndexableField(oop); +l1: /* end checkedFloatPtrOf: */; + oop = (bufferOop = stackValue(1)); + /* begin checkedShortPtrOf: */ - success(isWords(oop1)); + success(isWords(oop)); if (failed()) { buffer = 0; goto l2; } - buffer = ((short *) (firstIndexableField(oop1))); - l2: /* end checkedShortPtrOf: */; + buffer = firstIndexableField(oop); +l2: /* end checkedShortPtrOf: */; startIndex = stackIntegerValue(0); if (failed()) { return null; } rcvr = stackObjectValue(3); - /* begin loadFrom: */ - success((slotSizeOf(rcvr)) == 22); - if (failed()) { + if (!(loadFrom(rcvr))) { return null; } - oop2 = fetchPointerofObject(0, rcvr); - /* begin checkedFloatPtrOf: */ - success(isWords(oop2)); - if (failed()) { - resonators = 0; - goto l4; - } - resonators = ((float *) (firstIndexableField(oop2))); - l4: /* end checkedFloatPtrOf: */; - pitch = fetchFloatofObject(2, rcvr); - t0 = fetchIntegerofObject(3, rcvr); - nper = fetchIntegerofObject(4, rcvr); - nopen = fetchIntegerofObject(5, rcvr); - nmod = fetchIntegerofObject(6, rcvr); - a1 = fetchFloatofObject(7, rcvr); - a2 = fetchFloatofObject(8, rcvr); - x1 = fetchFloatofObject(9, rcvr); - x2 = fetchFloatofObject(10, rcvr); - b1 = fetchFloatofObject(11, rcvr); - c1 = fetchFloatofObject(12, rcvr); - glast = fetchFloatofObject(13, rcvr); - vlast = fetchFloatofObject(14, rcvr); - nlast = fetchFloatofObject(15, rcvr); - periodCount = fetchIntegerofObject(16, rcvr); - samplesCount = fetchIntegerofObject(17, rcvr); - seed = fetchIntegerofObject(18, rcvr); - cascade = fetchIntegerofObject(19, rcvr); - samplesPerFrame = fetchIntegerofObject(20, rcvr); - samplingRate = fetchIntegerofObject(21, rcvr); - if ((failed()) == 0) { - goto l5; - } - else { - return null; - } - l5:; success(((stSizeOf(bufferOop)) * 2) >= samplesPerFrame); if (failed()) { return null; } + /* begin synthesizeFrame:into:startingAt: */ + /* begin setCurrentFrame: */ /* Fudge factors... */ frame = aKlattFrame; + /* -4.44 dB */ ampFNV = (linearFromdB(frame[Anv])) * 0.6; + /* -4.44 dB */ ampFTV = (linearFromdB(frame[Atv])) * 0.6; + /* -7.96 dB */ ampF1V = (linearFromdB(frame[A1v])) * 0.4; + /* -16.5 dB */ ampF2V = (linearFromdB(frame[A2v])) * 0.15; + /* -24.4 dB */ ampF3V = (linearFromdB(frame[A3v])) * 0.06; + /* -28.0 dB */ ampF4V = (linearFromdB(frame[A4v])) * 0.04; + /* -16.5 dB */ ampF2F = (linearFromdB(frame[A2f])) * 0.15; + /* -24.4 dB */ ampF3F = (linearFromdB(frame[A3f])) * 0.06; + /* -28.0 dB */ ampF4F = (linearFromdB(frame[A4f])) * 0.04; + /* -33.2 dB */ ampF5F = (linearFromdB(frame[A5f])) * 0.022; + /* -30.5 dB */ /* Set coefficients of variable cascade resonators */ ampF6F = (linearFromdB(frame[A6f])) * 0.03; if (cascade >= 8) { if (samplingRate >= 16000) { + /* Inside Nyquist rate? */ resonatorfrequencybandwidth(R8c, 7500, 600); } @@ -518,6 +495,7 @@ primitiveSynthesizeFrameIntoStartingAt(void) } if (cascade >= 7) { if (samplingRate >= 16000) { + /* Inside Nyquist rate? */ resonatorfrequencybandwidth(R7c, 6500, 500); } @@ -539,51 +517,63 @@ primitiveSynthesizeFrameIntoStartingAt(void) resonatorfrequencybandwidth(Rtpc, frame[Ftp], frame[Btp]); antiResonatorfrequencybandwidth(Rnz, frame[Fnz], frame[Bnz]); antiResonatorfrequencybandwidth(Rtz, frame[Ftz], frame[Btz]); + /* begin resonator:frequency:bandwidth:gain: */ resonatorfrequencybandwidth(Rnpp, frame[Fnp], frame[Bnp]); - aFloat11 = (resonatorA(Rnpp)) * ampFNV; + aFloat = (resonatorA(Rnpp)) * ampFNV; + /* begin resonatorA:put: */ - resonators[(Rnpp * 5) - 5] = aFloat11; + resonators[0 /* ((Rnpp * 5) - 5) */] = aFloat; resonatorfrequencybandwidth(Rtpp, frame[Ftp], frame[Btp]); - aFloat1 = (resonatorA(Rtpp)) * ampFTV; + aFloat = (resonatorA(Rtpp)) * ampFTV; + /* begin resonatorA:put: */ - resonators[(Rtpp * 5) - 5] = aFloat1; + resonators[5 /* ((Rtpp * 5) - 5) */] = aFloat; resonatorfrequencybandwidth(R1vp, frame[F1], frame[B1]); - aFloat2 = (resonatorA(R1vp)) * ampF1V; + aFloat = (resonatorA(R1vp)) * ampF1V; + /* begin resonatorA:put: */ - resonators[(R1vp * 5) - 5] = aFloat2; + resonators[10 /* ((R1vp * 5) - 5) */] = aFloat; resonatorfrequencybandwidth(R2vp, frame[F2], frame[B2]); - aFloat3 = (resonatorA(R2vp)) * ampF2V; + aFloat = (resonatorA(R2vp)) * ampF2V; + /* begin resonatorA:put: */ - resonators[(R2vp * 5) - 5] = aFloat3; + resonators[15 /* ((R2vp * 5) - 5) */] = aFloat; resonatorfrequencybandwidth(R3vp, frame[F3], frame[B3]); - aFloat4 = (resonatorA(R3vp)) * ampF3V; + aFloat = (resonatorA(R3vp)) * ampF3V; + /* begin resonatorA:put: */ - resonators[(R3vp * 5) - 5] = aFloat4; + resonators[20 /* ((R3vp * 5) - 5) */] = aFloat; resonatorfrequencybandwidth(R4vp, frame[F4], frame[B4]); - aFloat5 = (resonatorA(R4vp)) * ampF4V; + aFloat = (resonatorA(R4vp)) * ampF4V; + /* begin resonatorA:put: */ - resonators[(R4vp * 5) - 5] = aFloat5; + resonators[25 /* ((R4vp * 5) - 5) */] = aFloat; resonatorfrequencybandwidth(R2fp, frame[F2], frame[B2f]); - aFloat6 = (resonatorA(R2fp)) * ampF2F; + aFloat = (resonatorA(R2fp)) * ampF2F; + /* begin resonatorA:put: */ - resonators[(R2fp * 5) - 5] = aFloat6; + resonators[30 /* ((R2fp * 5) - 5) */] = aFloat; resonatorfrequencybandwidth(R3fp, frame[F3], frame[B3f]); - aFloat7 = (resonatorA(R3fp)) * ampF3F; + aFloat = (resonatorA(R3fp)) * ampF3F; + /* begin resonatorA:put: */ - resonators[(R3fp * 5) - 5] = aFloat7; + resonators[35 /* ((R3fp * 5) - 5) */] = aFloat; resonatorfrequencybandwidth(R4fp, frame[F4], frame[B4f]); - aFloat8 = (resonatorA(R4fp)) * ampF4F; + aFloat = (resonatorA(R4fp)) * ampF4F; + /* begin resonatorA:put: */ - resonators[(R4fp * 5) - 5] = aFloat8; + resonators[40 /* ((R4fp * 5) - 5) */] = aFloat; resonatorfrequencybandwidth(R5fp, frame[F5], frame[B5f]); - aFloat9 = (resonatorA(R5fp)) * ampF5F; + aFloat = (resonatorA(R5fp)) * ampF5F; + /* begin resonatorA:put: */ - resonators[(R5fp * 5) - 5] = aFloat9; + resonators[45 /* ((R5fp * 5) - 5) */] = aFloat; resonatorfrequencybandwidth(R6fp, frame[F6], frame[B6f]); - aFloat10 = (resonatorA(R6fp)) * ampF6F; + aFloat = (resonatorA(R6fp)) * ampF6F; + /* begin resonatorA:put: */ - resonators[(R6fp * 5) - 5] = aFloat10; + resonators[50 /* ((R6fp * 5) - 5) */] = aFloat; if (pitch > 0) { /* begin linearFromdB: */ voicing = (pow(2.0,((((frame[Voicing]) - 7) - 87.0) / 6.0))) * 32.767; @@ -595,6 +585,7 @@ primitiveSynthesizeFrameIntoStartingAt(void) } friction = (linearFromdB(frame[Friction])) * 0.25; aspiration = (linearFromdB(frame[Aspiration])) * 0.05; + /* -26.0 dB */ /* Flod overall gain into output resonator (low-pass filter) */ bypass = (linearFromdB(frame[Bypass])) * 0.05; @@ -602,34 +593,43 @@ primitiveSynthesizeFrameIntoStartingAt(void) if (gain <= 0) { gain = 57; } + /* begin linearFromdB: */ ampGain = (pow(2.0,((gain - 87.0) / 6.0))) * 32.767; - resonatorfrequencybandwidth(Rout, 0, samplingRate); + bw = samplingRate; + + /* begin resonator:frequency:bandwidth:gain: */ + resonatorfrequencybandwidth(Rout, 0, bw); aFloat = (resonatorA(Rout)) * ampGain; + /* begin resonatorA:put: */ - resonators[(Rout * 5) - 5] = aFloat; + resonators[115 /* ((Rout * 5) - 5) */] = aFloat; noise = nlast; index = startIndex; top = (samplesPerFrame + startIndex) - 1; while (index <= top) { + /* Get low-passed random number for aspiration and friction noise */ /* radom number between -8196.0 and 8196.0 */ /* Tilt down noise spectrum by soft low-pass filter having a pole near the origin in the z-plane. */ noise = (((double) ((nextRandom()) - 0x8000) )) / 4.0; noise += 0.75 * nlast; + /* Amplitude modulate noise (reduce noise amplitude during second half of glottal period) if voicing simultaneously present. */ nlast = noise; if (nper > nmod) { noise = noise * 0.5; } + /* Compute voicing waveform. */ frictionNoise = friction * noise; + /* begin glottalSource */ - if (t0 == 0) { + if (!t0) { voice = 0; - goto l25; + goto l4; } if (nper < nopen) { x0 = (a1 * x1) + (a2 * x2); @@ -642,6 +642,7 @@ primitiveSynthesizeFrameIntoStartingAt(void) } if (nper >= t0) { nper = 0; + /* begin pitchSynchronousReset */ if ((frame[F0]) > 0) { /* begin voicedPitchSynchronousReset */ @@ -653,25 +654,29 @@ primitiveSynthesizeFrameIntoStartingAt(void) csin = sin(((2.0 * PI) * 4.7) * timeCount); deltaF0 = ((((frame[Flutter]) * 2.0) * (frame[F0])) / 100.0) * ((asin + bsin) + csin); pitch += deltaF0; + /* begin addJitter */ pitch += ((((nextRandom()) - 0x7FFF) * (frame[Jitter])) / 32768.0) * (frame[F0]); - if ((periodCount % 2) == 0) { - pitch += ((frame[Diplophonia]) * (frame[F0])) * (1.0 - (frame[Ro])); + if (periodCount % 2) { + pitch -= ((frame[Diplophonia]) * (frame[F0])) * (1.0 - (frame[Ro])); } else { - pitch -= ((frame[Diplophonia]) * (frame[F0])) * (1.0 - (frame[Ro])); + pitch += ((frame[Diplophonia]) * (frame[F0])) * (1.0 - (frame[Ro])); } if (pitch < 0) { pitch = 0; } + /* Duration of period before amplitude modulation. */ t0 = ((sqInt)(samplingRate / pitch)); nmod = t0; if ((frame[Voicing]) > 0) { nmod = nmod / 2; } + /* Set the LF glottal pulse model parameters. */ nopen = ((sqInt)(t0 * (frame[Ro]))); + /* begin ro:ra:rk: */ te = ((sqInt)(t0 * (frame[Ro]))); ro = (((double) te )) / (((double) t0 )); @@ -688,46 +693,53 @@ primitiveSynthesizeFrameIntoStartingAt(void) cosphi = cos(phi); sinphi = sin(phi); rphid = ((ra / ro) * phi) * d; + /* begin zeroQphi:cosphi:sinphi:rphid: */ - expuphi = exp(0 * phi); + /* begin qu:phi:cosphi:sinphi:rphid: */ + expuphi = exp(0); qzero = (expuphi * ((((rphid)) * sinphi) - cosphi)) + 1.0; if (qzero > 0) { ua = 0; ub = 1; qa = qzero; + /* begin qu:phi:cosphi:sinphi:rphid: */ - expuphi1 = exp(ub * phi); - qb = (expuphi1 * ((((rphid * ((ub * ub) + 1.0)) + ub) * sinphi) - cosphi)) + 1.0; + expuphi = exp(ub * phi); + qb = (expuphi * ((((rphid * ((ub * ub) + 1.0)) + ub) * sinphi) - cosphi)) + 1.0; while (qb > 0) { ua = ub; qa = qb; ub = ub * 2; + /* begin qu:phi:cosphi:sinphi:rphid: */ - expuphi2 = exp(ub * phi); - qb = (expuphi2 * ((((rphid * ((ub * ub) + 1.0)) + ub) * sinphi) - cosphi)) + 1.0; + expuphi = exp(ub * phi); + qb = (expuphi * ((((rphid * ((ub * ub) + 1.0)) + ub) * sinphi) - cosphi)) + 1.0; } } else { ua = -1; ub = 0; + /* begin qu:phi:cosphi:sinphi:rphid: */ - expuphi3 = exp(ua * phi); - qa = (expuphi3 * ((((rphid * ((ua * ua) + 1.0)) + ua) * sinphi) - cosphi)) + 1.0; + expuphi = exp(ua * phi); + qa = (expuphi * ((((rphid * ((ua * ua) + 1.0)) + ua) * sinphi) - cosphi)) + 1.0; qb = qzero; while (qa < 0) { ub = ua; qb = qa; ua = ua * 2; + /* begin qu:phi:cosphi:sinphi:rphid: */ - expuphi4 = exp(ua * phi); - qa = (expuphi4 * ((((rphid * ((ua * ua) + 1.0)) + ua) * sinphi) - cosphi)) + 1.0; + expuphi = exp(ua * phi); + qa = (expuphi * ((((rphid * ((ua * ua) + 1.0)) + ua) * sinphi) - cosphi)) + 1.0; } } while ((ub - ua) > Epsilon) { uc = (ub + ua) / 2.0; + /* begin qu:phi:cosphi:sinphi:rphid: */ - expuphi5 = exp(uc * phi); - qc = (expuphi5 * ((((rphid * ((uc * uc) + 1.0)) + uc) * sinphi) - cosphi)) + 1.0; + expuphi = exp(uc * phi); + qc = (expuphi * ((((rphid * ((uc * uc) + 1.0)) + uc) * sinphi) - cosphi)) + 1.0; if (qc > 0) { ua = uc; qa = qc; @@ -748,6 +760,7 @@ primitiveSynthesizeFrameIntoStartingAt(void) gammapwr = pow(gamma,(t0 - te)); b1 = gamma; c1 = ((1.0 - gamma) * gammapwr) / (1.0 - gammapwr); + /* begin normalizeGlottalPulse */ s0 = 0.0; s1 = x1; @@ -760,14 +773,16 @@ primitiveSynthesizeFrameIntoStartingAt(void) if (!(s0 == 0.0)) { x1 = (x1 / s0) * 10000.0; } + /* begin addShimmer */ /* x1 must be <= 0 */ x1 += ((((nextRandom()) - 0x7FFF) * (frame[Shimmer])) / 32768.0) * x1; if (x1 > 0) { x1 = 0; } + /* begin addAmplitudeDiplophonia */ - if (!((periodCount % 2) == 0)) { + if (periodCount % 2) { /* x1 must be <= 0 */ x1 = x1 * (1.0 - (frame[Diplophonia])); if (x1 > 0) { @@ -783,7 +798,8 @@ primitiveSynthesizeFrameIntoStartingAt(void) } nper += 1; voice = x0; - l25: /* end glottalSource */; +l4: /* end glottalSource */; + /* Add turbulence during glottal open phase. Use random rather than noise because noise is low-passed. */ vlast = voice; @@ -791,119 +807,140 @@ primitiveSynthesizeFrameIntoStartingAt(void) voice += (turbulence * (((double) ((nextRandom()) - 0x8000) ))) / 4.0; } glotout = voicing * voice; + /* Compute aspiration amplitude and add to voicing source. */ parGlotout = parVoicing * voice; aspirationNoise = aspiration * noise; glotout += aspirationNoise; + /* Cascade vocal tract, excited by laryngeal sources. Nasal antiresonator, nasal resonator, trachearl antirresonator, tracheal resonator, then formants F8, F7, F6, F5, F4, F3, F2, F1. */ parGlotout += aspirationNoise; + /* begin cascadeBranch: */ if (!(cascade > 0)) { out = 0.0; - goto l17; + goto l3; } + /* begin antiResonator:value: */ - answer12 = (((resonatorA(Rnz)) * glotout) + ((resonatorB(Rnz)) * ((p112 = resonatorP1(Rnz))))) + ((resonatorC(Rnz)) * (resonatorP2(Rnz))); - resonators[(Rnz * 5) - 1] = p112; - resonators[(Rnz * 5) - 2] = glotout; - out1 = answer12; + answerDouble = (((resonatorA(Rnz)) * glotout) + ((resonatorB(Rnz)) * ((p1Double = resonatorP1(Rnz))))) + ((resonatorC(Rnz)) * (resonatorP2(Rnz))); + aFloatFloat = p1Double; + + /* begin resonatorP2:put: */ + resonators[104 /* ((Rnz * 5) - 1) */] = aFloatFloat; + aFloatFloat = glotout; + + /* begin resonatorP1:put: */ + resonators[103 /* ((Rnz * 5) - 2) */] = aFloatFloat; + outFloat = answerDouble; + /* begin resonator:value: */ /* (p1 between: -100000 and: 100000) ifFalse: [self halt]. (answer between: -100000 and: 100000) ifFalse: [self halt]. */ - answer1 = (((resonatorA(Rnpc)) * out1) + ((resonatorB(Rnpc)) * ((p11 = resonatorP1(Rnpc))))) + ((resonatorC(Rnpc)) * (resonatorP2(Rnpc))); - resonators[(Rnpc * 5) - 1] = p11; - resonators[(Rnpc * 5) - 2] = answer1; - out1 = answer1; + answerFloat = (((resonatorA(Rnpc)) * outFloat) + ((resonatorB(Rnpc)) * ((p1Float = resonatorP1(Rnpc))))) + ((resonatorC(Rnpc)) * (resonatorP2(Rnpc))); + resonators[99 /* ((Rnpc * 5) - 1) */] = p1Float; + resonators[98 /* ((Rnpc * 5) - 2) */] = answerFloat; + outFloat = answerFloat; + /* begin antiResonator:value: */ - answer2 = (((resonatorA(Rtz)) * out1) + ((resonatorB(Rtz)) * ((p12 = resonatorP1(Rtz))))) + ((resonatorC(Rtz)) * (resonatorP2(Rtz))); - resonators[(Rtz * 5) - 1] = p12; - resonators[(Rtz * 5) - 2] = out1; - out1 = answer2; + answerDouble = (((resonatorA(Rtz)) * outFloat) + ((resonatorB(Rtz)) * ((p1Double = resonatorP1(Rtz))))) + ((resonatorC(Rtz)) * (resonatorP2(Rtz))); + aFloatFloat = p1Double; + + /* begin resonatorP2:put: */ + resonators[114 /* ((Rtz * 5) - 1) */] = aFloatFloat; + aFloatFloat = outFloat; + + /* begin resonatorP1:put: */ + resonators[113 /* ((Rtz * 5) - 2) */] = aFloatFloat; + outFloat = answerDouble; + /* begin resonator:value: */ /* (p1 between: -100000 and: 100000) ifFalse: [self halt]. (answer between: -100000 and: 100000) ifFalse: [self halt]. */ - answer3 = (((resonatorA(Rtpc)) * out1) + ((resonatorB(Rtpc)) * ((p13 = resonatorP1(Rtpc))))) + ((resonatorC(Rtpc)) * (resonatorP2(Rtpc))); - resonators[(Rtpc * 5) - 1] = p13; - resonators[(Rtpc * 5) - 2] = answer3; - out1 = answer3; + answerFloat = (((resonatorA(Rtpc)) * outFloat) + ((resonatorB(Rtpc)) * ((p1Float = resonatorP1(Rtpc))))) + ((resonatorC(Rtpc)) * (resonatorP2(Rtpc))); + resonators[109 /* ((Rtpc * 5) - 1) */] = p1Float; + resonators[108 /* ((Rtpc * 5) - 2) */] = answerFloat; + outFloat = answerFloat; if (cascade >= 8) { /* begin resonator:value: */ /* (p1 between: -100000 and: 100000) ifFalse: [self halt]. (answer between: -100000 and: 100000) ifFalse: [self halt]. */ - answer4 = (((resonatorA(R8c)) * out1) + ((resonatorB(R8c)) * ((p14 = resonatorP1(R8c))))) + ((resonatorC(R8c)) * (resonatorP2(R8c))); - resonators[(R8c * 5) - 1] = p14; - resonators[(R8c * 5) - 2] = answer4; - out1 = answer4; + answerFloat = (((resonatorA(R8c)) * outFloat) + ((resonatorB(R8c)) * ((p1Float = resonatorP1(R8c))))) + ((resonatorC(R8c)) * (resonatorP2(R8c))); + resonators[94 /* ((R8c * 5) - 1) */] = p1Float; + resonators[93 /* ((R8c * 5) - 2) */] = answerFloat; + outFloat = answerFloat; } if (cascade >= 7) { /* begin resonator:value: */ /* (p1 between: -100000 and: 100000) ifFalse: [self halt]. (answer between: -100000 and: 100000) ifFalse: [self halt]. */ - answer5 = (((resonatorA(R7c)) * out1) + ((resonatorB(R7c)) * ((p15 = resonatorP1(R7c))))) + ((resonatorC(R7c)) * (resonatorP2(R7c))); - resonators[(R7c * 5) - 1] = p15; - resonators[(R7c * 5) - 2] = answer5; - out1 = answer5; + answerFloat = (((resonatorA(R7c)) * outFloat) + ((resonatorB(R7c)) * ((p1Float = resonatorP1(R7c))))) + ((resonatorC(R7c)) * (resonatorP2(R7c))); + resonators[89 /* ((R7c * 5) - 1) */] = p1Float; + resonators[88 /* ((R7c * 5) - 2) */] = answerFloat; + outFloat = answerFloat; } if (cascade >= 6) { /* begin resonator:value: */ /* (p1 between: -100000 and: 100000) ifFalse: [self halt]. (answer between: -100000 and: 100000) ifFalse: [self halt]. */ - answer6 = (((resonatorA(R6c)) * out1) + ((resonatorB(R6c)) * ((p16 = resonatorP1(R6c))))) + ((resonatorC(R6c)) * (resonatorP2(R6c))); - resonators[(R6c * 5) - 1] = p16; - resonators[(R6c * 5) - 2] = answer6; - out1 = answer6; + answerFloat = (((resonatorA(R6c)) * outFloat) + ((resonatorB(R6c)) * ((p1Float = resonatorP1(R6c))))) + ((resonatorC(R6c)) * (resonatorP2(R6c))); + resonators[84 /* ((R6c * 5) - 1) */] = p1Float; + resonators[83 /* ((R6c * 5) - 2) */] = answerFloat; + outFloat = answerFloat; } if (cascade >= 5) { /* begin resonator:value: */ /* (p1 between: -100000 and: 100000) ifFalse: [self halt]. (answer between: -100000 and: 100000) ifFalse: [self halt]. */ - answer7 = (((resonatorA(R5c)) * out1) + ((resonatorB(R5c)) * ((p17 = resonatorP1(R5c))))) + ((resonatorC(R5c)) * (resonatorP2(R5c))); - resonators[(R5c * 5) - 1] = p17; - resonators[(R5c * 5) - 2] = answer7; - out1 = answer7; + answerFloat = (((resonatorA(R5c)) * outFloat) + ((resonatorB(R5c)) * ((p1Float = resonatorP1(R5c))))) + ((resonatorC(R5c)) * (resonatorP2(R5c))); + resonators[79 /* ((R5c * 5) - 1) */] = p1Float; + resonators[78 /* ((R5c * 5) - 2) */] = answerFloat; + outFloat = answerFloat; } if (cascade >= 4) { /* begin resonator:value: */ /* (p1 between: -100000 and: 100000) ifFalse: [self halt]. (answer between: -100000 and: 100000) ifFalse: [self halt]. */ - answer8 = (((resonatorA(R4c)) * out1) + ((resonatorB(R4c)) * ((p18 = resonatorP1(R4c))))) + ((resonatorC(R4c)) * (resonatorP2(R4c))); - resonators[(R4c * 5) - 1] = p18; - resonators[(R4c * 5) - 2] = answer8; - out1 = answer8; + answerFloat = (((resonatorA(R4c)) * outFloat) + ((resonatorB(R4c)) * ((p1Float = resonatorP1(R4c))))) + ((resonatorC(R4c)) * (resonatorP2(R4c))); + resonators[74 /* ((R4c * 5) - 1) */] = p1Float; + resonators[73 /* ((R4c * 5) - 2) */] = answerFloat; + outFloat = answerFloat; } if (cascade >= 3) { /* begin resonator:value: */ /* (p1 between: -100000 and: 100000) ifFalse: [self halt]. (answer between: -100000 and: 100000) ifFalse: [self halt]. */ - answer9 = (((resonatorA(R3c)) * out1) + ((resonatorB(R3c)) * ((p19 = resonatorP1(R3c))))) + ((resonatorC(R3c)) * (resonatorP2(R3c))); - resonators[(R3c * 5) - 1] = p19; - resonators[(R3c * 5) - 2] = answer9; - out1 = answer9; + answerFloat = (((resonatorA(R3c)) * outFloat) + ((resonatorB(R3c)) * ((p1Float = resonatorP1(R3c))))) + ((resonatorC(R3c)) * (resonatorP2(R3c))); + resonators[69 /* ((R3c * 5) - 1) */] = p1Float; + resonators[68 /* ((R3c * 5) - 2) */] = answerFloat; + outFloat = answerFloat; } if (cascade >= 2) { /* begin resonator:value: */ /* (p1 between: -100000 and: 100000) ifFalse: [self halt]. (answer between: -100000 and: 100000) ifFalse: [self halt]. */ - answer10 = (((resonatorA(R2c)) * out1) + ((resonatorB(R2c)) * ((p110 = resonatorP1(R2c))))) + ((resonatorC(R2c)) * (resonatorP2(R2c))); - resonators[(R2c * 5) - 1] = p110; - resonators[(R2c * 5) - 2] = answer10; - out1 = answer10; + answerFloat = (((resonatorA(R2c)) * outFloat) + ((resonatorB(R2c)) * ((p1Float = resonatorP1(R2c))))) + ((resonatorC(R2c)) * (resonatorP2(R2c))); + resonators[64 /* ((R2c * 5) - 1) */] = p1Float; + resonators[0x3F /* ((R2c * 5) - 2) */] = answerFloat; + outFloat = answerFloat; } if (cascade >= 1) { /* begin resonator:value: */ /* (p1 between: -100000 and: 100000) ifFalse: [self halt]. (answer between: -100000 and: 100000) ifFalse: [self halt]. */ - answer11 = (((resonatorA(R1c)) * out1) + ((resonatorB(R1c)) * ((p111 = resonatorP1(R1c))))) + ((resonatorC(R1c)) * (resonatorP2(R1c))); - resonators[(R1c * 5) - 1] = p111; - resonators[(R1c * 5) - 2] = answer11; - out1 = answer11; + answerFloat = (((resonatorA(R1c)) * outFloat) + ((resonatorB(R1c)) * ((p1Float = resonatorP1(R1c))))) + ((resonatorC(R1c)) * (resonatorP2(R1c))); + resonators[59 /* ((R1c * 5) - 1) */] = p1Float; + resonators[58 /* ((R1c * 5) - 2) */] = answerFloat; + outFloat = answerFloat; } - out = out1; - l17: /* end cascadeBranch: */; + out = outFloat; +l3: /* end cascadeBranch: */; + /* Source is voicing plus aspiration. */ source = parGlotout; + /* Friction-excited parallel vocal tract formants F6, F5, F4, F3, F2, outputs added with alternating sign. Sound source for other parallel resonators is friction plus first difference of @@ -911,15 +948,17 @@ primitiveSynthesizeFrameIntoStartingAt(void) out += parallelVoicedBranch(source); source = (frictionNoise + parGlotout) - glast; glast = parGlotout; + /* Apply bypas and output low-pass filter */ out = (parallelFrictionBranch(source)) - out; out = (bypass * source) - out; + /* begin resonator:value: */ /* (p1 between: -100000 and: 100000) ifFalse: [self halt]. (answer between: -100000 and: 100000) ifFalse: [self halt]. */ answer = (((resonatorA(Rout)) * out) + ((resonatorB(Rout)) * ((p1 = resonatorP1(Rout))))) + ((resonatorC(Rout)) * (resonatorP2(Rout))); - resonators[(Rout * 5) - 1] = p1; - resonators[(Rout * 5) - 2] = answer; + resonators[119 /* ((Rout * 5) - 1) */] = p1; + resonators[118 /* ((Rout * 5) - 2) */] = answer; out = answer; temp = ((sqInt)(out * ampGain)); if (temp < -32768) { @@ -932,55 +971,9 @@ primitiveSynthesizeFrameIntoStartingAt(void) index += 1; samplesCount += 1; } - /* begin saveTo: */ - pushRemappableOop(rcvr); - pushRemappableOop(floatObjectOf(pitch)); - pushRemappableOop(floatObjectOf(a1)); - pushRemappableOop(floatObjectOf(a2)); - pushRemappableOop(floatObjectOf(x1)); - pushRemappableOop(floatObjectOf(x2)); - pushRemappableOop(floatObjectOf(b1)); - pushRemappableOop(floatObjectOf(c1)); - pushRemappableOop(floatObjectOf(glast)); - pushRemappableOop(floatObjectOf(vlast)); - nlastOop = floatObjectOf(nlast); - vlastOop = popRemappableOop(); - glastOop = popRemappableOop(); - c1Oop = popRemappableOop(); - b1Oop = popRemappableOop(); - x2Oop = popRemappableOop(); - x1Oop = popRemappableOop(); - a2Oop = popRemappableOop(); - a1Oop = popRemappableOop(); - pitchOop = popRemappableOop(); - klattOop = popRemappableOop(); - if (failed()) { + if (!(saveTo(rcvr))) { return null; } - storePointerofObjectwithValue(2, klattOop, pitchOop); - storeIntegerofObjectwithValue(3, klattOop, t0); - storeIntegerofObjectwithValue(4, klattOop, nper); - storeIntegerofObjectwithValue(5, klattOop, nopen); - storeIntegerofObjectwithValue(6, klattOop, nmod); - storePointerofObjectwithValue(7, klattOop, a1Oop); - storePointerofObjectwithValue(8, klattOop, a2Oop); - storePointerofObjectwithValue(9, klattOop, x1Oop); - storePointerofObjectwithValue(10, klattOop, x2Oop); - storePointerofObjectwithValue(11, klattOop, b1Oop); - storePointerofObjectwithValue(12, klattOop, c1Oop); - storePointerofObjectwithValue(13, klattOop, glastOop); - storePointerofObjectwithValue(14, klattOop, vlastOop); - storePointerofObjectwithValue(15, klattOop, nlastOop); - storeIntegerofObjectwithValue(16, klattOop, periodCount); - storeIntegerofObjectwithValue(17, klattOop, samplesCount); - storeIntegerofObjectwithValue(18, klattOop, seed); - if ((failed()) == 0) { - goto l3; - } - else { - return null; - } - l3:; pop(3); return 0; } @@ -1040,6 +1033,7 @@ resonatorfrequencybandwidth(sqInt index, float freq, float bw) arg = ((PI * 2.0) / samplingRate) * freq; b = (r * (cos(arg))) * 2.0; a = (1.0 - b) - c; + /* begin resonatorA:put: */ resonators[(index * 5) - 5] = a; resonators[(index * 5) - 4] = b; @@ -1053,16 +1047,76 @@ resonatorvalue(sqInt index, float aFloat) float answer; float p1; - /* (p1 between: -100000 and: 100000) ifFalse: [self halt]. (answer between: -100000 and: 100000) ifFalse: [self halt]. */ answer = (((resonatorA(index)) * aFloat) + ((resonatorB(index)) * ((p1 = resonatorP1(index))))) + ((resonatorC(index)) * (resonatorP2(index))); + /* begin resonatorP2:put: */ resonators[(index * 5) - 1] = p1; resonators[(index * 5) - 2] = answer; return answer; } + /* KlattSynthesizerPlugin>>#saveTo: */ +static sqInt +saveTo(sqInt origKlattOop) +{ + sqInt a1Oop; + sqInt a2Oop; + sqInt b1Oop; + sqInt c1Oop; + sqInt glastOop; + sqInt klattOop; + sqInt nlastOop; + sqInt pitchOop; + sqInt vlastOop; + sqInt x1Oop; + sqInt x2Oop; + + pushRemappableOop(origKlattOop); + pushRemappableOop(floatObjectOf(pitch)); + pushRemappableOop(floatObjectOf(a1)); + pushRemappableOop(floatObjectOf(a2)); + pushRemappableOop(floatObjectOf(x1)); + pushRemappableOop(floatObjectOf(x2)); + pushRemappableOop(floatObjectOf(b1)); + pushRemappableOop(floatObjectOf(c1)); + pushRemappableOop(floatObjectOf(glast)); + pushRemappableOop(floatObjectOf(vlast)); + nlastOop = floatObjectOf(nlast); + vlastOop = popRemappableOop(); + glastOop = popRemappableOop(); + c1Oop = popRemappableOop(); + b1Oop = popRemappableOop(); + x2Oop = popRemappableOop(); + x1Oop = popRemappableOop(); + a2Oop = popRemappableOop(); + a1Oop = popRemappableOop(); + pitchOop = popRemappableOop(); + klattOop = popRemappableOop(); + if (failed()) { + return 0; + } + storePointerofObjectwithValue(2, klattOop, pitchOop); + storeIntegerofObjectwithValue(3, klattOop, t0); + storeIntegerofObjectwithValue(4, klattOop, nper); + storeIntegerofObjectwithValue(5, klattOop, nopen); + storeIntegerofObjectwithValue(6, klattOop, nmod); + storePointerofObjectwithValue(7, klattOop, a1Oop); + storePointerofObjectwithValue(8, klattOop, a2Oop); + storePointerofObjectwithValue(9, klattOop, x1Oop); + storePointerofObjectwithValue(10, klattOop, x2Oop); + storePointerofObjectwithValue(11, klattOop, b1Oop); + storePointerofObjectwithValue(12, klattOop, c1Oop); + storePointerofObjectwithValue(13, klattOop, glastOop); + storePointerofObjectwithValue(14, klattOop, vlastOop); + storePointerofObjectwithValue(15, klattOop, nlastOop); + storeIntegerofObjectwithValue(16, klattOop, periodCount); + storeIntegerofObjectwithValue(17, klattOop, samplesCount); + storeIntegerofObjectwithValue(18, klattOop, seed); + return (failed()) == 0; +} + /* Note: This is coded so that it can be run in Squeak. */ @@ -1072,12 +1126,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -1104,8 +1157,8 @@ setInterpreter(struct VirtualMachine *anInterpreter) return ok; } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "Klatt"; diff --git a/src/plugins/Matrix2x3Plugin/Matrix2x3Plugin.c b/src/plugins/Matrix2x3Plugin/Matrix2x3Plugin.c index 9cac74572d..9e80937a03 100644 --- a/src/plugins/Matrix2x3Plugin/Matrix2x3Plugin.c +++ b/src/plugins/Matrix2x3Plugin/Matrix2x3Plugin.c @@ -1,9 +1,9 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - Matrix2x3Plugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + Matrix2x3Plugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 */ -static char __buildInfo[] = "Matrix2x3Plugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f " __DATE__ ; +static char __buildInfo[] = "Matrix2x3Plugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 " __DATE__ ; #include "config.h" @@ -104,7 +104,7 @@ extern sqInt storePointerofObjectwithValue(sqInt index, sqInt oop, sqInt valuePo extern #endif struct VirtualMachine* interpreterProxy; -static const char *moduleName = "Matrix2x3Plugin VMMaker.oscog-eem.3455 " INT_EXT; +static const char *moduleName = "Matrix2x3Plugin VMMaker.oscog-eem.3456 " INT_EXT; static double m23ArgX; static double m23ArgY; static double m23ResultX; @@ -215,11 +215,10 @@ primitiveComposeMatrix(void) float *m2; float *m3; sqInt matrix; - sqInt matrix1; - sqInt matrix2; sqInt result; matrix = (result = stackValue(0)); + /* begin loadArgumentMatrix: */ if (!((isWords(matrix)) && ((slotSizeOf(matrix)) == 6))) { @@ -227,28 +226,30 @@ primitiveComposeMatrix(void) m3 = null; goto l1; } - m3 = ((float *) (firstIndexableField(matrix))); - l1: /* end loadArgumentMatrix: */; - matrix1 = stackValue(1); + m3 = firstIndexableField(matrix); +l1: /* end loadArgumentMatrix: */; + matrix = stackValue(1); + /* begin loadArgumentMatrix: */ - if (!((isWords(matrix1)) - && ((slotSizeOf(matrix1)) == 6))) { + if (!((isWords(matrix)) + && ((slotSizeOf(matrix)) == 6))) { primitiveFail(); m2 = null; goto l2; } - m2 = ((float *) (firstIndexableField(matrix1))); - l2: /* end loadArgumentMatrix: */; - matrix2 = stackValue(2); + m2 = firstIndexableField(matrix); +l2: /* end loadArgumentMatrix: */; + matrix = stackValue(2); + /* begin loadArgumentMatrix: */ - if (!((isWords(matrix2)) - && ((slotSizeOf(matrix2)) == 6))) { + if (!((isWords(matrix)) + && ((slotSizeOf(matrix)) == 6))) { primitiveFail(); m1 = null; goto l3; } - m1 = ((float *) (firstIndexableField(matrix2))); - l3: /* end loadArgumentMatrix: */; + m1 = firstIndexableField(matrix); +l3: /* end loadArgumentMatrix: */; if (!(failed())) { /* begin matrix2x3ComposeMatrix:with:into: */ a11 = ((m1[0]) * (m2[0])) + ((m1[1]) * (m2[3])); @@ -273,19 +274,20 @@ EXPORT(sqInt) primitiveInvertPoint(void) { float *matrix; - sqInt matrix1; + sqInt matrixSqInt; loadArgumentPoint(stackValue(0)); - matrix1 = stackValue(1); + matrixSqInt = stackValue(1); + /* begin loadArgumentMatrix: */ - if (!((isWords(matrix1)) - && ((slotSizeOf(matrix1)) == 6))) { + if (!((isWords(matrixSqInt)) + && ((slotSizeOf(matrixSqInt)) == 6))) { primitiveFail(); matrix = null; goto l1; } - matrix = ((float *) (firstIndexableField(matrix1))); - l1: /* end loadArgumentMatrix: */; + matrix = firstIndexableField(matrixSqInt); +l1: /* end loadArgumentMatrix: */; if (failed()) { return null; } @@ -294,16 +296,17 @@ primitiveInvertPoint(void) /* begin roundAndStoreResultPoint: */ m23ResultX += 0.5; m23ResultY += 0.5; - if (!(( /* begin okayIntValue: */ + if (!((/* okayIntValue: */ (m23ResultX >= (((double) (MinSmallInteger) ))) && (m23ResultX <= (((double) (MaxSmallInteger) )))) - && ((m23ResultY >= (((double) (MinSmallInteger) ))) + && (/* okayIntValue: */ + (m23ResultY >= (((double) (MinSmallInteger) ))) && (m23ResultY <= (((double) (MaxSmallInteger) )))))) { primitiveFail(); goto l2; } popthenPush(2, makePointwithxValueyValue(((sqInt)m23ResultX), ((sqInt)m23ResultY))); - l2: /* end roundAndStoreResultPoint: */; +l2: /* end roundAndStoreResultPoint: */; } return 0; } @@ -316,7 +319,7 @@ primitiveInvertRectInto(void) double cornerY; sqInt dstOop; float *matrix; - sqInt matrix1; + sqInt matrixSqInt; double maxX; double maxY; double minX; @@ -327,16 +330,17 @@ primitiveInvertRectInto(void) dstOop = stackValue(0); srcOop = stackValue(1); - matrix1 = stackValue(2); + matrixSqInt = stackValue(2); + /* begin loadArgumentMatrix: */ - if (!((isWords(matrix1)) - && ((slotSizeOf(matrix1)) == 6))) { + if (!((isWords(matrixSqInt)) + && ((slotSizeOf(matrixSqInt)) == 6))) { primitiveFail(); matrix = null; goto l1; } - matrix = ((float *) (firstIndexableField(matrix1))); - l1: /* end loadArgumentMatrix: */; + matrix = firstIndexableField(matrixSqInt); +l1: /* end loadArgumentMatrix: */; if (!((matrix) && (((fetchClassOf(srcOop)) == (fetchClassOf(dstOop))) && ((isPointers(srcOop)) @@ -351,6 +355,7 @@ primitiveInvertRectInto(void) originY = m23ArgY; matrix2x3InvertPoint(matrix); minX = (maxX = m23ResultX); + /* Load bottom-right point */ minY = (maxY = m23ResultY); loadArgumentPoint(fetchPointerofObject(1, srcOop)); @@ -363,6 +368,7 @@ primitiveInvertRectInto(void) minX = ((minX < m23ResultX) ? minX : m23ResultX); maxX = ((maxX < m23ResultX) ? m23ResultX : maxX); minY = ((minY < m23ResultY) ? minY : m23ResultY); + /* Load top-right point */ maxY = ((maxY < m23ResultY) ? m23ResultY : maxY); m23ArgX = cornerX; @@ -371,6 +377,7 @@ primitiveInvertRectInto(void) minX = ((minX < m23ResultX) ? minX : m23ResultX); maxX = ((maxX < m23ResultX) ? m23ResultX : maxX); minY = ((minY < m23ResultY) ? minY : m23ResultY); + /* Load bottom-left point */ maxY = ((maxY < m23ResultY) ? m23ResultY : maxY); m23ArgX = originX; @@ -392,18 +399,19 @@ EXPORT(sqInt) primitiveIsIdentity(void) { float *matrix; - sqInt matrix1; + sqInt matrixSqInt; + + matrixSqInt = stackValue(0); - matrix1 = stackValue(0); /* begin loadArgumentMatrix: */ - if (!((isWords(matrix1)) - && ((slotSizeOf(matrix1)) == 6))) { + if (!((isWords(matrixSqInt)) + && ((slotSizeOf(matrixSqInt)) == 6))) { primitiveFail(); matrix = null; goto l1; } - matrix = ((float *) (firstIndexableField(matrix1))); - l1: /* end loadArgumentMatrix: */; + matrix = firstIndexableField(matrixSqInt); +l1: /* end loadArgumentMatrix: */; if (!(failed())) { methodReturnBool(((((((matrix[0]) == (1.0f)) && ((matrix[1]) == (0.0f))) && ((matrix[2]) == (0.0f))) && ((matrix[3]) == (0.0f))) && ((matrix[4]) == (1.0f))) && ((matrix[5]) == (0.0f))); } @@ -415,18 +423,19 @@ EXPORT(sqInt) primitiveIsPureTranslation(void) { float *matrix; - sqInt matrix1; + sqInt matrixSqInt; + + matrixSqInt = stackValue(0); - matrix1 = stackValue(0); /* begin loadArgumentMatrix: */ - if (!((isWords(matrix1)) - && ((slotSizeOf(matrix1)) == 6))) { + if (!((isWords(matrixSqInt)) + && ((slotSizeOf(matrixSqInt)) == 6))) { primitiveFail(); matrix = null; goto l1; } - matrix = ((float *) (firstIndexableField(matrix1))); - l1: /* end loadArgumentMatrix: */; + matrix = firstIndexableField(matrixSqInt); +l1: /* end loadArgumentMatrix: */; if (!(failed())) { methodReturnBool(((((matrix[0]) == (1.0f)) && ((matrix[1]) == (0.0f))) && ((matrix[3]) == (0.0f))) && ((matrix[4]) == (1.0f))); } @@ -438,36 +447,39 @@ EXPORT(sqInt) primitiveTransformPoint(void) { float *matrix; - sqInt matrix1; + sqInt matrixSqInt; loadArgumentPoint(stackValue(0)); - matrix1 = stackValue(1); + matrixSqInt = stackValue(1); + /* begin loadArgumentMatrix: */ - if (!((isWords(matrix1)) - && ((slotSizeOf(matrix1)) == 6))) { + if (!((isWords(matrixSqInt)) + && ((slotSizeOf(matrixSqInt)) == 6))) { primitiveFail(); matrix = null; goto l1; } - matrix = ((float *) (firstIndexableField(matrix1))); - l1: /* end loadArgumentMatrix: */; + matrix = firstIndexableField(matrixSqInt); +l1: /* end loadArgumentMatrix: */; if (!(failed())) { /* begin matrix2x3TransformPoint: */ m23ResultX = ((m23ArgX * (matrix[0])) + (m23ArgY * (matrix[1]))) + (matrix[2]); m23ResultY = ((m23ArgX * (matrix[3])) + (m23ArgY * (matrix[4]))) + (matrix[5]); + /* begin roundAndStoreResultPoint: */ m23ResultX += 0.5; m23ResultY += 0.5; - if (!(( /* begin okayIntValue: */ + if (!((/* okayIntValue: */ (m23ResultX >= (((double) (MinSmallInteger) ))) && (m23ResultX <= (((double) (MaxSmallInteger) )))) - && ((m23ResultY >= (((double) (MinSmallInteger) ))) + && (/* okayIntValue: */ + (m23ResultY >= (((double) (MinSmallInteger) ))) && (m23ResultY <= (((double) (MaxSmallInteger) )))))) { primitiveFail(); goto l2; } popthenPush(2, makePointwithxValueyValue(((sqInt)m23ResultX), ((sqInt)m23ResultY))); - l2: /* end roundAndStoreResultPoint: */; +l2: /* end roundAndStoreResultPoint: */; } return 0; } @@ -480,7 +492,7 @@ primitiveTransformRectInto(void) double cornerY; sqInt dstOop; float *matrix; - sqInt matrix1; + sqInt matrixSqInt; double maxX; double maxY; double minX; @@ -491,16 +503,17 @@ primitiveTransformRectInto(void) dstOop = stackValue(0); srcOop = stackValue(1); - matrix1 = stackValue(2); + matrixSqInt = stackValue(2); + /* begin loadArgumentMatrix: */ - if (!((isWords(matrix1)) - && ((slotSizeOf(matrix1)) == 6))) { + if (!((isWords(matrixSqInt)) + && ((slotSizeOf(matrixSqInt)) == 6))) { primitiveFail(); matrix = null; goto l1; } - matrix = ((float *) (firstIndexableField(matrix1))); - l1: /* end loadArgumentMatrix: */; + matrix = firstIndexableField(matrixSqInt); +l1: /* end loadArgumentMatrix: */; if (!((matrix) && (((fetchClassOf(srcOop)) == (fetchClassOf(dstOop))) && ((isPointers(srcOop)) @@ -513,10 +526,12 @@ primitiveTransformRectInto(void) } originX = m23ArgX; originY = m23ArgY; + /* begin matrix2x3TransformPoint: */ m23ResultX = ((m23ArgX * (matrix[0])) + (m23ArgY * (matrix[1]))) + (matrix[2]); m23ResultY = ((m23ArgX * (matrix[3])) + (m23ArgY * (matrix[4]))) + (matrix[5]); minX = (maxX = m23ResultX); + /* Load bottom-right point */ minY = (maxY = m23ResultY); loadArgumentPoint(fetchPointerofObject(1, srcOop)); @@ -525,26 +540,31 @@ primitiveTransformRectInto(void) } cornerX = m23ArgX; cornerY = m23ArgY; + /* begin matrix2x3TransformPoint: */ m23ResultX = ((m23ArgX * (matrix[0])) + (m23ArgY * (matrix[1]))) + (matrix[2]); m23ResultY = ((m23ArgX * (matrix[3])) + (m23ArgY * (matrix[4]))) + (matrix[5]); minX = ((minX < m23ResultX) ? minX : m23ResultX); maxX = ((maxX < m23ResultX) ? m23ResultX : maxX); minY = ((minY < m23ResultY) ? minY : m23ResultY); + /* Load top-right point */ maxY = ((maxY < m23ResultY) ? m23ResultY : maxY); m23ArgX = cornerX; m23ArgY = originY; + /* begin matrix2x3TransformPoint: */ m23ResultX = ((m23ArgX * (matrix[0])) + (m23ArgY * (matrix[1]))) + (matrix[2]); m23ResultY = ((m23ArgX * (matrix[3])) + (m23ArgY * (matrix[4]))) + (matrix[5]); minX = ((minX < m23ResultX) ? minX : m23ResultX); maxX = ((maxX < m23ResultX) ? m23ResultX : maxX); minY = ((minY < m23ResultY) ? minY : m23ResultY); + /* Load bottom-left point */ maxY = ((maxY < m23ResultY) ? m23ResultY : maxY); m23ArgX = originX; m23ArgY = cornerY; + /* begin matrix2x3TransformPoint: */ m23ResultX = ((m23ArgX * (matrix[0])) + (m23ArgY * (matrix[1]))) + (matrix[2]); m23ResultY = ((m23ArgX * (matrix[3])) + (m23ArgY * (matrix[4]))) + (matrix[5]); @@ -605,12 +625,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -643,8 +662,8 @@ setInterpreter(struct VirtualMachine *anInterpreter) return ok; } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "Matrix2x3Plugin"; diff --git a/src/plugins/ScratchPlugin/ScratchPlugin.c b/src/plugins/ScratchPlugin/ScratchPlugin.c index 00d5299740..ce04cda70c 100644 --- a/src/plugins/ScratchPlugin/ScratchPlugin.c +++ b/src/plugins/ScratchPlugin/ScratchPlugin.c @@ -1,9 +1,9 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - ScratchPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + ScratchPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 */ -static char __buildInfo[] = "ScratchPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f " __DATE__ ; +static char __buildInfo[] = "ScratchPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 " __DATE__ ; #include "config.h" @@ -109,7 +109,7 @@ extern sqInt success(sqInt aBoolean); extern #endif struct VirtualMachine* interpreterProxy; -static const char *moduleName = "ScratchPlugin VMMaker.oscog-eem.3455 " INT_EXT; +static const char *moduleName = "ScratchPlugin VMMaker.oscog-eem.3456 " INT_EXT; /*** Methods ***/ @@ -216,22 +216,24 @@ primitiveBlur(void) inOop = stackValue(2); outOop = stackValue(1); width = stackIntegerValue(0); + /* begin checkedUnsignedIntPtrOf: */ success(isWords(inOop)); if (failed()) { in = 0; goto l1; } - in = ((unsigned int *) (firstIndexableField(inOop))); - l1: /* end checkedUnsignedIntPtrOf: */; + in = firstIndexableField(inOop); +l1: /* end checkedUnsignedIntPtrOf: */; + /* begin checkedUnsignedIntPtrOf: */ success(isWords(outOop)); if (failed()) { out = 0; goto l2; } - out = ((unsigned int *) (firstIndexableField(outOop))); - l2: /* end checkedUnsignedIntPtrOf: */; + out = firstIndexableField(outOop); +l2: /* end checkedUnsignedIntPtrOf: */; sz = stSizeOf(inOop); success((stSizeOf(outOop)) == sz); if (failed()) { @@ -245,7 +247,8 @@ primitiveBlur(void) for (dX = -1; dX <= 1; dX += 1) { /* add 1 when testing in Squeak */ pix = (in[((y + dY) * width) + (x + dX)]) & 0xFFFFFF; - if (!(pix == 0)) { + if (pix) { + /* skip transparent pixels */ rTotal += ((((usqInt)(pix)) >> 16)) & 0xFF; gTotal += ((((usqInt)(pix)) >> 8)) & 0xFF; @@ -254,11 +257,11 @@ primitiveBlur(void) } } } - if (n == 0) { - outPix = 0; + if (n) { + outPix = ((((((usqInt)((rTotal / n)) << 16)))) + (((((usqInt)((gTotal / n)) << 8))))) + (bTotal / n); } else { - outPix = (((((sqInt)((usqInt)((rTotal / n)) << 16)))) + ((((sqInt)((usqInt)((gTotal / n)) << 8))))) + (bTotal / n); + outPix = 0; } out[(y * width) + x] = outPix; } @@ -272,8 +275,8 @@ EXPORT(sqInt) primitiveBrightnessShift(void) { unsigned int b; - int brightness; - sqInt g; + int brightness; + unsigned int g; sqInt hF; sqInt hI; sqInt hue; @@ -288,7 +291,7 @@ primitiveBrightnessShift(void) sqInt p; unsigned int pix; sqInt q; - sqInt r; + unsigned int r; sqInt result; unsigned int saturation; sqInt shift; @@ -300,33 +303,37 @@ primitiveBrightnessShift(void) inOop = stackValue(2); outOop = stackValue(1); shift = stackIntegerValue(0); + /* begin checkedUnsignedIntPtrOf: */ success(isWords(inOop)); if (failed()) { in = 0; goto l1; } - in = ((unsigned int *) (firstIndexableField(inOop))); - l1: /* end checkedUnsignedIntPtrOf: */; + in = firstIndexableField(inOop); +l1: /* end checkedUnsignedIntPtrOf: */; sz = stSizeOf(inOop); + /* begin checkedUnsignedIntPtrOf: */ success(isWords(outOop)); if (failed()) { out = 0; goto l2; } - out = ((unsigned int *) (firstIndexableField(outOop))); - l2: /* end checkedUnsignedIntPtrOf: */; + out = firstIndexableField(outOop); +l2: /* end checkedUnsignedIntPtrOf: */; success((stSizeOf(outOop)) == sz); if (failed()) { return null; } for (i = 0; i < sz; i += 1) { pix = (in[i]) & 0xFFFFFF; - if (!(pix == 0)) { + if (pix) { + /* skip pixel values of 0 (transparent) */ r = ((((usqInt)(pix)) >> 16)) & 0xFF; g = ((((usqInt)(pix)) >> 8)) & 0xFF; + /* find min and max color components */ b = pix & 0xFF; max = (min = r); @@ -342,9 +349,10 @@ primitiveBrightnessShift(void) if (b < min) { min = b; } + /* begin hueFromR:G:B:min:max: */ span = max - min; - if (span == 0) { + if (!span) { hue = 0; goto l3; } @@ -364,13 +372,14 @@ primitiveBrightnessShift(void) goto l3; } hue = result; - l3: /* end hueFromR:G:B:min:max: */; - if (max == 0) { - saturation = 0; +l3: /* end hueFromR:G:B:min:max: */; + if (max) { + saturation = ((max - min) * 1000) / max; } else { - saturation = ((max - min) * 1000) / max; + saturation = 0; } + /* compute new brigthness */ brightness = (max * 1000) / 0xFF; brightness += shift * 10; @@ -380,10 +389,13 @@ primitiveBrightnessShift(void) if (brightness < 0) { brightness = 0; } + /* begin bitmap:at:putH:s:v: */ outPix = 0; + /* integer part of hue (0..5) */ hI = hue / 60; + /* fractional part ofhue */ hF = hue % 60; p = (1000 - saturation) * brightness; @@ -394,24 +406,24 @@ primitiveBrightnessShift(void) q = q / 3922; t = t / 3922; if (0 == hI) { - outPix = (((((sqInt)((usqInt)(v) << 16)))) + ((((sqInt)((usqInt)(t) << 8))))) + p; + outPix = ((((((usqInt)(v) << 16)))) + (((((usqInt)(t) << 8))))) + p; } if (1 == hI) { - outPix = (((((sqInt)((usqInt)(q) << 16)))) + ((((sqInt)((usqInt)(v) << 8))))) + p; + outPix = ((((((usqInt)(q) << 16)))) + (((((usqInt)(v) << 8))))) + p; } if (2 == hI) { - outPix = (((((sqInt)((usqInt)(p) << 16)))) + ((((sqInt)((usqInt)(v) << 8))))) + t; + outPix = ((((((usqInt)(p) << 16)))) + (((((usqInt)(v) << 8))))) + t; } if (3 == hI) { - outPix = (((((sqInt)((usqInt)(p) << 16)))) + ((((sqInt)((usqInt)(q) << 8))))) + v; + outPix = ((((((usqInt)(p) << 16)))) + (((((usqInt)(q) << 8))))) + v; } if (4 == hI) { - outPix = (((((sqInt)((usqInt)(t) << 16)))) + ((((sqInt)((usqInt)(p) << 8))))) + v; + outPix = ((((((usqInt)(t) << 16)))) + (((((usqInt)(p) << 8))))) + v; } if (5 == hI) { - outPix = (((((sqInt)((usqInt)(v) << 16)))) + ((((sqInt)((usqInt)(p) << 8))))) + q; + outPix = ((((((usqInt)(v) << 16)))) + (((((usqInt)(p) << 8))))) + q; } - if (outPix == 0) { + if (!outPix) { outPix = 1; } out[i] = outPix; @@ -448,8 +460,8 @@ primitiveCondenseSound(void) if (failed()) { return null; } - src = ((short *) (firstIndexableField(srcOop))); - dst = ((short *) (firstIndexableField(dstOop))); + src = firstIndexableField(srcOop); + dst = firstIndexableField(dstOop); for (i = 1; i <= count; i += 1) { max = 0; for (j = 1; j <= factor; j += 1) { @@ -495,22 +507,24 @@ primitiveDoubleSize(void) outH = stackIntegerValue(2); dstX = stackIntegerValue(1); dstY = stackIntegerValue(0); + /* begin checkedUnsignedIntPtrOf: */ success(isWords(inOop)); if (failed()) { in = ((unsigned int *) 0); goto l1; } - in = ((unsigned int *) (firstIndexableField(inOop))); - l1: /* end checkedUnsignedIntPtrOf: */; + in = firstIndexableField(inOop); +l1: /* end checkedUnsignedIntPtrOf: */; + /* begin checkedUnsignedIntPtrOf: */ success(isWords(outOop)); if (failed()) { out = ((unsigned int *) 0); goto l2; } - out = ((unsigned int *) (firstIndexableField(outOop))); - l2: /* end checkedUnsignedIntPtrOf: */; + out = firstIndexableField(outOop); +l2: /* end checkedUnsignedIntPtrOf: */; success((dstX + (2 * inW)) < outW); success((dstY + (2 * inH)) < outH); if (failed()) { @@ -553,8 +567,8 @@ primitiveExtractChannel(void) if (failed()) { return null; } - src = ((short *) (firstIndexableField(srcOop))); - dst = ((short *) (firstIndexableField(dstOop))); + src = firstIndexableField(srcOop); + dst = firstIndexableField(dstOop); if (rightFlag) { src++; } @@ -571,19 +585,13 @@ primitiveFisheye(void) { double ang; sqInt b; - sqInt b1; - sqInt b2; sqInt bottomPix; sqInt centerX; sqInt centerY; double dx; double dy; sqInt frac1; - sqInt frac11; - sqInt frac12; sqInt g; - sqInt g1; - sqInt g2; sqInt height; unsigned int *in; sqInt index; @@ -593,12 +601,8 @@ primitiveFisheye(void) sqInt pix; sqInt power; double r; - sqInt r1; - sqInt r2; - sqInt r3; sqInt result; - sqInt result1; - sqInt result2; + sqInt rSqInt; double scaledPower; sqInt srcX; sqInt srcY; @@ -606,32 +610,34 @@ primitiveFisheye(void) sqInt topPix; sqInt width; sqInt x; - sqInt x1; - sqInt xFrac; + int xFrac; + sqInt xSqInt; sqInt y; - sqInt y1; - sqInt yFrac; + unsigned int yFrac; + sqInt ySqInt; inOop = stackValue(3); outOop = stackValue(2); width = stackIntegerValue(1); power = stackIntegerValue(0); + /* begin checkedUnsignedIntPtrOf: */ success(isWords(inOop)); if (failed()) { in = 0; goto l1; } - in = ((unsigned int *) (firstIndexableField(inOop))); - l1: /* end checkedUnsignedIntPtrOf: */; + in = firstIndexableField(inOop); +l1: /* end checkedUnsignedIntPtrOf: */; + /* begin checkedUnsignedIntPtrOf: */ success(isWords(outOop)); if (failed()) { out = 0; goto l2; } - out = ((unsigned int *) (firstIndexableField(outOop))); - l2: /* end checkedUnsignedIntPtrOf: */; + out = firstIndexableField(outOop); +l2: /* end checkedUnsignedIntPtrOf: */; sz = stSizeOf(inOop); success((stSizeOf(outOop)) == sz); if (failed()) { @@ -658,104 +664,108 @@ primitiveFisheye(void) srcX = 0x400 * x; srcY = 0x400 * y; } + /* begin interpolatedFrom:x:y:width:height: */ - x1 = (((usqInt)(srcX)) >> 10); - if ((x1 < -1) - || (x1 >= width)) { + xSqInt = (((usqInt)(srcX)) >> 10); + if ((xSqInt < -1) + || (xSqInt >= width)) { pix = 0; goto l5; } - y1 = (((usqInt)(srcY)) >> 10); - if ((y1 < -1) - || (y1 >= height)) { + ySqInt = (((usqInt)(srcY)) >> 10); + if ((ySqInt < -1) + || (ySqInt >= height)) { pix = 0; goto l5; } xFrac = srcX & 0x3FF; - if (x1 == -1) { - x1 = 0; + if (xSqInt == -1) { + xSqInt = 0; xFrac = 0; } - if (x1 == (width - 1)) { + if (xSqInt == (width - 1)) { xFrac = 0; } yFrac = srcY & 0x3FF; - if (y1 == -1) { - y1 = 0; + if (ySqInt == -1) { + ySqInt = 0; yFrac = 0; } - if (y1 == (height - 1)) { + if (ySqInt == (height - 1)) { yFrac = 0; } + /* for squeak: + 1 */ - index = (y1 * width) + x1; + index = (ySqInt * width) + xSqInt; topPix = (in[index]) & 0xFFFFFF; if (xFrac > 0) { /* begin interpolate:and:frac: */ - if (topPix == 0) { + if (!topPix) { topPix = (in[index + 1]) & 0xFFFFFF; goto l3; } - if (((in[index + 1]) & 0xFFFFFF) == 0) { + if (!((in[index + 1]) & 0xFFFFFF)) { goto l3; } frac1 = 0x400 - xFrac; - r3 = ((frac1 * (((((usqInt)(topPix)) >> 16)) & 0xFF)) + (xFrac * (((((usqInt)(((in[index + 1]) & 0xFFFFFF))) >> 16)) & 0xFF))) / 0x400; + rSqInt = ((frac1 * (((((usqInt)(topPix)) >> 16)) & 0xFF)) + (xFrac * (((((usqInt)(((in[index + 1]) & 0xFFFFFF))) >> 16)) & 0xFF))) / 0x400; g = ((frac1 * (((((usqInt)(topPix)) >> 8)) & 0xFF)) + (xFrac * (((((usqInt)(((in[index + 1]) & 0xFFFFFF))) >> 8)) & 0xFF))) / 0x400; b = ((frac1 * (topPix & 0xFF)) + (xFrac * (((in[index + 1]) & 0xFFFFFF) & 0xFF))) / 0x400; - result = (((((sqInt)((usqInt)(r3) << 16)))) + ((((sqInt)((usqInt)(g) << 8))))) + b; - if (result == 0) { + result = ((((((usqInt)(rSqInt) << 16)))) + (((((usqInt)(g) << 8))))) + b; + if (!result) { result = 1; } topPix = result; - l3: /* end interpolate:and:frac: */; +l3: /* end interpolate:and:frac: */; } - if (yFrac == 0) { + if (!yFrac) { pix = topPix; goto l5; } + /* for squeak: + 1 */ - index = ((y1 + 1) * width) + x1; + index = ((ySqInt + 1) * width) + xSqInt; bottomPix = (in[index]) & 0xFFFFFF; if (xFrac > 0) { /* begin interpolate:and:frac: */ - if (bottomPix == 0) { + if (!bottomPix) { bottomPix = (in[index + 1]) & 0xFFFFFF; goto l4; } - if (((in[index + 1]) & 0xFFFFFF) == 0) { + if (!((in[index + 1]) & 0xFFFFFF)) { goto l4; } - frac11 = 0x400 - xFrac; - r1 = ((frac11 * (((((usqInt)(bottomPix)) >> 16)) & 0xFF)) + (xFrac * (((((usqInt)(((in[index + 1]) & 0xFFFFFF))) >> 16)) & 0xFF))) / 0x400; - g1 = ((frac11 * (((((usqInt)(bottomPix)) >> 8)) & 0xFF)) + (xFrac * (((((usqInt)(((in[index + 1]) & 0xFFFFFF))) >> 8)) & 0xFF))) / 0x400; - b1 = ((frac11 * (bottomPix & 0xFF)) + (xFrac * (((in[index + 1]) & 0xFFFFFF) & 0xFF))) / 0x400; - result1 = (((((sqInt)((usqInt)(r1) << 16)))) + ((((sqInt)((usqInt)(g1) << 8))))) + b1; - if (result1 == 0) { - result1 = 1; + frac1 = 0x400 - xFrac; + rSqInt = ((frac1 * (((((usqInt)(bottomPix)) >> 16)) & 0xFF)) + (xFrac * (((((usqInt)(((in[index + 1]) & 0xFFFFFF))) >> 16)) & 0xFF))) / 0x400; + g = ((frac1 * (((((usqInt)(bottomPix)) >> 8)) & 0xFF)) + (xFrac * (((((usqInt)(((in[index + 1]) & 0xFFFFFF))) >> 8)) & 0xFF))) / 0x400; + b = ((frac1 * (bottomPix & 0xFF)) + (xFrac * (((in[index + 1]) & 0xFFFFFF) & 0xFF))) / 0x400; + result = ((((((usqInt)(rSqInt) << 16)))) + (((((usqInt)(g) << 8))))) + b; + if (!result) { + result = 1; } - bottomPix = result1; - l4: /* end interpolate:and:frac: */; + bottomPix = result; +l4: /* end interpolate:and:frac: */; } + /* begin interpolate:and:frac: */ - if (topPix == 0) { + if (!topPix) { pix = bottomPix; goto l5; } - if (bottomPix == 0) { + if (!bottomPix) { pix = topPix; goto l5; } - frac12 = 0x400 - yFrac; - r2 = ((frac12 * (((((usqInt)(topPix)) >> 16)) & 0xFF)) + (yFrac * (((((usqInt)(bottomPix)) >> 16)) & 0xFF))) / 0x400; - g2 = ((frac12 * (((((usqInt)(topPix)) >> 8)) & 0xFF)) + (yFrac * (((((usqInt)(bottomPix)) >> 8)) & 0xFF))) / 0x400; - b2 = ((frac12 * (topPix & 0xFF)) + (yFrac * (bottomPix & 0xFF))) / 0x400; - result2 = (((((sqInt)((usqInt)(r2) << 16)))) + ((((sqInt)((usqInt)(g2) << 8))))) + b2; - if (result2 == 0) { - result2 = 1; + frac1 = 0x400 - yFrac; + rSqInt = ((frac1 * (((((usqInt)(topPix)) >> 16)) & 0xFF)) + (yFrac * (((((usqInt)(bottomPix)) >> 16)) & 0xFF))) / 0x400; + g = ((frac1 * (((((usqInt)(topPix)) >> 8)) & 0xFF)) + (yFrac * (((((usqInt)(bottomPix)) >> 8)) & 0xFF))) / 0x400; + b = ((frac1 * (topPix & 0xFF)) + (yFrac * (bottomPix & 0xFF))) / 0x400; + result = ((((((usqInt)(rSqInt) << 16)))) + (((((usqInt)(g) << 8))))) + b; + if (!result) { + result = 1; } - pix = result2; - l5: /* end interpolatedFrom:x:y:width:height: */; + pix = result; +l5: /* end interpolatedFrom:x:y:width:height: */; out[(y * width) + x] = pix; } } @@ -786,7 +796,7 @@ primitiveGetFolderPath(void) GetFolderPathForID(folderID, nameStr, 2000); count = strlen(nameStr); resultOop = instantiateClassindexableSize(classString(), count); - dst = ((char *) (firstIndexableField(resultOop))); + dst = firstIndexableField(resultOop); for (i = 0; i < count; i += 1) { dst[i] = (nameStr[i]); } @@ -798,23 +808,22 @@ primitiveGetFolderPath(void) EXPORT(sqInt) primitiveHalfSizeAverage(void) { - int b; + unsigned int b; sqInt dstH; sqInt dstIndex; sqInt dstW; sqInt dstX; sqInt dstY; - int g; + unsigned int g; int *in; sqInt inH; sqInt inW; sqInt oop; - sqInt oop1; int *out; sqInt outH; sqInt outW; int pixel; - int r; + unsigned int r; sqInt srcIndex; sqInt srcX; sqInt srcY; @@ -822,25 +831,27 @@ primitiveHalfSizeAverage(void) sqInt y; oop = stackValue(11); + /* begin checkedUnsignedIntPtrOf: */ success(isWords(oop)); if (failed()) { in = ((unsigned int *) 0); goto l1; } - in = ((unsigned int *) (firstIndexableField(oop))); - l1: /* end checkedUnsignedIntPtrOf: */; + in = firstIndexableField(oop); +l1: /* end checkedUnsignedIntPtrOf: */; inW = stackIntegerValue(10); inH = stackIntegerValue(9); - oop1 = stackValue(8); + oop = stackValue(8); + /* begin checkedUnsignedIntPtrOf: */ - success(isWords(oop1)); + success(isWords(oop)); if (failed()) { out = ((unsigned int *) 0); goto l2; } - out = ((unsigned int *) (firstIndexableField(oop1))); - l2: /* end checkedUnsignedIntPtrOf: */; + out = firstIndexableField(oop); +l2: /* end checkedUnsignedIntPtrOf: */; outW = stackIntegerValue(7); outH = stackIntegerValue(6); srcX = stackIntegerValue(5); @@ -877,6 +888,7 @@ primitiveHalfSizeAverage(void) pixel = in[(srcIndex + inW) + 1]; r += pixel & 0xFF0000; g += pixel & 0xFF00; + /* store combined RGB into target bitmap */ b += pixel & 0xFF; out[dstIndex] = ((((((usqInt)(r)) >> 2)) & 0xFF0000) | ((((((usqInt)(g)) >> 2)) & 0xFF00) | ((((usqInt)(b)) >> 2)))); @@ -898,18 +910,17 @@ primitiveHalfSizeDiagonal(void) sqInt dstW; sqInt dstX; sqInt dstY; - sqInt g; + unsigned int g; int *in; sqInt inH; sqInt inW; sqInt oop; - sqInt oop1; int *out; sqInt outH; sqInt outW; int p1; int p2; - sqInt r; + unsigned int r; sqInt srcIndex; sqInt srcX; sqInt srcY; @@ -917,25 +928,27 @@ primitiveHalfSizeDiagonal(void) sqInt y; oop = stackValue(11); + /* begin checkedUnsignedIntPtrOf: */ success(isWords(oop)); if (failed()) { in = ((unsigned int *) 0); goto l1; } - in = ((unsigned int *) (firstIndexableField(oop))); - l1: /* end checkedUnsignedIntPtrOf: */; + in = firstIndexableField(oop); +l1: /* end checkedUnsignedIntPtrOf: */; inW = stackIntegerValue(10); inH = stackIntegerValue(9); - oop1 = stackValue(8); + oop = stackValue(8); + /* begin checkedUnsignedIntPtrOf: */ - success(isWords(oop1)); + success(isWords(oop)); if (failed()) { out = ((unsigned int *) 0); goto l2; } - out = ((unsigned int *) (firstIndexableField(oop1))); - l2: /* end checkedUnsignedIntPtrOf: */; + out = firstIndexableField(oop); +l2: /* end checkedUnsignedIntPtrOf: */; outW = stackIntegerValue(7); outH = stackIntegerValue(6); srcX = stackIntegerValue(5); @@ -961,6 +974,7 @@ primitiveHalfSizeDiagonal(void) p2 = in[(srcIndex + inW) + 1]; r = ((((usqInt)(((p1 & 0xFF0000) + (p2 & 0xFF0000)))) >> 1)) & 0xFF0000; g = ((((usqInt)(((p1 & 0xFF00) + (p2 & 0xFF00)))) >> 1)) & 0xFF00; + /* store combined RGB into target bitmap */ b = (((usqInt)(((p1 & 0xFF) + (p2 & 0xFF)))) >> 1); out[dstIndex] = (r | (g | b)); @@ -978,7 +992,7 @@ primitiveHueShift(void) { unsigned int b; unsigned int brightness; - sqInt g; + unsigned int g; sqInt hF; sqInt hI; sqInt hue; @@ -993,7 +1007,7 @@ primitiveHueShift(void) sqInt p; unsigned int pix; sqInt q; - sqInt r; + unsigned int r; sqInt result; unsigned int saturation; sqInt shift; @@ -1005,33 +1019,37 @@ primitiveHueShift(void) inOop = stackValue(2); outOop = stackValue(1); shift = stackIntegerValue(0); + /* begin checkedUnsignedIntPtrOf: */ success(isWords(inOop)); if (failed()) { in = 0; goto l1; } - in = ((unsigned int *) (firstIndexableField(inOop))); - l1: /* end checkedUnsignedIntPtrOf: */; + in = firstIndexableField(inOop); +l1: /* end checkedUnsignedIntPtrOf: */; sz = stSizeOf(inOop); + /* begin checkedUnsignedIntPtrOf: */ success(isWords(outOop)); if (failed()) { out = 0; goto l2; } - out = ((unsigned int *) (firstIndexableField(outOop))); - l2: /* end checkedUnsignedIntPtrOf: */; + out = firstIndexableField(outOop); +l2: /* end checkedUnsignedIntPtrOf: */; success((stSizeOf(outOop)) == sz); if (failed()) { return null; } for (i = 0; i < sz; i += 1) { pix = (in[i]) & 0xFFFFFF; - if (!(pix == 0)) { + if (pix) { + /* skip pixel values of 0 (transparent) */ r = ((((usqInt)(pix)) >> 16)) & 0xFF; g = ((((usqInt)(pix)) >> 8)) & 0xFF; + /* find min and max color components */ b = pix & 0xFF; max = (min = r); @@ -1048,13 +1066,14 @@ primitiveHueShift(void) min = b; } brightness = (max * 1000) / 0xFF; - if (max == 0) { - saturation = 0; + if (max) { + saturation = ((max - min) * 1000) / max; } else { - saturation = ((max - min) * 1000) / max; + saturation = 0; } if (brightness < 110) { + /* force black to a very dark, saturated gray */ brightness = 110; saturation = 1000; @@ -1063,13 +1082,14 @@ primitiveHueShift(void) saturation = 90; } if ((brightness == 110) || (saturation == 90)) { + /* tint all blacks and grays the same */ hue = 0; } else { /* begin hueFromR:G:B:min:max: */ span = max - min; - if (span == 0) { + if (!span) { hue = 0; goto l3; } @@ -1089,14 +1109,18 @@ primitiveHueShift(void) goto l3; } hue = result; - l3: /* end hueFromR:G:B:min:max: */; +l3: /* end hueFromR:G:B:min:max: */; } + /* compute new hue */ hue = ((hue + shift) + 360000000) % 360; + /* begin bitmap:at:putH:s:v: */ outPix = 0; + /* integer part of hue (0..5) */ hI = hue / 60; + /* fractional part ofhue */ hF = hue % 60; p = (1000 - saturation) * brightness; @@ -1107,24 +1131,24 @@ primitiveHueShift(void) q = q / 3922; t = t / 3922; if (0 == hI) { - outPix = (((((sqInt)((usqInt)(v) << 16)))) + ((((sqInt)((usqInt)(t) << 8))))) + p; + outPix = ((((((usqInt)(v) << 16)))) + (((((usqInt)(t) << 8))))) + p; } if (1 == hI) { - outPix = (((((sqInt)((usqInt)(q) << 16)))) + ((((sqInt)((usqInt)(v) << 8))))) + p; + outPix = ((((((usqInt)(q) << 16)))) + (((((usqInt)(v) << 8))))) + p; } if (2 == hI) { - outPix = (((((sqInt)((usqInt)(p) << 16)))) + ((((sqInt)((usqInt)(v) << 8))))) + t; + outPix = ((((((usqInt)(p) << 16)))) + (((((usqInt)(v) << 8))))) + t; } if (3 == hI) { - outPix = (((((sqInt)((usqInt)(p) << 16)))) + ((((sqInt)((usqInt)(q) << 8))))) + v; + outPix = ((((((usqInt)(p) << 16)))) + (((((usqInt)(q) << 8))))) + v; } if (4 == hI) { - outPix = (((((sqInt)((usqInt)(t) << 16)))) + ((((sqInt)((usqInt)(p) << 8))))) + v; + outPix = ((((((usqInt)(t) << 16)))) + (((((usqInt)(p) << 8))))) + v; } if (5 == hI) { - outPix = (((((sqInt)((usqInt)(v) << 16)))) + ((((sqInt)((usqInt)(p) << 8))))) + q; + outPix = ((((((usqInt)(v) << 16)))) + (((((usqInt)(p) << 8))))) + q; } - if (outPix == 0) { + if (!outPix) { outPix = 1; } out[i] = outPix; @@ -1139,51 +1163,43 @@ EXPORT(sqInt) primitiveInterpolate(void) { sqInt b; - sqInt b1; - sqInt b2; sqInt bottomPix; sqInt frac1; - sqInt frac11; - sqInt frac12; sqInt g; - sqInt g1; - sqInt g2; unsigned int *in; sqInt index; sqInt inOop; sqInt r; - sqInt r1; - sqInt r2; sqInt result; - sqInt result1; - sqInt result2; - sqInt result3; + sqInt resultSqInt; sqInt sz; sqInt topPix; sqInt width; sqInt x; sqInt xFixed; - sqInt xFrac; + int xFrac; sqInt y; sqInt yFixed; - sqInt yFrac; + unsigned int yFrac; inOop = stackValue(3); width = stackIntegerValue(2); xFixed = stackIntegerValue(1); yFixed = stackIntegerValue(0); + /* begin checkedUnsignedIntPtrOf: */ success(isWords(inOop)); if (failed()) { in = 0; goto l1; } - in = ((unsigned int *) (firstIndexableField(inOop))); - l1: /* end checkedUnsignedIntPtrOf: */; + in = firstIndexableField(inOop); +l1: /* end checkedUnsignedIntPtrOf: */; sz = stSizeOf(inOop); if (failed()) { return null; } + /* begin interpolatedFrom:x:y:width:height: */ x = (((usqInt)(xFixed)) >> 10); if ((x < -1) @@ -1213,75 +1229,78 @@ primitiveInterpolate(void) if (y == ((sz / width) - 1)) { yFrac = 0; } + /* for squeak: + 1 */ index = (y * width) + x; topPix = (in[index]) & 0xFFFFFF; if (xFrac > 0) { /* begin interpolate:and:frac: */ - if (topPix == 0) { + if (!topPix) { topPix = (in[index + 1]) & 0xFFFFFF; goto l3; } - if (((in[index + 1]) & 0xFFFFFF) == 0) { + if (!((in[index + 1]) & 0xFFFFFF)) { goto l3; } frac1 = 0x400 - xFrac; r = ((frac1 * (((((usqInt)(topPix)) >> 16)) & 0xFF)) + (xFrac * (((((usqInt)(((in[index + 1]) & 0xFFFFFF))) >> 16)) & 0xFF))) / 0x400; g = ((frac1 * (((((usqInt)(topPix)) >> 8)) & 0xFF)) + (xFrac * (((((usqInt)(((in[index + 1]) & 0xFFFFFF))) >> 8)) & 0xFF))) / 0x400; b = ((frac1 * (topPix & 0xFF)) + (xFrac * (((in[index + 1]) & 0xFFFFFF) & 0xFF))) / 0x400; - result3 = (((((sqInt)((usqInt)(r) << 16)))) + ((((sqInt)((usqInt)(g) << 8))))) + b; - if (result3 == 0) { - result3 = 1; + resultSqInt = ((((((usqInt)(r) << 16)))) + (((((usqInt)(g) << 8))))) + b; + if (!resultSqInt) { + resultSqInt = 1; } - topPix = result3; - l3: /* end interpolate:and:frac: */; + topPix = resultSqInt; +l3: /* end interpolate:and:frac: */; } - if (yFrac == 0) { + if (!yFrac) { result = topPix; goto l4; } + /* for squeak: + 1 */ index = ((y + 1) * width) + x; bottomPix = (in[index]) & 0xFFFFFF; if (xFrac > 0) { /* begin interpolate:and:frac: */ - if (bottomPix == 0) { + if (!bottomPix) { bottomPix = (in[index + 1]) & 0xFFFFFF; goto l2; } - if (((in[index + 1]) & 0xFFFFFF) == 0) { + if (!((in[index + 1]) & 0xFFFFFF)) { goto l2; } - frac11 = 0x400 - xFrac; - r1 = ((frac11 * (((((usqInt)(bottomPix)) >> 16)) & 0xFF)) + (xFrac * (((((usqInt)(((in[index + 1]) & 0xFFFFFF))) >> 16)) & 0xFF))) / 0x400; - g1 = ((frac11 * (((((usqInt)(bottomPix)) >> 8)) & 0xFF)) + (xFrac * (((((usqInt)(((in[index + 1]) & 0xFFFFFF))) >> 8)) & 0xFF))) / 0x400; - b1 = ((frac11 * (bottomPix & 0xFF)) + (xFrac * (((in[index + 1]) & 0xFFFFFF) & 0xFF))) / 0x400; - result1 = (((((sqInt)((usqInt)(r1) << 16)))) + ((((sqInt)((usqInt)(g1) << 8))))) + b1; - if (result1 == 0) { - result1 = 1; + frac1 = 0x400 - xFrac; + r = ((frac1 * (((((usqInt)(bottomPix)) >> 16)) & 0xFF)) + (xFrac * (((((usqInt)(((in[index + 1]) & 0xFFFFFF))) >> 16)) & 0xFF))) / 0x400; + g = ((frac1 * (((((usqInt)(bottomPix)) >> 8)) & 0xFF)) + (xFrac * (((((usqInt)(((in[index + 1]) & 0xFFFFFF))) >> 8)) & 0xFF))) / 0x400; + b = ((frac1 * (bottomPix & 0xFF)) + (xFrac * (((in[index + 1]) & 0xFFFFFF) & 0xFF))) / 0x400; + resultSqInt = ((((((usqInt)(r) << 16)))) + (((((usqInt)(g) << 8))))) + b; + if (!resultSqInt) { + resultSqInt = 1; } - bottomPix = result1; - l2: /* end interpolate:and:frac: */; + bottomPix = resultSqInt; +l2: /* end interpolate:and:frac: */; } + /* begin interpolate:and:frac: */ - if (topPix == 0) { + if (!topPix) { result = bottomPix; goto l4; } - if (bottomPix == 0) { + if (!bottomPix) { result = topPix; goto l4; } - frac12 = 0x400 - yFrac; - r2 = ((frac12 * (((((usqInt)(topPix)) >> 16)) & 0xFF)) + (yFrac * (((((usqInt)(bottomPix)) >> 16)) & 0xFF))) / 0x400; - g2 = ((frac12 * (((((usqInt)(topPix)) >> 8)) & 0xFF)) + (yFrac * (((((usqInt)(bottomPix)) >> 8)) & 0xFF))) / 0x400; - b2 = ((frac12 * (topPix & 0xFF)) + (yFrac * (bottomPix & 0xFF))) / 0x400; - result2 = (((((sqInt)((usqInt)(r2) << 16)))) + ((((sqInt)((usqInt)(g2) << 8))))) + b2; - if (result2 == 0) { - result2 = 1; + frac1 = 0x400 - yFrac; + r = ((frac1 * (((((usqInt)(topPix)) >> 16)) & 0xFF)) + (yFrac * (((((usqInt)(bottomPix)) >> 16)) & 0xFF))) / 0x400; + g = ((frac1 * (((((usqInt)(topPix)) >> 8)) & 0xFF)) + (yFrac * (((((usqInt)(bottomPix)) >> 8)) & 0xFF))) / 0x400; + b = ((frac1 * (topPix & 0xFF)) + (yFrac * (bottomPix & 0xFF))) / 0x400; + resultSqInt = ((((((usqInt)(r) << 16)))) + (((((usqInt)(g) << 8))))) + b; + if (!resultSqInt) { + resultSqInt = 1; } - result = result2; - l4: /* end interpolatedFrom:x:y:width:height: */; + result = resultSqInt; +l4: /* end interpolatedFrom:x:y:width:height: */; pop(5); pushInteger(result); return 0; @@ -1309,7 +1328,7 @@ primitiveIsHidden(void) if (failed()) { return 0; } - src = ((char *) (firstIndexableField(pathOop))); + src = firstIndexableField(pathOop); count = stSizeOf(pathOop); if (count >= 1000) { success(0); @@ -1343,7 +1362,7 @@ primitiveOpenURL(void) if (failed()) { return 0; } - src = ((char *) (firstIndexableField(urlOop))); + src = firstIndexableField(urlOop); count = stSizeOf(urlOop); if (count >= 2000) { success(0); @@ -1364,7 +1383,7 @@ primitiveSaturationShift(void) { unsigned int b; unsigned int brightness; - sqInt g; + unsigned int g; sqInt hF; sqInt hI; sqInt hue; @@ -1379,9 +1398,9 @@ primitiveSaturationShift(void) sqInt p; unsigned int pix; sqInt q; - sqInt r; + unsigned int r; sqInt result; - int saturation; + int saturation; sqInt shift; sqInt span; sqInt sz; @@ -1391,23 +1410,25 @@ primitiveSaturationShift(void) inOop = stackValue(2); outOop = stackValue(1); shift = stackIntegerValue(0); + /* begin checkedUnsignedIntPtrOf: */ success(isWords(inOop)); if (failed()) { in = 0; goto l1; } - in = ((unsigned int *) (firstIndexableField(inOop))); - l1: /* end checkedUnsignedIntPtrOf: */; + in = firstIndexableField(inOop); +l1: /* end checkedUnsignedIntPtrOf: */; sz = stSizeOf(inOop); + /* begin checkedUnsignedIntPtrOf: */ success(isWords(outOop)); if (failed()) { out = 0; goto l2; } - out = ((unsigned int *) (firstIndexableField(outOop))); - l2: /* end checkedUnsignedIntPtrOf: */; + out = firstIndexableField(outOop); +l2: /* end checkedUnsignedIntPtrOf: */; success((stSizeOf(outOop)) == sz); if (failed()) { return null; @@ -1415,9 +1436,11 @@ primitiveSaturationShift(void) for (i = 0; i < sz; i += 1) { pix = (in[i]) & 0xFFFFFF; if (!(pix < 2)) { + /* skip pixel values of 0 (transparent) and 1 (black) */ r = ((((usqInt)(pix)) >> 16)) & 0xFF; g = ((((usqInt)(pix)) >> 8)) & 0xFF; + /* find min and max color components */ b = pix & 0xFF; max = (min = r); @@ -1434,17 +1457,18 @@ primitiveSaturationShift(void) min = b; } brightness = (max * 1000) / 0xFF; - if (max == 0) { - saturation = 0; + if (max) { + saturation = ((max - min) * 1000) / max; } else { - saturation = ((max - min) * 1000) / max; + saturation = 0; } if (saturation > 0) { + /* do nothing if pixel is unsaturated (gray) */ /* begin hueFromR:G:B:min:max: */ span = max - min; - if (span == 0) { + if (!span) { hue = 0; goto l3; } @@ -1464,7 +1488,7 @@ primitiveSaturationShift(void) goto l3; } hue = result; - l3: /* end hueFromR:G:B:min:max: */; +l3: /* end hueFromR:G:B:min:max: */; saturation += shift * 10; if (saturation > 1000) { saturation = 1000; @@ -1472,10 +1496,13 @@ primitiveSaturationShift(void) if (saturation < 0) { saturation = 0; } + /* begin bitmap:at:putH:s:v: */ outPix = 0; + /* integer part of hue (0..5) */ hI = hue / 60; + /* fractional part ofhue */ hF = hue % 60; p = (1000 - saturation) * brightness; @@ -1486,24 +1513,24 @@ primitiveSaturationShift(void) q = q / 3922; t = t / 3922; if (0 == hI) { - outPix = (((((sqInt)((usqInt)(v) << 16)))) + ((((sqInt)((usqInt)(t) << 8))))) + p; + outPix = ((((((usqInt)(v) << 16)))) + (((((usqInt)(t) << 8))))) + p; } if (1 == hI) { - outPix = (((((sqInt)((usqInt)(q) << 16)))) + ((((sqInt)((usqInt)(v) << 8))))) + p; + outPix = ((((((usqInt)(q) << 16)))) + (((((usqInt)(v) << 8))))) + p; } if (2 == hI) { - outPix = (((((sqInt)((usqInt)(p) << 16)))) + ((((sqInt)((usqInt)(v) << 8))))) + t; + outPix = ((((((usqInt)(p) << 16)))) + (((((usqInt)(v) << 8))))) + t; } if (3 == hI) { - outPix = (((((sqInt)((usqInt)(p) << 16)))) + ((((sqInt)((usqInt)(q) << 8))))) + v; + outPix = ((((((usqInt)(p) << 16)))) + (((((usqInt)(q) << 8))))) + v; } if (4 == hI) { - outPix = (((((sqInt)((usqInt)(t) << 16)))) + ((((sqInt)((usqInt)(p) << 8))))) + v; + outPix = ((((((usqInt)(t) << 16)))) + (((((usqInt)(p) << 8))))) + v; } if (5 == hI) { - outPix = (((((sqInt)((usqInt)(v) << 16)))) + ((((sqInt)((usqInt)(p) << 8))))) + q; + outPix = ((((((usqInt)(v) << 16)))) + (((((usqInt)(p) << 8))))) + q; } - if (outPix == 0) { + if (!outPix) { outPix = 1; } out[i] = outPix; @@ -1535,7 +1562,7 @@ primitiveScale(void) int *out; sqInt outH; sqInt outOop; - sqInt outPix; + usqInt outPix; sqInt outW; sqInt outX; sqInt outY; @@ -1545,10 +1572,10 @@ primitiveScale(void) int p4; sqInt t; sqInt tWeight; - sqInt w1; - sqInt w2; - sqInt w3; - sqInt w4; + int w1; + unsigned int w2; + unsigned int w3; + unsigned int w4; sqInt xIncr; sqInt yIncr; @@ -1560,38 +1587,45 @@ primitiveScale(void) outH = stackIntegerValue(0); success((stSizeOf(inOop)) == (inW * inH)); success((stSizeOf(outOop)) == (outW * outH)); + /* begin checkedUnsignedIntPtrOf: */ success(isWords(inOop)); if (failed()) { in = ((unsigned int *) 0); goto l1; } - in = ((unsigned int *) (firstIndexableField(inOop))); - l1: /* end checkedUnsignedIntPtrOf: */; + in = firstIndexableField(inOop); +l1: /* end checkedUnsignedIntPtrOf: */; + /* begin checkedUnsignedIntPtrOf: */ success(isWords(outOop)); if (failed()) { out = ((unsigned int *) 0); goto l2; } - out = ((unsigned int *) (firstIndexableField(outOop))); - l2: /* end checkedUnsignedIntPtrOf: */; + out = firstIndexableField(outOop); +l2: /* end checkedUnsignedIntPtrOf: */; if (failed()) { return null; } + /* source x and y, scaled by 1024 */ inX = (inY = 0); + /* source x increment, scaled by 1024 */ xIncr = (inW * 0x400) / outW; + /* source y increment, scaled by 1024 */ yIncr = (inH * 0x400) / outH; for (outY = 0; outY < outH; outY += 1) { inX = 0; for (outX = 0; outX < outW; outX += 1) { + /* compute weights, scaled by 2^20 */ w1 = (0x400 - (inX & 0x3FF)) * (0x400 - (inY & 0x3FF)); w2 = (inX & 0x3FF) * (0x400 - (inY & 0x3FF)); w3 = (0x400 - (inX & 0x3FF)) * (inY & 0x3FF); + /* get source pixels */ w4 = (inX & 0x3FF) * (inY & 0x3FF); t = ((((usqInt)(inY)) >> 10) * inW) + (((usqInt)(inX)) >> 10); @@ -1613,41 +1647,43 @@ primitiveScale(void) p4 = p3; } tWeight = 0; - if (p1 == 0) { + if (!p1) { p1 = p2; tWeight += w1; } - if (p2 == 0) { + if (!p2) { p2 = p1; tWeight += w2; } - if (p3 == 0) { + if (!p3) { p3 = p4; tWeight += w3; } - if (p4 == 0) { + if (!p4) { p4 = p3; tWeight += w4; } - if (p1 == 0) { + if (!p1) { p1 = p3; p2 = p4; } - if (p3 == 0) { + if (!p3) { p3 = p1; p4 = p2; } outPix = 0; if (tWeight < 500000) { + /* compute an (opaque) output pixel if less than 50% transparent */ t = (((w1 * ((((usqInt)(p1)) >> 16) & 0xFF)) + (w2 * ((((usqInt)(p2)) >> 16) & 0xFF))) + (w3 * ((((usqInt)(p3)) >> 16) & 0xFF))) + (w4 * ((((usqInt)(p4)) >> 16) & 0xFF)); - outPix = ((sqInt)((usqInt)(((((usqInt)(t)) >> 20) & 0xFF)) << 16)); + outPix = (((usqInt)(((((usqInt)(t)) >> 20) & 0xFF)) << 16)); t = (((w1 * ((((usqInt)(p1)) >> 8) & 0xFF)) + (w2 * ((((usqInt)(p2)) >> 8) & 0xFF))) + (w3 * ((((usqInt)(p3)) >> 8) & 0xFF))) + (w4 * ((((usqInt)(p4)) >> 8) & 0xFF)); - outPix = outPix | (((sqInt)((usqInt)(((((usqInt)(t)) >> 20) & 0xFF)) << 8))); + outPix = outPix | ((((usqInt)(((((usqInt)(t)) >> 20) & 0xFF)) << 8))); t = (((w1 * (p1 & 0xFF)) + (w2 * (p2 & 0xFF))) + (w3 * (p3 & 0xFF))) + (w4 * (p4 & 0xFF)); + /* If the result is black, remember to make it Squeak-standard-fake-black */ outPix = outPix | ((((usqInt)(t)) >> 20) & 0xFF); - if (outPix == 0) { + if (!outPix) { outPix = 1; } outPix = outPix | 0xFF000000U; @@ -1677,7 +1713,7 @@ primitiveSetUnicodePasteBuffer(void) if (failed()) { return 0; } - utf16 = ((short *) (firstIndexableField(strOop))); + utf16 = firstIndexableField(strOop); count = stSizeOf(strOop); SetUnicodePasteBuffer(utf16, count); pop(1); @@ -1702,7 +1738,7 @@ primitiveSetWindowTitle(void) if (failed()) { return 0; } - src = ((char *) (firstIndexableField(titleOop))); + src = firstIndexableField(titleOop); count = stSizeOf(titleOop); if (count >= 1000) { success(0); @@ -1740,7 +1776,7 @@ primitiveShortToLongPath(void) success(0); return 0; } - ptr = ((char *) (firstIndexableField(shortPathOop))); + ptr = firstIndexableField(shortPathOop); count = stSizeOf(shortPathOop); if (count >= 1000) { success(0); @@ -1757,7 +1793,7 @@ primitiveShortToLongPath(void) } count = strlen(longPath); resultOop = instantiateClassindexableSize(classString(), count); - ptr = ((char *) (firstIndexableField(resultOop))); + ptr = firstIndexableField(resultOop); for (i = 0; i < count; i += 1) { ptr[i] = (longPath[i]); } @@ -1808,42 +1844,46 @@ primitiveWaterRipples1(void) inOop = stackValue(5); outOop = stackValue(4); width = stackIntegerValue(3); + /* begin checkedUnsignedIntPtrOf: */ success(isWords(inOop)); if (failed()) { in = 0; goto l1; } - in = ((unsigned int *) (firstIndexableField(inOop))); - l1: /* end checkedUnsignedIntPtrOf: */; + in = firstIndexableField(inOop); +l1: /* end checkedUnsignedIntPtrOf: */; + /* begin checkedUnsignedIntPtrOf: */ success(isWords(outOop)); if (failed()) { out = 0; goto l2; } - out = ((unsigned int *) (firstIndexableField(outOop))); - l2: /* end checkedUnsignedIntPtrOf: */; + out = firstIndexableField(outOop); +l2: /* end checkedUnsignedIntPtrOf: */; allPix = stSizeOf(inOop); ripply = stackIntegerValue(2); aArOop = stackValue(1); bArOop = stackValue(0); + /* begin checkedFloatPtrOf: */ success(isWordsOrBytes(aArOop)); if (failed()) { aArray = 0; goto l3; } - aArray = ((double *) (firstIndexableField(aArOop))); - l3: /* end checkedFloatPtrOf: */; + aArray = firstIndexableField(aArOop); +l3: /* end checkedFloatPtrOf: */; + /* begin checkedFloatPtrOf: */ success(isWordsOrBytes(bArOop)); if (failed()) { bArray = 0; goto l4; } - bArray = ((double *) (firstIndexableField(bArOop))); - l4: /* end checkedFloatPtrOf: */; + bArray = firstIndexableField(bArOop); +l4: /* end checkedFloatPtrOf: */; success((stSizeOf(outOop)) == allPix); if (failed()) { return null; @@ -1933,8 +1973,6 @@ primitiveWhirl(void) { double ang; sqInt b; - sqInt b1; - sqInt b2; sqInt bottomPix; sqInt centerX; sqInt centerY; @@ -1945,11 +1983,7 @@ primitiveWhirl(void) double dy; double factor; sqInt frac1; - sqInt frac11; - sqInt frac12; sqInt g; - sqInt g1; - sqInt g2; sqInt height; unsigned int *in; sqInt index; @@ -1958,13 +1992,9 @@ primitiveWhirl(void) sqInt outOop; sqInt pix; sqInt r; - sqInt r1; - sqInt r2; sqInt radius; double radiusSquared; sqInt result; - sqInt result1; - sqInt result2; double scaleX; double scaleY; double sina; @@ -1973,34 +2003,36 @@ primitiveWhirl(void) double whirlRadians; sqInt width; sqInt x; - sqInt x1; sqInt xFixed; - sqInt xFrac; + int xFrac; + sqInt xSqInt; sqInt y; - sqInt y1; sqInt yFixed; - sqInt yFrac; + unsigned int yFrac; + sqInt ySqInt; inOop = stackValue(3); outOop = stackValue(2); width = stackIntegerValue(1); degrees = stackIntegerValue(0); + /* begin checkedUnsignedIntPtrOf: */ success(isWords(inOop)); if (failed()) { in = 0; goto l1; } - in = ((unsigned int *) (firstIndexableField(inOop))); - l1: /* end checkedUnsignedIntPtrOf: */; + in = firstIndexableField(inOop); +l1: /* end checkedUnsignedIntPtrOf: */; + /* begin checkedUnsignedIntPtrOf: */ success(isWords(outOop)); if (failed()) { out = 0; goto l2; } - out = ((unsigned int *) (firstIndexableField(outOop))); - l2: /* end checkedUnsignedIntPtrOf: */; + out = firstIndexableField(outOop); +l2: /* end checkedUnsignedIntPtrOf: */; sz = stSizeOf(inOop); success((stSizeOf(outOop)) == sz); if (failed()) { @@ -2032,6 +2064,7 @@ primitiveWhirl(void) dy = scaleY * (((double) (y - centerY) )); d = (dx * dx) + (dy * dy); if (d < radiusSquared) { + /* inside the whirl circle */ factor = 1.0 - ((sqrt(d)) / radius); ang = whirlRadians * (factor * factor); @@ -2039,104 +2072,108 @@ primitiveWhirl(void) cosa = cos(ang); xFixed = ((sqInt)(1024.0 * ((((cosa * dx) - (sina * dy)) / scaleX) + centerX))); yFixed = ((sqInt)(1024.0 * ((((sina * dx) + (cosa * dy)) / scaleY) + centerY))); + /* begin interpolatedFrom:x:y:width:height: */ - x1 = (((usqInt)(xFixed)) >> 10); - if ((x1 < -1) - || (x1 >= width)) { + xSqInt = (((usqInt)(xFixed)) >> 10); + if ((xSqInt < -1) + || (xSqInt >= width)) { pix = 0; goto l5; } - y1 = (((usqInt)(yFixed)) >> 10); - if ((y1 < -1) - || (y1 >= height)) { + ySqInt = (((usqInt)(yFixed)) >> 10); + if ((ySqInt < -1) + || (ySqInt >= height)) { pix = 0; goto l5; } xFrac = xFixed & 0x3FF; - if (x1 == -1) { - x1 = 0; + if (xSqInt == -1) { + xSqInt = 0; xFrac = 0; } - if (x1 == (width - 1)) { + if (xSqInt == (width - 1)) { xFrac = 0; } yFrac = yFixed & 0x3FF; - if (y1 == -1) { - y1 = 0; + if (ySqInt == -1) { + ySqInt = 0; yFrac = 0; } - if (y1 == (height - 1)) { + if (ySqInt == (height - 1)) { yFrac = 0; } + /* for squeak: + 1 */ - index = (y1 * width) + x1; + index = (ySqInt * width) + xSqInt; topPix = (in[index]) & 0xFFFFFF; if (xFrac > 0) { /* begin interpolate:and:frac: */ - if (topPix == 0) { + if (!topPix) { topPix = (in[index + 1]) & 0xFFFFFF; goto l3; } - if (((in[index + 1]) & 0xFFFFFF) == 0) { + if (!((in[index + 1]) & 0xFFFFFF)) { goto l3; } frac1 = 0x400 - xFrac; r = ((frac1 * (((((usqInt)(topPix)) >> 16)) & 0xFF)) + (xFrac * (((((usqInt)(((in[index + 1]) & 0xFFFFFF))) >> 16)) & 0xFF))) / 0x400; g = ((frac1 * (((((usqInt)(topPix)) >> 8)) & 0xFF)) + (xFrac * (((((usqInt)(((in[index + 1]) & 0xFFFFFF))) >> 8)) & 0xFF))) / 0x400; b = ((frac1 * (topPix & 0xFF)) + (xFrac * (((in[index + 1]) & 0xFFFFFF) & 0xFF))) / 0x400; - result = (((((sqInt)((usqInt)(r) << 16)))) + ((((sqInt)((usqInt)(g) << 8))))) + b; - if (result == 0) { + result = ((((((usqInt)(r) << 16)))) + (((((usqInt)(g) << 8))))) + b; + if (!result) { result = 1; } topPix = result; - l3: /* end interpolate:and:frac: */; +l3: /* end interpolate:and:frac: */; } - if (yFrac == 0) { + if (!yFrac) { pix = topPix; goto l5; } + /* for squeak: + 1 */ - index = ((y1 + 1) * width) + x1; + index = ((ySqInt + 1) * width) + xSqInt; bottomPix = (in[index]) & 0xFFFFFF; if (xFrac > 0) { /* begin interpolate:and:frac: */ - if (bottomPix == 0) { + if (!bottomPix) { bottomPix = (in[index + 1]) & 0xFFFFFF; goto l4; } - if (((in[index + 1]) & 0xFFFFFF) == 0) { + if (!((in[index + 1]) & 0xFFFFFF)) { goto l4; } - frac11 = 0x400 - xFrac; - r1 = ((frac11 * (((((usqInt)(bottomPix)) >> 16)) & 0xFF)) + (xFrac * (((((usqInt)(((in[index + 1]) & 0xFFFFFF))) >> 16)) & 0xFF))) / 0x400; - g1 = ((frac11 * (((((usqInt)(bottomPix)) >> 8)) & 0xFF)) + (xFrac * (((((usqInt)(((in[index + 1]) & 0xFFFFFF))) >> 8)) & 0xFF))) / 0x400; - b1 = ((frac11 * (bottomPix & 0xFF)) + (xFrac * (((in[index + 1]) & 0xFFFFFF) & 0xFF))) / 0x400; - result1 = (((((sqInt)((usqInt)(r1) << 16)))) + ((((sqInt)((usqInt)(g1) << 8))))) + b1; - if (result1 == 0) { - result1 = 1; + frac1 = 0x400 - xFrac; + r = ((frac1 * (((((usqInt)(bottomPix)) >> 16)) & 0xFF)) + (xFrac * (((((usqInt)(((in[index + 1]) & 0xFFFFFF))) >> 16)) & 0xFF))) / 0x400; + g = ((frac1 * (((((usqInt)(bottomPix)) >> 8)) & 0xFF)) + (xFrac * (((((usqInt)(((in[index + 1]) & 0xFFFFFF))) >> 8)) & 0xFF))) / 0x400; + b = ((frac1 * (bottomPix & 0xFF)) + (xFrac * (((in[index + 1]) & 0xFFFFFF) & 0xFF))) / 0x400; + result = ((((((usqInt)(r) << 16)))) + (((((usqInt)(g) << 8))))) + b; + if (!result) { + result = 1; } - bottomPix = result1; - l4: /* end interpolate:and:frac: */; + bottomPix = result; +l4: /* end interpolate:and:frac: */; } + /* begin interpolate:and:frac: */ - if (topPix == 0) { + if (!topPix) { pix = bottomPix; goto l5; } - if (bottomPix == 0) { + if (!bottomPix) { pix = topPix; goto l5; } - frac12 = 0x400 - yFrac; - r2 = ((frac12 * (((((usqInt)(topPix)) >> 16)) & 0xFF)) + (yFrac * (((((usqInt)(bottomPix)) >> 16)) & 0xFF))) / 0x400; - g2 = ((frac12 * (((((usqInt)(topPix)) >> 8)) & 0xFF)) + (yFrac * (((((usqInt)(bottomPix)) >> 8)) & 0xFF))) / 0x400; - b2 = ((frac12 * (topPix & 0xFF)) + (yFrac * (bottomPix & 0xFF))) / 0x400; - result2 = (((((sqInt)((usqInt)(r2) << 16)))) + ((((sqInt)((usqInt)(g2) << 8))))) + b2; - if (result2 == 0) { - result2 = 1; + frac1 = 0x400 - yFrac; + r = ((frac1 * (((((usqInt)(topPix)) >> 16)) & 0xFF)) + (yFrac * (((((usqInt)(bottomPix)) >> 16)) & 0xFF))) / 0x400; + g = ((frac1 * (((((usqInt)(topPix)) >> 8)) & 0xFF)) + (yFrac * (((((usqInt)(bottomPix)) >> 8)) & 0xFF))) / 0x400; + b = ((frac1 * (topPix & 0xFF)) + (yFrac * (bottomPix & 0xFF))) / 0x400; + result = ((((((usqInt)(r) << 16)))) + (((((usqInt)(g) << 8))))) + b; + if (!result) { + result = 1; } - pix = result2; - l5: /* end interpolatedFrom:x:y:width:height: */; + pix = result; +l5: /* end interpolatedFrom:x:y:width:height: */; out[(width * y) + x] = pix; } } @@ -2166,7 +2203,7 @@ primOpenPortNamed(void) if (failed()) { return 0; } - src = ((char *) (firstIndexableField(nameOop))); + src = firstIndexableField(nameOop); count = stSizeOf(nameOop); for (i = 0; i < count; i += 1) { nameStr[i] = (src[i]); @@ -2220,12 +2257,12 @@ primPortName(void) } SerialPortName(portIndex, nameStr, 1000); count = strlen(nameStr); - if (count == 0) { + if (!count) { success(0); return 0; } resultOop = instantiateClassindexableSize(classString(), count); - dst = ((char *) (firstIndexableField(resultOop))); + dst = firstIndexableField(resultOop); for (i = 0; i < count; i += 1) { dst[i] = (nameStr[i]); } @@ -2319,12 +2356,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -2350,8 +2386,8 @@ setInterpreter(struct VirtualMachine *anInterpreter) return ok; } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "ScratchPlugin"; diff --git a/src/plugins/Squeak3D/Squeak3D.c b/src/plugins/Squeak3D/Squeak3D.c index 45c27addf2..1a83272ff6 100644 --- a/src/plugins/Squeak3D/Squeak3D.c +++ b/src/plugins/Squeak3D/Squeak3D.c @@ -1,5 +1,5 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from B3DEnginePlugin Balloon3D-Plugins-eem.23 uuid: dbdf2f40-097a-4885-afd0-569d1dcf0f43 */ @@ -331,7 +331,7 @@ EXPORT(sqInt) b3dClipPolygon(void) { sqInt count; - sqInt count1; + sqInt countSqInt; sqInt outMask; int *tempVtxArray; int *vtxArray; @@ -351,6 +351,7 @@ b3dClipPolygon(void) } vtxArray -= PrimVertexSize; tempVtxArray -= PrimVertexSize; + /* begin clipPolygon:count:with:mask: */ if (outMask == OutLeftBit) { count = clipPolygonLeftFromtocount(tempVtxArray, vtxArray, vtxCount); @@ -376,35 +377,35 @@ b3dClipPolygon(void) count = clipPolygonBackFromtocount(tempVtxArray, vtxArray, vtxCount); goto l1; } - count1 = vtxCount; - count1 = clipPolygonLeftFromtocount(vtxArray, tempVtxArray, count1); - if (count1 == 0) { + countSqInt = vtxCount; + countSqInt = clipPolygonLeftFromtocount(vtxArray, tempVtxArray, countSqInt); + if (!countSqInt) { count = 0; goto l1; } - count1 = clipPolygonRightFromtocount(tempVtxArray, vtxArray, count1); - if (count1 == 0) { + countSqInt = clipPolygonRightFromtocount(tempVtxArray, vtxArray, countSqInt); + if (!countSqInt) { count = 0; goto l1; } - count1 = clipPolygonTopFromtocount(vtxArray, tempVtxArray, count1); - if (count1 == 0) { + countSqInt = clipPolygonTopFromtocount(vtxArray, tempVtxArray, countSqInt); + if (!countSqInt) { count = 0; goto l1; } - count1 = clipPolygonBottomFromtocount(tempVtxArray, vtxArray, count1); - if (count1 == 0) { + countSqInt = clipPolygonBottomFromtocount(tempVtxArray, vtxArray, countSqInt); + if (!countSqInt) { count = 0; goto l1; } - count1 = clipPolygonFrontFromtocount(vtxArray, tempVtxArray, count1); - if (count1 == 0) { + countSqInt = clipPolygonFrontFromtocount(vtxArray, tempVtxArray, countSqInt); + if (!countSqInt) { count = 0; goto l1; } - count1 = clipPolygonBackFromtocount(tempVtxArray, vtxArray, count1); - count = count1; - l1: /* end clipPolygon:count:with:mask: */; + countSqInt = clipPolygonBackFromtocount(tempVtxArray, vtxArray, countSqInt); + count = countSqInt; +l1: /* end clipPolygon:count:with:mask: */; pop(5); pushInteger(count); return 0; @@ -420,24 +421,17 @@ EXPORT(sqInt) b3dComputeMinIndexZ(void) { sqInt i; - sqInt i1; int *idxArray; sqInt idxSize; int index; sqInt minIndex; - sqInt minIndex1; - sqInt minIndex2; double minZ; - double minZ1; sqInt primType; float *vtxArray; float *vtxPtr; - float *vtxPtr1; sqInt vtxSize; double wValue; - double wValue1; double zValue; - double zValue1; if (!((methodArgumentCount()) == 5)) { return primitiveFail(); @@ -462,7 +456,7 @@ b3dComputeMinIndexZ(void) if (primType <= 3) { /* begin processNonIndexedIDX:ofSize: */ minZ = 10.0; - minIndex1 = 0; + minIndex = 0; vtxPtr = vtxArray; for (i = 1; i <= vtxSize; i += 1) { zValue = vtxPtr[PrimVtxRasterPosZ]; @@ -470,35 +464,33 @@ b3dComputeMinIndexZ(void) if (!(wValue == 0.0)) { zValue = zValue / wValue; } - if ((minIndex1 == 0) + if ((minIndex == 0) || (zValue < minZ)) { - minIndex1 = i; + minIndex = i; minZ = zValue; } } - minIndex = minIndex1; } else { /* begin processIndexedIDX:ofSize:idxArray:idxSize: */ - minZ1 = 10.0; - minIndex2 = 0; - for (i1 = 1; i1 <= idxSize; i1 += 1) { - index = idxArray[i1]; + minZ = 10.0; + minIndex = 0; + for (i = 1; i <= idxSize; i += 1) { + index = idxArray[i]; if (index > 0) { - vtxPtr1 = vtxArray + ((index - 1) * PrimVertexSize); - zValue1 = vtxPtr1[PrimVtxRasterPosZ]; - wValue1 = vtxPtr1[PrimVtxRasterPosW]; - if (!(wValue1 == 0.0)) { - zValue1 = zValue1 / wValue1; + vtxPtr = vtxArray + ((index - 1) * PrimVertexSize); + zValue = vtxPtr[PrimVtxRasterPosZ]; + wValue = vtxPtr[PrimVtxRasterPosW]; + if (!(wValue == 0.0)) { + zValue = zValue / wValue; } - if ((minIndex2 == 0) - || (zValue1 < minZ1)) { - minIndex2 = i1; - minZ1 = zValue1; + if ((minIndex == 0) + || (zValue < minZ)) { + minIndex = i; + minZ = zValue; } } } - minIndex = minIndex2; } if (!(failed())) { pop(6); @@ -517,22 +509,16 @@ EXPORT(sqInt) b3dComputeMinZ(void) { sqInt i; - sqInt i1; int *idxArray; sqInt idxSize; int index; double minZ; - double minZ1; - double minZ2; sqInt primType; float *vtxArray; float *vtxPtr; - float *vtxPtr1; sqInt vtxSize; double wValue; - double wValue1; double zValue; - double zValue1; if (!((methodArgumentCount()) == 5)) { return primitiveFail(); @@ -556,7 +542,7 @@ b3dComputeMinZ(void) } if (primType <= 3) { /* begin processNonIndexed:ofSize: */ - minZ1 = 10.0; + minZ = 10.0; vtxPtr = vtxArray; for (i = 1; i <= vtxSize; i += 1) { zValue = vtxPtr[PrimVtxRasterPosZ]; @@ -564,30 +550,28 @@ b3dComputeMinZ(void) if (!(wValue == 0.0)) { zValue = zValue / wValue; } - if (zValue < minZ1) { - minZ1 = zValue; + if (zValue < minZ) { + minZ = zValue; } } - minZ = minZ1; } else { /* begin processIndexed:ofSize:idxArray:idxSize: */ - minZ2 = 10.0; - for (i1 = 1; i1 <= idxSize; i1 += 1) { - index = idxArray[i1]; + minZ = 10.0; + for (i = 1; i <= idxSize; i += 1) { + index = idxArray[i]; if (index > 0) { - vtxPtr1 = vtxArray + ((index - 1) * PrimVertexSize); - zValue1 = vtxPtr1[PrimVtxRasterPosZ]; - wValue1 = vtxPtr1[PrimVtxRasterPosW]; - if (!(wValue1 == 0.0)) { - zValue1 = zValue1 / wValue1; + vtxPtr = vtxArray + ((index - 1) * PrimVertexSize); + zValue = vtxPtr[PrimVtxRasterPosZ]; + wValue = vtxPtr[PrimVtxRasterPosW]; + if (!(wValue == 0.0)) { + zValue = zValue / wValue; } - if (zValue1 < minZ2) { - minZ2 = zValue1; + if (zValue < minZ) { + minZ = zValue; } } } - minZ = minZ2; } if (!(failed())) { pop(6); @@ -604,7 +588,6 @@ EXPORT(sqInt) b3dDetermineClipFlags(void) { sqInt flags; - int fullMask; sqInt i; int result; void *vtxArray; @@ -628,9 +611,10 @@ b3dDetermineClipFlags(void) || (failed())) { return primitiveFail(); } + /* begin determineClipFlags:count: */ vtxPtr = ((float *) vtxArray); - fullMask = InAllMask + OutAllMask; + result = InAllMask + OutAllMask; for (i = 1; i <= vtxCount; i += 1) { w = vtxPtr[PrimVtxRasterPosW]; w2 = 0.0 - w; @@ -674,11 +658,10 @@ b3dDetermineClipFlags(void) else { flags = flags | OutBackBit; } - fullMask = fullMask & flags; + result = result & flags; (((int *) vtxPtr))[PrimVtxClipFlags] = flags; vtxPtr += PrimVertexSize; } - result = fullMask; if (!(failed())) { pop(3); pushInteger(result); @@ -697,7 +680,7 @@ b3dInitializeRasterizerState(void) sqInt objOop; sqInt stateOop; - if (!((methodArgumentCount()) == 0)) { + if (methodArgumentCount()) { return primitiveFail(); } stateOop = stackValue(0); @@ -767,12 +750,12 @@ b3dInitPrimitiveObject(void) } vtxSize = stackIntegerValue(4); vtxArray = stackPrimitiveVertexArrayofSize(5, vtxSize); - if (vtxArray == null) { + if (!vtxArray) { return primitiveFail(); } idxSize = stackIntegerValue(2); idxArray = stackPrimitiveIndexArrayofSizevalidateforVertexSize(3, idxSize, 1, vtxSize); - if (idxArray == null) { + if (!idxArray) { return primitiveFail(); } primitive = stackIntegerValue(6); @@ -792,7 +775,8 @@ b3dInitPrimitiveObject(void) if (!(isWords(primOop))) { return primitiveFail(); } - primObj = ((void *) (firstIndexableField(primOop))); + primObj = firstIndexableField(primOop); + /* Do the work */ primSize = byteSizeOf(primOop); if (primitive == 3) { @@ -836,7 +820,6 @@ b3dInplaceHouseHolderInvert(void) double sum; double x[4][4] = { {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1} }; - /* begin stackMatrix: */ oop = stackValue(0); if ((isWords(oop)) @@ -846,7 +829,7 @@ b3dInplaceHouseHolderInvert(void) } primitiveFail(); rcvr = ((void *) null); - l1: /* end stackMatrix: */; +l1: /* end stackMatrix: */; for (i = 0; i <= 3; i += 1) { for (j = 0; j <= 3; j += 1) { (m[i])[j] = (rcvr[(i * 4) + j]); @@ -945,15 +928,18 @@ b3dLoadIndexArray(void) if ((slotSizeOf(srcArray)) < count) { return primitiveFail(); } + /* Check dstArray */ - srcPtr = ((int *) (firstIndexableField(srcArray))); + srcPtr = firstIndexableField(srcArray); + /* Check if there is enough room left in dstArray */ dstSize = slotSizeOf(dstArray); if ((dstStart + count) > dstSize) { return primitiveFail(); } + /* Do the actual work */ - dstPtr = ((int *) (firstIndexableField(dstArray))); + dstPtr = firstIndexableField(dstArray); for (i = 0; i < count; i += 1) { idx = srcPtr[i]; if ((idx < 1) @@ -996,6 +982,7 @@ b3dLoadVertexBuffer(void) normalPtr = vbLoadArraysize(stackObjectValue(4), 3 * count); vtxPtr = vbLoadArraysize(stackObjectValue(5), 3 * count); dstStart = stackIntegerValue(6); + /* Check for all problems above */ dstPtr = stackPrimitiveVertexArrayofSize(7, dstStart + count); if ((dstPtr == null) @@ -1003,23 +990,23 @@ b3dLoadVertexBuffer(void) || (failed()))) { return primitiveFail(); } - if (normalPtr == null) { - defaultNormal = defaultVtx + PrimVtxNormal; + if (normalPtr) { + defaultNormal = normalPtr; } else { - defaultNormal = normalPtr; + defaultNormal = defaultVtx + PrimVtxNormal; } - if (texPtr == null) { - defaultTexCoords = defaultVtx + PrimVtxTexCoords; + if (texPtr) { + defaultTexCoords = texPtr; } else { - defaultTexCoords = texPtr; + defaultTexCoords = defaultVtx + PrimVtxTexCoords; } - if (colorPtr == null) { - defaultColor = defaultVtx + PrimVtxColor32; + if (colorPtr) { + defaultColor = colorPtr; } else { - defaultColor = colorPtr; + defaultColor = defaultVtx + PrimVtxColor32; } pVtx = dstPtr + (dstStart * PrimVertexSize); for (i = 0; i < count; i += 1) { @@ -1034,13 +1021,13 @@ b3dLoadVertexBuffer(void) pVtx[PrimVtxTexCoordV] = (defaultTexCoords[1]); pVtx += PrimVertexSize; vtxPtr += 3; - if (!(normalPtr == null)) { + if (normalPtr) { defaultNormal += 3; } - if (!(colorPtr == null)) { + if (colorPtr) { defaultColor += 1; } - if (!(texPtr == null)) { + if (texPtr) { defaultTexCoords += 2; } } @@ -1092,6 +1079,7 @@ b3dMapVertexBuffer(void) || (failed())) { return primitiveFail(); } + /* begin mapVB:ofSize:into: */ vtxPtr = ((float *) vtxArray); for (i = 1; i <= vtxCount; i += 1) { @@ -1100,22 +1088,22 @@ b3dMapVertexBuffer(void) if (!(w == 0.0)) { w = 1.0 / w; } - if ((flags & OutLeftBit) != 0) { + if (flags & OutLeftBit) { x = -1.0; } else { - if ((flags & OutRightBit) != 0) { + if (flags & OutRightBit) { x = 1.0; } else { x = (vtxPtr[PrimVtxRasterPosX]) * w; } } - if ((flags & OutTopBit) != 0) { + if (flags & OutTopBit) { y = -1.0; } else { - if ((flags & OutBottomBit) != 0) { + if (flags & OutBottomBit) { y = 1.0; } else { @@ -1178,7 +1166,7 @@ b3dOrthoNormInverseMatrix(void) double y; double z; - if (!((methodArgumentCount()) == 0)) { + if (methodArgumentCount()) { return primitiveFail(); } srcOop = stackObjectValue(0); @@ -1194,10 +1182,11 @@ b3dOrthoNormInverseMatrix(void) return primitiveFailFor(PrimErrNoMemory); } srcOop = stackObjectValue(0); - src = ((float *) (firstIndexableField(srcOop))); + src = firstIndexableField(srcOop); + /* Transpose upper 3x3 matrix */ /* dst at: 0 put: (src at: 0). */ - dst = ((float *) (firstIndexableField(dstOop))); + dst = firstIndexableField(dstOop); dst[1] = (src[4]); dst[2] = (src[8]); dst[4] = (src[1]); @@ -1265,14 +1254,17 @@ b3dPrimitiveNextClippedTriangle(void) /* Check if tri is completely inside */ triMask = (vtxArray[(idx1 * PrimVertexSize) + PrimVtxClipFlags]) & ((vtxArray[(idx2 * PrimVertexSize) + PrimVtxClipFlags]) & (vtxArray[(idx3 * PrimVertexSize) + PrimVtxClipFlags])); if (!((InAllMask & triMask) == InAllMask)) { + /* Tri is not completely inside -> needs clipping. */ if (((triMask & OutAllMask) != 0)) { + /* tri is completely outside. Store all zeros */ idxArray[i] = 0; idxArray[i + 1] = 0; idxArray[i + 2] = 0; } else { + /* tri must be partially clipped. */ pop(6); pushInteger(i); @@ -1355,34 +1347,22 @@ b3dShadeVertexBuffer(void) { sqInt a; double aPart; - double aPart1; - double aPart2; sqInt b; double bPart; - double bPart1; - double bPart2; double cosAngle; sqInt g; double gPart; - double gPart1; - double gPart2; sqInt i; sqInt j; sqInt lightArray; sqInt lightCount; sqInt lightOop; float *lightPart; - float *lightPart1; - float *lightPart2; sqInt r; sqInt rgba; double rPart; - double rPart1; - double rPart2; double scale; - double scale1; - double scale11; - double scale2; + double scaleDouble; double specularFactor; float *vtxArray; sqInt vtxCount; @@ -1398,9 +1378,11 @@ b3dShadeVertexBuffer(void) return primitiveFail(); } litVertex = vtxArray; + /* Go over all vertices */ lightCount = slotSizeOf(lightArray); for (i = 1; i <= vtxCount; i += 1) { + /* Load the primitive vertex */ /* begin loadPrimitiveVertex */ rgba = (((int*) litVertex))[PrimVtxColor32]; @@ -1412,6 +1394,7 @@ b3dShadeVertexBuffer(void) rgba = ((usqInt)(rgba)) >> 8; vtxInColor[3] = ((rgba & 0xFF) * (1.0 / 255.0)); if (((vbFlags & VBTrackEmission) != 0)) { + /* Load color from vertex */ vtxOutColor[0] = ((vtxInColor[0]) + (primMaterial[EmissionRed])); vtxOutColor[1] = ((vtxInColor[1]) + (primMaterial[EmissionGreen])); @@ -1425,13 +1408,16 @@ b3dShadeVertexBuffer(void) vtxOutColor[3] = (primMaterial[EmissionAlpha]); } for (j = 0; j < lightCount; j += 1) { + /* Fetch the light source */ /* begin fetchLightSource:ofObject: */ lightOop = fetchPointerofObject(j, lightArray); primLight = firstIndexableField(lightOop); + /* begin loadPrimitiveLightSource */ lightFlags = (((int*) primLight))[PrimLightFlags]; if (((lightFlags & FlagPositional) != 0)) { + /* Must compute the direction for this vertex */ l2vDirection[0] = ((litVertex[PrimVtxPositionX]) - (primLight[PrimLightPositionX])); l2vDirection[1] = ((litVertex[PrimVtxPositionY]) - (primLight[PrimLightPositionY])); @@ -1453,6 +1439,7 @@ b3dShadeVertexBuffer(void) l2vDirection[2] = (primLight[PrimLightDirectionZ]); } } + /* begin computeAttenuation */ lightScale = 1.0; if (((lightFlags & FlagAttenuated) != 0)) { @@ -1462,9 +1449,11 @@ b3dShadeVertexBuffer(void) lightScale = lightScale * (computeSpotFactor()); } if (lightScale > 0.001) { + /* Compute the ambient part */ if (((lightFlags & FlagAmbientPart) != 0)) { lightPart = primLight + AmbientPart; + /* begin addPart:from:trackFlag:scale: */ if (((vbFlags & VBTrackAmbient) != 0)) { rPart = ((vtxInColor[0]) * (lightPart[0])) * lightScale; @@ -1473,6 +1462,7 @@ b3dShadeVertexBuffer(void) aPart = ((vtxInColor[3]) * (lightPart[3])) * lightScale; } else { + /* Note: This should be pre-computed. */ rPart = (((primMaterial + AmbientPart)[0]) * (lightPart[0])) * lightScale; gPart = (((primMaterial + AmbientPart)[1]) * (lightPart[1])) * lightScale; @@ -1485,6 +1475,7 @@ b3dShadeVertexBuffer(void) vtxOutColor[3] = ((vtxOutColor[3]) + aPart); } if (((lightFlags & FlagDiffusePart) != 0)) { + /* Compute angle from light->vertex to vertex normal */ /* begin dotProductOfFloat:withDouble: */ cosAngle = ((((litVertex + PrimVtxNormal)[0]) * (l2vDirection[0])) + (((litVertex + PrimVtxNormal)[1]) * (l2vDirection[1]))) + (((litVertex + PrimVtxNormal)[2]) * (l2vDirection[2])); @@ -1493,55 +1484,61 @@ b3dShadeVertexBuffer(void) cosAngle = 0.0 - cosAngle; } if (cosAngle > 0.0) { - lightPart1 = primLight + DiffusePart; - scale1 = lightScale * cosAngle; + lightPart = primLight + DiffusePart; + scale = lightScale * cosAngle; + /* begin addPart:from:trackFlag:scale: */ if (((vbFlags & VBTrackDiffuse) != 0)) { - rPart1 = ((vtxInColor[0]) * (lightPart1[0])) * scale1; - gPart1 = ((vtxInColor[1]) * (lightPart1[1])) * scale1; - bPart1 = ((vtxInColor[2]) * (lightPart1[2])) * scale1; - aPart1 = ((vtxInColor[3]) * (lightPart1[3])) * scale1; + rPart = ((vtxInColor[0]) * (lightPart[0])) * scale; + gPart = ((vtxInColor[1]) * (lightPart[1])) * scale; + bPart = ((vtxInColor[2]) * (lightPart[2])) * scale; + aPart = ((vtxInColor[3]) * (lightPart[3])) * scale; } else { + /* Note: This should be pre-computed. */ - rPart1 = (((primMaterial + DiffusePart)[0]) * (lightPart1[0])) * scale1; - gPart1 = (((primMaterial + DiffusePart)[1]) * (lightPart1[1])) * scale1; - bPart1 = (((primMaterial + DiffusePart)[2]) * (lightPart1[2])) * scale1; - aPart1 = (((primMaterial + DiffusePart)[3]) * (lightPart1[3])) * scale1; + rPart = (((primMaterial + DiffusePart)[0]) * (lightPart[0])) * scale; + gPart = (((primMaterial + DiffusePart)[1]) * (lightPart[1])) * scale; + bPart = (((primMaterial + DiffusePart)[2]) * (lightPart[2])) * scale; + aPart = (((primMaterial + DiffusePart)[3]) * (lightPart[3])) * scale; } - vtxOutColor[0] = ((vtxOutColor[0]) + rPart1); - vtxOutColor[1] = ((vtxOutColor[1]) + gPart1); - vtxOutColor[2] = ((vtxOutColor[2]) + bPart1); - vtxOutColor[3] = ((vtxOutColor[3]) + aPart1); + vtxOutColor[0] = ((vtxOutColor[0]) + rPart); + vtxOutColor[1] = ((vtxOutColor[1]) + gPart); + vtxOutColor[2] = ((vtxOutColor[2]) + bPart); + vtxOutColor[3] = ((vtxOutColor[3]) + aPart); } } } if ((((lightFlags & FlagSpecularPart) != 0)) && ((primMaterial[MaterialShininess]) > 0.0)) { + /* Compute specular part */ l2vSpecDir[0] = (l2vDirection[0]); l2vSpecDir[1] = (l2vDirection[1]); l2vSpecDir[2] = (l2vDirection[2]); if (((vbFlags & VBUseLocalViewer) != 0)) { /* begin computeSpecularDirection */ - scale11 = ((((litVertex + PrimVtxPosition)[0]) * ((litVertex + PrimVtxPosition)[0])) + (((litVertex + PrimVtxPosition)[1]) * ((litVertex + PrimVtxPosition)[1]))) + (((litVertex + PrimVtxPosition)[2]) * ((litVertex + PrimVtxPosition)[2])); - if ((scale11 == 0.0) - || (scale11 == 1.0)) { - scale2 = scale11; - goto l2; + /* begin inverseLengthOfFloat: */ + scaleDouble = ((((litVertex + PrimVtxPosition)[0]) * ((litVertex + PrimVtxPosition)[0])) + (((litVertex + PrimVtxPosition)[1]) * ((litVertex + PrimVtxPosition)[1]))) + (((litVertex + PrimVtxPosition)[2]) * ((litVertex + PrimVtxPosition)[2])); + if ((scaleDouble == 0.0) + || (scaleDouble == 1.0)) { + scale = scaleDouble; + goto l1; } - scale2 = 1.0 / (sqrt(scale11)); - l2: /* end inverseLengthOfFloat: */; - l2vSpecDir[0] = ((l2vSpecDir[0]) - ((litVertex[PrimVtxPositionX]) * scale2)); - l2vSpecDir[1] = ((l2vSpecDir[1]) - ((litVertex[PrimVtxPositionY]) * scale2)); - l2vSpecDir[2] = ((l2vSpecDir[2]) - ((litVertex[PrimVtxPositionZ]) * scale2)); + scale = 1.0 / (sqrt(scaleDouble)); +l1: /* end inverseLengthOfFloat: */; + l2vSpecDir[0] = ((l2vSpecDir[0]) - ((litVertex[PrimVtxPositionX]) * scale)); + l2vSpecDir[1] = ((l2vSpecDir[1]) - ((litVertex[PrimVtxPositionY]) * scale)); + l2vSpecDir[2] = ((l2vSpecDir[2]) - ((litVertex[PrimVtxPositionZ]) * scale)); } else { l2vSpecDir[2] = ((l2vSpecDir[2]) - 1.0); } + /* begin dotProductOfFloat:withDouble: */ cosAngle = ((((litVertex + PrimVtxNormal)[0]) * (l2vSpecDir[0])) + (((litVertex + PrimVtxNormal)[1]) * (l2vSpecDir[1]))) + (((litVertex + PrimVtxNormal)[2]) * (l2vSpecDir[2])); if (cosAngle > 0.0) { + /* Normalize the angle */ /* cosAngle should be somewhere between 0 and 1. If not, then the vertex normal was not normalized */ @@ -1557,28 +1554,31 @@ b3dShadeVertexBuffer(void) specularFactor = pow(cosAngle,(primMaterial[MaterialShininess])); } } - lightPart2 = primLight + SpecularPart; + lightPart = primLight + SpecularPart; + /* begin addPart:from:trackFlag:scale: */ if (((vbFlags & VBTrackSpecular) != 0)) { - rPart2 = ((vtxInColor[0]) * (lightPart2[0])) * specularFactor; - gPart2 = ((vtxInColor[1]) * (lightPart2[1])) * specularFactor; - bPart2 = ((vtxInColor[2]) * (lightPart2[2])) * specularFactor; - aPart2 = ((vtxInColor[3]) * (lightPart2[3])) * specularFactor; + rPart = ((vtxInColor[0]) * (lightPart[0])) * specularFactor; + gPart = ((vtxInColor[1]) * (lightPart[1])) * specularFactor; + bPart = ((vtxInColor[2]) * (lightPart[2])) * specularFactor; + aPart = ((vtxInColor[3]) * (lightPart[3])) * specularFactor; } else { + /* Note: This should be pre-computed. */ - rPart2 = (((primMaterial + SpecularPart)[0]) * (lightPart2[0])) * specularFactor; - gPart2 = (((primMaterial + SpecularPart)[1]) * (lightPart2[1])) * specularFactor; - bPart2 = (((primMaterial + SpecularPart)[2]) * (lightPart2[2])) * specularFactor; - aPart2 = (((primMaterial + SpecularPart)[3]) * (lightPart2[3])) * specularFactor; + rPart = (((primMaterial + SpecularPart)[0]) * (lightPart[0])) * specularFactor; + gPart = (((primMaterial + SpecularPart)[1]) * (lightPart[1])) * specularFactor; + bPart = (((primMaterial + SpecularPart)[2]) * (lightPart[2])) * specularFactor; + aPart = (((primMaterial + SpecularPart)[3]) * (lightPart[3])) * specularFactor; } - vtxOutColor[0] = ((vtxOutColor[0]) + rPart2); - vtxOutColor[1] = ((vtxOutColor[1]) + gPart2); - vtxOutColor[2] = ((vtxOutColor[2]) + bPart2); - vtxOutColor[3] = ((vtxOutColor[3]) + aPart2); + vtxOutColor[0] = ((vtxOutColor[0]) + rPart); + vtxOutColor[1] = ((vtxOutColor[1]) + gPart); + vtxOutColor[2] = ((vtxOutColor[2]) + bPart); + vtxOutColor[3] = ((vtxOutColor[3]) + aPart); } } } + /* begin storePrimitiveVertex */ r = ((sqInt)((vtxOutColor[0]) * 0xFF)); r = (((((r < 0xFF) ? r : 0xFF)) < 0) ? 0 : (((r < 0xFF) ? r : 0xFF))); @@ -1587,9 +1587,10 @@ b3dShadeVertexBuffer(void) b = ((sqInt)((vtxOutColor[2]) * 0xFF)); b = (((((b < 0xFF) ? b : 0xFF)) < 0) ? 0 : (((b < 0xFF) ? b : 0xFF))); a = ((sqInt)((vtxOutColor[3]) * 0xFF)); + /* The following is equal to b + (g << 8) + (r << 16) + (a << 24) */ a = (((((a < 0xFF) ? a : 0xFF)) < 0) ? 0 : (((a < 0xFF) ? a : 0xFF))); - (((int*) litVertex))[PrimVtxColor32] = (b + (((sqInt)((usqInt)((g + (((sqInt)((usqInt)((r + (((sqInt)((usqInt)(a) << 8))))) << 8))))) << 8)))); + (((int*) litVertex))[PrimVtxColor32] = (b + ((((usqInt)((g + ((((usqInt)((r + ((((usqInt)(a) << 8))))) << 8))))) << 8)))); litVertex += PrimVertexSize; } pop(6); @@ -1655,7 +1656,8 @@ b3dTransformDirection(void) && ((slotSizeOf(v3Oop)) == 3))) { return primitiveFail(); } - vertex = ((float *) (firstIndexableField(v3Oop))); + vertex = firstIndexableField(v3Oop); + /* begin stackMatrix: */ oop = stackValue(1); if ((isWords(oop)) @@ -1665,8 +1667,8 @@ b3dTransformDirection(void) } primitiveFail(); matrix = ((void *) null); - l1: /* end stackMatrix: */; - if (matrix == null) { +l1: /* end stackMatrix: */; + if (!matrix) { return primitiveFail(); } x = vertex[0]; @@ -1679,7 +1681,7 @@ b3dTransformDirection(void) if (!v3Oop) { return primitiveFailFor(PrimErrNoMemory); } - vertex = ((float *) (firstIndexableField(v3Oop))); + vertex = firstIndexableField(v3Oop); vertex[0] = (((float) rx)); vertex[1] = (((float) ry)); vertex[2] = (((float) rz)); @@ -1718,9 +1720,6 @@ b3dTransformMatrixWithInto(void) float *m3; float *m31; sqInt oop; - sqInt oop1; - sqInt oop2; - /* begin stackMatrix: */ oop = stackValue(0); @@ -1731,42 +1730,47 @@ b3dTransformMatrixWithInto(void) } primitiveFail(); m3 = ((void *) null); - l1: /* end stackMatrix: */; +l1: /* end stackMatrix: */; + /* begin stackMatrix: */ - oop1 = stackValue(1); - if ((isWords(oop1)) - && ((slotSizeOf(oop1)) == 16)) { - m2 = firstIndexableField(oop1); + oop = stackValue(1); + if ((isWords(oop)) + && ((slotSizeOf(oop)) == 16)) { + m2 = firstIndexableField(oop); goto l2; } primitiveFail(); m2 = ((void *) null); - l2: /* end stackMatrix: */; +l2: /* end stackMatrix: */; + /* begin stackMatrix: */ - oop2 = stackValue(2); - if ((isWords(oop2)) - && ((slotSizeOf(oop2)) == 16)) { - m1 = firstIndexableField(oop2); + oop = stackValue(2); + if ((isWords(oop)) + && ((slotSizeOf(oop)) == 16)) { + m1 = firstIndexableField(oop); goto l3; } primitiveFail(); m1 = ((void *) null); - l3: /* end stackMatrix: */; +l3: /* end stackMatrix: */; if (((m1 == null) || (m2 == null)) || (m3 == null)) { return primitiveFail(); } if (m2 == m3) { return primitiveFail(); } + /* begin transformMatrix:with:into: */ m11 = ((float *) m1); m21 = ((float *) m2); m31 = ((float *) m3); for (i = 0; i <= 3; i += 1) { + /* Compute next row */ c1 = ((((m11[0]) * (m21[0])) + ((m11[1]) * (m21[4]))) + ((m11[2]) * (m21[8]))) + ((m11[3]) * (m21[12])); c2 = ((((m11[0]) * (m21[1])) + ((m11[1]) * (m21[5]))) + ((m11[2]) * (m21[9]))) + ((m11[3]) * (m21[13])); c3 = ((((m11[0]) * (m21[2])) + ((m11[1]) * (m21[6]))) + ((m11[2]) * (m21[10]))) + ((m11[3]) * (m21[14])); + /* Store result */ c4 = ((((m11[0]) * (m21[3])) + ((m11[1]) * (m21[7]))) + ((m11[2]) * (m21[11]))) + ((m11[3]) * (m21[15])); m31[0] = c1; @@ -1807,7 +1811,8 @@ b3dTransformPoint(void) && ((slotSizeOf(v3Oop)) == 3))) { return primitiveFail(); } - vertex = ((float *) (firstIndexableField(v3Oop))); + vertex = firstIndexableField(v3Oop); + /* begin stackMatrix: */ oop = stackValue(1); if ((isWords(oop)) @@ -1817,8 +1822,8 @@ b3dTransformPoint(void) } primitiveFail(); matrix = ((void *) null); - l1: /* end stackMatrix: */; - if (matrix == null) { +l1: /* end stackMatrix: */; + if (!matrix) { return primitiveFail(); } x = vertex[0]; @@ -1832,7 +1837,7 @@ b3dTransformPoint(void) if (!v3Oop) { return primitiveFailFor(PrimErrNoMemory); } - vertex = ((float *) (firstIndexableField(v3Oop))); + vertex = firstIndexableField(v3Oop); if (rw == 1.0) { vertex[0] = (((float) rx)); vertex[1] = (((float) ry)); @@ -1871,6 +1876,7 @@ b3dTransformPrimitiveNormal(void) if (!(rescale == (nilObject()))) { rescale = booleanValueOf(rescale); } + /* begin stackMatrix: */ oop = stackValue(1); if ((isWords(oop)) @@ -1880,7 +1886,7 @@ b3dTransformPrimitiveNormal(void) } primitiveFail(); matrix = ((void *) null); - l1: /* end stackMatrix: */; +l1: /* end stackMatrix: */; pVertex = stackPrimitiveVertex(2); if ((matrix == null) || (pVertex == null)) { return primitiveFail(); @@ -1906,7 +1912,6 @@ b3dTransformPrimitivePosition(void) sqInt oop; float *pVertex; - /* begin stackMatrix: */ oop = stackValue(0); if ((isWords(oop)) @@ -1916,7 +1921,7 @@ b3dTransformPrimitivePosition(void) } primitiveFail(); matrix = ((void *) null); - l1: /* end stackMatrix: */; +l1: /* end stackMatrix: */; pVertex = stackPrimitiveVertex(1); if ((matrix == null) || (pVertex == null)) { return primitiveFail(); @@ -1938,7 +1943,6 @@ b3dTransformPrimitiveRasterPosition(void) sqInt oop; float *pVertex; - /* begin stackMatrix: */ oop = stackValue(0); if ((isWords(oop)) @@ -1948,7 +1952,7 @@ b3dTransformPrimitiveRasterPosition(void) } primitiveFail(); matrix = ((void *) null); - l1: /* end stackMatrix: */; +l1: /* end stackMatrix: */; pVertex = stackPrimitiveVertex(1); if ((matrix == null) || (pVertex == null)) { return primitiveFail(); @@ -1973,7 +1977,6 @@ b3dTransformVertexBuffer(void) float *modelViewMatrix; sqInt mvFlags; sqInt oop; - sqInt oop1; sqInt prFlags; float *projectionMatrix; float *pVertex; @@ -1982,6 +1985,7 @@ b3dTransformVertexBuffer(void) sqInt vtxCount; flags = stackIntegerValue(0); + /* begin stackMatrix: */ oop = stackValue(1); if ((isWords(oop)) @@ -1991,17 +1995,18 @@ b3dTransformVertexBuffer(void) } primitiveFail(); projectionMatrix = ((void *) null); - l1: /* end stackMatrix: */; +l1: /* end stackMatrix: */; + /* begin stackMatrix: */ - oop1 = stackValue(2); - if ((isWords(oop1)) - && ((slotSizeOf(oop1)) == 16)) { - modelViewMatrix = firstIndexableField(oop1); + oop = stackValue(2); + if ((isWords(oop)) + && ((slotSizeOf(oop)) == 16)) { + modelViewMatrix = firstIndexableField(oop); goto l2; } primitiveFail(); modelViewMatrix = ((void *) null); - l2: /* end stackMatrix: */; +l2: /* end stackMatrix: */; vtxCount = stackIntegerValue(3); vtxArray = stackPrimitiveVertexArrayofSize(4, vtxCount); if (((projectionMatrix == null) || (modelViewMatrix == null)) || (vtxArray == null)) { @@ -2010,11 +2015,13 @@ b3dTransformVertexBuffer(void) if (failed()) { return null; } + /* begin transformVB:count:by:and:flags: */ rescale = 0; mvFlags = analyzeMatrix(modelViewMatrix); prFlags = analyzeMatrix(projectionMatrix); pVertex = ((float *) vtxArray); + /* Check if we have to rescale the normals */ hasNormals = ((flags & VBVtxHasNormals) != 0); if (hasNormals) { @@ -2027,25 +2034,28 @@ b3dTransformVertexBuffer(void) } if ((((mvFlags & FlagM44NoPerspective) != 0)) && (prFlags == 0)) { + /* Modelview matrix has no perspective part and projection is not optimized */ - if ((mvFlags == FlagM44NoTranslation) == 0) { - /* Modelview matrix with translation */ + if (mvFlags == FlagM44NoTranslation) { + + /* Modelview matrix without translation */ for (i = 1; i <= vtxCount; i += 1) { if (hasNormals) { transformPrimitiveNormalbyrescale(pVertex, modelViewMatrix, rescale); } - transformPrimitivePositionFastby(pVertex, modelViewMatrix); + transformPrimitivePositionFasterby(pVertex, modelViewMatrix); transformPrimitiveRasterPositionby(pVertex, projectionMatrix); pVertex += PrimVertexSize; } } else { - /* Modelview matrix without translation */ + + /* Modelview matrix with translation */ for (i = 1; i <= vtxCount; i += 1) { if (hasNormals) { transformPrimitiveNormalbyrescale(pVertex, modelViewMatrix, rescale); } - transformPrimitivePositionFasterby(pVertex, modelViewMatrix); + transformPrimitivePositionFastby(pVertex, modelViewMatrix); transformPrimitiveRasterPositionby(pVertex, projectionMatrix); pVertex += PrimVertexSize; } @@ -2053,6 +2063,7 @@ b3dTransformVertexBuffer(void) goto l3; } if ((((mvFlags & prFlags) & FlagM44Identity) != 0)) { + /* If both are identity matrices just copy entries */ for (i = 1; i <= vtxCount; i += 1) { pVertex[PrimVtxRasterPosX] = (pVertex[PrimVtxPositionX]); @@ -2064,6 +2075,7 @@ b3dTransformVertexBuffer(void) goto l3; } if (((mvFlags & FlagM44Identity) != 0)) { + /* If model view matrix is identity just perform projection */ for (i = 1; i <= vtxCount; i += 1) { transformPrimitiveRasterPositionby(pVertex, projectionMatrix); @@ -2072,6 +2084,7 @@ b3dTransformVertexBuffer(void) goto l3; } if (((prFlags & FlagM44Identity) != 0)) { + /* If projection matrix is identity just transform and copy. Note: This case is not very likely so it's not been unrolled. */ for (i = 1; i <= vtxCount; i += 1) { @@ -2105,7 +2118,7 @@ b3dTransformVertexBuffer(void) transformPrimitiveRasterPositionby(pVertex, projectionMatrix); pVertex += PrimVertexSize; } - l3: /* end transformVB:count:by:and:flags: */; +l3: /* end transformVB:count:by:and:flags: */; pop(5); return 0; } @@ -2119,7 +2132,7 @@ b3dTransposeMatrix(void) float *src; sqInt srcOop; - if (!((methodArgumentCount()) == 0)) { + if (methodArgumentCount()) { return primitiveFail(); } srcOop = stackObjectValue(0); @@ -2135,9 +2148,10 @@ b3dTransposeMatrix(void) return primitiveFailFor(PrimErrNoMemory); } srcOop = stackObjectValue(0); - src = ((float *) (firstIndexableField(srcOop))); + src = firstIndexableField(srcOop); + /* dst at: 0 put: (src at: 0). */ - dst = ((float *) (firstIndexableField(dstOop))); + dst = firstIndexableField(dstOop); dst[1] = (src[4]); dst[2] = (src[8]); dst[3] = (src[12]); @@ -2174,6 +2188,7 @@ clipPolygonBackFromtocount(int *buf1, int *buf2, sqInt n) for (i = 1; i <= n; i += 1) { inNext = (((next[PrimVtxClipFlags]) & InBackBit) != 0); if (!(inLast == inNext)) { + /* Passes clip boundary */ /* begin backClipValueFrom:to: */ t = (((((float *) last))[PrimVtxRasterPosZ]) - ((((float *) last))[PrimVtxRasterPosW])) / ((((((float *) next))[PrimVtxRasterPosW]) - ((((float *) last))[PrimVtxRasterPosW])) - (((((float *) next))[PrimVtxRasterPosZ]) - ((((float *) last))[PrimVtxRasterPosZ]))); @@ -2213,6 +2228,7 @@ clipPolygonBottomFromtocount(int *buf1, int *buf2, sqInt n) for (i = 1; i <= n; i += 1) { inNext = (((next[PrimVtxClipFlags]) & InBottomBit) != 0); if (!(inLast == inNext)) { + /* Passes clip boundary */ /* begin bottomClipValueFrom:to: */ t = (0.0 - (((((float *) last))[PrimVtxRasterPosY]) + ((((float *) last))[PrimVtxRasterPosW]))) / ((((((float *) next))[PrimVtxRasterPosW]) - ((((float *) last))[PrimVtxRasterPosW])) + (((((float *) next))[PrimVtxRasterPosY]) - ((((float *) last))[PrimVtxRasterPosY]))); @@ -2252,6 +2268,7 @@ clipPolygonFrontFromtocount(int *buf1, int *buf2, sqInt n) for (i = 1; i <= n; i += 1) { inNext = (((next[PrimVtxClipFlags]) & InFrontBit) != 0); if (!(inLast == inNext)) { + /* Passes clip boundary */ /* begin frontClipValueFrom:to: */ t = (0.0 - (((((float *) last))[PrimVtxRasterPosZ]) + ((((float *) last))[PrimVtxRasterPosW]))) / ((((((float *) next))[PrimVtxRasterPosW]) - ((((float *) last))[PrimVtxRasterPosW])) + (((((float *) next))[PrimVtxRasterPosZ]) - ((((float *) last))[PrimVtxRasterPosZ]))); @@ -2291,6 +2308,7 @@ clipPolygonLeftFromtocount(int *buf1, int *buf2, sqInt n) for (i = 1; i <= n; i += 1) { inNext = (((next[PrimVtxClipFlags]) & InLeftBit) != 0); if (!(inLast == inNext)) { + /* Passes clip boundary */ /* begin leftClipValueFrom:to: */ t = (0.0 - (((((float *) last))[PrimVtxRasterPosX]) + ((((float *) last))[PrimVtxRasterPosW]))) / ((((((float *) next))[PrimVtxRasterPosW]) - ((((float *) last))[PrimVtxRasterPosW])) + (((((float *) next))[PrimVtxRasterPosX]) - ((((float *) last))[PrimVtxRasterPosX]))); @@ -2330,6 +2348,7 @@ clipPolygonRightFromtocount(int *buf1, int *buf2, sqInt n) for (i = 1; i <= n; i += 1) { inNext = (((next[PrimVtxClipFlags]) & InRightBit) != 0); if (!(inLast == inNext)) { + /* Passes clip boundary */ /* begin rightClipValueFrom:to: */ t = (((((float *) last))[PrimVtxRasterPosX]) - ((((float *) last))[PrimVtxRasterPosW])) / ((((((float *) next))[PrimVtxRasterPosW]) - ((((float *) last))[PrimVtxRasterPosW])) - (((((float *) next))[PrimVtxRasterPosX]) - ((((float *) last))[PrimVtxRasterPosX]))); @@ -2369,6 +2388,7 @@ clipPolygonTopFromtocount(int *buf1, int *buf2, sqInt n) for (i = 1; i <= n; i += 1) { inNext = (((next[PrimVtxClipFlags]) & InTopBit) != 0); if (!(inLast == inNext)) { + /* Passes clip boundary */ /* begin topClipValueFrom:to: */ t = (((((float *) last))[PrimVtxRasterPosY]) - ((((float *) last))[PrimVtxRasterPosW])) / ((((((float *) next))[PrimVtxRasterPosW]) - ((((float *) last))[PrimVtxRasterPosW])) - (((((float *) next))[PrimVtxRasterPosY]) - ((((float *) last))[PrimVtxRasterPosY]))); @@ -2410,6 +2430,7 @@ computeSpotFactor(void) } deltaCos = primLight[SpotLightDeltaCos]; if (deltaCos <= 1.0e-5) { + /* No delta -- a sharp boundary between on and off. Since off has already been determined above, we are on */ return 1.0; @@ -2527,17 +2548,17 @@ interpolateFromtoatinto(float *last, float *next, double t, float *out) nextValue = rgbaNext & 0xFF; rgbaNext = ((usqInt)(rgbaNext)) >> 8; delta = (((int) (nextValue - lastValue))) * t; - newValue += ((sqInt)((usqInt)((((sqInt)(lastValue + delta)))) << 8)); + newValue += (((usqInt)((((sqInt)(lastValue + delta)))) << 8)); lastValue = rgbaLast & 0xFF; rgbaLast = ((usqInt)(rgbaLast)) >> 8; nextValue = rgbaNext & 0xFF; rgbaNext = ((usqInt)(rgbaNext)) >> 8; delta = (((int) (nextValue - lastValue))) * t; - newValue += ((sqInt)((usqInt)((((sqInt)(lastValue + delta)))) << 16)); + newValue += (((usqInt)((((sqInt)(lastValue + delta)))) << 16)); lastValue = rgbaLast & 0xFF; nextValue = rgbaNext & 0xFF; delta = (((int) (nextValue - lastValue))) * t; - newValue += ((sqInt)((usqInt)((((sqInt)(lastValue + delta)))) << 24)); + newValue += (((usqInt)((((sqInt)(lastValue + delta)))) << 24)); (((unsigned int*) out))[PrimVtxColor32] = newValue; delta = (next[PrimVtxTexCoordU]) - (last[PrimVtxTexCoordU]); out[PrimVtxTexCoordU] = (((float) ((last[PrimVtxTexCoordU]) + (delta * t)))); @@ -2587,7 +2608,7 @@ loadObjectsFrom(sqInt stackIndex) if (!(isWords(objOop))) { return primitiveFail(); } - objPtr = ((B3DPrimitiveObject *) (firstIndexableField(objOop))); + objPtr = firstIndexableField(objOop); if (objPtr->magic != B3D_PRIMITIVE_OBJECT_MAGIC) { return primitiveFail(); } @@ -2611,6 +2632,7 @@ loadRasterizerState(sqInt stackIndex) if ((copyBitsFn == 0) || (loadBBFn == 0)) { + /* We need loadBitBltFrom/copyBits here so try to load it implicitly */ if (!(initialiseModule())) { return 0; @@ -2625,37 +2647,37 @@ loadRasterizerState(sqInt stackIndex) if (!(isWords(obj))) { return 0; } - objPtr = ((void *) (firstIndexableField(obj))); + objPtr = firstIndexableField(obj); state.faceAlloc = objPtr; obj = fetchPointerofObject(1, stateOop); if (!(isWords(obj))) { return 0; } - objPtr = ((void *) (firstIndexableField(obj))); + objPtr = firstIndexableField(obj); state.edgeAlloc = objPtr; obj = fetchPointerofObject(2, stateOop); if (!(isWords(obj))) { return 0; } - objPtr = ((void *) (firstIndexableField(obj))); + objPtr = firstIndexableField(obj); state.attrAlloc = objPtr; obj = fetchPointerofObject(3, stateOop); if (!(isWords(obj))) { return 0; } - objPtr = ((void *) (firstIndexableField(obj))); + objPtr = firstIndexableField(obj); state.aet = objPtr; obj = fetchPointerofObject(4, stateOop); if (!(isWords(obj))) { return 0; } - objPtr = ((void *) (firstIndexableField(obj))); + objPtr = firstIndexableField(obj); state.addedEdges = objPtr; obj = fetchPointerofObject(5, stateOop); if (!(isWords(obj))) { return 0; } - objPtr = ((void *) (firstIndexableField(obj))); + objPtr = firstIndexableField(obj); state.fillList = objPtr; obj = fetchPointerofObject(6, stateOop); if (obj == (nilObject())) { @@ -2667,7 +2689,7 @@ loadRasterizerState(sqInt stackIndex) return 0; } objLen = byteSizeOf(obj); - objPtr = ((void *) (firstIndexableField(obj))); + objPtr = firstIndexableField(obj); state.objects = (B3DPrimitiveObject **)objPtr; state.nObjects = objLen/sizeof(B3DPrimitiveObject *); } @@ -2681,7 +2703,7 @@ loadRasterizerState(sqInt stackIndex) return 0; } objLen = byteSizeOf(obj); - objPtr = ((void *) (firstIndexableField(obj))); + objPtr = firstIndexableField(obj); state.textures = (B3DTexture *)objPtr; state.nTextures = objLen / sizeof(B3DTexture); } @@ -2695,7 +2717,7 @@ loadRasterizerState(sqInt stackIndex) return 0; } objLen = slotSizeOf(obj); - objPtr = ((void *) (firstIndexableField(obj))); + objPtr = firstIndexableField(obj); state.spanBuffer = (unsigned int *)objPtr; state.spanSize = objLen; } @@ -2789,8 +2811,9 @@ loadTextureinto(sqInt textureOop, B3DTexture *destPtr) || (texEnvMode > 1)) { return 0; } + /* Set the texture parameters */ - bitsPtr = ((void *) (firstIndexableField(formBits))); + bitsPtr = firstIndexableField(formBits); return b3dLoadTexture(destPtr, formWidth, formHeight, formDepth, (unsigned int*) bitsPtr, 0, NULL) == B3D_NO_ERROR; } @@ -2849,7 +2872,8 @@ loadViewportFrom(sqInt stackIndex) EXPORT(sqInt) moduleUnloaded(char *aModuleName) { - if ((strcmp(aModuleName, bbPluginName)) == 0) { + if (!(strcmp(aModuleName, bbPluginName))) { + /* BitBlt just shut down. How nasty. */ loadBBFn = 0; copyBitsFn = 0; @@ -2870,7 +2894,6 @@ primitiveSetBitBltPlugin(void) sqInt pluginName; char *ptr; - /* Must be string to work */ pluginName = stackValue(0); if (!(isBytes(pluginName))) { @@ -2880,16 +2903,17 @@ primitiveSetBitBltPlugin(void) if (length >= 0x100) { return primitiveFail(); } - ptr = ((char *) (firstIndexableField(pluginName))); + ptr = firstIndexableField(pluginName); needReload = 0; for (i = 0; i < length; i += 1) { + /* Compare and store the plugin to be used */ if (!((bbPluginName[i]) == (ptr[i]))) { bbPluginName[i] = (ptr[i]); needReload = 1; } } - if (!((bbPluginName[length]) == 0)) { + if (bbPluginName[length]) { bbPluginName[length] = 0; needReload = 1; } @@ -2911,12 +2935,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -3023,7 +3046,7 @@ stackPrimitiveIndexArrayofSizevalidateforVertexSize(sqInt stackIndex, sqInt nIte sqInt oopSize; oop = stackObjectValue(stackIndex); - if (oop == null) { + if (!oop) { return null; } if (!(isWords(oop))) { @@ -3033,7 +3056,7 @@ stackPrimitiveIndexArrayofSizevalidateforVertexSize(sqInt stackIndex, sqInt nIte if (oopSize < nItems) { return null; } - idxPtr = ((int *) (firstIndexableField(oop))); + idxPtr = firstIndexableField(oop); if (aBool) { for (i = 0; i < nItems; i += 1) { index = idxPtr[i]; @@ -3058,7 +3081,7 @@ stackPrimitiveVertexArrayofSize(sqInt index, sqInt nItems) sqInt oopSize; oop = stackObjectValue(index); - if (oop == null) { + if (!oop) { return null; } if (isWords(oop)) { @@ -3082,7 +3105,7 @@ stackPrimitiveVertex(sqInt index) sqInt oop; oop = stackObjectValue(index); - if (oop == null) { + if (!oop) { return null; } if ((isWords(oop)) @@ -3282,7 +3305,7 @@ transformPrimitiveRasterPositionby(float *pVertex, float *matrix) static void* vbLoadArraysize(sqInt oop, sqInt count) { - if (oop == null) { + if (!oop) { primitiveFail(); return null; } @@ -3300,8 +3323,8 @@ vbLoadArraysize(sqInt oop, sqInt count) return firstIndexableField(oop); } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "Squeak3D"; diff --git a/src/plugins/SqueakFFIPrims/SqueakFFIPrims.c b/src/plugins/SqueakFFIPrims/SqueakFFIPrims.c index 66e456b130..7ce02c1afe 100644 --- a/src/plugins/SqueakFFIPrims/SqueakFFIPrims.c +++ b/src/plugins/SqueakFFIPrims/SqueakFFIPrims.c @@ -1,5 +1,5 @@ /* Automatically generated by - ThreadedFFIPlugin VMMaker.oscog-mt.3362 uuid: b8f74e14-6430-924d-93fb-2fc1cd50ba34 + ThreadedFFIPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 */ #if defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_7__) || defined(__arm32__) || defined(ARM32) || defined(_M_ARM) diff --git a/src/plugins/StarSqueakPlugin/StarSqueakPlugin.c b/src/plugins/StarSqueakPlugin/StarSqueakPlugin.c index db11031510..9992eb21e5 100644 --- a/src/plugins/StarSqueakPlugin/StarSqueakPlugin.c +++ b/src/plugins/StarSqueakPlugin/StarSqueakPlugin.c @@ -1,9 +1,9 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - StarSqueakPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + StarSqueakPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 */ -static char __buildInfo[] = "StarSqueakPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f " __DATE__ ; +static char __buildInfo[] = "StarSqueakPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 " __DATE__ ; #include "config.h" @@ -64,7 +64,7 @@ extern sqInt success(sqInt aBoolean); extern #endif struct VirtualMachine* interpreterProxy; -static const char *moduleName = "StarSqueakPlugin VMMaker.oscog-eem.3455 " INT_EXT; +static const char *moduleName = "StarSqueakPlugin VMMaker.oscog-eem.3456 " INT_EXT; /*** Methods ***/ @@ -116,22 +116,24 @@ primitiveDiffuseFromToWidthHeightDelta(void) width = stackIntegerValue(2); height = stackIntegerValue(1); delta = stackIntegerValue(0); + /* begin checkedUnsignedIntPtrOf: */ success(isWords(srcOop)); if (failed()) { src = 0; goto l1; } - src = ((unsigned int *) (firstIndexableField(srcOop))); - l1: /* end checkedUnsignedIntPtrOf: */; + src = firstIndexableField(srcOop); +l1: /* end checkedUnsignedIntPtrOf: */; + /* begin checkedUnsignedIntPtrOf: */ success(isWords(dstOop)); if (failed()) { dst = 0; goto l2; } - dst = ((unsigned int *) (firstIndexableField(dstOop))); - l2: /* end checkedUnsignedIntPtrOf: */; + dst = firstIndexableField(dstOop); +l2: /* end checkedUnsignedIntPtrOf: */; success((stSizeOf(srcOop)) == (stSizeOf(dstOop))); success((stSizeOf(srcOop)) == (width * height)); if (failed()) { @@ -188,14 +190,15 @@ primitiveEvaporateRate(void) patchVarOop = stackValue(1); rate = stackIntegerValue(0); + /* begin checkedUnsignedIntPtrOf: */ success(isWords(patchVarOop)); if (failed()) { patchVar = 0; goto l1; } - patchVar = ((unsigned int *) (firstIndexableField(patchVarOop))); - l1: /* end checkedUnsignedIntPtrOf: */; + patchVar = firstIndexableField(patchVarOop); +l1: /* end checkedUnsignedIntPtrOf: */; sz = stSizeOf(patchVarOop); if (failed()) { return null; @@ -237,22 +240,24 @@ primitiveMapFromToWidthHeightPatchSizeRgbFlagsShift(void) patchSize = stackIntegerValue(2); rgbFlags = stackIntegerValue(1); shiftAmount = stackIntegerValue(0); + /* begin checkedUnsignedIntPtrOf: */ success(isWords(srcOop)); if (failed()) { src = 0; goto l1; } - src = ((unsigned int *) (firstIndexableField(srcOop))); - l1: /* end checkedUnsignedIntPtrOf: */; + src = firstIndexableField(srcOop); +l1: /* end checkedUnsignedIntPtrOf: */; + /* begin checkedUnsignedIntPtrOf: */ success(isWords(dstOop)); if (failed()) { dst = 0; goto l2; } - dst = ((unsigned int *) (firstIndexableField(dstOop))); - l2: /* end checkedUnsignedIntPtrOf: */; + dst = firstIndexableField(dstOop); +l2: /* end checkedUnsignedIntPtrOf: */; success((stSizeOf(dstOop)) == (w * h)); success((stSizeOf(dstOop)) == (((stSizeOf(srcOop)) * patchSize) * patchSize)); if (failed()) { @@ -271,7 +276,7 @@ primitiveMapFromToWidthHeightPatchSizeRgbFlagsShift(void) srcIndex = -1; for (y = 0; y < (h / patchSize); y += 1) { for (x = 0; x < (w / patchSize); x += 1) { - level = ((shiftAmount < 0) ? (((usqInt)((src[(srcIndex += 1)]))) >> (-shiftAmount)) : (((usqInt)((src[(srcIndex += 1)])) << shiftAmount))); + level = ((shiftAmount < 0) ? (((usqInt)((src[(srcIndex += 1)]))) >> (-shiftAmount)) : ((((usqInt)((src[(srcIndex += 1)])) << shiftAmount)))); if (level > 0xFF) { level = 0xFF; } @@ -303,12 +308,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -325,8 +329,8 @@ setInterpreter(struct VirtualMachine *anInterpreter) return ok; } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "StarSqueakPlugin"; diff --git a/src/plugins/UnicodePlugin/UnicodePlugin.c b/src/plugins/UnicodePlugin/UnicodePlugin.c index 40e7afec0b..6969b6d703 100644 --- a/src/plugins/UnicodePlugin/UnicodePlugin.c +++ b/src/plugins/UnicodePlugin/UnicodePlugin.c @@ -1,9 +1,9 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - UnicodePlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + UnicodePlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 */ -static char __buildInfo[] = "UnicodePlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f " __DATE__ ; +static char __buildInfo[] = "UnicodePlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 " __DATE__ ; #include "config.h" @@ -82,7 +82,7 @@ extern sqInt success(sqInt aBoolean); extern #endif struct VirtualMachine* interpreterProxy; -static const char *moduleName = "UnicodePlugin VMMaker.oscog-eem.3455 " INT_EXT; +static const char *moduleName = "UnicodePlugin VMMaker.oscog-eem.3456 " INT_EXT; /*** Methods ***/ @@ -105,7 +105,7 @@ copyStringintomax(sqInt stringOop, char *stringPtr, sqInt maxChars) success(0); return 0; } - srcPtr = ((char *) (firstIndexableField(stringOop))); + srcPtr = firstIndexableField(stringOop); for (i = 1; i <= count; i += 1) { *stringPtr++ = *srcPtr++; } @@ -143,7 +143,7 @@ primitiveClipboardGet(void) if (failed()) { return 0; } - utf16 = ((unsigned short *) (firstIndexableField(utf16Oop))); + utf16 = firstIndexableField(utf16Oop); utf16Length = 2 * (stSizeOf(utf16Oop)); count = unicodeClipboardGet(utf16, utf16Length); return methodReturnInteger(count); @@ -167,7 +167,7 @@ primitiveClipboardPut(void) if (failed()) { return 0; } - utf16 = ((unsigned short *) (firstIndexableField(strOop))); + utf16 = firstIndexableField(strOop); utf16Length = 2 * (stSizeOf(strOop)); if ((count >= 0) && (count < utf16Length)) { utf16Length = count; @@ -198,20 +198,22 @@ primitiveDrawString(void) sqInt w; utf8Oop = stackValue(3); + /* begin asCString: */ success(isBytes(utf8Oop)); utf8 = (failed() - ? ((char *) 0) - : firstIndexableField(utf8Oop)); + ? ((char *) 0) + : firstIndexableField(utf8Oop)); w = stackIntegerValue(2); h = stackIntegerValue(1); bitmapOop = stackValue(0); + /* begin cWordsPtr:minSize: */ success((isWords(bitmapOop)) && ((stSizeOf(bitmapOop)) >= (w * h))); bitmapPtr = ((void *) ((failed() - ? 0 - : firstIndexableField(bitmapOop)))); + ? 0 + : firstIndexableField(bitmapOop)))); if (failed()) { return null; } @@ -231,11 +233,12 @@ primitiveGetFontList(void) sqInt strOop; strOop = stackValue(0); + /* begin asCString: */ success(isBytes(strOop)); str = (failed() - ? ((char *) 0) - : firstIndexableField(strOop)); + ? ((char *) 0) + : firstIndexableField(strOop)); if (!(failed())) { strLength = stSizeOf(strOop); methodReturnInteger(unicodeGetFontList(str, strLength)); @@ -256,18 +259,20 @@ primitiveGetXRanges(void) sqInt utf8Oop; utf8Oop = stackValue(1); + /* begin asCString: */ success(isBytes(utf8Oop)); utf8 = (failed() - ? ((char *) 0) - : firstIndexableField(utf8Oop)); + ? ((char *) 0) + : firstIndexableField(utf8Oop)); resultOop = stackValue(0); + /* begin cWordsPtr:minSize: */ success((isWords(resultOop)) && ((stSizeOf(resultOop)) >= 0)); resultPtr = ((void *) ((failed() - ? 0 - : firstIndexableField(resultOop)))); + ? 0 + : firstIndexableField(resultOop)))); if (failed()) { return null; } @@ -289,11 +294,12 @@ primitiveMeasureString(void) sqInt w; utf8Oop = stackValue(0); + /* begin asCString: */ success(isBytes(utf8Oop)); utf8 = (failed() - ? ((char *) 0) - : firstIndexableField(utf8Oop)); + ? ((char *) 0) + : firstIndexableField(utf8Oop)); if (failed()) { return null; } @@ -364,12 +370,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -391,8 +396,8 @@ setInterpreter(struct VirtualMachine *anInterpreter) return ok; } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "UnicodePlugin"; diff --git a/src/plugins/UnixOSProcessPlugin/UnixOSProcessPlugin.c b/src/plugins/UnixOSProcessPlugin/UnixOSProcessPlugin.c index bbb715ffa6..30b8780ec2 100644 --- a/src/plugins/UnixOSProcessPlugin/UnixOSProcessPlugin.c +++ b/src/plugins/UnixOSProcessPlugin/UnixOSProcessPlugin.c @@ -1,9 +1,9 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - UnixOSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-eem.80 uuid: fb31a85b-5735-4fa9-bd48-0449646a9200 + UnixOSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-eem.81 uuid: 9b4cc8a5-4a9a-4dbb-92f1-f5290a13a66e */ -static char __buildInfo[] = "UnixOSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-eem.80 uuid: fb31a85b-5735-4fa9-bd48-0449646a9200 " __DATE__ ; +static char __buildInfo[] = "UnixOSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-eem.81 uuid: 9b4cc8a5-4a9a-4dbb-92f1-f5290a13a66e " __DATE__ ; /* D T Lewis - UnixOSProcessPlugin.c translated from class UnixOSProcessPlugin of OSProcessPlugin version 4.6.7 Cog */ @@ -229,7 +229,7 @@ static sqInt (*isIntegerObject)(sqInt objectPointer); #endif static sqInt (*methodArgumentCount)(void); static sqInt (*methodReturnInteger)(sqInt integer); -static sqInt (*methodReturnString)(char *aCString); +static sqInt (*methodReturnString)(const char *aCString); static sqInt (*methodReturnValue)(sqInt oop); static sqInt (*nilObject)(void); static sqInt (*pop)(sqInt nItems); @@ -274,7 +274,7 @@ extern sqInt isIntegerObject(sqInt objectPointer); #endif extern sqInt methodArgumentCount(void); extern sqInt methodReturnInteger(sqInt integer); -extern sqInt methodReturnString(char *aCString); +extern sqInt methodReturnString(const char *aCString); extern sqInt methodReturnValue(sqInt oop); extern sqInt nilObject(void); extern sqInt pop(sqInt nItems); @@ -297,7 +297,7 @@ extern sqInt trueObject(void); extern #endif struct VirtualMachine* interpreterProxy; -static const char *moduleName = "UnixOSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-eem.80 " INT_EXT; +static const char *moduleName = "UnixOSProcessPlugin VMConstruction-Plugins-OSProcessPlugin.oscog-eem.81 " INT_EXT; static void *originalSigHandlers[NSIG + 1]; static pid_t *pidArray = NULL; static sqInt pidCount; @@ -342,6 +342,7 @@ createPipeForReaderwriter(FILEHANDLETYPE *readerIOStreamPtr, FILEHANDLETYPE *wri int filedes[2]; if ((pipe(filedes)) == -1) { + /* Translates to a pipe() system call */ return 0; } @@ -368,6 +369,7 @@ cStringFromString(sqInt aString) sPtr = arrayValueOf(aString); len = sizeOfSTArrayFromCPrimitive(sPtr); + /* Space for a null terminated C string. */ cString = callocWrappersize(len + 1, 1); (char *) strncpy (cString, sPtr, len); @@ -411,9 +413,8 @@ dupToStdErr(sqInt anSQFileDataStructure) { int filenoToDup; - /* begin fileDescriptorFrom: */ - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(anSQFileDataStructure)) && ((byteSizeOf(anSQFileDataStructure)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(anSQFileDataStructure))))) @@ -422,7 +423,7 @@ dupToStdErr(sqInt anSQFileDataStructure) goto l1; } filenoToDup = ((int) (fileno(fileHandleFrom(anSQFileDataStructure)))); - l1: /* end fileDescriptorFrom: */; +l1: /* end fileDescriptorFrom: */; if (!(filenoToDup < 0)) { if (!(filenoToDup == 2)) { fflush(stderr); @@ -449,9 +450,8 @@ dupToStdIn(sqInt anSQFileDataStructure) { int filenoToDup; - /* begin fileDescriptorFrom: */ - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(anSQFileDataStructure)) && ((byteSizeOf(anSQFileDataStructure)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(anSQFileDataStructure))))) @@ -460,9 +460,9 @@ dupToStdIn(sqInt anSQFileDataStructure) goto l1; } filenoToDup = ((int) (fileno(fileHandleFrom(anSQFileDataStructure)))); - l1: /* end fileDescriptorFrom: */; +l1: /* end fileDescriptorFrom: */; if (!(filenoToDup < 0)) { - if (!(filenoToDup == 0)) { + if (filenoToDup) { fflush(stdin); dup2(filenoToDup, 0); rewind(stdin); @@ -488,9 +488,8 @@ dupToStdOut(sqInt anSQFileDataStructure) { int filenoToDup; - /* begin fileDescriptorFrom: */ - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(anSQFileDataStructure)) && ((byteSizeOf(anSQFileDataStructure)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(anSQFileDataStructure))))) @@ -499,7 +498,7 @@ dupToStdOut(sqInt anSQFileDataStructure) goto l1; } filenoToDup = ((int) (fileno(fileHandleFrom(anSQFileDataStructure)))); - l1: /* end fileDescriptorFrom: */; +l1: /* end fileDescriptorFrom: */; if (!(filenoToDup < 0)) { if (!(filenoToDup == 1)) { fflush(stdout); @@ -523,18 +522,19 @@ environmentAtAsType(sqInt classIdentifier) index = stackIntegerValue(0); if (!(failed())) { + /* Count number of environment variables. */ p = getEnvironmentVector(); - if (p == null) { - primitiveFail(); - } - else { + if (p) { q = p; envCnt = 0; while (*q++) envCnt++; methodReturnValue((((index >= 1) && (index <= envCnt)) - ? cStringasCollection(p[index - 1], classIdentifier) - : nilObject())); + ? cStringasCollection(p[index - 1], classIdentifier) + : nilObject())); + } + else { + primitiveFail(); } } return 0; @@ -577,7 +577,7 @@ fixPointersInArrayOfStringswithOffsets(sqInt flattenedStrings, sqInt offsets) sqInt val; count = stSizeOf(offsets); - offsetArray = ((sqInt *) (firstIndexableField(offsets))); + offsetArray = firstIndexableField(offsets); sz = ((usqInt)(byteSizeOf(flattenedStrings))); if ((count * (sizeof(char *))) >= sz) { primitiveFailFor(PrimErrBadArgument); @@ -594,12 +594,12 @@ fixPointersInArrayOfStringswithOffsets(sqInt flattenedStrings, sqInt offsets) ptr[idx] = ((((char *) ptr)) + val); idx += 1; } - if ((ptr[idx]) != 0) { + if (ptr[idx]) { primitiveFailFor(PrimErrBadArgument); } return (failed() - ? 0 - : ptr); + ? 0 + : ptr); } @@ -667,7 +667,6 @@ forkAndExecInDirectory(sqInt useSignalHandler) sqInt envVecBuffer; sqInt executableFile; sqInt fd; - sqInt fdLimiT; struct itimerval intervalTimer; pid_t pid; char *progNamePtr; @@ -677,6 +676,7 @@ forkAndExecInDirectory(sqInt useSignalHandler) sqInt stdErr; sqInt stdIn; sqInt stdOut; + sqInt toDoLimit; sqInt workingDir; if ((methodArgumentCount()) != 9) { @@ -707,11 +707,13 @@ forkAndExecInDirectory(sqInt useSignalHandler) intervalTimer.it_value.tv_sec = 0; intervalTimer.it_value.tv_usec = 0; setitimer (ITIMER_REAL, &intervalTimer, &saveIntervalTimer); - if (((pid = vfork())) != 0) { + if ((pid = vfork())) { + /* Normal return to Smalltalk - this is the old parent process. */ /* Enable the timer again before resuming Smalltalk. */ setitimer (ITIMER_REAL, &saveIntervalTimer, 0L); if (!(failed())) { + /* Pop 9 arguments plus receiver, push pid. */ pop(10); pushInteger(pid); @@ -726,12 +728,13 @@ forkAndExecInDirectory(sqInt useSignalHandler) fprintf(stderr, "bad workingDir parameter\n"); _exit(-1); } - if ((chdir(pwdPtr)) != 0) { + if (chdir(pwdPtr)) { primitiveFailFor(PrimErrNotFound); perror("chdir"); _exit(-1); } } + /* Dup the file handles to attach the new child process to the right streams on descriptors 0, 1 and 2. */ progNamePtr = arrayValueOf(executableFile); @@ -744,7 +747,8 @@ forkAndExecInDirectory(sqInt useSignalHandler) if (!(stdIn == (nilObject()))) { dupToStdIn(stdIn); } - for (fd = 3, fdLimiT = ((getdtablesize()) - 1); fd <= fdLimiT; fd += 1) { + toDoLimit = (getdtablesize()) - 1; + for (fd = 3; fd <= toDoLimit; fd += 1) { close(fd); } if (envVecBuffer == (nilObject())) { @@ -759,6 +763,7 @@ forkAndExecInDirectory(sqInt useSignalHandler) perror("bad env or bad args"); _exit(-1); } + /* begin restoreDefaultSignalHandlers */ sigNum = 1; while (sigNum <= (signalArraySize())) { @@ -840,6 +845,7 @@ forkSqueak(sqInt useSignalHandler) if (useSignalHandler) { setSigChldHandler(); } + /* Enable the timer again before resuming Smalltalk. */ pid = fork(); setitimer (ITIMER_REAL, &saveIntervalTimer, 0L); @@ -866,26 +872,29 @@ forwardSignaltoSemaphoreAt(sqInt sigNum, sqInt semaphoreIndex) { void *oldHandler; - if (semaphoreIndex == 0) { + if (!semaphoreIndex) { + /* Disable the handler */ - if ((semaIndices[sigNum]) != 0) { + if (semaIndices[sigNum]) { oldHandler = (originalSignalHandlers())[sigNum]; oldHandler = setSignalNumberhandler(sigNum, oldHandler); semaIndices[sigNum] = 0; return oldHandler; } else { + /* either -1 for printAllStacks or a positive integer for semaphore forwarding */ /* Signal handler had not been set, answer an error */ - return SIG_ERR /* begin sigErrorNumber */; + return SIG_ERR /* sigErrorNumber */; } } if ((semaIndices[sigNum]) > 0) { + /* Handler is already set, answer an error */ - return SIG_ERR /* begin sigErrorNumber */; + return SIG_ERR /* sigErrorNumber */; } - oldHandler = setSignalNumberhandler(sigNum, handleSignal /* begin handleSignalFunctionAddress */); - if (oldHandler != SIG_ERR /* begin sigErrorNumber */) { + oldHandler = setSignalNumberhandler(sigNum, handleSignal /* handleSignalFunctionAddress */); + if (oldHandler != SIG_ERR /* sigErrorNumber */) { (originalSignalHandlers())[sigNum] = oldHandler; semaIndices[sigNum] = semaphoreIndex; } @@ -906,34 +915,33 @@ getCurrentWorkingDirectoryAsType(sqInt classIdentifier) sqInt incrementBy; sqInt len; sqInt maxSize; - sqInt newString; bufferSize = 100; incrementBy = 100; maxSize = 5000; while (1) { cwdString = instantiateClassindexableSize(classString(), bufferSize); - if (cwdString == null) { + if (!cwdString) { primitiveFailFor(PrimErrNoMemory); } buffer = arrayValueOf(cwdString); + /* getcwd(buffer, bufferSize) */ cwd = getcwd(buffer, bufferSize); if (!((cwd == 0) && (bufferSize < maxSize))) break; bufferSize += incrementBy; } - if (cwd == 0) { - primitiveFail(); - } - else { + if (cwd) { /* begin cString:asCollection: */ len = strlen(cwd); - newString = instantiateClassindexableSize(classIdentifier, len); - strncpy(arrayValueOf(newString), cwd, len); - cwdString = newString; + cwdString = instantiateClassindexableSize(classIdentifier, len); + strncpy(arrayValueOf(cwdString), cwd, len); methodReturnValue(cwdString); } + else { + primitiveFail(); + } return 0; } @@ -957,7 +965,8 @@ getEnvironmentVector(void) if (!ptr) { func = ioLoadFunctionFrom("ioGetEnvVec", ""); - if (!(func == null)) { + if (func) { + /* RThis is a hack under simulation; ioLoadFunction:From: answers 0, which is not nil, but only in simulation... */ ptr = ((char ** (*) (void)) func)(); } @@ -994,7 +1003,7 @@ getStdHandle(sqInt n) sqInt validMask; validMask = sqFileStdioHandlesInto(fileRecords); - if ((validMask & (1U << n)) == 0) { + if (!(validMask & (1U << n))) { return primitiveFailFor(PrimErrUnsupported); } fileOop = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); @@ -1017,7 +1026,7 @@ getStdHandle(sqInt n) static void handleSignal(int sigNum) { - int semaIndex; + int semaIndex; semaIndex = semaIndices[sigNum]; forwardSignaltoSemaphoreAt(sigNum, semaIndex); @@ -1069,7 +1078,7 @@ isNonNullSQFile(sqInt objectPointer) sqFileBytes = arrayValueOf(objectPointer); idx = 0; while (idx < (sizeof(SQFile))) { - if ((sqFileBytes[idx]) != 0) { + if (sqFileBytes[idx]) { return 1; } idx += 1; @@ -1105,8 +1114,10 @@ makePipeForReaderwriter(FILEHANDLETYPE *readerIOStreamPtr, FILEHANDLETYPE *write int filedes[2]; /* begin setSigPipeHandler */ - setSignalNumberhandler(SIGPIPE /* begin sigPipeNumber */, SIG_IGN /* begin sigIgnoreNumber */); + /* begin setSigPipeIgnore */ + setSignalNumberhandler(SIGPIPE /* sigPipeNumber */, SIG_IGN /* sigIgnoreNumber */); if ((pipe(filedes)) == -1) { + /* Translates to a pipe() system call */ return 0; } @@ -1166,6 +1177,7 @@ needSigaltstack(void) useSignalStack = 0; return 0; } + /* Now see if there's already a sigaltstack in place */ useSignalStack = 1; if ((sigaltstack(0, (&sigstack))) < 0) { @@ -1245,29 +1257,29 @@ primitiveArgumentAt(void) sqInt classIdentifier; sqInt index; sqInt len; - sqInt newString; sqInt s; char *sPtr; classIdentifier = classString(); + /* begin argumentAtAsType: */ index = stackIntegerValue(0); if (failed()) { - goto l2; + goto l1; } if ((index > argCnt) || (index < 1)) { popthenPush(2, nilObject()); } else { sPtr = argVec[index - 1]; + /* begin cString:asCollection: */ len = strlen(sPtr); - newString = instantiateClassindexableSize(classIdentifier, len); - strncpy(arrayValueOf(newString), sPtr, len); - s = newString; + s = instantiateClassindexableSize(classIdentifier, len); + strncpy(arrayValueOf(s), sPtr, len); popthenPush(2, s); } - l2: /* end argumentAtAsType: */; +l1: /* end argumentAtAsType: */; return 0; } @@ -1284,29 +1296,29 @@ primitiveArgumentAtAsBytes(void) sqInt classIdentifier; sqInt index; sqInt len; - sqInt newString; sqInt s; char *sPtr; classIdentifier = classByteArray(); + /* begin argumentAtAsType: */ index = stackIntegerValue(0); if (failed()) { - goto l2; + goto l1; } if ((index > argCnt) || (index < 1)) { popthenPush(2, nilObject()); } else { sPtr = argVec[index - 1]; + /* begin cString:asCollection: */ len = strlen(sPtr); - newString = instantiateClassindexableSize(classIdentifier, len); - strncpy(arrayValueOf(newString), sPtr, len); - s = newString; + s = instantiateClassindexableSize(classIdentifier, len); + strncpy(arrayValueOf(s), sPtr, len); popthenPush(2, s); } - l2: /* end argumentAtAsType: */; +l1: /* end argumentAtAsType: */; return 0; } @@ -1332,11 +1344,11 @@ primitiveCanReceiveSignals(void) pidToSignal = stackIntegerValue(0); result = kill(pidToSignal, 0); pop(2); - if (result == 0) { - push(trueObject()); + if (result) { + push(falseObject()); } else { - push(falseObject()); + push(trueObject()); } } else { @@ -1393,13 +1405,14 @@ primitiveConfstr(void) if (failed()) { return primitiveFailFor(PrimErrBadArgument); } + /* Find required buffer size */ bufferSize = confstr(optionIndex, 0, 0); - if (bufferSize == 0) { + if (!bufferSize) { return popthenPush(2, nilObject()); } bufferString = instantiateClassindexableSize(classString(), bufferSize); - buffer = ((char *) (firstIndexableField(bufferString))); + buffer = firstIndexableField(bufferString); result = confstr(optionIndex, buffer, bufferSize); popthenPush(2, stringFromCString(buffer)); return 0; @@ -1431,7 +1444,6 @@ primitiveCreatePipe(void) FILEHANDLETYPE *writerIOStreamPtr; SQFile *writerPtr; - /* Create the anonymous OS pipe */ thisSession = getThisSessionID(); readerIOStreamPtr = (&readerIOStream); @@ -1440,6 +1452,7 @@ primitiveCreatePipe(void) return primitiveFail(); } writer = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); + /* begin fileValueOf: */ writerPtr = arrayValueOf(writer); writerPtr->file = writerIOStream; @@ -1448,6 +1461,7 @@ primitiveCreatePipe(void) writerPtr->lastOp = 0; pushRemappableOop(writer); reader = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); + /* begin fileValueOf: */ readerPtr = arrayValueOf(reader); readerPtr->file = readerIOStream; @@ -1493,7 +1507,6 @@ primitiveCreatePipeWithSessionIdentifier(void) FILEHANDLETYPE *writerIOStreamPtr; SQFile *writerPtr; - /* Create the anonymous OS pipe */ thisSession = sessionIdentifierFrom(stackObjectValue(0)); readerIOStreamPtr = (&readerIOStream); @@ -1502,6 +1515,7 @@ primitiveCreatePipeWithSessionIdentifier(void) return primitiveFail(); } writer = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); + /* begin fileValueOf: */ writerPtr = arrayValueOf(writer); writerPtr->file = writerIOStream; @@ -1510,6 +1524,7 @@ primitiveCreatePipeWithSessionIdentifier(void) writerPtr->lastOp = 0; pushRemappableOop(writer); reader = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); + /* begin fileValueOf: */ readerPtr = arrayValueOf(reader); readerPtr->file = readerIOStream; @@ -1599,15 +1614,16 @@ primitiveEnvironmentAtSymbol(void) char * getenvResult; classIdentifier = classString(); + /* begin environmentAtSymbolAsType: */ getenvResult = getenv(transientCStringFromString(stackObjectValue(0))); - if (getenvResult == 0) { - return primitiveFail(); - } - else { + if (getenvResult) { pop(2); push(cStringasCollection(getenvResult, classIdentifier)); } + else { + return primitiveFail(); + } return null; } @@ -1623,15 +1639,16 @@ primitiveEnvironmentAtSymbolAsBytes(void) char * getenvResult; classIdentifier = classByteArray(); + /* begin environmentAtSymbolAsType: */ getenvResult = getenv(transientCStringFromString(stackObjectValue(0))); - if (getenvResult == 0) { - return primitiveFail(); - } - else { + if (getenvResult) { pop(2); push(cStringasCollection(getenvResult, classIdentifier)); } + else { + return primitiveFail(); + } return null; } @@ -1682,7 +1699,11 @@ primitiveFileProtectionMask(void) statBuf = arrayValueOf(buffer); path = transientCStringFromString(stackObjectValue(0)); mode = stat(path, statBuf); - if (mode == 0) { + if (mode) { + pop(2); + pushInteger(errno); + } + else { mode = statBuf->st_mode; result = instantiateClassindexableSize(classArray(), 4); stObjectatput(result, 4, integerObjectOf(mode & 07)); @@ -1692,10 +1713,6 @@ primitiveFileProtectionMask(void) pop(2); push(result); } - else { - pop(2); - pushInteger(errno); - } return 0; } @@ -1742,7 +1759,11 @@ primitiveFileStat(void) statBuf = arrayValueOf(buffer); path = transientCStringFromString(stackObjectValue(0)); mode = stat(path, statBuf); - if (mode == 0) { + if (mode) { + pop(2); + pushInteger(errno); + } + else { mode = statBuf->st_mode; stObjectatput(mask, 4, integerObjectOf(mode & 07)); stObjectatput(mask, 3, integerObjectOf((mode & 070) >> 3)); @@ -1754,10 +1775,6 @@ primitiveFileStat(void) pop(2); push(result); } - else { - pop(2); - pushInteger(errno); - } return 0; } @@ -1962,7 +1979,7 @@ primitiveForwardSignalToSemaphore(void) return; } handler = forwardSignaltoSemaphoreAt(sigNum, semaphoreIndex); - if (handler == SIG_ERR /* begin sigErrorNumber */) { + if (handler == SIG_ERR /* sigErrorNumber */) { primitiveFail(); return; } @@ -2000,8 +2017,9 @@ primitiveFpathconf(void) return primitiveFailFor(PrimErrBadArgument); } aSQFileByteArray = stackValue(1); + /* begin fileDescriptorFrom: */ - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(aSQFileByteArray)) && ((byteSizeOf(aSQFileByteArray)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(aSQFileByteArray))))) @@ -2010,7 +2028,7 @@ primitiveFpathconf(void) goto l1; } fd = ((int) (fileno(fileHandleFrom(aSQFileByteArray)))); - l1: /* end fileDescriptorFrom: */; +l1: /* end fileDescriptorFrom: */; if (fd < 0) { return primitiveFailFor(PrimErrBadArgument); } @@ -2176,6 +2194,7 @@ primitiveGetSession(void) return primitiveFail(); } charArray1 = ((void *) ((unsigned char *)&thisSessionID)); + /* begin copyBytesFrom:to:length: */ memcpy(sessionByteArrayPointer, charArray1, sessionIDSize); popthenPush(1, sessionOop); @@ -2209,6 +2228,7 @@ primitiveGetStdErrHandleWithSessionIdentifier(void) SESSIONIDENTIFIERTYPE thisSession; fileOop = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); + /* begin fileValueOf: */ file = arrayValueOf(fileOop); thisSession = sessionIdentifierFrom(stackObjectValue(0)); @@ -2248,6 +2268,7 @@ primitiveGetStdInHandleWithSessionIdentifier(void) SESSIONIDENTIFIERTYPE thisSession; fileOop = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); + /* begin fileValueOf: */ file = arrayValueOf(fileOop); thisSession = sessionIdentifierFrom(stackObjectValue(0)); @@ -2287,6 +2308,7 @@ primitiveGetStdOutHandleWithSessionIdentifier(void) SESSIONIDENTIFIERTYPE thisSession; fileOop = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); + /* begin fileValueOf: */ file = arrayValueOf(fileOop); thisSession = sessionIdentifierFrom(stackObjectValue(0)); @@ -2347,7 +2369,7 @@ primitiveIsAtEndOfFile(void) sqInt sqFileOop; sqFileOop = stackValue(0); - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(sqFileOop)) && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop))))) @@ -2355,7 +2377,7 @@ primitiveIsAtEndOfFile(void) return primitiveFail(); } file = fileHandleFrom(sqFileOop); - if (file == 0) { + if (!file) { return primitiveFail(); } if (feof(file)) { @@ -2390,15 +2412,15 @@ primitiveKillOnExit(void) if (failed()) { return null; } - if (!(pidArray == 0)) { + if (pidArray) { free(pidArray); } pidArray = malloc(pidCount * sizeof(pid_t)); - if (pidArray == 0) { + if (!pidArray) { pidCount = 0; return primitiveFail(); } - pidPointer = ((sqInt *) (firstIndexableField(pids))); + pidPointer = firstIndexableField(pids); count = 0; p = pidArray; while (count <= pidCount) { @@ -2451,7 +2473,7 @@ primitiveLockFileRegion(void) if (failed()) { return; } - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(sqFileOop)) && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop))))) @@ -2460,6 +2482,7 @@ primitiveLockFileRegion(void) return; } fileHandle = fileHandleFrom(sqFileOop); + /* begin unixFileNumber: */ fileNo = ((int) (fileno(fileHandle))); if (exclusive) { @@ -2502,7 +2525,6 @@ primitiveMakePipe(void) FILEHANDLETYPE *writerIOStreamPtr; SQFile *writerPtr; - /* Create the anonymous OS pipe */ thisSession = getThisSessionID(); readerIOStreamPtr = (&readerIOStream); @@ -2511,6 +2533,7 @@ primitiveMakePipe(void) return primitiveFail(); } writer = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); + /* begin fileValueOf: */ writerPtr = arrayValueOf(writer); writerPtr->file = writerIOStream; @@ -2519,6 +2542,7 @@ primitiveMakePipe(void) writerPtr->lastOp = 0; pushRemappableOop(writer); reader = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); + /* begin fileValueOf: */ readerPtr = arrayValueOf(reader); readerPtr->file = readerIOStream; @@ -2565,7 +2589,6 @@ primitiveMakePipeWithSessionIdentifier(void) FILEHANDLETYPE *writerIOStreamPtr; SQFile *writerPtr; - /* Create the anonymous OS pipe */ thisSession = sessionIdentifierFrom(stackObjectValue(0)); readerIOStreamPtr = (&readerIOStream); @@ -2574,6 +2597,7 @@ primitiveMakePipeWithSessionIdentifier(void) return primitiveFail(); } writer = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); + /* begin fileValueOf: */ writerPtr = arrayValueOf(writer); writerPtr->file = writerIOStream; @@ -2582,6 +2606,7 @@ primitiveMakePipeWithSessionIdentifier(void) writerPtr->lastOp = 0; pushRemappableOop(writer); reader = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); + /* begin fileValueOf: */ readerPtr = arrayValueOf(reader); readerPtr->file = readerIOStream; @@ -2633,8 +2658,9 @@ primitiveNice(void) errno = 0; result = nice(niceIncrement); if (result == -1) { + /* sys call may have failed, test errno to be sure */ - if (!(errno == 0)) { + if (errno) { return primitiveFail(); } } @@ -2688,14 +2714,15 @@ primitivePutEnv(void) keyValueString = stackObjectValue(0); cStringPtr = cStringFromString(keyValueString); - if ((putenv(cStringPtr)) == 0) { + if (putenv(cStringPtr)) { + return primitiveFail(); + } + else { + /* Set environment variable. */ pop(2); push(keyValueString); } - else { - return primitiveFail(); - } return 0; } @@ -2739,7 +2766,6 @@ primitiveReapChildProcess(void) sqInt resultArray; sqInt status; - /* Force C code translator to declare the variable */ exitStatus = 0; pidToHandle = stackIntegerValue(0); @@ -2749,11 +2775,12 @@ primitiveReapChildProcess(void) push(nilObject()); } else { + /* Answer an array with pid and result status */ pid = integerObjectOf(pidResult); status = integerObjectOf(exitStatus); resultArray = instantiateClassindexableSize(classArray(), 2); - arrayPtr = ((sqInt *) (firstIndexableField(resultArray))); + arrayPtr = firstIndexableField(resultArray); arrayPtr[0] = pid; arrayPtr[1] = status; pop(2); @@ -2804,7 +2831,7 @@ primitiveSendSigabrtTo(void) else { if (isIntegerObject(stackValue(0))) { pidToSignal = stackIntegerValue(0); - result = kill(pidToSignal, SIGABRT /* begin sigAbrtNumber */); + result = kill(pidToSignal, SIGABRT /* sigAbrtNumber */); pop(2); pushInteger(result); } @@ -2840,7 +2867,7 @@ primitiveSendSigalrmTo(void) else { if (isIntegerObject(stackValue(0))) { pidToSignal = stackIntegerValue(0); - result = kill(pidToSignal, SIGALRM /* begin sigAlrmNumber */); + result = kill(pidToSignal, SIGALRM /* sigAlrmNumber */); pop(2); pushInteger(result); } @@ -2877,7 +2904,7 @@ primitiveSendSigchldTo(void) else { if (isIntegerObject(stackValue(0))) { pidToSignal = stackIntegerValue(0); - result = kill(pidToSignal, SIGCHLD /* begin sigChldNumber */); + result = kill(pidToSignal, SIGCHLD /* sigChldNumber */); pop(2); pushInteger(result); } @@ -2913,7 +2940,7 @@ primitiveSendSigcontTo(void) else { if (isIntegerObject(stackValue(0))) { pidToSignal = stackIntegerValue(0); - result = kill(pidToSignal, SIGCONT /* begin sigContNumber */); + result = kill(pidToSignal, SIGCONT /* sigContNumber */); pop(2); pushInteger(result); } @@ -2948,7 +2975,7 @@ primitiveSendSighupTo(void) else { if (isIntegerObject(stackValue(0))) { pidToSignal = stackIntegerValue(0); - result = kill(pidToSignal, SIGHUP /* begin sigHupNumber */); + result = kill(pidToSignal, SIGHUP /* sigHupNumber */); pop(2); pushInteger(result); } @@ -2984,7 +3011,7 @@ primitiveSendSigintTo(void) else { if (isIntegerObject(stackValue(0))) { pidToSignal = stackIntegerValue(0); - result = kill(pidToSignal, SIGINT /* begin sigIntNumber */); + result = kill(pidToSignal, SIGINT /* sigIntNumber */); pop(2); pushInteger(result); } @@ -3020,7 +3047,7 @@ primitiveSendSigkillTo(void) else { if (isIntegerObject(stackValue(0))) { pidToSignal = stackIntegerValue(0); - result = kill(pidToSignal, SIGKILL /* begin sigKillNumber */); + result = kill(pidToSignal, SIGKILL /* sigKillNumber */); pop(2); pushInteger(result); } @@ -3056,7 +3083,7 @@ primitiveSendSigpipeTo(void) else { if (isIntegerObject(stackValue(0))) { pidToSignal = stackIntegerValue(0); - result = kill(pidToSignal, SIGPIPE /* begin sigPipeNumber */); + result = kill(pidToSignal, SIGPIPE /* sigPipeNumber */); pop(2); pushInteger(result); } @@ -3091,7 +3118,7 @@ primitiveSendSigquitTo(void) else { if (isIntegerObject(stackValue(0))) { pidToSignal = stackIntegerValue(0); - result = kill(pidToSignal, SIGQUIT /* begin sigQuitNumber */); + result = kill(pidToSignal, SIGQUIT /* sigQuitNumber */); pop(2); pushInteger(result); } @@ -3127,7 +3154,7 @@ primitiveSendSigstopTo(void) else { if (isIntegerObject(stackValue(0))) { pidToSignal = stackIntegerValue(0); - result = kill(pidToSignal, SIGSTOP /* begin sigStopNumber */); + result = kill(pidToSignal, SIGSTOP /* sigStopNumber */); pop(2); pushInteger(result); } @@ -3163,7 +3190,7 @@ primitiveSendSigtermTo(void) else { if (isIntegerObject(stackValue(0))) { pidToSignal = stackIntegerValue(0); - result = kill(pidToSignal, SIGTERM /* begin sigTermNumber */); + result = kill(pidToSignal, SIGTERM /* sigTermNumber */); pop(2); pushInteger(result); } @@ -3199,7 +3226,7 @@ primitiveSendSigusr1To(void) else { if (isIntegerObject(stackValue(0))) { pidToSignal = stackIntegerValue(0); - result = kill(pidToSignal, SIGUSR1 /* begin sigUsr1Number */); + result = kill(pidToSignal, SIGUSR1 /* sigUsr1Number */); pop(2); pushInteger(result); } @@ -3235,7 +3262,7 @@ primitiveSendSigusr2To(void) else { if (isIntegerObject(stackValue(0))) { pidToSignal = stackIntegerValue(0); - result = kill(pidToSignal, SIGUSR2 /* begin sigUsr2Number */); + result = kill(pidToSignal, SIGUSR2 /* sigUsr2Number */); pop(2); pushInteger(result); } @@ -3339,7 +3366,7 @@ EXPORT(sqInt) primitiveSigChldNumber(void) { pop(1); - pushInteger(SIGCHLD /* begin sigChldNumber */); + pushInteger(SIGCHLD /* sigChldNumber */); return 0; } @@ -3351,7 +3378,7 @@ EXPORT(sqInt) primitiveSigHupNumber(void) { pop(1); - pushInteger(SIGHUP /* begin sigHupNumber */); + pushInteger(SIGHUP /* sigHupNumber */); return 0; } @@ -3363,7 +3390,7 @@ EXPORT(sqInt) primitiveSigIntNumber(void) { pop(1); - pushInteger(SIGINT /* begin sigIntNumber */); + pushInteger(SIGINT /* sigIntNumber */); return 0; } @@ -3375,7 +3402,7 @@ EXPORT(sqInt) primitiveSigKillNumber(void) { pop(1); - pushInteger(SIGKILL /* begin sigKillNumber */); + pushInteger(SIGKILL /* sigKillNumber */); return 0; } @@ -3387,7 +3414,7 @@ EXPORT(sqInt) primitiveSigPipeNumber(void) { pop(1); - pushInteger(SIGPIPE /* begin sigPipeNumber */); + pushInteger(SIGPIPE /* sigPipeNumber */); return 0; } @@ -3399,7 +3426,7 @@ EXPORT(sqInt) primitiveSigQuitNumber(void) { pop(1); - pushInteger(SIGQUIT /* begin sigQuitNumber */); + pushInteger(SIGQUIT /* sigQuitNumber */); return 0; } @@ -3411,7 +3438,7 @@ EXPORT(sqInt) primitiveSigTermNumber(void) { pop(1); - pushInteger(SIGTERM /* begin sigTermNumber */); + pushInteger(SIGTERM /* sigTermNumber */); return 0; } @@ -3423,7 +3450,7 @@ EXPORT(sqInt) primitiveSigUsr1Number(void) { pop(1); - pushInteger(SIGUSR1 /* begin sigUsr1Number */); + pushInteger(SIGUSR1 /* sigUsr1Number */); return 0; } @@ -3435,7 +3462,7 @@ EXPORT(sqInt) primitiveSigUsr2Number(void) { pop(1); - pushInteger(SIGUSR2 /* begin sigUsr2Number */); + pushInteger(SIGUSR2 /* sigUsr2Number */); return 0; } @@ -3489,12 +3516,13 @@ primitiveSpaceForByteSizeInDirectoryPath(void) return primitiveFail(); } blockSize = buf.f_bsize; + /* simulation default 10MB */ freeBlocks = buf.f_bavail; requiredBlocks = (1 + bytesRequired) / blockSize; fileSystemFull = (freeBlocks >= requiredBlocks - ? trueObject() - : falseObject()); + ? trueObject() + : falseObject()); popthenPush(3, fileSystemFull); return 0; } @@ -3516,7 +3544,7 @@ primitiveSQFileFlush(void) sqInt sqFileOop; sqFileOop = stackValue(0); - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(sqFileOop)) && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop))))) @@ -3551,7 +3579,7 @@ primitiveSQFileFlushWithSessionIdentifier(void) sqInt sqFileOop; sqFileOop = stackValue(1); - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(sqFileOop)) && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop))))) @@ -3579,15 +3607,16 @@ primitiveSQFileSetBlocking(void) sqInt sqFileOop; sqFileOop = stackValue(0); - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(sqFileOop)) && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop))))) && (isNonNullSQFile(sqFileOop)))) { return primitiveFail(); } + /* begin fileDescriptorFrom: */ - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(sqFileOop)) && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop))))) @@ -3596,7 +3625,7 @@ primitiveSQFileSetBlocking(void) goto l1; } descriptor = ((int) (fileno(fileHandleFrom(sqFileOop)))); - l1: /* end fileDescriptorFrom: */; +l1: /* end fileDescriptorFrom: */; if (descriptor == -1) { return primitiveFail(); } @@ -3628,7 +3657,7 @@ primitiveSQFileSetBlockingWithSessionIdentifier(void) SESSIONIDENTIFIERTYPE thisSession; sqFileOop = stackValue(1); - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(sqFileOop)) && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop))))) @@ -3639,7 +3668,7 @@ primitiveSQFileSetBlockingWithSessionIdentifier(void) thisSession = sessionIdentifierFrom(stackObjectValue(0)); if (thisSession == (sqFile->sessionID)) { /* begin fileDescriptorFrom: */ - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(sqFileOop)) && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop))))) @@ -3648,7 +3677,7 @@ primitiveSQFileSetBlockingWithSessionIdentifier(void) goto l1; } descriptor = ((int) (fileno(fileHandleFrom(sqFileOop)))); - l1: /* end fileDescriptorFrom: */; +l1: /* end fileDescriptorFrom: */; if (descriptor < 0) { return primitiveFail(); } @@ -3678,15 +3707,16 @@ primitiveSQFileSetNonBlocking(void) sqInt sqFileOop; sqFileOop = stackValue(0); - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(sqFileOop)) && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop))))) && (isNonNullSQFile(sqFileOop)))) { return primitiveFail(); } + /* begin fileDescriptorFrom: */ - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(sqFileOop)) && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop))))) @@ -3695,7 +3725,7 @@ primitiveSQFileSetNonBlocking(void) goto l1; } descriptor = ((int) (fileno(fileHandleFrom(sqFileOop)))); - l1: /* end fileDescriptorFrom: */; +l1: /* end fileDescriptorFrom: */; if (descriptor < 0) { return primitiveFail(); } @@ -3727,7 +3757,7 @@ primitiveSQFileSetNonBlockingWithSessionIdentifier(void) SESSIONIDENTIFIERTYPE thisSession; sqFileOop = stackValue(1); - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(sqFileOop)) && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop))))) @@ -3738,7 +3768,7 @@ primitiveSQFileSetNonBlockingWithSessionIdentifier(void) thisSession = sessionIdentifierFrom(stackObjectValue(0)); if (thisSession == (sqFile->sessionID)) { /* begin fileDescriptorFrom: */ - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(sqFileOop)) && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop))))) @@ -3747,7 +3777,7 @@ primitiveSQFileSetNonBlockingWithSessionIdentifier(void) goto l1; } descriptor = ((int) (fileno(fileHandleFrom(sqFileOop)))); - l1: /* end fileDescriptorFrom: */; +l1: /* end fileDescriptorFrom: */; if (descriptor < 0) { return primitiveFail(); } @@ -3781,7 +3811,7 @@ primitiveSQFileSetUnbuffered(void) sqInt sqFileOop; sqFileOop = stackValue(0); - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(sqFileOop)) && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop))))) @@ -3820,7 +3850,7 @@ primitiveSQFileSetUnbufferedWithSessionIdentifier(void) SESSIONIDENTIFIERTYPE thisSession; sqFileOop = stackValue(1); - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(sqFileOop)) && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop))))) @@ -3883,7 +3913,7 @@ primitiveTestEndOfFileFlag(void) sqInt sqFileOop; sqFileOop = stackValue(0); - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(sqFileOop)) && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop))))) @@ -3891,7 +3921,7 @@ primitiveTestEndOfFileFlag(void) return primitiveFail(); } file = fileHandleFrom(sqFileOop); - if (file == 0) { + if (!file) { return primitiveFail(); } if (feof(file)) { @@ -3949,7 +3979,7 @@ primitiveTestLockableFileRegion(void) len = stackIntegerValue(1); start = stackIntegerValue(2); sqFileOop = stackValue(3); - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(sqFileOop)) && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop))))) @@ -3957,6 +3987,7 @@ primitiveTestLockableFileRegion(void) return primitiveFail(); } fileHandle = fileHandleFrom(sqFileOop); + /* begin unixFileNumber: */ fileNo = ((int) (fileno(fileHandle))); if (exclusive) { @@ -4027,7 +4058,7 @@ primitiveUnixFileNumber(void) sqInt sqFileOop; sqFileOop = stackValue(0); - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(sqFileOop)) && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop))))) @@ -4035,6 +4066,7 @@ primitiveUnixFileNumber(void) return primitiveFail(); } fileHandle = fileHandleFrom(sqFileOop); + /* begin unixFileNumber: */ fileNo = ((int) (fileno(fileHandle))); pop(2); @@ -4071,7 +4103,7 @@ primitiveUnlockFileRegion(void) len = stackIntegerValue(0); start = stackIntegerValue(1); sqFileOop = stackValue(2); - if (!( /* begin isSQFileObject: */ + if (!(/* isSQFileObject: */ (((isBytes(sqFileOop)) && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile)))) && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop))))) @@ -4079,6 +4111,7 @@ primitiveUnlockFileRegion(void) return primitiveFail(); } fileHandle = fileHandleFrom(sqFileOop); + /* begin unixFileNumber: */ fileNo = ((int) (fileno(fileHandle))); lockStruct.l_type = F_UNLCK; @@ -4131,7 +4164,6 @@ realpathAsType(sqInt classIdentifier) sqInt bufferSize; sqInt len; sqInt newPathString; - sqInt newString; char *pathString; char * realpathResult; sqInt s; @@ -4143,22 +4175,22 @@ realpathAsType(sqInt classIdentifier) newPathString = popRemappableOop(); buffer = arrayValueOf(newPathString); realpathResult = realpath(pathString, buffer); - if (realpathResult == 0) { - return primitiveFail(); - } - else { + if (realpathResult) { if ((strlen(realpathResult)) >= 0x400) { perror("warning: statically allocated array exceeded in UnixOSProcessPlugin>>primitiveRealPath, object memory may have been corrupted"); return primitiveFail(); } + /* begin cString:asCollection: */ len = strlen(realpathResult); - newString = instantiateClassindexableSize(classIdentifier, len); - strncpy(arrayValueOf(newString), realpathResult, len); - s = newString; + s = instantiateClassindexableSize(classIdentifier, len); + strncpy(arrayValueOf(s), realpathResult, len); pop(2); push(s); } + else { + return primitiveFail(); + } return 0; } @@ -4251,25 +4283,25 @@ securityHeurisitic(void) void (*sHSAfn)(void); sCWIfn = ioLoadFunctionFrom("secCanWriteImage", "SecurityPlugin"); - if (sCWIfn == 0) { + if (!sCWIfn) { return 0; } canWriteImage = ((sqInt (*) (void)) sCWIfn)(); sHFAfn = ioLoadFunctionFrom("secHasFileAccess", "SecurityPlugin"); - if (sHFAfn == 0) { + if (!sHFAfn) { return 0; } hasFileAccess = ((sqInt (*) (void)) sHFAfn)(); sHSAfn = ioLoadFunctionFrom("secHasSocketAccess", "SecurityPlugin"); - if (sHSAfn == 0) { + if (!sHSAfn) { return 0; } hasSocketAccess = ((sqInt (*) (void)) sHSAfn)(); return ((canWriteImage && (hasFileAccess)) && (hasSocketAccess) - ? 0 - : 1); + ? 0 + : 1); } @@ -4287,7 +4319,8 @@ sendSignalToPids(void) count = 0; while (count < pidCount) { pid = pidArray[count]; - /* begin sendSignal:toPid: */ + + /* sendSignal:toPid: */ kill(pid, sigNumToSend); count += 1; } @@ -4328,12 +4361,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -4403,7 +4435,7 @@ setSigChldHandler(void) (sigchldHandlerAction.sa_flags = ((sigchldHandlerAction.sa_flags)) | SA_ONSTACK); } sigemptyset((&((sigchldHandlerAction.sa_mask)))); - if ((sigaction(SIGCHLD, (&sigchldHandlerAction), 0)) == (((sqInt)SIG_ERR /* begin sigErrorNumber */))) { + if ((sigaction(SIGCHLD, (&sigchldHandlerAction), 0)) == (((sqInt)SIG_ERR /* sigErrorNumber */))) { perror("sigaction"); } # else // defined(SA_NOCLDSTOP) @@ -4427,7 +4459,7 @@ setSignalNumberhandler(sqInt signalNumber, void *signalHandlerAddress) (sigHandlerAction.sa_handler = ((void (*)(int)) signalHandlerAddress)); (sigHandlerAction.sa_flags = SA_ONSTACK | SA_RESTART); sigemptyset((&((sigHandlerAction.sa_mask)))); - if ((sigaction(signalNumber, (&sigHandlerAction), (&oldHandlerAction))) == (((sqInt)SIG_ERR /* begin sigErrorNumber */))) { + if ((sigaction(signalNumber, (&sigHandlerAction), (&oldHandlerAction))) == (((sqInt)SIG_ERR /* sigErrorNumber */))) { perror("signal"); } return (oldHandlerAction.sa_handler); @@ -4439,7 +4471,6 @@ shutdownModule(void) { sqInt sigNum; - /* begin restoreDefaultSignalHandlers */ sigNum = 1; while (sigNum <= (signalArraySize())) { @@ -4486,6 +4517,7 @@ stringFromCString(const char *aCString) sqInt newString; classIdentifier = classString(); + /* begin cString:asCollection: */ len = strlen(aCString); newString = instantiateClassindexableSize(classIdentifier, len); @@ -4519,12 +4551,12 @@ transientCStringFromString(sqInt aString) sqInt newString; char *stringPtr; - /* Allocate space for a null terminated C string. */ len = sizeOfSTArrayFromCPrimitive(arrayValueOf(aString)); pushRemappableOop(aString); newString = instantiateClassindexableSize(classString(), len + 1); stringPtr = arrayValueOf(popRemappableOop()); + /* Point to the actual C string. */ cString = arrayValueOf(newString); (char *)strncpy(cString, stringPtr, len); @@ -4544,8 +4576,8 @@ versionString(void) return version; } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "UnixOSProcessPlugin"; diff --git a/src/plugins/VMProfileMacSupportPlugin/VMProfileMacSupportPlugin.c b/src/plugins/VMProfileMacSupportPlugin/VMProfileMacSupportPlugin.c index e44cd3da6e..52532d2cb9 100644 --- a/src/plugins/VMProfileMacSupportPlugin/VMProfileMacSupportPlugin.c +++ b/src/plugins/VMProfileMacSupportPlugin/VMProfileMacSupportPlugin.c @@ -1,9 +1,9 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - VMProfileMacSupportPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMProfileMacSupportPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 */ -static char __buildInfo[] = "VMProfileMacSupportPlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f " __DATE__ ; +static char __buildInfo[] = "VMProfileMacSupportPlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 " __DATE__ ; #include "config.h" @@ -103,7 +103,7 @@ extern sqInt topRemappableOop(void); extern #endif struct VirtualMachine* interpreterProxy; -static const char *moduleName = "VMProfileMacSupportPlugin VMMaker.oscog-eem.3455 " INT_EXT; +static const char *moduleName = "VMProfileMacSupportPlugin VMMaker.oscog-eem.3456 " INT_EXT; /*** Methods ***/ @@ -134,7 +134,6 @@ primitiveDLSym(void) char *symbolName; sqInt sz; - /* begin stackEphemeralStringValue: */ obj = stackValue(0); if (!(isBytes(obj))) { @@ -152,16 +151,15 @@ primitiveDLSym(void) memcpy(dstPtr, firstIndexableField(obj), sz); dstPtr[sz] = 0; symbolName = dstPtr; - l1: /* end stackEphemeralStringValue: */; - if (!(symbolName == null)) { +l1: /* end stackEphemeralStringValue: */; + if (symbolName) { addr = dlsym(RTLD_SELF, symbolName); - methodReturnValue((addr == 0 - ? nilObject() - : - /* begin positiveMachineIntegerFor: */ -(BytesPerWord == 8 - ? positive64BitIntegerFor(((usqIntptr_t)addr)) - : positive32BitIntegerFor(((usqIntptr_t)addr))))); + methodReturnValue((addr + ? /* positiveMachineIntegerFor: */ + (BytesPerWord == 8 + ? positive64BitIntegerFor(((usqIntptr_t)addr)) + : positive32BitIntegerFor(((usqIntptr_t)addr))) + : nilObject())); } return 0; } @@ -191,7 +189,7 @@ primitiveExecutableModulesAndOffsets(void) nimages = _dyld_image_count(); resultObj = instantiateClassindexableSize(classArray(), nimages * 4); - if (resultObj == 0) { + if (!resultObj) { return primitiveFailFor(PrimErrNoMemory); } pushRemappableOop(resultObj); @@ -202,18 +200,18 @@ primitiveExecutableModulesAndOffsets(void) slide = _dyld_get_image_vmaddr_slide(i); # if __x86_64__ || __arm64__ h64 = ((const struct mach_header_64 *) (_dyld_get_image_header(i))); - if (!(h64 == null)) { + if (h64) { s64 = getsectbynamefromheader_64(h64, SEG_TEXT, SECT_TEXT); - if (!(s64 == null)) { + if (s64) { start = (s64->addr); size = (s64->size); } } # else // __x86_64__ || __arm64__ h = _dyld_get_image_header(i); - if (!(h == null)) { + if (h) { s = getsectbynamefromheader(h, SEG_TEXT, SECT_TEXT); - if (!(s == null)) { + if (s) { start = (s->addr); size = (s->size); } @@ -228,31 +226,28 @@ primitiveExecutableModulesAndOffsets(void) storePointerofObjectwithValue(i * 4, topRemappableOop(), valueObj); nameObjData = arrayValueOf(valueObj); memcpy(nameObjData, name, strlen(name)); - valueObj = - /* begin signedMachineIntegerFor: */ -(BytesPerWord == 8 - ? signed64BitIntegerFor(slide) - : signed32BitIntegerFor(slide)); + valueObj = /* signedMachineIntegerFor: */ + (BytesPerWord == 8 + ? signed64BitIntegerFor(slide) + : signed32BitIntegerFor(slide)); if (failed()) { popRemappableOop(); return primitiveFailFor(PrimErrNoMemory); } storePointerofObjectwithValue((i * 4) + 1, topRemappableOop(), valueObj); - valueObj = - /* begin positiveMachineIntegerFor: */ -(BytesPerWord == 8 - ? positive64BitIntegerFor(start) - : positive32BitIntegerFor(start)); + valueObj = /* positiveMachineIntegerFor: */ + (BytesPerWord == 8 + ? positive64BitIntegerFor(start) + : positive32BitIntegerFor(start)); if (failed()) { popRemappableOop(); return primitiveFailFor(PrimErrNoMemory); } storePointerofObjectwithValue((i * 4) + 2, topRemappableOop(), valueObj); - valueObj = - /* begin positiveMachineIntegerFor: */ -(BytesPerWord == 8 - ? positive64BitIntegerFor(size) - : positive32BitIntegerFor(size)); + valueObj = /* positiveMachineIntegerFor: */ + (BytesPerWord == 8 + ? positive64BitIntegerFor(size) + : positive32BitIntegerFor(size)); if (failed()) { popRemappableOop(); return primitiveFailFor(PrimErrNoMemory); @@ -300,31 +295,32 @@ primitiveTextSymbols(void) slide = _dyld_get_image_vmaddr_slide(moduleIndex); # if __x86_64__ || __arm64__ h64 = ((const struct mach_header_64 *) (_dyld_get_image_header(moduleIndex))); - if (!(h64 == null)) { + if (h64) { s64 = getsectbynamefromheader_64(h64, SEG_TEXT, SECT_TEXT); - if (!(s64 == null)) { + if (s64) { start = ((s64->addr)) + slide; end = start + ((s64->size)); } } # else // __x86_64__ || __arm64__ h = _dyld_get_image_header(moduleIndex); - if (!(h == null)) { + if (h) { s = getsectbynamefromheader(h, SEG_TEXT, SECT_TEXT); - if (!(s == null)) { + if (s) { start = (s->addr); end = start + ((s->size)); } } # endif // __x86_64__ || __arm64__ - if (start == 0) { + if (!start) { return primitiveFailFor(PrimErrOperationFailed); } if (!((dlInfos = malloc((sizeof(Dl_info)) * ((ndlInfos = (increment = 0x400))))))) { return primitiveFailFor(PrimErrNoCMemory); } index = 0; + /* Yes, dear reader, one could use binary search to reduce the amount of effort. But when this author attempted to do so, he achieved only a marginal improvement for a substantial increase in complexity. So KISS and do a linear scan, looking ahead 64 bytes to reduce overhead as simply as possible. 64 gave @@ -353,7 +349,7 @@ primitiveTextSymbols(void) } } resultObj = instantiateClassindexableSize(classArray(), index * 2); - if (resultObj == 0) { + if (!resultObj) { free(dlInfos); return primitiveFailFor(PrimErrNoMemory); } @@ -361,11 +357,10 @@ primitiveTextSymbols(void) ndlInfos = index; index = 0; while (index < ndlInfos) { - valueObj = - /* begin positiveMachineIntegerFor: */ -(BytesPerWord == 8 - ? positive64BitIntegerFor(((dlInfos[index]).dli_saddr)) - : positive32BitIntegerFor(((dlInfos[index]).dli_saddr))); + valueObj = /* positiveMachineIntegerFor: */ + (BytesPerWord == 8 + ? positive64BitIntegerFor(((dlInfos[index]).dli_saddr)) + : positive32BitIntegerFor(((dlInfos[index]).dli_saddr))); if (failed()) { free(dlInfos); popRemappableOop(); @@ -396,12 +391,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -436,8 +430,8 @@ setInterpreter(struct VirtualMachine *anInterpreter) return ok; } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "VMProfileMacSupportPlugin"; diff --git a/src/plugins/XDisplayControlPlugin/XDisplayControlPlugin.c b/src/plugins/XDisplayControlPlugin/XDisplayControlPlugin.c index 8a93a6d5d1..91039124f7 100644 --- a/src/plugins/XDisplayControlPlugin/XDisplayControlPlugin.c +++ b/src/plugins/XDisplayControlPlugin/XDisplayControlPlugin.c @@ -1,5 +1,5 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3444 uuid: 2a902a4a-be82-4097-91a4-28da2fa623c8 + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from XDisplayControlPlugin VMConstruction-Plugins-XDisplayControlPlugin.oscog-eem.19 uuid: 51bf0a7a-bd19-4c35-9f1f-2d67c4cde3c4 */ @@ -63,7 +63,7 @@ static sqInt (*classString)(void); static sqInt (*falseObject)(void); static sqInt (*instantiateClassindexableSize)(sqInt classPointer, sqInt size); static void * (*ioLoadFunctionFrom)(char *functionName, char *moduleName); -static sqInt (*methodReturnString)(char *aCString); +static sqInt (*methodReturnString)(const char *aCString); static sqInt (*methodReturnValue)(sqInt oop); static sqInt (*nilObject)(void); static sqInt (*pop)(sqInt nItems); @@ -80,7 +80,7 @@ extern sqInt classString(void); extern sqInt falseObject(void); extern sqInt instantiateClassindexableSize(sqInt classPointer, sqInt size); extern void * ioLoadFunctionFrom(char *functionName, char *moduleName); -extern sqInt methodReturnString(char *aCString); +extern sqInt methodReturnString(const char *aCString); extern sqInt methodReturnValue(sqInt oop); extern sqInt nilObject(void); extern sqInt pop(sqInt nItems); @@ -157,17 +157,19 @@ primitiveCanConnectToDisplay(void) name = stackObjectValue(0); namePtr = transientCStringFromString(name); d = XOpenDisplay(namePtr); - if (d == 0) { - /* Failed to make connection to server, answer false */ - pop(2); - push(falseObject()); - } - else { + if (d) { + /* Successfully opened connection; close it and answer true */ XCloseDisplay(d); pop(2); push(trueObject()); } + else { + + /* Failed to make connection to server, answer false */ + pop(2); + push(falseObject()); + } } return 0; } @@ -218,11 +220,11 @@ primitiveGetDisplayName(void) /* begin methodReturnStringOrNil: */ - if (displayName == null) { - methodReturnValue(nilObject()); + if (displayName) { + methodReturnString(displayName); } else { - methodReturnString(displayName); + methodReturnValue(nilObject()); } return 0; } @@ -236,7 +238,7 @@ primitiveIsConnectedToDisplay(void) { extern int isConnectedToXServer; - if (isConnectedToXServer != 0) { + if (isConnectedToXServer) { pop(1); push(trueObject()); } @@ -378,25 +380,25 @@ securityHeurisitic(void) void (*sHSAfn)(void); sCWIfn = ioLoadFunctionFrom("secCanWriteImage", "SecurityPlugin"); - if (sCWIfn == 0) { + if (!sCWIfn) { return 0; } canWriteImage = ((sqInt (*) (void)) sCWIfn)(); sHFAfn = ioLoadFunctionFrom("secHasFileAccess", "SecurityPlugin"); - if (sHFAfn == 0) { + if (!sHFAfn) { return 0; } hasFileAccess = ((sqInt (*) (void)) sHFAfn)(); sHSAfn = ioLoadFunctionFrom("secHasSocketAccess", "SecurityPlugin"); - if (sHSAfn == 0) { + if (!sHSAfn) { return 0; } hasSocketAccess = ((sqInt (*) (void)) sHSAfn)(); return ((canWriteImage && (hasFileAccess)) && (hasSocketAccess) - ? 0 - : 1); + ? 0 + : 1); } @@ -408,12 +410,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -464,7 +465,6 @@ transientCStringFromString(sqInt aString) sqInt newString; char *stringPtr; - /* Allocate space for a null terminated C string. */ len = sizeOfSTArrayFromCPrimitive(arrayValueOf(aString)); @@ -476,6 +476,7 @@ transientCStringFromString(sqInt aString) aString = popRemappableOop(); #endif /* SPURVM */ stringPtr = arrayValueOf(aString); + /* Point to the actual C string. */ cString = arrayValueOf(newString); strncpy(cString, stringPtr, len); @@ -502,8 +503,8 @@ versionString(void) return version; } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "XDisplayControlPlugin"; diff --git a/src/plugins/ZipPlugin/ZipPlugin.c b/src/plugins/ZipPlugin/ZipPlugin.c index 0c019ac277..877116be9f 100644 --- a/src/plugins/ZipPlugin/ZipPlugin.c +++ b/src/plugins/ZipPlugin/ZipPlugin.c @@ -1,9 +1,9 @@ /* Automatically generated by - VMPluginCodeGenerator VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + VMPluginCodeGenerator VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 from - DeflatePlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f + DeflatePlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 */ -static char __buildInfo[] = "DeflatePlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e-7e08-4a76-8b1b-7755e8e0811f " __DATE__ ; +static char __buildInfo[] = "DeflatePlugin VMMaker.oscog-eem.3456 uuid: e316760f-1758-4b6b-aa08-f84bc7c44ef3 " __DATE__ ; #include "config.h" @@ -50,7 +50,6 @@ static char __buildInfo[] = "DeflatePlugin VMMaker.oscog-eem.3455 uuid: 3fb5350e /*** Function Prototypes ***/ static sqInt deflateBlockchainLengthgoodMatch(sqInt lastIndex, sqInt chainLength, sqInt goodMatch); -static sqInt determineSizeOfReadStream(sqInt rcvr); static sqInt determineSizeOfWriteStream(sqInt rcvr); static sqInt findMatchlastLengthlastMatchchainLengthgoodMatch(sqInt here, sqInt lastLength, sqInt lastMatch, sqInt maxChainLength, sqInt goodMatch); EXPORT(const char*) getModuleName(void); @@ -126,7 +125,7 @@ extern sqInt superclassOf(sqInt classPointer); extern #endif struct VirtualMachine* interpreterProxy; -static const char *moduleName = "ZipPlugin VMMaker.oscog-eem.3455 " INT_EXT; +static const char *moduleName = "ZipPlugin VMMaker.oscog-eem.3456 " INT_EXT; static sqInt readStreamInstSize; static sqInt writeStreamInstSize; static unsigned int zipBaseDistance[] = { @@ -294,17 +293,16 @@ deflateBlockchainLengthgoodMatch(sqInt lastIndex, sqInt chainLength, sqInt goodM sqInt flushNeeded; sqInt hasMatch; sqInt here; - sqInt here1; sqInt hereLength; - sqInt hereMatch; + unsigned int hereMatch; + sqInt hereSqInt; sqInt i; unsigned int literal; sqInt matchResult; sqInt newLength; - sqInt newMatch; + unsigned int newMatch; unsigned int prevEntry; unsigned int prevEntry1; - unsigned int prevEntry2; hereLength = 0; hereMatch = 0; @@ -318,10 +316,12 @@ deflateBlockchainLengthgoodMatch(sqInt lastIndex, sqInt chainLength, sqInt goodM here = zipBlockPos; while (here <= lastIndex) { if (!hasMatch) { + /* Find the first match */ matchResult = findMatchlastLengthlastMatchchainLengthgoodMatch(here, DeflateMinMatch - 1, here, chainLength, goodMatch); + /* begin insertStringAt: */ - zipHashValue = ((((sqInt)((usqInt)(zipHashValue) << DeflateHashShift))) ^ (zipCollection[(here + DeflateMinMatch) - 1])) & DeflateHashMask; + zipHashValue = (((((usqInt)(zipHashValue) << DeflateHashShift))) ^ (zipCollection[(here + DeflateMinMatch) - 1])) & DeflateHashMask; prevEntry = zipHashHead[zipHashValue]; zipHashHead[zipHashValue] = here; zipHashTail[here & DeflateWindowMask] = prevEntry; @@ -330,12 +330,14 @@ deflateBlockchainLengthgoodMatch(sqInt lastIndex, sqInt chainLength, sqInt goodM } matchResult = findMatchlastLengthlastMatchchainLengthgoodMatch(here + 1, hereLength, hereMatch, chainLength, goodMatch); newMatch = matchResult & 0xFFFF; + /* Now check if the next match is better than the current one. If not, output the current match (provided that the current match is at least MinMatch long) */ newLength = (((usqInt)(matchResult)) >> 16); if ((hereLength >= newLength) && (hereLength >= DeflateMinMatch)) { + /* Encode the current match */ /* begin encodeMatch:distance: */ zipLiterals[zipLiteralCount] = (hereLength - DeflateMinMatch); @@ -352,20 +354,22 @@ deflateBlockchainLengthgoodMatch(sqInt lastIndex, sqInt chainLength, sqInt goodM zipLiteralCount += 1; zipMatchCount += 1; flushNeeded = (zipLiteralCount == zipLiteralSize) - || (((zipLiteralCount & 0xFFF) == 0) - && (shouldFlush())); + || (((zipLiteralCount & 0xFFF) == 0) + && (shouldFlush())); for (i = 1; i < hereLength; i += 1) { - here1 = (here += 1); + hereSqInt = (here += 1); + /* begin insertStringAt: */ - zipHashValue = ((((sqInt)((usqInt)(zipHashValue) << DeflateHashShift))) ^ (zipCollection[(here1 + DeflateMinMatch) - 1])) & DeflateHashMask; + zipHashValue = (((((usqInt)(zipHashValue) << DeflateHashShift))) ^ (zipCollection[(hereSqInt + DeflateMinMatch) - 1])) & DeflateHashMask; prevEntry1 = zipHashHead[zipHashValue]; - zipHashHead[zipHashValue] = here1; - zipHashTail[here1 & DeflateWindowMask] = prevEntry1; + zipHashHead[zipHashValue] = hereSqInt; + zipHashTail[hereSqInt & DeflateWindowMask] = prevEntry1; } hasMatch = 0; here += 1; } else { + /* Either the next match is better than the current one or we didn't have a good match after all (e.g., current match length < MinMatch). Output a single literal. */ @@ -375,17 +379,18 @@ deflateBlockchainLengthgoodMatch(sqInt lastIndex, sqInt chainLength, sqInt goodM zipLiteralFreq[zipCollection[here]] = ((zipLiteralFreq[zipCollection[here]]) + 1); zipLiteralCount += 1; flushNeeded = (zipLiteralCount == zipLiteralSize) - || (((zipLiteralCount & 0xFFF) == 0) - && (shouldFlush())); + || (((zipLiteralCount & 0xFFF) == 0) + && (shouldFlush())); here += 1; if ((here <= lastIndex) && (!flushNeeded)) { + /* Cache the results for the next round */ /* begin insertStringAt: */ - zipHashValue = ((((sqInt)((usqInt)(zipHashValue) << DeflateHashShift))) ^ (zipCollection[(here + DeflateMinMatch) - 1])) & DeflateHashMask; - prevEntry2 = zipHashHead[zipHashValue]; + zipHashValue = (((((usqInt)(zipHashValue) << DeflateHashShift))) ^ (zipCollection[(here + DeflateMinMatch) - 1])) & DeflateHashMask; + prevEntry1 = zipHashHead[zipHashValue]; zipHashHead[zipHashValue] = here; - zipHashTail[here & DeflateWindowMask] = prevEntry2; + zipHashTail[here & DeflateWindowMask] = prevEntry1; hasMatch = 1; hereMatch = newMatch; hereLength = newLength; @@ -401,28 +406,6 @@ deflateBlockchainLengthgoodMatch(sqInt lastIndex, sqInt chainLength, sqInt goodM } -/* Determine the inst size of the class above InflateStream by - looking for the first class whose inst size is less than 13. */ - - /* InflatePlugin>>#determineSizeOfReadStream: */ -static sqInt -determineSizeOfReadStream(sqInt rcvr) -{ - sqInt class; - - class = fetchClassOf(rcvr); - while ((class != (nilObject())) - && ((instanceSizeOf(class)) >= 13)) { - class = superclassOf(class); - } - if (class == (nilObject())) { - return 0; - } - readStreamInstSize = instanceSizeOf(class); - return 1; -} - - /* Determine the inst size of the class above DeflateStream or ZipEncoder by looking for the first class whose inst size is less than 7. */ @@ -458,7 +441,7 @@ findMatchlastLengthlastMatchchainLengthgoodMatch(sqInt here, sqInt lastLength, s sqInt chainLength; sqInt distance; sqInt length; - sqInt length1; + sqInt lengthSqInt; sqInt limit; unsigned int matchPos; sqInt matchResult; @@ -466,21 +449,25 @@ findMatchlastLengthlastMatchchainLengthgoodMatch(sqInt here, sqInt lastLength, s /* Compute the default match result */ /* There is no way to find a better match than MaxMatch */ - matchResult = ((((sqInt)((usqInt)(lastLength) << 16)))) | lastMatch; + matchResult = (((((usqInt)(lastLength) << 16)))) | lastMatch; if (lastLength >= DeflateMaxMatch) { return matchResult; } + /* Compute the distance to the (possible) match */ - matchPos = zipHashHead[((((sqInt)((usqInt)(zipHashValue) << DeflateHashShift))) ^ (zipCollection[(here + DeflateMinMatch) - 1])) & DeflateHashMask]; + matchPos = zipHashHead[(((((usqInt)(zipHashValue) << DeflateHashShift))) ^ (zipCollection[(here + DeflateMinMatch) - 1])) & DeflateHashMask]; + /* Note: It is required that 0 < distance < MaxDistance */ distance = here - matchPos; if (!((distance > 0) && (distance < DeflateMaxDistance))) { return matchResult; } + /* Max. nr of match chain to search */ chainLength = maxChainLength; if (here > DeflateMaxDistance) { + /* Limit for matches that are too old */ limit = here - DeflateMaxDistance; } @@ -489,6 +476,7 @@ findMatchlastLengthlastMatchchainLengthgoodMatch(sqInt here, sqInt lastLength, s } bestLength = lastLength; while (1) { + /* Compare the current string with the string at match position */ /* begin compare:with:min: */ if (!((zipCollection[here + bestLength]) == (zipCollection[matchPos + bestLength]))) { @@ -507,13 +495,13 @@ findMatchlastLengthlastMatchchainLengthgoodMatch(sqInt here, sqInt lastLength, s length = 1; goto l1; } - length1 = 2; - while ((length1 < DeflateMaxMatch) - && ((zipCollection[here + length1]) == (zipCollection[matchPos + length1]))) { - length1 += 1; + lengthSqInt = 2; + while ((lengthSqInt < DeflateMaxMatch) + && ((zipCollection[here + lengthSqInt]) == (zipCollection[matchPos + lengthSqInt]))) { + lengthSqInt += 1; } - length = length1; - l1: /* end compare:with:min: */; + length = lengthSqInt; +l1: /* end compare:with:min: */; if ((here + length) > zipPosition) { length = zipPosition - here; } @@ -522,9 +510,11 @@ findMatchlastLengthlastMatchchainLengthgoodMatch(sqInt here, sqInt lastLength, s length = DeflateMinMatch - 1; } if (length > bestLength) { + /* We have a new (better) match than before */ /* Compute the new match result */ - matchResult = ((((sqInt)((usqInt)(length) << 16)))) | matchPos; + matchResult = (((((usqInt)(length) << 16)))) | matchPos; + /* There is no way to find a better match than MaxMatch */ bestLength = length; if (bestLength >= DeflateMaxMatch) { @@ -572,7 +562,7 @@ loadDeflateStreamFrom(sqInt rcvr) if (!(isBytes(oop))) { return 0; } - if (writeStreamInstSize == 0) { + if (!writeStreamInstSize) { if (!(determineSizeOfWriteStream(rcvr))) { return 0; } @@ -584,6 +574,7 @@ loadDeflateStreamFrom(sqInt rcvr) zipCollection = firstIndexableField(oop); zipCollectionSize = byteSizeOf(oop); zipPosition = fetchIntegerofObject(1, rcvr); + /* zipWriteLimit := interpreterProxy fetchInteger: 3 ofObject: rcvr. */ /* hashHead */ zipReadLimit = fetchIntegerofObject(2, rcvr); @@ -592,6 +583,7 @@ loadDeflateStreamFrom(sqInt rcvr) && ((slotSizeOf(oop)) == DeflateHashTableSize))) { return 0; } + /* hashTail */ zipHashHead = firstIndexableField(oop); oop = fetchPointerofObject(writeStreamInstSize + 1, rcvr); @@ -601,6 +593,7 @@ loadDeflateStreamFrom(sqInt rcvr) } zipHashTail = firstIndexableField(oop); zipHashValue = fetchIntegerofObject(writeStreamInstSize + 2, rcvr); + /* zipBlockStart := interpreterProxy fetchInteger: writeStreamInstSize + 4 ofObject: rcvr. */ /* literals */ zipBlockPos = fetchIntegerofObject(writeStreamInstSize + 3, rcvr); @@ -609,6 +602,7 @@ loadDeflateStreamFrom(sqInt rcvr) return 0; } zipLiteralSize = slotSizeOf(oop); + /* distances */ zipLiterals = firstIndexableField(oop); oop = fetchPointerofObject(writeStreamInstSize + 6, rcvr); @@ -616,6 +610,7 @@ loadDeflateStreamFrom(sqInt rcvr) && ((slotSizeOf(oop)) >= zipLiteralSize))) { return 0; } + /* literalFreq */ zipDistances = firstIndexableField(oop); oop = fetchPointerofObject(writeStreamInstSize + 7, rcvr); @@ -623,6 +618,7 @@ loadDeflateStreamFrom(sqInt rcvr) && ((slotSizeOf(oop)) == DeflateMaxLiteralCodes))) { return 0; } + /* distanceFreq */ zipLiteralFreq = firstIndexableField(oop); oop = fetchPointerofObject(writeStreamInstSize + 8, rcvr); @@ -642,7 +638,7 @@ loadZipEncoderFrom(sqInt rcvr) { sqInt oop; - if (writeStreamInstSize == 0) { + if (!writeStreamInstSize) { if (!(determineSizeOfWriteStream(rcvr))) { return 0; } @@ -662,6 +658,7 @@ loadZipEncoderFrom(sqInt rcvr) zipCollection = firstIndexableField(oop); zipCollectionSize = byteSizeOf(oop); zipPosition = fetchIntegerofObject(1, rcvr); + /* zipWriteLimit := interpreterProxy fetchInteger: 3 ofObject: rcvr. */ zipReadLimit = fetchIntegerofObject(2, rcvr); zipBitBuf = fetchIntegerofObject(writeStreamInstSize, rcvr); @@ -697,6 +694,7 @@ primitiveDeflateBlock(void) } result = deflateBlockchainLengthgoodMatch(lastIndex, chainLength, goodMatch); if (!(failed())) { + /* Store back modified values */ storeIntegerofObjectwithValue(writeStreamInstSize + 2, rcvr, zipHashValue); storeIntegerofObjectwithValue(writeStreamInstSize + 3, rcvr, zipBlockPos); @@ -734,7 +732,7 @@ primitiveDeflateUpdateHashTable(void) return primitiveFail(); } tableSize = slotSizeOf(table); - tablePtr = ((int *) (firstIndexableField(table))); + tablePtr = firstIndexableField(table); for (i = 0; i < tableSize; i += 1) { entry = tablePtr[i]; if (entry >= delta) { @@ -755,6 +753,7 @@ primitiveDeflateUpdateHashTable(void) EXPORT(sqInt) primitiveInflateDecompressBlock(void) { + sqInt class; sqInt oop; sqInt rcvr; @@ -766,6 +765,7 @@ primitiveInflateDecompressBlock(void) return primitiveFail(); } zipDistTable = firstIndexableField(oop); + /* literal table */ zipDistTableSize = slotSizeOf(oop); oop = stackValue(1); @@ -773,16 +773,24 @@ primitiveInflateDecompressBlock(void) return primitiveFail(); } zipLitTable = firstIndexableField(oop); + /* Receiver (InflateStream) */ zipLitTableSize = slotSizeOf(oop); rcvr = stackValue(2); if (!(isPointers(rcvr))) { return primitiveFail(); } - if (readStreamInstSize == 0) { - if (!(determineSizeOfReadStream(rcvr))) { + if (!readStreamInstSize) { + /* begin determineSizeOfReadStream: */ + class = fetchClassOf(rcvr); + while ((class != (nilObject())) + && ((instanceSizeOf(class)) >= 13)) { + class = superclassOf(class); + } + if (class == (nilObject())) { return primitiveFail(); } + readStreamInstSize = instanceSizeOf(class); if ((slotSizeOf(rcvr)) < (readStreamInstSize + 8)) { readStreamInstSize = 0; return primitiveFail(); @@ -802,6 +810,7 @@ primitiveInflateDecompressBlock(void) } zipReadLimit -= 1; zipSourcePos -= 1; + /* collection */ zipSourceLimit -= 1; oop = fetchPointerofObject(0, rcvr); @@ -809,16 +818,19 @@ primitiveInflateDecompressBlock(void) return primitiveFail(); } zipCollection = firstIndexableField(oop); + /* source */ zipCollectionSize = byteSizeOf(oop); oop = fetchPointerofObject(readStreamInstSize + 3, rcvr); if (!(isBytes(oop))) { return primitiveFail(); } + /* do the primitive */ zipSource = firstIndexableField(oop); zipDecompressBlock(); if (!(failed())) { + /* store modified values back */ storeIntegerofObjectwithValue(2, rcvr, zipReadLimit + 1); storeIntegerofObjectwithValue(readStreamInstSize, rcvr, zipState); @@ -865,7 +877,7 @@ primitiveUpdateAdler32(void) if (!(stopIndex <= length)) { return primitiveFail(); } - bytePtr = ((unsigned char *) (firstIndexableField(collection))); + bytePtr = firstIndexableField(collection); startIndex -= 1; stopIndex -= 1; s1 = adler32 & 0xFFFF; @@ -875,7 +887,7 @@ primitiveUpdateAdler32(void) s1 = (s1 + b) % 0xFFF1; s2 = (s2 + s1) % 0xFFF1; } - adler32 = ((((usqInt)(s2) << 16))) + s1; + adler32 = (((((usqInt)(s2) << 16)))) + s1; methodReturnValue(positive32BitIntegerFor(adler32)); return 0; } @@ -914,7 +926,7 @@ primitiveUpdateGZipCrc32(void) primitiveFail(); return; } - bytePtr = ((unsigned char *) (firstIndexableField(collection))); + bytePtr = firstIndexableField(collection); startIndex -= 1; stopIndex -= 1; for (i = startIndex; i <= stopIndex; i += 1) { @@ -980,6 +992,7 @@ primitiveZipSendBlock(void) && ((slotSizeOf(distStream)) >= 3))) { return primitiveFail(); } + /* begin sendBlock:with:with:with: */ oop = fetchPointerofObject(0, litStream); litPos = fetchIntegerofObject(1, litStream); @@ -990,7 +1003,7 @@ primitiveZipSendBlock(void) result = primitiveFail(); goto l7; } - litArray = ((unsigned char *) (firstIndexableField(oop))); + litArray = firstIndexableField(oop); oop = fetchPointerofObject(0, distStream); if (!((isWords(oop)) && ((litLimit <= (slotSizeOf(oop))) @@ -999,35 +1012,36 @@ primitiveZipSendBlock(void) result = primitiveFail(); goto l7; } - distArray = ((unsigned int *) (firstIndexableField(oop))); + distArray = firstIndexableField(oop); oop = fetchPointerofObject(0, litTree); if (!(isWords(oop))) { result = primitiveFail(); goto l7; } litBlCount = slotSizeOf(oop); - llBitLengths = ((unsigned int *) (firstIndexableField(oop))); + llBitLengths = firstIndexableField(oop); oop = fetchPointerofObject(1, litTree); if (!((isWords(oop)) && (litBlCount == (slotSizeOf(oop))))) { result = primitiveFail(); goto l7; } - llCodes = ((unsigned int *) (firstIndexableField(oop))); + llCodes = firstIndexableField(oop); oop = fetchPointerofObject(0, distTree); if (!(isWords(oop))) { result = primitiveFail(); goto l7; } distBlCount = slotSizeOf(oop); - distBitLengths = ((unsigned int *) (firstIndexableField(oop))); + distBitLengths = firstIndexableField(oop); oop = fetchPointerofObject(1, distTree); if (!((isWords(oop)) && (distBlCount == (slotSizeOf(oop))))) { result = primitiveFail(); goto l7; } - distCodes = ((unsigned int *) (firstIndexableField(oop))); + distCodes = firstIndexableField(oop); + /* begin nextZipBits:put: */ if (!((0 >= 0) && ((1) > 0))) { @@ -1043,59 +1057,31 @@ primitiveZipSendBlock(void) zipBitBuf = ((usqInt)(zipBitBuf)) >> 8; zipBitPos -= 8; } - l1: /* end nextZipBits:put: */; +l1: /* end nextZipBits:put: */; sum = 0; while ((litPos < litLimit) && ((zipPosition + 4) < zipCollectionSize)) { lit = litArray[litPos]; dist = distArray[litPos]; litPos += 1; - if (dist == 0) { - /* literal */ - sum += 1; - if (!(lit < litBlCount)) { - result = primitiveFail(); - goto l7; - } - /* begin nextZipBits:put: */ - if (!(((llCodes[lit]) >= 0) - && ((1U << (llBitLengths[lit])) > (llCodes[lit])))) { - primitiveFail(); - goto l2; - } - zipBitBuf = zipBitBuf | (((usqInt)((llCodes[lit])) << zipBitPos)); - zipBitPos += llBitLengths[lit]; - while ((zipBitPos >= 8) - && (zipPosition < zipCollectionSize)) { - zipCollection[zipPosition] = (zipBitBuf & 0xFF); - zipPosition += 1; - zipBitBuf = ((usqInt)(zipBitBuf)) >> 8; - zipBitPos -= 8; - } - l2: /* end nextZipBits:put: */; - } - else { + if (dist) { + /* match */ /* eem 8/30/2020 Can't happen; litArray has type unsigned char *, lit unsigned char. Leaving this in causes a C compiler warning. */ sum = (sum + lit) + DeflateMinMatch; - if (0) { - if (!(lit < 0x100)) { - result = primitiveFail(); - goto l7; - } - } code = zipMatchLengthCodes[lit]; if (!(code < litBlCount)) { result = primitiveFail(); goto l7; } + /* begin nextZipBits:put: */ if (!(((llCodes[code]) >= 0) && ((1U << (llBitLengths[code])) > (llCodes[code])))) { primitiveFail(); goto l3; } - zipBitBuf = zipBitBuf | (((usqInt)((llCodes[code])) << zipBitPos)); + zipBitBuf = zipBitBuf | ((((usqInt)((llCodes[code])) << zipBitPos))); zipBitPos += llBitLengths[code]; while ((zipBitPos >= 8) && (zipPosition < zipCollectionSize)) { @@ -1104,17 +1090,18 @@ primitiveZipSendBlock(void) zipBitBuf = ((usqInt)(zipBitBuf)) >> 8; zipBitPos -= 8; } - l3: /* end nextZipBits:put: */; +l3: /* end nextZipBits:put: */; extra = zipExtraLengthBits[code - 0x101]; - if (!(extra == 0)) { + if (extra) { lit -= zipBaseLength[code - 0x101]; + /* begin nextZipBits:put: */ if (!((lit >= 0) && ((1U << extra) > lit))) { primitiveFail(); goto l4; } - zipBitBuf = zipBitBuf | (((usqInt)(lit) << zipBitPos)); + zipBitBuf = zipBitBuf | ((((usqInt)(lit) << zipBitPos))); zipBitPos += extra; while ((zipBitPos >= 8) && (zipPosition < zipCollectionSize)) { @@ -1123,7 +1110,7 @@ primitiveZipSendBlock(void) zipBitBuf = ((usqInt)(zipBitBuf)) >> 8; zipBitPos -= 8; } - l4: /* end nextZipBits:put: */; +l4: /* end nextZipBits:put: */; } dist -= 1; if (!(dist < 0x8000)) { @@ -1140,13 +1127,14 @@ primitiveZipSendBlock(void) result = primitiveFail(); goto l7; } + /* begin nextZipBits:put: */ if (!(((distCodes[code]) >= 0) && ((1U << (distBitLengths[code])) > (distCodes[code])))) { primitiveFail(); goto l5; } - zipBitBuf = zipBitBuf | (((usqInt)((distCodes[code])) << zipBitPos)); + zipBitBuf = zipBitBuf | ((((usqInt)((distCodes[code])) << zipBitPos))); zipBitPos += distBitLengths[code]; while ((zipBitPos >= 8) && (zipPosition < zipCollectionSize)) { @@ -1155,17 +1143,18 @@ primitiveZipSendBlock(void) zipBitBuf = ((usqInt)(zipBitBuf)) >> 8; zipBitPos -= 8; } - l5: /* end nextZipBits:put: */; +l5: /* end nextZipBits:put: */; extra = zipExtraDistanceBits[code]; - if (!(extra == 0)) { + if (extra) { dist -= zipBaseDistance[code]; + /* begin nextZipBits:put: */ if (!((dist >= 0) && ((1U << extra) > dist))) { primitiveFail(); goto l6; } - zipBitBuf = zipBitBuf | (((sqInt)((usqInt)(dist) << zipBitPos))); + zipBitBuf = zipBitBuf | ((((usqInt)(dist) << zipBitPos))); zipBitPos += extra; while ((zipBitPos >= 8) && (zipPosition < zipCollectionSize)) { @@ -1174,9 +1163,35 @@ primitiveZipSendBlock(void) zipBitBuf = ((usqInt)(zipBitBuf)) >> 8; zipBitPos -= 8; } - l6: /* end nextZipBits:put: */; +l6: /* end nextZipBits:put: */; } } + else { + + /* literal */ + sum += 1; + if (!(lit < litBlCount)) { + result = primitiveFail(); + goto l7; + } + + /* begin nextZipBits:put: */ + if (!(((llCodes[lit]) >= 0) + && ((1U << (llBitLengths[lit])) > (llCodes[lit])))) { + primitiveFail(); + goto l2; + } + zipBitBuf = zipBitBuf | ((((usqInt)((llCodes[lit])) << zipBitPos))); + zipBitPos += llBitLengths[lit]; + while ((zipBitPos >= 8) + && (zipPosition < zipCollectionSize)) { + zipCollection[zipPosition] = (zipBitBuf & 0xFF); + zipPosition += 1; + zipBitBuf = ((usqInt)(zipBitBuf)) >> 8; + zipBitPos -= 8; + } +l2: /* end nextZipBits:put: */; + } } if (failed()) { result = null; @@ -1185,7 +1200,7 @@ primitiveZipSendBlock(void) storeIntegerofObjectwithValue(1, litStream, litPos); storeIntegerofObjectwithValue(1, distStream, litPos); result = sum; - l7: /* end sendBlock:with:with:with: */; +l7: /* end sendBlock:with:with:with: */; if (!(failed())) { storeIntegerofObjectwithValue(1, rcvr, zipPosition); storeIntegerofObjectwithValue(writeStreamInstSize, rcvr, zipBitBuf); @@ -1207,12 +1222,11 @@ setInterpreter(struct VirtualMachine *anInterpreter) { sqInt ok; - /* This may seem tautological, but in a real plugin it checks that the VM provides the version the plugin was compiled against which is the version the plugin expects. */ interpreterProxy = anInterpreter; ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR)) - && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); + && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR)); if (ok) { #if !defined(SQUEAK_BUILTIN_PLUGIN) @@ -1259,10 +1273,11 @@ shouldFlush(void) if (zipLiteralCount == zipLiteralSize) { return 1; } - if (!((zipLiteralCount & 0xFFF) == 0)) { + if (zipLiteralCount & 0xFFF) { return 0; } if ((zipMatchCount * 10) <= zipLiteralCount) { + /* This is basically random data. There is no need to flush early since the overhead for encoding the trees will add to the overall size */ @@ -1283,45 +1298,46 @@ static unsigned int zipDecodeValueFromsize(unsigned int *table, sqInt tableSize) { sqInt bits; - sqInt bits1; sqInt bitsNeeded; unsigned char byte; sqInt index; unsigned int tableIndex; unsigned int value; - /* Initial bits needed */ bitsNeeded = (((usqInt)((table[0]))) >> 24); if (bitsNeeded > MaxBits) { primitiveFail(); return 0; } + /* First real table */ tableIndex = 2; while (1) { /* begin zipNextBits: */ while (zipBitPos < bitsNeeded) { byte = zipSource[(zipSourcePos += 1)]; - zipBitBuf += ((usqInt)(byte) << zipBitPos); + zipBitBuf += (((usqInt)(byte) << zipBitPos)); zipBitPos += 8; } - bits1 = zipBitBuf & ((1U << bitsNeeded) - 1); + bits = zipBitBuf & ((1U << bitsNeeded) - 1); zipBitBuf = ((usqInt)(zipBitBuf)) >> bitsNeeded; zipBitPos -= bitsNeeded; - bits = bits1; index = (tableIndex + bits) - 1; if (index >= tableSize) { primitiveFail(); return 0; } + /* Lookup entry in table */ value = table[index]; - if ((value & 0x3F000000) == 0) { + if (!(value & 0x3F000000)) { return value; } + /* Table offset in low 16 bit */ tableIndex = value & 0xFFFF; + /* Additional bits in high 8 bit */ bitsNeeded = ((((usqInt)(value)) >> 24)) & 0xFF; if (bitsNeeded > MaxBits) { @@ -1351,18 +1367,22 @@ zipDecompressBlock(void) max = zipCollectionSize - 1; while ((zipReadLimit < max) && (zipSourcePos <= zipSourceLimit)) { + /* Back up stuff if we're running out of space */ oldBits = zipBitBuf; oldBitPos = zipBitPos; oldPos = zipSourcePos; value = zipDecodeValueFromsize(zipLitTable, zipLitTableSize); if (value < 0x100) { + /* A literal */ zipCollection[(zipReadLimit += 1)] = value; } else { + /* length/distance or end of block */ if (value == 0x100) { + /* End of block */ zipState = zipState & StateNoMoreData; return 0; @@ -1404,7 +1424,7 @@ zipNextBits(sqInt n) while (zipBitPos < n) { byte = zipSource[(zipSourcePos += 1)]; - zipBitBuf += ((usqInt)(byte) << zipBitPos); + zipBitBuf += (((usqInt)(byte) << zipBitPos)); zipBitPos += 8; } bits = zipBitBuf & ((1U << n) - 1); @@ -1413,8 +1433,8 @@ zipNextBits(sqInt n) return bits; } - /*** Exports ***/ + #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "ZipPlugin";