Skip to content

Instantly share code, notes, and snippets.

@fowlmouth
Last active December 30, 2015 14:48
Show Gist options
  • Save fowlmouth/aa06e723494708c8d21b to your computer and use it in GitHub Desktop.
Save fowlmouth/aa06e723494708c8d21b to your computer and use it in GitHub Desktop.
import macros, strutils
macro unrolledLoop (name: expr, start, fin: int; body: stmt): stmt {.immediate.} =
result = newStmtList()
for x in start.intval .. fin.intval:
var res = newStmtList()
res.add parseStmt("const $1 = $2".format(name, x))
res.add body.copyNimTree
result.add newBlockStmt(res)
unrolledLoop(i, 0, 10):
var x: array[0 .. i, char]
echo i, ": ", sizeof(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment