.cursor implementation (#12637)
* cursors: first implementation * added currently failing test * .cursor works for doubly linked lists * make -d:useMalloc work again * added code to nil out refs in a destructor * it's now called --gc:arc * renderer.nim: render nkBreakState properly * make simple closure iterators work without leaking
This commit is contained in:
parent
7e689873e2
commit
dfb020b174
12 changed files with 106 additions and 36 deletions
|
|
@ -76,13 +76,16 @@
|
|||
when not defined(nimhygiene):
|
||||
{.pragma: dirty.}
|
||||
|
||||
when not defined(nimHasCursor):
|
||||
{.pragma: cursor.}
|
||||
|
||||
type
|
||||
DoublyLinkedNodeObj*[T] = object ## \
|
||||
## A node a doubly linked list consists of.
|
||||
##
|
||||
## It consists of a `value` field, and pointers to `next` and `prev`.
|
||||
next*: <//>(ref DoublyLinkedNodeObj[T])
|
||||
prev*: ref DoublyLinkedNodeObj[T]
|
||||
prev* {.cursor.}: ref DoublyLinkedNodeObj[T]
|
||||
value*: T
|
||||
DoublyLinkedNode*[T] = ref DoublyLinkedNodeObj[T]
|
||||
|
||||
|
|
@ -100,7 +103,7 @@ type
|
|||
## Use `initSinglyLinkedList proc <#initSinglyLinkedList>`_ to create
|
||||
## a new empty list.
|
||||
head*: <//>(SinglyLinkedNode[T])
|
||||
tail*: SinglyLinkedNode[T]
|
||||
tail* {.cursor.}: SinglyLinkedNode[T]
|
||||
|
||||
DoublyLinkedList*[T] = object ## \
|
||||
## A doubly linked list.
|
||||
|
|
@ -108,7 +111,7 @@ type
|
|||
## Use `initDoublyLinkedList proc <#initDoublyLinkedList>`_ to create
|
||||
## a new empty list.
|
||||
head*: <//>(DoublyLinkedNode[T])
|
||||
tail*: DoublyLinkedNode[T]
|
||||
tail* {.cursor.}: DoublyLinkedNode[T]
|
||||
|
||||
SinglyLinkedRing*[T] = object ## \
|
||||
## A singly linked ring.
|
||||
|
|
@ -116,7 +119,7 @@ type
|
|||
## Use `initSinglyLinkedRing proc <#initSinglyLinkedRing>`_ to create
|
||||
## a new empty ring.
|
||||
head*: <//>(SinglyLinkedNode[T])
|
||||
tail*: SinglyLinkedNode[T]
|
||||
tail* {.cursor.}: SinglyLinkedNode[T]
|
||||
|
||||
DoublyLinkedRing*[T] = object ## \
|
||||
## A doubly linked ring.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue