home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume9 / teco / part01 / teco_data.doc < prev    next >
Text File  |  1987-03-11  |  5KB  |  93 lines

  1. A few quick comments on the ways teco arranges its internal
  2. data storage
  3.  
  4.   Teco has two classes of buffer:
  5.     1. Text buffer (the text buffer, q-registers, the command string)
  6.     2. Other (buffer header, buffer pointer, iteration-stack entry)
  7.  
  8.  
  9. Text buffers
  10.  
  11.   Each text buffer is a linked list of cells; this is a convenient
  12. way to divide a single address space among an arbitrary number of
  13. buffers of arbitrary size.  Each cell ("struct buffcell") contains a
  14. forward pointer, a backward pointer, and an array of characters.
  15. The teco buffer, each q-register, each entry on the q-register
  16. pushdown list, and the command string are lists of these cells.
  17.  
  18.   Teco maintains a list of free buffer cells, and its storage
  19. allocation routines furnish cells when needed and accept returned
  20. ones.  If the list of free cells is empty, teco calls malloc() to
  21. get a block of storage which it then divides into cells.  Teco never
  22. returns the storage it gets from malloc().
  23.  
  24.   The text buffer is kept in packed form: each cell but the last
  25. contains the full number of characters.  This makes it easy for teco
  26. to find its way through the buffer but increases the time taken by
  27. insert and delete.  It might be interesting to add a "count" field
  28. to the buffer cell and allow cells within the buffer to have empty
  29. spaces at the end; this is a possible future modification.
  30.  
  31.  
  32. Other
  33.  
  34.   Teco uses three types of small data cell - the q-register header
  35. ("struct qh"), the q-register pointer ("struct qp"), and the macro
  36. iteration list entry ("struct is").  Although defined as separate
  37. structures, these are really the same basic cell: they are kept as
  38. a list of free cells and cast to the proper definition when needed.
  39.  
  40.   As in the case of text-buffer cells, data cells are supplied by and
  41. returned to teco's storage allocation routines.  When a data cell is
  42. needed and no free cells are available, the storage allocator obtains
  43. a text buffer cell and carves it up into smaller cells, thus, the text-
  44. buffer cell system is the only interface to malloc().
  45.  
  46.   A text-buffer header ("struct qh") consists of a forward pointer that
  47. points to the first cell of the buffer, a backward pointer that is NULL,
  48. a count of characters, and an integer value - the "value" of a numeric
  49. q-register.  The teco buffer has a named header named buff; the q-registers
  50. have an array, named qreg[], of headers.  
  51.  
  52.     NOTE that the "struct qh" and the "struct buffcell" begin
  53.     identically: the forward and backward pointers are in
  54.     the same locations in both structures.  Teco uses this in
  55.     handling lists: because the buffer header appears to be a
  56.     buffer cell, inserting a cell at the beginning of a list is
  57.     the same as inserting one farther down.  This is probably a
  58.     bad implementation and may not work on all machines.
  59.  
  60.   A q-register pointer ("struct qp") points to a place within a text
  61. buffer or q-register or the command string.  It has a pointer to the
  62. current buffer cell, a value of the current character within the cell,
  63. values for the number of characters in the buffer and the number of the
  64. current character, and, if it is a macro-stack entry, a pointer to the
  65. iteration stack for that macro.
  66.  
  67.   A number of q-register pointers are used as general temporaries, for
  68. moving text within the buffer, outputting text, etc.  A stack of these
  69. pointers, the macro stack mstack[], controls the execution of command
  70. strings and macros.  The stack's first entry always points to the command
  71. string, and a new entry is pushed each time a macro is invoked and is
  72. popped when the macro terminates.
  73.  
  74.   An iteration-stack entry ("struct is") maintains the data needed for
  75. command-string or macro iteration.  Each command or macro level can
  76. have an iteration stack associated with it: this is kept as a linked
  77. list of iteration-stack entries, and the macro stack entry contains a
  78. pointer to the head of the list.  Each iteration-stack entry contains
  79. forward and backward pointers for the iteration stack, a pointer
  80. (cell address, character offset, absolute character count) to the
  81. command that starts the iteration, a count of iterations remaining,
  82. and a flag for definite/indefinite iteration.
  83.  
  84.   An iteration stack is created for a particular command or macro level
  85. the first time that a loop is encountered at that level.  The cells of
  86. the stack are not reclaimed but are reused the next time an iteration
  87. occurs at that command level.
  88.  
  89.   The data definitions specify two more data-structure types, a macro
  90. stack entry ("struct ms") and a buffer header list entry ("struct bh").
  91. These are not used at present.
  92.  
  93.