home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / utilities / utilss / siod / !Siod / Docs / siod_doc < prev    next >
Text File  |  1993-03-01  |  22KB  |  633 lines

  1.  *                   COPYRIGHT (c) 1988-1992 BY                             *
  2.  *        PARADIGM ASSOCIATES INCORPORATED, CAMBRIDGE, MASSACHUSETTS.       *
  3.  *        See the source file SLIB.C for more information.                  *
  4.  
  5. Documentation for Release 2.9 21-MAR-92, George Carrette
  6.  
  7. [Release Notes:]
  8.  
  9. 1.4 This release is functionally the same as release 1.3 but has been
  10. remodularized in response to people who have been encorporating SIOD
  11. as an interpreted extension language in other systems.
  12.  
  13. 1.5 Added the -g flag to enable mark-and-sweep garbage collection.
  14.     The default is stop-and-copy.
  15.  
  16. 2.0 Set_Repl_Hooks, catch & throw. 
  17.  
  18. 2.1 Additions to SIOD.SCM: Backquote, cond.
  19.  
  20. 2.2 User Type extension. Read-Macros. (From C-programmer level).
  21.  
  22. 2.3 save-forms. load with argument t, comment character, faster intern.
  23.     -o flag gives obarray size. default 100.
  24.  
  25. 2.4 speed up arithmetic and the evaluator. fixes to siod.scm. no_interrupt
  26.     around calls to C I/O. gen_readr.
  27.  
  28. 2.5 numeric arrays in siod.c
  29.  
  30. 2.6 remodularize .h files, procedure prototypes. gc, eval, print hooks
  31.     now table-driven.
  32.  
  33. 2.7 hash tables, fasload.
  34.  
  35. 2.8 bug fixes.
  36.  
  37. 2.9 added trace.c, fseek, ftell, some fixes.
  38.  
  39. gjc@paradigm.com, gjc@mitech.com
  40. George Carrette
  41.  
  42.    
  43. Paradigm Associates Inc          Phone: 617-492-6079
  44. 29 Putnam Ave, Suite 6
  45. Cambridge, MA 02138
  46.  
  47. [Files:]
  48.  
  49.  siod.h    Declarations 
  50.  siodp.h   private declarations.
  51.  slib.c    scheme library.
  52.  sliba.c   array library.
  53.  siod.c    a main program.
  54.  trace.c   an optional trace package.
  55.  siod.scm  Some scheme code
  56.  pratt.scm A pratt-parser in scheme.
  57.  
  58.  
  59. [Motivation:]
  60.  
  61. The most obvious thing one should notice is that this lisp implementation 
  62. is extremely small. For example, the resulting binary executable file 
  63. on a VAX/VMS system with /notraceback/nodebug is 17 kilo-bytes.
  64.  
  65. Small enough to understand, the source file slib.c is 30 kilo-bytes.
  66.  
  67. Small enough to include in the smallest applications which require
  68. command interpreters or extension languages.
  69.  
  70. We also want to be able to run code from the book "Structure and
  71. Interpretation of Computer Programs." 
  72.  
  73. Techniques used will be familiar to most lisp implementors.  Having
  74. objects be all the same size, and having only two statically allocated
  75. spaces simplifies and speeds up both consing and gc considerably.  the
  76. MSUBR hack allows for a modular implementation of tail recursion,     
  77. an extension of the FSUBR that is, as far as I know, original.
  78. The optional mark and sweep garbage collector may be selected at runtime.
  79.  
  80. Error handling is rather crude. A topic taken with machine fault,
  81. exception handling, tracing, debugging, and state recovery which we
  82. could cover in detail, but is clearly beyond the scope of this
  83. implementation. Suffice it to say that if you have a good symbolic
  84. debugger you can set a break point at "err" and observe in detail all
  85. the arguments and local variables of the procedures in question, since
  86. there is no casting of data types. For example, if X is an offending
  87. or interesting object then examining X->type will give you the type,
  88. and X->storage_as.cons will show the car and the cdr.
  89.  
  90. [Invocation:]
  91.  
  92. siod [-hXXXXX] [-iXXXXX] [-gX] [-oXXXXX] [-nXXXXX] [-sXXXXX]
  93.  -h where XXXXX is an integer, to specify the heap size, in obj cells,
  94.  -i where XXXXX is a filename to load before going into the repl loop.
  95.  -g where X = 1 for stop-and-copy GC, X = 0 for mark-and-sweep.
  96.  -o where XXXXX is the size of the symbol hash table to use, default 100.
  97.  -n where XXXXX is the number of preconsed/interned non-negative numbers.
  98.  -s where XXXXX is the number of bytes of machine recursion stack.
  99.  
  100.   Example:
  101.    siod -isiod.scm -h100000
  102.  
  103. [Garbage Collection:]
  104.  
  105. There are two storage management techniques which may be chosen at runtime
  106. by specifying the -g argument flag. 
  107.  
  108.  -g1 (the default) is stop-and-copy. This is the simplest and most
  109.      portable implementation. GC is only done at toplevel.
  110.  -g0 is mark-and-sweep. GC is done at any time, required or requested.
  111.      However, the implementation is not as portable.
  112.  
  113. Discussion of stop-and-copy follows:
  114.  
  115. As one can see from the source, garbage collection is really quite an easy
  116. thing. The procedure gc_relocate is about 25 lines of code, and
  117. scan_newspace is about 15.
  118.  
  119. The real tricks in handling garbage collection are (in a copying gc):
  120.  (1) keeping track of locations containing objects
  121.  (2) parsing the heap (in the space scanning)
  122.  
  123. The procedure gc_protect is called once (e.g. at startup) on each
  124. "global" location which will contain a lisp object.
  125.  
  126. That leaves the stack. Now, if we had chosen not to use the argument
  127. and return-value passing mechanism provided by the C-language
  128. implementation, (also known as the "machine stack" and "machine
  129. procedure calling mechanism) this lisp would be larger, slower, and
  130. rather more difficult to read and understand. Furthermore it would be
  131. considerably more painful to *add* functionality in the way of SUBR's
  132. to the implementation.
  133.  
  134. Aside from writing a very machine and compiler specific assembling language
  135. routine for each C-language implementation, embodying assumptions about
  136. the placement choices for arguments and local values, etc, we
  137. are left with the following limitation: "YOU CAN GC ONLY AT TOP-LEVEL"
  138.  
  139. However, this fits in perfectly with the programming style imposed in
  140. many user interface implementations including the MIT X-Windows Toolkit.
  141. In the X Toolkit, a callback or work procedure is not supposed to spend
  142. much time implementing the action. Therefore it cannot have allocated
  143. much storage, and the callback trampoline mechanism can post a work
  144. procedure to call the garbage collector when needed.
  145.  
  146. Our simple object format makes parsing the heap rather trivial.
  147. In more complex situations one ends up requiring object headers or markers
  148. of some kind to keep track of the actual storage lengths of objects
  149. and what components of objects are lisp pointers.
  150.  
  151. Because of the usefulness of strings, they were added by default into
  152. SIOD 2.6. The implementation requires a hook that calls the C library
  153. memory free procedure when an object is in oldspace and never
  154. got relocated to newspace. Obviously this slows down the mark-and-sweep
  155. GC, and removes one of the usual advantages it has over mark-and-sweep.
  156.  
  157. Discussion of mark-and-sweep follows:
  158.  
  159. In a mark-and-sweep GC the objects are not relocated. Instead
  160. one only has to LOOK at objects which are referenced by the argument
  161. frames and local variables of the underlying (in this case C-coded)
  162. implementation procedures. If a pointer "LOOKS" like it is a valid
  163. lisp object (see the procedure mark_locations_array) then it may be marked,
  164. and the objects it points to may be marked, as being in-use storage which
  165. is not linked into the freelist in the gc_sweep phase.
  166.  
  167. Another advantage of the mark_and_sweep storage management technique is
  168. that only one heap is required.
  169.  
  170. This main disadvantages are:
  171. (1) start-up cost to initially link freelist.
  172.     (can be avoided by more general but slower NEWCELL code).
  173. (2) does not COMPACT or LOCALIZE the use of storage. This is poor engineering
  174.     practice in a virtual memory environment.
  175. (2) the entire heap must be looked at, not just the parts with useful storage.
  176.  
  177. In general, mark-and-sweep is slower in that it has to look at more
  178. memory locations for a given heap size, however the heap size can
  179. be smaller for a given problem being solved. More complex analysis
  180. is required when READ-ONLY, STATIC, storage spaces are considered.
  181. Additionally the most sophisticated stop-and-copy storage management
  182. techniques take into account considerations of object usage temporality.
  183.  
  184. The technique assumes that all machine registers the GC needs to
  185. look at will be saved by a setjmp call into the save_regs_gc_mark data.
  186.  
  187. [Compilation:]
  188.  
  189. This code (version 2.7) has been compiled and run under the following:
  190. - SUN-IV,      GCC (GNU C)
  191. - VAX/VMS,     VAXC
  192. - MacIntosh,   THINK C 5.0
  193.  
  194. Earlier versions were compiled and run on the AMIGA, Encore, and 4.3BSD.
  195. There are reports that the code will also compile and run under MS-DOS.
  196.  
  197. On all unix machines use (with floating-point flags as needed)
  198.   
  199.   %cc -O -c siod.c
  200.   %cc -O -c slib.c
  201.   %