mirror of
https://github.com/forth-ev/VolksForth.git
synced 2024-11-26 02:49:17 +00:00
Initial reference implementation of a tmpheap, using the new ?heapmovetx variable.
This commit is contained in:
parent
8f2f97e1f2
commit
27eb76f5a3
59
6502/C64/src/tmpheap.fth
Normal file
59
6502/C64/src/tmpheap.fth
Normal file
@ -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 ;
|
Loading…
Reference in New Issue
Block a user