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 / history.h < prev    next >
C/C++ Source or Header  |  1999-01-02  |  5KB  |  150 lines

  1. /* -*-C-*-
  2.  
  3. $Id: history.h,v 9.29 1999/01/02 06:11:34 cph Exp $
  4.  
  5. Copyright (c) 1987, 1988, 1989, 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. /* History maintenance data structures and support. */
  23.  
  24. /* The history consists of a "vertebra" which is a doubly linked ring,
  25.    each entry pointing to a "rib".  The rib consists of a singly
  26.    linked ring whose entries contain expressions and environments. */
  27.  
  28. #define HIST_RIB        0
  29. #define HIST_NEXT_SUBPROBLEM    1
  30. #define HIST_PREV_SUBPROBLEM    2
  31. #define HIST_MARK        1
  32.  
  33. #define RIB_EXP            0
  34. #define RIB_ENV            1
  35. #define RIB_NEXT_REDUCTION    2
  36. #define RIB_MARK        2
  37.  
  38. #define HISTORY_MARK_TYPE (UNMARKED_HISTORY_TYPE ^ MARKED_HISTORY_TYPE)
  39. #define HISTORY_MARK_MASK (HISTORY_MARK_TYPE << DATUM_LENGTH)
  40.  
  41. #if ((UNMARKED_HISTORY_TYPE | HISTORY_MARK_TYPE) != MARKED_HISTORY_TYPE)
  42. #include "error: Bad history types in types.h and history.h"
  43. #endif
  44.  
  45. #define HISTORY_MARK(object) (object) |= HISTORY_MARK_MASK
  46. #define HISTORY_UNMARK(object) (object) &=~ HISTORY_MARK_MASK
  47. #define HISTORY_MARKED_P(object) (((object) & HISTORY_MARK_MASK) != 0)
  48.  
  49. /* Save_History places a restore history frame on the stack. Such a
  50.    frame consists of a normal continuation frame plus a pointer to the
  51.    stacklet on which the last restore history is located and the
  52.    offset within that stacklet.  If the last restore history is in
  53.    this stacklet then the history pointer is #F to signify this.  If
  54.    there is no previous restore history then the history pointer is #F
  55.    and the offset is 0. */
  56.  
  57. #define Save_History(Return_Code)                    \
  58. {                                    \
  59.   STACK_PUSH                                \
  60.     ((Prev_Restore_History_Stacklet == NULL)                \
  61.      ? SHARP_F                                \
  62.      : (MAKE_POINTER_OBJECT                        \
  63.     (TC_CONTROL_POINT, Prev_Restore_History_Stacklet)));        \
  64.   STACK_PUSH (LONG_TO_UNSIGNED_FIXNUM (Prev_Restore_History_Offset));    \
  65.   Store_Expression                            \
  66.     (MAKE_POINTER_OBJECT (UNMARKED_HISTORY_TYPE, History));        \
  67.   Store_Return (Return_Code);                        \
  68.   Save_Cont ();                                \
  69.   History = (OBJECT_ADDRESS (Get_Fixed_Obj_Slot (Dummy_History)));    \
  70. }
  71.  
  72. /* History manipulation in the interpreter. */
  73.  
  74. #ifndef DISABLE_HISTORY
  75.  
  76. #define New_Subproblem(expression, environment)                \
  77. {                                    \
  78.   History = (OBJECT_ADDRESS (History [HIST_NEXT_SUBPROBLEM]));        \
  79.   HISTORY_MARK (History [HIST_MARK]);                    \
  80.   {                                    \
  81.     fast SCHEME_OBJECT * Rib = (OBJECT_ADDRESS (History [HIST_RIB]));    \
  82.     HISTORY_MARK (Rib [RIB_MARK]);                    \
  83.     (Rib [RIB_ENV]) = (environment);                    \
  84.     (Rib [RIB_EXP]) = (expression);                    \
  85.   }                                    \
  86. }
  87.  
  88. #define Reuse_Subproblem(expression, environment)            \
  89. {                                    \
  90.   fast SCHEME_OBJECT * Rib = (OBJECT_ADDRESS (History [HIST_RIB]));    \
  91.   HISTORY_MARK (Rib [RIB_MARK]);                    \
  92.   (Rib [RIB_ENV]) = (environment);                    \
  93.   (Rib [RIB_EXP]) = (expression);                    \
  94. }
  95.  
  96. #define New_Reduction(expression, environment)                \
  97. {                                    \
  98.   fast SCHEME_OBJECT * Rib =                        \
  99.     (OBJECT_ADDRESS                            \
  100.      (FAST_MEMORY_REF ((History [HIST_RIB]), RIB_NEXT_REDUCTION)));    \
  101.   (History [HIST_RIB]) =                        \
  102.     (MAKE_POINTER_OBJECT (UNMARKED_HISTORY_TYPE, Rib));            \
  103.   (Rib [RIB_ENV]) = (environment);                    \
  104.   (Rib [RIB_EXP]) = (expression);                    \
  105.   HISTORY_UNMARK (Rib [RIB_MARK]);                    \
  106. }
  107.  
  108. #define End_Subproblem()                        \
  109. {                                    \
  110.   HISTORY_UNMARK (History [HIST_MARK]);                    \
  111.   History = (OBJECT_ADDRESS (History [HIST_PREV_SUBPROBLEM]));        \
  112. }
  113.  
  114. #else /* DISABLE_HISTORY */
  115.  
  116. #define New_Subproblem(Expr, Env) {}
  117. #define Reuse_Subproblem(Expr, Env) {}
  118. #define New_Reduction(Expr, Env) {}
  119. #define End_Subproblem() {}
  120.  
  121. #endif /* DISABLE_HISTORY */
  122.  
  123. /* History manipulation for the compiled code interface. */
  124.  
  125. #ifndef DISABLE_HISTORY
  126.  
  127. #define Compiler_New_Reduction()                    \
  128. {                                    \
  129.   New_Reduction                                \
  130.     (SHARP_F,                                \
  131.      (MAKE_OBJECT (TC_RETURN_CODE, RC_POP_FROM_COMPILED_CODE)));    \
  132. }
  133.  
  134. #define Compiler_New_Subproblem()                    \
  135. {                                    \
  136.   New_Subproblem                            \
  137.     (SHARP_F,                                \
  138.      (MAKE_OBJECT (TC_RETURN_CODE, RC_POP_FROM_COMPILED_CODE)));    \
  139. }
  140.  
  141. #define Compiler_End_Subproblem End_Subproblem
  142.  
  143. #else /* DISABLE_HISTORY */
  144.  
  145. #define Compiler_New_Reduction()
  146. #define Compiler_New_Subproblem()
  147. #define Compiler_End_Subproblem()
  148.  
  149. #endif /* DISABLE_HISTORY */
  150.