What are the available interactive languages that

2019-01-09 22:59发布

问题:

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.

回答1:

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.



回答2:

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



回答3:

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.



回答4:

Some AVR interpreters/VMs:

  1. http://www.cqham.ru/tbcgroup/index_eng.htm
  2. http://www.jcwolfram.de/projekte/avr/chipbasic2/main.php
  3. http://www.jcwolfram.de/projekte/avr/chipbasic8/main.php
  4. http://www.jcwolfram.de/projekte/avr/main.php
  5. http://code.google.com/p/python-on-a-chip/
  6. http://www.avrfreaks.net/index.php?module=Freaks%20Academy&func=viewItem&item_id=688&item_type=project
  7. http://www.avrfreaks.net/index.php?module=Freaks%20Academy&func=viewItem&item_id=626&item_type=project
  8. http://www.avrfreaks.net/index.php?module=Freaks%20Academy&func=viewItem&item_id=460&item_type=project
  9. http://www.harbaum.org/till/nanovm/index.shtml


回答5:

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.



回答6:

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



回答7:

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



回答8:

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



回答9:

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



回答10:

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.



回答11:

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



回答12:

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



回答13:

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.



回答14:

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.



回答15:

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.



回答16:

Erlang - http://erlang.org/

it can fit in 2MB

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