summary refs log tree commit diff stats
path: root/tests/destructor/trecursive.nim
blob: 55e67f52af9851f74d17640f3dbb1747f15eb50a (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
discard """
   output: '''
test1 OK
'''
"""

import smart_ptr

type
  Node[T] = object
    value: T
    next: SharedPtr[Node[T]]

  ForwardList[T] = object
    first: SharedPtr[Node[T]]
    len: Natural

proc pushFront*[T] (list: var ForwardList[T], val: sink T) =
  var newNode = newSharedPtr(Node[T](value: val))
  var result = false
  while not result:
    var head = list.first
    newNode.get.next = head
    result = list.first.cas(head, newNode)
  list.len.atomicInc()

proc test1() =
  var list: ForwardList[int]
  list.pushFront(1)
  doAssert list.len == 1
  echo "test1 OK"

test1()