Eliot Miranda uploaded a new version of VMMaker to project VM Maker: http://source.squeak.org/VMMaker/VMMaker.oscog-eem.2470.mcz ==================== Summary ==================== Name: VMMaker.oscog-eem.2470 Author: eem Time: 22 October 2018, 3:24:27.362245 pm UUID: df5df1d8-a195-4cba-becc-b8833a08355a Ancestors: VMMaker.oscog-eem.2469 Plugins: Fix a regression in VMMaker.oscog-eem.2467. Slang: special case coercing a Float literal to #float, emitting it as N.Mf =============== Diff against VMMaker.oscog-eem.2469 =============== Item was added: + ----- Method: BitBltSimulation>>lockSurfaceFn: (in category 'surface support') ----- + lockSurfaceFn: sourceHandle _: pitchPtr _: x _: y _: w _: h + "Simulate the lockSurfaceFn function call as a failure to load the surface." + <doNotGenerate> + ^0! Item was removed: - ----- Method: BitBltSimulation>>lockSurfaceFn:_:_:_:_:_: (in category 'surface support') ----- - lockSurfaceFn: sourceHandle _: pitchPtr _: x _: y _: w _: h - "Simulate the lockSurfaceFn function call as a failure to load the surface." - <doNotGenerate> - ^0! Item was added: + ----- Method: BitBltSimulation>>querySurfaceFn: (in category 'surface support') ----- + querySurfaceFn: handle _: widthPtr _: heightPtr _: depthPtr _: endianPtr + "Query the dimension of an OS surface. + This method is provided so that in case the inst vars of the + source form are broken, *actual* values of the OS surface + can be obtained. This might, for instance, happen if the user + resizes the main window. + This is a simulation of the querySurfaceFn function call; simulate as a failure." + <doNotGenerate> + ^false! Item was removed: - ----- Method: BitBltSimulation>>querySurfaceFn:_:_:_:_: (in category 'surface support') ----- - querySurfaceFn: handle _: widthPtr _: heightPtr _: depthPtr _: endianPtr - "Query the dimension of an OS surface. - This method is provided so that in case the inst vars of the - source form are broken, *actual* values of the OS surface - can be obtained. This might, for instance, happen if the user - resizes the main window. - This is a simulation of the querySurfaceFn function call; simulate as a failure." - <doNotGenerate> - ^false! Item was changed: ----- Method: CCodeGenerator>>generateCCoercion:on:indent: (in category 'C translation') ----- generateCCoercion: msgNode on: aStream indent: level "Generate the C code for this message onto the given stream." + | cExpr cType literal | + cExpr := msgNode args first. + cType := msgNode args last value. + (cType = #float + and: [cExpr isConstant + and: [cExpr value isFloat + and: [(literal := self cLiteralFor: cExpr value) allSatisfy: [:c| c == $. or: [c isDigit]]]]]) ifTrue: + [aStream nextPutAll: literal; nextPut: $f. + ^self]. aStream nextPutAll: '(('. + aStream nextPutAll: cType. - aStream nextPutAll: msgNode args last value. aStream nextPutAll: ') '. + self emitCExpression: cExpr on: aStream. + aStream nextPut: $)! - self emitCExpression: msgNode args first on: aStream. - aStream nextPut: $) - - ! Item was added: + ----- Method: FilePluginSimulator>>dir_Create: (in category 'simulation') ----- + dir_Create: dirNameIndex _: dirNameSize + ^[FileDirectory default + primCreateDirectory: (interpreterProxy interpreter + asString: dirNameIndex + size: dirNameSize). + true] + on: Error + do: [:ex| false]! Item was removed: - ----- Method: FilePluginSimulator>>dir_Create:_: (in category 'simulation') ----- - dir_Create: dirNameIndex _: dirNameSize - ^[FileDirectory default - primCreateDirectory: (interpreterProxy interpreter - asString: dirNameIndex - size: dirNameSize). - true] - on: Error - do: [:ex| false]! Item was added: + ----- Method: FilePluginSimulator>>dir_EntryLookup: (in category 'simulation') ----- + dir_EntryLookup: pathString _: pathStringLength _: entryNameString _: entryNameStringLength _: name _: nameLength _: creationDate _: modificationDate _: isDirectory _: sizeIfFile _: posixPermissions _: isSymlink + "sqInt dir_EntryLookup(char *pathString, sqInt pathStringLength, char *nameString, sqInt nameStringLength, + /* outputs: */ char *name, sqInt *nameLength, sqInt *creationDate, sqInt *modificationDate, + sqInt *isDirectory, squeakFileOffsetType *sizeIfFile, sqInt *posixPermissions, sqInt *isSymlink)" + | result pathName entryName | + pathName := ((0 to: pathStringLength - 1) collect: [:i| (pathString at: i) asCharacter]) as: ByteString. + entryName := ((0 to: entryNameStringLength - 1) collect: [:i| (entryNameString at: i) asCharacter]) as: ByteString. + result := self primLookupEntryIn: pathName name: entryName. + result ifNil: [^DirNoMoreEntries]. + result isInteger ifTrue: + [result > 1 ifTrue: + [interpreterProxy primitiveFailFor: result]. + ^DirBadPath]. + name replaceFrom: 1 to: result first size with: result first startingAt: 1. + nameLength at: 0 put: result first size. + creationDate at: 0 put: (result at: 2). + modificationDate at: 0 put: (result at: 3). + isDirectory at: 0 put: (result at: 4). + sizeIfFile at: 0 put: (result at: 5). + posixPermissions at: 0 put: (result at: 6 ifAbsent: [(result at: 4) ifTrue: [8r755] ifFalse: [8r644]]). + isSymlink at: 0 put: (result at: 7 ifAbsent: [false]). + ^DirEntryFound! Item was removed: - ----- Method: FilePluginSimulator>>dir_EntryLookup:_:_:_:_:_:_:_:_:_:_:_: (in category 'simulation') ----- - dir_EntryLookup: pathString _: pathStringLength _: entryNameString _: entryNameStringLength _: name _: nameLength _: creationDate _: modificationDate _: isDirectory _: sizeIfFile _: posixPermissions _: isSymlink - "sqInt dir_EntryLookup(char *pathString, sqInt pathStringLength, char *nameString, sqInt nameStringLength, - /* outputs: */ char *name, sqInt *nameLength, sqInt *creationDate, sqInt *modificationDate, - sqInt *isDirectory, squeakFileOffsetType *sizeIfFile, sqInt *posixPermissions, sqInt *isSymlink)" - | result pathName entryName | - pathName := ((0 to: pathStringLength - 1) collect: [:i| (pathString at: i) asCharacter]) as: ByteString. - entryName := ((0 to: entryNameStringLength - 1) collect: [:i| (entryNameString at: i) asCharacter]) as: ByteString. - result := self primLookupEntryIn: pathName name: entryName. - result ifNil: [^DirNoMoreEntries]. - result isInteger ifTrue: - [result > 1 ifTrue: - [interpreterProxy primitiveFailFor: result]. - ^DirBadPath]. - name replaceFrom: 1 to: result first size with: result first startingAt: 1. - nameLength at: 0 put: result first size. - creationDate at: 0 put: (result at: 2). - modificationDate at: 0 put: (result at: 3). - isDirectory at: 0 put: (result at: 4). - sizeIfFile at: 0 put: (result at: 5). - posixPermissions at: 0 put: (result at: 6 ifAbsent: [(result at: 4) ifTrue: [8r755] ifFalse: [8r644]]). - isSymlink at: 0 put: (result at: 7 ifAbsent: [false]). - ^DirEntryFound! Item was added: + ----- Method: FilePluginSimulator>>dir_Lookup: (in category 'simulation') ----- + dir_Lookup: pathString _: pathStringLength _: index _: name _: nameLength _: creationDate _: modificationDate _: isDirectory _: sizeIfFile _: posixPermissions _: isSymlink + "sqInt dir_Lookup( char *pathString, sqInt pathStringLength, sqInt index, + /* outputs: */ char *name, sqInt *nameLength, sqInt *creationDate, sqInt *modificationDate, + sqInt *isDirectory, squeakFileOffsetType *sizeIfFile, sqInt * posixPermissions, sqInt *isSymlink)" + | result pathName | + pathName := ((0 to: pathStringLength - 1) collect: [:i| (pathString at: i) asCharacter]) as: ByteString. + result := self primLookupEntryIn: pathName index: index. + result ifNil: [^DirNoMoreEntries]. + result isInteger ifTrue: + [result > 1 ifTrue: + [interpreterProxy primitiveFailFor: result]. + ^DirBadPath]. + name replaceFrom: 1 to: result first size with: result first startingAt: 1. + nameLength at: 0 put: result first size. + creationDate at: 0 put: (result at: 2). + modificationDate at: 0 put: (result at: 3). + isDirectory at: 0 put: (result at: 4). + sizeIfFile at: 0 put: (result at: 5). + posixPermissions at: 0 put: (result at: 6 ifAbsent: [(result at: 4) ifTrue: [8r755] ifFalse: [8r644]]). + isSymlink at: 0 put: (result at: 7 ifAbsent: [false]). + ^DirEntryFound! Item was removed: - ----- Method: FilePluginSimulator>>dir_Lookup:_:_:_:_:_:_:_:_:_:_: (in category 'simulation') ----- - dir_Lookup: pathString _: pathStringLength _: index _: name _: nameLength _: creationDate _: modificationDate _: isDirectory _: sizeIfFile _: posixPermissions _: isSymlink - "sqInt dir_Lookup( char *pathString, sqInt pathStringLength, sqInt index, - /* outputs: */ char *name, sqInt *nameLength, sqInt *creationDate, sqInt *modificationDate, - sqInt *isDirectory, squeakFileOffsetType *sizeIfFile, sqInt * posixPermissions, sqInt *isSymlink)" - | result pathName | - pathName := ((0 to: pathStringLength - 1) collect: [:i| (pathString at: i) asCharacter]) as: ByteString. - result := self primLookupEntryIn: pathName index: index. - result ifNil: [^DirNoMoreEntries]. - result isInteger ifTrue: - [result > 1 ifTrue: - [interpreterProxy primitiveFailFor: result]. - ^DirBadPath]. - name replaceFrom: 1 to: result first size with: result first startingAt: 1. - nameLength at: 0 put: result first size. - creationDate at: 0 put: (result at: 2). - modificationDate at: 0 put: (result at: 3). - isDirectory at: 0 put: (result at: 4). - sizeIfFile at: 0 put: (result at: 5). - posixPermissions at: 0 put: (result at: 6 ifAbsent: [(result at: 4) ifTrue: [8r755] ifFalse: [8r644]]). - isSymlink at: 0 put: (result at: 7 ifAbsent: [false]). - ^DirEntryFound! Item was changed: ----- Method: FloatArrayPlugin>>primitiveDivFloatArray (in category 'arithmetic primitives') ----- primitiveDivFloatArray "Primitive. Divide each element in the receiver by the corresponding element in the argument, both FloatArrays, and store the result into the receiver." <export: true> | rcvr arg rcvrPtr argPtr length | <var: #rcvrPtr type: #'float *'> <var: #argPtr type: #'float *'> arg := interpreterProxy stackValue: 0. rcvr := interpreterProxy stackValue: 1. ((interpreterProxy isWords: arg) and: [(interpreterProxy isWords: rcvr) and: [(length := interpreterProxy stSizeOf: arg) = (interpreterProxy stSizeOf: rcvr)]]) ifFalse: [^interpreterProxy primitiveFail]. rcvrPtr := self cCoerce: (interpreterProxy firstIndexableField: rcvr) to: #'float *'. argPtr := self cCoerce: (interpreterProxy firstIndexableField: arg) to: #'float *'. "Check if any of the argument's values is zero" 0 to: length - 1 do: + [:i| (argPtr at: i) = (self cCoerce: 0.0 to: #float) ifTrue: "i.e. check for both 0.0 and -0.0" - [:i| (argPtr + i) = 0.0 ifTrue: "i.e. check for both 0.0 and -0.0" [^interpreterProxy primitiveFail]]. 0 to: length - 1 do: [:i| rcvrPtr at: i put: (self cCoerce: (rcvrPtr at: i) to: #double) / (self cCoerce: (argPtr at: i) to: #double)]. interpreterProxy pop: 1 "Leave rcvr on stack"! Item was added: + ----- Method: InterpreterPlugin>>strncpy: (in category 'simulation support') ----- + strncpy: aString _: bString _: n + <doNotGenerate> + ^interpreterProxy strncpy: aString _: bString _: n! Item was removed: - ----- Method: InterpreterPlugin>>strncpy:_:_: (in category 'simulation support') ----- - strncpy: aString _: bString _: n - <doNotGenerate> - ^interpreterProxy strncpy: aString _: bString _: n! Item was added: + ----- Method: JPEGReadWriter2Plugin>>primJPEGReadImagefromByteArrayonFormdoDitheringerrorMgrReadScanlines: (in category 'simulation') ----- + primJPEGReadImagefromByteArrayonFormdoDitheringerrorMgrReadScanlines: jpegDecompressStruct _: jpegErrorMgr2Struct _: source _: sourceSize _: ditherFlag _: formBitmap _: pixelsPerWord _: wordsPerRow _: formNativeDepth + "void primJPEGReadImagefromByteArrayonFormdoDitheringerrorMgrReadScanlines( + char* jpegDecompressStruct, + char* jpegErrorMgr2Struct, + char* source, + unsigned int sourceSize, + int ditherFlag, + unsigned int* bitmap, + unsigned int pixelsPerWord, + unsigned int wordsPerRow, + int nativeDepth)" + <doNotGenerate> + | sourceBytes decompressStruct errorStruct form | + sourceBytes := source asByteArray. + decompressStruct := jpegDecompressStruct asByteArray. + errorStruct := jpegErrorMgr2Struct asByteArray. + (self evaluateIfFailed: + [| slave height | + slave := JPEGReadWriter2 new. + height := slave primImageWidth: decompressStruct. "cheating ;-)" + form := Form extent: wordsPerRow * pixelsPerWord @ height depth: formNativeDepth. + slave + primJPEGReadImage: decompressStruct + fromByteArray: sourceBytes + onForm: form + doDithering: true + errorMgr: errorStruct]) ifTrue: [^nil]. + jpegDecompressStruct overwriteContentsWith: decompressStruct. + jpegErrorMgr2Struct overwriteContentsWith: errorStruct. + source overwriteContentsWith: sourceBytes. "could happen..." + ByteArray adoptInstance: form bits. + formBitmap overwriteContentsWith: form bits. + ^nil! Item was removed: - ----- Method: JPEGReadWriter2Plugin>>primJPEGReadImagefromByteArrayonFormdoDitheringerrorMgrReadScanlines:_:_:_:_:_:_:_:_: (in category 'simulation') ----- - primJPEGReadImagefromByteArrayonFormdoDitheringerrorMgrReadScanlines: jpegDecompressStruct _: jpegErrorMgr2Struct _: source _: sourceSize _: ditherFlag _: formBitmap _: pixelsPerWord _: wordsPerRow _: formNativeDepth - "void primJPEGReadImagefromByteArrayonFormdoDitheringerrorMgrReadScanlines( - char* jpegDecompressStruct, - char* jpegErrorMgr2Struct, - char* source, - unsigned int sourceSize, - int ditherFlag, - unsigned int* bitmap, - unsigned int pixelsPerWord, - unsigned int wordsPerRow, - int nativeDepth)" - <doNotGenerate> - | sourceBytes decompressStruct errorStruct form | - sourceBytes := source asByteArray. - decompressStruct := jpegDecompressStruct asByteArray. - errorStruct := jpegErrorMgr2Struct asByteArray. - (self evaluateIfFailed: - [| slave height | - slave := JPEGReadWriter2 new. - height := slave primImageWidth: decompressStruct. "cheating ;-)" - form := Form extent: wordsPerRow * pixelsPerWord @ height depth: formNativeDepth. - slave - primJPEGReadImage: decompressStruct - fromByteArray: sourceBytes - onForm: form - doDithering: true - errorMgr: errorStruct]) ifTrue: [^nil]. - jpegDecompressStruct overwriteContentsWith: decompressStruct. - jpegErrorMgr2Struct overwriteContentsWith: errorStruct. - source overwriteContentsWith: sourceBytes. "could happen..." - ByteArray adoptInstance: form bits. - formBitmap overwriteContentsWith: form bits. - ^nil! Item was added: + ----- Method: JPEGReadWriter2Plugin>>primJPEGWriteImageonByteArrayformqualityprogressiveJPEGerrorMgrWriteScanlines: (in category 'simulation') ----- + primJPEGWriteImageonByteArrayformqualityprogressiveJPEGerrorMgrWriteScanlines: width _: height _: nativeDepth _: bitmap _: jpegCompressStruct _: jpegErrorMgr2Struct _: quality _: progressiveFlag _: pixelsPerWord _: wordsPerRow _: destination _: destinationSizePtr + "void primJPEGWriteImageonByteArrayformqualityprogressiveJPEGerrorMgrWriteScanlines( + unsigned int width, + unsigned int height, + int nativeDepth, + unsigned int* bitmap, + char* jpegCompressStruct, + char* jpegErrorMgr2Struct, + int quality, + int progressiveFlag, + unsigned int pixelsPerWord, + unsigned int wordsPerRow, + char* destination, + unsigned int* destinationSizePtr)" + <doNotGenerate> + | bits form compressStruct errorStruct destinationBytes destinationSize | + bits := bitmap asByteArray. + Bitmap adoptInstance: bits. + form := Form extent: width @ height depth: nativeDepth bits: bits. + compressStruct := jpegCompressStruct asByteArray. + errorStruct := jpegErrorMgr2Struct asByteArray. + destinationBytes := destination asByteArray. + (self evaluateIfFailed: + [destinationSize :=JPEGReadWriter2 new + primJPEGWriteImage: compressStruct + onByteArray: destinationBytes + form: form + quality: quality + progressiveJPEG: progressiveFlag + errorMgr: errorStruct]) ifTrue: [^nil]. + jpegCompressStruct overwriteContentsWith: compressStruct. + jpegErrorMgr2Struct overwriteContentsWith: errorStruct. + destination overwriteContentsWith: destinationBytes. + destinationSizePtr at: 0 put: destinationSize. + ^nil! Item was removed: - ----- Method: JPEGReadWriter2Plugin>>primJPEGWriteImageonByteArrayformqualityprogressiveJPEGerrorMgrWriteScanlines:_:_:_:_:_:_:_:_:_:_:_: (in category 'simulation') ----- - primJPEGWriteImageonByteArrayformqualityprogressiveJPEGerrorMgrWriteScanlines: width _: height _: nativeDepth _: bitmap _: jpegCompressStruct _: jpegErrorMgr2Struct _: quality _: progressiveFlag _: pixelsPerWord _: wordsPerRow _: destination _: destinationSizePtr - "void primJPEGWriteImageonByteArrayformqualityprogressiveJPEGerrorMgrWriteScanlines( - unsigned int width, - unsigned int height, - int nativeDepth, - unsigned int* bitmap, - char* jpegCompressStruct, - char* jpegErrorMgr2Struct, - int quality, - int progressiveFlag, - unsigned int pixelsPerWord, - unsigned int wordsPerRow, - char* destination, - unsigned int* destinationSizePtr)" - <doNotGenerate> - | bits form compressStruct errorStruct destinationBytes destinationSize | - bits := bitmap asByteArray. - Bitmap adoptInstance: bits. - form := Form extent: width @ height depth: nativeDepth bits: bits. - compressStruct := jpegCompressStruct asByteArray. - errorStruct := jpegErrorMgr2Struct asByteArray. - destinationBytes := destination asByteArray. - (self evaluateIfFailed: - [destinationSize :=JPEGReadWriter2 new - primJPEGWriteImage: compressStruct - onByteArray: destinationBytes - form: form - quality: quality - progressiveJPEG: progressiveFlag - errorMgr: errorStruct]) ifTrue: [^nil]. - jpegCompressStruct overwriteContentsWith: compressStruct. - jpegErrorMgr2Struct overwriteContentsWith: errorStruct. - destination overwriteContentsWith: destinationBytes. - destinationSizePtr at: 0 put: destinationSize. - ^nil! Item was changed: ----- Method: Matrix2x3Plugin>>roundAndStoreResultPoint: (in category 'private') ----- roundAndStoreResultPoint: nItemsToPop "Store the result of a previous operation. Fail if we cannot represent the result as SmallInteger" m23ResultX := m23ResultX + 0.5. m23ResultY := m23ResultY + 0.5. + ((self okayIntValue: m23ResultX) + and: [self okayIntValue: m23ResultY]) ifFalse: + [^interpreterProxy primitiveFail]. + interpreterProxy + pop: nItemsToPop + thenPush: (interpreterProxy + makePointwithxValue: m23ResultX asInteger + yValue: m23ResultY asInteger)! - (self okayIntValue: m23ResultX) ifFalse:[^interpreterProxy primitiveFail]. - (self okayIntValue: m23ResultY) ifFalse:[^interpreterProxy primitiveFail]. - interpreterProxy pop: nItemsToPop thenPush: - (interpreterProxy makePointwithxValue: m23ResultX asInteger - yValue: m23ResultY asInteger)! Item was added: + ----- Method: Spur64BitMemoryManager>>memmove: (in category 'simulation only') ----- + memmove: destAddress _: sourceAddress _: bytes + <doNotGenerate> + | dst src | + dst := destAddress asInteger. + src := sourceAddress asInteger. + "Emulate the c library memmove function" + self assert: bytes \\ 4 = 0. + destAddress > sourceAddress + ifTrue: + [bytes - 4 to: 0 by: -4 do: + [:i| self long32At: dst + i put: (self long32At: src + i)]] + ifFalse: + [0 to: bytes - 4 by: 4 do: + [:i| self long32At: dst + i put: (self long32At: src + i)]]! Item was removed: - ----- Method: Spur64BitMemoryManager>>memmove:_:_: (in category 'simulation only') ----- - memmove: destAddress _: sourceAddress _: bytes - <doNotGenerate> - | dst src | - dst := destAddress asInteger. - src := sourceAddress asInteger. - "Emulate the c library memmove function" - self assert: bytes \\ 4 = 0. - destAddress > sourceAddress - ifTrue: - [bytes - 4 to: 0 by: -4 do: - [:i| self long32At: dst + i put: (self long32At: src + i)]] - ifFalse: - [0 to: bytes - 4 by: 4 do: - [:i| self long32At: dst + i put: (self long32At: src + i)]]! Item was added: + ----- Method: SpurMemoryManager>>memcpy: (in category 'simulation') ----- + memcpy: destAddress _: sourceAddress _: bytes + "For SpurGenerationScavenger>>copyToFutureSpace:bytes:. N.B. If ranges overlap, must use memmove." + <doNotGenerate> + self deny: ((destAddress <= sourceAddress and: [destAddress asInteger + bytes > sourceAddress]) + or: [sourceAddress <= destAddress and: [sourceAddress asInteger + bytes > destAddress]]). + ^self memmove: destAddress _: sourceAddress _: bytes! Item was removed: - ----- Method: SpurMemoryManager>>memcpy:_:_: (in category 'simulation') ----- - memcpy: destAddress _: sourceAddress _: bytes - "For SpurGenerationScavenger>>copyToFutureSpace:bytes:. N.B. If ranges overlap, must use memmove." - <doNotGenerate> - self deny: ((destAddress <= sourceAddress and: [destAddress asInteger + bytes > sourceAddress]) - or: [sourceAddress <= destAddress and: [sourceAddress asInteger + bytes > destAddress]]). - ^self memmove: destAddress _: sourceAddress _: bytes! Item was added: + ----- Method: VMClass>>memcpy: (in category 'C library simulation') ----- + memcpy: dString _: sString _: bytes + <doNotGenerate> + "implementation of memcpy(3). N.B. If ranges overlap, must use memmove." + (dString isString or: [sString isString]) ifFalse: + [| destAddress sourceAddress | + dString class == ByteArray ifTrue: + [self memcpy: dString _: sString _: bytes]. + destAddress := dString asInteger. + sourceAddress := sString asInteger. + self deny: ((destAddress <= sourceAddress and: [destAddress + bytes > sourceAddress]) + or: [sourceAddress <= destAddress and: [sourceAddress + bytes > destAddress]])]. + dString isInteger + ifTrue: + [1 to: bytes do: + [:i| | v | + v := sString isString + ifTrue: [sString basicAt: i] + ifFalse: [self byteAt: sString + i - 1]. + self byteAt: dString + i - 1 put: v]] + ifFalse: + [1 to: bytes do: + [:i| | v | + v := sString isString + ifTrue: [sString basicAt: i] + ifFalse: [self byteAt: sString + i - 1]. + dString basicAt: i put: v]]. + ^dString! Item was removed: - ----- Method: VMClass>>memcpy:_:_: (in category 'C library simulation') ----- - memcpy: dString _: sString _: bytes - <doNotGenerate> - "implementation of memcpy(3). N.B. If ranges overlap, must use memmove." - (dString isString or: [sString isString]) ifFalse: - [| destAddress sourceAddress | - dString class == ByteArray ifTrue: - [self memcpy: dString _: sString _: bytes]. - destAddress := dString asInteger. - sourceAddress := sString asInteger. - self deny: ((destAddress <= sourceAddress and: [destAddress + bytes > sourceAddress]) - or: [sourceAddress <= destAddress and: [sourceAddress + bytes > destAddress]])]. - dString isInteger - ifTrue: - [1 to: bytes do: - [:i| | v | - v := sString isString - ifTrue: [sString basicAt: i] - ifFalse: [self byteAt: sString + i - 1]. - self byteAt: dString + i - 1 put: v]] - ifFalse: - [1 to: bytes do: - [:i| | v | - v := sString isString - ifTrue: [sString basicAt: i] - ifFalse: [self byteAt: sString + i - 1]. - dString basicAt: i put: v]]. - ^dString! Item was added: + ----- Method: VMClass>>memmove: (in category 'C library simulation') ----- + memmove: destAddress _: sourceAddress _: bytes + <doNotGenerate> + | dst src | + dst := destAddress asInteger. + src := sourceAddress asInteger. + "Emulate the c library memmove function" + self assert: bytes \\ 4 = 0. + destAddress > sourceAddress + ifTrue: + [bytes - 4 to: 0 by: -4 do: + [:i| self longAt: dst + i put: (self longAt: src + i)]] + ifFalse: + [0 to: bytes - 4 by: 4 do: + [:i| self longAt: dst + i put: (self longAt: src + i)]]! Item was removed: - ----- Method: VMClass>>memmove:_:_: (in category 'C library simulation') ----- - memmove: destAddress _: sourceAddress _: bytes - <doNotGenerate> - | dst src | - dst := destAddress asInteger. - src := sourceAddress asInteger. - "Emulate the c library memmove function" - self assert: bytes \\ 4 = 0. - destAddress > sourceAddress - ifTrue: - [bytes - 4 to: 0 by: -4 do: - [:i| self longAt: dst + i put: (self longAt: src + i)]] - ifFalse: - [0 to: bytes - 4 by: 4 do: - [:i| self longAt: dst + i put: (self longAt: src + i)]]! Item was added: + ----- Method: VMClass>>strcat: (in category 'C library simulation') ----- + strcat: aString _: bString + <doNotGenerate> + "implementation of strcat(3)" + ^(self asString: aString), (self asString: bString)! Item was removed: - ----- Method: VMClass>>strcat:_: (in category 'C library simulation') ----- - strcat: aString _: bString - <doNotGenerate> - "implementation of strcat(3)" - ^(self asString: aString), (self asString: bString)! Item was added: + ----- Method: VMClass>>strncmp: (in category 'C library simulation') ----- + strncmp: aString _: bString _: n + <doNotGenerate> + "implementation of strncmp(3)" + bString isString + ifTrue: + [1 to: n do: + [:i| | v | + v := (aString basicAt: i) - (bString basicAt: i). + v ~= 0 ifTrue: [^v]]] + ifFalse: + [1 to: n do: + [:i| | v | + v := (aString basicAt: i) - (self byteAt: bString + i - 1). + v ~= 0 ifTrue: [^v]]]. + ^0! Item was removed: - ----- Method: VMClass>>strncmp:_:_: (in category 'C library simulation') ----- - strncmp: aString _: bString _: n - <doNotGenerate> - "implementation of strncmp(3)" - bString isString - ifTrue: - [1 to: n do: - [:i| | v | - v := (aString basicAt: i) - (bString basicAt: i). - v ~= 0 ifTrue: [^v]]] - ifFalse: - [1 to: n do: - [:i| | v | - v := (aString basicAt: i) - (self byteAt: bString + i - 1). - v ~= 0 ifTrue: [^v]]]. - ^0! Item was added: + ----- Method: VMClass>>strncpy: (in category 'C library simulation') ----- + strncpy: dest _: src _: n + <doNotGenerate> + "implementation of strncpy(3). + See e.g. https://manpages.debian.org/stretch/manpages-dev/strncpy.3.en.html + The C version always takes an address; the simulation allows a String, ByteArray, + CArray or address within the simulation object memory (Positive Integer)" + | getBlock setBlock count | + count := n. + "Determine the source and destination access blocks based on the parameter type" + getBlock := src isCollection + ifTrue: + [count := count min: src size. + src isString + ifTrue: [[ :idx | src basicAt: idx]] "basicAt: answers integers" + ifFalse: + [src class == ByteArray ifTrue: + [[ :idx | src at: idx]]]] + ifFalse: + [src isInteger + ifTrue: [[ :idx | self byteAt: src + idx - 1]] + ifFalse: + [src class == CArray ifTrue: + [[ :idx | src at: idx - 1]]]]. + getBlock ifNil: [self error: 'unhandled type of source string']. + setBlock := dest isCollection + ifTrue: + [dest isString + ifTrue: [[ :idx | dest basicAt: idx put: (getBlock value: idx)]] "basicAt:put: stores integers" + ifFalse: + [dest class == ByteArray ifTrue: + [[ :idx | dest at: idx put: (getBlock value: idx)]]]] + ifFalse: + [dest isInteger ifTrue: + [[ :idx | self byteAt: dest + idx - 1 put: (getBlock value: idx)]]]. + setBlock ifNil: [self error: 'unhandled type of destination string']. + 1 to: count do: setBlock. + "SVr4, 4.3BSD, C89, C99 require the remainder of the buffer be filled with nulls" + getBlock := [:idx| 0]. + count + 1 to: n do: setBlock. + ^dest! Item was removed: - ----- Method: VMClass>>strncpy:_:_: (in category 'C library simulation') ----- - strncpy: dest _: src _: n - <doNotGenerate> - "implementation of strncpy(3). - See e.g. https://manpages.debian.org/stretch/manpages-dev/strncpy.3.en.html - The C version always takes an address; the simulation allows a String, ByteArray, - CArray or address within the simulation object memory (Positive Integer)" - | getBlock setBlock count | - count := n. - "Determine the source and destination access blocks based on the parameter type" - getBlock := src isCollection - ifTrue: - [count := count min: src size. - src isString - ifTrue: [[ :idx | src basicAt: idx]] "basicAt: answers integers" - ifFalse: - [src class == ByteArray ifTrue: - [[ :idx | src at: idx]]]] - ifFalse: - [src isInteger - ifTrue: [[ :idx | self byteAt: src + idx - 1]] - ifFalse: - [src class == CArray ifTrue: - [[ :idx | src at: idx - 1]]]]. - getBlock ifNil: [self error: 'unhandled type of source string']. - setBlock := dest isCollection - ifTrue: - [dest isString - ifTrue: [[ :idx | dest basicAt: idx put: (getBlock value: idx)]] "basicAt:put: stores integers" - ifFalse: - [dest class == ByteArray ifTrue: - [[ :idx | dest at: idx put: (getBlock value: idx)]]]] - ifFalse: - [dest isInteger ifTrue: - [[ :idx | self byteAt: dest + idx - 1 put: (getBlock value: idx)]]]. - setBlock ifNil: [self error: 'unhandled type of destination string']. - 1 to: count do: setBlock. - "SVr4, 4.3BSD, C89, C99 require the remainder of the buffer be filled with nulls" - getBlock := [:idx| 0]. - count + 1 to: n do: setBlock. - ^dest! |
Free forum by Nabble | Edit this page |