Integer arithmetic

Christian Tismer tismer at tismer.com
Tue Mar 25 11:30:24 CET 2003


Alex Martelli wrote:
> Daniel Timothy Bentley wrote:
> 
> 
>>I am currently embarking on the utterly futile and mildly recursive task
>>of implementing a C interpreter in python (Jython specifically).
>>
>>Right now, I'm trying to think about integer ops.
...

Alex:
> so you code
> 
>     foo = makeint(bar + baz)
> 
> with some makeint function such as the above one.

I had a similar problem for the PyPy project. In order
to overcome the problem of always having to call
conversion functions, I wrote a class that tries
to promote its restricted type through expressions.

So if you start a variable by

x = r_int(42)

and perform any integer operations on it, the result
will stay in the same domain.

Feel free to use the attached code as you like.

ciao - chris

-- 
Christian Tismer             :^)   <mailto:tismer at tismer.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a     :    *Starship* http://starship.python.net/
14109 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34  home +49 30 802 86 56  pager +49 173 24 18 776
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?   http://www.stackless.com/
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: restricted_int.py
URL: <http://mail.python.org/pipermail/python-list/attachments/20030325/ae01eb2c/attachment.ksh>


More information about the Python-list mailing list