stacks.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* classes: h_files */
  2. #ifndef SCM_STACKS_H
  3. #define SCM_STACKS_H
  4. /* Copyright (C) 1995,1996,2000,2001, 2004, 2006 Free Software Foundation, Inc.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library 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 GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "libguile/__scm.h"
  21. /* {Frames and stacks}
  22. */
  23. typedef struct scm_t_info_frame {
  24. /* SCM flags; */
  25. scm_t_bits flags;
  26. SCM source;
  27. SCM proc;
  28. SCM args;
  29. } scm_t_info_frame;
  30. #define SCM_FRAME_N_SLOTS (sizeof (scm_t_info_frame) / sizeof (SCM))
  31. #define SCM_STACK(obj) ((scm_t_stack *) SCM_STRUCT_DATA (obj))
  32. #define SCM_STACK_LAYOUT "pwuourpW"
  33. typedef struct scm_t_stack {
  34. SCM id; /* Stack id */
  35. scm_t_info_frame *frames; /* Info frames */
  36. unsigned long length; /* Stack length */
  37. unsigned long tail_length;
  38. scm_t_info_frame tail[1];
  39. } scm_t_stack;
  40. SCM_API SCM scm_stack_type;
  41. #define SCM_STACKP(obj) (SCM_STRUCTP (obj) && scm_is_eq (SCM_STRUCT_VTABLE (obj), scm_stack_type))
  42. #define SCM_STACK_LENGTH(stack) (SCM_STACK (stack) -> length)
  43. #define SCM_FRAMEP(obj) \
  44. (scm_is_pair (obj) && SCM_STACKP (SCM_CAR (obj)) \
  45. && scm_is_unsigned_integer (SCM_CDR (obj), \
  46. 0, SCM_STACK_LENGTH (SCM_CAR (obj))-1))
  47. #define SCM_FRAME_REF(frame, slot) \
  48. (SCM_STACK (SCM_CAR (frame)) -> frames[scm_to_size_t (SCM_CDR (frame))].slot)
  49. #define SCM_FRAME_NUMBER(frame) \
  50. (SCM_BACKWARDS_P \
  51. ? scm_to_size_t (SCM_CDR (frame)) \
  52. : (SCM_STACK_LENGTH (SCM_CAR (frame)) \
  53. - scm_to_size_t (SCM_CDR (frame)) \
  54. - 1)) \
  55. #define SCM_FRAME_FLAGS(frame) SCM_FRAME_REF (frame, flags)
  56. #define SCM_FRAME_SOURCE(frame) SCM_FRAME_REF (frame, source)
  57. #define SCM_FRAME_PROC(frame) SCM_FRAME_REF (frame, proc)
  58. #define SCM_FRAME_ARGS(frame) SCM_FRAME_REF (frame, args)
  59. #define SCM_FRAME_PREV(frame) scm_frame_previous (frame)
  60. #define SCM_FRAME_NEXT(frame) scm_frame_next (frame)
  61. #define SCM_FRAMEF_VOID (1L << 2)
  62. #define SCM_FRAMEF_REAL (1L << 3)
  63. #define SCM_FRAMEF_PROC (1L << 4)
  64. #define SCM_FRAMEF_EVAL_ARGS (1L << 5)
  65. #define SCM_FRAMEF_OVERFLOW (1L << 6)
  66. #define SCM_FRAME_VOID_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_VOID)
  67. #define SCM_FRAME_REAL_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_REAL)
  68. #define SCM_FRAME_PROC_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_PROC)
  69. #define SCM_FRAME_EVAL_ARGS_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_EVAL_ARGS)
  70. #define SCM_FRAME_OVERFLOW_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_OVERFLOW)
  71. SCM_API SCM scm_stack_p (SCM obj);
  72. SCM_API SCM scm_make_stack (SCM obj, SCM args);
  73. SCM_API SCM scm_stack_id (SCM stack);
  74. SCM_API SCM scm_stack_ref (SCM stack, SCM i);
  75. SCM_API SCM scm_stack_length (SCM stack);
  76. SCM_API SCM scm_frame_p (SCM obj);
  77. SCM_API SCM scm_last_stack_frame (SCM obj);
  78. SCM_API SCM scm_frame_number (SCM frame);
  79. SCM_API SCM scm_frame_source (SCM frame);
  80. SCM_API SCM scm_frame_procedure (SCM frame);
  81. SCM_API SCM scm_frame_arguments (SCM frame);
  82. SCM_API SCM scm_frame_previous (SCM frame);
  83. SCM_API SCM scm_frame_next (SCM frame);
  84. SCM_API SCM scm_frame_real_p (SCM frame);
  85. SCM_API SCM scm_frame_procedure_p (SCM frame);
  86. SCM_API SCM scm_frame_evaluating_args_p (SCM frame);
  87. SCM_API SCM scm_frame_overflow_p (SCM frame);
  88. SCM_API void scm_init_stacks (void);
  89. #endif /* SCM_STACKS_H */
  90. /*
  91. Local Variables:
  92. c-file-style: "gnu"
  93. End:
  94. */