What are the available interactive languages that run in tiny memory?

Programming LanguagesEmbeddedMicrocontrollerInteractive

Programming Languages Problem Overview


I am looking for general purpose programming languages that

  • have an interactive (live coding) prompt
  • work in 32 KB of RAM by itself or 8 KB when the compiler is hosted on a separate machine
  • run on a microcontroller with as little as 8-32 KB RAM total (without an MMU).

Below is my list so far, what am I missing?

  • Python: The PyMite VM needs 64K flash, 8K RAM. Targets LPC, SAM7 and ATmegas with 8K or more. Hosted.
  • Lua: The eLua FAQ recommends 256K flash, 64K RAM.
  • FORTH: amforth needs 8K flash, 150 bytes RAM, 30 bytes EEPROM on an ATmega.
  • Scheme: armpit Scheme The smallest target is the LPC2103 with 32K Flash, 4K SRAM.
  • C: Interactive C runs on 68HC11 with no flash and 32K SRAM. Hosted.
  • C: picoc an open source, cross-compiling, interactive C system. When compiled for AVR, it takes 63K flash, 8K RAM. The RAM could be reduced with effort to keep tables in flash.
  • C++: AngelScript an open source, byte-code based, C/C++ like scripting language with easy native calls.
  • Tcl: TinyTCL runs on DOS, 60K binary. Looks easy to port.
  • BASIC: TinyBasic: Initializes with a 64K heap, might be adjustable.
  • Lisp
  • PostScript: (I haven't found a FOSS implementation for low memory yet)
  • Shell: bitlash: An interactive command shell for Arduino (ATmega). See also AVRSH.

Programming Languages Solutions


Solution 1 - Programming Languages

A homebrew Forth runtime can be implemented in very little memory indeed. I know someone who made one on a Cosmac in the 1970s. The core runtime was just 30 bytes.

Solution 2 - Programming Languages

I hear that CHIP-8, XPL0, PicoC, and Objective Caml have been ported to graphing calculators. The Wikipedia "Lego Mindstorms" article lists a bunch of programming languages that allegedly run on the Lego RCX or Lego NXT platform. Do any of them meet your "live coding" criteria?

You might want to check out the other microcontroller Forths at the Forth wiki . It lists at least 4 Forths for the Atmel AVR: amforth (which you already mention), PFAVR, avrforth, and ByteForth.
(Links to those interpreters, as well as this StackOverflow question, are included in the "Embedded Systems" wikibook).

Solution 3 - Programming Languages

I would recommend LUA (or eLUA http://www.eluaproject.net/ ). I've "ported" LUA to a Cortex-M3 a while back. From the top of my head it had a flash size of 60~100KB and needed about 20KB RAM to run. I did strip down to the bare essentials, but depending on your application, that might be enough. There's still room for optimization, especially about RAM requirements, but I doubt you can run it comfortable in 8KB.

Solution 4 - Programming Languages

Solution 5 - Programming Languages

Wren fits your criteria -- by default it's configured to use just 4k of RAM. AFAIK it hasn't seen any actual use, since the guy I wrote it for decided he didn't need an interpreter running wholly on the target system after all.

The language is influenced most obviously by ML and Forth.

Solution 6 - Programming Languages

Have you considered a port in C of Tiny Basic? Or, perhaps rewriting the UCSD Pascal p-machine to your architecture from Z-80?

Seriously, though, JavaScript would make a good embedded scripting language, but I've no clue what the minimum memory requirements are for the VM + GC, nor how difficult to remove OS dependencies. I played with NJS a while back, which could possibly fit your needs. This one is interesting in that the compiler is written in JavaScript (self hosting).

Solution 7 - Programming Languages

You can take a look at very powerful AvrCo Multitasking Pascal for AVR. You can try it at http://www.e-lab.de. MEGA8/88 version is free. There are tons of drivers and simulator with JTAG debugger and nice live or simulated visualizations of all standard devices (LCDCHAR, LCDGRAPH, 7SEG, 14SEG, LEDDOT, KEYBOARD, RC5, SERVO, STEPPER...).

Solution 8 - Programming Languages

You're missing EmbedVM, homepage here, svn repo here. Remember to check out both [1,2] videos on the front page ;)

From the homepage:

> EmbedVM is a small embeddable virtual machine for microcontrollers > with a C-like language frontend. It has been tested with GCC and AVR > microcontrollers. But as the Virtual machine is rather simple it > should be easy to port it to other architectures. > > The VM simulates a 16bit CPU that can access up to 64kB of memory. It > can only operate on 16bit values and arrays of 16bit and 8bit values. > There is no support for complex data structures (struct, objects, > etc.). A function can have a maximum of 32 local variables and 32 > arguments. > > Besides the memory for the VM, a small structure holding the VM state > and the reasonable amount of memory the EmbedVM functions need on the > stack there are no additional memory requirements for the VM. > Especially the VM does not depend on any dymaic memory management. > > EmbedVM is optimized for size and simplicity, not execution speed. The > VM itself takes up about 3kB of program memory on an AVR > microcontroller. On an AVR ATmega168 running at 16MHz the VM can > execute about 75 VM instructions per millisecond. > > All memory accesses done by the VM are parformed using user callback > functions. So it is possible to have some or all of the VM memory on > external memory devices, flash memory, etc. or "memory-map" hardware > functions to the VM. > > The compiler is a UNIX/Linux commandline tool that reads in a *.evm > file and generates bytecode in vaious formats (binary file, intel hex, > C array initializers and a special debug output format). It also > generates a symbol file that can be used to access data in the VM > memory from the host application.

The C-like language looks like this: http://svn.clifford.at/embedvm/trunk/examples/numberquizz/vmcode.evm

Solution 9 - Programming Languages

I would recommend MY-BASIC, runs with in minimum 8 KB RAM, and easy to port.

Solution 10 - Programming Languages

There's also JavaScript, via Espruino.

This is built specifically for Microcontrollers and there are builds for various different chips (mainly STM32s) that fit a full system into as little as 8kB RAM.

Solution 11 - Programming Languages

Have you considered simply using the /bin/sh supplied by busybox? Or on of the smaller scripting languages they recommend?

Solution 12 - Programming Languages

Prolog - http://www.gprolog.org/

According to a google search "prolog small" the size of the executable can be made quite small by avoiding linking the built-in predicates.

Solution 13 - Programming Languages

None of the languages in the list in the question or in the answers proved satisfactory for the requirement of super easy compilation and integration into an existing micro controller project (disclosure: I didn't actually try every single one of the suggestions).

I found instead tinyscript which is a single .c+.h file that compiled with the rest of the source files on my project with the only additional configuration required being to provide a void outchar(int c) which can be empty if you don't require output from the scripts.

For me speed of execution is far less important than ease of build and integration and interop with C, as my use case is mainly just calling some C functions in order.

Solution 14 - Programming Languages

I have been using in my previous work busybox on a BlackFin.

we compiled perl + php for it, after changing s/fork/vfork/g it worked pretty good... more or less. Not having an MMU is not a good idea. The memory fragmentation will kill the server pretty easily. All I did was:

for i in `seq 1 100`; do wget http://black-fin-ip/test.php; done

It died while I was walking to my boss and telling him that the server is going to die in production :)

Solution 15 - Programming Languages

I would suggest use python. But now the only problem is the memory overhead right? So I have great idea for people who may be stuck in this problem later on.

First thing's first, write a bf interpreter(or just get source code from somewhere). The interpreter will be really small. Also bf is a Turing complete language. Now you need to write your code in python and then transpiler it to bf using bfpy( https://github.com/felko/bfpy/blob/master/README.md ). I've given you the solution with the least overhead and I am pretty sure a bf interpreter will easily stay under 10KB of ram usage.

Solution 16 - Programming Languages

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondwhallView Question on Stackoverflow
Solution 1 - Programming LanguagesConcernedOfTunbridgeWellsView Answer on Stackoverflow
Solution 2 - Programming LanguagesDavid CaryView Answer on Stackoverflow
Solution 3 - Programming LanguagesRonView Answer on Stackoverflow
Solution 4 - Programming LanguagesavraView Answer on Stackoverflow
Solution 5 - Programming LanguagesDarius BaconView Answer on Stackoverflow
Solution 6 - Programming LanguagesJames HugardView Answer on Stackoverflow
Solution 7 - Programming LanguagesavraView Answer on Stackoverflow
Solution 8 - Programming LanguagesMorten JensenView Answer on Stackoverflow
Solution 9 - Programming LanguagespipipiView Answer on Stackoverflow
Solution 10 - Programming LanguagesGordon WilliamsView Answer on Stackoverflow
Solution 11 - Programming Languagesdmckee --- ex-moderator kittenView Answer on Stackoverflow
Solution 12 - Programming LanguagesLarry WatanabeView Answer on Stackoverflow
Solution 13 - Programming LanguagesDaniel LandauView Answer on Stackoverflow
Solution 14 - Programming LanguageselcucoView Answer on Stackoverflow
Solution 15 - Programming LanguagesThomasView Answer on Stackoverflow
Solution 16 - Programming LanguagesLarry WatanabeView Answer on Stackoverflow