Linked by Thom Holwerda on Fri 25th Aug 2006 09:03 UTC, submitted by anonymous
General Development Adam Dunkels, well-known author of the Contiki operating system and the uIP embedded TCP/IP stack, has written a really small BASIC interpreter called uBASIC in about 700 lines of C code. It is intended to be a very small scripting language for systems where memory really is at a premium such as deeply embedded systems which may have as little as a few hundreds of bytes of RAM. It provides an interesting look into how to write a very lightweight script interpreter.
Thread beginning with comment 155841
To read all comments associated with this story, please click here.
Low on memory?
by Invincible Cow on Fri 25th Aug 2006 13:07 UTC
Invincible Cow
Member since:
2006-06-24

If you have memory constraints, why on earth use a scripting language?

Reply Score: 4

RE: Low on memory?
by whartung on Fri 25th Aug 2006 19:04 in reply to "Low on memory?"
whartung Member since:
2005-07-06

An interpreted language can be very memory efficient, since you can reduce high level operations to a single byte.

Simple example:

PRINT "THIS IS A STRING"

the PRINT gets turned into a token, say 0x25, followed by a 0x10 byte (16, string length) then the characters of the string.

LD HL, STRING_LABEL
JSR PRINT

The interpreter has a 1 byte overhead above the actual data space, whereas in assembly you have a 6 byte overhead.

For a single print statement, the rest of the interpreter is overkill. But for large programs, since the interpreter is a static cost, the cost of the interpreter becomes less and less in terms of the overall size cost of the program.

Not to mention any actual productivity benefits.

No, typically the cost of an interpreter has always been performance, not size.

Reply Parent Score: 3