c-dsl/pp
src/c-dsl/pp.tur
defn
c-include
(c-include [header :cstr] :cstr)
emit a #include directive for a local or system header.
Parameters
| header | header filename string (without angle brackets or quotes) |
Returns
"#include \"header\""
Example
(c-include "mylib.h") ; => "#include \"mylib.h\""
Since: P1
defn
c-include-sys
(c-include-sys [header :cstr] :cstr)
emit a #include directive for a system header.
Parameters
| header | system header filename string (without angle brackets) |
Returns
"#include <header>"
Example
(c-include-sys "stdio.h") ; => "#include <stdio.h>"
Since: P1
defn
c-define
(c-define [name :cstr value :cstr] :cstr)
emit a simple #define directive.
Parameters
| name | macro name string | |
| value | replacement string |
Returns
"#define name value"
Example
(c-define "PI" "3.14159f") ; => "#define PI 3.14159f"
Since: P1
defn
c-define-fn
(c-define-fn [signature :cstr body :cstr] :cstr)
emit a function-like #define directive.
Parameters
| signature | macro signature string including params (e.g. "MAX(a,b)") | |
| body | macro body string |
Returns
"#define signature body"
Example
(c-define-fn "MAX(a,b)" "((a)>(b)?(a):(b))") ; => "#define MAX(a,b) ((a)>(b)?(a):(b))"
Since: P1
defn
c-undef
(c-undef [name :cstr] :cstr)
emit a #undef directive.
Parameters
| name | macro name to undefine |
Returns
"#undef name"
Since: P1
defn
c-ifdef
(c-ifdef [guard :cstr body :cstr] :cstr)
emit an #ifdef / #endif guarded block.
Parameters
| guard | preprocessor symbol name string | |
| body | body string to wrap |
Returns
"#ifdef guard\nbody\n#endif"
Example
(c-ifdef "DEBUG" (c-call-stmt "printf" ...))
Since: P1
defn
c-ifndef
(c-ifndef [guard :cstr body :cstr] :cstr)
emit an #ifndef / #endif guarded block.
Parameters
| guard | preprocessor symbol name string | |
| body | body string to wrap |
Returns
"#ifndef guard\nbody\n#endif"
Example
(c-ifndef "MY_HEADER_H" "#define MY_HEADER_H\n...")
Since: P1
defn
c-if-pp
(c-if-pp [cond :cstr body :cstr] :cstr)
emit a #if / #endif guarded block.
Parameters
| cond | preprocessor condition expression string | |
| body | body string to wrap |
Returns
"#if cond\nbody\n#endif"
Since: P1
defn
c-static-assert
(c-static-assert [expr :cstr msg :cstr] :cstr)
emit a static_assert declaration.
Parameters
| expr | compile-time expression string | |
| msg | assertion message string (with quotes if needed) |
Returns
"static_assert(expr, msg);"
Example
(c-static-assert "sizeof(int32_t) == 4" "\"int32_t must be 4 bytes\"")
Since: P1
defn
c-pragma
(c-pragma [args :cstr] :cstr)
emit a #pragma directive.
Parameters
| args | pragma arguments string |
Returns
"#pragma args"
Example
(c-pragma "once") ; => "#pragma once"
Since: P1