[Vm-dev] VM Maker: VMMaker.oscog-akg.2340.mcz
commits at source.squeak.org
commits at source.squeak.org
Sat Mar 3 14:47:08 UTC 2018
Alistair Grant uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-akg.2340.mcz
==================== Summary ====================
Name: VMMaker.oscog-akg.2340
Author: akg
Time: 3 March 2018, 3:37:32.917843 pm
UUID: 27e21eb5-be74-4672-a779-32c073498b95
Ancestors: VMMaker.oscog-eem.2339
Extend FilePlugin to allow a file to be opened using either the file descriptor (fd) or FILE* in Pharo.
Original PR: pharo-project/pharo-vm#108
Updated PR: pharo-project/pharo-vm#142
(both superseeded)
Many thanks to @zecke (Holger Freyther) for the original code.
As a (redundant) example of how this can be used, to open stderr (fd=2)
for writing:
| stderr |
stderr := BinaryFileStream handle: (FilePluginPrims new
openFileDescriptor: 2 writable: true)
file: (File named: 'fd2')
forWrite: true.
stderr nextPutAll: 'Hello World'; lf.
=============== Diff against VMMaker.oscog-eem.2339 ===============
Item was added:
+ ----- Method: FilePlugin>>cfileRecordSize (in category 'pharo primitives') -----
+ cfileRecordSize
+ "Return the size of a stdio FILE* handle"
+ <inline: #always>
+ ^self sizeof: #'FILE*'!
Item was added:
+ ----- Method: FilePlugin>>fileOpenFd:write: (in category 'private - pharo') -----
+ fileOpenFd: fd write: writeFlag
+ "Open the fd as file. Answer the file oop."
+ | file fileOop |
+ <option: #PharoVM>
+ <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 added:
+ ----- Method: FilePlugin>>fileOpenFile:write: (in category 'private - pharo') -----
+ fileOpenFile: cfile write: writeFlag
+ "Open the FILE* as file. Answer the file oop."
+ | file fileOop |
+ <option: #PharoVM>
+ <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>>primitiveFileOpenUseFile (in category 'pharo primitives') -----
+ primitiveFileOpenUseFile
+ | writeFlag cfileOop cfile filePointer |
+ <option: #PharoVM>
+ <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 added:
+ ----- Method: FilePlugin>>primitiveFileOpenUseFileDescriptor (in category 'pharo primitives') -----
+ primitiveFileOpenUseFileDescriptor
+ | writeFlag fdPointer fd filePointer |
+ <option: #PharoVM>
+ <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.!
More information about the Vm-dev
mailing list