[Vm-dev] primFailCode currently dormant?
eliot.miranda at gmail.com
Sun May 2 18:23:14 UTC 2010
On Fri, Apr 30, 2010 at 10:56 PM, Igor Stasenko <siguctua at gmail.com> wrote:
> Alien adds a new primitive pragma:
> <primitive: 'foo' error: tempName module: 'bar' >
> where tempName is auto-declared during parsing as a special temp which
> will be used to retrieve primitive error code. i.e.
> <primitive: 'foo' error: code module: 'bar' >
> "prim failed , check the error code"
> code = 5 ifTrue: [ self error: 'you wrong' ]
> code = 666 ifTrue: [ self error: 'you are wrong as hell' ]
> The problem is, that i found that while its integrated in parser
> (through Alien package overrides),
> it leads to nowhere in current Interpreter. :(
But it's fully supported in the Newspeak VM and in the Cog VMs. Please
don't delete this.
> The sole reference to primFailCode is only in #primitiveFailFor: ,
> which actually should be used by prims to set the failure code:
> Interpreter>>primitiveFailFor: reasonCode
> "Set specific primitive failure."
> primFailCode := reasonCode.
> self primitiveFail.
> I'd like to propose an alternative implementation:
> - at VM side , add only a single primitive:
> self export: true.
> self pop: 1 thenPush: (self integerObjectOf: primFailCode).
> "reset the code"
> primFailCode := 0.
> At language side, we can support both, old and new format:
> Add the method , which will retrieve the code:
> "Primitive: answer the last primitive failure code. Resets the failure
> Note: it can fail only if we're running on older VMs, which has no
> support of this primitive, if so, answer the generic failure code"
> <primitive: 'primitiveLastFailureCode' module: ''>
> ^ 0
> And then, to handle things manually, one could use:
> Myclass>> foo
> <primitive: 'myprimitive' module: 'mymodule>
> "we're failed"
> | code |
> code := self lastFailureCode.
> ... handle the error code...
> And to support the Alien's new pragma pattern (primitive:error:module:)
> it can simply instruct the encoder to generate an implicit bytecode
> sequence (at method's beginning), which equals to:
> temp := self lastFailureCode.
> (where temp, is one, which used in pragma)
> What you think?
This is bad for a number of reasons, primarily thread-safety. There's
nothing to guarantee that the prim fail code is accessed before a process
switch which could cause the error code to get overwritten. Instead if you
wanted to do something in this area you could get the Newspeak VM and start
integrating the code there-from.
But I'm now in a position to put some effort into open sourcing Cog, having
completed my current Teleplace assignment, and so perhaps being patient and
waiting a little longer is the best approach. In the mean time please don't
change any of the primitive fail code stuff. Its fully functional in the
code we're using at Teleplace and in Newspeak and it would be good to avoid
> Best regards,
> Igor Stasenko AKA sig.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Vm-dev