summary refs log tree commit diff stats
path: root/tests/osproc
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2021-11-24 15:49:32 +0100
committerGitHub <noreply@github.com>2021-11-24 15:49:32 +0100
commita0073d2d4c18f030eccef98a130f7f1f2ad9d67a (patch)
treee878dc9af846deca505d30a67ca5858d8a773dd6 /tests/osproc
parentc7c6b13a325958c6b55cbec2eb812eb06074101b (diff)
downloadNim-a0073d2d4c18f030eccef98a130f7f1f2ad9d67a.tar.gz
renamed 'gc' switch to 'mm'; [backport:1.6] (#19187)
* renamed 'gc' switch to 'mm'; [backport:1.6]
* better docs
Diffstat (limited to 'tests/osproc')
0 files changed, 0 insertions, 0 deletions
d=fa06203e90d9bb9211d0b6b9726fc9f2c5dc80ad'>^
2bd1aa186 ^
913bc9596 ^
2bd1aa186 ^


913bc9596 ^
2bd1aa186 ^











1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
                                                             
 
                 




                                                                     



                                                                              
                   
                         
                           


                              
                                











                                                                       
## This module implements syntax sugar for some declarations.

import std/macros

macro byaddr*(sect) =
  ## Allows a syntax for l-value references, being an exact analog to
  ## `auto& a = ex;` in C++.
  ## 
  ## .. warning:: This makes use of 2 experimental features, namely nullary
  ##   templates instantiated as symbols and variable macro pragmas.
  ##   For this reason, its behavior is not stable. The current implementation
  ##   allows redefinition, but this is not an intended consequence.
  runnableExamples:
    var s = @[10, 11, 12]
    var a {.byaddr.} = s[0]
    a += 100
    assert s == @[110, 11, 12]
    assert a is int
    var b {.byaddr.}: int = s[0]
    assert a.addr == b.addr
  expectLen sect, 1
  let def = sect[0]
  let
    lhs = def[0]
    typ = def[1]
    ex = def[2]
    addrTyp = if typ.kind == nnkEmpty: typ else: newTree(nnkPtrTy, typ)
  result = quote do:
    let tmp: `addrTyp` = addr(`ex`)
    template `lhs`: untyped = tmp[]
  result.copyLineInfo(def)