[Vm-dev] primFailCode currently dormant?

Igor Stasenko siguctua at gmail.com
Sat May 1 05:56:47 UTC 2010


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. :(

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 code.
  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?

Best regards,
Igor Stasenko AKA sig.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lastFailure.1.cs
Type: application/octet-stream
Size: 320 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20100501/5881a043/lastFailure.1.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lastFailure-Object.1.cs
Type: application/octet-stream
Size: 471 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20100501/5881a043/lastFailure-Object.1.obj

More information about the Vm-dev mailing list