-
Notifications
You must be signed in to change notification settings - Fork 2
/
block-015.fth
32 lines (26 loc) · 1.33 KB
/
block-015.fth
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
( Block 15 - Blocks )
find blk-mv loaded?
3 load ( strings )
: blk-fn ( blk--fn ) >t p1 z" block-" s-cpy t> <# # # #s #> s-cat z" .fth" s-cat ;
: blk-read ( blkNum buf bufSize--numRead ) >t >a a@ t@ 0 fill
blk-fn fopen-rb ?dup if >r a@ t@ r@ fread r> fclose else 0 then atdrop ;
: blk-write ( blkNum buf bufSize--numWritten ) >t >a
blk-fn fopen-wb ?dup if >r a@ t@ r@ fwrite r> fclose else 0 then atdrop ;
: blk-rm ( blkNum-- ) blk-fn fdelete ;
: blk-cp ( from to--sz ) >t p2 25000 blk-read t> swap p2 swap blk-write ;
: blk-mv ( from to-- ) over swap blk-cp drop blk-rm ;
: blk-ins ( blkNum stop-- ) 1+ >t >a
begin t@- t@ swap blk-mv t@ a@ > while tdrop a> blk-rm ;
... for comparison ...
find blk-mv loaded?
3 load( strings )
blk-fn( blk--fn )>t p1 z" block-" s-cpy t> <# # # #s #> s-cat z" .fth" s-cat ;
blk-read( blkNum buf bufSize--numRead )>t >a a@ t@ 0 fill
blk-fn fopen-rb ?dupif>r a@ t@ r@ fread r> fclose else 0thenatdrop ;
blk-write( blkNum buf bufSize--numWritten )>t >a
blk-fn fopen-wb ?dupif>r a@ t@ r@ fwrite r> fclose else 0thenatdrop ;
blk-rm( blkNum-- )blk-fn fdelete ;
blk-cp( from to--sz )>t p2 25000 blk-read t> swap p2 swap blk-write ;
blk-mv( from to-- )over swap blk-cp drop blk-rm ;
blk-ins( blkNum stop-- )1+ >t >a
begint@- t@ swap blk-mv t@ a@ >whiletdrop a> blk-rm ;