[Vm-dev] primitives argument handling

Eliot Miranda eliot.miranda at gmail.com
Sun Aug 21 03:29:36 UTC 2016


Hi Ben,

> On Aug 21, 2016, at 3:34 AM, Ben Coman <btc at openinworld.com> wrote:
> 
> 
> Thanks Bert.  So in #primitiveVMParameter I see...
> 
> argumentCount = 0 ifTrue: [ ...  self pop: 1 thenPush: ... ].
> argumentCount = 1 ifTrue: [ ... self pop: 2 thenPush: ... ].
> 
> ...which I understand.   However take for example
> #primitiveUTCMicrosecondClock which currently does not check
> argumentCount and so always does [ self pop: 1 ... ].   If this
> primitive was called with a parameter, I presume this would cause a
> leak on the stack since it does not fail for argumentCount > 0 ?
> 
> So if I wanted to add an argument to primitiveUTCMicrosecondClock to
> return one of the raw clocks that fed a clock skew algorithm that was
> the primary clock used by the system, by adding argumentCount
> conditional logic, an Image using that feature would be broken on an
> older VM?

Yes.

BTW, in general VMs are backward compatible and images are forward compatible, at least within major releases.  A new VM should guarantee to run older images.  Hence Sour was also a chance to clean house.

> 
> cheers -ben
> 
>> On Sun, Aug 21, 2016 at 1:15 AM, Bert Freudenberg <bert at freudenbergs.de> wrote:
>> 
>> Each primitive is supposed to check the number of arguments it is called with. If the number is not what it expects, it must fail, and leave the stack untouched (so that the primitive method can run the failure code).
>> 
>> The same primitive can also handle different numbers of arguments, e.g.
>> 
>> SystemNavigation default browseAllSelect: [:cm | cm primitive = 254]
>> 
>> - Bert -
>> 
>>> On Sat, Aug 20, 2016 at 3:41 PM, Ben Coman <btc at openinworld.com> wrote:
>>> 
>>> 
>>> Just checking my understanding of how something works.  I think I
>>> heard somewhere that its the primitive's job to drop its arguments off
>>> the stack.
>>> 
>>> So it would seem(??) that starting with VM1/Image1 having primitive
>>> #primX ... if VM2 had modified that primitive to take an optional
>>> argument such that Image2 invoked that primitive as #primX: ,  then
>>> Image2 could not be backward compatible with VM, because Image2 would
>>> be adding the argument to the stack that would not be removed by VM1.
>>> 
>>> The reason I ask is I was considering having a go at the VM clock
>>> improvements issue [1] I logged.  As well as implementing the clock
>>> skewing algorithm Eliot suggested, I was also wanting to provide Image
>>> access to the two clocks used by that algorithm - so the algorithm
>>> performance could be monitored from the Image.
>>> 
>>> cheers -ben
>>> 
>>> [1] https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/36
>> 
>> 
>> 


More information about the Vm-dev mailing list