1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-12-25 04:58:05 +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)
up to x's previous entry.
PREV a -- a Return a wordref's previous entry.
WHLEN a -- n Get word header length from wordref. That is,
name length + 3. a is a wordref
WORD( a -- a Get wordref's beginning addr.

View File

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

View File

@ -39,9 +39,6 @@
1+
;
( Get word addr, starting at name's address )
: '< ' DUP WHLEN - ;
( Relink atom at a, applying offset o with limit ol.
Returns a, appropriately skipped.
)
@ -127,6 +124,10 @@
The output of this word is 3 numbers: top copied address,
top copied CURRENT, and then the beginning of the copied dict
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 -- )
: RLDICT
@ -142,7 +143,7 @@
( H@+2 == offset )
H@ 2+ ! ( )
( We have our offset, now let's copy our memory chunk )
H@ @ DUP WHLEN - ( src )
H@ @ WORD( ( src )
DUP H@ -^ ( src u )
DUP ROT SWAP ( u src u )
H@ 4 + ( u src u dst )
@ -154,9 +155,9 @@
offset by u+4. +4 before, remember, we're using 4 bytes
as variable space. )
4 + ( u+4 )
DUP H@ + ( u we )
DUP CURRENT @ WORD( + ( u we )
DUP .X CRLF
SWAP CURRENT @ + ( we wr )
SWAP CURRENT @ PREV + ( we wr )
DUP .X CRLF
BEGIN ( we wr )
DUP ROT ( wr wr we )
@ -169,7 +170,7 @@
DUP ( wr wr )
PREV ( oldwr newwr )
SWAP ( wr oldwr )
DUP WHLEN - ( wr we )
WORD( ( wr we )
SWAP ( we wr )
( Are we finished? We're finished if wr-4 <= H@ )
DUP 4 - H@ <=