Install
eggc and clutch come as native binaries for Linux (x86_64, arm64), macOS
(arm64, x86_64) and Windows (x86_64). eggc compiles through C, so you also need a C
compiler (cc; on Windows gcc, with $env:CC = "gcc" in PowerShell).
curl -fsSL https://raw.githubusercontent.com/femto/egg/main/install.sh | sh
irm https://raw.githubusercontent.com/femto/egg/main/install.ps1 | iex
They install the latest release in ~/.egg (EGG_HOME; EGG_VERSION=0.1.0
for another release) and check it against the release’s SHA-256 sums. They
put the installation’s bin ($EGG_HOME/bin, by default ~/.egg/bin) on
your PATH: install.sh in your shells’ startup files (~/.profile,
~/.bash_profile, ~/.bashrc, ~/.zshenv, fish’s conf.d;
EGG_NO_MODIFY_PATH=1 leaves them alone, so have yours run
. ~/.egg/env yourself), install.ps1 in your user PATH. Open a new
terminal and run eggc --version. Or download an archive from
Releases yourself.
Quick start
From a clone instead, eggc runs on Ruby 3.0+ (and a C compiler):
git clone https://github.com/femto/egg
cd egg
bin/eggc run examples/complex/word_freq.egg
Save this as hello.egg and run eggc run hello.egg (bin/eggc in a
clone):
uses alloc, io
fn greet(io: Io, a: Allocator, name: str) void {
const msg = a.concat("hello, ", name)
defer a.free(msg)
io.print(msg)
}
fn main(io: Io, a: Allocator) void {
greet(io, a, "egg")
}
Optional: a native eggc with Spinel
bin/eggc is a Ruby script, so the above needs nothing built. It is written
in the Ruby subset Spinel compiles, so it
(and clutch) can also be native binaries that start in a few milliseconds
and need no Ruby. See Native eggc.
Commands
bin/eggc run examples/fib.egg # 6765
bin/eggc emit-c examples/fib.egg # show the generated C
bin/eggc build examples/fib.egg -o fib # quick to build: cc -O0
bin/eggc build --release examples/fib.egg -o fib # optimized: cc -O2
bin/eggc check file.egg --json # diagnostics as JSON lines
bin/eggc build -g examples/fib.egg # debug build: gdb/lldb break on .egg lines
bin/eggc run app.egg -- one two # what follows -- goes to the program
bin/eggc run app.egg -lfoo -L lib # link a C library (or `link "foo"` in an `allow unsafe` file)
bin/eggc run app.egg --pkg json=../egg-json/src # @import("json") is ../egg-json/src/json.egg
bin/eggc spec # whole spec, for pasting into an AI
bin/eggc lsp # language server for editors (stdin/stdout)
ruby test/run.rb # all tests (CC=clang to switch compilers)
Packages are built with clutch, the package manager (docs/clutch.md):
bin/clutch new chat && cd chat # a program: clutch.toml and src/main.egg
../bin/clutch add json # a dependency from the index (or --git URL, --path DIR)
../bin/clutch run # resolve, write clutch.lock, build and run
Editor support
editors/vscode is a VS Code extension: highlighting, go to definition,
hover, outline, errors as you type (all served by eggc lsp) and
breakpoints. Install it with:
code --install-extension editors/vscode/egg-lang-0.0.5.vsix
Or in VS Code: Extensions view → ... menu → Install from VSIX… →
pick editors/vscode/egg-lang-0.0.5.vsix. Reload the window and .egg
files are highlighted.
To work on the extension without repackaging, build it once, symlink the
folder and reload (rerun the build after changing extension.js):
(cd editors/vscode && npm install && npm run vscode:prepublish)
ln -s "$PWD/editors/vscode" ~/.vscode/extensions/femto.egg-lang-0.0.5
Rebuild the .vsix with cd editors/vscode && npx @vscode/vsce package --no-dependencies.
Debugging
eggc build -g puts #line directives in the generated C and compiles with
-g (and -O0, unless --release), so gdb and lldb break, step and show
the stack in .egg source:
bin/eggc build -g examples/loops.egg -o build/loops
lldb build/loops -o "breakpoint set --file loops.egg --line 37" -o run
In VS Code (with the extension above, plus CodeLLDB or the C/C++
extension): open a .egg file, click the gutter to set a breakpoint, pick
Debug .egg (lldb) or Debug .egg (gdb) and press F5. The repo’s
.vscode/tasks.json builds the current file into build/ first.
Limits: variables show under their C names (v_n for n), and stepping
into a checked operation lands in a C runtime helper (egg_add and so on);
use step over.