home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / tile.lzh / tile.1 / README
Encoding:
Text File  |  1990-07-26  |  14.0 KB  |  374 lines

  1. THREADED INTERPRETIVE LANGUAGE ENVIRONMENT (TILE) [RELEASE 2.0]
  2.  
  3. June 29, 1990
  4.  
  5. Mikael R.K. Patel
  6. Computer Aided Design Laboratory (CADLAB)
  7. Department of Computer and Information Science
  8. Linkoping University
  9. S-581 83 LINKOPING
  10. SWEDEN
  11. Email: mip@ida.liu.se
  12.  
  13.  
  14. 1.    INTRODUCTION
  15.  
  16. TILE Forth is a 32-bit implementation of the Forth-83 Standard 
  17. written in C. Thus allowing it to be easily moved between different 
  18. computers compared to traditional Forth implementations in assembly.
  19.  
  20. Most Forth implementations are done in assembly to be able to
  21. utilize the underlying architecture as optimal as possible. TILE 
  22. Forth goes another direction. The main idea behind TILE Forth is to 
  23. achieve a portable forth implementation for workstations and medium 
  24. size computer systems so that new groups of programmers may be exposed 
  25. to the flavor of an extensible language such as Forth. 
  26.  
  27. The implementation of TILE Forth is selected so that, in principle, 
  28. any C-level procedure may become available on the interactive and
  29. incremental forth level. Other models of implementation of a threaded
  30. interpreter in C are possible but are not as flexible.
  31.  
  32. TILE Forth is organized as a set of modules to allow the kernel to be 
  33. used as a general threading engine for C. Environment dependencies such
  34. as memory allocation, error handling and input/output have been separated
  35. out of the kernel to increase flexibility. The forth application is "just"
  36. an example of how to use the kernel.
  37.  
  38. Comparing forth implementation using the traditional benchmark such as
  39. the classical sieves calculation is difficult because of difference in
  40. speed between workstations and personal computers. The Byte sieves
  41. benchmark is reported to typically run in 16 seconds on a direct threaded
  42. forth implementation. This benchmark will run in 27 seconds in TILE forth 
  43. on a SUN-3/60 and less than 13 seconds on a SUN SPARCstation 1. These times 
  44. are the total time for loading TILE forth, compiling and executing the
  45. benchmark. Comparing to, for instance, other interpretive languages such 
  46. as Lisp, where one of the classical benchmarks is calculation of the 
  47. Fibonacci function, the performance increase is over one magnitude.
  48.  
  49. The kernel supports the Standard Forth-83 word set except for the
  50. blocks file word set which are not used. The kernel is extended with
  51. many of the concepts from modern programming languages. Here is a list
  52. of some of the extensions; argument binding and local variables, queue
  53. management, low level compiler words, string functions, floating point
  54. numbers, exceptions and multi-tasking. The TILE Forth environment also
  55. contains a set of reusable source files for high level multi-tasking, 
  56. data modeling and structuring modules, and a number of programming tools.
  57.  
  58. To allow interaction and incremental program development TILE Forth
  59. includes a programming environment as a mode in GNU Emacs. This environ-
  60. ment helps with program structuring, documentation search, and program
  61. development. Each vocabulary in the kernel and the source library file is 
  62. described by a manual, documentation and test file. This style of 
  63. programming is emphasized throughout the environment to increase 
  64. understanding and reusability of the library modules. During compilation
  65. TILE Forth's io-package keeps track for which modules have been loaded
  66. so that they are only loaded once even if included by several modules.
  67.  
  68. Writing a Forth in C gives some possibilities that normally are
  69. not available when performing the same task in assembly. TILE Forth
  70. has been profiled using the available tools under Unix. This information
  71. has been used to optimize the compiler so that it achieves a compilation
  72. speed of over 200.000 lines per minute on my machine (a disk-less SUN
  73. SPARCstation 1). Currently code is only saved in source form and 
  74. applications are typically "compile-and-go".
  75.  
  76. So far TILE Forth has been ported and tested at over forty locations
  77. without any major problems except where C compilers do not allow sub-
  78. routine pointers in data structures. 
  79.  
  80.  
  81. 2.    EXTENSIONS
  82.  
  83. What is new in the TILE forth? First of all the overall organization
  84. of words. To increase portability and understanding of forth code modules
  85. vocabularies are used as the primary packaging mechanism. New data types
  86. such as rational and floating point numbers are implemented in separate
  87. vocabularies. The vocabularies act as both a program module and an 
  88. abstract data type.
  89.  
  90. 2.1    Extendable interpreter
  91.  
  92. To allow extension of the literal symbol set (normally only integer
  93. numbers) each vocabulary is allowed to have a literal recognition
  94. function. This function is executed by the interpreter when the symbol
  95. search has failed. The literal recognizer for the forth vocabulary is 
  96. "?number". This simple mechanism allows modules such as for rational and 
  97. floating point numbers, and integer ranges to extend with their own
  98. literal function.
  99.  
  100. 2.2    Data description
  101.  
  102. As the Forth-83 Standard lack tools for description of data structures 
  103. TILE Forth contains a fairly large library of tools for this purpose. 
  104. These are described more in detail in the next section.
  105.  
  106. 2.3    Argument binding and local variables
  107.  
  108. When writing a forth function with many arguments stack shuffling
  109. becomes a real pain. Argument binding and local variables is a nice
  110. way out of these situations. Also for the new-comer to Forth this
  111. gives some support to this at first very cryptic language. Even
  112. the stack function may be rewritten using this mechanism:
  113.  
  114.     : 2drop { a b } ;
  115.     : 2swap { a b c d } c d a b  ;
  116.     : fac { n } n 0> if n 1- recurse n * else 1 then ;
  117.  
  118. The argument frame is created on top of the parameter stack and is
  119. disposed when functions is exited. This implementations style of
  120. reduces the cost of binding as most functions have more arguments
  121. then return values. A minimum number of data elements have to be
  122. move to create and manage the argument frame.
  123.  
  124. 2.4     Exception handling
  125.  
  126. Another extension in TILE Forth is exception handling with multiple
  127. exception handling code block. The syntactical structure is very
  128. close to that of Ada, i.e., any colon definition may contain an error
  129. handling section. Should an error occur during the execution of the
  130. function the stack status is restore to the situation at the call
  131. of the function and the lastest exception block is executed with the 
  132. signal or exception as a parameter;
  133.  
  134.     exception zero-divide ( -- exception)
  135.  
  136.     : div ( x y -- z)
  137.           /
  138.     exception> ( x y signal -- )
  139.       drop zero-divide raise
  140.         ;
  141.  
  142. Error situations may be indicated using an exception raise function. 
  143. Low level errors, such as zero division, are transformed to exceptions 
  144. in TILE Forth.
  145.  
  146. 2.5    Entry visibility and forward declaration
  147.  
  148. Last, some of the less significant extension are forward declaration
  149. of entries, hidden or private entries, and extra entry modes. Forward
  150. declaration of entries are automatically bound when the entry is later
  151. given a definition. Should a binding not exist at run-time an error
  152. message is given and the computation is aborted.
  153.  
  154.     forward eval ( ... )
  155.  
  156.     : apply ( ... ) ... eval ... ;
  157.     : eval ( ... ) ... apply ... ;
  158.  
  159. Three new entry modes have been added to the classical forth model 
  160. (immediate). These allow hiding of entries in different situations.
  161. The first two marks the last defined word's visibility according to
  162. an interpreter state. These two modifiers are called "compilation" 
  163. and "execution" and are used as "immediate". A word like "if" is
  164. "compilation immediate" meaning it is visible when compiling and 
  165. then always executed. 
  166.  
  167.     compiler forth definitions
  168.  
  169.     : if ( -- ) compile (?branch) >mark ; compilation immediate
  170.  
  171. The "private" modifier is somewhat different. It concerns the
  172. visibility across vocabularies (modules and types). If a word is
  173. marked as "private" the word is only visible when the vocabulary in 
  174. which it is defined in is "current". This is very close to the concept
  175. of hidden in modules and packages in Modula-2 and Ada.
  176.  
  177.     4 field +name ( entry -- ptr) private
  178.  
  179. The above definition will only be visible in the vocabulary it was 
  180. defined. The "private" modifier is useful to help isolate implementation
  181. dependencies and reduce the name space which also increases compilation
  182. speed.
  183.  
  184.  
  185. 3.     SOURCE LIBRARY
  186.  
  187. The TILE Forth programming environment contains a number of tools to 
  188. make programming in Forth a bit easier. If you have GNU Emacs, TILE 
  189. Forth may run in a specialized forth-mode. This mode supports automatic 
  190. program indentation (pretty printing), documentation search, and 
  191. interactive and incremental program development, or "edit-compile-test" 
  192. style of program development.
  193.  
  194. To aid program development there is also a source code library with
  195. manual pages, documentation (glossary), and test and example code.
  196. Most of the source code are data modeling tools. In principle, from 
  197. bit field definition to object oriented structures are available. The 
  198. source code library also contains debugging tools for tracing, break-
  199. point'ing and profiling of programs. 
  200.  
  201. The first level of data modeling tools are modules for describing;
  202. 1) bit fields, 2) structures (records), 3) aggregates of data 
  203. (vectors, stacks, buffers, etc), and 4) high level data objects
  204. (lists, sets, etc).
  205.  
  206. The next level of tools are some tools for high level syntactic sugar
  207. for multi-tasking concepts (semaphores, channels, etc), finite state
  208. machines (FSM), anonymous code block (blocks), a general top down parser
  209. with backtrack and semantic binding, and a simulation package. The source
  210. library will be extended during the coming releases.
  211.  
  212.  
  213. 4.     PROGRAMMING STYLE
  214.  
  215. A source code module has, in general, the following structure; the 
  216. first section includes any modules needed (these are only loaded once).
  217. Second follows global definitions for the module. Normally this is 
  218. a vocabulary for the module. Third comes the search chain to be used
  219. throughout the module. It is important not to change the search order
  220. as 1) it becomes difficult for a reader to understand the code, 2)
  221. any change in the search chain flushes the internal lookup cache
  222. in TILE Forth and reduces compilation speed.
  223.  
  224.     .( Loading the Library...) cr
  225.  
  226.     #include someLibrary.f83
  227.     ...
  228.  
  229.     ( Global data and definitions)
  230.  
  231.     : someGlobalDefinitions ( -- ) ... ;
  232.  
  233.     vocabulary theLibrary
  234.  
  235.     someLibrary ... theLibrary definitions
  236.  
  237.     ( Local data and definitions)
  238.  
  239.     : somePrivateDefinitions ( -- ) ... ; private
  240.     ...
  241.     : someDefinitions ( -- ) ... ; 
  242.  
  243.     forth only
  244.  
  245. To create lexical levels within the same vocabulary the word "restore" 
  246. may be used. It stores the vocabulary pointer to the given entry and 
  247. thus hides the words defined after this entry. The word "restore" has 
  248. much the same action as "forget" but without putting back the dictionary 
  249. pointer.
  250.  
  251.  
  252. 5.    SOURCE FILES
  253.  
  254. The TILE Forth source is broken down into the following files:
  255.  
  256. README
  257.    This short documentation of TILE.
  258.  
  259. COPYING
  260.    The GNU General Public License.
  261.  
  262. INSTALL
  263.    Some help on how to install TILE Forth.
  264.  
  265. PORTING
  266.    Some help on how to port TILE Forth and typical problems
  267.  
  268. Makefile
  269.    Allows a number of compilation styles for debugging, profiling, 
  270.    sharing etc. New machines and conditional compilation symbols are 
  271.    added here.
  272.  
  273. src
  274.   The C source library with the kernel code and GNU Emacs forth-mode.
  275.  
  276. lib
  277.    The Forth-83 source library for data description and management, 
  278.    high level tasking, etc.
  279.  
  280. tst
  281.    Test file for each Forth-83 source code file and a set of benchmarks.
  282.  
  283. man
  284.    Manual pages for the TILE Forth C kernel and Forth-83 source code 
  285.    library.
  286.  
  287. doc
  288.    Documentation and glossaries for each source code file and kernel
  289.    vocabularies.
  290.  
  291. bin
  292.    Utility commands and the TILE forth compiler/interpreter.
  293.  
  294.  
  295.  
  296. 6.    CONFIGURATION
  297.  
  298. TILE forth is targeted for 32-bit machines and no special aid is 
  299. available to allow it to be compiled for other bit-widths. The 
  300. configuration is maintained by a "make" files. 
  301.  
  302. This configuration file allows a number of different modes to support
  303. typical program development phases (on C level) such as debugging, 
  304. profiling, optimization and packaging. Please see the information in
  305. these files.
  306.  
  307.  
  308. 7.    COPYING
  309.  
  310. This software is offered as shareware. You may use it freely, but 
  311. if you do use it and find it useful, you are encouraged to send the
  312. author a contribution (>= $50) to the following address:
  313.  
  314.     TILE Technology HB
  315.     Stragatan 19
  316.     S-582 67 Linkoping
  317.     SWEDEN
  318.  
  319. If you send me a contribution, I will send you manual pages and 
  320. documentation files and will answer questions by mail. Also your
  321. name will be put on a distribution list for future releases.
  322.  
  323. For further information about copying see the file COPYING and
  324. the headers in the source code files. Commercial usage of the
  325. kernel is not allowed without a license from the company above.
  326.  
  327.  
  328. 8.    NOTE
  329.  
  330. Due to the 32-bit implementation in C a number of Forth-83 definitions 
  331. are not directly confirmed. Below is a short list of words that might 
  332. give problems when porting Forth code to this environment:
  333.  
  334. * The Block Word Set is not supported. Source code is saved as text 
  335.   files.
  336.  
  337. * All stacks and words size are 32-bit. Thus special care must be 
  338.   taken with memory allocation and access.
  339.  
  340. * Lowercase and uppercase are distinguished, and all forth words are
  341.   lowercase. 
  342.  
  343. * A word in TILE is allowed arbitrary length as the name is stored as
  344.   as a null terminated string.
  345.  
  346. * Input such as "key" performs a read operation to the operating system
  347.   thus will echo the characters.
  348.  
  349. * Variables should not allocate extra memory. "create" should be used.
  350.  
  351. * Double number arithmetic functions are not available.
  352.  
  353. Some major changes have been made to the kernel in this second release.
  354. To allow implementation of floating point numbers and increase porting
  355. the kernel is now written in its own extendable typing system. Some
  356. extension have been removed such as the casting operator in the 
  357. interpreter.
  358.  
  359.  
  360. ACKNOWLEDGMENTS
  361.  
  362. First of all I wish to express my gratitude to Goran Rydqvist for helped
  363. me out with the first version of the kernel and who implemented the 
  364. forth-mode for GNU Emacs. 
  365.  
  366. Second a special thanks to the beta test group who gave me valuable
  367. feedback. Especially Mitch Bradley, Bob Giovannucci Jr., Moises Lejter, 
  368. and Brooks David Smith. 
  369.  
  370. Last, I wish to thank the may users that have been in touch after the
  371. first release and given me many comments and encouragements.
  372.  
  373. Thank you all.
  374.