|
On Sat, Jan 17, 2004 at 08:51:40PM +0000, Ralph Hempel wrote:
> Ernst!
>
> Good to see you're still among us. I'd be happy to
> post your WORDS and SEE (with appropraite credit)
> and write up a little tutorial on their usage.
Long time no see:)
Below is source for .S DUMP WORDS and SEE. Usage of the individual words
should be basically clear, but I have some remarks nontheless:
- Those words were originally embedded in a collection of words that I
always load. I removed as much as possible, and then tested it on a basic
pbforth system (wordlist extensions required). I might have made a mistake
in weeding out, though:)
- C@++ and @++ have names that are clearly C inspired instead of Forth
inspired. I'm not very happy about them, but I couldn't think up a good
forth-ish alternative.
- SEE takes the name of a word, and prints out the definition of that word,
if it is defined by :. Here's the output of SEE C.dump:
: C.dump
BB36 89 CE .. DUP
BB38 BA A6 .. C.printable?
BB3A 89 36 .6 0=
BB3C 87 EC .. 0branch
BB3E BB 46 .F
BB40 89 C0 .. DROP
BB42 86 E0 .. doLIT
BB44 00 2E ..
BB46 9A BA .. EMIT
BB48 89 F0 .. EXIT
Every line consists of address, bytes in hex, bytes as characters, word.
Not everything inside a :-definition is a forth word, there might also be
data, for example at address BB3E and BB44. The first is the target of the
0branch (IF), the second the literal value that doLIT will push on the
stack. SEE doesn't try to be intelligent about it and just dumps the data.
It's up to the programmer to discover the logic behind it. E.g. the dump
above actually gives the following code:
: C.dump DUP C.printable? 0= IF DROP 2E EMIT THEN EXIT
2E is hex for `.' and THEN is the target address for 0branch.
- Because there is no clear ending to a word, there's a problem in deciding
when SEE should stop displaying. A possible way is to dump until the next
word, or the beginning of the vocabulary, if the dumped word is the most
recently defined one. But this can get very unpleasant if you SEE a word
after which there's 20k of ALLOT'ed data. Fortunately, the compiler
ensures that the last instruction of every word is EXIT (generated by ;),
so SEE disassembles until it meets an EXIT instruction. It is of course
possible that the programmer used EXIT in the middle of a word. This is
quickly clear from a branch that jumps over the EXIT. In this case, use
"next-address (see)" to SEE until the next EXIT. In the example above
"BB4A (see)".
- As coded, SEE only works for : words, but it can be extended to work for
e.g. DOES> as well.
Comments, questions, improvements etc. are welcome of course.
Ernst
------ code starts here -------------------------------
DECIMAL
: C.printable? ( ch -- flag ) BL 127 WITHIN ;
: enough? DUP 0= ; ( x -- x flag )
: C@++ ( c-addr - next-c-addr x ) DUP CHAR+ SWAP C@ ;
: @++ ( a-addr - next-a-addr x ) DUP CELL+ SWAP @ ;
: .S ( -- ) \ TOOLS
DEPTH ?DUP IF BEGIN DUP 0 >
WHILE DUP PICK . 1-
REPEAT DROP
THEN ;
: C.dump ( ch -- )
DUP C.printable? 0= IF DROP [CHAR] . THEN EMIT ;
\ DUMP ( addr u -- ) \ TOOLS
\ Display the contents of u consecutive address units starting
\ at addr.
\
: DUMP ?DUP
IF BASE @ >R HEX
1- 16 / 1+
0 DO CR DUP DUP 0 <# # # # # #> TYPE SPACE SPACE
16 0 DO DUP C@ 0 <# # # #> TYPE SPACE CHAR+ LOOP
SPACE SWAP
16 0 DO DUP C@ C.dump CHAR+
LOOP DROP
enough? IF LEAVE THEN
LOOP
R> BASE !
THEN DROP ;
NONSTANDARD-WORDLIST SET-CURRENT
\ WORDLIST-WORDS ( wid -- )
\ List the definition names in wordlist identified by wid.
: WORDLIST-WORDS
CR 0 >R
BEGIN @ ?DUP
WHILE DUP .name R> 1+ >R
cell- \ pointer to next word
enough? UNTIL
THEN SPACE R> . ." words " ;
\ NONSTANDARD-WORDS ( -- )
\ List the definition names in NONSTANDARD-WORDLIST.
: NONSTANDARD-WORDS NONSTANDARD-WORDLIST WORDLIST-WORDS ;
FORTH-WORDLIST SET-CURRENT
\ WORDS ( -- ) \ TOOLS
\ List the definition names in the first wordlist of the
\ search order.
: WORDS #order CELL+ @ WORDLIST-WORDS ;
\ (see) ( a-addr1 -- )
\ List the words called from a-addr1 onwards upto the next EXIT,
\ preceded by the address, and literal bytes.
: (see) ( a-addr1 - )
BASE @ >R HEX
BEGIN CR 3 SPACES
DUP S>D <# # # # # #> TYPE 2 SPACES \ addr
DUP C@++ S>D <# # # #> TYPE SPACE
C@ S>D <# # # #> TYPE 2 SPACES \ xx xx
DUP C@++ C.dump
C@ C.dump 2 SPACES \ ch ch
@++ DUP xt>name ?DUP IF .name THEN \ word
['] EXIT =
UNTIL
DROP
R> BASE ! ;
\ SEE ( " name" -- ) \ TOOLS
\ List the definition of name, upto the first EXIT.
\ The remainder can be seen by using (see).
: SEE ( " name" -- )
(') OVER
?call ['] doLIST = 0= ABORT" Not a : word " \ R: f xt S: xt1
>R SWAP ." : " xt>name .name
1 = IF ." IMMEDIATE" THEN \ S: xt1
R> (see) CR ;
--
Ernst de Ridder - hnridder@informatik.uni-rostock.de
Universitaet Rostock - Lehrstuhl fuer Theoretische Informatik
Albert Einstein Str. 21 - D-18051 Rostock - Germany
http://wwwteo.informatik.uni-rostock.de/~hnridder
|
|
Message has 2 Replies: | | Re: WORDLIST
|
| (...) Hi I've tried to reproduce your code but Bricx has a limit on its line length. Is there an easy way round this problem or do I have to split the longer word definitions. David Liddell. (21 years ago, 28-Jan-04, to lugnet.robotics.rcx.pbforth)
| | | Re: WORDLIST
|
| (...) On a plain pbForth system I get errors when trying to load this code. What do you mean by "wordlist extensions required"? Is there source code available somewhere which adds the wordlist extensions to pbForth? My pbForth doesn't know about (...) (21 years ago, 30-Jan-04, to lugnet.robotics.rcx.pbforth)
|
Message is in Reply To:
| | RE: WORDLIST
|
| Ernst! Good to see you're still among us. I'd be happy to post your WORDS and SEE (with appropraite credit) and write up a little tutorial on their usage. You can post them here and also email them to me directly. Cheers, Ralph (...) (21 years ago, 17-Jan-04, to lugnet.robotics.rcx.pbforth)
|
14 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|