Categories
Computing

Lox on Raspberry Pi Microcontrollers

I’ve recently read and enjoyed Robert Nystrom’s ‘Crafting Interpreters‘. I’ve also been exploring Raspberry Pi microcontrollers. I’ve used them both in this GitHub repo, which combines the C bytecode implementation of the Lox language from the book with the C SDK for the Pico.

It runs well, even on these constrained (133Mhz, 264K RAM) devices. The repl seems responsive, and the code all fits. I had to make two changes:

  • I reduced STACK_MAX, as the default produced an image that would not load in the 264k RAM on the Pico. The default ran fine on the newer Pico 2, which has 520K RAM.
  • I reworked main() to provide just the REPL directly. By default the Pico SDK does not provide a filesystem, so there’s no way to load and run scripts ‘from the command line’.

I am curious to explore this further. Clearly the amounts of RAM consumed could be refined, and it might be interesting to add a filesystem. The Micropython port does this, and provides a very productive development experience.

The repo contains some cmake configuration files, mostly because the Pico SDK defaults to using cmake. This provides a build that works on my machine, and can hopefully be compiled for a host PC (a Mac OS machine in my case), or two of the Pico boards: Pico and Pico 2.

In the specimen directory are a few lox scripts I used while reading the book, and a file of one-line scripts that I find easy to enter via cut & paste to the repl.

Pico 2 was interesting to build for, as it contains both ARM and Risc-V cores. The idea seems to be that you choose at boot time which instruction set you use. I’ve built the code for both ARM and Risc-V. I’m curious what that means in practice – in this repo, I can see no particularly obvious differences. The details of ARM vs Risc-V are all managed by simply selecting a different toolchain for the C code.

Categories
Photography

Competition Photos

Yesterday I entered two photos in GPC’s 2024/25 season, in the first competition of 2025. This was an ‘open restricted’ PDI, so these images were digitally projected, and had to come from two distinct genres. In my case, that is ‘still life’ and ‘nature’.

Autumn Still Life

Taken at one of our members evenings earlier in the year, this still life was posed by another club member. I had to compose my image in the frame, and capture it. The judge wasn’t certain the kettle to the right worked (would it have been better omitted, or all in frame?). They also noted that the lace in the foreground really needed to be sharply in focus.

Take off!

Taken during a trip to RSPB Arne, I spent a bit of time watching this Little Egret. It was then quite challenging to develop this image, so that the white plumage remains fully detailed, while the background has some detail in it. The judge noted that they would have preferred the background a touch darker. To fully qualify in a nature competition, this would need a more descriptive title.