micro-python - is it possible?

E

Evil Bastard

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?
 
R

Robert

Evil Bastard said:
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
 
M

McBooCzech

Check Lua programing language. Maybe this can fit your requirements.
HTH
Petr Jakes
 
G

Grant Edwards

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.
 
W

Wouter van Ooijen

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
 
M

Magnus Lycka

Evil said:
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?
 
M

Michael Hudson

Magnus Lycka said:
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
 
P

Paul Rubin

Evil Bastard said:
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.
 
A

Alejandro Weinstein

Evil said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,318
Members
47,998
Latest member
GretaCjy4

Latest Threads

Top