c-dsl/types
src/c-dsl/types.tur
defn
c-type
(c-type [t :cstr] :cstr)
map a Turmeric type keyword string to a C99 type string.
Parameters
| t | type keyword (e.g. ":int", ":float", ":cstr", ":void") |
Returns
The corresponding C type string. Unknown keywords with a leading colon have the colon stripped; others are returned as-is.
Example
(c-type ":int") ; => "int32_t" (c-type ":float") ; => "float" (c-type ":cstr") ; => "char*" (c-type ":void") ; => "void"
Since: P1
defn
c-ptr-type
(c-ptr-type [inner :cstr] :cstr)
create a C pointer type string.
Parameters
| inner | Turmeric type keyword or bare C type string |
Returns
"<C-type>*"
Example
(c-ptr-type ":int") ; => "int32_t*" (c-ptr-type ":void") ; => "void*"
Since: P1
defn
c-arr-type
(c-arr-type [inner :cstr n :int] :cstr)
create a C fixed-size array type fragment.
Parameters
| inner | element type keyword or bare C type string | |
| n | array length |
Returns
"<C-type>[n]"
Example
(c-arr-type ":uint8" 16) ; => "uint8_t[16]"
Since: P1
defn
c-fn-type
(c-fn-type [param-types :int ret :cstr] :cstr)
create a C function-pointer type string.
Parameters
| param-types | Vec[cstr] of type keyword or C type strings, built with | |
| (vec-of ...). (Was a cons list prior to v0.2.0.) | ||
| ret | return type keyword or C type string |
Returns
"<ret>(*)(p1, p2, ...)"
Example
(c-fn-type (vec-of ":int" ":int") ":int") ; => "int32_t(*)(int32_t, int32_t)"
Since: P1
defn
c-const-type
(c-const-type [t :cstr] :cstr)
prepend "const " to a type string.
Parameters
| t | C type string (already mapped via c-type if needed) |
Returns
"const <t>"
Example
(c-const-type "char*") ; => "const char*"
Since: P1
defn
c-volatile-type
(c-volatile-type [t :cstr] :cstr)
prepend "volatile " to a type string.
Parameters
| t | C type string |
Returns
"volatile <t>"
Since: P1