mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-01 17:41:17 +00:00
merged branch overloading-for-macros
This commit is contained in:
@@ -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')``.
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user