In article ,   
   Ruvim 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,   
   >   
   >This is not allowed, without any options.   
   >   
   >The alloted data space regions shall be contiguous unless "definitions   
   >are added to or removed from the dictionary between allocations"   
   >(3.3.3.2), or the function of `INCLUDED` is performed (11.6.1.1718,   
   >11.6.2.1714). No other conditions are mentioned anywhere.   
      
   That settles it. Note that it applies to interpret mode only,   
   during a definition being permanent is not an issue because it is in a   
   definition.   
   This is a defect ("bug") in S" in ciforth.   
      
   The only solution is to make S" state smart:   
   : S" STATE @ IF POSTPONE " ELSE &" PARSE ; IMMEDIATE   
      
   [ Before it was an alias for the "-as-a-prefix without the   
   prefix flag.   
   : S" POSTPONE " ; IMMEDIATE   
   It sticks to the design rule for ciforth that only denotations,   
   generalisation of numbers, are allowed to be state smart. ]   
      
   >   
   >> 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?   
   >>   
   >> [ It was sufficient to replace S" with S"' in order to make it run:   
   >> : S"' &" PARSE ;   
   >> ]   
   >>   
   >   
   >   
   >--   
   >Ruvim   
   >   
   --   
   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 the   
   hide of the bear until you shot it. Better one bird in the hand than ten in   
   the air. First gain is a cat purring. - the Wise from Antrim -   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|