No matching definitions.

c-dsl/mem

src/c-dsl/mem.tur
defn

c-addr

(c-addr [expr :cstr] :cstr)

take the address of an expression.

exprlvalue expression string

"(&expr)"

(c-addr "x")  ; => "(&x)"

Since: P1

defn

c-deref

(c-deref [expr :cstr] :cstr)

dereference a pointer expression.

exprpointer expression string

"(*expr)"

(c-deref "ptr")  ; => "(*ptr)"

Since: P1

defn

c-index

(c-index [arr :cstr idx :cstr] :cstr)

index into a pointer or array expression.

arrarray/pointer expression string
idxindex expression string

"arr[idx]"

(c-index "arr" "i")  ; => "arr[i]"

Since: P1

defn

c-cast

(c-cast [expr :cstr type :cstr] :cstr)

emit a C type cast expression.

exprexpression string to cast
typetarget 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

defn

c-malloc

(c-malloc [size :cstr] :cstr)

emit a malloc call.

sizesize expression string

"malloc(size)"

(c-malloc (c-binop "*" "n" (c-sizeof ":int")))
  ; => "malloc((n * sizeof(int32_t)))"

Since: P1

defn

c-calloc

(c-calloc [n :cstr size :cstr] :cstr)

emit a calloc call.

nelement count expression string
sizeelement size expression string

"calloc(n, size)"

Since: P1

defn

c-realloc

(c-realloc [ptr :cstr size :cstr] :cstr)

emit a realloc call.

ptrpointer expression string
sizenew size expression string

"realloc(ptr, size)"

Since: P1

defn

c-free

(c-free [ptr :cstr] :cstr)

emit a free statement.

ptrpointer expression string

"free(ptr);"

(c-free "buf")  ; => "free(buf);"

Since: P1

defn

c-alloca

(c-alloca [size :cstr] :cstr)

emit an alloca call (stack allocation).

sizesize expression string

"alloca(size)"

Since: P1

defn

c-sizeof

(c-sizeof [type :cstr] :cstr)

emit a sizeof expression.

typeTurmeric type keyword or C type string

"sizeof(C-type)"

(c-sizeof ":int")  ; => "sizeof(int32_t)"

Since: P1

defn

c-alignof

(c-alignof [type :cstr] :cstr)

emit an alignof expression.

typeTurmeric type keyword or C type string

"alignof(C-type)"

Since: P1

defn

c-null

(c-null [type :cstr] :cstr)

emit a NULL pointer cast.

typepointer type keyword or C type string

"((C-type)NULL)"

(c-null ":void*")  ; => "((void*)NULL)"

Since: P1

defn

c-ptr-add

(c-ptr-add [ptr :cstr offset :cstr] :cstr)

emit pointer arithmetic addition.

ptrpointer expression string
offsetoffset expression string

"(ptr + offset)"

(c-ptr-add "arr" "i")  ; => "(arr + i)"

Since: P1

defn

c-ptr-sub

(c-ptr-sub [ptr :cstr offset :cstr] :cstr)

emit pointer arithmetic subtraction.

ptrpointer expression string
offsetoffset expression string

"(ptr - offset)"

Since: P1

defn

c-offsetof

(c-offsetof [type :cstr field :cstr] :cstr)

emit an offsetof expression.

typestruct type keyword or name string
fieldfield name string

"offsetof(type, field)"

(c-offsetof "Point" "x")  ; => "offsetof(Point, x)"

Since: P1