Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #43754
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Question about checking the stack |
| Date | 2015-11-25 12:53 +0000 |
| Organization | Institut fuer Computersprachen, Technische Universitaet Wien |
| Message-ID | <2015Nov25.135333@mips.complang.tuwien.ac.at> (permalink) |
| References | <b2176cc4-7ef3-4ba8-9270-6fed74cf429f@googlegroups.com> |
Chris Curl <ccurl609@gmail.com> writes:
>For you guys who have implemented your own Forths ... when do you check the stack?
>
>Playing with it in SP-Forth (with the stack empty) ... I see this behavior:
>
>"." gives me ONE number followed by "-4 Stack underflow."
>". ." gives me ONE number and the -4 error.
>": sss . . . ; sss" gives me THREE numbers and the -4 error.
>": xxx sss sss ; xxx" gives me SIX numbers and the -4 error.
>Lastly, "sss sss" gives me THREE numbers and the -4 error.
>
>So it looks like it doesn't check the stack at all during execution; rather, it checks after executing each word during the interpretation loop.
>
>Is that pretty standard behavior?
Many systems do it this way, yes. However, Gforth's debugging engine
"gforth" reports the error earlier (on nice operating systems):
.
:1: Stack underflow
>>>.<<<
Backtrace:
$7FFFF69F1708 dup
$7FFFF69F2E30 s>d
. .
:2: Stack underflow
>>>.<<< .
Backtrace:
$7FFFF69F1708 dup
$7FFFF69F2E30 s>d
: sss . . . ; sss
:3: Stack underflow
: sss . . . ; >>>sss<<<
Backtrace:
$7FFFF69F1708 dup
$7FFFF69F2E30 s>d
$7FFFF6A44308 .
: xxx sss sss ; xxx
:4: Stack underflow
: xxx sss sss ; >>>xxx<<<
Backtrace:
$7FFFF69F1708 dup
$7FFFF69F2E30 s>d
$7FFFF6A44308 .
$7FFFF6A44368 sss
sss sss
:5: Stack underflow
>>>sss<<< sss
Backtrace:
$7FFFF69F1708 dup
$7FFFF69F2E30 s>d
$7FFFF6A44308 .
As you can see the error is always caught in the DUP called by S>D
called by ".".
How is that implemented? There is an unmapped page where the memory
location for the stack item below the bottom of the stack would lie,
so accessing that memory location causes a segmentation violation in
the OS, and when the access is to a place close to the bottom of the
data stack, Gforth translates this into a "-4 throw" (stack
underflow). So this does not cost any checks at run-time.
There is a cost, though: For accurate error reporting the debugging
engine always stores the IP and the RP in memory. Also, the debugging
engine keeps all stack items in memory (no stack caching in
registers), and does not use static superinstructions: Stack caching
occasionally loads memory cells below the stack bottom into a register
(when the stack is empty), and for static superinstructions there is
only one IP to report for a sequence of primitives.
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2015: http://www.rigwit.co.uk/EuroForth2015/
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Question about checking the stack Chris Curl <ccurl609@gmail.com> - 2015-11-24 22:31 -0800
Re: Question about checking the stack Lars Brinkhoff <lars.spam@nocrew.org> - 2015-11-25 07:46 +0100
Re: Question about checking the stack Chris Curl <ccurl609@gmail.com> - 2015-11-24 23:09 -0800
Re: Question about checking the stack Ron Aaron <rambamist@gmail.com> - 2015-11-25 09:16 +0200
Re: Question about checking the stack Paul Rubin <no.email@nospam.invalid> - 2015-11-24 23:19 -0800
Re: Question about checking the stack "Elizabeth D. Rather" <erather@forth.com> - 2015-11-24 22:05 -1000
Re: Question about checking the stack Paul Rubin <no.email@nospam.invalid> - 2015-11-25 13:17 -0800
Re: Question about checking the stack "Elizabeth D. Rather" <erather@forth.com> - 2015-11-25 13:58 -1000
Re: Question about checking the stack Paul Rubin <no.email@nospam.invalid> - 2015-11-25 18:00 -0800
Re: Question about checking the stack "Elizabeth D. Rather" <erather@forth.com> - 2015-11-25 17:44 -1000
Re: Question about checking the stack Paul Rubin <no.email@nospam.invalid> - 2015-11-25 23:05 -0800
Re: Question about checking the stack "Elizabeth D. Rather" <erather@forth.com> - 2015-11-25 21:38 -1000
Re: Question about checking the stack Ron Aaron <rambamist@gmail.com> - 2015-11-26 09:49 +0200
Re: Question about checking the stack "Elizabeth D. Rather" <erather@forth.com> - 2015-11-25 22:42 -1000
Re: Question about checking the stack anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-11-26 14:51 +0000
Re: Question about checking the stack Paul Rubin <no.email@nospam.invalid> - 2015-11-30 13:00 -0800
Re: Question about checking the stack hughaguilar96@gmail.com - 2015-11-30 21:54 -0800
Re: Question about checking the stack Julian Fondren <julian.fondren@gmail.com> - 2015-12-01 04:24 -0800
Re: Question about checking the stack Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-12-01 05:07 -0800
Re: Question about checking the stack Julian Fondren <julian.fondren@gmail.com> - 2015-12-01 06:02 -0800
Re: Question about checking the stack "Elizabeth D. Rather" <erather@forth.com> - 2015-12-01 19:30 -1000
Re: Question about checking the stack Albert van der Horst <albert@spenarnc.xs4all.nl> - 2015-12-01 14:47 +0000
Re: Question about checking the stack Chris Curl <ccurl609@gmail.com> - 2015-12-01 11:56 -0800
Re: Question about checking the stack Alfred Singlestone <vitonis@gmail.com> - 2015-12-03 05:48 -0800
Re: Question about checking the stack "Elizabeth D. Rather" <erather@forth.com> - 2015-12-03 09:24 -1000
Re: Question about checking the stack Chris Curl <ccurl609@gmail.com> - 2015-12-03 21:10 -0800
Re: Question about checking the stack "Elizabeth D. Rather" <erather@forth.com> - 2015-12-03 20:52 -1000
Re: Question about checking the stack Chris Curl <ccurl609@gmail.com> - 2015-12-04 06:08 -0800
Re: Question about checking the stack Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2015-12-01 20:32 +0000
Re: Question about checking the stack "Elizabeth D. Rather" <erather@forth.com> - 2015-12-01 19:32 -1000
Re: Question about checking the stack Lars Brinkhoff <lars.spam@nocrew.org> - 2015-12-01 08:18 +0100
Re: Question about checking the stack Alfred Singlestone <vitonis@gmail.com> - 2015-11-27 06:25 -0800
Re: Question about checking the stack Ron Aaron <rambamist@gmail.com> - 2015-11-28 17:55 +0200
Re: Question about checking the stack mhx@iae.nl - 2015-11-28 08:24 -0800
Re: Question about checking the stack Ron Aaron <rambamist@gmail.com> - 2015-11-28 20:54 +0200
Re: Question about checking the stack "Elizabeth D. Rather" <erather@forth.com> - 2015-11-28 11:32 -1000
Re: Question about checking the stack Paul Rubin <no.email@nospam.invalid> - 2015-11-28 19:17 -0800
Re: Question about checking the stack Ron Aaron <rambamist@gmail.com> - 2015-11-29 07:30 +0200
Re: Question about checking the stack Alfred Singlestone <vitonis@gmail.com> - 2015-11-29 09:41 -0800
Re: Question about checking the stack minforth@arcor.de - 2015-11-30 01:48 -0800
Re: Question about checking the stack "Elizabeth D. Rather" <erather@forth.com> - 2015-11-30 08:03 -1000
Re: Question about checking the stack hughaguilar96@gmail.com - 2015-11-28 19:09 -0800
Re: Question about checking the stack Paul Rubin <no.email@nospam.invalid> - 2015-11-26 00:03 -0800
Re: Question about checking the stack "Elizabeth D. Rather" <erather@forth.com> - 2015-11-25 22:49 -1000
Re: Question about checking the stack hughaguilar96@gmail.com - 2015-11-26 10:59 -0800
Re: Question about checking the stack franck.bensusan@gmail.com - 2015-11-25 21:03 -0800
Re: Question about checking the stack Alfred Singlestone <vitonis@gmail.com> - 2015-11-27 06:14 -0800
Re: Question about checking the stack "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-11-25 04:54 -0500
Re: Question about checking the stack François <francois.ganza@wanadoo.fr> - 2015-11-25 03:09 -0800
Re: Question about checking the stack anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-11-25 12:53 +0000
Re: Question about checking the stack Paul Rubin <no.email@nospam.invalid> - 2015-11-25 09:02 -0800
Re: Question about checking the stack Bernd Paysan <bernd.paysan@gmx.de> - 2015-11-25 18:53 +0100
Re: Question about checking the stack Paul Rubin <no.email@nospam.invalid> - 2015-11-25 12:01 -0800
Re: Question about checking the stack anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-11-25 17:26 +0000
Re: Question about checking the stack François <francois.ganza@wanadoo.fr> - 2015-11-25 13:51 -0800
Re: Question about checking the stack Chris Curl <ccurl609@gmail.com> - 2015-11-28 09:29 -0800
Re: Question about checking the stack Alfred Singlestone <vitonis@gmail.com> - 2015-11-28 12:03 -0800
Re: Question about checking the stack François <francois.ganza@wanadoo.fr> - 2015-12-01 06:15 -0800
Re: Question about checking the stack Chris Curl <ccurl609@gmail.com> - 2015-12-01 14:05 -0800
Re: Question about checking the stack "Elizabeth D. Rather" <erather@forth.com> - 2015-12-01 19:35 -1000
Re: Question about checking the stack dunno <dunno@dunno.dunno> - 2015-12-03 03:40 +0000
csiph-web