home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / tutor / l2p040 < prev    next >
Encoding:
Text File  |  1990-07-15  |  4.3 KB  |  110 lines

  1.        ╔════════════════════════════════════════════════════╗
  2.        ║ Lesson 2 Part 015  F-PC 3.5 Tutorial by Jack Brown ║
  3.        ╚════════════════════════════════════════════════════╝
  4.  
  5.                    ┌────────────────────────┐
  6.                    │ The Colon Decompiler.  │
  7.                    └────────────────────────┘
  8.  
  9. We will start off today by looking at F-PC's decompiler utility. A
  10. decompiler is a utility that will take a compiled colon definition and
  11. reproduce the source code for the colon definition (when Forth compiles
  12. a colon definition it actually compiles a list of addresses).  In F-PC
  13. the word that does the decompiling is SEE .  The rationale for the name
  14. is that you can " SEE " into the compiled code.  To decompile a word the
  15. syntax used is:
  16.  
  17. SEE <word_name> <enter>
  18.  
  19. But first we must have something to decompile.  Let's first compile
  20. COUNT_UP from last time that we placed in the file COUNTING.SEQ
  21. OPEN COUNTING.SEQ <enter> ok
  22. ( If you don't already have this file type: )
  23. ( NEWFILE  COUNTING  and enter the defintion of COUNT_UP )
  24.  
  25. 1 LOAD
  26. Loading.. ok
  27. SEE COUNT_UP
  28. : COUNT_UP
  29.         1 + 0
  30.         ?DO     CR I .
  31.         LOOP    ;  ok
  32.  
  33. Notice that the output of the decompiler is identical to the original
  34. except for the fact the it is formatted differently.  We have also
  35. repaired our version of COUNT_UP so that it works as advertised.
  36.  
  37. SEE can be handy to quickly check that what got compiled is what you
  38. thought it was.  It is faster than VIEW but has the disadvantage that
  39. there are no comments.  With VIEW we are looking at the actual source
  40. code file.
  41.  
  42.                       ┌────────────────┐
  43.                       │ The Debugger.  │
  44.                       └────────────────┘
  45.  
  46. F-PC has a very nice feature that will allow you to single step through
  47. your programs as they execute. Let's try the debugger on our COUNT_UP
  48. word.  The syntax used to specify that <word_name> should be debugged
  49. the next time it is executed is:
  50.  
  51. DEBUG <word_name> <enter> ok
  52.  
  53. To debug COUNT_UP type:
  54.  
  55. DEBUG COUNT_UP <enter>
  56. xxxx COUNT_UP nesting Debugger ready. ok
  57. 4 COUNT_UP <enter>
  58.  
  59. You should see something like the display below.  Pressing the space bar
  60. will single step you through both the source code for the word being
  61. debugged and display:
  62.  
  63. 1) The current segment:offset for the current word.
  64. 2) The current word name.
  65. 3) The current state of the stack.
  66.  
  67.  : COUNT_UP ( n -- )
  68.         1 +  0                       <--- Source code for word
  69.              ?DO                     <--- being debugged.
  70.                   CR I .
  71.              LOOP ;
  72.  C-cont, D-done, F-forth, N-nest, Q-quit, S-skipto, U-unnest,
  73.                                                   X-source-on/off
  74. 4 COUNT_UP  [1]      4
  75. 5D9A  0    (LIT)            ?>  [2]      4       1
  76. 5D9A  4    +                ?>  [1]      5
  77. 5D9A  6    (LIT)            ?>  [2]      5       0
  78. 5D9A  A    (?DO)            ?>  Stack Empty.
  79. 5D9A  E d  CR               ?>
  80.  Stack Empty.
  81. 5D9A 10    I                ?>  [1]      0
  82. 5D9A 12 :  .                ?> 0  Stack Empty.
  83. 5D9A 14    (LOOP)           ?>  Stack Empty.
  84.  
  85. Keep pressing the space bar till the word has completed. While debugging
  86. there are other commands available which are displayed in the bar that
  87. splits the source screen and the debugging screen.  A the function of
  88. the additional commands are: ( HELP DEBUG for a complete listing )
  89.  
  90. C-cont          Continuous, free running mode.
  91. F-forth         Allow entry of Forth commands, until a <return>
  92. Q-quit          Quit the debugger, and unpatch the debug word.
  93. N-nest          Nest into the current definition.
  94. U-unnest        Unnest from the current word being debugged.
  95. Z-zip           Zip through definitions, stoping at : definitions.
  96. X-source OFF    Turn OFF the display of source text at the top.
  97.  
  98. ╓──────────────╖
  99. ║ Problem 2.5  ║
  100. ╙──────────────╜
  101. 1) Experiment with all of the above commands while debugging COUNT_UP
  102. 2) Read the section  in the file DEBUG.HLP that describes the debugger.
  103. Find out the out the name of another word that will allow you to start
  104. the debugger. ( Warning: make sure you put a number on the stack for
  105. COUNT_UP first!)
  106.  
  107. ┌────────────────────────────────────┐
  108. │  Please move to Lesson 2 Part 050  │
  109. └────────────────────────────────────┘
  110.