summary refs log tree commit diff stats
path: root/lib/std/pragmas.nim
blob: 5dce04c11a44b96e20286e3195afdc5592221fae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# see `semLowerLetVarCustomPragma` for compiler support that enables these
# lowerings

template byaddr*(lhs, typ, expr) =
  ## Allows a syntax for lvalue reference, exact analog to
  ## `auto& a = expr;` in C++
  runnableExamples:
    var s = @[10,11,12]
    var a {.byaddr.} = s[0]
    a+=100
    doAssert s == @[110,11,12]
    doAssert a is int
    var b {.byaddr.}: int = s[0]
    doAssert a.addr == b.addr
  when typ is type(nil):
    let tmp = addr(expr)
  else:
    let tmp: ptr typ = addr(expr)
  template lhs: untyped = tmp[]