diff options
Diffstat (limited to 'lib/core')
-rw-r--r-- | lib/core/locks.nim | 5 | ||||
-rw-r--r-- | lib/core/macros.nim | 35 |
2 files changed, 36 insertions, 4 deletions
diff --git a/lib/core/locks.nim b/lib/core/locks.nim index fbe9c8acf..f9add0037 100644 --- a/lib/core/locks.nim +++ b/lib/core/locks.nim @@ -19,6 +19,8 @@ type {.deprecated: [TLock: Lock, TCond: Cond].} +{.push stackTrace: off.} + proc initLock*(lock: var Lock) {.inline.} = ## Initializes the given lock. initSysLock(lock) @@ -59,9 +61,12 @@ proc signal*(cond: var Cond) {.inline.} = template withLock*(a: Lock, body: untyped) = ## Acquires the given lock, executes the statements in body and ## releases the lock after the statements finish executing. + mixin acquire, release a.acquire() {.locks: [a].}: try: body finally: a.release() + +{.pop.} diff --git a/lib/core/macros.nim b/lib/core/macros.nim index af1e9de28..3473c5d7e 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -317,10 +317,30 @@ proc toStrLit*(n: NimNode): NimNode {.compileTime.} = ## in a string literal node return newStrLitNode(repr(n)) -proc lineinfo*(n: NimNode): string {.magic: "NLineInfo", noSideEffect.} +type + LineInfo* = object + filename*: string + line*,column*: int + +proc `$`*(arg: Lineinfo): string = + result = arg.filename & "(" & $arg.line & ", " & $arg.column & ")" + +#proc lineinfo*(n: NimNode): LineInfo {.magic: "NLineInfo", noSideEffect.} ## returns the position the node appears in the original source file ## in the form filename(line, col) +proc getLine(arg: NimNode): int {.magic: "NLineInfo", noSideEffect.} +proc getColumn(arg: NimNode): int {.magic: "NLineInfo", noSideEffect.} +proc getFile(arg: NimNode): string {.magic: "NLineInfo", noSideEffect.} + +proc lineInfoObj*(n: NimNode): LineInfo {.compileTime.} = + result.filename = n.getFile + result.line = n.getLine + result.column = n.getColumn + +proc lineInfo*(arg: NimNode): string {.compileTime.} = + $arg.lineInfoObj + proc internalParseExpr(s: string): NimNode {. magic: "ParseExprToAst", noSideEffect.} @@ -527,10 +547,17 @@ proc newLit*[N,T](arg: array[N,T]): NimNode {.compileTime.} = result.add newLit(x) proc newLit*[T](arg: seq[T]): NimNode {.compileTime.} = - result = nnkBracket.newTree + var bracket = nnkBracket.newTree for x in arg: - result.add newLit(x) - result = nnkPrefix.newTree(bindSym"@", result) + bracket.add newLit(x) + + result = nnkCall.newTree( + nnkBracketExpr.newTree( + nnkAccQuoted.newTree( bindSym"@" ), + getTypeInst( bindSym"T" ) + ), + bracket + ) proc newLit*(arg: tuple): NimNode {.compileTime.} = result = nnkPar.newTree |