home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / EFFO / pd6.lzh / SRC / README < prev    next >
Text File  |  1989-12-21  |  13KB  |  345 lines

  1. THREADED INTERPRETIVE LANGUAGE ENVIRONMENT (TILE)
  2.  
  3. November 30, 1989
  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 Forth-83 implementation written in C. Thus allowing it to
  17. be easily moved between different computers compared to traditional Forth
  18. implementations in assembler. 
  19.  
  20. TILE Forth is organized in a set of modules to allow the kernel to be used
  21. as a general threading engine for C. Also environment dependencies such
  22. as memory allocation, error handling and input/output are separated to
  23. increase flexibility. 
  24.  
  25. The kernel supports the Standard Forth-83 Word Set except for blocks
  26. which are not used. The kernel is extended with the following; argument
  27. binding and local variables, queue management, low level compiler words,
  28. null terminated string functions, exceptions and multi-tasking. The TILE 
  29. Forth environment also contains a set of source files for high level multi-
  30. tasking, data structuring and a number of programming tools.
  31.  
  32. To allow interaction and incremental program development TILE Forth
  33. contains a programming environment. This environment helps with 
  34. program structuring, i.e., pretty printing, documentation search, and
  35. program development. Each vocabulary in the kernel and the source files
  36. is described by a documentation and test file. This style of programming
  37. is emphasized throughout the environment.
  38.  
  39. So far TILE Forth has been ported and tested to over twenty locations
  40. without any major problems except where C compilers do not allow sub-
  41. routine pointers in data structures.
  42.  
  43. Most Forth implementations are done in assembly to be able to
  44. utilize the underlying architecture as optimal as possible. TILE Forth
  45. goes an other direction. The main idea behind TILE Forth is to achieve
  46. a portable forth implementation for workstations and medium size
  47. computer systems so that new groups of programmers may be exposed 
  48. to the flavor of an extensible language such as Forth. The forth
  49. application is just an example of how to use the kernel. 
  50.  
  51. The organization of TILE Forth is selected so that, in principle, any
  52. C-level procedure may become available on the interactive and
  53. incremental forth level. Other models of implementation of a threaded
  54. interpreter in C are possible but are not as flexible.
  55.  
  56. TILE Forth is divided into three major parts, the kernel, io-, error-, 
  57. and memory management packages, and the application example, TILE Forth 
  58. itself. 
  59.  
  60. TILE Forth extends the Forth 83 required standard with many of the
  61. concepts from modern programming language such as argument binding, 
  62. and local variable frame, multi-tasking, exception management etc.
  63.  
  64. Writing a Forth in C gives some possibilities that normally are
  65. not available when performing the same task in assembler. TILE Forth
  66. has been profiled using the available tools in Unix. This information
  67. has been used to optimize the compiler so that it achieves a compilation
  68. speed of over 100.000 lines per minute on a Sun-4.
  69.  
  70. Currently code is only saved in source form and applications are
  71. typically compile-and-go. 
  72.  
  73. Comparing with the traditional benchmark such as the classical sieves
  74. calculation is difficult because of difference in speed between
  75. workstations and personal computers. The Byte sieves benchmark is
  76. reported to typically run in 16 seconds on a DTC forth implementation.
  77. This benchmark will run in 27 seconds in TILE forth on a SUN-3/60.
  78. This is the total time for starting forth, compiling and executing the 
  79. benchmark.
  80.  
  81. Comparing to, for instance, other interpretive languages such as 
  82. Lisp, where one of the classical benchmarks is calculation of the 
  83. Fibonacci function, the performance increase is almost two magnitudes.
  84.  
  85.  
  86. 2.     EXTENSIONS
  87.  
  88. What is new in the forth vocabulary? First of all is the overall
  89. organization of words. Vocabularies, casting and entry caching is
  90. used to make word search faster, but also to make programs written 
  91. in TILE Forth more portable to other forth dialects. If a vocabulary 
  92. other than forth is used the target system much realize these. The 
  93. casting operator in the forth top loop, interpret, allow selection 
  94. of words from vocabularies without changing the search order thus 
  95. operator overloading may be achieved. In general, the top loop 
  96. recognizes a casting operation as a parenthesized vocabulary name 
  97. prefix. An example; selecting string concatenation without changing 
  98. the search order just write:
  99.  
  100.        (string) +
  101.  
  102. As Forth lack tools for description of data structures TILE Forth 
  103. contains a fairly large library of tools. These are described more 
  104. in detail in the next section.
  105.  
  106. When writing a forth function with many arguments stack shuffling
  107. becomes a real pain. Argument binding and local variables are nice
  108. ways out of these situations. Also for the new-comer to Forth
  109. this gives some support. Even the stack function may be rewritten:
  110.  
  111.        : 2swap { a b c d } c d a b  ;
  112.        : 2drop { a b } ;
  113.  
  114. An other extension in TILE Forth are exception handing with multiple
  115. exception handling code block. The syntactical structure is very
  116. close to that of Ada, i.e., any colon definition may contain an error
  117. handling section. Should an error occur during the execution of the
  118. function the stack status is restore to the situation at call
  119. and the last exception block is executed. Error situations may be
  120. indicated user an exception raise function. Low level errors, such as 
  121. zero division, are transformed to exceptions in TILE Forth.
  122.  
  123.        : div ( x y -- z)
  124.           /
  125.        exception> ( x y exception -- )
  126.          true abort" div: zero division attempted" 
  127.         ;
  128.  
  129. Last some of the less significant extension are forward declaration
  130. of entries, hidden or private entries, and extra entry modes. Three
  131. new entry modes have been added to the classical forth model (immediate).
  132. These allow hiding of entries in different situations.
  133.  
  134. The first two marks the last defined words visibility according to
  135. an interpreter state. These two modifiers are called "compilation" 
  136. and "execution" and are used as "immediate". A word like "if" is
  137. "compilation immediate" meaning it is visible when compiling and then
  138. always executed. 
  139.  
  140.        compiler forth definitions
  141.  
  142.        : if ( -- ) compile (?branch) >mark ; compilation immediate
  143.  
  144. The "private" modifier is somewhat different. If concerns the
  145. visibility across vocabularies. If a word is marked as "private" 
  146. the word is only visible when the vocabulary in which it is defined
  147. in is "current". This means that if the vocabulary is not "current"
  148. and in the search chain "context" the word is not visible. This 
  149. is very close to the concept of hidden in modules and packages in Modula-2 
  150. and Ada.
  151.  
  152.        4 field +name ( entry -- name) private
  153.  
  154. The above definition will only be visible in the vocabulary it was 
  155. defined. This is useful to isolate implementation dependencies and reduce
  156. the name space.
  157.  
  158.  
  159. 3.     SOURCE LIBRARY
  160.  
  161. The TILE Forth programming environment contains a number of tools to make
  162. programming in Forth a bit easier. If you have GNU Emacs, TILE Forth 
  163. may run in a specialized forth-mode. This mode supports automatic 
  164. program indentation (pretty printing), documentation search, interactive and
  165. incremental program development. 
  166.  
  167. To aid program development there is also a source code library with
  168. documentation (glossary), and test and example code. Most of the source
  169. code are data modeling tools. In principle, from bit field definition to
  170. object oriented structures are available. The source code library also
  171. contains debugging tools for tracing, break-point'ing and profiling of 
  172. programs. 
  173.  
  174. The first level of data modeling tools are three modules for describing;
  175. 1) bit fields, 2) structures (records), and 3) aggregates of data (vectors,
  176. stacks, buffers, etc).
  177.  
  178. The next level of tools are some tools for high level syntactic sugar
  179. for multi-tasking concepts (semaphores, channels, etc), finite state
  180. machines (FSM), and anonymous code block (blocks).
  181.  
  182. The source library will be extended during the coming releases (see
  183. the release plan, file: RELEASES).
  184.  
  185.  
  186. 4.     PROGRAMMING STYLE
  187.  
  188. A source code module has, in general, the following structure; First 
  189. section includes any modules needed (theses are only loaded once).
  190. Second follows global definitions for the module. Normally this is 
  191. a vocabulary for the module. Third comes the search chain to be used
  192. throughout the module. It is important not to change the search order
  193. as 1) it becomes difficult for a reader to understand to code, 2)
  194. any change in the search chain flushes the internal lookup cache
  195. in TILE Forth.
  196.  
  197.        .( Loading the Library...) cr
  198.  
  199.        #include someLibrary.f83
  200.  
  201.        ( Global data and definitions)
  202.  
  203.        vocabulary theLibrary
  204.  
  205.        someLibrary theLibrary definitions
  206.  
  207.        ( Local data and definitions)
  208.  
  209.        : someDefinitions ( -- ) ... ; 
  210.        : somePrivateDefinitions ( -- ) ... ; private
  211.  
  212.        forth only
  213.  
  214. To create lexical level within the same vocabulary the word "restore" may
  215. be used. It stores the vocabulary pointer to the given entry and thus
  216. hides the words defined after this entry. The word "restore" has much the
  217. same action as "forget" but without putting back the dictionary pointer (dp).
  218.  
  219. Each module should also be documented according to the template documentation
  220. file. This format allows the documentation function to work properly.
  221.  
  222.  
  223. 5.     SOURCE FILES
  224.  
  225. The TILE Forth source is broken down into the following files:
  226.  
  227. tile
  228.    The TILE Forth source code and documentation library.
  229.  
  230. tile.1
  231.    Manual for "man" under Unix.
  232.  
  233. README
  234.    This short documentation of TILE.
  235.  
  236. COPYING
  237.    The GNU General Public License.
  238.  
  239. RELEASES
  240.    The current plan of source code releases.
  241.  
  242. PORTING
  243.    Some help on how to port TILE Forth and typical problems
  244.  
  245. Makefile
  246.    Allows a number of compilation styles for debugging, profiling, sharing
  247.    etc. New machines and conditional compilation symbols are added here.
  248.  
  249. forth.c
  250.    The main program using the multi-tasking kernel. Also gives access to
  251.    program arguments and start symbol.
  252.  
  253. forth.el
  254.    Forth Mode for GNU Emacs. Allows interactive program development in
  255.    EMACS and documentation search.
  256.  
  257. kernel.c..h
  258.    The multi-tasking Forth kernel. 
  259.  
  260. error.c..h
  261.    The signal and error handling package of TILE Forth.
  262.  
  263. io.c..h
  264.    The input and output management package of TILE Forth.
  265.  
  266. memory.c..h
  267.    Memory allocation package of TILE Forth.
  268.  
  269. src
  270.    The Forth source library with data description, high level tasking and
  271.    other tools.
  272.  
  273. tst
  274.    Test file for each Forth source code file and a set of benchmarks.
  275.  
  276. doc
  277.    Documentation and glossary for each source code file and kernel
  278.    vocabularies.
  279.  
  280. The documentation follow the C style and the glossary structure is used
  281. by the Forth Mode search function.
  282.  
  283.  
  284. 6.     CONFIGURATION
  285.  
  286. TILE forth is targeted for 32-bit machines and no special aid is available
  287. to allow it to be compiled for other bit-widths. The configuration is 
  288. maintained by a "make" files. 
  289.  
  290. The configuration file allows a number of different modes to support
  291. typical program development phases (on C level) such as debugging, 
  292. profiling, optimization and packaging. Please see the information in
  293. these files.
  294.  
  295.  
  296. 7.     COPYING
  297.  
  298. This software is offered as shareware. You may use it freely, but 
  299. if you do use it and find it useful, you are encouraged to send the
  300. author a contribution for the next project (an object oriented threaded
  301. interpreter -- `the flexibility of Smalltalk to the speed of Forth').
  302.  
  303. For further information about copying see the file COPYING and the
  304. header in each source code file.
  305.  
  306.  
  307. 8.     NOTE
  308.  
  309. Due to the 32-bit implementation in C a number of Forth definitions are 
  310. not confirmed. Below is a short list of words that might give problems
  311. when porting Forth code to this environment:
  312.  
  313. * The Block Word Set is not supported. Source code is saved as text files.
  314.  
  315. * All stacks and words size are 32-bit. Thus special care must be taken
  316.   with memory allocation and access.
  317.  
  318. * Lowercase and uppercase are distinguished, and all forth words are
  319.   lowercase. 
  320.  
  321. * A word in TILE is allowed arbitrary length as the name is stored as
  322.   as a null terminated string.
  323.  
  324. * Input such as key performs a traditional read operation to the
  325.   operation system thus will echo the characters.
  326.  
  327. * Variables should not allocate extra memory. "create" should be used.
  328.  
  329.  
  330. ACKNOWLEDGMENTS
  331.  
  332. First of all I wish to express my gratitude to Goran Rydqvist for helped
  333. me out with the first version of the kernel and who implemented the 
  334. forth-mode for GNU Emacs. 
  335.  
  336. Second a special thanks to the beta test group who gave me valuable
  337. feedback. Especially Mitch Bradley, Bob Giovannucci Jr., Moises Lejter, 
  338. and Brooks David Smith. 
  339.  
  340. Thank you all.
  341.  
  342.  
  343.  
  344.  
  345.