home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mitsch75.zip / scheme-7_5_17-src.zip / scheme-7.5.17 / src / microcode / dstack.h < prev    next >
C/C++ Source or Header  |  1999-01-03  |  7KB  |  193 lines

  1. /* -*-C-*-
  2.  
  3. $Id: dstack.h,v 1.9 1999/01/03 05:33:41 cph Exp $
  4.  
  5. Copyright (C) 1990-1999 Massachusetts Institute of Technology
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful, but
  13. WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. #ifndef __DSTACK_H__
  23. #define __DSTACK_H__
  24.  
  25. #include "ansidecl.h"
  26. #include <setjmp.h>
  27.  
  28. #ifndef _SUNOS4
  29. extern void
  30.   EXFUN (abort, (void)),
  31.   EXFUN (exit, (int)),
  32.   EXFUN (free, (void *));
  33. #endif
  34.  
  35. extern void EXFUN (dstack_initialize, (void));
  36. /* Call this once to initialize the stack. */
  37.  
  38. extern void EXFUN (dstack_reset, (void));
  39. /* Call this once to reset the stack. */
  40.  
  41. extern PTR EXFUN (dstack_alloc, (unsigned int length));
  42. /* Allocate a chunk of `length' bytes of space on the stack and return
  43.    a pointer to it. */
  44.  
  45. extern void EXFUN
  46.   (dstack_protect,
  47.    (void EXFUN ((*protector), (PTR environment)), PTR environment));
  48. /* Create an unwind protection frame that invokes `protector' when
  49.    the stack is unwound.  `environment' is passed to `protector' as
  50.    its sole argument when it is invoked. */
  51.  
  52. extern void EXFUN
  53.   (dstack_alloc_and_protect,
  54.    (unsigned int length,
  55.     void EXFUN ((*initializer), (PTR environment)),
  56.     void EXFUN ((*protector), (PTR environment))));
  57. /* Allocate a chunk of `length' bytes of space, call `initializer' to
  58.    initialize that space, and create an unwind protection frame that
  59.    invokes `protector' when the stack is unwound.  */
  60.  
  61. extern PTR dstack_position;
  62. /* The current stack pointer. */
  63.  
  64. extern void EXFUN (dstack_set_position, (PTR position));
  65. /* Unwind the stack to `position', which must be a previous value of
  66.    `dstack_position'. */
  67.  
  68. extern void EXFUN (dstack_bind, (PTR location, PTR value));
  69. /* Dynamically bind `location' to `value'.  `location' is treated as
  70.    `PTR*' -- it is declared `PTR' for programming convenience. */
  71.  
  72. enum transaction_action_type { tat_abort, tat_commit, tat_always };
  73.  
  74. extern void EXFUN (transaction_initialize, (void));
  75. extern void EXFUN (transaction_begin, (void));
  76. extern void EXFUN (transaction_abort, (void));
  77. extern void EXFUN (transaction_commit, (void));
  78. extern void EXFUN
  79.   (transaction_record_action,
  80.    (enum transaction_action_type type,
  81.     void EXFUN ((*procedure), (PTR environment)),
  82.     PTR environment));
  83.  
  84. typedef unsigned long Tptrvec_index;
  85. typedef unsigned long Tptrvec_length;
  86.  
  87. struct struct_ptrvec
  88. {
  89.   Tptrvec_length length;
  90.   PTR * elements;
  91. };
  92. typedef struct struct_ptrvec * Tptrvec;
  93.  
  94. #define PTRVEC_LENGTH(ptrvec) ((ptrvec) -> length)
  95. #define PTRVEC_REF(ptrvec, index) (((ptrvec) -> elements) [(index)])
  96. #define PTRVEC_LOC(ptrvec, index) (& (PTRVEC_REF ((ptrvec), (index))))
  97. #define PTRVEC_START(ptrvec) (PTRVEC_LOC ((ptrvec), 0))
  98. #define PTRVEC_END(ptrvec) (PTRVEC_LOC ((ptrvec), (PTRVEC_LENGTH (ptrvec))))
  99.  
  100. extern Tptrvec EXFUN (ptrvec_allocate, (Tptrvec_length length));
  101. extern void EXFUN (ptrvec_deallocate, (Tptrvec ptrvec));
  102. extern void EXFUN (ptrvec_set_length, (Tptrvec ptrvec, Tptrvec_length length));
  103. extern Tptrvec EXFUN (ptrvec_copy, (Tptrvec ptrvec));
  104. extern void EXFUN (ptrvec_adjoin, (Tptrvec ptrvec, PTR element));
  105. extern int EXFUN (ptrvec_memq, (Tptrvec ptrvec, PTR element));
  106. extern void EXFUN
  107.   (ptrvec_move_left,
  108.    (Tptrvec source, Tptrvec_index source_start, Tptrvec_index source_end,
  109.     Tptrvec target, Tptrvec_index target_start));
  110. extern void EXFUN
  111.   (ptrvec_move_right,
  112.    (Tptrvec source, Tptrvec_index source_start, Tptrvec_index source_end,
  113.     Tptrvec target, Tptrvec_index target_start));
  114.  
  115. typedef struct condition_type * Tcondition_type;
  116. typedef struct condition * Tcondition;
  117. typedef struct condition_restart * Tcondition_restart;
  118.  
  119. struct condition_type
  120. {
  121.   unsigned long index;
  122.   PTR name;
  123.   Tptrvec generalizations;
  124.   void EXFUN ((*reporter), (Tcondition));
  125. };
  126. #define CONDITION_TYPE_INDEX(type) ((type) -> index)
  127. #define CONDITION_TYPE_NAME(type) ((type) -> name)
  128. #define CONDITION_TYPE_GENERALIZATIONS(type) ((type) -> generalizations)
  129. #define CONDITION_TYPE_REPORTER(type) ((type) -> reporter)
  130.  
  131. struct condition
  132. {
  133.   Tcondition_type type;
  134.   Tptrvec irritants;
  135. };
  136. #define CONDITION_TYPE(condition) ((condition) -> type)
  137. #define CONDITION_IRRITANTS(condition) ((condition) -> irritants)
  138.  
  139. struct condition_restart
  140. {
  141.   PTR name;
  142.   Tcondition_type type;
  143.   void EXFUN ((*procedure), (PTR));
  144. };
  145. #define CONDITION_RESTART_NAME(restart) ((restart) -> name)
  146. #define CONDITION_RESTART_TYPE(restart) ((restart) -> type)
  147. #define CONDITION_RESTART_PROCEDURE(restart) ((restart) -> procedure)
  148.  
  149. /* Allocate and return a new condition type object. */
  150. extern Tcondition_type EXFUN
  151.   (condition_type_allocate,
  152.    (PTR name,
  153.     Tptrvec generalizations,
  154.     void EXFUN ((*reporter), (Tcondition condition))));
  155.  
  156. /* Deallocate the condition type object `type'. */
  157. extern void EXFUN (condition_type_deallocate, (Tcondition_type type));
  158.  
  159. /* Allocate and return a new condition object. */
  160. extern Tcondition EXFUN
  161.   (condition_allocate, (Tcondition_type type, Tptrvec irritants));
  162.  
  163. /* Deallocate the condition object `condition'. */
  164. extern void EXFUN (condition_deallocate, (Tcondition condition));
  165.  
  166. /* Bind a handler for the condition type object `type'. */
  167. extern void EXFUN
  168.   (condition_handler_bind,
  169.    (Tcondition_type type, void EXFUN ((*handler), (Tcondition condition))));
  170.  
  171. /* Signal `condition'. */
  172. extern void EXFUN (condition_signal, (Tcondition condition));
  173.  
  174. /* Bind a restart called `name' for the condition type object `type'.
  175.    Invoking the restart causes `restart_procedure' to be executed. */
  176. extern void EXFUN
  177.   (condition_restart_bind,
  178.    (PTR name,
  179.     Tcondition_type type,
  180.     void EXFUN ((*procedure), (PTR argument))));
  181.  
  182. /* Find a restart called `name' that matches `condition'.
  183.    If `condition' is 0, any restart called `name' will do.
  184.    If no such restart exists, 0 is returned. */
  185. extern Tcondition_restart EXFUN
  186.   (condition_restart_find, (PTR name, Tcondition condition));
  187.  
  188. /* Return a ptrvec of the restarts that match `condition'.
  189.    If `condition' is 0, all restarts are returned. */
  190. extern Tptrvec EXFUN (condition_restarts, (Tcondition condition));
  191.  
  192. #endif /* __DSTACK_H__ */
  193.