home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / fweb153.zip / fweb-1.53 / web / texts.hweb < prev    next >
Text File  |  1995-09-23  |  4KB  |  88 lines

  1. @z --- texts.hweb ---
  2.  
  3. FWEB version 1.53 (September 23, 1995)
  4.  
  5. Based on version 0.5 of S. Levy's CWEB [copyright (C) 1987 Princeton University]
  6.  
  7. @x-----------------------------------------------------------------------------
  8.  
  9. @* DATA STRUCTURES EXCLUSIVE to FTANGLE.  
  10. We've already seen that the |byte_mem| array holds the names of
  11. identifiers, strings, and modules; the |tok_mem| array holds the
  12. replacement texts for modules and macros.  Allocation is sequential, since
  13. things are deleted only during Phase II, and only in a last-in-first-out
  14. manner.
  15.  
  16. A \&{text} variable is a structure containing a pointer |tok_start| into
  17. |tok_mem|, which tells where the corresponding text starts, and an integer
  18. |text_link|, which, as we shall see later, is used to connect pieces of
  19. text that have the same name.  Additional entries keep track of the
  20. language that referenced the name (|Language|), the number |nargs| of
  21. arguments if it is a macro, and the offset |moffset| of the macro
  22. replacement text from the start (namely, after the right paren of the
  23. argument list or after the blank space if there are no arguments).  All the
  24. \&{text}s are stored in the array |text_info|, and we use a |text_pointer|
  25. variable to refer to them.
  26.  
  27. The first position of |tok_mem| that is unoccupied by replacement text is
  28. called |tok_ptr|, and the first unused location of |text_info| is called
  29. |text_ptr|.  Thus we usually have the identity
  30. |text_ptr->tok_start=tok_ptr|.
  31.  
  32. In fact, there are two kinds of macros, immediate and deferred. The
  33. immediate ones are defined in the definition section and are processed
  34. during phase~1; these can be entered sequentially into |tok_mem|. The
  35. deferred ones, however, are not processed until phase~2, after the code has
  36. been shuffled around. Since they must be read during phase~1, however, they
  37. must be stored somewhere, and it is convenient to put them into a separate
  38. place---the deferred pool---than the code text that is being built at the
  39. moment the deferred macro definition is encountered. Thus, we have the
  40. deferred variables |text_infod|, |tok_memd|, etc.
  41.  
  42. @<Typed...@>=
  43.  
  44. typedef struct 
  45.   {
  46.   eight_bits HUGE *tok_start; /* Pointer into |tok_mem| (for a module or
  47. regular macro).  For an internal macro, points to the internal function. */
  48.   sixteen_bits text_link; // Relates replacement texts  (0 for a macro).
  49.   boolean Language; // Which language referenced this name.
  50.   eight_bits nargs;    // Number of macro arguments.
  51.   unsigned moffset:8,    // Offset to macro replacement text from start.
  52.     recursive:1, // Is this macro allowed to be recursive?
  53.     var_args:1, // Can it have variable number of arguments?
  54.     module_text:1, // Distinguishes from preprocessor fragment.
  55.     built_in:1;    // Is it a built-in function (internal macro)?
  56.   } text;
  57.  
  58. typedef text HUGE *text_pointer;
  59.  
  60. @<Glob...@>=
  61.  
  62. EXTERN long max_texts;    // Number of replacement texts, must be $< 10240$.
  63. EXTERN text HUGE *text_info; // Dynamic array.
  64. EXTERN text_pointer text_end; // End of above.
  65.  
  66. EXTERN long dtexts_max; // Number of deferred replacement texts.
  67. EXTERN text HUGE *txt_dinfo; // Dynamic array.
  68. EXTERN text_pointer textd_end;
  69.  
  70. EXTERN text_pointer text_ptr,txt_dptr; /* First unused position in |text_info|
  71.                     and in |txt_dinfo|. */
  72.  
  73. EXTERN long max_toks; // Number of bytes in compressed code.
  74. EXTERN eight_bits HUGE *tok_mem; // Dynamic array.
  75. EXTERN eight_bits HUGE *tok_m_end;
  76.  
  77. EXTERN long max_dtoks; // Number of bytes in deferred macros.
  78. EXTERN eight_bits HUGE *tok_dmem; // Dynamic array.
  79. EXTERN eight_bits HUGE *tokd_end;
  80.  
  81. EXTERN eight_bits HUGE *tok_ptr, HUGE *tok_dptr; /* First unused position in
  82.             |tok_mem| and in |tok_dmem|. */
  83. EXTERN eight_bits HUGE *mx_tok_ptr, HUGE *mx_dtok_ptr; /* Largest value
  84.     assumed by |tok_ptr|  and |tok_ptrd|; for statistics. */
  85.  
  86. EXTERN text_pointer macro_text;
  87.