Felix also allows you to insert executable code literally in fixed places inside Felix code. There are two cases.
Statements can be lifted with the plain cstmt statement:
proc hello() {
cstmt """
std::cout<< "Hello World" << ::std::endl;
std::cout<< "C++ Embedded in Felix" << ::std::endl;
""";
}
If the C statement does not return, use the noreturn option:
proc leave() {
noreturn cstmt "::std::exit(0);";
}
Lifted code can accept arguments:
proc error(x:int) {
noreturn cstmt "::std::exit($1);" x;
}
The argument can be a tuple, the components are inserted by the usual rules for C bindings using $9 style notation.
An expression can be lifted too, however the type must be given:
var x = cexpr[int]"42" endcexpr;
If the expression is not atomic, it is wise to enclose it in parentheses.
There is a short hand for lifting variables:
cvar[int] M_PI;
which is equivalent to:
cexpr[int]"M_PI" endcexpr;