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


Groups > comp.lang.forth > #134660

Re: How does the input stream traditionally work?

From peter <peter.noreply@tin.it>
Newsgroups comp.lang.forth
Subject Re: How does the input stream traditionally work?
Date 2026-03-14 10:12 +0100
Organization A noiseless patient Spider
Message-ID <20260314101239.000020c7@tin.it> (permalink)
References <87bjgre5yy.fsf@nightsong.com>

Show all headers | View raw


On Fri, 13 Mar 2026 15:10:13 -0700
Paul Rubin <no.email@nospam.invalid> wrote:

> They can really be nested, right?  So there's a REPL that can load files
> that can load other files, there is EVALUATE, there are parsing words
> that intercept the input stream from when they are invoked, etc.  So the
> current input source has to at least conceptually be maintained on a
> stack.
> 
> Is there typically an explicit stack for this inside a text interpreter?
> Is it normally just done with recursion and the usual D and R stacks?
> Using stack juggling in the implementations where the person doesn't
> want to use local variables?
> 
> Wondering what is usual in this.

Check out the standard words SAVE-INPUT and RESTORE-INPUT!

Here is Evaluate from ntf64 as an example

: EVALUATE ( addr u -- )
	save-input 2>r 
	(#src) ! (src) !  0 >in ! -1 sid ! 0 blk ! ['] refill-evaluate [refill] !	
	s" Evaluate:" sourcename place
	['] interpret catch
	dup -1 < if .source then
	2r> restore-input drop 
	throw ;

save-input in my implementation only leaves a pointer to a structure,
holding all input state, on the stack and a count of 1. That info is saved on
the return stack. Every input source starts it own interpreter, catches its
result and if thrown prints out where it was in the source.

There are of course many ways of doing this!

BR
Peter 

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


Thread

How does the input stream traditionally work? Paul Rubin <no.email@nospam.invalid> - 2026-03-13 15:10 -0700
  Re: How does the input stream traditionally work? peter <peter.noreply@tin.it> - 2026-03-14 10:12 +0100
    Re: How does the input stream traditionally work? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-03-14 15:09 +0000
      Re: How does the input stream traditionally work? peter <peter.noreply@tin.it> - 2026-03-14 23:30 +0100
        Re: How does the input stream traditionally work? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-03-15 14:02 +0000
          Re: How does the input stream traditionally work? albert@spenarnc.xs4all.nl - 2026-03-15 19:25 +0100
  Re: How does the input stream traditionally work? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-03-14 11:26 +0000
    Re: How does the input stream traditionally work? Paul Rubin <no.email@nospam.invalid> - 2026-03-14 23:34 -0700
      Re: How does the input stream traditionally work? dxf <dxforth@gmail.com> - 2026-03-15 18:26 +1100
        Re: How does the input stream traditionally work? Paul Rubin <no.email@nospam.invalid> - 2026-03-15 13:21 -0700
          Re: How does the input stream traditionally work? dxf <dxforth@gmail.com> - 2026-03-16 10:46 +1100
            Re: How does the input stream traditionally work? Paul Rubin <no.email@nospam.invalid> - 2026-03-15 18:09 -0700
              Re: How does the input stream traditionally work? dxf <dxforth@gmail.com> - 2026-03-16 13:13 +1100
                Re: How does the input stream traditionally work? Paul Rubin <no.email@nospam.invalid> - 2026-03-16 15:14 -0700
                Re: How does the input stream traditionally work? dxf <dxforth@gmail.com> - 2026-03-17 10:37 +1100
                Re: How does the input stream traditionally work? Paul Rubin <no.email@nospam.invalid> - 2026-03-16 17:27 -0700
                Re: How does the input stream traditionally work? dxf <dxforth@gmail.com> - 2026-03-17 12:48 +1100
                Re: How does the input stream traditionally work? albert@spenarnc.xs4all.nl - 2026-03-17 11:16 +0100
                Re: How does the input stream traditionally work? Gerry Jackson <do-not-use@swldwa.uk> - 2026-03-17 11:27 +0000
            Re: How does the input stream traditionally work? dxf <dxforth@gmail.com> - 2026-04-21 18:40 +1000
              Re: How does the input stream traditionally work? albert@spenarnc.xs4all.nl - 2026-04-21 12:39 +0200
              Re: How does the input stream traditionally work? Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-21 19:47 +0200
      Re: How does the input stream traditionally work? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-03-15 16:29 +0000
        Re: How does the input stream traditionally work? albert@spenarnc.xs4all.nl - 2026-03-15 19:48 +0100
  Re: How does the input stream traditionally work? albert@spenarnc.xs4all.nl - 2026-03-14 15:33 +0100

csiph-web