For the past while I've been building Moth, a programming language that reads the way you'd say it out loud. Moth 1.11 came out today, and this is what it is and how it works.

What it looks like

set guests to list of "Ada", "Grace", "Alan" for each guest in guests say "Welcome, " guest "!" end to fib with n if n is less than 2 return n end return fib(n - 1) + fib(n - 2) end say "fib(32) is " fib(32) 

There are no symbols to learn beyond a little arithmetic, and when something goes wrong, Moth says so in plain words: line 12: there is no item 5, the list only has 3 items.

Numbers work the way people expect, like a spreadsheet: they're compared to 15 significant digits, so 0.1 + 0.2 is 0.3 says yes.

A compiler written in itself

moth build hello.moth turns a program into hello.exe on Windows, or hello on Linux: a program of its own, with nothing to install.

Building fib.moth into fib.exe: fib(32) in 16 ms, against 341 ms for the same program in Python

The compiler that does this is written in Moth. It writes x86-64 machine code and the Windows (PE) and Linux (ELF) file formats byte by byte, with no assembler, no linker and no C toolchain. moth.exe builds itself, and the Linux moth builds it too, into exactly the same bytes.

How fast

The same four programs in C, Rust, Moth and Python, each timed from start to finish on Windows 11:

C Rust Moth Python
fib(32): 7 million calls 20 ms 18 ms 25 ms 521 ms
adding 1 to 100,000,000 36 ms 10 ms 37 ms 11.1 s
primes up to 300,000 71 ms 71 ms 72 ms 2.2 s
30,000,000 steps of decimal maths 48 ms 51 ms 49 ms 4.6 s

Moth still keeps its promises in these: numbers are decimals compared to 15 digits, and every step that could go wrong is checked. The compiler gets there by working out, as it writes the code, what each variable is sure to hold.

Four engines that must agree

Moth also runs in the browser. The playground has a debugger that goes backwards through a run, and mistakes are underlined as you type.

Behind it are three engines: a bytecode VM, a JIT that compiles Moth to JavaScript, and a WebAssembly compiler that writes the module byte by byte. All of them, and the native compiler, must say, draw and fail exactly alike. CI checks that on every push, including with 5,000 randomly broken programs.

Batteries included

Moth ships with a standard library: HTTP and an HTTPS server, sockets with TLS, email, SQLite through C libraries, JSON, XML, TOML, zip, PNG and JPEG images, AES-GCM encryption, charts, numbers of any size, and tools to use every core at once. There's a package manager, a profiler, a coverage tool, notebooks, an installer builder and a VS Code extension.

Try it

It's open source under Apache 2.0. I'd love to hear what you think of the syntax, and what you'd build with it.