VM Maker: VMMaker.oscog-akg.2346.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

VM Maker: VMMaker.oscog-akg.2346.mcz

commits-2
 
Alistair Grant uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-akg.2346.mcz

==================== Summary ====================

Name: VMMaker.oscog-akg.2346
Author: akg
Time: 7 March 2018, 10:06:25.159309 am
UUID: 314dcb1d-cd55-439c-972b-87c4b916d71a
Ancestors: VMMaker.oscog-eem.2345

FilePlugin connect to file primitives

- Rename primitiveFileOpenUseFileDescriptor to primitiveConnectToFileDescriptor
- Rename primitiveFileOpenUseFile to primitiveConnectToFile
- Add support for Windows
- Bug fix pointer retrieval in primitiveConnectToFile
- Additional comments

=============== Diff against VMMaker.oscog-eem.2345 ===============

Item was removed:
- ----- Method: FilePlugin>>cfileRecordSize (in category 'private') -----
- cfileRecordSize
- "Return the size of a stdio FILE* handle"
- <inline: #always>
- ^self sizeof: #'FILE*'!

Item was added:
+ ----- Method: FilePlugin>>connectToFd:write: (in category 'private') -----
+ connectToFd: fd write: writeFlag
+ "Connect to the supplied file descriptor. Answer the file oop.
+ On POSIX platforms this translates to fdopen().
+ writeFlag must be compatible with the existing file access."
+ | file fileOop |
+ <var: #file type: 'SQFile *'>
+ <var: 'fd' type: 'int'>
+ <export: true>
+ fileOop := interpreterProxy instantiateClass: interpreterProxy classByteArray indexableSize: self fileRecordSize.
+ file := self fileValueOf: fileOop.
+ interpreterProxy failed
+ ifFalse: [self cCode: 'sqConnectToFileDescriptor(file, fd, writeFlag)' inSmalltalk: [file]].
+ ^ fileOop!

Item was added:
+ ----- Method: FilePlugin>>connectToFile:write: (in category 'private') -----
+ connectToFile: cfile write: writeFlag
+ "Open the FILE* as file. Answer the file oop.
+ writeFlag must be compatible with the existing file access."
+ | file fileOop |
+ <var: 'file' type: 'SQFile *'>
+ <var: 'cfile' type: 'void *'>
+ <export: true>
+ fileOop := interpreterProxy instantiateClass: interpreterProxy classByteArray indexableSize: self fileRecordSize.
+ file := self fileValueOf: fileOop.
+ interpreterProxy failed
+ ifFalse: [self cCode: 'sqConnectToFile(file, cfile, writeFlag)' inSmalltalk: [file]].
+ ^ fileOop!

Item was removed:
- ----- Method: FilePlugin>>fileOpenFd:write: (in category 'private') -----
- fileOpenFd: fd write: writeFlag
- "Open the fd as file. Answer the file oop."
- | file fileOop |
- <var: #file type: 'SQFile *'>
- <var: 'fd' type: 'int'>
- <export: true>
- fileOop := interpreterProxy instantiateClass: interpreterProxy classByteArray indexableSize: self fileRecordSize.
- file := self fileValueOf: fileOop.
- interpreterProxy failed
- ifFalse: [self cCode: 'sqFileFdOpen(file, fd, writeFlag)' inSmalltalk: [file]].
- ^ fileOop!

Item was removed:
- ----- Method: FilePlugin>>fileOpenFile:write: (in category 'private') -----
- fileOpenFile: cfile write: writeFlag
- "Open the FILE* as file. Answer the file oop."
- | file fileOop |
- <var: #file type: 'SQFile *'>
- <var: 'cfile' type: 'FILE *'>
- <export: true>
- fileOop := interpreterProxy instantiateClass: interpreterProxy classByteArray indexableSize: self fileRecordSize.
- file := self fileValueOf: fileOop.
- interpreterProxy failed
- ifFalse: [self cCode: 'sqFileFileOpen(file, cfile, writeFlag)' inSmalltalk: [file]].
- ^ fileOop!

Item was added:
+ ----- Method: FilePlugin>>pointerFrom: (in category 'private') -----
+ pointerFrom: pointerByteArray
+ "Answer the machine address contained in anExternalAddressOop."
+
+ | ptr addressUnion idx |
+ <returnTypeC: 'void *'>
+ <var: 'ptr' type: 'unsigned char *'>
+ <var: 'addressUnion' type: 'union {void *address; unsigned char bytes[sizeof(void *)];}'>
+ ((interpreterProxy is: pointerByteArray KindOf: 'ByteArray') and:
+ [(interpreterProxy stSizeOf: pointerByteArray) = self sizeOfPointer])
+ ifFalse: [^ nil].
+ ptr := interpreterProxy arrayValueOf: pointerByteArray.
+ idx := 0.
+ [idx < self sizeOfPointer] whileTrue:
+ [self cCode: 'addressUnion.bytes[idx] = ptr[idx]'.
+ idx := idx + 1].
+ ^ self cCode: 'addressUnion.address' inSmalltalk: [addressUnion]
+ !

Item was added:
+ ----- Method: FilePlugin>>primitiveConnectToFile (in category 'file primitives') -----
+ primitiveConnectToFile
+ "Connect to the file with the supplied FILE* and writeFlag.
+ FILE* must be supplied in a byte object (ByteArray) with the platform address size.
+ writeFlag must be a boolean and compatible with the existing file access."
+ | writeFlag cfileOop cfile filePointer |
+ <var: 'cfile' type: 'void* '>
+ <export: true>
+ writeFlag := interpreterProxy
+ booleanValueOf: (interpreterProxy stackValue: 0).
+ cfileOop := interpreterProxy stackValue: 1.
+ cfile := self pointerFrom: cfileOop.
+ cfile ifNil:
+ [^interpreterProxy primitiveFailFor: PrimErrBadArgument].
+ filePointer := self connectToFile: cfile write: writeFlag.
+ interpreterProxy failed ifFalse:
+ [^interpreterProxy pop: 3 "rcvr, name, writeFlag"
+ thenPush: filePointer].
+ ^interpreterProxy primitiveFail.!

Item was added:
+ ----- Method: FilePlugin>>primitiveConnectToFileDescriptor (in category 'file primitives') -----
+ primitiveConnectToFileDescriptor
+ "Connect to the existing file identified by fileDescriptor.
+ fileDescriptor must be an integer.
+ writeFlag is aboolean indicating whether to open in read or write mode and must be compatible with the existing file access."
+ | writeFlag fdPointer fd filePointer |
+ <var: 'fd' type: 'int'>
+ <export: true>
+ writeFlag := interpreterProxy
+ booleanValueOf: (interpreterProxy stackValue: 0).
+ fdPointer := interpreterProxy stackValue: 1.
+ (interpreterProxy isIntegerObject: fdPointer)
+ ifFalse: [^ interpreterProxy primitiveFailFor: PrimErrBadArgument].
+ fd := interpreterProxy integerValueOf: fdPointer.
+ filePointer := self connectToFd: fd write: writeFlag.
+ interpreterProxy failed
+ ifFalse: [^interpreterProxy pop: 3 "rcvr, name, writeFlag"
+ thenPush: filePointer].
+ ^interpreterProxy primitiveFail.!

Item was removed:
- ----- Method: FilePlugin>>primitiveFileOpenUseFile (in category 'file primitives') -----
- primitiveFileOpenUseFile
- "Open the file with the supplied FILE* and writeFlag.
- FILE* must be supplied in a byte object (ByteArray) with the platform address size.
- writeFlag must be a boolean."
- | writeFlag cfileOop cfile filePointer |
- <var: 'cfile' type: 'FILE* '>
- <export: true>
- writeFlag := interpreterProxy
- booleanValueOf: (interpreterProxy stackValue: 0).
- cfileOop := interpreterProxy stackValue: 1.
- (((interpreterProxy isBytes: cfileOop) and:
- [(interpreterProxy byteSizeOf: cfileOop) = self cfileRecordSize]))
- ifFalse: [^interpreterProxy primitiveFailFor: PrimErrBadArgument].
- cfile := interpreterProxy firstIndexableField: cfileOop.
- interpreterProxy failed ifFalse:
- [filePointer := self fileOpenFile: cfile write: writeFlag].
- interpreterProxy failed ifFalse:
- [^interpreterProxy pop: 3 "rcvr, name, writeFlag"
- thenPush: filePointer].
- ^interpreterProxy primitiveFail.!

Item was removed:
- ----- Method: FilePlugin>>primitiveFileOpenUseFileDescriptor (in category 'file primitives') -----
- primitiveFileOpenUseFileDescriptor
- "Open the file with the supplied file descriptor and writeFlag.
- fileDescriptor must be an integer.
- writeFlag must be a boolean."
- | writeFlag fdPointer fd filePointer |
- <var: 'fd' type: 'int'>
- <export: true>
- writeFlag := interpreterProxy
- booleanValueOf: (interpreterProxy stackValue: 0).
- fdPointer := interpreterProxy stackValue: 1.
- (interpreterProxy isIntegerObject: fdPointer)
- ifFalse: [^ interpreterProxy primitiveFailFor: PrimErrBadArgument].
- fd := interpreterProxy integerValueOf: fdPointer.
- filePointer := self fileOpenFd: fd write: writeFlag.
- interpreterProxy failed
- ifFalse: [^interpreterProxy pop: 3 "rcvr, name, writeFlag"
- thenPush: filePointer].
- ^interpreterProxy primitiveFail.!

Item was added:
+ ----- Method: FilePlugin>>sizeOfPointer (in category 'private') -----
+ sizeOfPointer
+ "Return the size of a pointer (address size)"
+ <inline: #always>
+ ^self sizeof: #'void *'!