v0.3.0 — MIT License

G-Lang
C evolved.

A transpiler-based extension of C. Write modern, expressive code — default parameters, function overloading, defer, modules, a math library — and compile it with any C compiler. No runtime. No bloat. No OOP.

// World.g — entity movement
#module World
#import GMath

struct Entity = {
  Vec2 pos;
  float speed = 1.0f;
  int active = 1;
}

void entity_update(Entity* e, float dt) {
  defer { log_frame(e); }
  Vec2 vel = GMath.vec2(1.0f, 0.0f);
  GMath.vec2_scale_ip(&vel, e->speed * dt);
  GMath.vec2_add_ip(&e->pos, vel);
}
Default parameters
Function overloading
defer keyword
Module system
Error-as-value
Struct defaults
GMath / GString / GArray
Struct embedding
Zero default values

Everything C is missing.

G adds exactly what developers reach for — nothing more, nothing less.

01

Default Parameters

Functions can declare default values. heal(amount=10) — call with or without the argument.

02

Function Overloading

Same name, different types or argument counts. No macros, no runtime cost — rewritten at transpile time.

03

defer

Register cleanup code at the point of resource acquisition. LIFO execution before every return.

04

Module System

#module Entity namespaces all symbols automatically. #import Entity as e with dot-syntax access.

05

Struct Defaults

Declare field defaults inline. Auto-generated _Entity_init() — no manual boilerplate.

06

Struct Embedding

Embed a struct's fields directly into a parent with using. Access nested fields without dot-chaining — flat, direct, zero overhead.

07

Error-as-value

Primitive-returning functions wrap in Result_T. Check .error, use .value. No exceptions.

08

Standard glibg Library

GMath (Vec2/3/4, Mat4, Quaternion), GString (safe strings), GArray (dynamic arrays). Ready for SDL and OpenGL.

09

Full Toolchain

gompile transpiles. guild build handles the full pipeline. VSCodium extension with LSP and debugger.

10

No Garbage Default Values

Variables declared but not initialized default to 0, '\0', or NULL — never garbage. Opt out explicitly with undefined.

Installation

G-Lang requires Python 3.10+, GCC, and optionally GDB for debugging. Clone the repo and run setup:

# Clone and set up
git clone https://codeberg.org/garrett85/G.git
cd G
bash setup.sh

setup.sh installs gompile and guild commands to ~/.local/bin/ and optionally installs the VSCodium extension.

Quick Start

Create a .g file

// hello.g
#module Hello

void greet(char* name = "world") {
  printf("Hello, %s!\n", name);
}

Transpile it

gompile hello.g
# outputs gompiled/hello.c and gompiled/hello.h

Or build a full project with guild

# guild.toml
name = "my_game"
version = "0.1.0"

[build]
sources = ["Entity.g", "World.g", "main.c"]
libs = ["SDL2"]
flags = ["-Wall"]
guild build # debug build
guild build --release # optimized
guild run # build + run

Naming Conventions

ContextName
LanguageG / G-Lang
File extension.g
Transpiler scriptgompile.py
Transpiler commandgompile
Build systemguild / guild.py
Generated C outputgompiled/Name.c
Generated headergompiled/Name.h
Source mapsgompiled/Name.map.json

Key Features

Default Parameters

int add(int a=5, int b=3) {
  int result;
  result = a + b;
  return result;
}

Function Overloading

float scale(float v, float s) { ... }
Vec2 scale(Vec2 v, float s) { ... }
// Call sites rewritten at transpile time — zero runtime cost

defer

void load_texture() {
  FILE* f = fopen("tex.png", "rb");
  defer { fclose(f); } // always runs
  // ... work with f ...
}

Module System

#module Physics

// In another file:
#import Physics as ph
ph.apply_force(&body, force);
v0.3.0 — Latest Release

Download G-Lang

Choose the package that fits your needs. Both require Python 3.10+, GCC, and GDB.

Dev Package

Full source including tests and debug demo

  • Everything in Project Package
  • test/ — full test suite
  • debug_demo/ — debugger example
  • Complete commit history
  • Contribute and report issues
Clone from Codeberg ↗

Or install directly from the command line:

$git clone https://codeberg.org/garrett85/G.git
$cd G && bash setup.sh

What you need

Required

Python 3.10+

The transpiler and build system are pure Python. No pip installs needed.

Required

GCC / Clang

Any C compiler that handles C11. GCC is the default; set cc = "clang" in guild.toml to switch.

Optional

GDB + VSCodium

For full source-level debugging. Set a breakpoint in your .g file, step through, inspect variables.

Why G-Lang exists.

C is the language games are built in. From id Software's Quake... to modern indie engines, C's performance, predictability, and direct hardware access make it the pragmatic choice. But C has papercuts — small, daily frustrations that accumulate over a project.

G-Lang fixes the papercuts. It's a transpiler that converts G source files to standard C before compilation. The output is readable, debuggable C that you can inspect, modify, and compile with any C toolchain.

G adds exactly what developers — game developers especially — reach for constantly: default parameters so you stop writing boilerplate, function overloading so vec_add works for Vec2 and Vec3, defer for deterministic cleanup, a module system that namespace everything automatically, and a math library that pairs directly with OpenGL and Vulkan.

Philosophy

Status

G-Lang is at v0.3.0. The language is functional and usable end-to-end — transpiler, build system, standard library, and full VSCodium integration with syntax highlighting, autocomplete, and a source-level debugger.

It has not yet been battle-tested in a shipped game. 1.0 means a real game ships with it. That's the milestone.

Author

Built by Garrett Gaston. Source on Codeberg. MIT License.