home *** CD-ROM | disk | FTP | other *** search
- \ Lesson 6 Part 11 ( F-PC 3.5 Tutorial by Jack Brown )
- COMMENT:
- Wow.... the word GET only works when you execute it directly... It
- doesn't work when you use it in a definition. This is because GET gets
- compiled and the ' does not try to do its job of picking up the cfa of
- the next word in the input stream until the word REPORT is executed. By
- then it is too late. Here is a version that will work in a definition.
- But to make it we will have to use the words [COMPILE] and COMPILE
- COMMENT;
- : GET ' [COMPILE] LITERAL COMPILE .FIELD ; IMMEDIATE
- COMMENT:
- This version of get is IMMEDIATE so that when you compile the word
- REPORT from the last message it executes immediately gets the cfa of the
- word following and compiles it ( that's what the LITERAL does remember)
- then we compile the word .FIELD. ( .FIELD gets compiled every time we
- use GET )
-
- Make sure you redefine the word REPORT from the previous message and
- then try it!! Also decompile it by using SEE REPORT ( in F-PC to
- see what really is happening )
-
- Now try using you new GET in direct execution mode like we did with the
- first one. ie try the following :
-
- MONITORS GET COST MONITORS GET QUANTITY
-
- Horrors... this version does not work when try to use it in interpretive
- mode. Wouldn't it be nice to have a GET that works both in compile mode
- and interpretive mode?? here is the solution:
- COMMENT;
- : GET ( -- )
- ' STATE @
- IF [COMPILE] LITERAL
- COMPILE .FIELD
- ELSE .FIELD
- THEN ;
- IMMEDIATE
- COMMENT:
- This version of GET is said to be "state smart" because it checks the
- system variable state and then does the correct thing when compiling.
- "state smart" words must be IMMEDIATE.
-
- By the way.... state smart words were banned from the FORTH 83 standard.
-
- ." is not state smart in FORTH 83 ( it was in fig FORTH and FORTH79)
- and so it can only be used inside a definition. If you have a version
- of fig FORTH look up the definition of ." and you will see that it uses
- the same ideas that were illustrated in the word GET above.
-
- One more time.... If you are only reading this you will not not grasp
- what is really going on. Capture this message and take the time to
- figure exactly what is going on here. I guarantee that mastery of these
- two words will really pay off in your understanding of how the FORTH
- compiler works.
-
- Happy COMPILEing or should I say [COMPILE]ing
-
- Problem 6.14
- Write a STATE smart version of ." that can be used both inside and
- outside a colon definition. Hint: Look at the F-PC definitions of .(
- and ." and combine the two actions in a way similar to what we did with
- the two functions required for GET.
-
- Problem 6.15
- The ANS Forth Standard is going to replace the the words COMPILE and
- [COMPILE] with the single new word POSTPONE . Check out the ANS Forth
- Basis document and give state smart definition of GET and ." that use
- POSTPONE .
- COMMENT;
- ( Please Move to Lesson 6 Part 12 )
-