What are the available interactive languages that run in tiny memory? [closed]
Asked Answered
P

16

76

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.
Plenteous answered 4/7, 2009 at 18:30 Comment(7)
The forth system you mention appears to require only 8k of flash, but you list it as 128k. Am i missing something?Swage
1) The Flash/RAM numbers for the FORTH impl. is for the named processor. 2) I'm not aware of a community wiki in stackoverflow. I'll look into it.Plenteous
There are a number of versions of Tcl for embedded programming: wiki.tcl.tk/1363Agathy
An interesting question. Speaking as an embedded programmer, I'm curious as to why you want an interactive prompt to run on the embedded system. Apart from the "neato" factor, that is. As long as my embedded system is connected to a PC, I would try to do as much processing as possible in the PC, and have minimal code in the embedded device. It's easier to implement a particular functionality in code on a PC than in an embedded system, in general.Udo
I used Interactive C during a robotics elective in college. I learned more about C through the interactive prompt in 6 weeks than I did during the entire semester of a C laboratory. I've been programming Python since 1996 and I its interactive prompt let me learn the language (to the point of doing what I needed to do) in 2 days. So I believe interactive languages are great for learning and also rapid prototyping. Lastly, I'm the lead developer of PyMite, so I am looking for examples of peer languages and learning all I can from them.Plenteous
The languages marked "Hosted" are ones where the compiler stays on the PC and bytecode (or some other form of [semi]executable) is sent to the target device.Plenteous
PostScript is a fairly heavyweight system, although the non-graphical forth-like bits could be implemented in a much smaller footprint. Even the older version 23 and version 38 (Mid'80s PS level 1) builds were 512K with 13 fonts and 1MB with 35 fonts.Sieve
S
10

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.

Sieve answered 4/7, 2009 at 18:30 Comment(1)
FORTH was already listed. This is a comment, not an answer.Plenteous
H
8

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

Houchens answered 4/7, 2009 at 18:30 Comment(0)
R
6

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.

Radiochemical answered 4/7, 2009 at 18:30 Comment(0)
S
5

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.

Stalinabad answered 4/7, 2009 at 18:30 Comment(1)
Thanks, but the eLua project was already on my list (see the second bullet in the question).Plenteous
R
3

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

Reitz answered 4/7, 2009 at 18:30 Comment(0)
G
2

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

Growl answered 4/7, 2009 at 18:30 Comment(0)
A
1

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.

Altdorfer answered 4/7, 2009 at 18:30 Comment(0)
I
1

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.

Imprecation answered 4/7, 2009 at 18:30 Comment(0)
L
1

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

Lifeguard answered 4/7, 2009 at 18:30 Comment(0)
L
1

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

Letterpress answered 4/7, 2009 at 18:30 Comment(0)
S
0

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.

Selaginella answered 4/7, 2009 at 18:30 Comment(0)
F
0

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

Frobisher answered 4/7, 2009 at 19:31 Comment(3)
I'm looking for languages that run on microcontrollers with no MMU and have such small RAM (8K-32K) that an OS is unreasonable. I will edit the question to make this more clear.Plenteous
ucLinux doesn't have an MMU and runs on microcontrollers. It uses busybox.Reputation
@DoxaLogos: Thanks for coming to my defense and all, but I don't think that ucLinix will run in this small a memory footprint. (I didn't read at first. Leaving the answer because it might be useful to someone else coming by.) ANyone know how small an OS you can write that will support BB?Frobisher
S
-1

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.

Sharasharai answered 4/7, 2009 at 18:30 Comment(0)
P
-2

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 :)

Piffle answered 4/7, 2009 at 18:30 Comment(1)
This answer is not accepted because Perl and PHP don't run in less than 32 KB of RAM. Having no MMU is a requirement. I'm working on deeply embedded systems; 32 KB is the total amount of RAM in the system.Plenteous
S
-3

Erlang - http://erlang.org/

it can fit in 2MB

http://www.experts123.com/q/is-erlang-small-enough-for-embedded-systems.html

Selaginella answered 4/7, 2009 at 18:30 Comment(1)
2mb is over 30x the entire memory size he has available!Finding

© 2022 - 2024 — McMap. All rights reserved.