Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #134980

Re: locals

From Paul Rubin <no.email@nospam.invalid>
Newsgroups comp.lang.forth
Subject Re: locals
Date 2026-04-25 22:40 -0700
Organization A noiseless patient Spider
Message-ID <87340i46vi.fsf@nightsong.com> (permalink)
References (5 earlier) <69db0856$1@news.ausics.net> <871pg66epy.fsf@nightsong.com> <2026Apr25.064712@mips.complang.tuwien.ac.at> <87o6j74l1z.fsf@nightsong.com> <2026Apr25.084323@mips.complang.tuwien.ac.at>

Show all headers | View raw


anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
> And traditionally Forth has been implemented without locals, for the
> same reason: It takes less memory and, for the system implementor,
> less work

A simple implementation of locals doesn't sound like that much work?
Mostly you need a runtime scheme to make sure the locals are cleaned up
in case of exceptions being thrown.  If you're willing to ignore the
standard you don't need to complicate the text interpreter much.  I
remember Mark Wills' TI99/4A Forth simply reserved 4 extra return stack
cells at each level of subroutine call, that you could treat like
registers.  Maybe that burns too much memory for a very small CPU.  I've
imagined some alternate versions of COLON, e.g.
  : foo ( ... ) ;    \ regular colon, no locals
  1: foo ( ... ) ;   \ one local called A
  2: foo (... ) ;    \ two locals, A and B
  ...
  4: foo (... ) ;    \ four locals: A, B, C, D.

> In any case, when it comes to performance measurements on "simple
> interpreters" like the Gforth of 1994, Forth code with locals usually
> turns out to be slower and consume more memory than Forth code using
> (and trying to avoid) stack juggling.

The slowdown doesn't surprise me but it's not that big a deal, compared
to the slowdown of using interpreted Forth instead of assembly language
in the first place.  Words that don't use the locals won't be affected.

> ... looking at the code for Gforth for 3DUP.3 compared to the others,
> Gforth still uses more primitives ...

That's a lot of code in the expansion!  I wonder how it will look in a
simple interpreter.  

> You seem to argue that the random-access aspect of locals provides a
> performance advantage on simple systems, but in most cases, code using
> locals is at a performance disadvantage on such systems

Well, if the slowdown is less than say 2x, I'd say the code cleanup
matters more, due to the traditional 90/10 rule (maybe now 99/1) of
where CPU cycles go.  Code the hot spots for speed and the rest for
convenience.

> (and traditionalists have often used that to argue against locals).

The REAL traditionalists (machine language programmers) can use the same
argument against Forth itself.

> Keeping at least one stack item in a register leads to a smaller and
> faster implementation, and is not more complex than keeping all the
> stack memory in RAM.

That's only with a fancy compiler AND a requirement of the application
code having statically determined stack effects.  Traditional words like
?DUP would confuse this scheme amirite?

> A way to use RAM that is less frowned upon by Forth traditionalists is
> (global) variables.  The fact that the use of global variables is
> frowned upon in the wider programming community for various reasons
> seems to pour oil into the fire of their elitism.

I see what you mean by that.  But, whole-program C compilers do
something like register allocation to re-use those "global" cells when
sets of them won't be needed at the same time.  The Forth approach would
need either a similar fancy compiler, or else require the programmer to
do an error-prone manual memory layout process, or else burn memory
unnecessarily for those cells whose usage doesn't overlap.

Currently I'm thinking about an 8051 part which has 256 bytes of RAM, so
that issue is potentially significant.

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-05 23:25 +0100
  Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-05 23:30 +0100
    Re: Coroutines in Forth Paul Rubin <no.email@nospam.invalid> - 2026-04-05 17:16 -0700
      Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-06 19:58 +0100
        Re: Coroutines in Forth Paul Rubin <no.email@nospam.invalid> - 2026-04-22 11:13 -0700
          Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-22 22:05 +0200
      Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-07 13:23 +0200
  Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-06 13:51 +0200
    Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-06 22:20 +0100
      Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-07 13:35 +0200
        Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-07 20:55 +0100
          Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-08 12:34 +0200
            Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-08 12:32 +0100
          Re: Coroutines in Forth Stephen Pelc <stephen@vfxforth.com> - 2026-04-09 10:12 +0000
        Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-10 19:01 +0200
          Re: Coroutines in Forth dxf <dxforth@gmail.com> - 2026-04-11 11:54 +1000
            Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-05-01 13:07 +0200
          Re: Coroutines in Forth peter <peter.noreply@tin.it> - 2026-04-11 09:49 +0200
          Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-11 22:03 +0200
            Re: Coroutines in Forth dxf <dxforth@gmail.com> - 2026-04-12 12:49 +1000
              Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-12 12:13 +0200
                Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-12 17:39 +0200
                Re: Coroutines in Forth dxf <dxforth@gmail.com> - 2026-04-13 10:54 +1000
                Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-13 19:24 +0200
              Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-12 13:48 +0200
              Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-13 12:13 +0200
              Re: Coroutines in Forth Paul Rubin <no.email@nospam.invalid> - 2026-04-22 11:18 -0700
                Re: Coroutines in Forth dxf <dxforth@gmail.com> - 2026-04-23 11:13 +1000
                Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-23 12:37 +0200
                Re: Coroutines in Forth Paul Rubin <no.email@nospam.invalid> - 2026-04-24 10:36 -0700
                Re: Coroutines in Forth dxf <dxforth@gmail.com> - 2026-04-25 12:12 +1000
                Re: Coroutines in Forth Paul Rubin <no.email@nospam.invalid> - 2026-04-24 23:31 -0700
                Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-25 10:45 +0200
                Re: Coroutines in Forth dxf <dxforth@gmail.com> - 2026-04-25 22:06 +1000
                Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-25 15:11 +0200
                Re: Coroutines in Forth dxf <dxforth@gmail.com> - 2026-04-26 13:33 +1000
                Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-26 16:28 +0200
                Re: Coroutines in Forth Paul Rubin <no.email@nospam.invalid> - 2026-04-25 21:46 -0700
                FP stack depth limitations (was: Coroutines in Forth) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-26 05:55 +0000
                Re: FP stack depth limitations Paul Rubin <no.email@nospam.invalid> - 2026-04-26 00:28 -0700
                Re: FP stack depth limitations dxf <dxforth@gmail.com> - 2026-04-26 19:55 +1000
                Re: FP stack depth limitations (was: Coroutines in Forth) peter <peter.noreply@tin.it> - 2026-04-26 09:57 +0200
                Re: FP stack depth limitations (was: Coroutines in Forth) albert@spenarnc.xs4all.nl - 2026-04-26 14:34 +0200
                Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-25 15:01 +0200
                Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-05-01 13:13 +0200
                Forth, C, hardware, and programming virtues (was: Coroutines in Forth) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-25 05:26 +0000
                Re: Forth, C, hardware, and programming virtues Paul Rubin <no.email@nospam.invalid> - 2026-04-24 23:55 -0700
                Re: Forth, C, hardware, and programming virtues anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-25 08:21 +0000
                Re: Forth, C, hardware, and programming virtues albert@spenarnc.xs4all.nl - 2026-04-25 11:27 +0200
                Re: Forth, C, hardware, and programming virtues Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-25 15:43 +0200
                Re: Forth, C, hardware, and programming virtues anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-25 17:21 +0000
                Re: Forth, C, hardware, and programming virtues dxf <dxforth@gmail.com> - 2026-04-26 15:21 +1000
                Re: Forth, C, hardware, and programming virtues Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-26 15:08 +0200
                Re: Forth, C, hardware, and programming virtues albert@spenarnc.xs4all.nl - 2026-04-26 00:34 +0200
                Re: Forth, C, hardware, and programming virtues Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-26 15:10 +0200
                locals (was: Coroutines in Forth) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-25 04:47 +0000
                Re: locals Paul Rubin <no.email@nospam.invalid> - 2026-04-24 23:21 -0700
                Re: locals anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-25 06:43 +0000
                Re: locals albert@spenarnc.xs4all.nl - 2026-04-25 11:43 +0200
                Re: locals anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-25 10:22 +0000
                Re: locals peter <peter.noreply@tin.it> - 2026-04-25 16:07 +0200
                Re: locals Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-25 17:38 +0200
                Re: locals albert@spenarnc.xs4all.nl - 2026-04-26 01:13 +0200
                Re: locals anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-26 14:03 +0000
                Re: locals peter <peter.noreply@tin.it> - 2026-04-27 09:31 +0200
                Re: locals anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-27 07:53 +0000
                Re: locals peter <peter.noreply@tin.it> - 2026-04-27 11:52 +0200
                Re: locals albert@spenarnc.xs4all.nl - 2026-04-26 00:51 +0200
                Re: locals Paul Rubin <no.email@nospam.invalid> - 2026-04-25 22:40 -0700
                Re: locals albert@spenarnc.xs4all.nl - 2026-04-26 14:55 +0200
                Re: locals anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-26 09:50 +0000
                Re: locals Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-26 16:22 +0200
                Re: locals anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-26 17:04 +0000
                Re: locals dxf <dxforth@gmail.com> - 2026-04-27 11:51 +1000
                Re: locals Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-28 08:21 +0200
                Re: locals Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-28 08:22 +0200
                Re: locals dxf <dxforth@gmail.com> - 2026-04-27 11:12 +1000
                Re: locals Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-28 14:34 +0200
                Re: locals Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-28 14:34 +0200
                Re: locals Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-29 12:44 +0100
                Re: locals Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-29 14:37 +0200
                Re: locals Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-29 14:44 +0200
                Re: locals Paul Rubin <no.email@nospam.invalid> - 2026-05-01 23:50 -0700
                Re: locals anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-05-02 10:34 +0000
                Re: locals Paul Rubin <no.email@nospam.invalid> - 2026-05-01 23:54 -0700
                Re: locals dxf <dxforth@gmail.com> - 2026-05-02 17:36 +1000
                Re: locals Paul Rubin <no.email@nospam.invalid> - 2026-05-02 01:11 -0700
                Re: locals anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-05-02 15:58 +0000
      Re: Coroutines in Forth Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-07 09:28 -0500
        Re: Coroutines in Forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-07 16:12 +0000
          Re: Coroutines in Forth Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-07 18:06 -0500
          Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-08 11:43 +0100
            Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-08 13:16 +0200
              Re: Coroutines in Forth Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-08 11:47 -0500
                Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-08 21:48 +0100
                Re: Coroutines in Forth Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-09 07:06 -0500
                Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-09 16:41 +0200
                Re: Coroutines in Forth Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-09 13:34 -0500
                Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-10 01:23 +0200
                Re: Coroutines in Forth Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-09 21:34 -0500
                Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-09 13:01 +0200
                Re: Coroutines in Forth Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-09 07:01 -0500
                Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-09 16:10 +0200
                Re: Coroutines in Forth Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-09 13:29 -0500
              Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-08 21:26 +0100
          Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-08 14:22 +0200
          Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-28 15:31 +0200
            Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-29 10:49 +0200
              Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-29 15:22 +0200
        Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-08 11:33 +0100
          Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-08 13:07 +0200
            Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-08 22:05 +0100

csiph-web