c-dsl/fns
src/c-dsl/fns.tur
format a single function parameter declaration.
Example
(c-param "x" ":int") ; => "int32_t x" (c-param "s" ":cstr") ; => "char* s"
defn
c-param
(c-param [name : cstr type : cstr] :)
Since: P1 (return type tightened to CParam in U6)
defn
c-defn
(c-defn [name : cstr ret : cstr body : cstr params : CParam] :)
emit a C function definition.
Parameters
| name | function name string | |
| params | cons list of parameter strings (from c-param) | |
| ret | return type keyword or C type string | |
| body | function body string (use c-stmts for multi-statement bodies) |
Returns
Complete C function definition string.
Example
(c-defn "square"
(cons (c-param "x" ":int") 0)
":int"
(c-return (c-binop "*" "x" "x")))
; => "int32_t square(int32_t x) {\n return (x * x);\n}"
Since: P1 (variadic typed in U6)
defn
c-defn-static
(c-defn-static [name : cstr ret : cstr body : cstr params : CParam] :)
emit a static C function definition.
Parameters
| name | function name string | |
| params | cons list of parameter strings | |
| ret | return type keyword or C type string | |
| body | function body string |
Since: P1
defn
c-defn-inline
(c-defn-inline [name : cstr ret : cstr body : cstr params : CParam] :)
emit a static inline C function definition.
Parameters
| name | function name string | |
| params | cons list of parameter strings | |
| ret | return type keyword or C type string | |
| body | function body string |
Since: P1
defn
c-call
(c-call [fn-name : cstr args : int] :)
emit a C function call expression.
Parameters
| fn-name | function name string | |
| args | cons list of argument expression strings |
Returns
"fn_name(arg1, arg2, ...)"
Example
(c-call "printf" (cons "\"%d\\n\"" (cons "x" 0))) ; => "printf(\"%d\\n\", x)"
Since: P1
defn
c-declare
(c-declare [ret : cstr name : cstr params : CTypeRef] :)
Since: P1 (variadic typed in U6 extension)
defn
c-extern
(c-extern [ret : cstr name : cstr params : CTypeRef] :)
emit an extern declaration for a C function.
Parameters
| ret | return type keyword or C type string | |
| name | function name string | |
| params | cons list of type strings |
Returns
"extern ret name(params);"
Since: P1 (variadic typed in U6 extension)
Internal definitions
__cparam-of__c-defn-impl-- build a function definition with an optional prefix.__c-declare-impl-- emit a forward declaration for a C function.