stacks.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* classes: h_files */
  2. #ifndef STACKSH
  3. #define STACKSH
  4. /* Copyright (C) 1995,1996, 2000, 2002 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., 59 Temple Place, Suite 330,
  19. * Boston, MA 02111-1307 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_info_frame {
  51. /* SCM flags; */
  52. scm_bits_t flags;
  53. SCM source;
  54. SCM proc;
  55. SCM args;
  56. } scm_info_frame;
  57. #define SCM_FRAME_N_SLOTS (sizeof (scm_info_frame) / sizeof (SCM))
  58. #define SCM_STACK(obj) ((scm_stack *) SCM_STRUCT_DATA (obj))
  59. #define SCM_STACK_LAYOUT "pwuourpW"
  60. typedef struct scm_stack {
  61. SCM id; /* Stack id */
  62. scm_info_frame *frames; /* Info frames */
  63. unsigned int length; /* Stack length */
  64. unsigned int tail_length;
  65. scm_info_frame tail[1];
  66. } scm_stack;
  67. extern SCM scm_stack_type;
  68. #define SCM_STACKP(obj) (SCM_STRUCTP (obj) && SCM_EQ_P (SCM_STRUCT_VTABLE (obj), scm_stack_type))
  69. #define SCM_STACK_LENGTH(stack) (SCM_STACK (stack) -> length)
  70. #define SCM_FRAMEP(obj) (SCM_CONSP (obj) \
  71. && SCM_STACKP (SCM_CAR (obj)) \
  72. && SCM_INUMP (SCM_CDR (obj))) \
  73. #define SCM_FRAME_REF(frame, slot) \
  74. (SCM_STACK (SCM_CAR (frame)) -> frames[SCM_INUM (SCM_CDR (frame))].slot) \
  75. #define SCM_FRAME_NUMBER(frame) \
  76. (SCM_BACKWARDS_P \
  77. ? SCM_INUM (SCM_CDR (frame)) \
  78. : (SCM_STACK_LENGTH (SCM_CAR (frame)) \
  79. - SCM_INUM (SCM_CDR (frame)) \
  80. - 1)) \
  81. #define SCM_FRAME_FLAGS(frame) SCM_FRAME_REF (frame, flags)
  82. #define SCM_FRAME_SOURCE(frame) SCM_FRAME_REF (frame, source)
  83. #define SCM_FRAME_PROC(frame) SCM_FRAME_REF (frame, proc)
  84. #define SCM_FRAME_ARGS(frame) SCM_FRAME_REF (frame, args)
  85. #define SCM_FRAME_PREV(frame) scm_frame_previous (frame)
  86. #define SCM_FRAME_NEXT(frame) scm_frame_next (frame)
  87. #define SCM_FRAMEF_VOID (1L << 2)
  88. #define SCM_FRAMEF_REAL (1L << 3)
  89. #define SCM_FRAMEF_PROC (1L << 4)
  90. #define SCM_FRAMEF_EVAL_ARGS (1L << 5)
  91. #define SCM_FRAMEF_OVERFLOW (1L << 6)
  92. #define SCM_FRAME_VOID_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_VOID)
  93. #define SCM_FRAME_REAL_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_REAL)
  94. #define SCM_FRAME_PROC_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_PROC)
  95. #define SCM_FRAME_EVAL_ARGS_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_EVAL_ARGS)
  96. #define SCM_FRAME_OVERFLOW_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_OVERFLOW)
  97. SCM scm_stack_p (SCM obj);
  98. SCM scm_make_stack (SCM obj, SCM args);
  99. SCM scm_stack_id (SCM stack);
  100. SCM scm_stack_ref (SCM stack, SCM i);
  101. SCM scm_stack_length (SCM stack);
  102. SCM scm_frame_p (SCM obj);
  103. SCM scm_last_stack_frame (SCM obj);
  104. SCM scm_frame_number (SCM frame);
  105. SCM scm_frame_source (SCM frame);
  106. SCM scm_frame_procedure (SCM frame);
  107. SCM scm_frame_arguments (SCM frame);
  108. SCM scm_frame_previous (SCM frame);
  109. SCM scm_frame_next (SCM frame);
  110. SCM scm_frame_real_p (SCM frame);
  111. SCM scm_frame_procedure_p (SCM frame);
  112. SCM scm_frame_evaluating_args_p (SCM frame);
  113. SCM scm_frame_overflow_p (SCM frame);
  114. void scm_init_stacks (void);
  115. #endif /* STACKSH */
  116. /*
  117. Local Variables:
  118. c-file-style: "gnu"
  119. End:
  120. */