merged branch overloading-for-macros

This commit is contained in:
Zahary Karadjov
2012-03-19 12:06:38 +02:00
39 changed files with 366 additions and 218 deletions

View File

@@ -50,7 +50,7 @@ proc filter*[T](seq1: seq[T], pred: proc(item: T): bool): seq[T] =
## Returns all items in a sequence that fulfilled the predicate.
accumulateResult(filter(seq1, pred))
template filterIt*(seq1, pred: expr): expr =
template filterIt*(seq1, pred: expr): expr {.immediate.} =
## Finds a specific item in a sequence as long as the
## predicate returns true. The predicate needs to be an expression
## containing ``it``: ``filterIt("abcxyz", it == 'x')``.

View File

@@ -17,15 +17,15 @@ type
proc `==` *(a, b: TColor): bool {.borrow.}
## compares two colors.
template extract(a: TColor, r, g, b: expr) =
template extract(a: TColor, r, g, b: expr) {.immediate.}=
var r = a.int shr 16 and 0xff
var g = a.int shr 8 and 0xff
var b = a.int and 0xff
template rawRGB(r, g, b: expr): expr =
template rawRGB(r, g, b: int): expr =
TColor(r shl 16 or g shl 8 or b)
template colorOp(op: expr) =
template colorOp(op: expr) {.immediate.} =
extract(a, ar, ag, ab)
extract(b, br, bg, bb)
result = rawRGB(op(ar, br), op(ag, bg), op(ab, bb))

View File

@@ -242,12 +242,12 @@ proc UnixToNativePath*(path: string): string {.
inc(i)
when defined(windows):
template wrapUnary(varname, winApiProc, arg: expr) =
template wrapUnary(varname, winApiProc, arg: expr) {.immediate.} =
var tmp = allocWideCString(arg)
var varname = winApiProc(tmp)
dealloc tmp
template wrapBinary(varname, winApiProc, arg, arg2: expr) =
template wrapBinary(varname, winApiProc, arg, arg2: expr) {.immediate.} =
var tmp2 = allocWideCString(arg)
var varname = winApiProc(tmp2, arg2)
dealloc tmp2