home *** CD-ROM | disk | FTP | other *** search
/ Dream 48 / Amiga_Dream_48.iso / Atari / forth / forst.zoo / forst / forst.doc < prev    next >
Text File  |  1990-12-10  |  16KB  |  375 lines

  1.                                 USING ForST
  2.  
  3.  
  4. This file should be read in conjunction with BULLETIN.DOC, which provides
  5. a much more concise overview of the system.
  6.  
  7.  
  8. ForST
  9.  
  10. ForST is a generic 68000 subroutine-threaded, 32-bit Forth with
  11. significant optimisation of compiled code.  Compiled code compares very
  12. favourably with that from other 68000 compilers.  An overview of the system
  13. is given in a five-part series of articles in Forth Dimensions (starting
  14. Vol XII/2).  Since the original articles were written (mid-1989), the
  15. system has been modified to include:
  16.  
  17.         Headers with links and a flag field (ffa) to direct
  18.           code optimisation
  19.         Register variables as an improved means of local variable
  20.           storage (about 30% faster and significantly smaller code
  21.           than with memory local variables)
  22.         Optimisation with two edges, leading to a further reduction of
  23.           about 20% in execution time.
  24.         Better access to operating system functions and I/O redirection.
  25.         Construction of code primitives by high-level access to
  26.           hardware registers, rather than by using an assembler.
  27.  
  28. Because of the policy of providing a generic system, ForST does not
  29. use the special features of the GEM environment.  Rather, it has been
  30. constructed with an eye to porting to other 68000 command-line systems.
  31.  
  32.  
  33. The files
  34.  
  35. Two executable files are provided in the root directory:
  36.  
  37.         1. FORST.TOS, which is assembled from FORST.S.  This file has
  38.            the headers used by the DevPac monitor.
  39.  
  40.         2. FORSTX.TOS, which is created by the following sequence:
  41.                 a. Double click on FORST.TOS in the usual way;
  42.                 b. When ForST has signed on, type:
  43.                    macros load a:\lib\util.s
  44.                 c. When the prompt appears again, type:
  45.                    cd a:\lib ( to log into the lib folder)
  46.                    load ldfloats.s ( to load f-point package)
  47.                 d. When prompted, type:
  48.                    load redir.s  ( for redirection words)
  49.                 d. When prompted again, type:
  50.                    save a:\forstx.tos
  51.  
  52.         3. Exit (when you wish) to the desktop with SYSTEM
  53.  
  54. In the SOURCE directory are all the assembly source files needed to
  55. reassemble the basic ForST system.  An overview is given in the
  56. BULLETIN.DOC file.  These files are in the public domain ONLY for
  57. non-profit use, and provided that acknowledgement is made of their
  58. origin.
  59.  
  60. In the LIB directory are a number of system utilities and enhancements,
  61. which illustrate the use of the extended Forth style and register/local
  62. variables.  Not all will approve of them, I know.  These files are
  63. placed in the public domain on the sole condition that their origin be
  64. acknowledged.
  65.  
  66. The util.s file contains many of the convenience words you will need:
  67.  
  68.         a: b: c: d: and e: to set the logged disk
  69.         dir (= dir *.*) or (eg) dir a:\lib\*.s etc
  70.         ren <oldname> <newname>
  71.         del <filename>
  72.         copy, ucopy, lcopy <fromname> <toname>
  73.         cd <pathname>  (includes . and ..)
  74.         words (list available words)
  75.         macwords (list available macros)
  76.         what <wordname> (information about the word)
  77.  
  78.  
  79. Using ForST
  80.  
  81. ForST can be used as a fairly standard Forth.  The code that it compiles
  82. can be controlled by CALLS (to compile subroutine-threaded code) and
  83. MACROS (to expand macro words and optimise where possible).  To check
  84. compiled code, a crude hex dump of any word can be obtained with
  85.  
  86.         wd <wordname>
  87.  
  88. which waits for a series of keystrokes, and quits on <ESC>.
  89.  
  90.         what <wordname>
  91.  
  92. gives some basic information, extracted from the word's header.  It is
  93. a little naive, especially with DEFERed and VECTORed words (in Part 5
  94. of the Forth Dimensions series).  The word length given is based on the
  95. number of 16-bit cells, modulo $400, and may not be accurate for very
  96. long definitions.
  97.  
  98. Experience with ForST has shown that source code in the standard Forth style
  99. gives rather poor object code.  It is much better to use register (best) or
  100. local variables and, in any case, I feel that the source code is much more
  101. intelligible.  The register version of the sieve benchmark executes 100
  102. iterations in just over 25 seconds, while nearly 60 seconds are required with
  103. the standard Forth source.  The object code is about 10% smaller,too.  The
  104. source file is in the LIB directory.
  105.  
  106. The register and local variables are the most controversial part of ForST.  I
  107. simply ask that others give them a try.  A number of examples are provided
  108. in the LIB directory.  I am not particularly happy with the declaration
  109. syntax:
  110.  
  111.         3 regargs source dest #chars
  112.  
  113. but it is difficult to do much better with the simple standard Forth
  114. input parsing.  (Look at an approach to a more powerful parser in the ForST
  115. source file XPARSE.S.)
  116.  
  117.  
  118. Integer and floating point (real) arithmetic
  119.  
  120. After ldfloats.s has been loaded, you will have the option of integer
  121. or real arithmetic, using the familiar arithmetic words:
  122.         +, -, *, /, mod, abs, negate
  123. as well as number and . (dot).  INT and FIX round a real number to an
  124. integer value IN REAL FORMAT.  Forth kludge words like +!, 2+, */, etc.
  125. work only with integers.  ADDTO is also a strictly integer operation.
  126.  
  127. You can select which mode you want with INTEGERS and REALS.  This is
  128. very convenient, (look at the file TRIG.S) but I caution you that you must
  129. not feed a real to a loop counter - it knows only about integers - and you
  130. could find yourself in a near-infinite loop.  And if you try to feed a
  131. real number as a count of ARGS or LOCALS, the compiler will become very
  132. confused.  To get around this problem, when you are in REALS mode, you can
  133. preface a number with the cast INTEGER, or (vice-versa) with REAL when you
  134. are in INTEGER mode (see ForST file VECTORS.S).
  135.  
  136.  
  137. System vectoring
  138.  
  139. The arithmetic modes illustrate vectoring of a number of words.  The vectors
  140. are at the top of the assembly source file SHELL.S.  The above arithmetic
  141. words are, in fact, VECTORed words with compile-time bindings (cf DEFERed
  142. words with run-time bindings, described in Part 5 of the FD series) and can
  143. be used to enhance the system.  A new definition of WORD is provided (in
  144. ForST source file XPARSE.S).  It can be installed into the ForST system by
  145.  
  146.         HEAD NEWWORD IS WORD
  147.  
  148. AND its performance is scarcely distinguishable from that of the original
  149. system word.
  150.  
  151.  
  152. Environments
  153.  
  154. The present version of ForST allows command line re-entry (by pressing
  155. the UP arrow BEFORE any other key).  The line can be traversed with LEFT
  156. and RIGHT arrows (to either end with ctrl-arrows) and back space is
  157. permitted anywhere in the line.  This simplifies the correction and
  158. re-entry of a command line.  The assembly source is in SHELL.S and EXPECT.S.
  159.  
  160. ForST offers a pretty fair command-line environment, but there is one thing
  161. missing: an editor.  I have to confess that I'm bored with writing editors
  162. (I wrote several in the early days of Forth for the Tandy Color Computer),
  163. and that I am impatient with bad ones.  In any case, I have a philosophical
  164. thing about ignoring good tools which are already available.
  165.  
  166. I have been using ForST for months from inside the excellent DevPac 2
  167. editor shell and find it pretty convenient to flip between editing and
  168. testing operations.  Even better is the Tempus 2 editor, which handles
  169. four open files and provides a really good shell.  Protext can also be
  170. used, but stops key autorepeat and plays around with the screen display.
  171. Many other shells can be tried: the Beckemeyer MT C-Shell is great, if
  172. you like a CLI, and the Megamax Laser C shell also works (but is rather
  173. unstable).  One thing is certain: Forth will not be accepted until it
  174. can be shown to work with other software.  This is a case in point.
  175.  
  176. Another way to this end is
  177.  
  178.         RUN <filename> <switches>
  179.  
  180. is provided to allow running of other programs from inside ForST.  I have
  181. enjoyed using Unix utilities, such as grep, inside ForST.  This will work
  182. only for non-GEM ('vanilla') programs.  The assembly source for RUN is in
  183. FILES.S.
  184.  
  185. I have experimented with using the STWRITER ELITE editor from inside ForST,
  186. but it is not a convenient solution to the editor problem because, to get
  187. ASCII files, it is necessary to print text to a file, rather than just
  188. save it.  (The main problem is a small header with 'DO' in it.)
  189.  
  190.  
  191. Registers and their use
  192.  
  193.         1. System registers:
  194.  
  195.         a4:     stack frame pointer (for locals)
  196.         a5:     code base pointer (all addresses are
  197.                 reckoned as OFFSETS from this value
  198.                 as explained below)
  199.         a6:     data stack pointer
  200.         a7:     return stack pointer
  201.         d6:     loop counter (gives I for DO ... LOOP
  202.                 and used to hold the comparison value
  203.                 in a CASE construct)
  204.         d7:     loop limit (gives I')
  205.  
  206. 2. Registers for user variables:
  207.  
  208.         These are described in Part 4 of the Forth Dimensions
  209.         ForST series.  The compiler generates code to save
  210.         and restore them as necessary.  The registers are
  211.         allocated in a fixed order:
  212.  
  213.                 a3, a2, d5, d4, d3, d2
  214.  
  215. 3. Scratch registers:
  216.  
  217.                 d0, d1, a0, a1
  218.  
  219.         These are used in Forth primitives, and are available
  220.         for low-level use.  It is the user's responsibility
  221.         to look after their house keeping.  Their advantage
  222.         is that they are not automatically saved and restored,
  223.         and tighter code can be generated.  Examples are given
  224.         in the ForST file REGS.S.
  225.  
  226.  
  227. Addresses
  228.  
  229. Because ForST is assembled in PC-relative code, and will operate
  230. anywhere in memory, all internal addresses are stored as offsets from
  231. the base address in register A5.  OS> converts an offset to an address
  232. and >OS does the opposite.
  233.  
  234. CP (code pointer) and HP (header pointer) are two system variables
  235. which contain offsets and, for convenience, the actual addresses are
  236. given by HERE and THERE, respectively.
  237.  
  238. Internal addresses should always be stored as offsets.  Otherwise, if
  239. code is saved and reloaded in a different location, they will be
  240. incorrect.  A permanent external address, such as a ROM location, can
  241. be handled in the usual way.
  242.  
  243.  
  244. Headers
  245.  
  246. These are described in Part 4 of the FD articles and field address
  247. conversions are carried out by the word WHAT (used as WHAT <word name>.
  248. Note that the cfa is returned by  HEAD <name> and the code address by
  249.  ' <name>.  Because the headers are disposable, there is no way to
  250. determine the cfa from the code address.  Of course, the cfa and pfa
  251. contain address OFFSETS.  The ForST code for WHAT is in file WHAT.S.
  252. It is not elegant, but pretty much describes the header fields.
  253.  
  254. Headers can, and should, be shed when they are no longer needed, but
  255. remember to include a dummy word (like TASK) to subsequently allow you
  256. to remove the associated code when you are finished with it.  Heads of
  257. individual words can be removed by HIDE <word name>.  This complements
  258. FROM, KEEP and PUBLIC (an example of their use is in the file LDFLOATS.S).
  259.  
  260.  
  261. Saving the code image
  262.  
  263. The code and headers can be saved at any time by SAVE <filename>.  (The
  264. file name can include a path on the presently logged disk.)  Before
  265. doing this, you may want to adjust the amount of work space and space
  266. for the return stack and heads by altering the values in WORK, STACK
  267. and HEADS.  Look at the assembly files VARS.S and GLOBALS.S for all
  268. the system variables.
  269.  
  270.  
  271. Crashes
  272.  
  273. The TOS system is very robust and you will very rarely have to
  274. reset, unless you are in the habit of doing quite crazy things.
  275. If you try to access protected memory (addresses 0 - $7ff), or fetch
  276. or store a word or long word at an odd address, you will be thrown
  277. back to the desktop.  ForST has not included protective code to let
  278. you do these (unnecessary) things: it would slow everything down too
  279. much.  Two bombs mean you are tying to access protected memory; three
  280. bombs mean you are trying to access an odd memory location for a two-
  281. byte or four-byte value and four mean that you are trying to execute
  282. garbage code.
  283.  
  284.  
  285. I/O redirection
  286.  
  287. This is available from words in REDIR.S:
  288.  
  289.         1. file> <filename> will get input from a file, but it is simpler
  290.            and safer to use load <filename>
  291.  
  292.         2. console> resets to input from the keyboard after using file>
  293.  
  294.         3. more usefully, output can be directed to a disk file by
  295.  
  296.            a. >file <filename>, whereby output intended for the vdu is
  297.               sent to the file; or better
  298.  
  299.            b. >tee <filename>, whereby output is sent to BOTH the vdu
  300.               and the file.
  301.  
  302.            c. >console, which closes the open output file and returns
  303.               output to the console.
  304.            This is useful for getting a file of available words:
  305.               >tee words.lst  words  >console
  306.            Another example is:
  307.               >tee dir.hex <cr> (open the output file)
  308.               dump dir <cr> (dump the word 'dir')
  309.               <now keep a key depressed until $4E75 (RTS) is printed,
  310.                then press (ESC)>
  311.               >console <cr> (close file)
  312.               print dir.hex  (to printer)
  313.  
  314.         4. print <filename> sends a file to the printer.  The same
  315.            result can be obtained with:
  316.               copy <filename> prn:
  317.            In this case, the copy is made to a temporary file, which
  318.            is then sent to the printer.
  319.            (The 'hardware files' are PRN:, CON: and AUX:)
  320.  
  321.  
  322. Forth source code files
  323.  
  324. Apart from internal nuts-and-bolts details, ForST can be used very much
  325. like 16-bit Forths.  Illustrative source files of extended Forth style
  326. are provided.  They have a .S extension, because the editors I have used
  327. (DevPac and Assempro) like their files that way, but .FTH would probably
  328. be a better choice.  All the files provided (from DevPac) include tabs
  329. and will look a little strange with Assempro (which expands tabs to spaces).
  330.  
  331. Any editor can be used, provided it can generate vanilla ASCII files.
  332. The built-in version of WORD converts all tabs, carriage returns, line
  333. feeds and nulls to spaces to provide maximum compatibility (see SHELL.S
  334. file).  Automatic conversion is made to upper case.
  335.  
  336. Full source is provided.  I would appreciate criticism (constructive
  337. is preferred!) and suggestions.  I hope that the comments will go a
  338. fair way towards providing the documentation that I am too lazy to write.
  339. There are quite a few words which have not had their headers included,
  340. but these can be added quite easily (but be sure that they are assembled
  341. into DATA space).
  342.  
  343. In the main, related code has been localised.  I/O, for example, has
  344. been confined to IO.S and FILES.S.  An overview of the particular files
  345. is in BULLETIN.S and a glossary of new words in GLOSSARY.LST.  It should
  346. be pretty easy to adapt ForST to other 68000 systems.
  347.  
  348. Using the DevPac ST2 assembler, the basic ForST system can be reassembled
  349. very quickly (about 20 seconds from a hard disk and 60 from a floppy).
  350. This just has to beat the gymnastics of metacompilation.  I used the
  351. cheaper Assempro system earlier in development.  It is acceptable, but
  352. much slower and makes testing difficult - and there are a few file
  353. incompatibilities.
  354.  
  355.  
  356. Feedback
  357.  
  358. I would be delighted to hear from users.  Callers from outside
  359. Australia please remember that Sydney time is 9 to 11 hours ahead of
  360. GMT (depending on time of year).  I am very grumpy when woken in the
  361. middle of the night.  On this basis, the best time to call is 9 am
  362. to 11 am, GMT.
  363.  
  364.  
  365.  
  366.  
  367. Good luck,
  368.  
  369. John Redmond,
  370. 23 Mirool Street,
  371. West Ryde,
  372. NSW 2114,
  373. Australia.
  374. Phone 612-85-3751.
  375.