Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #34720 > unrolled thread
| Started by | albert@spenarnc.xs4all.nl (Albert van der Horst) |
|---|---|
| First post | 2014-11-30 17:10 +0000 |
| Last post | 2014-11-30 12:36 -0800 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.forth
A useful trick in recursive debugging. albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-11-30 17:10 +0000
Re: A useful trick in recursive debugging. Paul Rubin <no.email@nospam.invalid> - 2014-11-30 09:54 -0800
Re: A useful trick in recursive debugging. albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-11-30 20:04 +0000
Re: A useful trick in recursive debugging. Paul Rubin <no.email@nospam.invalid> - 2014-11-30 12:36 -0800
| From | albert@spenarnc.xs4all.nl (Albert van der Horst) |
|---|---|
| Date | 2014-11-30 17:10 +0000 |
| Subject | A useful trick in recursive debugging. |
| Message-ID | <547b4f72$0$15832$e4fe514c@dreader35.news.xs4all.nl> |
Normally .S looks something like
: .S
CR &S EMIT &[ EMIT SPACE
DSP@ S0 @ BEGIN 2DUP - 0< WHILE 0 CELL+ - DUP @ . REPEAT 2DROP
&] EMIT ;
With output like
S[ 0 0 0 0 0 0 0 896 -420 ]
Stack printouts for recursive programs can be hard to read.
A little indenting works wonders. What you need is some way
to find out the return stack depth. In the example the actual
stack pointe RSP@ is compared to the initial one.
You may even have RDEPTH in your favourite Forth.
: .S
CR R0 @ RSP@ - 1 CELLS / SPACES &S EMIT &[ EMIT SPACE
DSP@ S0 @ BEGIN 2DUP - 0< WHILE 0 CELL+ - DUP @ . REPEAT 2DROP
&] EMIT ;
Now the output for a recursive program is
...
S[ 3 1 ]
S[ 4 3 0 ]
S[ 4 0 2 0 ]
S[ 4 1 2 9 ]
S[ 4 1 1 -20 ]
S[ 4 1 1 0 ]>
S[ 4 2 ]
S[ 6 3 9 ]
S[ 6 0 2 9 ]
S[ 6 0 2 18 ]
S[ 6 0 1 -11 ]
S[ 6 0 1 9 ]>
S[ 6 0 ]>
For
: doit .s aap noot .... mies .s ;
the input and the output of a Forth word now line up
nicely.
Groetjes Albert
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
[toc] | [next] | [standalone]
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Date | 2014-11-30 09:54 -0800 |
| Message-ID | <7xr3wk8thd.fsf@ruckus.brouhaha.com> |
| In reply to | #34720 |
albert@spenarnc.xs4all.nl (Albert van der Horst) writes: > S[ 3 1 ] > S[ 4 3 0 ] How do you locate the boundaries between DS frames without pushing/popping DSP on the return stack with every function call?
[toc] | [prev] | [next] | [standalone]
| From | albert@spenarnc.xs4all.nl (Albert van der Horst) |
|---|---|
| Date | 2014-11-30 20:04 +0000 |
| Message-ID | <547b784d$0$6971$e4fe514c@dreader36.news.xs4all.nl> |
| In reply to | #34722 |
In article <7xr3wk8thd.fsf@ruckus.brouhaha.com>,
Paul Rubin <no.email@nospam.invalid> wrote:
>albert@spenarnc.xs4all.nl (Albert van der Horst) writes:
>> S[ 3 1 ]
>> S[ 4 3 0 ]
>
>How do you locate the boundaries between DS frames without
>pushing/popping DSP on the return stack with every function call?
With a .S at the start and the entry of a recursive call, all
intermediate stack prints are more indented. So those two line
up vertically. That is often enough. After all .S is not much
more than a simple debugging tool.
In other words, DS stack frames are just the two or three last
stack items from a less indented line
S[ 0 0 0 0 0 1 2 ]
..
s[ ..
S[ ..
..
S[ 0 0 0 0 0 3 ]
With a stack diagram of ( n n -- n )
we see that some call did ( 1 2 -- 3 )
Groetjes Albert
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
[toc] | [prev] | [next] | [standalone]
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Date | 2014-11-30 12:36 -0800 |
| Message-ID | <7x38901l52.fsf@ruckus.brouhaha.com> |
| In reply to | #34724 |
albert@spenarnc.xs4all.nl (Albert van der Horst) writes: > In article <7xr3wk8thd.fsf@ruckus.brouhaha.com>, > Paul Rubin <no.email@nospam.invalid> wrote: >>albert@spenarnc.xs4all.nl (Albert van der Horst) writes: >>> S[ 3 1 ] >>> S[ 4 3 0 ] >> >>How do you locate the boundaries between DS frames without >>pushing/popping DSP on the return stack with every function call? > > With a .S at the start and the entry of a recursive call, all > intermediate stack prints are more indented. So those two line > up vertically. That is often enough. After all .S is not much > more than a simple debugging tool. Oh I see, that output was from a separate call to .S at each level. Does the .S somehow distinguish between recursive calls and ordinary calls? I.e. do you get indentation if you're 4 levels deep in normal, non-recursive calls? I suppose it's fine either way.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web