Deutsch   English   Français   Italiano  
<66e67077$1@news.ausics.net>

View for Bookmarking (what is this?)
Look up another Usenet article

Date: Sun, 15 Sep 2024 15:28:24 +1000
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
From: dxf <dxforth@gmail.com>
Subject: Re: Avoid treating the stack as an array [Re: "Back & Forth" is
 back!]
Newsgroups: comp.lang.forth
References: <nnd$61e0ad9a$48ed61c2@b4d945e456041481>
 <vasqjd$icjm$1@dont-email.me> <66d26c4b$1@news.ausics.net>
 <vaubf7$tbke$1@dont-email.me> <nnd$04cff141$0193ba04@301336b8dd8ed69a>
 <vbfqnd$v4c4$1@dont-email.me> <nnd$26b4d59b$27bdb181@ce638e508b04426e>
 <87bk0vbvgk.fsf@nightsong.com> <66e0fa58$1@news.ausics.net>
 <66e11d64$1@news.ausics.net> <877cbh4b6z.fsf@nightsong.com>
 <66e2a497$1@news.ausics.net> <2024Sep14.143207@mips.complang.tuwien.ac.at>
Content-Language: en-GB
In-Reply-To: <2024Sep14.143207@mips.complang.tuwien.ac.at>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: news.ausics.net
Message-ID: <66e67077$1@news.ausics.net>
Organization: Ausics - https://newsgroups.ausics.net
Lines: 53
X-Complaints: abuse@ausics.net
Path: ...!weretis.net!feeder9.news.weretis.net!news.bbs.nz!news.ausics.net!not-for-mail
Bytes: 2703

On 14/09/2024 10:32 pm, Anton Ertl wrote:
> dxf <dxforth@gmail.com> writes:
>> On 12/09/2024 4:51 pm, Paul Rubin wrote:
>>> dxf <dxforth@gmail.com> writes:
>> https://pastebin.com/2xcRSbQW
>>
>>>> SWAP averaged 1 in 7 definitions.  OVER 1 in 9.  Is 'stack juggling' a
>>>> problem in forth?  It doesn't appear to be.
> 
> : ARG ( n -- adr len -1 | 0 )
>   >r  0 0  cmdtail  r> 0 ?do
>     2nip
>     bl skip  2dup bl scan
>     rot over - -rot
>   loop 2drop
>   dup if  -1  end  and ;

I believe it's well written and efficient.

: 2nip  2swap 2drop ;
: end  postpone exit postpone then ; immediate 
defer cmdtail ( -- adr len)

: ARG ( n -- adr len -1 | 0 )
   >r  0 0  cmdtail  r> 0 ?do
     2nip
     bl skip  2dup bl scan
     rot over - -rot
   loop 2drop
   dup if  -1  end  and ;

VFX:

( 180 bytes, 44 instructions )
 
> The heavy use of global variables in this program also does not
> support the idea that proper usage of the stacks makes locals
> unnecessary.

I see many small colon definitions and very few variables - global or
local:

integer #TERMS          \ number of terminals in DTA file
integer TERM            \ working terminal#
variable #DIGIT
variable LEN
integer MAXCHR

The first two are necessarily global and would exist regardless.
The remaining three are used by a group of functions with the view of
keeping them simple.  The alternative would be to carry them around as
parameters shuffling them from one function to another.  That seems
worse to me.