home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / tutor / l7p050 < prev    next >
Text File  |  1990-07-15  |  3KB  |  97 lines

  1.        ╔════════════════════════════════════════════════════╗
  2.        ║  Lesson 7 Part 050 F-PC 3.5 Tutorial by Jack Brown ║
  3.        ╚════════════════════════════════════════════════════╝
  4.  
  5.                   ┌─────────────────────────┐
  6.                   │  Some Sound Problems.   │
  7.                   └─────────────────────────┘
  8.  
  9. ╓───────────────╖
  10. ║  Problem 7.1  ║
  11. ╙───────────────╜
  12. Create the SOUND vocabulary and add the SOUND words from Lesson 7 Part
  13. 4.  Once you have SCALE working make an new word to play a simple tune!
  14.  
  15. ╓───────────────╖
  16. ║  Problem 7.2  ║
  17. ╙───────────────╜
  18. Write some Forth words to generate " sound effects". Make sure that you
  19. place them in the SOUND vocabulary. Try:
  20.  
  21.   : TEST  S.ON  255 0 DO I TONE 1 TENTHS LOOP S.OFF ;
  22.  
  23.                    ┌───────────────────────┐
  24.                    │  Vectored Execution   │
  25.                    └───────────────────────┘
  26.  
  27. \ Vectored execution reference:  Brodie  Ch 9 p 215
  28.  
  29. EXECUTE  ( cfa  -- ) Execute the word whose cfa is on stack.  To get
  30.                      cfa, code field address, of a word we use  '
  31.  
  32. : F.HELLO  ( -- ) ." Hello,  I speak FORTH " ;
  33. : B.HELLO  ( -- ) ." Hello,  I speak BASIC " ;
  34. : P.HELLO  ( -- ) ." Hello,  I speak PASCAL" ;
  35.  
  36.   VARIABLE  INTRO
  37. : GREETING  ( -- ) INTRO @ EXECUTE ;
  38.  
  39. ' F.HELLO EXECUTE <enter>  I speak FORTH ok
  40.  
  41. ' F.HELLO INTRO ! <enter>  ok
  42. GREETING <enter>  I speak FORTH ok
  43.  
  44. ' P.HELLO INTRO ! <enter>  ok
  45. GREETING <enter>  I speak PASCAL ok
  46.  
  47. ' B.HELLO INTRO ! <enter>  ok
  48. GREETING <enter>  I speak BASIC ok
  49.  
  50. The VARIABLE INTRO is called a vector.  And the process of changing
  51. the cfa that is stored in INTRO is called revectoring.  The concept
  52. of using variable to store a cfa and later fetching and executing it
  53. is called  "Vectored Execution"
  54.  
  55. PERFORM  ( adr   -- )   Equivalent to   @ EXECUTE  and will execute
  56.                         slightly faster.
  57.  
  58. \ Try the above examples with GREETING1  below.
  59. : GREETING1  INTRO  PERFORM  ;
  60.  
  61. The word IS is a state smart word that can be used to set the pfa
  62. of DEFERed words, CONSTANTs, or VARIABLEs.
  63.  
  64. IS {word}  ( adr  -- )  Store adr  in pfa of  {word}
  65.  
  66. Sample usage:   ' F.HELLO IS INTRO   etc ,
  67. Repeat the above examples using  IS
  68.  
  69. In order to prevent unnecessary delays,  F-PC has a special type of
  70. variable called a  DEFERed word.   A DEFERed word is like a variable
  71. in that it has a pfa that will hold one word, however this word is
  72. always the cfa of another word and when a DEFERed word executes it
  73. will automatically fetch the cfa stored in its pfa and execute it!
  74.  
  75. DEFER {word}  ( -- )  Like a variable except that it fetches its
  76.                       contents and executes them.
  77. Try the following:
  78. DEFER  GREETING2 <enter> ok
  79.  
  80. ' F.HELLO IS GREETING2 <enter>  ok
  81. GREETING2 <enter>  I speak FORTH ok
  82. ' P.HELLO IS GREETING2 <enter>  ok
  83. GREETING2 <enter>  I speak PASCAL ok
  84. ' B.HELLO IS GREETING2 <enter>  ok
  85. GREETING2 <enter>  I speak BASIC ok
  86.  
  87. ╓───────────────╖
  88. ║  Problem 7.3  ║
  89. ╙───────────────╜
  90. Have you used F-PC's  FLOOK yet?  Type:   HELP FLOOK   and then use
  91. your new knowledge to find some DEFERed words in F-PC.  Give a list of
  92. those the Forth 83 standard words that are DEFERed in F-PC.  Why do you
  93. think these words are DEFERed words?
  94. ┌──────────────────────────────────┐
  95. │ Please Move to Lesson 7 Part 060 │
  96. └──────────────────────────────────┘
  97.