From 627522012b4280fb1fd9e030a1529e3ece4d7d7a Mon Sep 17 00:00:00 2001 From: Philip Zembrod Date: Fri, 10 May 2024 22:58:37 +0200 Subject: [PATCH] Add two linked list utility words that are extracted from cc64's profiler.fth. --- 6502/C64/src/lists.fth | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 6502/C64/src/lists.fth diff --git a/6502/C64/src/lists.fth b/6502/C64/src/lists.fth new file mode 100644 index 0000000..b9b2686 --- /dev/null +++ b/6502/C64/src/lists.fth @@ -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 ; +