Last active
August 29, 2015 14:20
-
-
Save PhilipWitte/3f77d0876ca82d13c6bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type | |
PBCEnv = ref object | |
PBCPattern = int | |
proc pbc_pattern_new(e:PBCEnv, msg, format: cstring, offsets: varargs[int]): int = | |
echo msg, ", ", format | |
for n in offsets: | |
result += n | |
macro wrapped_pbc_pattern_new(e: PBCEnv, msg, format: cstring, offsets: varargs[int]): expr = | |
result = newCall(!"pbc_pattern_new", e, msg, format) | |
for n in offsets.children: | |
result.add(n) | |
echo result.treeRepr | |
template newPattern*(e: PBCEnv, msg, format: string, offsets: varargs[int]): PBCPattern = | |
let result = wrapped_pbc_pattern_new(e, msg, format, offsets) | |
if result == 0: # changed this to 'int' for my test | |
raise newException(AssertionError, "pbc_pattern_new returned NULL") | |
result | |
echo newPattern(PBCEnv(), "msg", "fmt", 1, 2, 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment