Skip to content
Adam
Language

Directives

The @ directives: code chosen at build time, and the build's settings.

Examples: res\examples\language\directives holds small, commented programs for this page's features, each listing the output it prints; run one with adam build <file> -r.

Conditional code

The conditional directives, @define, @undef, @ifdef, @ifndef, @elseif, @else and @endif, may stand anywhere, and the compiler evaluates them.

directives_define.adam
module exe directives_define;

@define VERBOSE

begin
@ifdef VERBOSE
  println("verbose build");
@else
  println("quiet build");
@endif
@ifdef DEBUG
  println("debug build");
@else
  println("release build");
@endif
@ifdef RELEASE_FAST
  println("level fast");
@endif
end.
output on x86_64-windows-gnu and x86_64-linux-gnu
verbose build
release build
level fast

Predefined symbols

A build defines ADAM; BUILD_EXE, BUILD_DLL, BUILD_LIB or BUILD_UNIT from the file's kind; and TARGET_ names for its target's parts (TARGET_X86_64, TARGET_WINDOWS or TARGET_LINUX, TARGET_GNU), its whole triple (TARGET_X86_64_WINDOWS_GNU) and TARGET_64BIT for a 64-bit pointer. A debug build defines DEBUG, and a release build RELEASE and RELEASE_<level> (RELEASE_FAST for -opt fast).

directives_target.adam
module exe directives_target;

begin
  // The branch for the build's own target is compiled; the other is left out
@ifdef TARGET_X86_64_WINDOWS_GNU
  println("Built for x86_64-windows-gnu");
@else
  println("Built for x86_64-linux-gnu");
@endif
end.
output on x86_64-windows-gnu
Built for x86_64-windows-gnu

Build settings

A build directive stands only in the module's directive prologue, right after module ..;; anywhere else it is an error.

  • @optimize takes debug, safe, fast or small, and @target a triple; each stands at most once in the main module, and adam -opt and adam -t win over them.
  • @linklibrary and @addlibrarypath add a library and a folder to search, found the way an external clause's library is.
  • @addresdata "KEY" "PATH"; builds a file into the binary under its key, the same on every target, and the program reads it back by key at run time.
  • Version info is stamped only with @addverinfo on;, from @vimajor, @viminor, @vipatch and the @vi texts; @exeicon gives the exe its icon.
  • @outputpath sets the build's output folder, and adam -o wins over it.

Messages and breakpoints

@message hint|warn|error|fatal "text"; reports its text at its line, and @breakpoint; marks its line for the debugger; both are also statements. The Directives lists every directive.

↑ ↓ moveEnter openEsc close