Skip to content
 
 

Repository files navigation

G — Natural Language to C99

"You write prose. G speaks to hardware."

G is a zero-syntax systems programming language. You write human prose — "Set the first pin high and wait 500 ms" — and G compiles it deterministically to C99, to bare-metal x86-64 / ARM64 assembly, to AVR and ESP32 raw MMIO, and to OpenQASM 2.0 quantum circuits. One language, every layer of the stack.


Architecture

                    ┌──────────────────────────────────────────────────┐
    human prose     │                 G compiler (Rust)                │
  "Set X to 5."     │                                                  │
        │           │   Lexer → Semantic Graph → HIR → Type Unification │
        ▼           │         → Ownership Gates → MIR → SSA             │
   zero syntax      │         → Optimizer (G-### diagnostics)           │
        │           └──────────────┬───────────────────────────────────┘
        ▼                          ▼
   deterministic            ┌──────────┐  ┌──────────┐  ┌──────────┐
   bit-for-bit output       │   C99    │  │  asm     │  │ OpenQASM │
                            │ Desktop  │  │ x86-64   │  │ 2.0      │
                            │ AVR MMIO │  │ ARM64    │  └──────────┘
                            │ ESP32    │  └──────────┘
                            └──────────┘

Same semantic graph, every backend — the optimizer feeds C99 for the desktop, GNU as for x86-64 / AArch64, raw MMIO for AVR and ESP32, and quantum assembly for QASM targets.


Quick Start (End Users)

Download the latest release from the GitHub Releases page — each zip is a complete standalone toolchain (the dist/ folder: g/gufran, cpm, apm, g-lsp, a bundled TCC, runtime/, stdlib/) built automatically for Windows, Linux, and macOS by GitHub Actions. Unzip it and run — it just works:

dist/g.exe examples/json.g --run          # Windows
dist/g.exe examples/build_script.g --run  # OS stdlib: lists files, runs tcc, prints exit codes
dist/g.exe examples/web_app.g --run       # serve http://localhost:8080 (HTTP framework in stdlib/net.g)
dist/g.exe examples/cli_tool.g --run Gufran  # CLI args + env: "Hello Gufran, your home is ..."
dist/g examples/hello.g                   # Linux/macOS (dist/g.exe -> dist/g)

Prefer to build it yourself? build_release.ps1 (Windows) and build_release.sh (Linux/macOS) regenerate dist/ from source — they compile the bundled TCC too.

dist/g.exe examples/json.g --run          # Windows
dist/g.exe examples/build_script.g --run  # OS stdlib: lists files, runs tcc, prints exit codes
dist/g.exe examples/web_app.g --run       # serve http://localhost:8080 (HTTP framework in stdlib/net.g)
dist/g.exe examples/cli_tool.g --run Gufran  # CLI args + env: "Hello Gufran, your home is ..."
dist/g examples/hello.g                   # Linux/macOS (dist/g.exe -> dist/g)

Add the folder holding g.exe to your PATH, then:

g examples/json.g --run      # compile with bundled TCC and execute
g examples/json.g --check    # pipeline + quality gates only
g examples/json.g --out json.c   # emit C99 instead
g examples/baremetal_x86.g --target baremetal-x86 --out x86.s  # raw assembly

No Rust, no Cargo, no C compiler installation required.

The Cardinal Package Manager

cpm (alias apm) scaffolds and drives G projects:

dist/cpm.exe init hello      # hello/cardinal.toml + hello/main.g
cd hello
..\dist\cpm.exe run          # dist/g.exe main.g --run  → "Hello from CPM"
..\dist\cpm.exe build        # dist/g.exe main.g --out build/main.c
..\dist\cpm.exe add ..\..\my_lib   # local dependencies, -I wired automatically

Features

  • Zero syntax — human prose in, no brackets, no semicolons, no end. required (implicit EOF scoping)
  • Deterministic, bit-for-bit reproducible compilation
  • Typed routines with recursion, records, enums (exhaustiveness-checked), ADTs (Optional/Result)
  • Lists, Tables, Maps with bounds-checked indexing
  • Text opsSplit, Substring, contains, followed by, Number of / Text of
  • Memory safety — arena/static allocation, ownership tracking, capability lattice
  • FFI to CImport C function ... from "<shim>.h" (deduplicated includes, Phase 44.1)
  • Standard Librarystdlib/net.g (TCP + HTTP framework), stdlib/math.g, stdlib/regex.g, stdlib/os.g (process execution), stdlib/fs.g
  • --run — compile with the bundled TCC and execute; argument forwarding; child cleanup on exit
  • Bare-metal x86-64 & ARM64 — syscall assembly with real stack frames ([rbp-8], [sp, 16+8N] slots, unlimited variables)
  • AVR — raw MMIO (DDRB/PORTB), Timer0 CTC interrupts and INT0 ISRs (ISR(TIMER0_COMPA_vect))
  • ESP32 — FreeRTOS tasks from Every <N> ms do ... verse
  • Quantum — OpenQASM 2.0 output for quantum processors
  • CLI & OSGet argument count / Get argument N / Get env, List directory, File exists, Current time, RunCommand
  • Self-hosted bootstrapexamples/bootstrap.g compiles and runs itself
  • IDE toolingg-lsp Language Server with completion, hover, goto-definition
  • Package managementcpm/apm with cardinal.toml
  • 545 tests, zero warnings, MIT licensed

Repository Layout

g-language/
├── .github/
│   └── workflows/
│       └── release.yml   CI/CD: push a v* tag → build Windows/Linux/macOS
│                         bundles → upload zips to the GitHub Release
├── .gitignore
├── Cargo.toml / Cargo.lock
├── LICENSE              MIT license
├── README.md            this file
├── CHANGELOG.md         the journey, Phase 1 → v1.0
├── MANUAL.md            implementation manual & phase ledger
├── build_release.ps1    regenerates dist/ from source + TCC (Windows)
├── build_release.sh     regenerates dist/ from source + TCC (Linux/macOS)
├── docs/
│   └── rfc-0001.md      grammar table & language charter
├── examples/            G programs: json.g, web_app.g, build_script.g,
│                        bootstrap.g, baremetal_*.g, and the Stage 2-5
│                        bootstrap compilers (lexer/parser/validator/codegen)
├── runtime/             g_rt.h + shims (cli, fs, math, os, regex, tcp, http)
├── src/                 Rust compiler core (main, gufran, cpm, apm, lsp,
│                        lib, lexer, parser, hir, mir, ssa, codegen, ...)
├── stdlib/              pure-verse standard library (net.g, math.g,
│                        regex.g, os.g, fs.g)
├── tests/               compile.rs + e2e.rs (545 tests)
└── dist/                generated by the build scripts (git-ignored):
                         g.exe, gufran.exe, cpm.exe, apm.exe, g-lsp.exe,
                         bin/ (bundled TCC), runtime/, stdlib/

Example Programs

examples/hello.g:

Target G Desktop.

print hello world.

Wait 100 ms.

If 2 + 2 is 4 then
    print arithmetic works.
After.

examples/json.g — a complete recursive-descent JSON parser written in pure verse (tables, enums, records, recursion):

$ target/release/g examples/json.g --run
G
true
3.5

examples/server.g — a native TCP web server (Winsock/socket FFI via runtime/tcp_shim.h, -lws2_32): serves Hello world on port 8080. examples/web_app.g / examples/api_server.g — the same server with zero FFI boilerplate through stdlib/net.g, routing /api{"status":"ok"}.

examples/build_script.g — OS standard library (Phase 44):

Target G Desktop. Import "stdlib/os.g". Import "stdlib/fs.g".
Set Files to Execute ListDir with "examples". ...
$ dist/g.exe examples/build_script.g --run
Found 29 files
TCC exists. Size: 23552 bytes
tcc version 0.9.27 (x86_64 Windows)
TCC exit code: 0

examples/baremetal_x86.g — direct-to-CPU assembly (Phase 36):

Target G Baremetal x86_64.

Print "Direct to CPU".
$ g examples/baremetal_x86.g --target baremetal-x86 --out x86.s
# GNU as, SysV sys_write/sys_exit, stack-frame variables ([rbp-8], ...)

examples/baremetal_avr_isr.g — hardware interrupts (Phase 43):

Target G Baremetal avr.

Every 10 ms do Set LED on.

TCCR0A/TCCR0B/OCR0A/TIMSK0 Timer0 CTC config + ISR(TIMER0_COMPA_vect) with the action inside. examples/baremetal_esp32_task.g turns the same verse into a FreeRTOS task (xTaskCreate) on ESP32.


CLI Reference

g|gufran <file.g> [--out out.c] [--check] [--run args...]
g|gufran -g <source> [--out out.c] [--check] [--run args...]
  --check              pipeline + quality gates, emit no C
  --out F              write generated C/asm/QASM to F
  --run                compile with the bundled TCC (or tcc/gcc/clang on
                       PATH) and execute; trailing args are forwarded to
                       the child program
  --target T           baremetal-x86 | baremetal-arm64 | baremetal-avr |
                       baremetal-esp32 | baremetal-quantum | c99 (default)
  -g                   compile inline G source

g, gufran, cpm, apm, and g-lsp are separate binaries built from the same repository.


Diagnostics (G-###)

G-010 undeclared/return misuse · G-011 use-after-move · G-012 out-of-scope · G-020 type mismatch · G-021 unification failure · G-030 capability violation · G-040 profile constraint · G-041 backend/board · G-050 default policy · G-060 redefinition · G-070 unrecognized concept · G-071 implicit closure · G-080 unused · G-090 dead code eliminated · G-100 constant folded.

License

MIT — Copyright (c) 2026 SK GUFRAN AHMED. See LICENSE.

About

Cardinal Language / G is a zero-syntax systems programming language.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages