Implementation of .s

12 views
Skip to first unread message

crc

unread,
Apr 15, 2011, 2:50:42 PM4/15/11
to RETRO 10
I'm looking at ways of implementing .s currently.

The current definition is a recursive function:

: (.s) ( - ) depth 0; drop &(.s) dip dup putn space ;
: .s ( - ) cr depth "<%d> " puts (.s) cr ;

With 100 values on the data stack, this uses 312 cells of address
stack.

A non-recursive approach would have less impact on the stack:
: .s ( - )
depth [ "\n<%d> " puts ] sip 0;
heap [ dup [ swap , ] times
[ here 1- @ dup putn space -1 allot ] times ]
preserve ;

This has a max hit of 42 cells. But it does modify memory starting at
**here**. So if you're using non-allocated space as a buffer, this
will overwrite things. We could add a buffer:

create stack 128 allot
: .s ( - )
depth [ "\n<%d> " puts ] sip 0;
dup 128 > [ drop 128 ] ifTrue
heap [ stack !heap
dup [ swap , ] times
[ here 1- @ dup putn space -1 allot ] times ]
preserve ;

But this is getting less clean. What do you all prefer (and why), or
is there a better way to do this?

-- crc
Reply all
Reply to author
Forward
0 new messages