Seven backends, and t27b
You will learn
One spec, many target languages, and a native compiler with no LLVM.
One t27 spec can become Zig, C, Rust, JavaScript, TypeScript or Verilog; Verilog comes two ways, straight from the spec and through the HIR, which makes seven backends. The player shows the Rust t27c writes for hello_world. t27b is a second compiler: native AArch64 machine code, no LLVM, a JIT for tests and Mach-O object files. It is not finished, and we say how far it is: in run 26c447ad8 it passed 307 of the 449 specs that the reference compiler passes with tests, 68.4%.
Try it
Switch the player to JavaScript under Also try, generate the module, and run it.

A terminal in your browser running the t27 compiler as WebAssembly: t27c gen rust prints the Rust it emits for hello_world.t27, and t27c test runs the spec's tests.
specs/tutorial/08_modules_and_arrays.t27
// SPDX-License-Identifier: Apache-2.0
; 08 — Modules, visibility and arrays
; Lesson 8, the last one. How a spec names itself, what it exposes, how it
; pulls in another spec, and the array/index syntax used by every lookup table
; in the corpus.
; .
; After this, open specs/numeric/gf16.t27 -- it is a real spec built entirely
; out of what these eight lessons cover.
; phi^2 + 1/phi^2 = 3 | TRINITY
module tutorial-08-modules;
// ============================================================================
// use
//
// use path::to::spec;
//
// Pulls in another spec. Paths are `::`-separated and rooted at the corpus,
// not at the filesystem.
// ============================================================================
use base::types;
// ============================================================================
// pub
//
// `pub` makes a name part of this spec's surface. Without it the name is
// internal: usable here, invisible elsewhere. Default to leaving things
// private -- a spec's exported surface is a promise to whoever imports it.
// ============================================================================
pub const EXPORTED_WIDTH : u8 = 16;
// No `pub`: an implementation detail of this module.
const INTERNAL_SCALE : u8 = 4;
pub fn scaled_width() u8 {
return EXPORTED_WIDTH / INTERNAL_SCALE;
}
// ============================================================================
// Arrays
//
// [_]TYPE{ a, b, c }
//
// The `_` means "as many as I wrote". Fixed tables like this are how the
// numeric specs carry their constants.
// ============================================================================
pub const TRIT_VALUES = [_]i8{ -1, 0, 1 };
pub const POWERS_OF_TWO = [_]u16{ 1, 2, 4, 8, 16, 32, 64, 128 };
pub const EXPONENT_BIAS = [_]u8{ 15, 31, 63, 127 };
// ============================================================================
// Indexing
//
// `array[i]`, zero-based.
// ============================================================================
pub fn power_of_two(index: u8) u16 {
return POWERS_OF_TWO[index];
}
pub fn bias_for_width(index: u8) u8 {
return EXPONENT_BIAS[index];
}
// ============================================================================
// Tests
// ============================================================================
test "the power table matches its own definition" {
try std.testing.expectEqual(@as(u16, 1), power_of_two(0));
try std.testing.expectEqual(@as(u16, 128), power_of_two(7));
}
test "bias table carries the four standard widths" {
try std.testing.expectEqual(@as(u8, 15), bias_for_width(0));
try std.testing.expectEqual(@as(u8, 127), bias_for_width(3));
}
test "a private constant is still usable inside its own module" {
try std.testing.expectEqual(@as(u8, 4), scaled_width());
}
invariant exported_width_is_a_power_of_two
assert EXPORTED_WIDTH == 16
All lessons
Module 1 · The chip
What an FPGA is, which chip we use, and how its pins meet the board.
Module 2 · Numbers in hardware
Bits, trits and number formats, and what arithmetic costs in logic.
Module 3 · Your t27 program
Write a spec, test it, and see why compiling is not the same as being right.
Module 4 · Inside t27c
How the compiler reads a spec and what it writes, including the native t27b.
Module 5 · From spec to hardware
The Verilog t27c writes, the cells it becomes, and what one LUT does.
Module 6 · Reading synthesis
What yosys reports about your design, and which warnings matter.
Module 7 · Place, route, timing
Where the cells land on the die, and whether the clock is met.
Module 8 · The bitstream
How a routed design becomes the bits the chip loads, with no Vivado.
Module 9 · On the board
Ask the chip who it is, load the bits, and check them.