Skip to content

Getting Started with NG

NG compiles and runs through a single tool, ngi, which drives the full pipeline (parse → resolve → typecheck → FlowIR → QBE IL → native executable) for a file or an inline source unit.

Requirements

  • macOS or Linux with a modern C++ compiler (the build pins clang/clang++ with libc++ on macOS; Homebrew LLVM provides clang-tidy/clang-format).
  • CMake ≥ 3.25 and Ninja.

Build

bash
cmake -S . -B build -GNinja
cmake --build build -j

This produces:

  • build/ngi — the NG frontend (headless).
  • build/ng_test — the full Catch2 test suite (run ctest --test-dir build).

Run your first program

Write hello.ng:

ng
import prelude;

fun main() -> i64 {
    print("hello, NG");
    return 42;
}

Run it:

bash
./build/ngi hello.ng

Output:

text
compiled 32 vNext function(s)
hello, NG
native main exited with code 42

main may return nothing (unit), i64, f64, or string; string and float returns are printed to stdout, and an integer return becomes the process exit code reported by the driver.

Inline source

ngi --source compiles and runs a source unit directly, and ngi --expr parses a single expression:

bash
./build/ngi --source 'import prelude; fun main() { print(1 + 2); }'
./build/ngi --expr '2 * 3 + 4'

Native compilation

NG can compile programs to native executables using the --native flag. The --output flag specifies the output file path:

bash
./build/ngi --native --output hello hello.ng   # compile to native executable
./build/ngi --native hello.ng                  # compile and run immediately

Native executables are self-contained and don't require the NG runtime at execution time. See Language Guide: Why NG? for binary size comparisons with other languages.

Interactive programs

GUI/interactive programs run a frame loop (see ImGui Integration):

bash
./build/ngi example/ng_ide.ng

Tests and examples

  • ./build/ng_test runs the whole suite (1700+ assertions across 430+ cases), including a sweep that runs every example/*.ng end to end.
  • example/ holds one runnable example per feature area — a great way to learn by reading.

Next steps

Made with ❤️ by the NG community.