micro-python - is it possible?

Evil Bastard spam at me.please
Tue Aug 30 07:11:55 EDT 2005


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.



More information about the Python-list mailing list