* * gc.c (scm_protect_object, scm_unprotect_object): New functions.
[bpt/guile.git] / libguile / root.h
1 /* classes: h_files */
2
3 #ifndef ROOTH
4 #define ROOTH
5
6 /* Copyright (C) 1996 Free Software Foundation, Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This program 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
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this software; see the file COPYING. If not, write to
20 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 * As a special exception, the Free Software Foundation gives permission
23 * for additional uses of the text contained in its release of GUILE.
24 *
25 * The exception is that, if you link the GUILE library with other files
26 * to produce an executable, this does not by itself cause the
27 * resulting executable to be covered by the GNU General Public License.
28 * Your use of that executable is in no way restricted on account of
29 * linking the GUILE library code into it.
30 *
31 * This exception does not however invalidate any other reasons why
32 * the executable file might be covered by the GNU General Public License.
33 *
34 * This exception applies only to the code released by the
35 * Free Software Foundation under the name GUILE. If you copy
36 * code from other Free Software Foundation releases into a copy of
37 * GUILE, as the General Public License permits, the exception does
38 * not apply to the code that you add in this way. To avoid misleading
39 * anyone as to the status of such modified files, you must delete
40 * this exception notice from them.
41 *
42 * If you write modifications of your own for GUILE, it is your choice
43 * whether to permit this exception to apply to your modifications.
44 * If you do not wish that, delete this exception notice.
45 */
46 \f
47
48 \f
49
50 #include "libguile/__scm.h"
51 #include "libguile/debug.h"
52
53 \f
54
55 #define scm_flo0 scm_sys_protects[0]
56 #define scm_listofnull scm_sys_protects[1]
57 #define scm_undefineds scm_sys_protects[2]
58 #define scm_nullvect scm_sys_protects[3]
59 #define scm_nullstr scm_sys_protects[4]
60 #define scm_symhash scm_sys_protects[5]
61 #define scm_weak_symhash scm_sys_protects[6]
62 #define scm_symhash_vars scm_sys_protects[7]
63 #define scm_kw_obarray scm_sys_protects[8]
64 #define scm_type_obj_list scm_sys_protects[9]
65 #define scm_first_type scm_sys_protects[10]
66 #define scm_stand_in_procs scm_sys_protects[11]
67 #define scm_object_whash scm_sys_protects[12]
68 #define scm_permobjs scm_sys_protects[13]
69 #define scm_asyncs scm_sys_protects[14]
70 #define scm_protects scm_sys_protects[15]
71 #ifdef DEBUG_EXTENSIONS
72 #define scm_source_whash scm_sys_protects[16]
73 #define SCM_NUM_PROTECTS 17
74 #else
75 #define SCM_NUM_PROTECTS 16
76 #endif
77
78 extern SCM scm_sys_protects[];
79
80 \f
81
82 extern long scm_tc16_root;
83
84 #define SCM_ROOTP(obj) (scm_tc16_root == SCM_TYP16 (obj))
85 #define SCM_ROOT_STATE(root) ((scm_root_state *) SCM_CDR (root))
86
87 typedef struct scm_root_state
88 {
89 SCM_STACKITEM * stack_base;
90 jmp_buf save_regs_gc_mark;
91 int errjmp_bad;
92
93 SCM rootcont;
94 SCM dynwinds;
95 SCM continuation_stack;
96 SCM continuation_stack_ptr;
97 #ifdef DEBUG_EXTENSIONS
98 /* It is very inefficient to have this variable in the root state. */
99 scm_debug_frame *last_debug_frame;
100 #endif
101
102 SCM progargs; /* vestigial */
103 SCM exitval; /* vestigial */
104
105 SCM cur_inp;
106 SCM cur_outp;
107 SCM cur_errp;
108 SCM def_inp;
109 SCM def_outp;
110 SCM def_errp;
111
112 SCM system_transformer;
113 SCM top_level_lookup_closure_var;
114
115 SCM handle; /* The root object for this root state */
116 SCM parent; /* The parent root object */
117 } scm_root_state;
118
119 #define scm_stack_base (scm_root->stack_base)
120 #define scm_save_regs_gc_mark (scm_root->save_regs_gc_mark)
121 #define scm_errjmp_bad (scm_root->errjmp_bad)
122
123 #define scm_rootcont (scm_root->rootcont)
124 #define scm_dynwinds (scm_root->dynwinds)
125 #define scm_continuation_stack (scm_root->continuation_stack)
126 #define scm_continuation_stack_ptr (scm_root->continuation_stack_ptr)
127 #define scm_progargs (scm_root->progargs)
128 #ifdef USE_THREADS
129 #define scm_last_debug_frame (scm_root->last_debug_frame)
130 #endif
131 #define scm_exitval (scm_root->exitval)
132 #define scm_cur_inp (scm_root->cur_inp)
133 #define scm_cur_outp (scm_root->cur_outp)
134 #define scm_cur_errp (scm_root->cur_errp)
135 #define scm_def_inp (scm_root->def_inp)
136 #define scm_def_outp (scm_root->def_outp)
137 #define scm_def_errp (scm_root->def_errp)
138 #define scm_top_level_lookup_closure_var \
139 (scm_root->top_level_lookup_closure_var)
140 #define scm_system_transformer (scm_root->system_transformer)
141
142 #ifdef USE_THREADS
143 #define scm_root ((scm_root_state *) SCM_THREAD_LOCAL_DATA)
144 #define scm_set_root(new_root) SCM_SET_THREAD_LOCAL_DATA (new_root)
145 #else /* USE_THREADS */
146 extern struct scm_root_state *scm_root;
147 #define scm_set_root(new_root) (scm_root = (new_root))
148 #endif /* USE_THREADS */
149
150 \f
151
152 extern SCM scm_make_root SCM_P ((SCM parent));
153 extern SCM scm_call_with_dynamic_root SCM_P ((SCM thunk, SCM handler));
154 extern SCM scm_apply_with_dynamic_root SCM_P ((SCM proc, SCM a1, SCM args, SCM handler));
155 extern SCM scm_call_catching_errors SCM_P ((SCM (*thunk)(), SCM (*err_filter)(), void * closure));
156 extern void scm_init_root SCM_P ((void));
157
158 #endif /* ROOTH */