stacks.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* classes: h_files */
  2. #ifndef SCM_STACKS_H
  3. #define SCM_STACKS_H
  4. /* Copyright (C) 1995,1996,2000,2001 Free Software Foundation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this software; see the file COPYING. If not, write to
  18. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19. * Boston, MA 02110-1301 USA
  20. *
  21. * As a special exception, the Free Software Foundation gives permission
  22. * for additional uses of the text contained in its release of GUILE.
  23. *
  24. * The exception is that, if you link the GUILE library with other files
  25. * to produce an executable, this does not by itself cause the
  26. * resulting executable to be covered by the GNU General Public License.
  27. * Your use of that executable is in no way restricted on account of
  28. * linking the GUILE library code into it.
  29. *
  30. * This exception does not however invalidate any other reasons why
  31. * the executable file might be covered by the GNU General Public License.
  32. *
  33. * This exception applies only to the code released by the
  34. * Free Software Foundation under the name GUILE. If you copy
  35. * code from other Free Software Foundation releases into a copy of
  36. * GUILE, as the General Public License permits, the exception does
  37. * not apply to the code that you add in this way. To avoid misleading
  38. * anyone as to the status of such modified files, you must delete
  39. * this exception notice from them.
  40. *
  41. * If you write modifications of your own for GUILE, it is your choice
  42. * whether to permit this exception to apply to your modifications.
  43. * If you do not wish that, delete this exception notice.
  44. *
  45. * The author can be reached at djurfeldt@nada.kth.se
  46. * Mikael Djurfeldt, SANS/NADA KTH, 10044 STOCKHOLM, SWEDEN */
  47. #include "libguile/__scm.h"
  48. /* {Frames and stacks}
  49. */
  50. typedef struct scm_t_info_frame {
  51. /* SCM flags; */
  52. scm_t_bits flags;
  53. SCM source;
  54. SCM proc;
  55. SCM args;
  56. } scm_t_info_frame;
  57. #define SCM_FRAME_N_SLOTS (sizeof (scm_t_info_frame) / sizeof (SCM))
  58. #define SCM_STACK(obj) ((scm_t_stack *) SCM_STRUCT_DATA (obj))
  59. #define SCM_STACK_LAYOUT "pwuourpW"
  60. typedef struct scm_t_stack {
  61. SCM id; /* Stack id */
  62. scm_t_info_frame *frames; /* Info frames */
  63. unsigned long length; /* Stack length */
  64. unsigned long tail_length;
  65. scm_t_info_frame tail[1];
  66. } scm_t_stack;
  67. #if (SCM_DEBUG_DEPRECATED == 0)
  68. # define scm_info_frame scm_t_info_frame
  69. # define scm_stack scm_t_stack
  70. #endif
  71. extern SCM scm_stack_type;
  72. #define SCM_STACKP(obj) (SCM_STRUCTP (obj) && SCM_EQ_P (SCM_STRUCT_VTABLE (obj), scm_stack_type))
  73. #define SCM_STACK_LENGTH(stack) (SCM_STACK (stack) -> length)
  74. #define SCM_FRAMEP(obj) \
  75. (SCM_CONSP (obj) && SCM_STACKP (SCM_CAR (obj)) \
  76. && SCM_INUMP (SCM_CDR (obj)) && SCM_INUM (SCM_CDR (obj)) >= 0 \
  77. && ((unsigned long int) SCM_INUM (SCM_CDR (obj)) \
  78. < SCM_STACK_LENGTH (SCM_CAR (obj))))
  79. #define SCM_FRAME_REF(frame, slot) \
  80. (SCM_STACK (SCM_CAR (frame)) -> frames[SCM_INUM (SCM_CDR (frame))].slot) \
  81. #define SCM_FRAME_NUMBER(frame) \
  82. (SCM_BACKWARDS_P \
  83. ? SCM_INUM (SCM_CDR (frame)) \
  84. : (SCM_STACK_LENGTH (SCM_CAR (frame)) \
  85. - SCM_INUM (SCM_CDR (frame)) \
  86. - 1)) \
  87. #define SCM_FRAME_FLAGS(frame) SCM_FRAME_REF (frame, flags)
  88. #define SCM_FRAME_SOURCE(frame) SCM_FRAME_REF (frame, source)
  89. #define SCM_FRAME_PROC(frame) SCM_FRAME_REF (frame, proc)
  90. #define SCM_FRAME_ARGS(frame) SCM_FRAME_REF (frame, args)
  91. #define SCM_FRAME_PREV(frame) scm_frame_previous (frame)
  92. #define SCM_FRAME_NEXT(frame) scm_frame_next (frame)
  93. #define SCM_FRAMEF_VOID (1L << 2)
  94. #define SCM_FRAMEF_REAL (1L << 3)
  95. #define SCM_FRAMEF_PROC (1L << 4)
  96. #define SCM_FRAMEF_EVAL_ARGS (1L << 5)
  97. #define SCM_FRAMEF_OVERFLOW (1L << 6)
  98. #define SCM_FRAME_VOID_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_VOID)
  99. #define SCM_FRAME_REAL_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_REAL)
  100. #define SCM_FRAME_PROC_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_PROC)
  101. #define SCM_FRAME_EVAL_ARGS_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_EVAL_ARGS)
  102. #define SCM_FRAME_OVERFLOW_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_OVERFLOW)
  103. SCM scm_stack_p (SCM obj);
  104. SCM scm_make_stack (SCM obj, SCM args);
  105. SCM scm_stack_id (SCM stack);
  106. SCM scm_stack_ref (SCM stack, SCM i);
  107. SCM scm_stack_length (SCM stack);
  108. SCM scm_frame_p (SCM obj);
  109. SCM scm_last_stack_frame (SCM obj);
  110. SCM scm_frame_number (SCM frame);
  111. SCM scm_frame_source (SCM frame);
  112. SCM scm_frame_procedure (SCM frame);
  113. SCM scm_frame_arguments (SCM frame);
  114. SCM scm_frame_previous (SCM frame);
  115. SCM scm_frame_next (SCM frame);
  116. SCM scm_frame_real_p (SCM frame);
  117. SCM scm_frame_procedure_p (SCM frame);
  118. SCM scm_frame_evaluating_args_p (SCM frame);
  119. SCM scm_frame_overflow_p (SCM frame);
  120. void scm_init_stacks (void);
  121. #endif /* SCM_STACKS_H */
  122. /*
  123. Local Variables:
  124. c-file-style: "gnu"
  125. End:
  126. */