home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
forth
/
compiler
/
fpc
/
tutor
/
l7p050
< prev
next >
Wrap
Text File
|
1990-07-15
|
3KB
|
97 lines
╔════════════════════════════════════════════════════╗
║ Lesson 7 Part 050 F-PC 3.5 Tutorial by Jack Brown ║
╚════════════════════════════════════════════════════╝
┌─────────────────────────┐
│ Some Sound Problems. │
└─────────────────────────┘
╓───────────────╖
║ Problem 7.1 ║
╙───────────────╜
Create the SOUND vocabulary and add the SOUND words from Lesson 7 Part
4. Once you have SCALE working make an new word to play a simple tune!
╓───────────────╖
║ Problem 7.2 ║
╙───────────────╜
Write some Forth words to generate " sound effects". Make sure that you
place them in the SOUND vocabulary. Try:
: TEST S.ON 255 0 DO I TONE 1 TENTHS LOOP S.OFF ;
┌───────────────────────┐
│ Vectored Execution │
└───────────────────────┘
\ Vectored execution reference: Brodie Ch 9 p 215
EXECUTE ( cfa -- ) Execute the word whose cfa is on stack. To get
cfa, code field address, of a word we use '
: F.HELLO ( -- ) ." Hello, I speak FORTH " ;
: B.HELLO ( -- ) ." Hello, I speak BASIC " ;
: P.HELLO ( -- ) ." Hello, I speak PASCAL" ;
VARIABLE INTRO
: GREETING ( -- ) INTRO @ EXECUTE ;
' F.HELLO EXECUTE <enter> I speak FORTH ok
' F.HELLO INTRO ! <enter> ok
GREETING <enter> I speak FORTH ok
' P.HELLO INTRO ! <enter> ok
GREETING <enter> I speak PASCAL ok
' B.HELLO INTRO ! <enter> ok
GREETING <enter> I speak BASIC ok
The VARIABLE INTRO is called a vector. And the process of changing
the cfa that is stored in INTRO is called revectoring. The concept
of using variable to store a cfa and later fetching and executing it
is called "Vectored Execution"
PERFORM ( adr -- ) Equivalent to @ EXECUTE and will execute
slightly faster.
\ Try the above examples with GREETING1 below.
: GREETING1 INTRO PERFORM ;
The word IS is a state smart word that can be used to set the pfa
of DEFERed words, CONSTANTs, or VARIABLEs.
IS {word} ( adr -- ) Store adr in pfa of {word}
Sample usage: ' F.HELLO IS INTRO etc ,
Repeat the above examples using IS
In order to prevent unnecessary delays, F-PC has a special type of
variable called a DEFERed word. A DEFERed word is like a variable
in that it has a pfa that will hold one word, however this word is
always the cfa of another word and when a DEFERed word executes it
will automatically fetch the cfa stored in its pfa and execute it!
DEFER {word} ( -- ) Like a variable except that it fetches its
contents and executes them.
Try the following:
DEFER GREETING2 <enter> ok
' F.HELLO IS GREETING2 <enter> ok
GREETING2 <enter> I speak FORTH ok
' P.HELLO IS GREETING2 <enter> ok
GREETING2 <enter> I speak PASCAL ok
' B.HELLO IS GREETING2 <enter> ok
GREETING2 <enter> I speak BASIC ok
╓───────────────╖
║ Problem 7.3 ║
╙───────────────╜
Have you used F-PC's FLOOK yet? Type: HELP FLOOK and then use
your new knowledge to find some DEFERed words in F-PC. Give a list of
those the Forth 83 standard words that are DEFERed in F-PC. Why do you
think these words are DEFERed words?
┌──────────────────────────────────┐
│ Please Move to Lesson 7 Part 060 │
└──────────────────────────────────┘