blob: 3f64061fbe89bf375bd02d0cb12c8c9fcef7a9b1 (
plain) (
blame)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
discard """
cmd: "nim c --mm:arc --expandArc:foo --hints:off $file"
nimout: '''
--expandArc: foo
var
x
:tmpD
s
:tmpD_1
x = Ref(id: 8)
inc:
:tmpD = `=dup`(x)
:tmpD
inc:
let blitTmp = x
blitTmp
var id_1 = 777
s = RefCustom(id_2: addr(id_1))
inc_1 :
:tmpD_1 = `=dup`(s)
:tmpD_1
inc_1 :
let blitTmp_1 = s
blitTmp_1
-- end of expandArc ------------------------
'''
"""
type
Ref = ref object
id: int
RefCustom = object
id: ptr int
proc inc(x: sink Ref) =
inc x.id
proc inc(x: sink RefCustom) =
inc x.id[]
proc `=dup`(x: var RefCustom): RefCustom =
result.id = x.id
proc foo =
var x = Ref(id: 8)
inc(x)
inc(x)
var id = 777
var s = RefCustom(id: addr id)
inc s
inc s
foo()
proc foo2 =
var x = Ref(id: 8)
inc(x)
doAssert x.id == 9
inc(x)
doAssert x.id == 10
var id = 777
var s = RefCustom(id: addr id)
inc s
doAssert s.id[] == 778
inc s
doAssert s.id[] == 779
foo2()
|