Sujet : Re: Avoid treating the stack as an array [Re: "Back & Forth" is back!]
De : dxforth (at) *nospam* gmail.com (dxf)
Groupes : comp.lang.forthDate : 15. Sep 2024, 06:28:24
Autres entêtes
Organisation : Ausics - https://newsgroups.ausics.net
Message-ID : <66e67077$1@news.ausics.net>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13
User-Agent : Mozilla Thunderbird
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.