[Vm-dev] VM Maker: VMMaker.oscog-eem.2347.mcz

Levente Uzonyi leves at caesar.elte.hu
Thu Mar 8 20:21:52 UTC 2018


On Thu, 8 Mar 2018, Eliot Miranda wrote:

> 
> Hi Levente,
>
>> On Mar 7, 2018, at 3:44 PM, Levente Uzonyi <leves at caesar.elte.hu> wrote:
>> 
>>> On Wed, 7 Mar 2018, commits at source.squeak.org wrote:
>>> 
>>> Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
>>> http://source.squeak.org/VMMaker/VMMaker.oscog-eem.2347.mcz
>>> 
>> 
>> snip
>> 
>>> Item was changed:
>>> ----- 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 *'>
>>> -    <var: 'cfile' type: 'void* '>
>>>    <export: true>
>>> +    writeFlag := interpreterProxy booleanValueOf: (interpreterProxy stackValue: 0).
>>> -    writeFlag := interpreterProxy
>>> -                booleanValueOf: (interpreterProxy stackValue: 0).
>> 
>> It should be checked here if the primitive has failed or not, shouldn't it?
>
> Not necessarily.  All failures only set the failure code; they don't reset it.  So it is acceptable to gather a sequence of parameters and perform a single failure check.  The important thing is to check for failure before doing anything with the parameters.

Well, yes, in the end #connectToFile:write: will not use the value of 
writeFlag, but that is way too unintuitive in my option.
Also, since there is an error code for this case, the code could just 
return with PrimErrBadArgument.

Levente

>
>
>>
>>>    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 pop: 3 "rcvr, name, writeFlag"
>>> -                            thenPush: filePointer].
>>> -    ^interpreterProxy primitiveFail.!
>>> 
>>> Item was changed:
>>> ----- 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>
>>> -    <var: 'fd' type: 'int'>
>>>    <export: true>
>>>    writeFlag := interpreterProxy
>>>                booleanValueOf: (interpreterProxy stackValue: 0).
>> 
>> Same as above.
>> 
>> Levente
>>
>>>    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 failed
>>> -        ifFalse: [^interpreterProxy pop: 3 "rcvr, name, writeFlag"
>>> -            thenPush: filePointer].
>>> -    ^interpreterProxy primitiveFail.!


More information about the Vm-dev mailing list