I find Lisps to be very well suited towards this task, because of its homoiconicity and features like quasiquotation, effectively you have access to the best macro system possible.
I once threw together a 6502 assembler (really a front end to x65) in Scheme to be able to write Commodore programs with powerful Lisp-like macro facilities.
That reminds me of a great anecdote from an old thread:
In 1983, Rescue on Fractalus and Ballblazer, the first releases from Lucasfilm Games, were built with a system written in Lisp. It was a 6502 assembler with Lisp syntax and a Lisp-style macro facility, written in Portable Standard Lisp, running in Berkeley Unix on a 4MB VAX 11/750. Unfortunately it was eventually abandoned because the developer had left and it was a bit of a strain on the VAX that was shared by the whole development team.
Yes, I wrote it. Yes, it was my first non-academic programming job. Yes, the users complained about the parentheses, and the slowness. But, they also took advantage of the powerful macro facility.
You might have an idea on this but how would you approach the opposite operation? Assembly to an in-memory representation, how does Lisp/Scheme handle that kind of manipulation?
With the BYTE accessors and binary constants, I find bit and byte manipulation to be far easier in common-lisp than in C.
e.g. set the 3 bytes starting at bit 2 of x to the binary value 110:
(setf (ldb (byte 3 2) x) #b110)
or set the 3rd byte (8 bits starting at bit 24) of x to 0xab:
(setf (ldb (byte 8 24) x) #xab)
The first example compiles down to the following 2 instructions on sbcl/x64:
; A4: 4883E1C6 AND RCX, -58
; A8: 4883C930 OR RCX, 48
NOTE: The values are 1 bit shifted from what you might expect (binary 110 = 6; 6 << 2 == 24, not 48) because SBCL uses low-bit tagging to distinguish integers from pointers; working with arrays of unboxed machine-friendly sized integers (8,32,64) works as expected.
No I mean a disassembler, I can see how an assembler is nice to write in a language like that but I've never seen much byte manipulation examples. For example going from machine code to the list of opcodes for example.
Here's the times13 function in CCL on x86-64. (Note that #x68 is 13 shifted left 3 times to allow tag bits in the LS 3 bit positions. Also the below could be optimized a lot more but this is the default compilation.)
It's powerful to re-code time critical snippets of code in Assembler, while still having access to a high level language like Lisp for the complex stuff.
It might interest people to know that Forth always offered this functionality and the ':' compiler lets one build ASM macros as well.
I was wondering why one person on Hackaday thought Forth was uniquely suited for exploration in embedded systems programming other than also being a stack language like Assembly. Thanks for pointing this out.
It's not unusual. Lots of Lisp systems support inline assembler or inline C. Historically Lisp systems stored compiled code as LAP (Lisp Assembly Program) and loaded these files via its built-in assembler.
The old Lisp 1.5 manual documents an in-memory assembler in Appendix C, Page 73
Neat reminds me of Game Oriented Assembly Lisp, the language used for a bunch of the Naughty Dog games. It included inline assemblers for the various processors in the PS2, and was used in a very procedural, macro heavy style that this seems to be encouraging.
Neat!
Here's an example of GOAL code with inline code for the vector processors.
I asked a question on HN but didn't get any answers - this might be an easier forum to get one.
I'm working on a hobbyist rocketry project where I'm helping build the flight computer - basically an Arduino Nano connected to modules like a GPS system, accelerator, gyroscope, etc. Are there any Lisp dialects that someone would recommend for an Arduino? The Nano is technically replaceable so if there are better boards that can use Lisp I'd be interested too!
You might want to consider running something like the Raspberry Pi Zero. Looks like the Nano is 45mm x 18mm and the Pi Zero is 65mm x 30mm. If you could fit the Pi Zero it would probably make your life a lot easier.
This is a great suggestion; the Zero has enough oomph to run the JVM, which gives you access to Clojure!
I had the most luck installing the Zulu Embedded version of Java, and I've had a Clojure webapp running on my Pi Zero for over a week now without any hiccups.
I don't know anything about owl-lisp, but you also need a lisp that does not do any runtime memory allocation, as those are usually problematic in embedded projects, especially in those with as little RAM as the nano.
The nano is basically a thin uno and has little storage for large projects, and OPs list of sensors is large. Something like three hundred cell limit. Its just not going to fit.
I've played with drivers using ulisp and its fun and very fast on an adafruit SAMD51 board with plenty of storage. A Metro M4 Gran Central is a lovely dev board but too large for OP to launch.
Maybe an adafruit M4 feather board would work. I've not used one but its supposedly plug and play with ulisp, so I've heard.
I've never used one, but in theory a mattairtech.com product seems like what OP wants. ulisp should compile its just another SAMD51 board, right? And its available with some of the sensors OP wanted onboard. Note that "never used one" means OP will literally be breaking new ground. All I'm sure of its a physically very small SAMD51 board and I can't see any obvious reason ulisp wouldn't work.
The future of embeded dev is probably FPGA for custom hardware and interfaces with lisp or similar HLL (Straight up Clojure getting embedded?). No I don't mean tomorrow future, but maybe 2030.
I was browsing through the uLisp sources looking for places where I could maybe provide FPGA acceleration... Didn't come up with anything off the top of my head, but the thoughts are germinating :-) Might dust off my copy of the Rekursiv book...
I did just try uLisp but it used 96% of my storage and 74% of my RAM, so it's not viable. It was nice to set up though - it pretty much worked out the box - so I do suggest trying it out on slightly larger systems.
Common LISP could certainly generate assembler for Arduino and other MCUs, but there's no way you're fitting that fat old beast (whom I do still love) on one . :-)
Any Raspberry Pi should work fine for Lisp but if I had to use an Arduino I'd just write the code in Processing (or whatever they call the native Arduino compiler language these days) because fitting a Lisp into one would probably be more trouble than it's worth.
no direct arduino experience, but I'd imagine the potential would be greater for scheme than lisp since it is a more minimal subset - quick google reveals 'microscheme'
that said more powerful scheme features like tail recursion and macro systems may or may not be compatible with a more embedded scheme, so I wouldn't count on it being a full 'representative' of what scheme actually is - this may or may not matter, depending on the project
Knowing nothing about uLisp beyond glancing at the code snippets, this seems like it would be a fun tool to use for a CS class on low level programming and compilers.
I came upon uLisp over a few years ago, and was glad to see it show up for the ESP8266 chips. It makes programming these tiny controllers with WiFi enjoyable. Simple things like leaving the parameters blank in a WiFi connect function disconnects it from any current connection. It also blends in with my love of the minimal. I had been playing with Wasp Lisp [1,2] at the time when I found uLisp.
Can anybody speak to how hard uLisp would be to port to RISC-V? It looks pretty nifty. I have a little hobby computer I'm building around a RISC-V core, it might be nice to have it boot to this.
Related: Z80 assembler in Scheme
https://github.com/siraben/zkeme80/blob/master/src/assembler...