mirror of
https://github.com/forth-ev/VolksForth.git
synced 2024-11-22 05:32:28 +00:00
Add two linked list utility words that are extracted from cc64's profiler.fth.
This commit is contained in:
parent
44a5e83188
commit
627522012b
14
6502/C64/src/lists.fth
Normal file
14
6502/C64/src/lists.fth
Normal 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 ;
|
||||
|
Loading…
Reference in New Issue
Block a user