Changed license terms to the plain LGPL thru-out.
[bpt/guile.git] / libguile / stacks.h
1 /* classes: h_files */
2
3 #ifndef SCM_STACKS_H
4 #define SCM_STACKS_H
5
6 /* Copyright (C) 1995,1996,2000,2001 Free Software Foundation, Inc.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23 \f
24
25 #include "libguile/__scm.h"
26
27 /* {Frames and stacks}
28 */
29
30 typedef struct scm_t_info_frame {
31 /* SCM flags; */
32 scm_t_bits flags;
33 SCM source;
34 SCM proc;
35 SCM args;
36 } scm_t_info_frame;
37 #define SCM_FRAME_N_SLOTS (sizeof (scm_t_info_frame) / sizeof (SCM))
38
39 #define SCM_STACK(obj) ((scm_t_stack *) SCM_STRUCT_DATA (obj))
40 #define SCM_STACK_LAYOUT "pwuourpW"
41 typedef struct scm_t_stack {
42 SCM id; /* Stack id */
43 scm_t_info_frame *frames; /* Info frames */
44 unsigned long length; /* Stack length */
45 unsigned long tail_length;
46 scm_t_info_frame tail[1];
47 } scm_t_stack;
48
49 SCM_API SCM scm_stack_type;
50
51 #define SCM_STACKP(obj) (SCM_STRUCTP (obj) && SCM_EQ_P (SCM_STRUCT_VTABLE (obj), scm_stack_type))
52 #define SCM_STACK_LENGTH(stack) (SCM_STACK (stack) -> length)
53
54 #define SCM_FRAMEP(obj) \
55 (SCM_CONSP (obj) && SCM_STACKP (SCM_CAR (obj)) \
56 && SCM_INUMP (SCM_CDR (obj)) && SCM_INUM (SCM_CDR (obj)) >= 0 \
57 && ((unsigned long int) SCM_INUM (SCM_CDR (obj)) \
58 < SCM_STACK_LENGTH (SCM_CAR (obj))))
59
60 #define SCM_FRAME_REF(frame, slot) \
61 (SCM_STACK (SCM_CAR (frame)) -> frames[SCM_INUM (SCM_CDR (frame))].slot) \
62
63 #define SCM_FRAME_NUMBER(frame) \
64 (SCM_BACKWARDS_P \
65 ? SCM_INUM (SCM_CDR (frame)) \
66 : (SCM_STACK_LENGTH (SCM_CAR (frame)) \
67 - SCM_INUM (SCM_CDR (frame)) \
68 - 1)) \
69
70 #define SCM_FRAME_FLAGS(frame) SCM_FRAME_REF (frame, flags)
71 #define SCM_FRAME_SOURCE(frame) SCM_FRAME_REF (frame, source)
72 #define SCM_FRAME_PROC(frame) SCM_FRAME_REF (frame, proc)
73 #define SCM_FRAME_ARGS(frame) SCM_FRAME_REF (frame, args)
74 #define SCM_FRAME_PREV(frame) scm_frame_previous (frame)
75 #define SCM_FRAME_NEXT(frame) scm_frame_next (frame)
76
77 #define SCM_FRAMEF_VOID (1L << 2)
78 #define SCM_FRAMEF_REAL (1L << 3)
79 #define SCM_FRAMEF_PROC (1L << 4)
80 #define SCM_FRAMEF_EVAL_ARGS (1L << 5)
81 #define SCM_FRAMEF_OVERFLOW (1L << 6)
82
83 #define SCM_FRAME_VOID_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_VOID)
84 #define SCM_FRAME_REAL_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_REAL)
85 #define SCM_FRAME_PROC_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_PROC)
86 #define SCM_FRAME_EVAL_ARGS_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_EVAL_ARGS)
87 #define SCM_FRAME_OVERFLOW_P(f) (SCM_FRAME_FLAGS (f) & SCM_FRAMEF_OVERFLOW)
88
89 \f
90
91 SCM_API SCM scm_stack_p (SCM obj);
92 SCM_API SCM scm_make_stack (SCM obj, SCM args);
93 SCM_API SCM scm_stack_id (SCM stack);
94 SCM_API SCM scm_stack_ref (SCM stack, SCM i);
95 SCM_API SCM scm_stack_length (SCM stack);
96
97 SCM_API SCM scm_frame_p (SCM obj);
98 SCM_API SCM scm_last_stack_frame (SCM obj);
99 SCM_API SCM scm_frame_number (SCM frame);
100 SCM_API SCM scm_frame_source (SCM frame);
101 SCM_API SCM scm_frame_procedure (SCM frame);
102 SCM_API SCM scm_frame_arguments (SCM frame);
103 SCM_API SCM scm_frame_previous (SCM frame);
104 SCM_API SCM scm_frame_next (SCM frame);
105 SCM_API SCM scm_frame_real_p (SCM frame);
106 SCM_API SCM scm_frame_procedure_p (SCM frame);
107 SCM_API SCM scm_frame_evaluating_args_p (SCM frame);
108 SCM_API SCM scm_frame_overflow_p (SCM frame);
109
110 SCM_API void scm_init_stacks (void);
111
112 #endif /* SCM_STACKS_H */
113
114 /*
115 Local Variables:
116 c-file-style: "gnu"
117 End:
118 */