Removing the compiler from micropython

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
penjuin
Posts: 3
Joined: Wed Jul 20, 2016 2:55 pm

Removing the compiler from micropython

Post by penjuin » Wed Jul 20, 2016 3:09 pm

Hi,

I was one of the Kickstarter backers, and I've been keeping my eye on this project for some time. I have a question about the micropython backend, but first let me explain the context.

I'm in need of a "scripting" language for debugging and testing embedded devices during the development phase. In this circumstance, the device will only ever need to run the scripting code while it is connected to a Linux PC, as everything else will be in C for performance reasons. I'd like to use micropython as this interface, but it's still a bit too heavy for my needs. Is it possible to remove all compiler/language functionality and literally just stream the bytecodes (as compiled on a PC by micropython) to the device? Or burn the compiled bytecodes straight into a flash segment and run them from there? Or an SPI flash or something? I realise this would take some work, but is there fundamentally anything in the internal structure of micropython that would prevent this?

Has anyone tried something like this before? If so, what sort of savings do you see?

torwag
Posts: 220
Joined: Fri Dec 13, 2013 9:25 am

Re: Removing the compiler from micropython

Post by torwag » Wed Jul 20, 2016 4:35 pm

Hi,

it would be import to know in which areas you are limited. RAM, ROM?
I am not an expert here, but you might want to check about frozen bytecode which was added recently and helps to free RAM.
Cutting micropython a little bit down can be done, afaik, during compilation with a set of flags. Cutting it even more down, becomes tricky...

penjuin
Posts: 3
Joined: Wed Jul 20, 2016 2:55 pm

Re: Removing the compiler from micropython

Post by penjuin » Wed Jul 20, 2016 10:53 pm

Mostly flash is the problem, 80k is a lot for the low cost ARM chips.

shaoziyang
Posts: 363
Joined: Sun Apr 17, 2016 1:55 pm

Re: Removing the compiler from micropython

Post by shaoziyang » Thu Jul 21, 2016 3:52 am

penjuin wrote:Hi,

I was one of the Kickstarter backers, and I've been keeping my eye on this project for some time. I have a question about the micropython backend, but first let me explain the context.

I'm in need of a "scripting" language for debugging and testing embedded devices during the development phase. In this circumstance, the device will only ever need to run the scripting code while it is connected to a Linux PC, as everything else will be in C for performance reasons. I'd like to use micropython as this interface, but it's still a bit too heavy for my needs. Is it possible to remove all compiler/language functionality and literally just stream the bytecodes (as compiled on a PC by micropython) to the device? Or burn the compiled bytecodes straight into a flash segment and run them from there? Or an SPI flash or something? I realise this would take some work, but is there fundamentally anything in the internal structure of micropython that would prevent this?

Has anyone tried something like this before? If so, what sort of savings do you see?

If removing mostly language function, it will lost feature of micropython. Your may try Lua, it is smaller.

penjuin
Posts: 3
Joined: Wed Jul 20, 2016 2:55 pm

Re: Removing the compiler from micropython

Post by penjuin » Thu Jul 21, 2016 4:41 am

I'm not really trying to remove language functions, I just want to do the python->bytecode step on a PC, and then the bytecode->instructions step on the microcontroller separately.

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Removing the compiler from micropython

Post by pfalcon » Thu Jul 21, 2016 12:09 pm

shaoziyang wrote: If removing mostly language function, it will lost feature of micropython. Your may try Lua, it is smaller.
MicroPython is more efficient than Lua. In the same binary size, MicroPython offers more features than Lua. And we're committed to maintain the most minimal configuration, unlike Lua. So no, Lua is not smaller.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Removing the compiler from micropython

Post by pfalcon » Thu Jul 21, 2016 12:13 pm

penjuin wrote:I realise this would take some work, but is there fundamentally anything in the internal structure of micropython that would prevent this?
No. MicroPython is purposedly architectured to make that possible, and that's the direction in which it moves. But yes, actually doing that requires someone who really need that feature (so they make it).
Has anyone tried something like this before? If so, what sort of savings do you see?
Not that I heard of. MicroPython compiler is pretty efficient too, so the talk will be about fitting compiler-less MicroPython in 64K.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Removing the compiler from micropython

Post by pfalcon » Fri Jul 22, 2016 3:17 pm

Actually, I'm pretty rusty on the codebase myself. Such an option exists, and for a while: https://github.com/micropython/micropyt ... 16195a16ad
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

willie
Posts: 14
Joined: Mon Dec 14, 2015 12:05 am

Re: Removing the compiler from micropython

Post by willie » Sun Aug 14, 2016 9:30 pm

Hedgehog Lisp also works like that (compiler is on the PC side) if anyone cares. The target-side executable is just 20k or so including garbage collection, AVL trees as dictionaries, etc. Python is a more familiar language though.

Post Reply