Language Reference
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.
A tour in one block
Section titled “A tour in one block”1// Structs, enums, generics, traits.2struct Point<T> {3 x: T,4 y: T,5}6
7enum Shape {8 Circle(f64),9 Rectangle(f64, f64),10 Point,11}12
13trait Area {14 fn area(&self) -> f64;15}16
17impl Area for Shape {18 fn area(&self) -> f64 {19 match self {20 Shape::Circle(r) => 3.14159 * r * r,21 Shape::Rectangle(w, h) => w * h,22 Shape::Point => 0.0,23 }24 }25}26
27// Pattern matching, ranges, guards.28fn classify(n: i32) -> &str {29 match n {30 0 => "zero",31 1 | 2 => "small",32 x if x < 0 => "negative",33 _ => "large",34 }35}36
37// Closures and iterators.38fn sum_of_squares(values: &[i32]) -> i32 {39 values.iter().map(|x| *x * *x).sum()40}41
42// Async / await.43async fn fetch_twice() -> i32 {44 let a = fetch_one().await;45 let b = fetch_one().await;46 a + b47}Constructs
Section titled “Constructs”Declarations
Section titled “Declarations”| 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. |
Control flow
Section titled “Control flow”| 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). |
Pattern matching
Section titled “Pattern matching”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.
Generics and traits
Section titled “Generics and traits”- 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
Section titled “Closures”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
Section titled “Unsafe”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.
Macros
Section titled “Macros”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.
Compiler-known builtin types
Section titled “Compiler-known builtin types”| 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> |
Standard library
Section titled “Standard library”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.
Next steps
Section titled “Next steps”See the GSX reference for view syntax, and the pipeline explained for how the compiler processes these constructs.
