c-dsl/mem
c-addr
(c-addr [expr :cstr] :cstr)
take the address of an expression.
| expr | lvalue expression string |
"(&expr)"
(c-addr "x") ; => "(&x)"
Since: P1
c-deref
(c-deref [expr :cstr] :cstr)
dereference a pointer expression.
| expr | pointer expression string |
"(*expr)"
(c-deref "ptr") ; => "(*ptr)"
Since: P1
c-index
(c-index [arr :cstr idx :cstr] :cstr)
index into a pointer or array expression.
| arr | array/pointer expression string | |
| idx | index expression string |
"arr[idx]"
(c-index "arr" "i") ; => "arr[i]"
Since: P1
c-cast
(c-cast [expr :cstr type :cstr] :cstr)
emit a C type cast expression.
| expr | expression string to cast | |
| type | target type keyword or C type string |
"((C-type)expr)"
(c-cast "3.14" ":int") ; => "((int32_t)3.14)" (c-cast "ptr" ":void*") ; => "((void*)ptr)"
Since: P1
c-malloc
(c-malloc [size :cstr] :cstr)
emit a malloc call.
| size | size expression string |
"malloc(size)"
(c-malloc (c-binop "*" "n" (c-sizeof ":int"))) ; => "malloc((n * sizeof(int32_t)))"
Since: P1
c-calloc
(c-calloc [n :cstr size :cstr] :cstr)
emit a calloc call.
| n | element count expression string | |
| size | element size expression string |
"calloc(n, size)"
Since: P1
c-realloc
(c-realloc [ptr :cstr size :cstr] :cstr)
emit a realloc call.
| ptr | pointer expression string | |
| size | new size expression string |
"realloc(ptr, size)"
Since: P1
c-free
(c-free [ptr :cstr] :cstr)
emit a free statement.
| ptr | pointer expression string |
"free(ptr);"
(c-free "buf") ; => "free(buf);"
Since: P1
c-alloca
(c-alloca [size :cstr] :cstr)
emit an alloca call (stack allocation).
| size | size expression string |
"alloca(size)"
Since: P1
c-sizeof
(c-sizeof [type :cstr] :cstr)
emit a sizeof expression.
| type | Turmeric type keyword or C type string |
"sizeof(C-type)"
(c-sizeof ":int") ; => "sizeof(int32_t)"
Since: P1
c-alignof
(c-alignof [type :cstr] :cstr)
emit an alignof expression.
| type | Turmeric type keyword or C type string |
"alignof(C-type)"
Since: P1
c-null
(c-null [type :cstr] :cstr)
emit a NULL pointer cast.
| type | pointer type keyword or C type string |
"((C-type)NULL)"
(c-null ":void*") ; => "((void*)NULL)"
Since: P1
c-ptr-add
(c-ptr-add [ptr :cstr offset :cstr] :cstr)
emit pointer arithmetic addition.
| ptr | pointer expression string | |
| offset | offset expression string |
"(ptr + offset)"
(c-ptr-add "arr" "i") ; => "(arr + i)"
Since: P1
c-ptr-sub
(c-ptr-sub [ptr :cstr offset :cstr] :cstr)
emit pointer arithmetic subtraction.
| ptr | pointer expression string | |
| offset | offset expression string |
"(ptr - offset)"
Since: P1
c-offsetof
(c-offsetof [type :cstr field :cstr] :cstr)
emit an offsetof expression.
| type | struct type keyword or name string | |
| field | field name string |
"offsetof(type, field)"
(c-offsetof "Point" "x") ; => "offsetof(Point, x)"
Since: P1