Add two linked list utility words that are extracted from cc64's profiler.fth.

This commit is contained in:
Philip Zembrod 2024-05-10 22:58:37 +02:00
parent 44a5e83188
commit 627522012b

14
6502/C64/src/lists.fth Normal file
View File

@ -0,0 +1,14 @@
\ utility words for handling linked lists.
\ The first word of each list node contains the link to the next node.
: end-of-list ( list-node -- last-node )
BEGIN dup @ WHILE @ REPEAT ;
: reverse-list ( list-root-var -- )
dup >r @ 0 ( node[0] 0 )
BEGIN over WHILE ( node[i] node[i-1] )
over @ ( node[i] node[i-1] node[i+1] )
>r over ! r> ( node[i] node[i+1] )
swap REPEAT ( 0 node[n] )
r> ! drop ;