Skip to content

The EM language is dead, long live EM !!!

For the past fifteen years, the focus of the EM Programming Language has remained constant – producing "tiny code for tiny chips" where every byte of memory and μJoule of energy matters.  But now, I may have unwittingly come upon a better means  towards this end.

If you can't beat 'em, Zig•EM

My zeal to promote EM earlier this year blinded me to the challenges of sustaining a novel programming language for resource-constrained embedded systems.  Supporting just a handful of developers over the past decade pales in comparison with the effort demanded to render EM openly and freely available to the broader embedded community.

My (rhetorical) question to the community about the need to move beyond C (towards EM, of course !! ) elicited a mixed bag of reactions – from "cool, good luck"  to "sorry, try again" .  But then, I received this most consequential of comments which turned on the lights for me: 

"With a language like Zig I don't think there's need for EM"

FULL DISCLOSURE – You don't know what you don't know

I pride myself on staying informed about the latest directions in programming language design and imple­mentation.  For me, programming languages lie at the heart of Computer Science; and for me, conceiving and evolving the EM language provided a personal path to the discipline's core.

Honestly, I'd never even heard  of Zig when first receiving this comment several months ago. While attending the Embedded World Conference in Nürnberg shortly thereafter, I informally polled dozens of attendees; and with the exception of my esteemed colleague Jeremy Bennett, no one had heard of the Zig programming language either.  Several folks did, however, know about zigbee® – which you'd expect from this crowd. 😉

Like EM, Zig offers higher-level programming with higher-levels of performance when compared with C; and Zig regularly earns high-marks when held up against other modern systems programming languages like Go and Rust – both already targeting embedded MCUs.

But unlike the competition, Zig offers an inherent simplicity and transparency reminiscent of C – the incumbant systems programming language which some believe Zig could supplant.

First released in early 2016, the Zig community supporting and sustaining this novel language continues to cast its net further and wider.  Compared with Go and Rust, however, Zig very much remains a work in progress – while capturing new followers (like me) on a daily basis.

If you haven't already googled "Zig programming language", visit ziglang.org as a starting point.

Suffice it say, far more folks have already lined up behind Zig than would ever even hear of the EM programming language. To that end, I've decided to "downgrade" EM to a programming framework leveraging Zig as its host language – which finally leads us to Zig•EM.

It's Zig all the way down...

As described here, the current rendition of EM – a transpiler written in TypeScript – generates a meta-program (implemented in NodeJS) whose hosted execution shapes a downstream run-time program (implemented in C/C++); the latter then compiles into firmware targeting some resource-constrained MCU platform.

In the case of Zig•EM, it will use just one language throughout its implementation – resulting in a 10✕ reduction in the amount of code I'll need to maintain; I can also leverage ZLS, an implementation of Microsoft's Language Server Protocol which enables Zig integration with VSCode and other popular IDEs.

And above all, you can direct all questions / comments about the Zig language to the Zig community – as will I.

As its overarching goal, the Zig•EM framework strives to reconstitute the novel concepts and constructs first introduced within EM by using design-time patterns, build-time tooling, and run-time services – all leveraging the latest stable release of the Zig programming language.

Plans are worthless ...

... but planning is everything .(1)  Given our unanticipated change of course, let's set some new objectives for evolving the Zig•EM framework through the remainder of this year:

  1. General Dwight D. Eisenhower,
    34th President of the United States

focus exclusively on supporting the TI CC2340R5, which served as the initial hardware platform when EM debuted late last year; my enthusiasm for this wireless MCU hasn't waned in the interim !!

create a suite of basic Zig•EM examples – mimicking the dozen EM programs originally described here  – which would then illustrate how the framework maps EM constructs onto the Zig language

benchmark the runtime performance of Zig•EM in terms of program size, execution time, and power consumption – using our suite of basic examples along with a Zig-based re-work of EM•Mark

push forward with Zig•EM support for the CC2340R5's 2.4 GHz radio – eventually re-creating the minimalist BLE stack described here and measuring its performance against TI's legacy C code

maintain a public Git repository containing the Zig•EM framework source code – written entirely in Zig from the ground-up, and made openly available under an unconstrained MIT license

I'll try to post regular updates on progress towards these objectives, along with some high-level tours as Zig•EM takes shape.  Let's see what happens, as we do live in interesting times !!

How you can get involved

explore the Zig language – I highly recommend Karl Sequin's Learning Zig as a starting-point

experience the "Zen of Zig" at the Ziggit forum – a refreshing respite from the rants at Reddit

read my first post about Zig•EM to the Zig dev community – then sign-up and send me some ❤

Happy coding !!!   🌝   💻