By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,550 Members | 1,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,550 IT Pros & Developers. It's quick & easy.

micro-python - is it possible?

P: n/a
Hi,

Has anyone done any serious work on producing a subset of python's
language definition that would suit it to a tiny microcontroller
environment?

In its full form, python is a resource hog. If a microcontroller
implementation honoured the 'everything is an object' philosophy, the
code would spend 80% of the time in memory allocation/deallocation
routines, taking tens or hundreds of times longer for even the simplest
tasks.

One kludge I've come up with towards a micro-python is the use of 'magic
pseudo-functions' that lock in specific types and behaviour, eg:

- in the mainline, outside of any functions:
- x = int16(45)
- creates a signed 16-bit global int called x, initialises it
to 45
- y = const32(0x3342)
- creates a 32-bit constant called y, initialises it to 0x3342,
any attempt to assign to it raises an exception at compile
time
- z = int8()
- creates an uninitialised global byte var called z
- within a function:
- x = uint16(4)
- creates an unsigned 16-bit int on the return stack frame,
called x, initialised to 4

Another kludge is to legislate that 'None' is a 16-bit int with value of
zero, such that:
- return
- return None
- return 0
all do the same thing

Is anyone working along similar lines?

Is it even possible to devise a tiny python subset that has at least
some of python's advantages, but at the same time can be compiled to
low-footprint resource-lean code?

And could such a mini-python be worth using over C, Forth, etc?

Your thoughts?

--
Cheers
EB

--

One who is not a conservative by age 20 has no brain.
One who is not a liberal by age 40 has no heart.
Aug 30 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a

"Evil Bastard" <sp**@me.please> schrieb im Newsbeitrag
news:43********@news.orcon.net.nz...
Hi,

Has anyone done any serious work on producing a subset of python's
language definition that would suit it to a tiny microcontroller
environment?

remember there was some work done for minimizing py1.5.2 for mics. see
Google. even bare py1.5.2 would be possible with about 1.5MB overhead
statically compiled.
remember an own short trial on a AMD SC400 with Embedded Linux. all in 4 or
8 MB or so.

but Py2.x's became big nasty beasts with also nasty memory behaviour.

guess py1.5.2 is still very nice, tiny and fast for mics. Happy to have a
good basic script lng you won't use new style / meta classes / iterators
.....
Is it even possible to devise a tiny python subset that has at least
some of python's advantages, but at the same time can be compiled to
low-footprint resource-lean code?

And could such a mini-python be worth using over C, Forth, etc?


guess so if your app has non-trivial complexity: Faktor 5 in programming
speed and clarity of code - if you can grant 0.5..2MB overhead.

but guess you still need some 1%..5% C for time critical stuff.
Robert
Aug 30 '05 #2

P: n/a
Check Lua programing language. Maybe this can fit your requirements.
HTH
Petr Jakes

Aug 30 '05 #3

P: n/a
On 2005-08-30, Evil Bastard <sp**@me.please> wrote:
Has anyone done any serious work on producing a subset of python's
language definition that would suit it to a tiny microcontroller
environment?
No, not a tiny microcontroller environment. In the
microcontroller world, "tiny" means 100 bytes of ram and 4KB of
code space. OTOH, if you want to talk about medium-large uC
stuff (hundreds of KB or RAM and code space), somebody did port
and old version of Python to something like that. Google for
"deeply embedded python".
Is it even possible to devise a tiny python subset that has at least
some of python's advantages, but at the same time can be compiled to
low-footprint resource-lean code?


I doubt it.

--
Grant Edwards grante Yow! I appoint you
at ambassador to Fantasy
visi.com Island!!!
Aug 30 '05 #4

P: n/a
>No, not a tiny microcontroller environment. In the
microcontroller world, "tiny" means 100 bytes of ram and 4KB of
code space.


That's medium :)

PIC10F200: 256 12-bit instructions, 16 bytes RAM.
Wouter van Ooijen

-- ------------------------------------
http://www.voti.nl
Webshop for PICs and other electronics
http://www.voti.nl/hvu
Teacher electronics and informatics
Aug 30 '05 #5

P: n/a
On 2005-08-30, Wouter van Ooijen (www.voti.nl) <wo****@voti.nl> wrote:
No, not a tiny microcontroller environment. In the
microcontroller world, "tiny" means 100 bytes of ram and 4KB of
code space.


That's medium :)

PIC10F200: 256 12-bit instructions, 16 bytes RAM.


Touché

--
Grant Edwards grante Yow! I HAVE a towel.
at
visi.com
Aug 30 '05 #6

P: n/a
Evil Bastard wrote:
Hi,

Has anyone done any serious work on producing a subset of python's
language definition that would suit it to a tiny microcontroller
environment?


Isn't pypy meant to support different backends with different
requirements and constraints using the same basic language?
Aug 30 '05 #7

P: n/a
Magnus Lycka <ly***@carmen.se> writes:
Evil Bastard wrote:
Hi,
Has anyone done any serious work on producing a subset of python's
language definition that would suit it to a tiny microcontroller
environment?


Isn't pypy meant to support different backends with different
requirements and constraints using the same basic language?


Yup, not part of the project that I'm involved in, but it's part of
the plan.

Cheers,
mwh

--
59. In English every word can be verbed. Would that it were so in
our programming languages.
-- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html
Aug 30 '05 #8

P: n/a
Evil Bastard <sp**@me.please> writes:
Has anyone done any serious work on producing a subset of python's
language definition that would suit it to a tiny microcontroller
environment?


We just had this thread a few weeks ago and you decided to use FORTH
that time. The answers are the same this time.
Aug 30 '05 #9

P: n/a
Evil Bastard wrote:
Hi,

Has anyone done any serious work on producing a subset of python's
language definition that would suit it to a tiny microcontroller
environment?


Take a look at PyMite :

http://www.python.org/pycon/papers/pymite/

From the abstract :

"PyMite is a flyweight Python interpreter written from scratch to
execute on 8-bit microcontrollers as well as desktop computers..."

Regards,
Alejandro.
Aug 31 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.