Skip to content

Language Reference

Reference4 min read
Edit page

Glyim is a Rust-like systems programming language with its own file extension, .g. This page lists the constructs the compiler accepts. The full grammar is still evolving — the glyim-lang-core, glyim-lang-alloc, and glyim-lang-std crates contain the current standard library source, written in Glyim, and serve as the compiler’s bootstrapping corpus.

// Structs, enums, generics, traits.
struct Point<T> {
x: T,
y: T,
}
enum Shape {
Circle(f64),
Rectangle(f64, f64),
Point,
}
trait Area {
fn area(&self) -> f64;
}
impl Area for Shape {
fn area(&self) -> f64 {
match self {
Shape::Circle(r) => 3.14159 * r * r,
Shape::Rectangle(w, h) => w * h,
Shape::Point => 0.0,
}
}
}
// Pattern matching, ranges, guards.
fn classify(n: i32) -> &str {
match n {
0 => "zero",
1 | 2 => "small",
x if x < 0 => "negative",
_ => "large",
}
}
// Closures and iterators.
fn sum_of_squares(values: &[i32]) -> i32 {
values.iter().map(|x| *x * *x).sum()
}
// Async / await.
async fn fetch_twice() -> i32 {
let a = fetch_one().await;
let b = fetch_one().await;
a + b
}
Construct Syntax Notes
Function fn name(params) -> Ret { … } Free functions and associated functions in impl blocks.
Struct struct Name { field: T, … } Tuple and unit forms supported. Generic parameters with bounds and where-clauses.
Enum enum Name { A, B(T), C { x: T } } Algebraic data types.
Trait trait Name { fn method(&self); } Default methods and associated types are supported.
Impl impl Trait for Type { … } / impl Type { … } Static dispatch through the trait system.
Local binding let pattern: Type = expr; Types are usually inferred.
Construct Forms
Conditional if expr { … } else { … }
Loop while cond { … }, loop { … }, for x in iter { … }
Match match expr { pattern => arm, … }
Async async fn … and expr.await — desugared to state machines (straight-line and multi-await bodies).

Patterns support literals, ranges, or-patterns (1 | 2), slices, structs, tuples, enums, bindings, and if guards. The wildcard _ covers unmatched cases. Match arms are checked for exhaustiveness by the type checker.

  • Type parameters: struct Point<T>, fn f<T: Trait>(…), and where-clauses.
  • Trait bounds participate in the trait solver, which handles higher-ranked trait bounds (for<'a>).
  • Auto-traits (Send, Sync, Unpin) are computed automatically.
  • Trait objects use vtable generation for dynamic dispatch.

Closures capture their environment with capture analysis that classifies each capture as ByValue, ByRef(Mut), or ByRef(Not). Closure syntax mirrors Rust: |x| x + 1, |x: i32| -> i32 { x + 1 }.

unsafe fn declares a function with unchecked contracts. Calls to an unsafe fn outside an enclosing unsafe { } block trigger the unsafe_fn_call lint, which warns by default and can be allowed or denied from the CLI.

Declarative macros use macro_rules! with fragment specifiers including :expr, :ty, :pat, and :tt. Built-in macros:

Macro Purpose
file!, line!, column! Source location reporting.
env!, option_env! Environment variable access (required / optional).
include!, include_str!, include_bytes! Embed other files at compile time.
concat!, concat_idents! Literal and identifier concatenation.
stringify! Render an expression as a string literal.
format! Format a string from values and display specifiers.
vec! Build a Vec from elements or a fill value.
matches! Test whether an expression matches a pattern.
assert!, assert_eq!, assert_ne! Runtime assertions (checked in debug and release).
debug_assert!, debug_assert_eq!, debug_assert_ne! Assertions checked in debug builds only.
write!, writeln! Write formatted output into a sink.

The standard library additionally defines println!, print!, eprintln!, eprint!, and panic! as declarative macros in its .g sources; they resolve through the regular user-macro path rather than the builtin table.

Procedural macros are supported through a C-compatible token-stream ABI (glyim-proc-macro) with a dlopen-based cdylib loader, driven by the --proc-macro-deps CLI flag.

Category Types
Primitives i32, u32, f64, bool, char, str, &str and friends
Ranges Range, RangeInclusive, and the .. / ..= syntax
Optional / fallible Option<T>, Result<T, E>
Collections Vec<T>, String
Smart pointers Box<T>, Rc, PhantomData<T>, UnsafeCell<T>

The standard library is written in Glyim and ships in three crates:

  • glyim-lang-core — Option, Result, iter, slice, str, cell, mem, ptr, ops, cmp, marker, panic, hint, convert, default, future.
  • glyim-lang-alloc — Box, Vec, String, Rc, RawVec.
  • glyim-lang-std — io, fs, net, thread, sync, env, time, process, task.

Pass --with-stdlib to the compiler (or use glyip, which does this for you) to make these names resolve without explicit use statements.

See the GSX reference for view syntax, and the pipeline explained for how the compiler processes these constructs.