Logic circuits, written down.

A small language for building and simulating logic circuits, made for people learning how computers work.

↓ Download circ-compile for Linux, macOS, or Windows
half_adder.circ · live simulation click input pins to toggle
// half_adder.circ
import xor "<builtin>/xor.circ"
input a, b
xor s(a=a, b=b)
and c(a=a, b=b)
output sum(in=s.out)
output carry(in=c.out)
vocabulary
primitives
andnotledwireromram
macros
ornandnorxorxnor expand to primitives
signals
1–64 bitsinput[4] aa[0..2]{a, b}
files
import adder "adder.circ" one circuit each
from file to running chip
1
Write a .circ file

Use any text editor, or write in the playground to check your wiring as you type.

2
Compile it

Run circ-compile to produce a self-contained WebAssembly module. Use --preview to print a schematic in your terminal.

3
Run the circuit

Set input pins and read outputs from JavaScript. Run the module in a browser, in Node, or in the playground.

The whole language

Six primitives. Five macros. One import.

A program is a list of declarations: name input pins, place gates, and connect their ports. Combine circuits with imports to build larger ones. If you know the early Nand2Tetris hardware chapters, these building blocks will look familiar.

--preview

Source on the left. Schematic on the right.

This half-adder uses XOR for the sum and AND for the carry. Run circ-compile with --preview to print its schematic in your terminal.

Open it in the playground →
source
// half_adder.circ
import xor "<builtin>/xor.circ"
input a, b
xor s(a=a, b=b)
and c(a=a, b=b)
output sum(in=s.out)
output carry(in=c.out)
circ-compile --preview
╭───╮     ╭───╮
│ a ├○●──▶┤   │         ╭───────╮
╰───╯ │   │AND├○───────▶┤ carry │
      │╭─▶┤   │         ╰───────╯
╭───╮ ││  ╰───╯
│ b ├○┼╯
╰───╯ ││  ╭───────╮
      ╰┼─▶┤       │     ╭─────╮
       │  │[xor:s]├○───▶┤ sum │
       ╰─▶┤       │     ╰─────╯
          ╰───────╯
sourcecirc-compile --preview
Install

Run it on your own machine.

Linux · macOS · Windows · GPL v3
↓ Download circ-compile for Linux, macOS, or Windows/download →