Lame

A systems language that thinks like Lua.

Lame compiles to native code and has no garbage collector. Every value has one owner, and the compiler checks how values are lent and handed over. The vocabulary stays close to Lua: a few general mechanisms instead of one feature per situation.

Learn it by breaking it

Each step is a working program. Edit it, or press one of the mistakes, and the real compiler answers below the editor. It runs here in the page.

Try a mistake
Starting the compiler…

What was built

Yes: a whole compiler, written in Lua 5.4. It reads Lame, checks it, and writes one C file that any C compiler turns into a program. Press a stage to follow one line of code through it.

Why Lua, and why C

Lua was your first choice for the first compiler, and it lets the compiler run compile-time code with the same runtime. Writing C text needs no binding and gives Windows, Linux and macOS at once; the C compiler does the optimizing.

The library is written in Lame

List, Map, Text helpers, Option, files, JSON, threads: all Lame source in std/, built on raw pointers inside unsafe. Only a small C header sits underneath.

How it was checked

A test suite of programs that must run, must be rejected, or must stop with a given message. The generated code was run under Valgrind and sanitizers, and as Windows programs under Wine.

Speed

Two benchmarks ran at about 1.2 times the time of hand-written C, with overflow and bounds checks on.

Lua to Lame

What you already write, and how it looks here.

LuaLameNote

Use it on your machine

The page above checks code but cannot run it: running needs a C compiler. Locally you get both.

Get the branch

git clone https://github.com/Siekwie/Lame.git && cd Lame && git checkout claude/beautiful-mccarthy-7z9l33

Have Lua 5.4 and a C compiler

sudo apt install lua5.4 gcc

On Windows: Lua 5.4 and MinGW-w64 on the PATH, then bin\lame.bat. The generated programs were tested as Windows executables; running the compiler itself on Windows was not.

Run something

bin/lame run examples/hello.lame
bin/lame run examples/calculator.lame -- "2 * (3 + 4) ^ 2"

The commands

lame run file.lamecompile and run
lame build file.lame -o appmake an executable; add --release for speed
lame check file.lameonly report errors
lame test file.lamerun every function named test_…
lame fmt file.lamere-indent in place
lame doc file.lamepublic functions and their comments as Markdown
lame emit-c file.lamewrite the C file and stop

Where to look next

  • examples/: bank, shapes, tree, calculator, wordcount, life, todo (JSON), parallel (threads), callbacks (C)
  • docs/tour.md and docs/ownership.md: the long form of this page
  • docs/reference.md: every rule, with the grammar
  • docs/std/: the library, generated from its comments
  • lua5.4 tests/run.lua: the test suite

Decided without you, and not done

You asked to see where the language ends up unsteered. These are the choices most likely to matter to you; the full list is docs/branch-decisions.md. main is untouched.

Decided in your place

  • A borrow can be given a name that lasts to the end of its block. This loosens your "borrows are never kept" rule.
  • Indexes start at 0, the one Lua habit not followed.
  • Operators, loops and destructors are methods with fixed names (add, equals, get, next, drop), like metamethods.
  • Thread safety is two ordinary collections, Sendable and Shareable.
  • cond and a or b is an exact conditional.
  • ? converts an error into the function's error enum when its type is a member.
  • A number lent for reading needs no @read; everything else still does.

Not done

  • The compiler is still the Lua one; it is not written in Lame.
  • C is the only backend.
  • No language server, no separately compiled libraries.
  • The compiler was only run on Linux; the Windows launcher and macOS are untested.
  • No license was added: that choice is yours.