Sujet : Re: portable or not? Volatile strings
De : albert (at) *nospam* spenarnc.xs4all.nl
Groupes : comp.lang.forthDate : 12. Aug 2024, 10:01:48
Autres entêtes
Organisation : KPN B.V.
Message-ID : <nnd$05375ad3$6e018fac@ef3f66902c87c893>
References : 1 2
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <
v9cfp9$364en$1@dont-email.me>,
Ruvim <
ruvim.pinka@gmail.com> wrote:
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"
Not relevant. My "transient" region is permanent. That I have
permission to invalidate doesn't affect me.
<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.
My regions are not affected. So again this is not relevant.
>
>
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.
A permanent buffer can count as transient.
>
>
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).
That is putting restriction to my buffer.
>
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.
Lots of talk of whether the buffers become invalid.
My buffers never become invalid. That is not the point.
The standard talks about transient region. My regions are permanent
and there are other ways to handle S" , say by using ALLOCATE.
To call a region transient and then restrict how transient they are,
make a region not really temporary. So in this respect I am in the clear.
Note that as S" is in a definition, the string is bound to be permanent.
So I think the program is not portable, because what I do is perfectly
legal.
I can't make out what you think.
>
[ It was sufficient to replace S" with S"' in order to make it run:
: S"' &" PARSE ;
]
Okay let's say it out loud. Classic Forth is not fit for handling strings.
A denotation that generates a constant string "blablabla" that has
a status as a number is long overdue.
The mindset of formulating standards is so 70's.
>
Groetjes Albert
--
Ruvim
>
Groetjes Albert-- Don't praise the day before the evening. One swallow doesn't make spring.You must not say "hey" before you have crossed the bridge. Don't sell thehide of the bear until you shot it. Better one bird in the hand than ten inthe air. First gain is a cat purring. - the Wise from Antrim -