Skip to content

Basic API Reference

Basic API Reference

Compiler CLI

CommandPurpose
thagc build <file.tg> -o <bin>Compile source to native executable
thagc run <file.tg>Build and run
thagc check <file.tg>Validate parse/type/codegen without final link
thagc fmt <file.tg>Normalize source formatting

Dependency, registry, and update flows are handled by drago.

FlagMeaning
--target=<triple>Build for configured target triple
--emit-llvmEmit .ll IR instead of linking binary
--link-lib=<name>Add -l<name> to linker
--link-dir=<path>Add -L<path> to linker
--link-arg=<arg>Pass raw linker argument

Shipped stdlib modules

ModuleImportKey functions
std.ioimport std.io as ioread_line, read_int, read_ints, read_word, read_all
std.mathimport std.math as mathabs, min, max, clamp, sqrt, pow, gcd, lcm
std.stringimport std.string as stringconcat, from_int, to_int, from_f64, split, trim, contains
std.timeimport std.time as timenow_ms, sleep_ms

The following modules do not exist: lib.fs, lib.process, lib.env, lib.http, lib.toml, lib.tensor, lib.map.

Builtins (no import needed)

NameSignatureDescription
printprint(value)write str, bool, i32, i64, or f64 to stdout without newline
printlnprintln(value)write str, bool, i32, i64, or f64 to stdout with newline
eprinteprint(value)write str, bool, i32, i64, or f64 to stderr without newline
eprintlneprintln(value)write str, bool, i32, i64, or f64 to stderr with newline
flushflush()flush stdout

FFI declaration form

extern func symbol_name(arg1: i32, arg2: ptr) -> i32
  • Signature must match the C symbol ABI exactly.
  • Use str for const char*, ptr for void*, f64 for double.
  • There is no f32 type available to user code.
  • Add explicit link flags (--link-lib, --link-dir) for external libraries.

See FFI Safety Guidelines for the full checklist.