c-dsl/typedef
src/c-dsl/typedef.tur
defn
c-field
(c-field [name :cstr type :cstr] :cstr)
format a single struct/union field declaration.
Parameters
| name | field name string | |
| type | Turmeric type keyword or C type string |
Returns
"C-type name;"
Example
(c-field "x" ":int") ; => "int32_t x;" (c-field "name" ":cstr") ; => "char* name;"
Since: P1
defn
c-defstruct
(c-defstruct [name :cstr fields :int] :cstr)
emit a typedef struct definition.
Parameters
| name | struct name string | |
| fields | cons list of field declaration strings (from c-field) |
Returns
"typedef struct {\n field1\n field2\n} name;"
Example
(c-defstruct "Point"
(cons (c-field "x" ":int") (cons (c-field "y" ":int") 0)))
; => "typedef struct {\n int32_t x;\n int32_t y;\n} Point;"
Since: P1
defn
c-defunion
(c-defunion [name :cstr fields :int] :cstr)
emit a typedef union definition.
Parameters
| name | union name string | |
| fields | cons list of field declaration strings (from c-field) |
Returns
"typedef union {\n field1\n ...\n} name;"
Example
(c-defunion "Value"
(cons (c-field "i" ":int") (cons (c-field "f" ":float") 0)))
Since: P1
defn
c-defenum
(c-defenum [name :cstr variants :int] :cstr)
emit a typedef enum definition.
Parameters
| name | enum name string | |
| variants | cons list of variant name strings |
Returns
"typedef enum {\n VAR1,\n VAR2\n} name;"
Example
(c-defenum "Color" (cons "RED" (cons "GREEN" (cons "BLUE" 0))))
; => "typedef enum {\n RED,\n GREEN,\n BLUE\n} Color;"
Since: P1
defn
c-typedef
(c-typedef [type :cstr alias :cstr] :cstr)
emit a typedef alias declaration.
Parameters
| type | original C type string (e.g. "int32_t*" or "void(*)(int32_t)") | |
| alias | new type name string |
Returns
"typedef type alias;"
Example
(c-typedef "int32_t*" "IntPtr") ; => "typedef int32_t* IntPtr;"
Since: P1