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

  1. @z --- stacks.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. @* STACKS for OUTPUT.  The output process uses a stack to keep track
  10. of what is going on at different ``levels'' as the modules are being
  11. written out.  Entries on this stack have a number of parts:
  12.  
  13. \yskip\hang |end_field| is the |tok_mem| location where the replacement
  14. text of a particular level will end;
  15.  
  16. \hang |byte_field| is the |tok_mem| location from which the next token
  17. on a particular level will be read;
  18.  
  19. \hang |name_field| points to the name corresponding to a particular level;
  20.  
  21. \hang |repl_field| points to the replacement text currently being read
  22. at a particular level.
  23.  
  24. \hang |mod_field| is the module number, or zero if this is a macro.
  25.  
  26. \hang |global_Language| is the overriding language for the module and its
  27. extensions. 
  28.  
  29. \hang |Language| is the current language for the module. It will differ
  30. from |global_Language| if a language command was encountered in the middle
  31. of the module.
  32.  
  33. \hang |macro_buf| is the current scratch space for the macro processor;
  34. |macro_buf_end| is its end.
  35.  
  36. \yskip\noindent The current values of these nine quantities are referred
  37. to quite frequently, so they are stored in a separate place (|cur_state|)
  38. instead of in the |stack| array. We call the current values |cur_end|,
  39. |cur_byte|, |cur_name|, |cur_repl|, |cur_mod|, |cur_global_language|, and
  40. |cur_language|.
  41.  
  42. The global variable |stack_ptr| tells how many levels of output are
  43. currently in progress. The end of all output occurs when the stack is
  44. empty, i.e., when |stack_ptr=stack|.
  45.  
  46. @<Typed...@>=
  47.  
  48. typedef struct {
  49.   eight_bits HUGE *end_field; // Ending location of replacement text.
  50.   eight_bits HUGE *byte_field; // Present location within replacement text.
  51.   name_pointer name_field; // |byte_start| index for text being output.
  52.   text_pointer repl_field; // |tok_start| index for text being output.
  53.   sixteen_bits mod_field; // Module number, or zero if not a module.
  54.   PARAMS global_params,params; // Various flags.
  55.   eight_bits HUGE *macro_buf, HUGE *macro_buf_end; // Current macro buffer.
  56. } output_state;
  57.  
  58. typedef output_state HUGE *stack_pointer;
  59.  
  60. @ Here are the synonyms for the current values of the stack.
  61.  
  62. @d cur_end cur_state.end_field // Current ending location in |tok_mem|.
  63. @d cur_byte cur_state.byte_field // Location of next output byte in |tok_mem|.
  64. @d cur_name cur_state.name_field // Pointer to current name being expanded.
  65. @d cur_repl cur_state.repl_field // Pointer to current replacement text.
  66. @d cur_mod cur_state.mod_field // Current module number being expanded.
  67.  
  68. @d cur_language cur_state.language // Current language.
  69. @d cur_global_language cur_state.global_params.Language 
  70.     // Global language for this level.
  71.  
  72. /* Current flags. */
  73. @d cur_params cur_state.params //  Local flags.
  74. @d cur_global_params cur_state.global_params //  Global flags.
  75.  
  76. /* Current macro buffer params. */
  77. @d macrobuf cur_state.macro_buf
  78. @d macrobuf_end cur_state.macro_buf_end
  79.  
  80. @<Global...@>=
  81.  
  82. EXTERN output_state cur_state; /* |cur_end|, |cur_byte|, |cur_name|,
  83.     |cur_repl|, |cur_mod|, |cur_global_language|, and |cur_language|. */
  84.  
  85. EXTERN long stck_size; // Number of simultaneous levels of macro expansion.
  86. EXTERN output_state HUGE *stack; // Dynamic array: Info for non-current levels.
  87. EXTERN stack_pointer stck_end; // End of |stack|.
  88. EXTERN stack_pointer stck_ptr; // First unused loc.\ in the output state stack.
  89.