#modify directive

The #modify compiler directive lets one put a block of code that is executed at compile-time each time a call to that procedure is resolved. The #modify directive allows one to inspect parameter types at compile-time.

Here is an example for how to use #modify.

do_something :: (T: Type) -> bool {
    type_info := cast(*Type_Info) T;
    if type_info.type == .INTEGER  return true;
    if type_info.type == .ENUM     return true;
    if type_info.type == .POINTER  return true;
    return false;
}


function :: (dest: *$T, value: T)
#modify { return do_something(T); }
{
    
}

In the example above, returning false generates a compile-time error, while returning true tells the compiler that $T is a type that will be accepted at compile-time.

1 Like