3 ms·
A surprisingly rich feature set for a 40-KB runtime: a VM with GC that runs a Python/Ruby lookalike language, supporting procedural, OO, or functional styles. F
by nine_k 3y ago
A surprisingly rich feature set for a 40-KB runtime: a VM with GC that runs a Python/Ruby lookalike language, supporting procedural, OO, or functional styles. From the cursory look, seems pretty ergonomic to write.
What stood out for me is the ability to pre-create constant objects and put them mostly into ROM, so that the RAM is only used for the actually mutable data. This is something you can't have with MicroPython or Lua, AFAICT, and this makes a lot of difference in MCUs where ROM / flash is plentiful, and RAM is scarce.
- snops 3y agoYou can "freeze" micropython modules and have them saved in flash with Micropython, where flash only stores the precompiled bytecode. If your module contains stored data in the form of an immutable object, like a string or bytes(), it will be read straight out of flash without copying to RAM first. This needs you to run some code on a desktop computer to perform the freezing though. https://docs.micropython.org/en/latest/reference/constrained.html https://docs.micropython.org/en/latest/reference/constrained...
- mikepurvis 3y agoAny serious build setup for an MCU firmware is going to have steps like this in, generating code and saving blobs of this and that. Though I guess part of the pitch for micropython is being able to iterate without a flash step every time. Possibly addressed by having your dev boards fitted with a version of the MCU with enough RAM to run it all that way.
- matt_trentini 3y agoJust to be clear, not just data but bytecode will also be executed from flash too.
- tomcam 3y agoI have to admit, I went back to the site after reading your description. I find it much more comprehensive and appealing than the home page.
- paulclinger 3y agoIt does indeed look interesting and looks to be similar to Lua in several aspects (although, there are some noticeable differences too). FWIW, there has been work done in eLua to keep some of the data (transparently) in ROM: https://eluaproject.net/doc/v0.9/en_arch_ltr.html https://eluaproject.net/doc/v0.9/en_arch_ltr.html (see rotables).
- matt_trentini 3y agoAs @snops explained, MicroPython supports executing code from flash in the form of frozen code. The consequence of this is that it needs to be compiled in to the firmware binary which slows down the typical rapid development cycle of MicroPython. So a convenient workflow is to deploy at runtime (ie not in flash) until you stabilise your code base or approach production; at which point you can freeze your code into your firmware. For an even more convenient model, there is the proposal to support 'mapfs' so that some flash will be allocated to store code. You can then compile your Python to bytecode (with `mpy_cross`) and upload it to - and run from - this area at runtime. Although this feature has been demonstrated as a proof-of-concept, there are some subtleties to sort out before it hits mainline. If you're interested in the feature, please read or comment on the PR: https://github.com/micropython/micropython/pull/8381 https://github.com/micropython/micropython/pull/8381