QuoteThe whole line is autogenerated, it's a Bitfield Word *template* and takes the names from CMSIS-SVD. The actual Word 'name' is changed when pasted into a Forth program.
Could you explain more about how that works? I would have thought that in order to retain the "interpreter" nature of Forth, you'd have to have all the words in the dictionary. There are Forth "compilers" (that I'm not at all familiar with) that could do the same sort of templating or symbol translation that C++/C can do, but... that wouldn't be a Forth interpreter any more, would it?
QuoteI'm not pushing Forth here
Sure you are. But that's fine; it makes us think...
I wish more of the "new" languages were as clearly DIFFERENT as Forth is willing to be, rather than just "well, this is like Java/C++/C/Pascal/Algol except we added a few concepts we really like, and this time the VM we're proposing will really be secure!"
QuoteI'm waiting for someone to create a 'Tethered Python', I think that may give C and Arduino a run for it's money
"Tethered"? Adafruit is really pushing their "CircuitPython" (a derivative of MicroPython), and building boards that are capable of running it effectively (?) (at prices comparable with Arduino boards.) Generally this means adding several megabytes of serial flash to hold the source-level libraries that a Python sketch is likely to need. (and using at least a 48MHz ARM CM0 chip. None of this 8-bit nonsense.)
Python might qualify as "significantly different" from C/etc, but it's hard to tell how much is the language, and how much is the libraries. Though perhaps the ability to write really effective libraries OUGHT to be a major reason to like a language. I've felt that C falls apart for its inability to put data in libraries (ie "objects") effectively, and C++ seems to add feature after feature designed to allow the small subset of programmers who write really complex libraries to do so without stepping outside the bounds of the language (oh, the horror, if you should have to write part of a library in assembly language!")
I wrote a Python program that scrapes my favorite web-comic to my local disk. So it has a constant "start page", downloads the the appropriate image and associated text, finds the "next" link, and iterates till done, plus waiting a "friendly" time (2-50 seconds) between each page, so as not to cause excessive traffic. It's 54 lines of code, including the "imports" of "well known libraries", comments, and a dozen lines of "test code that is no longer used" (but is useful for reminding me how I got the final product.)
I am ... impressed, and also horrified!
I'd love to try and explain this further, apologies in advance for the usual ambiguities, bad spelling and comprehension. Warning: LONG!
The Forth I use. Mecrisp-stellaris
http://mecrisp.sourceforge.net/ comes as a binary ready to flash to the target MCU. By default it has a extensive Dictionary of Words as can be seen here:
https://mecrisp-stellaris-folkdoc.sourceforge.io/words.html#id1My CMSIS-SVD autogenerated peripheral memory map Words and my register bitfields are totally separate to Mecrisp-Stellaris and based on initial work by Ralph Doering
a few years ago.
My "svd2forth" stuff uses a XLST processor to generate the format I chose by processing any XML micro.svd file.
It's explained here:
https://mecrisp-stellaris-folkdoc.sourceforge.io/register-generator.html#cmsis-svdI develop as shown in this pic:
https://mecrisp-stellaris-folkdoc.sourceforge.io/modern-forth-development-environment.html#a-modern-forth-ideBasically I apply power to the hardware and see the Forth boot up greeting in the terminal window and I know I'm ready to start.
So lets assume I'm interested in GPIOC-8, I can ether:
1) search the preopened bitfields template file ... too slow
2) scroll thru my preopened bitfields template file ... too hard
3) In Gvim :
a) In insert mode, type first part of syntax and place cursor at the end of the search phrase i.e.
: GPIOC_MODER_<-- cursor here
b) Enter <ctrl x> <ctrl l> and up pops a list of similar words from bitfields.fs which contains every bitfield for the mcu listed.
c) select desired line and hit enter and the following is inserted in my source
: GPIOC_MODER_MODER8 ( %XX -- ) 16 lshift GPIOC_MODER bis! ; \ GPIOC_MODER_MODER8 Port x configuration bits y = 0..15
Note: my system strips all comments "\ I'm a comment" from the source and uploads to the MCU at 460800 baud, (too fast to read).
4) I click on the "MAKE" icon in Gvim and my source is then uploaded to the MCU which then compiles it. I have only clicked MAKE, I haven't touched the terminal window or pasted anything to it etc. The makefile strips the comments and then uses a remote connection to GNUSCREEN to upload the code.
Any errors in the code will be flagged in RED text and the PC bell will beep to wake me up.
"GPIOC_MODER_MODER8" now appears in my Forth Dictionary in the MCU.
After this is done, I can manually enter "INPUT GPIOC_MODER_MODER8" and hit enter in the terminal window and GPIOC-8 is instantly a INPUT.
I can also do that in the editor window but it wont take effect until the next MAKE.
To check that GPIOC-8 is now a input I can enter : "gpioc_moder." and I'll get a nice pretty printed register state as below (taken from a working system where bit 7 has been configured as a INPUT in exactly the same way.
GPIOC_MODER (read-write) $00004000
15|14|13|12|11|10|09|08|07|06|05|04|03|02|01|00
00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
Tethered Python:
Forth can run standalone on the target MCU as Mecrisp-Stellaris does. This means the MCU needs to have enough Flash to hold the 20KB Forth binary plus room for the user code. I use the STM32F051 which has 64KB Flash. A 1K line Forth program is considered long, So I have tons of room.
This is where C wins hands down because a C 'blinky' may be as small as 300 bytes but a Forth Blinky would probably need 20030 Bytes, substantially more.
However we also have 'Terthered Forths" where a HOST contains all the intelligence and is "tethered' to a TARGET chip with a cable supplying power and JTAG etc.
In this case the Forth Terminal appears to be talking to the Target, and interaction exactly like I have described above can take place when in "target' mode. GPIO's can be set, cleared tested and so on.
However the actual target code speed will be slower than if Forth was running on the target.
The payoff is that this competes with C in optimizations and code size on the target so a "Blinky" done this way in Forth would probably be a binary size of 80 bytes for the complete standalone self booting image with all the init code, interrupt vectors etc. It's also a binary file, no Forth, no terminal for your customers or competitors to play around with. You're also not bound by the GPL license regarding binaries you produce with it.
The HOST can be instructed to produce a standalone binary file at any point and flash it to the target.
We actually have a working Tethered Forth here:
https://mecrisp-across-folkdoc.sourceforge.ioThe really cool thing is that the HOST is a Ti Tiva Connected Launchpad which cross compiles (using Mecrisp-Stellaris) for a Ti MSP430 TARGET
Now I see no reason that a 'Tethered Micro Python" shouldn't exist and work the same way, then it too can produce binary file sizes as small as it can optimize.
This would mean that small Flash chips with say 16K could be used by a Tethered Python just like C or a Tethered Forth.
Note: Mecrisp-Across, our Tethered Forth works perfectly with a virgin MSP430 straight out of a new factory tube, no code is preloaded, the chip is totally blank. In other words, no bootloader or anything.
Python Web scraper:
Awesome, I'm not a big Python fan, I don't like the whitespace terminators, but I'm not criticizing Python, I use and love some indispensable apps that are written in Python so it is clearly very capable and coder friendly.
Python is certainly the Poster Child of the Revolution these days hence my surprise that no Tethered Python for small MCU's exists that I know of.
I'm slowly learning LISP which represents my highest HLL language aspirations as a electronics technician. LISP is the closest cousin to Forth one can find in that they are both able to reprogram themselves.
By that I mean the Forth Word ": + - ; " when executed like this:
2 2 + . ( 2 + 2 then print the result with . )
Will give zero and not 4. Why would you want to do this, I wouldn't but it demonstrates what I said above. Try that with your language of choice, can you redefine + as - ?