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 ;