From 27eb76f5a327959cae84e808699208ba5682e923 Mon Sep 17 00:00:00 2001 From: Philip Zembrod Date: Fri, 1 Jan 2021 15:14:22 +0100 Subject: [PATCH] Initial reference implementation of a tmpheap, using the new ?heapmovetx variable. --- 6502/C64/src/tmpheap.fth | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 6502/C64/src/tmpheap.fth diff --git a/6502/C64/src/tmpheap.fth b/6502/C64/src/tmpheap.fth new file mode 100644 index 0000000..4237e9c --- /dev/null +++ b/6502/C64/src/tmpheap.fth @@ -0,0 +1,59 @@ + +\ This is the reference implementation of tmpheap which allocates +\ the tmpheap on the regular heap and moves definitons prefixed +\ with || or within a ||on to ||off range onto the tmpheap. +\ tmpclear will remove all words on the tmpheap, wheras regular clear +\ will remove all words on tmpheap and heap together. + +\ Before the first use of ||, the tmpheap size in bytes must be +\ set with mk-tmp-heap ( size -- ) + +User tmpheap[ +User tmpheap> +User ]tmpheap + +: reset-tmp-heap ( -- ) + up@ dup ]tmpheap ! dup tmpheap> ! tmpheap[ ! ; + +reset-tmp-heap +' reset-tmp-heap is custom-remove + +: mk-tmp-heap ( size -- ) + heap dup ]tmpheap ! tmpheap> ! hallot heap tmpheap[ ! ; + +: tmp-hallot ( size -- addr ) + tmpheap> @ swap - + dup tmpheap[ @ u< abort" tmp heap overflow" + dup tmpheap> ! ; + +| : tmp-heapmove ( from from size -- from offset ) + dup tmp-hallot swap cmove + tmpheap> @ over - ; + +| : tmp-heapmove1x ( from size -- from offset ) + tmp-heapmove ?heapmovetx off ; + +: || ['] tmp-heapmove1x ?heapmovetx ! ; +: ||on ['] tmp-heapmove ?heapmovetx ! ; +: ||off ?heapmovetx off ; + + +| : remove-tmp-words-in-voc ( voc -- ) + BEGIN dup @ ?dup WHILE ( thread next-in-thread ) + dup tmpheap[ @ ]tmpheap @ uwithin IF ( thread next-in-thread ) + @ ?dup IF ( thread next-next-in-thread ) over ! + ELSE ( thread ) off exit THEN + ELSE ( thread next-in-thread ) nip + THEN + REPEAT drop ; + +| : remove-tmp-words ( -- ) + voc-link BEGIN @ ?dup + WHILE dup 4 - remove-tmp-words-in-voc REPEAT ; + +: tmpclear ( -- ) + remove-tmp-words + \ Uncomment the following line to help determine the ideal tmpheap + \ size for your project. + \ tmpheap> @ tmpheap[ @ - cr u. ." spare tmpheap bytes" + ]tmpheap @ tmpheap> ! last off ;