No matching definitions.

c-dsl/core

src/c-dsl/core.tur
defn

c-let1

(c-let1 [name :cstr type :cstr init :cstr] :cstr)

declare a single initialized local variable.

nameC identifier string
typeTurmeric type keyword or C type string
initinitializer expression string

"type name = init;"

(c-let1 "x" ":int" "42")  ; => "int32_t x = 42;"

Since: P1

defn

c-let1-uninit

(c-let1-uninit [name :cstr type :cstr] :cstr)

declare a single uninitialized local variable.

nameC identifier string
typeTurmeric type keyword or C type string

"type name;"

(c-let1-uninit "ptr" ":[:int]")  ; => "int32_t* ptr;"

Since: P1

defn

c-const1

(c-const1 [name :cstr type :cstr init :cstr] :cstr)

declare a single const variable.

nameC identifier string
typeTurmeric type keyword or C type string
initinitializer expression string

"const type name = init;"

(c-const1 "MAX_SIZE" ":int" "100")  ; => "const int32_t MAX_SIZE = 100;"

Since: P1

defn

c-set!

(c-set! [lhs :cstr rhs :cstr] :cstr)

emit an assignment statement.

lhsleft-hand side expression string
rhsright-hand side expression string

"lhs = rhs;"

(c-set! "x" "42")      ; => "x = 42;"
  (c-set! "arr[i]" "v")  ; => "arr[i] = v;"

Since: P1

defn

c-return

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

emit a return statement.

exprexpression to return

"return expr;"

(c-return "x + 1")  ; => "return x + 1;"

Since: P1

defn

c-return-void

(c-return-void :cstr)

emit a bare "return;" statement.

"return;"

Since: P1

defn

c-break

(c-break :cstr)

emit a break statement.

"break;"

Since: P1

defn

c-continue

(c-continue :cstr)

emit a continue statement.

"continue;"

Since: P1

defn

c-inc!

(c-inc! [var :cstr] :cstr)

emit a post-increment statement.

varvariable name string

"var++;"

(c-inc! "i")  ; => "i++;"

Since: P1

defn

c-dec!

(c-dec! [var :cstr] :cstr)

emit a post-decrement statement.

varvariable name string

"var--;"

Since: P1

defn

c-if

(c-if [cond-expr :cstr then-body :cstr else-body :cstr] :cstr)

emit an if/else statement.

cond-exprcondition expression string
then-bodybody string for the true branch (one or more statements)
else-bodybody string for the false branch (use "" to omit)

"if (cond) {\n then\n} else {\n else\n}" or without else branch.

(c-if "x > 0" (c-set! "y" "1") (c-set! "y" "-1"))
  ; => "if (x > 0) {\n    y = 1;\n} else {\n    y = -1;\n}"

Since: P1

defn

c-if-only

(c-if-only [cond-expr :cstr then-body :cstr] :cstr)

emit an if statement without an else branch.

cond-exprcondition expression string
then-bodybody string for the true branch

"if (cond) {\n body\n}"

Since: P1

defn

c-while

(c-while [cond-expr :cstr body :cstr] :cstr)

emit a while loop.

cond-exprcondition expression string
bodybody string (one or more statements)

"while (cond) {\n body\n}"

(c-while "i < len" (c-inc! "i"))

Since: P1

defn

c-do-while

(c-do-while [body :cstr cond-expr :cstr] :cstr)

emit a do-while loop.

bodybody string
cond-exprcondition expression string

"do {\n body\n} while (cond);"

Since: P1

defn

c-for1

(c-for1 [var :cstr type :cstr init :cstr cond :cstr step :cstr body :cstr] :cstr)

emit a for loop with a typed loop variable declaration.

varloop variable name
typetype keyword for the loop variable
initinitial value expression string
condcondition expression string
stepstep expression string (e.g. "i++" or "i += 2")
bodybody string

"for (type var = init; cond; step) {\n body\n}"

(c-for1 "i" ":int" "0" "i < 10" "i++" (c-call "printf" ...))

Since: P1

defn

c-for-raw

(c-for-raw [init :cstr cond :cstr step :cstr body :cstr] :cstr)

emit a for loop with a raw (pre-formatted) init clause.

initfull init clause string (e.g. "int32_t i = 0, j = n - 1")
condcondition expression string
stepstep expression string
bodybody string

"for (init; cond; step) {\n body\n}"

Since: P1

defn

c-case

(c-case [val :cstr body :cstr] :cstr)

emit a single switch case fragment.

valcase value string (e.g. "1" or "RED")
bodybody statements string

"case val:\n body"

(c-case "1" (c-break))  ; => "case 1:\n    break;"

Since: P1

defn

c-default-case

(c-default-case [body :cstr] :cstr)

emit the default switch case.

bodybody statements string

"default:\n body"

Since: P1

defn

c-switch

(c-switch [expr :cstr cases :int] :cstr)

emit a switch statement.

exprexpression to switch on
casescons list of case fragment strings (from c-case / c-default-case)

"switch (expr) {\ncases\n}"

(c-switch "x" (cons (c-case "0" "break;") (cons (c-default-case "break;") 0)))

Since: P1

defn

c-label

(c-label [name :cstr] :cstr)

emit a C label.

namelabel identifier string

"name:"

Since: P1

defn

c-goto

(c-goto [name :cstr] :cstr)

emit a goto statement.

nametarget label string

"goto name;"

Since: P1

defn

c-binop

(c-binop [op :cstr a :cstr b :cstr] :cstr)

emit a binary expression wrapped in parentheses.

opoperator string (e.g. "+", "&&", "==")
aleft operand string
bright operand string

"(a op b)"

(c-binop "+" "a" "b")   ; => "(a + b)"
  (c-binop "<" "i" "10")  ; => "(i < 10)"

Since: P1

defn

c-unop

(c-unop [op :cstr expr :cstr] :cstr)

emit a prefix unary expression.

opoperator string (e.g. "!", "-", "~")
exproperand string

"(op expr)"

(c-unop "!" "flag")  ; => "(!flag)"

Since: P1

defn

c-ternary

(c-ternary [cond-expr :cstr then-expr :cstr else-expr :cstr] :cstr)

emit a ternary conditional expression.

cond-exprcondition expression string
then-exprvalue when true
else-exprvalue when false

"(cond ? then : else)"

(c-ternary "x > 0" "1" "-1")  ; => "(x > 0 ? 1 : -1)"

Since: P1