Quellcode durchsuchen

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.
pull/102/head
Virgil Dupras vor 4 Jahren
Ursprung
Commit
f3c92684a0
3 geänderte Dateien mit 14 neuen und 12 gelöschten Zeilen
  1. +2
    -2
      blk/038
  2. +4
    -3
      forth/core.fs
  3. +8
    -7
      forth/link.fs

+ 2
- 2
blk/038 Datei anzeigen

@@ -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.





+ 4
- 3
forth/core.fs Datei anzeigen

@@ -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 !
;



+ 8
- 7
forth/link.fs Datei anzeigen

@@ -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@ <=


Laden…
Abbrechen
Speichern