c-dsl/fns
src/c-dsl/fns.tur
defn
c-param
(c-param [name :cstr type :cstr] :cstr)
format a single function parameter declaration.
Parameters
| name | parameter name string | |
| type | Turmeric type keyword or C type string |
Returns
"C-type name"
Example
(c-param "x" ":int") ; => "int32_t x" (c-param "s" ":cstr") ; => "char* s"
Since: P1
defn
c-defn
(c-defn [name :cstr params :int ret :cstr body :cstr] :cstr)
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
defn
c-defn-static
(c-defn-static [name :cstr params :int ret :cstr body :cstr] :cstr)
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 params :int ret :cstr body :cstr] :cstr)
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] :cstr)
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 :int] :cstr)
emit a forward declaration for a C function.
Parameters
| ret | return type keyword or C type string | |
| name | function name string | |
| params | cons list of type strings (types only, no names required) |
Returns
"ret name(params);"
Example
(c-declare ":int" "add" (cons "int32_t" (cons "int32_t" 0))) ; => "int32_t add(int32_t, int32_t);"
Since: P1
defn
c-extern
(c-extern [ret :cstr name :cstr params :int] :cstr)
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
Internal definitions
__c-defn-impl-- build a function definition with an optional prefix.