Snek Update — March, 2019

I've been busy hacking on Snek for the past few weeks and thought I'd post a status report.

Lola Parse Table Compression

The biggest snek-related development has been improvements in the Lola LL parser generator. Lola now squeezes the Snek parse tables down to 1248 bytes. That savings opened up the opportunity for some Snek additions.

Dictionaries

With "piles" of memory available, I've gone ahead and added Dictionaries to Snek. Dictionaries are stored in the same data structure as Lists and Tuples, they just use two slots per entry, with the first slot being the key and the second the value.

Lookups use a binary search (which led to a several-day exploration into optimal binary search implementations). This requires a "total ordering" of snek objects, and means that Dictionaries are sorted by key, which led to performance improvements for comparison operators.

Replacing snek_poly_equal with snek_poly_cmp

Before the Dictionary work, snek only offered relational operators (<, <=, >, >=) on Numbers. Needing a total ordering of all values for Dictionaries, I added support for a less-than relationship. This could be used to expand the relational operator support. However, having two parallel operations that performed the same traversal of the object effectively doubled the amount of memory used.

Replacing snek_poly_equal and the temporary snek_poly_less functions with the single snek_poly_cmp function saved a bunch of space and simplified the evaluation process for the relational operators.

Snek Development Environment Improvements

Snekde now offers a list of available serial ports to choose from in the 'open serial port' dialog. It also works harder to keep the serial port functioning well, including disabling xon/xoff before sending ^C to interrupt the application.

Documentation

I've created a web page to host information about Snek, which includes links to the Snek reference manual (still in the early stages of writing) and other information.

New Lego-compatible Motors

I spent yesterday at a local Lego convention, Bricks Cascade, where I found a new company selling Lego-compatible electrical devices. Motors have been the hardest part of the Lego program as they need to be firmly physically connected to the model, and hence Lego-specific. Lego hasn't made a simple directly-controlled motor for a long time; the current products all use a digital serial bus to control them, which isn't easily integrated into an Arduino environment.

Circuit Cubes offers a range of cubes in a standard size that snap onto regular Lego blocks. This includes batteries, lights, switches and (yes, the best part is always last), two different motors! All of these are as simple as possible with nary a micro-controller in sight and no SPI or I2C bus either.

We installed one of their Geared Motor Cubes into an existing robot and hooked up an Arduino running Snek. In a few minutes, the robot was wandering around the show floor.