home *** CD-ROM | disk | FTP | other *** search
- ╔════════════════════════════════════════════════════╗
- ║ Lesson 2 Part 015 F-PC 3.5 Tutorial by Jack Brown ║
- ╚════════════════════════════════════════════════════╝
-
- ┌────────────────────────┐
- │ The Colon Decompiler. │
- └────────────────────────┘
-
- We will start off today by looking at F-PC's decompiler utility. A
- decompiler is a utility that will take a compiled colon definition and
- reproduce the source code for the colon definition (when Forth compiles
- a colon definition it actually compiles a list of addresses). In F-PC
- the word that does the decompiling is SEE . The rationale for the name
- is that you can " SEE " into the compiled code. To decompile a word the
- syntax used is:
-
- SEE <word_name> <enter>
-
- But first we must have something to decompile. Let's first compile
- COUNT_UP from last time that we placed in the file COUNTING.SEQ
- OPEN COUNTING.SEQ <enter> ok
- ( If you don't already have this file type: )
- ( NEWFILE COUNTING and enter the defintion of COUNT_UP )
-
- 1 LOAD
- Loading.. ok
- SEE COUNT_UP
- : COUNT_UP
- 1 + 0
- ?DO CR I .
- LOOP ; ok
-
- Notice that the output of the decompiler is identical to the original
- except for the fact the it is formatted differently. We have also
- repaired our version of COUNT_UP so that it works as advertised.
-
- SEE can be handy to quickly check that what got compiled is what you
- thought it was. It is faster than VIEW but has the disadvantage that
- there are no comments. With VIEW we are looking at the actual source
- code file.
-
- ┌────────────────┐
- │ The Debugger. │
- └────────────────┘
-
- F-PC has a very nice feature that will allow you to single step through
- your programs as they execute. Let's try the debugger on our COUNT_UP
- word. The syntax used to specify that <word_name> should be debugged
- the next time it is executed is:
-
- DEBUG <word_name> <enter> ok
-
- To debug COUNT_UP type:
-
- DEBUG COUNT_UP <enter>
- xxxx COUNT_UP nesting Debugger ready. ok
- 4 COUNT_UP <enter>
-
- You should see something like the display below. Pressing the space bar
- will single step you through both the source code for the word being
- debugged and display:
-
- 1) The current segment:offset for the current word.
- 2) The current word name.
- 3) The current state of the stack.
-
- : COUNT_UP ( n -- )
- 1 + 0 <--- Source code for word
- ?DO <--- being debugged.
- CR I .
- LOOP ;
- C-cont, D-done, F-forth, N-nest, Q-quit, S-skipto, U-unnest,
- X-source-on/off
- 4 COUNT_UP [1] 4
- 5D9A 0 (LIT) ?> [2] 4 1
- 5D9A 4 + ?> [1] 5
- 5D9A 6 (LIT) ?> [2] 5 0
- 5D9A A (?DO) ?> Stack Empty.
- 5D9A E d CR ?>
- Stack Empty.
- 5D9A 10 I ?> [1] 0
- 5D9A 12 : . ?> 0 Stack Empty.
- 5D9A 14 (LOOP) ?> Stack Empty.
-
- Keep pressing the space bar till the word has completed. While debugging
- there are other commands available which are displayed in the bar that
- splits the source screen and the debugging screen. A the function of
- the additional commands are: ( HELP DEBUG for a complete listing )
-
- C-cont Continuous, free running mode.
- F-forth Allow entry of Forth commands, until a <return>
- Q-quit Quit the debugger, and unpatch the debug word.
- N-nest Nest into the current definition.
- U-unnest Unnest from the current word being debugged.
- Z-zip Zip through definitions, stoping at : definitions.
- X-source OFF Turn OFF the display of source text at the top.
-
- ╓──────────────╖
- ║ Problem 2.5 ║
- ╙──────────────╜
- 1) Experiment with all of the above commands while debugging COUNT_UP
- 2) Read the section in the file DEBUG.HLP that describes the debugger.
- Find out the out the name of another word that will allow you to start
- the debugger. ( Warning: make sure you put a number on the stack for
- COUNT_UP first!)
-
- ┌────────────────────────────────────┐
- │ Please move to Lesson 2 Part 050 │
- └────────────────────────────────────┘
-