decls.nim 529 B

1234567891011121314151617181920
  1. # see `semLowerLetVarCustomPragma` for compiler support that enables these
  2. # lowerings
  3. template byaddr*(lhs, typ, ex) =
  4. ## Allows a syntax for lvalue reference, exact analog to
  5. ## `auto& a = ex;` in C++
  6. runnableExamples:
  7. var s = @[10,11,12]
  8. var a {.byaddr.} = s[0]
  9. a+=100
  10. doAssert s == @[110,11,12]
  11. doAssert a is int
  12. var b {.byaddr.}: int = s[0]
  13. doAssert a.addr == b.addr
  14. when typ is typeof(nil):
  15. let tmp = addr(ex)
  16. else:
  17. let tmp: ptr typ = addr(ex)
  18. template lhs: untyped = tmp[]