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

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