1
0
mirror of https://github.com/hsoft/collapseos.git synced 2025-03-31 09:48:48 +11:00

link: improve reliability by never relinking last word

It's not possible to reliably determine its end and with some memory
initialization scenarios, it makes RLDICT fail.
This commit is contained in:
Virgil Dupras 2020-04-18 16:51:48 -04:00
parent 052c744000
commit f3c92684a0
3 changed files with 14 additions and 12 deletions

View File

@ -2,8 +2,8 @@
FORGET x -- Rewind the dictionary (both CURRENT and HERE) FORGET x -- Rewind the dictionary (both CURRENT and HERE)
up to x's previous entry. up to x's previous entry.
PREV a -- a Return a wordref's previous entry. PREV a -- a Return a wordref's previous entry.
WHLEN a -- n Get word header length from wordref. That is, WORD( a -- a Get wordref's beginning addr.
name length + 3. a is a wordref

View File

@ -154,17 +154,18 @@
- ( a-o ) - ( a-o )
; ;
: WHLEN : WORD(
1- C@ ( name len field ) DUP 1- C@ ( name len field )
127 AND ( 0x7f. remove IMMEDIATE flag ) 127 AND ( 0x7f. remove IMMEDIATE flag )
3 + ( fixed header len ) 3 + ( fixed header len )
-
; ;
: FORGET : FORGET
' DUP ( w w ) ' DUP ( w w )
( HERE must be at the end of prev's word, that is, at the ( HERE must be at the end of prev's word, that is, at the
beginning of w. ) beginning of w. )
DUP WHLEN - HERE ! ( w ) WORD( HERE ! ( w )
PREV CURRENT ! PREV CURRENT !
; ;

View File

@ -39,9 +39,6 @@
1+ 1+
; ;
( Get word addr, starting at name's address )
: '< ' DUP WHLEN - ;
( Relink atom at a, applying offset o with limit ol. ( Relink atom at a, applying offset o with limit ol.
Returns a, appropriately skipped. Returns a, appropriately skipped.
) )
@ -127,6 +124,10 @@
The output of this word is 3 numbers: top copied address, The output of this word is 3 numbers: top copied address,
top copied CURRENT, and then the beginning of the copied dict top copied CURRENT, and then the beginning of the copied dict
at the end to indicate that we're finished processing. at the end to indicate that we're finished processing.
Note that the last word is always skipped because it's not
possible to reliably detect its end. If you need that last
word, define a dummy word before calling RLDICT.
) )
( target -- ) ( target -- )
: RLDICT : RLDICT
@ -142,7 +143,7 @@
( H@+2 == offset ) ( H@+2 == offset )
H@ 2+ ! ( ) H@ 2+ ! ( )
( We have our offset, now let's copy our memory chunk ) ( We have our offset, now let's copy our memory chunk )
H@ @ DUP WHLEN - ( src ) H@ @ WORD( ( src )
DUP H@ -^ ( src u ) DUP H@ -^ ( src u )
DUP ROT SWAP ( u src u ) DUP ROT SWAP ( u src u )
H@ 4 + ( u src u dst ) H@ 4 + ( u src u dst )
@ -154,9 +155,9 @@
offset by u+4. +4 before, remember, we're using 4 bytes offset by u+4. +4 before, remember, we're using 4 bytes
as variable space. ) as variable space. )
4 + ( u+4 ) 4 + ( u+4 )
DUP H@ + ( u we ) DUP CURRENT @ WORD( + ( u we )
DUP .X CRLF DUP .X CRLF
SWAP CURRENT @ + ( we wr ) SWAP CURRENT @ PREV + ( we wr )
DUP .X CRLF DUP .X CRLF
BEGIN ( we wr ) BEGIN ( we wr )
DUP ROT ( wr wr we ) DUP ROT ( wr wr we )
@ -169,7 +170,7 @@
DUP ( wr wr ) DUP ( wr wr )
PREV ( oldwr newwr ) PREV ( oldwr newwr )
SWAP ( wr oldwr ) SWAP ( wr oldwr )
DUP WHLEN - ( wr we ) WORD( ( wr we )
SWAP ( we wr ) SWAP ( we wr )
( Are we finished? We're finished if wr-4 <= H@ ) ( Are we finished? We're finished if wr-4 <= H@ )
DUP 4 - H@ <= DUP 4 - H@ <=