Hi
I want to explain where ec is coming. I thought that the arguments of pragmas could only be literal and when I see ec it looks like a variable set by the VM newMethod: numberOfBytes header: headerWord "Primitive. Answer an instance of me. The number of literals (and other information) is specified by the headerWord (see my class comment). The first argument specifies the number of fields for bytecodes in the method. Fail if either argument is not a SmallInteger, or if numberOfBytes is negative, or if memory is low. Once the header of a method is set by this primitive, it cannot be changed to change the number of literals. Essential. See Object documentation whatIsAPrimitive." <primitive: 79 error: ec> ec == #'insufficient object memory' ifTrue: [^self handleFailingNewMethod: numberOfBytes header: headerWord]. ^self primitiveFailed Stef |
> On 22 Jun 2016, at 15:59, stepharo <[hidden email]> wrote: > > Hi > > I want to explain where ec is coming. > > I thought that the arguments of pragmas could only be literal and when I see ec it looks like a variable set by the VM > > > newMethod: numberOfBytes header: headerWord > "Primitive. Answer an instance of me. The number of literals (and other > information) is specified by the headerWord (see my class comment). > The first argument specifies the number of fields for bytecodes in the > method. Fail if either argument is not a SmallInteger, or if numberOfBytes > is negative, or if memory is low. Once the header of a method is set by > this primitive, it cannot be changed to change the number of literals. > Essential. See Object documentation whatIsAPrimitive." > > <primitive: 79 error: ec> > ec == #'insufficient object memory' ifTrue: > [^self handleFailingNewMethod: numberOfBytes header: headerWord]. > ^self primitiveFailed > > > Stef > > That is correct. It’s still a literal though. |
It's a special case added a couple year ago to figure out why a primitive fail. It's a special temporary variable that holds an error code. The special object array defines a list of error code that the VM can use to explain to the programmer why the primitive failed, which are currently symbols. On Wed, Jun 22, 2016 at 4:22 PM, Max Leske <[hidden email]> wrote:
|
This is simpler than the VW scheme which allocates a PrimFailCode that has a name inst car and a parameter. Our system has only the name.
|
In reply to this post by Clément Béra
So could we have a nice method comments that I can add to all the primitive using this ec? Proposal:
https://pharo.fogbugz.com/f/cases/18618/Better-additional-comment-for-primitive-79-error-ec-usage "ec is a special temporary variable that holds an error
code. In the VM primitive, failure is indicated by a variable
called primFailCode being non-zero. On activating a method with a
failing primitive, if the index is in bounds of the
primitiveFailCodes array in the VMspecialObjectsArray then the
failure code substitutes the symbol in the primitiveFailCodes
array, otherwise it supplies the integer value." Because what I like the most in smalltalk besides live coding is
comments. Stef
Le 22/6/16 à 17:25, Clément Bera a
écrit :
|
All the primitives in the Cog have error codes. Pharo does not write it explicitly for each primitive, but Pharo could. Knowing why a primitive failed is very useful. The Cog support over 400 primitives. Do you want to copy that comment 400 times ? I don't think so. What if one wants to update that comment, one would need to update all the 400 comments ? That's insane and very hard to maintain. It would be nice to update the comment of Object class>>#whatIsAPrimitive with a paragraph on error code instead, such as the one you wrote. On Sun, Jun 26, 2016 at 8:00 PM, stepharo <[hidden email]> wrote:
|
There are 28 users of primitive:error: not 400. So where can I find the others? Do you know if whatIsAPrimitive
description is up to date? Stef Le 26/6/16 à 21:00, Clément Bera a
écrit :
|
There is not only #primitive:error: but #primitive:module:error: and #primitive:error:module: . Then when you look at Object>>#at:, it's written <primitive: 60> but you could write <primitive: 60 error: ec>. I don't know why the error code is not there by default, it could be for performance, but it is supported and it is used to know why the primitive fails. So you can look at all of the users of #primitive: and #primitive:module: too. When I do this in my Pharo image: CompiledMethod allInstances count: [ :each | each primitive ~= 0 ] I have 9136. And all of them can have error code, though only 268 use it explicitly. whatIsAPrimitive comment looks correct. There are little details to fix: - LargeIntegers are 32 or 64 bits, not 16bits. - the code convention for 'no lookup' is respected, but writting 'optional' for optional primitive and 'essential' for essential primitive is not done in many primitives in Pharo. Maybe it makes sense for numbered primitive only. One needs to check where it's done, where it's not done and why. I think it's good to improve comments related to primitives as this is one part of the system where you cannot understand what they do just by reading the Smalltalk code. Thanks for doing that Stef. On Sun, Jun 26, 2016 at 10:06 PM, stepharo <[hidden email]> wrote:
|
Le 27/6/16 à 09:41, Clément Bera a
écrit :
Ok I understand now.
Ok so the what is a primitive is the way to go. Would be nice that someone knowing help us :)
Yes this is my point. I want that people can learn just reading it.
|
Free forum by Nabble | Edit this page |