Need a small language or script interpreter to embed in Teensy

Status
Not open for further replies.

BillG

Member
I run an electronics shop at a university. From time to time I need an embeddable interpreter so people in the labs can write a small program to do what they want with one of my hardware projects. For example, I have an XYZ stage controller that is moved with stepper motors. A Teensy controls the hardware and I'd like users to be able to write something like:
for i = 1 to 10 do
move_x(10);
delay(100);
if (i == 10) move_y(10);
end;
So a "tiny C" or "tiny Pascal" interpreter would work. The user would write the program then download it over the serial port to the Teensy where it would be compiled to bytecode or directly interpreted. I found Adam Dunkels' uBasic, https://github.com/adamdunkels/ubasic, which would actually do what I want but I don't like the idea of having to use line numbers.

I also found Pico-C, https://github.com/jpoirier/picoc, but it runs to 3500 lines of C, so it's not so small. Whatever I use, I need the source code so I can modify and extend the language. Does anyone have recommendations?
 
Since I'm using Arduino C/C++ for my projects, I want something written in C. I would add the interpreter code into my Arduino project so it would be available to to use with whatever functionality the main program provides.
 
I am currently working with the PicoC interpreter you mentioned, modifying it to work neatly in Arduino (on esp32 right now). I was intending to try it on Teensy eventually, ideally as a standalone library. While it is quite memory hungry, it is also pretty powerful, with floating point, arrays, good error reporting and easy extensibility. I have been impressed by it's capability. Let me know if you choose this path, I might be able to give you a bit of a head start.
 
@prickle,
I'm going to work with iArduino for now, as it has the features I need without being bloated. I'll keep you in mind if I need PicoC.
 
I am currently working with the PicoC interpreter you mentioned, modifying it to work neatly in Arduino (on esp32 right now). I was intending to try it on Teensy eventually, ideally as a standalone library. While it is quite memory hungry, it is also pretty powerful, with floating point, arrays, good error reporting and easy extensibility. I have been impressed by it's capability. Let me know if you choose this path, I might be able to give you a bit of a head start.

@prickle,
I got iArduino to compile - it uses 49K flash and 6K RAM - how much does PicoC take?

iArduino has some functions I don't need, like an interactive terminal mode, so I'm sure I can whittle it down some from these numbers.
 
@prickle,
I got iArduino to compile - it uses 49K flash and 6K RAM - how much does PicoC take?

iArduino has some functions I don't need, like an interactive terminal mode, so I'm sure I can whittle it down some from these numbers.

Cool. Glad it showed up in that search! Sounds promising. 6K of RAM no trouble, 49K Flash not bad either - except on the T_LC it would easily run on any T_3.x.
 
On ESP32 PicoC uses 47K of flash and 3.5K of ram, but this is just it's static footprint. In my instance I give it 32K of heap for stack (probably overkill) and it uses about 20K of heap to load and execute a moderately small script.
 
Status
Not open for further replies.
Back
Top