Author Topic: Lightweight Scripting Language for MCUs  (Read 28247 times)

0 Members and 1 Guest are viewing this topic.

Offline helius

  • Super Contributor
  • ***
  • Posts: 3659
  • Country: us
Re: Lightweight Scripting Language for MCUs
« Reply #75 on: August 02, 2023, 08:45:20 pm »
Yes, RPL is very similar to FORTH but also with some interesting differences.
RPL is dynamically typed, and knows the type of every object. Forth is untyped, and doesn't know the type of any object. That is such a large difference that the claimed similarity seems overstated.

RPL also is able to assign (and remember) a label attached to any object, as well as units for number objects. Not many other languages have that capability (I believe one might be Clojure?)

The absence of comments in stored programs is expected, based on the fact that the programs are stored in parsed form (as opposed to ASCII text). This is a problem that also arose in Lisp 1.5 and INTERLISP, and the approach there was to use a (COMMENT ...) form that was defined to do nothing. Since RPL is postfix, there is no simple way to achieve that, although you could simply write "Comment..." DROP to nullify the stack effect of the comment.
 

Offline audiotubes

  • Regular Contributor
  • *
  • Posts: 176
  • Country: cz
Re: Lightweight Scripting Language for MCUs
« Reply #76 on: August 02, 2023, 10:17:24 pm »
They're very similar in that they both use a stack-based paradigm, and that code is written by building up solutions from (ideally small) words that perform a specific function.
I have taken apart more gear than many people. But I have put less gear back together than most people. So there is still room for improvement.
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4220
  • Country: nz
Re: Lightweight Scripting Language for MCUs
« Reply #77 on: August 02, 2023, 10:59:56 pm »
The absence of comments in stored programs is expected, based on the fact that the programs are stored in parsed form (as opposed to ASCII text). This is a problem that also arose in Lisp 1.5 and INTERLISP, and the approach there was to use a (COMMENT ...) form that was defined to do nothing. Since RPL is postfix, there is no simple way to achieve that, although you could simply write "Comment..." DROP to nullify the stack effect of the comment.

But isn't that *precisely* a simple way to do exactly the same thing?

Or do ...

Code: [Select]
« DROP » → COMMENT «
  "get qty" COMMENT
  "Qty:" PROMPT
  "get unit price" COMMENT
  "Price:" PROMPT
  "display total" COMMENT
  → Q P « "Total " Q P * →STR + MSGBOX »
»

... and be happy.
 

Offline helius

  • Super Contributor
  • ***
  • Posts: 3659
  • Country: us
Re: Lightweight Scripting Language for MCUs
« Reply #78 on: August 03, 2023, 01:54:22 am »
It certainly has the same effect. But (unlike program syntax), comments' only purpose is to be read by humans, and the postfix construction is not easy to read. Even Forth uses parenthesized comments, set off before and after by easily identified brackets.

I should clarify that the INTERLISP style of comment is no longer used in Lisp code since around 40 years ago. It was a kludge based on the problem of programs being stored and edited in a parsed form, which was abandoned as the Common Lisp standard displaced older dialects.
 

Offline gnuarm

  • Super Contributor
  • ***
  • Posts: 2247
  • Country: pr
Re: Lightweight Scripting Language for MCUs
« Reply #79 on: August 03, 2023, 03:50:37 am »
It certainly has the same effect. But (unlike program syntax), comments' only purpose is to be read by humans, and the postfix construction is not easy to read. Even Forth uses parenthesized comments, set off before and after by easily identified brackets.

In Forth, it's much more common to denote comments by a backslash, with the comment ending at EOL

\ On test failure, set output frequency
: Test20kHz ( -- )  20000 GetAmpMeas . ;
CR .( Done loading Test20kHz)

The last line was part of the debugging code I added to isolate a problem.

It's not postfix that is hard to read, it is poorly written programs in any form that are hard to read.   One thing that is important in Forth, which is not so important in other languages, is to write code that is clear and simple.  Other languages allow, or even promote poor program design.
Rick C.  --  Puerto Rico is not a country... It's part of the USA
  - Get 1,000 miles of free Supercharging
  - Tesla referral code - https://ts.la/richard11209
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4220
  • Country: nz
Re: Lightweight Scripting Language for MCUs
« Reply #80 on: August 03, 2023, 06:26:30 am »
comments' only purpose is to be read by humans, and the postfix construction is not easy to read.

I would never dream of saying such a thing!! I've used postfix languages a lot (mostly PostScript). But ok ....

 

Offline Smokey

  • Super Contributor
  • ***
  • Posts: 2696
  • Country: us
  • Not An Expert
Re: Lightweight Scripting Language for MCUs
« Reply #81 on: May 16, 2024, 09:10:15 pm »
What is the state of things with embedded systems scripting in 2024?

My requirements are actually pretty minimal.  I have a fully functional ESP32 system (ESP-IDF, so FreeRTOS and all that) to which I want to embed a user scripting engine so the user can make their own simple LED animations.  It needs to be setup so they don't need to externally compile and flash anything (which they don't actually have access to do anyway).  Anyone know of something that would solve that problem?
« Last Edit: May 16, 2024, 09:13:13 pm by Smokey »
 

Offline tggzzz

  • Super Contributor
  • ***
  • Posts: 20027
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: Lightweight Scripting Language for MCUs
« Reply #82 on: May 16, 2024, 09:17:12 pm »
What is the state of things with embedded systems scripting in 2024?

My requirements are actually pretty minimal.  I have a fully functional ESP32 system (ESP-IDF, so FreeRTOS and all that) to which I want to embed a user scripting engine so the user can make their own simple LED animations.  It needs to be setup so they don't need to externally compile and flash anything (which they don't actually have access to do anyway).  Anyone know of something that would solve that problem?

Forth.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 27366
  • Country: nl
    • NCT Developments
Re: Lightweight Scripting Language for MCUs
« Reply #83 on: May 16, 2024, 09:24:41 pm »
What is the state of things with embedded systems scripting in 2024?

My requirements are actually pretty minimal.  I have a fully functional ESP32 system (ESP-IDF, so FreeRTOS and all that) to which I want to embed a user scripting engine so the user can make their own simple LED animations.  It needs to be setup so they don't need to externally compile and flash anything (which they don't actually have access to do anyway).  Anyone know of something that would solve that problem?
I've used Micropython for a similar situation. Embedded Lua (emblua, not eLua!) could be more suitable though as this is easier to integrate but in my case the customer insisted on using Python. Micropython needed a bit of hacking to integrate it into a C based ESP32 project and use the flash filesystem to read/store a script. The ESP32 IDF environment offers a Posix file I/O layer so Micropython has to be told it runs on a Unix system but still use a defined heap space.
« Last Edit: May 16, 2024, 09:37:19 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14897
  • Country: fr
Re: Lightweight Scripting Language for MCUs
« Reply #84 on: May 16, 2024, 09:58:57 pm »
Forth and Lua. Could also be a minimal, ad hoc scripting "language" if neither of the existing solutions are small enough to fit in said MCU.
The "MCU" is a hard requirement here.
What you can fit in a ESP32, or otherwise some other similar MCU with (relatively) a lot of Flash memory and RAM, is one thing, what would fit in a MCU with a lot less memory available is another entirely.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 27366
  • Country: nl
    • NCT Developments
Re: Lightweight Scripting Language for MCUs
« Reply #85 on: May 16, 2024, 10:20:00 pm »
Forth and Lua. Could also be a minimal, ad hoc scripting "language" if neither of the existing solutions are small enough to fit in said MCU.
The "MCU" is a hard requirement here.
What you can fit in a ESP32, or otherwise some other similar MCU with (relatively) a lot of Flash memory and RAM, is one thing, what would fit in a MCU with a lot less memory available is another entirely.
For embLua you mostly need flash. Like 128kB to be on the safe side. A simple Lua script needs a few kB of RAM at most. IIRC I have done tests using an LPC1225 which has 8kB of RAM. For Micropython 32kB of RAM is a good start.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Smokey

  • Super Contributor
  • ***
  • Posts: 2696
  • Country: us
  • Not An Expert
Re: Lightweight Scripting Language for MCUs
« Reply #86 on: May 16, 2024, 11:02:04 pm »
https://github.com/szieke/embLua

Quote
embLua requirements
To run scripts which do something 'meaningful' embLua needs:

RAM: 1k Stack, 11k Heap
ROM (not optimized code): 120 on MSP430, 90k on Renesas
C-Library
 

Offline Picuino

  • Super Contributor
  • ***
  • Posts: 1020
  • Country: es
    • Picuino web
Re: Lightweight Scripting Language for MCUs
« Reply #87 on: May 17, 2024, 08:01:41 am »
EDIT:
Has anything been said about TCL yet?
Does anyone know it as a scripting language for microcontrollers?

https://wiki.tcl-lang.org/page/Small+Tcl
https://tinytcl.sourceforge.net/
« Last Edit: May 17, 2024, 08:06:27 am by Picuino »
 

Offline tellurium

  • Frequent Contributor
  • **
  • Posts: 267
  • Country: ua
Re: Lightweight Scripting Language for MCUs
« Reply #88 on: May 17, 2024, 08:29:30 am »
If the anticipated code is trivial, one can consider very, very stripped down Javascript:

https://github.com/cesanta/elk/

And yeah, TCL!
Another tiny implementation is here:
https://github.com/zserge/partcl (code)
https://zserge.com/posts/tcl-interpreter/ (article)
« Last Edit: May 17, 2024, 08:32:10 am by tellurium »
Open source embedded network library https://github.com/cesanta/mongoose
TCP/IP stack + TLS1.3 + HTTP/WebSocket/MQTT in a single file
 

Offline coppice

  • Super Contributor
  • ***
  • Posts: 8942
  • Country: gb
Re: Lightweight Scripting Language for MCUs
« Reply #89 on: May 20, 2024, 06:12:22 pm »
EDIT:
Has anything been said about TCL yet?
Does anyone know it as a scripting language for microcontrollers?

https://wiki.tcl-lang.org/page/Small+Tcl
https://tinytcl.sourceforge.net/
I would avoid TCL, not because of anything inherently wrong with it, but because it has slumped from a prominent mainstream position to obscurity. Everything I know that is written in TCL is something old that is being maintained, but almost certainly wouldn't be started afresh in TCL. Its frequently hard to get people to put the effort into even simple maintenance of TCL code, which is often really sad. When a language gets in that state you aren't going to get much buy in from others. You are on your own.
 

Offline Smokey

  • Super Contributor
  • ***
  • Posts: 2696
  • Country: us
  • Not An Expert
Re: Lightweight Scripting Language for MCUs
« Reply #90 on: May 20, 2024, 06:51:51 pm »
It seems like embLua is a clear winner at this point (memory footprint, functionality, language complexity, etc), at least for embedding scripting into an already existing codebase like I need.  Am I wrong?
 

Offline coppice

  • Super Contributor
  • ***
  • Posts: 8942
  • Country: gb
Re: Lightweight Scripting Language for MCUs
« Reply #91 on: May 20, 2024, 06:55:27 pm »
It seems like embLua is a clear winner at this point (memory footprint, functionality, language complexity, etc), at least for embedding scripting into an already existing codebase like I need.  Am I wrong?
A lot of people who use it stick with it, so it seems to be a solution that results in reasonable levels of contentment.
 

Offline ksjh

  • Contributor
  • Posts: 27
  • Country: de
Re: Lightweight Scripting Language for MCUs
« Reply #92 on: May 20, 2024, 07:26:49 pm »
A while ago, I was looking for compact ESP32-C3 boards on AliExpress and found some marked "LuatOS-Core", so I tried to find out more about those boards and stumbled upon https://wiki.luatos.org/ when trying to find the pinout of those boards. I did not try LuatOS at all or look at it in more detail, but I thought it could be useful for your project. There seem to be implementations for the ESP32-C3 and the ESP32-S3, source is available on gitee, I did not check the licensing.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 27366
  • Country: nl
    • NCT Developments
Re: Lightweight Scripting Language for MCUs
« Reply #93 on: May 20, 2024, 07:41:45 pm »
A while ago, I was looking for compact ESP32-C3 boards on AliExpress and found some marked "LuatOS-Core", so I tried to find out more about those boards and stumbled upon https://wiki.luatos.org/ when trying to find the pinout of those boards. I did not try LuatOS at all or look at it in more detail, but I thought it could be useful for your project. There seem to be implementations for the ESP32-C3 and the ESP32-S3, source is available on gitee, I did not check the licensing.
The problem with Luatos is that it tries to provide a one-size-fits-all solution (like many other similar projects). These typically don't work. A better approach is to write the low level stuff in C and then use scripting for a implementing high-level logic only. This allows to implement a safety barrier between low level control stuff and the high level functionality.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 
The following users thanked this post: ksjh

Offline gnuarm

  • Super Contributor
  • ***
  • Posts: 2247
  • Country: pr
Re: Lightweight Scripting Language for MCUs
« Reply #94 on: May 20, 2024, 08:44:52 pm »
It seems like embLua is a clear winner at this point (memory footprint, functionality, language complexity, etc), at least for embedding scripting into an already existing codebase like I need.  Am I wrong?

Isn't the memory footprint of embLua rather large?  I've seen forth implementations that fit in a very few kB of flash (like ~4 kB) and around 256 B of RAM.  One advantage is that properly implemented, forth applications use very little program storage.   

Did I misunderstand the memory footprint of embLua?
Rick C.  --  Puerto Rico is not a country... It's part of the USA
  - Get 1,000 miles of free Supercharging
  - Tesla referral code - https://ts.la/richard11209
 

Offline Smokey

  • Super Contributor
  • ***
  • Posts: 2696
  • Country: us
  • Not An Expert
Re: Lightweight Scripting Language for MCUs
« Reply #95 on: May 20, 2024, 09:41:50 pm »
It seems like embLua is a clear winner at this point (memory footprint, functionality, language complexity, etc), at least for embedding scripting into an already existing codebase like I need.  Am I wrong?

Isn't the memory footprint of embLua rather large?  I've seen forth implementations that fit in a very few kB of flash (like ~4 kB) and around 256 B of RAM.  One advantage is that properly implemented, forth applications use very little program storage.   

Did I misunderstand the memory footprint of embLua?

12K RAM, 120K ROM is fine for an ESP32 I think.  If this was a smaller micro, I would probably need to reconsider.
Also the thing I definitely Don't Want is a scripting firmware that acts like an OS.  I already have my program which needs FreeRTOS because of the Wifi on the ESP32, so I don't want anything conflicting with that.
 

Offline gnuarm

  • Super Contributor
  • ***
  • Posts: 2247
  • Country: pr
Re: Lightweight Scripting Language for MCUs
« Reply #96 on: May 21, 2024, 12:00:39 am »
It seems like embLua is a clear winner at this point (memory footprint, functionality, language complexity, etc), at least for embedding scripting into an already existing codebase like I need.  Am I wrong?

Isn't the memory footprint of embLua rather large?  I've seen forth implementations that fit in a very few kB of flash (like ~4 kB) and around 256 B of RAM.  One advantage is that properly implemented, forth applications use very little program storage.   

Did I misunderstand the memory footprint of embLua?

12K RAM, 120K ROM is fine for an ESP32 I think.  If this was a smaller micro, I would probably need to reconsider.
Also the thing I definitely Don't Want is a scripting firmware that acts like an OS.  I already have my program which needs FreeRTOS because of the Wifi on the ESP32, so I don't want anything conflicting with that.

120 kB of flash is not what I call a small footprint.  I don't know what you mean by "acts like an OS".  Forth only does what you tell it to do.  It is very much like a scripting language, with either compiling code, or executing from a command line.  While there are forths which run on bare metal, these are less common on larger CPUs, and typically are programs under an OS.  However, forth can be the only code on a small MCU, which is why it can fit in only 4 kB of flash (what you call ROM).  There aren't many MCUs with ROM these days.
Rick C.  --  Puerto Rico is not a country... It's part of the USA
  - Get 1,000 miles of free Supercharging
  - Tesla referral code - https://ts.la/richard11209
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4240
  • Country: us
Re: Lightweight Scripting Language for MCUs
« Reply #97 on: May 21, 2024, 02:55:51 am »
I think the winner is probably some flavor of BASIC, but no one wants to admit it.  :-)

It doesn't help that there is so little cross-platform standardization of low-level primitives for BASICs.
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4220
  • Country: nz
Re: Lightweight Scripting Language for MCUs
« Reply #98 on: May 21, 2024, 07:39:24 am »
I think the winner is probably some flavor of BASIC, but no one wants to admit it.  :-)

I really don't think so :-)

The only advantage simple BASIC has is the line numbers facilitate easy program editing when you don't have a real full-screen text editor. But the line numbers quickly become an impediment to program growth. And only global variables and IF/GOTO .. just ugh.

If you add control structures and functions with arguments and local variables and structs or dictionaries then you lose the few advantages BASIC started with and might as well use Lua or a TinyC or Python or Scheme etc.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 27366
  • Country: nl
    • NCT Developments
Re: Lightweight Scripting Language for MCUs
« Reply #99 on: May 21, 2024, 08:52:57 am »
It seems like embLua is a clear winner at this point (memory footprint, functionality, language complexity, etc), at least for embedding scripting into an already existing codebase like I need.  Am I wrong?

Isn't the memory footprint of embLua rather large?  I've seen forth implementations that fit in a very few kB of flash (like ~4 kB) and around 256 B of RAM.  One advantage is that properly implemented, forth applications use very little program storage.   

Did I misunderstand the memory footprint of embLua?

12K RAM, 120K ROM is fine for an ESP32 I think.  If this was a smaller micro, I would probably need to reconsider.
Also the thing I definitely Don't Want is a scripting firmware that acts like an OS.  I already have my program which needs FreeRTOS because of the Wifi on the ESP32, so I don't want anything conflicting with that.

120 kB of flash is not what I call a small footprint.  I don't know what you mean by "acts like an OS".  Forth only does what you tell it to do.  It is very much like a scripting language, with either compiling code, or executing from a command line.  While there are forths which run on bare metal, these are less common on larger CPUs, and typically are programs under an OS.  However, forth can be the only code on a small MCU, which is why it can fit in only 4 kB of flash (what you call ROM).  There aren't many MCUs with ROM these days.
That is not a very fair comparison. The 90k to 120k for Lua includes: compiler to create bytecode, math, string, table support, bit-operations and various other features like key-value pairs. For math support, the floating point library is also linked in (which is included in the size). All in all you get a fairly complete package from embLua. Micropython is even better featured with things like filesystem support and modules to deal with JSON (for example).

'Act like an OS' means that the script language is the only way to get something done which is typically not what you want because it would require the script language libraries to also abstract ALL the peripherals on a microcontroller. The latter is where these attempts / projects typically go wrong as the number of platforms they support is just 2 or 3 out of thousands of different microcontrollers out there.
« Last Edit: May 21, 2024, 10:04:32 am by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf