On Sat, Oct 12, 2002 at 04:53:57PM +0200, Jerome Quelin wrote: > But I have a problem. When popping a value from an empty list, I get a "No > entries on list!" exception. Instead, I want to get a zero. I can add > something like: > > CHECK_EMPTY: > set I0, P2 > eq I0, 0, PUSH_ZERO > ret > PUSH_ZERO: > push P2, 0 > ret > > And then, before popping, I can add "bsr CHECK_EMPTY"... > But that's clumsy IMHO. > > So, what else can I do? Catching exceptions (is that possible with Parrot)?
Well, you could replace every 'pop I7, P2' with: set I7, P2 unless I7, L1234 pop I7, P2 L1234: ...program continues... The two better answers are (1) create your own PMC subclassing the IntList PMC, but override its pop() vtable entry with pasm code that checks for emptiness first; or (2) wait until Leo makes Array and PerlArray use list.c as their base implementations, and then you'll get the speed advantage of IntList while still using what you're using now. Note that #1 isn't possible yet either, and is probably a lot further off. (Actually, I'm the one to blame for #2 not yet being possible, because I've been stalling off committing Leo's PMC reorg patch because it seemed like a bunch of bugs have recently crept into the CVS tree, and I wanted a small set of recent changes to pore over looking for the culprits.)