Re: portable or not? Volatile strings

Liste des Groupes 
Sujet : Re: portable or not? Volatile strings
De : ruvim.pinka (at) *nospam* gmail.com (Ruvim)
Groupes : comp.lang.forth
Date : 12. Aug 2024, 09:05:59
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v9cfp9$364en$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
On 2024-08-11 17:35, albert@spenarnc.xs4all.nl wrote:
I come across a tetris game, and there were bricks defined in
this way:
 : DEF-BRICK     CREATE  4 0 DO
                             ' EXECUTE  0 DO  DUP I CHARS + C@ C,  LOOP DROP
                             REFILL DROP
                         LOOP
                 DOES>   ROT 4 * ROT + 2* CHARS + ;
 DEF-BRICK BRICK1        S"         "
                         S" ######  "
                         S"   ##    "
                         S"         "
 Apparently the data field of bricks are filled in some mysterious
way by DEF-BRICK but that is not the subject.
It does some parsing from the input stream, which is kind of
tricky. As REFILL is not present in lina's core, you must
do "-traditional- WANTED" , but that still is not the issue.
 I made S" " such that it ALLOT's the string at HERE, to
prevent problems with going out of scope, even in interpret mode.
(Only 256,000,000,000 -10 bytes left).
 This doesn't sit well with the definition of BRICK1 ,
that sees its data area grabbed.
You are probably not surprised that tetris doesn't work.
 The question is, is it legal to store these temporary strings
in the dictionary in this way?
Strings that are stored relatively to the HERE address may become invalid after:
     - a definition is created via a defining word;
     - definitions are compiled with : or :NONAME;
     - data space is allocated using ALLOT, `,` (comma),
       `C,` (c-comma), or ALIGN.
— as "3.3.3.6 Other transient regions" <https://forth-standard.org/standard/usage#usage:transient> says.
All affected transition regions shall be listed. If a region is not listed as affected, than it is not affected by allocating data space memory.
The section "11.3.4 Other transient regions" <https://forth-standard.org/standard/file#file:buffers> says:
| The system provides transient buffers for S" and S\" strings.
| These buffers shall be no less than 80 characters in length,
| and there shall be at least two buffers. The system should be
| able to store two strings defined by sequential use of
| S" or S\". RAM-limited systems may have environmental
| restrictions on the number of buffers and their lifetimes.
Since this doesn't say that the buffer my become invalid after some memory allocation, the buffer shall not become invalid after any memory allocation (by default).
In the same time, a Forth system is allowed to limit the buffer lifetime (for example, till the next memory allocation), and document it as an environmental restriction.

 [ It was sufficient to replace S" with S"' in order to make it run:
: S"' &" PARSE ;
]
 Groetjes Albert
--
Ruvim

Date Sujet#  Auteur
12 Aug 24 * Re: portable or not? Volatile strings14Ruvim
12 Aug 24 `* Re: portable or not? Volatile strings13albert
12 Aug 24  +- Re: portable or not? Volatile strings1Ruvim
12 Aug 24  +- Re: portable or not? Volatile strings1Gerry Jackson
13 Aug 24  `* Re: portable or not? Volatile strings10mhx
14 Aug 24   +* Re: portable or not? Volatile strings2dxf
14 Aug 24   i`- Re: portable or not? Volatile strings1mhx
14 Aug 24   `* Re: portable or not? Volatile strings7Anton Ertl
14 Aug 24    `* Re: portable or not? Volatile strings6Gerry Jackson
14 Aug 24     `* Re: portable or not? Volatile strings5mhx
14 Aug 24      `* Re: portable or not? Volatile strings4minforth
15 Aug 24       `* Re: portable or not? Volatile strings3dxf
15 Aug 24        `* Re: portable or not? Volatile strings2albert
16 Aug 24         `- Re: portable or not? Volatile strings1dxf

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal