autoboxing

66 views
Skip to first unread message

Dean Hall

unread,
Dec 11, 2012, 12:27:42 AM12/11/12
to python-o...@googlegroups.com
Hey everybody! Sorry it's been a long time. I have some good news, though.

Dr. Scott Rixner of Rice University in Houston, TX, USA has been leading a project that uses and improves p14p.

Person: http://www.cs.rice.edu/~rixner/
Slides: https://www.usenix.org/sites/default/files/conference/protected-files/barr_atc12_slides.pdf
Presentation: https://www.usenix.org/conference/usenixfederatedconferencesweek/design-and-implementation-embedded-python-run-time-system

Dr. Rixner donated a changeset that performs autoboxing. Autoboxing is a term that means, roughly, to turn a primitive type into an instance of an object wrapper class. What it means is you can now do this::

ipm> import list
ipm> l = [];
ipm> l.append(42)
ipm> l
[42]

Note that you MUST "import <type>" of whatever type you are boxing.

I just pushed this changeset to the default branch. I have enabled it for the posix64 and mbed platforms. If you want it on your platform, edit your platform's pmfeatures.py to set HAVE_AUTOBOX to True.

I am NOT going to push this changeset to the v10 branch because I plan to implement this in a more natural way. But it is perfectly possible for you to apply this changeset yourself if you need it. Details here: http://code.google.com/p/python-on-a-chip/issues/detail?id=240

Autoboxing requires extra RAM to create the wrapper instance. So I only recommend using this feature if you have 16 KB or more of heap.

share and enjoy,

!!Dean

P.S. Here are the methods that are available:

ipm> import list
ipm> l = []; l.append(42)
ipm> l
[42]
ipm> l.extend([1,2,3,4])
ipm> l
[42, 1, 2, 3, 4]
ipm> l.append(42)
ipm> l.count(42)
2
ipm> l.index(3)
3
ipm> l.insert(0, "zero")
ipm> l
['zero', 42, 1, 2, 3, 4, 42]
ipm> l.pop()
42
ipm> l
['zero', 42, 1, 2, 3, 4]
ipm> l.remove(1)
ipm> l
['zero', 42, 2, 3, 4]


ipm> import dict
ipm> d = {}
ipm> d[0] = "zero"
ipm> d[1] = "one"
ipm> d[2] = "two"
ipm> d.keys()
[2, 1, 0]
ipm> d.has_key(0)
True
ipm> d.has_key(3)
False
ipm> d.has_key(None)
False
ipm> d.values()
['two', 'one', 'zero']


ipm> import string
ipm> s = "testing"
ipm> s.join(".")
't.e.s.t.i.n.g' # Bug: Inconsistent with CPython
ipm> s.count('t')
2
ipm> s.count('z')
0
ipm> s.find("t")
0
ipm> s.find("ti")
-1 # Bug: Inconsistent with CPython
ipm> s.find("i")
4

Gmail - neonmark

unread,
Dec 12, 2012, 5:54:55 AM12/12/12
to python-o...@googlegroups.com
Wow Dean this is great news. I've been reading up on the paper and
presentation. Looks excellent. He hints at some eventual release. I look
forward to it and to your V10 implementation. Can you expand on what you
mean by 'natural way' ?
I guess the extra use of ram is exchanged for useful functionality. He
indicates it should lower ram use but I guess he means in comparison to
loading the ram up with pointers...

The use of foreign function interfaces once again reminds me of the old
lisp machines where FFI was IIRC originally implemented. One day a
python machine I am sure :-)

Cheers, Mark...

pir...@gmail.com

unread,
Dec 12, 2012, 6:01:47 AM12/12/12
to python-o...@googlegroups.com
Can you expand on what you mean by 'natural way' ?

I think is about don't have to do any import at all, and being list and dict classes per itself like in CPython. This sound good... :-)


--
"Si quieres viajar alrededor del mundo y ser invitado a hablar en un monton de sitios diferentes, simplemente escribe un sistema operativo Unix."
– Linus Tordvals, creador del sistema operativo Linux

Dean Hall

unread,
Dec 12, 2012, 9:01:29 AM12/12/12
to python-o...@googlegroups.com
Natural way := Is when the built-in types become true instances of a class. Then calling <instance>.<method> does a lookup in the instance's class's attributes to find the callable and turn it into a method.

!!Dean
> --
> You are subscribed to the "python-on-a-chip" (or p14p for short) Google Group.
> Site: http://groups.google.com/group/python-on-a-chip

Reply all
Reply to author
Forward
0 new messages