prev | toc | next
 

3.2.4 MUF Compiler Directives

Compiler directives — additional instructions that the server executes before or while compiling your code — were introduced in the MUF Overview. Below is a more complete reference of the available compiler directives.


$define <definition name> <definition> $enddef

This redefines <definition name> such that all instances of it will be replaced with <definition> when the program is compiled.


$undef <defname>

This undefines <defname>, making it an undefined value for the compiler. Its primary use is to allow compiler directives to be included in the source code without their being invoked by the compiler. For example, you might have a program that should be compiled differently if running at Mucker Level 3 rather than Mucker Level 2. You could include the following lines in your code...

====================================
$define MLev2     (* Undefine this if the program is set M3 *)
$undef  MLev3       (* Define this if the program is set M2 *)
====================================

This way, the person compiling the program would have an example of each valid form, even though only one is being invoked.


$echo <string>

This outputs <string> to the person compiling the program, at compile time. Example:

====================================
$echo Compiling multi-guest.muf...
$echo See header comment for configuration instructions.
====================================


__version

This is a pre-defined macro that is replaced at compile time with the current server version. It would be useful for tests to ensure that the server version can support all the primitives used in your program. The replacement string will be the same as that returned by the VERSION primitive.


$ifdef <condition>
  <compile-if-true>
$else
  <compile-if-false>
$endif

$ifndef <condition>
  <compile-if-true>
$else
  <compile-if-false>
$endif

These cause conditional compilation of blocks of code, based on <condition>. <Condition> can be a $defined name, or a test that consists of a comparator such as =, <, or > and a test value, all in one word, without whitespace. The else clause is optional. Comiler directives are nestable. Example:

====================================
$ifndef __version>Muck2.2fb3.5
  $define envprop .envprop $enddef
$endif

$define ploc

$ifdef proplocs .proploc $else $endif $enddef
====================================


$include <program>

This creates $defines based on the _defs/ propdir of <program>. For example, if object #345 had the following properties...

====================================
/_defs/desc: "_/de" getpropstr
/_defs/setpropstr: dup if 0 addprop else pop remove_prop then
/_defs/setpropval: dup if "" swap addprop else pop remove_prop then
/_defs/setprop: dup int? if setpropval else setpropstr then
====================================

... then a program that contains the line $include #345 would be compiled such that all instances of desc, setpropstr, setpropval, and setprop would be preplaced with their respective definitions on #345.


Escaped statements will be read literally, rather than interpreted and expanded by the compiler, which allows primitives and macros to be included in $defines. Example:

====================================
$define addprop over over or if \addprop else pop pop remove_prop
$enddef
====================================

In this case, ADDPROP will be expanded in the program itself, but the compiler will not recursively expand it... it will call the actual, in-server ADDPROP.

prev | toc | top | next