File: decls.nim

package info (click to toggle)
nim 1.4.6%2Breally1.4.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 936,800 kB
  • sloc: sh: 17,201; ansic: 4,767; makefile: 856; python: 407; sql: 298; asm: 141; xml: 13
file content (19 lines) | stat: -rw-r--r-- 529 bytes parent folder | download | duplicates (2)
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, ex) =
  ## Allows a syntax for lvalue reference, exact analog to
  ## `auto& a = ex;` 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 typeof(nil):
    let tmp = addr(ex)
  else:
    let tmp: ptr typ = addr(ex)
  template lhs: untyped = tmp[]