Conjure provides several global constants and functions that are automatically available in every module without needing to import them. These include compile-time constants for platform detection and essential runtime functions.
Build Constants
These constants are set at compile time and allow you to write platform-specific code or enable debug features that get optimized away in release builds.
OS
The OS constant indicates the target operating system. It uses the runtime.OS enum type.
import "conjure/runtime"
if OS == runtime.OS.Darwin {
io.println("Running on macOS")
} else if OS == .Linux { // shorthand for runtime.OS.Linux
io.println("Running on Linux")
} else {
io.println("Running on something else...")
}The supported values are:
| Constant Value | Description |
|---|---|
Linux | Linux-based operating systems |
Darwin | macOS and iOS |
Windows | Windows operating systems |
FreeBSD | FreeBSD-based systems |
Unknown | Fallback for unrecognized platforms |
ARCH
The ARCH constant indicates the target CPU architecture. It uses the runtime.Arch enum type.
import "conjure/runtime"
if ARCH == runtime.Arch.ARM64 {
io.println("Running on ARM64 (Apple Silicon or similar)")
} else if ARCH == runtime.Arch.X86_64 {
io.println("Running on x86-64")
}The supported values are:
| Constant Value | Description |
|---|---|
X86_64 | 64-bit Intel/AMD processors |
ARM64 | 64-bit ARM processors (Apple Silicon, modern mobile) |
I386 | 32-bit Intel/AMD (legacy) |
ARM | 32-bit ARM (legacy mobile/embedded) |
Unknown | Fallback for unrecognized architectures |
DEBUG
The DEBUG constant is true when the program is compiled with debug information enabled (using the -g flag). Use this for debug-only code paths.
if DEBUG {
io.println("Debug mode: extra validation enabled")
validateInternalState()
}When DEBUG is false, the compiler removes the entire conditional block from the output, resulting in zero runtime overhead.
DEV
The DEV constant is true when the program is compiled in development mode (without optimization). This is the default when no -O flag is specified.
if DEV {
io.println("Development build")
} else {
io.println("Release build")
}Like DEBUG, unused branches are eliminated at compile time.
Using Constants for Conditional Compilation
Because these constants are known at compile time, the compiler can eliminate dead code branches entirely. This is powerful for writing cross-platform code without runtime overhead.
import "conjure/runtime"
func getPlatformName() string {
if OS == runtime.OS.Darwin {
return "macOS"
} else if OS == runtime.OS.Linux {
return "Linux"
} else if OS == runtime.OS.Windows {
return "Windows"
} else {
return "Unknown"
}
}When compiled for macOS, this function compiles down to simply returning "macOS" with no runtime checks.
Global Functions
panic
Terminates the program immediately with an error message and exit code. Use this for unrecoverable errors.
func divide(a i32, b i32) i32 {
if b == 0 {
panic("Division by zero", 1)
}
return a / b
}Signature:
func panic(message string, code i32)The panic function never returns. After printing the message to stderr, it terminates the program with the specified exit code.
assert
Checks a condition and panics if it’s false. Use this for catching programming errors during development.
func processItems(items []Item) {
assert(items.len > 0, "items must not be empty")
// Process items...
}Signature:
func assert(cond bool, msg string)When the condition is false, assert calls panic with the message prefixed by “Assertion failed: ”.