#
, instructing the compiler to perform specific actions, enforce checks, or modify parameters.
These directives can only be used at the outermost level of a source file and cannot be placed inside function definitions.
#include
The #include
directive enables the inclusion of another FunC source file parsed in place of the directive.
Syntax:
#pragma
The #pragma
directive provides additional information to the compiler beyond what the language conveys.
#pragma
version
The #pragma
version directive enforces using a specific FunC compiler version when compiling the file.
The version is specified in semantic versioning (semver) format: a.b.c, where:
- a is the major version;
- b is the minor version;
- c is the patch version.
- a.b.c or =a.b.c—Requires exactly version a.b.c of the compiler;
- >a.b.c—Requires the compiler version to be greater than a.b.c.;
- >=a.b.c—Requires the compiler version to be greater than or equal to a.b.c;
- <a.b.c— Requires the compiler version to be less than a.b.c;
- <=a.b.c—Requires the compiler version to be less than or equal to a.b.c;
- ^a.b.c—Requires the major compiler version to be equal to the a part and the minor to be no lower than the b part;
- ^a.b—Requires the major compiler version to be *equal to a part and minor be no lower than b part;
- ^a—Requires the major compiler version to be no lower than a part.
- >a.b is equivalent to >a.b.0 and does not match version a.b.0.;
- <=a is equivalent to <=a.0.0 and does not match version a.0.1 version;
- ^a.b.0 is not the same as ^a.b
- ^a.1.2 matches a.1.3 but not a.2.3 or a.1.0;
- ^a.1 matches all of them.
#pragma
version directive can be used multiple times, and the compiler must satisfy all specified conditions.
#pragma not-version
The syntax of #pragma not-version
is identical to #pragma version
, but it fails if the specified condition is met.
This directive is applicable for blocking specific compiler versions known to have issues.
#pragma allow-post-modification
Introduced in FunC v0.4.1
Using a variable before it is modified within the same expression is prohibited by default.
For example, the following code will not compile:
#pragma allow-post-modification
. This allows variables to be modified after usage in mass assignments and function calls while sub-expressions are still computed left to right.
In the following example, x
will contain the initial value of ds
:
f(ds, ds~load_bits(8));
:
- The first argument of
f
will contain the initial value ofds
. - The second argument will contain the 8-bit-modified value of
ds
.
#pragma allow-post-modification
works only for code after the pragma.
#pragma compute-asm-ltr
Introduced in FunC v0.4.1
asm
declarations can override the order of argument evaluation. For example, in the following expression:
load_ref()
load_uint(256)
load_dict()
load_uint(8)
asm
declaration:
asm(value index dict key_len)
notation dictates a reordering of arguments.
To ensure strict left-to-right computation order, use #pragma compute-asm-ltr
. With this directive enabled, the same function call:
load_dict()
load_uint(8)
load_uint(256)
load_ref()
asm
reordering will occur only after computation.
#pragma compute-asm-ltr
works only for code after the pragma.
Note: #pragma compute-asm-ltr
applies only to the code after the directive in the file.