Deutsch   English   Français   Italiano  
<bd34e3d149f98c0b1fd9be68decee4b7203f5317@i2pn2.org>

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

Path: ...!weretis.net!feeder9.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: dxf <dxforth@gmail.com>
Newsgroups: comp.lang.forth
Subject: Re: Avoid treating the stack as an array [Re: "Back & Forth" is
 back!]
Date: Mon, 30 Sep 2024 16:13:43 +1000
Organization: i2pn2 (i2pn.org)
Message-ID: <bd34e3d149f98c0b1fd9be68decee4b7203f5317@i2pn2.org>
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>
 <2024Sep12.105526@mips.complang.tuwien.ac.at> <87seu01zbj.fsf@nightsong.com>
 <2024Sep16.182651@mips.complang.tuwien.ac.at> <66ea4436$1@news.ausics.net>
 <874j6d1pw8.fsf@nightsong.com> <66ea8196$1@news.ausics.net>
 <87zfo4zps8.fsf@nightsong.com> <66eba538$1@news.ausics.net>
 <87h69zcxlh.fsf@nightsong.com> <66f8d602@news.ausics.net>
 <878qvacnao.fsf@nightsong.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 30 Sep 2024 06:13:45 -0000 (UTC)
Injection-Info: i2pn2.org;
	logging-data="4106035"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="XPw7UV90Iy7EOhY4YuUXhpdoEf5Vz7K+BsxA/Cx8bVc";
User-Agent: Mozilla Thunderbird
In-Reply-To: <878qvacnao.fsf@nightsong.com>
Content-Language: en-GB
X-Spam-Checker-Version: SpamAssassin 4.0.0
Bytes: 3564
Lines: 38

On 30/09/2024 4:44 am, Paul Rubin wrote:
> dxf <dxforth@gmail.com> writes:
>> Perhaps I misunderstood.  So we agree Forth locals are unlikely to
>> ever match C locals for performance?
> 
> This I don't know.  If the issue is parameter passing in registers,
> maybe a fancy enough Forth compiler could do that.

IMO no because C doesn't have the complication of a permanent parameter
stack.  C typically pushes parameters onto the cpu stack which are the
locals, and which the calling function eventually discards.  In forth
locals amount to a 2-step process - pushing parameters onto the data stack,
pulling them off as locals and potentially storing them back.  Contrary
to what one may imagine this is more costly than 'stack juggling' which
has become a pejorative.  Forth has a data stack.  It's left to the user
to optimize it, or to abuse it, as he sees fits.

>> I don't know whether it's possible to make forth code using locals as
>> efficient as forth code using stack operations.  What I do question is
>> the necessity for it and the wisdom of it.
> 
> I think in case of an interpreter, locals might be more efficient, since
> as the thread title says, they treat the stack as an array.  The
> hardware is built to do that, so why not use it?  With an optimizing
> compiler, I think they should usually be equivalent in principle.

I don't understand the reference to 'interpreter'.  Having an interactive
environment with incremental compiler is very convenient but mostly I'm
coding for a target, the same as any C programmer.

> ... 
> Do you still use blocks instead of files nowadays?

For applications I've always used files as that's the norm for CP/M
and MS-DOS.  ANS-style file functions suit this very well.  For forth
source I use files organized as 'screens'.  DX-Forth comes with TED -
a regular text editor that can be used within forth - but personally
I prefer screens.