make typesafeprintf test green

This commit is contained in:
Andreas Rumpf 2018-07-17 20:33:42 +02:00
commit 0cbfd67522

View file

@ -9,7 +9,7 @@ proc printfImpl(formatstr: cstring) {.importc: "printf", varargs.}
iterator tokenize(format: string): char = iterator tokenize(format: string): char =
var i = 0 var i = 0
while true: while i < format.len:
case format[i] case format[i]
of '%': of '%':
case format[i+1] case format[i+1]
@ -42,7 +42,8 @@ macro printf(formatString: string{lit}, args: varargs[typed]): untyped =
$expectedType & ", actual type: " & $actualType $expectedType & ", actual type: " & $actualType
# keep the original callsite, but use cprintf instead # keep the original callsite, but use cprintf instead
result = callsite() result = newCall(bindSym"printfImpl")
result[0] = bindSym"printfImpl" result.add formatString
for a in args: result.add a
printf("test %d\n", 10) printf("test %d\n", 10)