Mercurial > vim
annotate src/if_mzsch.c @ 7680:4b72a6f11547
Added tag v7.4.1138 for changeset c80284cfe1b8dc3209439bb87cf027f2e6aa1544
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 19 Jan 2016 18:00:06 +0100 |
parents | 77a14f3bc18b |
children | bce3b5ddb393 |
rev | line source |
---|---|
14 | 1 /* vi:set ts=8 sts=4 sw=4: |
2 * | |
151 | 3 * MzScheme interface by Sergey Khorev <sergey.khorev@gmail.com> |
4074 | 4 * Based on work by Brent Fulgham <bfulgham@debian.org> |
14 | 5 * (Based on lots of help from Matthew Flatt) |
6 * | |
7 * This consists of six parts: | |
8 * 1. MzScheme interpreter main program | |
9 * 2. Routines that handle the external interface between MzScheme and | |
10 * Vim. | |
11 * 3. MzScheme input/output handlers: writes output via [e]msg(). | |
12 * 4. Implementation of the Vim Features for MzScheme | |
13 * 5. Vim Window-related Manipulation Functions. | |
14 * 6. Vim Buffer-related Manipulation Functions | |
15 * | |
16 * NOTES | |
17 * 1. Memory, allocated with scheme_malloc*, need not to be freed explicitly, | |
18 * garbage collector will do it self | |
19 * 2. Requires at least NORMAL features. I can't imagine why one may want | |
20 * to build with SMALL or TINY features but with MzScheme interface. | |
1894 | 21 * 3. I don't use K&R-style functions. Anyways, MzScheme headers are ANSI. |
14 | 22 */ |
23 | |
24 #include "vim.h" | |
1284 | 25 |
14 | 26 #include "if_mzsch.h" |
27 | |
800 | 28 /* Only do the following when the feature is enabled. Needed for "make |
29 * depend". */ | |
30 #if defined(FEAT_MZSCHEME) || defined(PROTO) | |
31 | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
32 /* |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
33 * scheme_register_tls_space is only available on 32-bit Windows until |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
34 * racket-6.3. See |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
35 * http://docs.racket-lang.org/inside/im_memoryalloc.html?q=scheme_register_tls_space |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
36 */ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
37 #if MZSCHEME_VERSION_MAJOR >= 500 && defined(WIN32) \ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
38 && defined(USE_THREAD_LOCAL) \ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
39 && (!defined(_WIN64) || MZSCHEME_VERSION_MAJOR >= 603) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
40 # define HAVE_TLS_SPACE 1 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
41 #endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
42 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
43 /* |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
44 * Since version 4.x precise GC requires trampolined startup. |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
45 * Futures and places in version 5.x need it too. |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
46 */ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
47 #if defined(MZ_PRECISE_GC) && MZSCHEME_VERSION_MAJOR >= 400 \ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
48 || MZSCHEME_VERSION_MAJOR >= 500 \ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
49 && (defined(MZ_USE_FUTURES) || defined(MZ_USE_PLACES)) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
50 # define TRAMPOLINED_MZVIM_STARTUP |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
51 #endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
52 |
14 | 53 /* Base data structures */ |
54 #define SCHEME_VIMBUFFERP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_buffer_type) | |
55 #define SCHEME_VIMWINDOWP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_window_type) | |
56 | |
57 typedef struct | |
58 { | |
1894 | 59 Scheme_Object so; |
14 | 60 buf_T *buf; |
61 } vim_mz_buffer; | |
62 | |
63 #define INVALID_BUFFER_VALUE ((buf_T *)(-1)) | |
64 | |
65 typedef struct | |
66 { | |
1894 | 67 Scheme_Object so; |
667 | 68 win_T *win; |
14 | 69 } vim_mz_window; |
70 | |
71 #define INVALID_WINDOW_VALUE ((win_T *)(-1)) | |
72 | |
73 /* | |
74 * Prims that form MzScheme Vim interface | |
75 */ | |
76 typedef struct | |
77 { | |
78 Scheme_Closed_Prim *prim; | |
79 char *name; | |
80 int mina; /* arity information */ | |
81 int maxa; | |
82 } Vim_Prim; | |
83 | |
84 typedef struct | |
85 { | |
86 char *name; | |
87 Scheme_Object *port; | |
88 } Port_Info; | |
89 | |
90 /* | |
91 *======================================================================== | |
92 * Vim-Control Commands | |
93 *======================================================================== | |
94 */ | |
95 /* | |
96 *======================================================================== | |
97 * Utility functions for the vim/mzscheme interface | |
98 *======================================================================== | |
99 */ | |
274 | 100 #ifdef HAVE_SANDBOX |
101 static Scheme_Object *sandbox_file_guard(int, Scheme_Object **); | |
102 static Scheme_Object *sandbox_network_guard(int, Scheme_Object **); | |
1125 | 103 static void sandbox_check(void); |
274 | 104 #endif |
14 | 105 /* Buffer-related commands */ |
106 static Scheme_Object *buffer_new(buf_T *buf); | |
107 static Scheme_Object *get_buffer_by_name(void *, int, Scheme_Object **); | |
108 static Scheme_Object *get_buffer_by_num(void *, int, Scheme_Object **); | |
109 static Scheme_Object *get_buffer_count(void *, int, Scheme_Object **); | |
110 static Scheme_Object *get_buffer_line(void *, int, Scheme_Object **); | |
111 static Scheme_Object *get_buffer_line_list(void *, int, Scheme_Object **); | |
112 static Scheme_Object *get_buffer_name(void *, int, Scheme_Object **); | |
113 static Scheme_Object *get_buffer_num(void *, int, Scheme_Object **); | |
114 static Scheme_Object *get_buffer_size(void *, int, Scheme_Object **); | |
115 static Scheme_Object *get_curr_buffer(void *, int, Scheme_Object **); | |
116 static Scheme_Object *get_next_buffer(void *, int, Scheme_Object **); | |
117 static Scheme_Object *get_prev_buffer(void *, int, Scheme_Object **); | |
118 static Scheme_Object *mzscheme_open_buffer(void *, int, Scheme_Object **); | |
119 static Scheme_Object *set_buffer_line(void *, int, Scheme_Object **); | |
120 static Scheme_Object *set_buffer_line_list(void *, int, Scheme_Object **); | |
121 static Scheme_Object *insert_buffer_line_list(void *, int, Scheme_Object **); | |
122 static Scheme_Object *get_range_start(void *, int, Scheme_Object **); | |
123 static Scheme_Object *get_range_end(void *, int, Scheme_Object **); | |
124 static vim_mz_buffer *get_vim_curr_buffer(void); | |
125 | |
126 /* Window-related commands */ | |
127 static Scheme_Object *window_new(win_T *win); | |
128 static Scheme_Object *get_curr_win(void *, int, Scheme_Object **); | |
129 static Scheme_Object *get_window_count(void *, int, Scheme_Object **); | |
130 static Scheme_Object *get_window_by_num(void *, int, Scheme_Object **); | |
131 static Scheme_Object *get_window_num(void *, int, Scheme_Object **); | |
132 static Scheme_Object *get_window_buffer(void *, int, Scheme_Object **); | |
133 static Scheme_Object *get_window_height(void *, int, Scheme_Object **); | |
134 static Scheme_Object *set_window_height(void *, int, Scheme_Object **); | |
135 #ifdef FEAT_VERTSPLIT | |
136 static Scheme_Object *get_window_width(void *, int, Scheme_Object **); | |
137 static Scheme_Object *set_window_width(void *, int, Scheme_Object **); | |
138 #endif | |
139 static Scheme_Object *get_cursor(void *, int, Scheme_Object **); | |
140 static Scheme_Object *set_cursor(void *, int, Scheme_Object **); | |
141 static Scheme_Object *get_window_list(void *, int, Scheme_Object **); | |
142 static vim_mz_window *get_vim_curr_window(void); | |
143 | |
144 /* Vim-related commands */ | |
145 static Scheme_Object *mzscheme_beep(void *, int, Scheme_Object **); | |
146 static Scheme_Object *get_option(void *, int, Scheme_Object **); | |
147 static Scheme_Object *set_option(void *, int, Scheme_Object **); | |
148 static Scheme_Object *vim_command(void *, int, Scheme_Object **); | |
149 static Scheme_Object *vim_eval(void *, int, Scheme_Object **); | |
150 static Scheme_Object *vim_bufferp(void *data, int, Scheme_Object **); | |
151 static Scheme_Object *vim_windowp(void *data, int, Scheme_Object **); | |
152 static Scheme_Object *vim_buffer_validp(void *data, int, Scheme_Object **); | |
153 static Scheme_Object *vim_window_validp(void *data, int, Scheme_Object **); | |
154 | |
155 /* | |
156 *======================================================================== | |
157 * Internal Function Prototypes | |
158 *======================================================================== | |
159 */ | |
160 static int vim_error_check(void); | |
161 static int do_mzscheme_command(exarg_T *, void *, Scheme_Closed_Prim *what); | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
162 static int startup_mzscheme(void); |
14 | 163 static char *string_to_line(Scheme_Object *obj); |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
164 #if MZSCHEME_VERSION_MAJOR >= 501 |
4074 | 165 # define OUTPUT_LEN_TYPE intptr_t |
166 #else | |
167 # define OUTPUT_LEN_TYPE long | |
168 #endif | |
169 static void do_output(char *mesg, OUTPUT_LEN_TYPE len); | |
14 | 170 static void do_printf(char *format, ...); |
171 static void do_flush(void); | |
172 static Scheme_Object *_apply_thunk_catch_exceptions( | |
173 Scheme_Object *, Scheme_Object **); | |
174 static Scheme_Object *extract_exn_message(Scheme_Object *v); | |
175 static Scheme_Object *do_eval(void *, int noargc, Scheme_Object **noargv); | |
176 static Scheme_Object *do_load(void *, int noargc, Scheme_Object **noargv); | |
1894 | 177 static void register_vim_exn(void); |
14 | 178 static vim_mz_buffer *get_buffer_arg(const char *fname, int argnum, |
179 int argc, Scheme_Object **argv); | |
180 static vim_mz_window *get_window_arg(const char *fname, int argnum, | |
181 int argc, Scheme_Object **argv); | |
182 static int line_in_range(linenr_T, buf_T *); | |
183 static void check_line_range(linenr_T, buf_T *); | |
184 static void mz_fix_cursor(int lo, int hi, int extra); | |
185 | |
1894 | 186 static int eval_with_exn_handling(void *, Scheme_Closed_Prim *, |
187 Scheme_Object **ret); | |
188 static void make_modules(void); | |
189 static void init_exn_catching_apply(void); | |
190 static int mzscheme_env_main(Scheme_Env *env, int argc, char **argv); | |
191 static int mzscheme_init(void); | |
192 #ifdef FEAT_EVAL | |
4074 | 193 static Scheme_Object *vim_to_mzscheme(typval_T *vim_value); |
194 static Scheme_Object *vim_to_mzscheme_impl(typval_T *vim_value, int depth, | |
1894 | 195 Scheme_Hash_Table *visited); |
4074 | 196 static int mzscheme_to_vim(Scheme_Object *obj, typval_T *tv); |
197 static int mzscheme_to_vim_impl(Scheme_Object *obj, typval_T *tv, int depth, | |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
198 Scheme_Hash_Table *visited); |
4074 | 199 static Scheme_Object *vim_funcref(void *data, int argc, Scheme_Object **argv); |
1894 | 200 #endif |
201 | |
202 #ifdef MZ_PRECISE_GC | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
203 static int buffer_size_proc(void *obj UNUSED) |
1894 | 204 { |
205 return gcBYTES_TO_WORDS(sizeof(vim_mz_buffer)); | |
206 } | |
207 static int buffer_mark_proc(void *obj) | |
208 { | |
209 return buffer_size_proc(obj); | |
210 } | |
211 static int buffer_fixup_proc(void *obj) | |
212 { | |
4074 | 213 /* apparently not needed as the object will be uncollectable while |
214 * the buffer is alive | |
215 */ | |
216 /* | |
217 vim_mz_buffer* buf = (vim_mz_buffer*) obj; | |
218 buf->buf->b_mzscheme_ref = GC_fixup_self(obj); | |
219 */ | |
1894 | 220 return buffer_size_proc(obj); |
221 } | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
222 static int window_size_proc(void *obj UNUSED) |
1894 | 223 { |
224 return gcBYTES_TO_WORDS(sizeof(vim_mz_window)); | |
225 } | |
226 static int window_mark_proc(void *obj) | |
227 { | |
228 return window_size_proc(obj); | |
229 } | |
230 static int window_fixup_proc(void *obj) | |
231 { | |
4074 | 232 /* apparently not needed as the object will be uncollectable while |
233 * the window is alive | |
234 */ | |
235 /* | |
236 vim_mz_window* win = (vim_mz_window*) obj; | |
237 win->win->w_mzscheme_ref = GC_fixup_self(obj); | |
238 */ | |
1894 | 239 return window_size_proc(obj); |
240 } | |
4074 | 241 /* with precise GC, w_mzscheme_ref and b_mzscheme_ref are immobile boxes |
242 * containing pointers to a window/buffer | |
243 * with conservative GC these are simply pointers*/ | |
244 # define WINDOW_REF(win) *(vim_mz_window **)((win)->w_mzscheme_ref) | |
245 # define BUFFER_REF(buf) *(vim_mz_buffer **)((buf)->b_mzscheme_ref) | |
246 #else | |
247 # define WINDOW_REF(win) (vim_mz_window *)((win)->w_mzscheme_ref) | |
248 # define BUFFER_REF(buf) (vim_mz_buffer *)((buf)->b_mzscheme_ref) | |
1894 | 249 #endif |
14 | 250 |
137 | 251 #ifdef DYNAMIC_MZSCHEME |
252 static Scheme_Object *dll_scheme_eof; | |
253 static Scheme_Object *dll_scheme_false; | |
254 static Scheme_Object *dll_scheme_void; | |
255 static Scheme_Object *dll_scheme_null; | |
256 static Scheme_Object *dll_scheme_true; | |
257 | |
258 static Scheme_Thread **dll_scheme_current_thread_ptr; | |
259 | |
260 static void (**dll_scheme_console_printf_ptr)(char *str, ...); | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
261 static void (**dll_scheme_console_output_ptr)(char *str, OUTPUT_LEN_TYPE len); |
137 | 262 static void (**dll_scheme_notify_multithread_ptr)(int on); |
263 | |
264 static void *(*dll_GC_malloc)(size_t size_in_bytes); | |
265 static void *(*dll_GC_malloc_atomic)(size_t size_in_bytes); | |
266 static Scheme_Env *(*dll_scheme_basic_env)(void); | |
267 static void (*dll_scheme_check_threads)(void); | |
268 static void (*dll_scheme_register_static)(void *ptr, long size); | |
269 static void (*dll_scheme_set_stack_base)(void *base, int no_auto_statics); | |
270 static void (*dll_scheme_add_global)(const char *name, Scheme_Object *val, | |
271 Scheme_Env *env); | |
272 static void (*dll_scheme_add_global_symbol)(Scheme_Object *name, | |
273 Scheme_Object *val, Scheme_Env *env); | |
274 static Scheme_Object *(*dll_scheme_apply)(Scheme_Object *rator, int num_rands, | |
275 Scheme_Object **rands); | |
276 static Scheme_Object *(*dll_scheme_builtin_value)(const char *name); | |
274 | 277 # if MZSCHEME_VERSION_MAJOR >= 299 |
278 static Scheme_Object *(*dll_scheme_byte_string_to_char_string)(Scheme_Object *s); | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
279 static Scheme_Object *(*dll_scheme_make_path)(const char *chars); |
274 | 280 # endif |
137 | 281 static void (*dll_scheme_close_input_port)(Scheme_Object *port); |
282 static void (*dll_scheme_count_lines)(Scheme_Object *port); | |
1284 | 283 #if MZSCHEME_VERSION_MAJOR < 360 |
137 | 284 static Scheme_Object *(*dll_scheme_current_continuation_marks)(void); |
1284 | 285 #else |
286 static Scheme_Object *(*dll_scheme_current_continuation_marks)(Scheme_Object *prompt_tag); | |
287 #endif | |
137 | 288 static void (*dll_scheme_display)(Scheme_Object *obj, Scheme_Object *port); |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
289 static char *(*dll_scheme_display_to_string)(Scheme_Object *obj, OUTPUT_LEN_TYPE *len); |
274 | 290 static int (*dll_scheme_eq)(Scheme_Object *obj1, Scheme_Object *obj2); |
137 | 291 static Scheme_Object *(*dll_scheme_do_eval)(Scheme_Object *obj, |
292 int _num_rands, Scheme_Object **rands, int val); | |
293 static void (*dll_scheme_dont_gc_ptr)(void *p); | |
294 static Scheme_Object *(*dll_scheme_eval)(Scheme_Object *obj, Scheme_Env *env); | |
295 static Scheme_Object *(*dll_scheme_eval_string)(const char *str, | |
296 Scheme_Env *env); | |
344 | 297 static Scheme_Object *(*dll_scheme_eval_string_all)(const char *str, |
137 | 298 Scheme_Env *env, int all); |
299 static void (*dll_scheme_finish_primitive_module)(Scheme_Env *env); | |
151 | 300 # if MZSCHEME_VERSION_MAJOR < 299 |
137 | 301 static char *(*dll_scheme_format)(char *format, int flen, int argc, |
302 Scheme_Object **argv, long *rlen); | |
151 | 303 # else |
304 static char *(*dll_scheme_format_utf8)(char *format, int flen, int argc, | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
305 Scheme_Object **argv, OUTPUT_LEN_TYPE *rlen); |
274 | 306 static Scheme_Object *(*dll_scheme_get_param)(Scheme_Config *c, int pos); |
151 | 307 # endif |
137 | 308 static void (*dll_scheme_gc_ptr_ok)(void *p); |
151 | 309 # if MZSCHEME_VERSION_MAJOR < 299 |
137 | 310 static char *(*dll_scheme_get_sized_string_output)(Scheme_Object *, |
311 long *len); | |
151 | 312 # else |
313 static char *(*dll_scheme_get_sized_byte_string_output)(Scheme_Object *, | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
314 OUTPUT_LEN_TYPE *len); |
151 | 315 # endif |
137 | 316 static Scheme_Object *(*dll_scheme_intern_symbol)(const char *name); |
317 static Scheme_Object *(*dll_scheme_lookup_global)(Scheme_Object *symbol, | |
318 Scheme_Env *env); | |
319 static Scheme_Object *(*dll_scheme_make_closed_prim_w_arity) | |
320 (Scheme_Closed_Prim *prim, void *data, const char *name, mzshort mina, | |
321 mzshort maxa); | |
322 static Scheme_Object *(*dll_scheme_make_integer_value)(long i); | |
344 | 323 static Scheme_Object *(*dll_scheme_make_pair)(Scheme_Object *car, |
137 | 324 Scheme_Object *cdr); |
274 | 325 static Scheme_Object *(*dll_scheme_make_prim_w_arity)(Scheme_Prim *prim, |
326 const char *name, mzshort mina, mzshort maxa); | |
151 | 327 # if MZSCHEME_VERSION_MAJOR < 299 |
137 | 328 static Scheme_Object *(*dll_scheme_make_string)(const char *chars); |
329 static Scheme_Object *(*dll_scheme_make_string_output_port)(); | |
151 | 330 # else |
331 static Scheme_Object *(*dll_scheme_make_byte_string)(const char *chars); | |
332 static Scheme_Object *(*dll_scheme_make_byte_string_output_port)(); | |
333 # endif | |
137 | 334 static Scheme_Object *(*dll_scheme_make_struct_instance)(Scheme_Object *stype, |
335 int argc, Scheme_Object **argv); | |
336 static Scheme_Object **(*dll_scheme_make_struct_names)(Scheme_Object *base, | |
337 Scheme_Object *field_names, int flags, int *count_out); | |
338 static Scheme_Object *(*dll_scheme_make_struct_type)(Scheme_Object *base, | |
339 Scheme_Object *parent, Scheme_Object *inspector, int num_fields, | |
340 int num_uninit_fields, Scheme_Object *uninit_val, | |
151 | 341 Scheme_Object *properties |
342 # if MZSCHEME_VERSION_MAJOR >= 299 | |
343 , Scheme_Object *guard | |
344 # endif | |
345 ); | |
137 | 346 static Scheme_Object **(*dll_scheme_make_struct_values)( |
347 Scheme_Object *struct_type, Scheme_Object **names, int count, | |
348 int flags); | |
349 static Scheme_Type (*dll_scheme_make_type)(const char *name); | |
350 static Scheme_Object *(*dll_scheme_make_vector)(int size, | |
351 Scheme_Object *fill); | |
352 static void *(*dll_scheme_malloc_fail_ok)(void *(*f)(size_t), size_t); | |
353 static Scheme_Object *(*dll_scheme_open_input_file)(const char *name, | |
354 const char *who); | |
355 static Scheme_Env *(*dll_scheme_primitive_module)(Scheme_Object *name, | |
356 Scheme_Env *for_env); | |
357 static int (*dll_scheme_proper_list_length)(Scheme_Object *list); | |
358 static void (*dll_scheme_raise)(Scheme_Object *exn); | |
359 static Scheme_Object *(*dll_scheme_read)(Scheme_Object *port); | |
360 static void (*dll_scheme_signal_error)(const char *msg, ...); | |
361 static void (*dll_scheme_wrong_type)(const char *name, const char *expected, | |
362 int which, int argc, Scheme_Object **argv); | |
151 | 363 # if MZSCHEME_VERSION_MAJOR >= 299 |
344 | 364 static void (*dll_scheme_set_param)(Scheme_Config *c, int pos, |
151 | 365 Scheme_Object *o); |
366 static Scheme_Config *(*dll_scheme_current_config)(void); | |
367 static Scheme_Object *(*dll_scheme_char_string_to_byte_string) | |
368 (Scheme_Object *s); | |
1307 | 369 static Scheme_Object *(*dll_scheme_char_string_to_path) |
370 (Scheme_Object *s); | |
4074 | 371 static void *(*dll_scheme_set_collects_path)(Scheme_Object *p); |
151 | 372 # endif |
1894 | 373 static Scheme_Hash_Table *(*dll_scheme_make_hash_table)(int type); |
374 static void (*dll_scheme_hash_set)(Scheme_Hash_Table *table, | |
375 Scheme_Object *key, Scheme_Object *value); | |
376 static Scheme_Object *(*dll_scheme_hash_get)(Scheme_Hash_Table *table, | |
377 Scheme_Object *key); | |
378 static Scheme_Object *(*dll_scheme_make_double)(double d); | |
379 static Scheme_Object *(*dll_scheme_make_sized_byte_string)(char *chars, | |
380 long len, int copy); | |
381 static Scheme_Object *(*dll_scheme_namespace_require)(Scheme_Object *req); | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
382 static Scheme_Object *(*dll_scheme_dynamic_wind)(void (*pre)(void *), Scheme_Object *(* volatile act)(void *), void (* volatile post)(void *), Scheme_Object *(*jmp_handler)(void *), void * volatile data); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
383 # ifdef MZ_PRECISE_GC |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
384 static void *(*dll_GC_malloc_one_tagged)(size_t size_in_bytes); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
385 static void (*dll_GC_register_traversers)(short tag, Size_Proc size, Mark_Proc mark, Fixup_Proc fixup, int is_constant_size, int is_atomic); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
386 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
387 # if MZSCHEME_VERSION_MAJOR >= 400 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
388 static void (*dll_scheme_init_collection_paths)(Scheme_Env *global_env, Scheme_Object *extra_dirs); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
389 static void **(*dll_scheme_malloc_immobile_box)(void *p); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
390 static void (*dll_scheme_free_immobile_box)(void **b); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
391 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
392 # if MZSCHEME_VERSION_MAJOR >= 500 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
393 # ifdef TRAMPOLINED_MZVIM_STARTUP |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
394 static int (*dll_scheme_main_setup)(int no_auto_statics, Scheme_Env_Main _main, int argc, char **argv); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
395 # if defined(IMPLEMENT_THREAD_LOCAL_VIA_WIN_TLS) || MZSCHEME_VERSION_MAJOR >= 603 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
396 static void (*dll_scheme_register_tls_space)(void *tls_space, int _tls_index); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
397 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
398 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
399 # if defined(IMPLEMENT_THREAD_LOCAL_VIA_WIN_TLS) || defined(IMPLEMENT_THREAD_LOCAL_EXTERNALLY_VIA_PROC) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
400 static Thread_Local_Variables *(*dll_scheme_external_get_thread_local_variables)(void); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
401 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
402 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
403 # if MZSCHEME_VERSION_MAJOR >= 600 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
404 static void (*dll_scheme_embedded_load)(intptr_t len, const char *s, int predefined); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
405 static void (*dll_scheme_register_embedded_load)(intptr_t len, const char *s); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
406 static void (*dll_scheme_set_config_path)(Scheme_Object *p); |
1894 | 407 # endif |
137 | 408 |
409 /* arrays are imported directly */ | |
410 # define scheme_eof dll_scheme_eof | |
411 # define scheme_false dll_scheme_false | |
412 # define scheme_void dll_scheme_void | |
413 # define scheme_null dll_scheme_null | |
414 # define scheme_true dll_scheme_true | |
415 | |
416 /* pointers are GetProceAddress'ed as pointers to pointer */ | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
417 #if !defined(USE_THREAD_LOCAL) && !defined(LINK_EXTENSIONS_BY_TABLE) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
418 # define scheme_current_thread (*dll_scheme_current_thread_ptr) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
419 # endif |
137 | 420 # define scheme_console_printf (*dll_scheme_console_printf_ptr) |
421 # define scheme_console_output (*dll_scheme_console_output_ptr) | |
422 # define scheme_notify_multithread (*dll_scheme_notify_multithread_ptr) | |
423 | |
424 /* and functions in a usual way */ | |
425 # define GC_malloc dll_GC_malloc | |
426 # define GC_malloc_atomic dll_GC_malloc_atomic | |
427 | |
428 # define scheme_add_global dll_scheme_add_global | |
429 # define scheme_add_global_symbol dll_scheme_add_global_symbol | |
430 # define scheme_apply dll_scheme_apply | |
431 # define scheme_basic_env dll_scheme_basic_env | |
432 # define scheme_builtin_value dll_scheme_builtin_value | |
274 | 433 # if MZSCHEME_VERSION_MAJOR >= 299 |
434 # define scheme_byte_string_to_char_string dll_scheme_byte_string_to_char_string | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
435 # define scheme_make_path dll_scheme_make_path |
274 | 436 # endif |
137 | 437 # define scheme_check_threads dll_scheme_check_threads |
438 # define scheme_close_input_port dll_scheme_close_input_port | |
439 # define scheme_count_lines dll_scheme_count_lines | |
440 # define scheme_current_continuation_marks \ | |
441 dll_scheme_current_continuation_marks | |
442 # define scheme_display dll_scheme_display | |
443 # define scheme_display_to_string dll_scheme_display_to_string | |
444 # define scheme_do_eval dll_scheme_do_eval | |
445 # define scheme_dont_gc_ptr dll_scheme_dont_gc_ptr | |
274 | 446 # define scheme_eq dll_scheme_eq |
137 | 447 # define scheme_eval dll_scheme_eval |
448 # define scheme_eval_string dll_scheme_eval_string | |
449 # define scheme_eval_string_all dll_scheme_eval_string_all | |
450 # define scheme_finish_primitive_module dll_scheme_finish_primitive_module | |
151 | 451 # if MZSCHEME_VERSION_MAJOR < 299 |
452 # define scheme_format dll_scheme_format | |
453 # else | |
454 # define scheme_format_utf8 dll_scheme_format_utf8 | |
455 # endif | |
137 | 456 # define scheme_gc_ptr_ok dll_scheme_gc_ptr_ok |
151 | 457 # if MZSCHEME_VERSION_MAJOR < 299 |
4074 | 458 # define scheme_get_sized_byte_string_output dll_scheme_get_sized_string_output |
151 | 459 # else |
460 # define scheme_get_sized_byte_string_output \ | |
461 dll_scheme_get_sized_byte_string_output | |
4074 | 462 # define scheme_get_param dll_scheme_get_param |
151 | 463 # endif |
137 | 464 # define scheme_intern_symbol dll_scheme_intern_symbol |
465 # define scheme_lookup_global dll_scheme_lookup_global | |
466 # define scheme_make_closed_prim_w_arity dll_scheme_make_closed_prim_w_arity | |
467 # define scheme_make_integer_value dll_scheme_make_integer_value | |
468 # define scheme_make_pair dll_scheme_make_pair | |
274 | 469 # define scheme_make_prim_w_arity dll_scheme_make_prim_w_arity |
151 | 470 # if MZSCHEME_VERSION_MAJOR < 299 |
4074 | 471 # define scheme_make_byte_string dll_scheme_make_string |
472 # define scheme_make_byte_string_output_port dll_scheme_make_string_output_port | |
151 | 473 # else |
474 # define scheme_make_byte_string dll_scheme_make_byte_string | |
475 # define scheme_make_byte_string_output_port \ | |
476 dll_scheme_make_byte_string_output_port | |
477 # endif | |
137 | 478 # define scheme_make_struct_instance dll_scheme_make_struct_instance |
479 # define scheme_make_struct_names dll_scheme_make_struct_names | |
480 # define scheme_make_struct_type dll_scheme_make_struct_type | |
481 # define scheme_make_struct_values dll_scheme_make_struct_values | |
482 # define scheme_make_type dll_scheme_make_type | |
483 # define scheme_make_vector dll_scheme_make_vector | |
484 # define scheme_malloc_fail_ok dll_scheme_malloc_fail_ok | |
485 # define scheme_open_input_file dll_scheme_open_input_file | |
486 # define scheme_primitive_module dll_scheme_primitive_module | |
487 # define scheme_proper_list_length dll_scheme_proper_list_length | |
488 # define scheme_raise dll_scheme_raise | |
489 # define scheme_read dll_scheme_read | |
490 # define scheme_register_static dll_scheme_register_static | |
491 # define scheme_set_stack_base dll_scheme_set_stack_base | |
492 # define scheme_signal_error dll_scheme_signal_error | |
493 # define scheme_wrong_type dll_scheme_wrong_type | |
151 | 494 # if MZSCHEME_VERSION_MAJOR >= 299 |
495 # define scheme_set_param dll_scheme_set_param | |
496 # define scheme_current_config dll_scheme_current_config | |
497 # define scheme_char_string_to_byte_string \ | |
498 dll_scheme_char_string_to_byte_string | |
1307 | 499 # define scheme_char_string_to_path \ |
500 dll_scheme_char_string_to_path | |
4074 | 501 # define scheme_set_collects_path dll_scheme_set_collects_path |
151 | 502 # endif |
1894 | 503 # define scheme_make_hash_table dll_scheme_make_hash_table |
504 # define scheme_hash_set dll_scheme_hash_set | |
505 # define scheme_hash_get dll_scheme_hash_get | |
506 # define scheme_make_double dll_scheme_make_double | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
507 # define scheme_make_sized_byte_string dll_scheme_make_sized_byte_string |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
508 # define scheme_namespace_require dll_scheme_namespace_require |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
509 # define scheme_dynamic_wind dll_scheme_dynamic_wind |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
510 # ifdef MZ_PRECISE_GC |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
511 # define GC_malloc_one_tagged dll_GC_malloc_one_tagged |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
512 # define GC_register_traversers dll_GC_register_traversers |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
513 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
514 # if MZSCHEME_VERSION_MAJOR >= 400 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
515 # ifdef TRAMPOLINED_MZVIM_STARTUP |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
516 # define scheme_main_setup dll_scheme_main_setup |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
517 # if defined(IMPLEMENT_THREAD_LOCAL_VIA_WIN_TLS) || MZSCHEME_VERSION_MAJOR >= 603 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
518 # define scheme_register_tls_space dll_scheme_register_tls_space |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
519 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
520 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
521 # define scheme_init_collection_paths dll_scheme_init_collection_paths |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
522 # define scheme_malloc_immobile_box dll_scheme_malloc_immobile_box |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
523 # define scheme_free_immobile_box dll_scheme_free_immobile_box |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
524 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
525 # if MZSCHEME_VERSION_MAJOR >= 600 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
526 # define scheme_embedded_load dll_scheme_embedded_load |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
527 # define scheme_register_embedded_load dll_scheme_register_embedded_load |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
528 # define scheme_set_config_path dll_scheme_set_config_path |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
529 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
530 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
531 # if MZSCHEME_VERSION_MAJOR >= 500 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
532 # if defined(IMPLEMENT_THREAD_LOCAL_VIA_WIN_TLS) || defined(IMPLEMENT_THREAD_LOCAL_EXTERNALLY_VIA_PROC) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
533 /* define as function for macro in schshread.h */ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
534 Thread_Local_Variables * |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
535 scheme_external_get_thread_local_variables(void) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
536 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
537 return dll_scheme_external_get_thread_local_variables(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
538 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
539 # endif |
1894 | 540 # endif |
137 | 541 |
542 typedef struct | |
543 { | |
544 char *name; | |
545 void **ptr; | |
546 } Thunk_Info; | |
547 | |
548 static Thunk_Info mzgc_imports[] = { | |
549 {"GC_malloc", (void **)&dll_GC_malloc}, | |
550 {"GC_malloc_atomic", (void **)&dll_GC_malloc_atomic}, | |
551 {NULL, NULL}}; | |
552 | |
553 static Thunk_Info mzsch_imports[] = { | |
554 {"scheme_eof", (void **)&dll_scheme_eof}, | |
555 {"scheme_false", (void **)&dll_scheme_false}, | |
556 {"scheme_void", (void **)&dll_scheme_void}, | |
557 {"scheme_null", (void **)&dll_scheme_null}, | |
558 {"scheme_true", (void **)&dll_scheme_true}, | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
559 #if !defined(USE_THREAD_LOCAL) && !defined(LINK_EXTENSIONS_BY_TABLE) |
137 | 560 {"scheme_current_thread", (void **)&dll_scheme_current_thread_ptr}, |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
561 #endif |
137 | 562 {"scheme_console_printf", (void **)&dll_scheme_console_printf_ptr}, |
563 {"scheme_console_output", (void **)&dll_scheme_console_output_ptr}, | |
344 | 564 {"scheme_notify_multithread", |
137 | 565 (void **)&dll_scheme_notify_multithread_ptr}, |
566 {"scheme_add_global", (void **)&dll_scheme_add_global}, | |
567 {"scheme_add_global_symbol", (void **)&dll_scheme_add_global_symbol}, | |
568 {"scheme_apply", (void **)&dll_scheme_apply}, | |
569 {"scheme_basic_env", (void **)&dll_scheme_basic_env}, | |
274 | 570 # if MZSCHEME_VERSION_MAJOR >= 299 |
571 {"scheme_byte_string_to_char_string", (void **)&dll_scheme_byte_string_to_char_string}, | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
572 {"scheme_make_path", (void **)&dll_scheme_make_path}, |
274 | 573 # endif |
137 | 574 {"scheme_builtin_value", (void **)&dll_scheme_builtin_value}, |
575 {"scheme_check_threads", (void **)&dll_scheme_check_threads}, | |
576 {"scheme_close_input_port", (void **)&dll_scheme_close_input_port}, | |
577 {"scheme_count_lines", (void **)&dll_scheme_count_lines}, | |
344 | 578 {"scheme_current_continuation_marks", |
137 | 579 (void **)&dll_scheme_current_continuation_marks}, |
580 {"scheme_display", (void **)&dll_scheme_display}, | |
581 {"scheme_display_to_string", (void **)&dll_scheme_display_to_string}, | |
582 {"scheme_do_eval", (void **)&dll_scheme_do_eval}, | |
583 {"scheme_dont_gc_ptr", (void **)&dll_scheme_dont_gc_ptr}, | |
274 | 584 {"scheme_eq", (void **)&dll_scheme_eq}, |
137 | 585 {"scheme_eval", (void **)&dll_scheme_eval}, |
586 {"scheme_eval_string", (void **)&dll_scheme_eval_string}, | |
587 {"scheme_eval_string_all", (void **)&dll_scheme_eval_string_all}, | |
344 | 588 {"scheme_finish_primitive_module", |
137 | 589 (void **)&dll_scheme_finish_primitive_module}, |
151 | 590 # if MZSCHEME_VERSION_MAJOR < 299 |
137 | 591 {"scheme_format", (void **)&dll_scheme_format}, |
151 | 592 # else |
593 {"scheme_format_utf8", (void **)&dll_scheme_format_utf8}, | |
274 | 594 {"scheme_get_param", (void **)&dll_scheme_get_param}, |
151 | 595 #endif |
137 | 596 {"scheme_gc_ptr_ok", (void **)&dll_scheme_gc_ptr_ok}, |
151 | 597 # if MZSCHEME_VERSION_MAJOR < 299 |
344 | 598 {"scheme_get_sized_string_output", |
137 | 599 (void **)&dll_scheme_get_sized_string_output}, |
151 | 600 # else |
344 | 601 {"scheme_get_sized_byte_string_output", |
151 | 602 (void **)&dll_scheme_get_sized_byte_string_output}, |
603 #endif | |
137 | 604 {"scheme_intern_symbol", (void **)&dll_scheme_intern_symbol}, |
605 {"scheme_lookup_global", (void **)&dll_scheme_lookup_global}, | |
344 | 606 {"scheme_make_closed_prim_w_arity", |
137 | 607 (void **)&dll_scheme_make_closed_prim_w_arity}, |
608 {"scheme_make_integer_value", (void **)&dll_scheme_make_integer_value}, | |
609 {"scheme_make_pair", (void **)&dll_scheme_make_pair}, | |
274 | 610 {"scheme_make_prim_w_arity", (void **)&dll_scheme_make_prim_w_arity}, |
151 | 611 # if MZSCHEME_VERSION_MAJOR < 299 |
137 | 612 {"scheme_make_string", (void **)&dll_scheme_make_string}, |
344 | 613 {"scheme_make_string_output_port", |
137 | 614 (void **)&dll_scheme_make_string_output_port}, |
151 | 615 # else |
616 {"scheme_make_byte_string", (void **)&dll_scheme_make_byte_string}, | |
344 | 617 {"scheme_make_byte_string_output_port", |
151 | 618 (void **)&dll_scheme_make_byte_string_output_port}, |
619 # endif | |
344 | 620 {"scheme_make_struct_instance", |
137 | 621 (void **)&dll_scheme_make_struct_instance}, |
622 {"scheme_make_struct_names", (void **)&dll_scheme_make_struct_names}, | |
623 {"scheme_make_struct_type", (void **)&dll_scheme_make_struct_type}, | |
624 {"scheme_make_struct_values", (void **)&dll_scheme_make_struct_values}, | |
625 {"scheme_make_type", (void **)&dll_scheme_make_type}, | |
626 {"scheme_make_vector", (void **)&dll_scheme_make_vector}, | |
627 {"scheme_malloc_fail_ok", (void **)&dll_scheme_malloc_fail_ok}, | |
628 {"scheme_open_input_file", (void **)&dll_scheme_open_input_file}, | |
629 {"scheme_primitive_module", (void **)&dll_scheme_primitive_module}, | |
630 {"scheme_proper_list_length", (void **)&dll_scheme_proper_list_length}, | |
631 {"scheme_raise", (void **)&dll_scheme_raise}, | |
632 {"scheme_read", (void **)&dll_scheme_read}, | |
633 {"scheme_register_static", (void **)&dll_scheme_register_static}, | |
634 {"scheme_set_stack_base", (void **)&dll_scheme_set_stack_base}, | |
635 {"scheme_signal_error", (void **)&dll_scheme_signal_error}, | |
636 {"scheme_wrong_type", (void **)&dll_scheme_wrong_type}, | |
151 | 637 # if MZSCHEME_VERSION_MAJOR >= 299 |
638 {"scheme_set_param", (void **)&dll_scheme_set_param}, | |
639 {"scheme_current_config", (void **)&dll_scheme_current_config}, | |
640 {"scheme_char_string_to_byte_string", | |
641 (void **)&dll_scheme_char_string_to_byte_string}, | |
1894 | 642 {"scheme_char_string_to_path", (void **)&dll_scheme_char_string_to_path}, |
4074 | 643 {"scheme_set_collects_path", (void **)&dll_scheme_set_collects_path}, |
151 | 644 # endif |
1894 | 645 {"scheme_make_hash_table", (void **)&dll_scheme_make_hash_table}, |
646 {"scheme_hash_set", (void **)&dll_scheme_hash_set}, | |
647 {"scheme_hash_get", (void **)&dll_scheme_hash_get}, | |
648 {"scheme_make_double", (void **)&dll_scheme_make_double}, | |
649 {"scheme_make_sized_byte_string", (void **)&dll_scheme_make_sized_byte_string}, | |
650 {"scheme_namespace_require", (void **)&dll_scheme_namespace_require}, | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
651 {"scheme_dynamic_wind", (void **)&dll_scheme_dynamic_wind}, |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
652 # ifdef MZ_PRECISE_GC |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
653 {"GC_malloc_one_tagged", (void **)&dll_GC_malloc_one_tagged}, |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
654 {"GC_register_traversers", (void **)&dll_GC_register_traversers}, |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
655 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
656 # if MZSCHEME_VERSION_MAJOR >= 400 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
657 # ifdef TRAMPOLINED_MZVIM_STARTUP |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
658 {"scheme_main_setup", (void **)&dll_scheme_main_setup}, |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
659 # if defined(IMPLEMENT_THREAD_LOCAL_VIA_WIN_TLS) || MZSCHEME_VERSION_MAJOR >= 603 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
660 {"scheme_register_tls_space", (void **)&dll_scheme_register_tls_space}, |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
661 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
662 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
663 {"scheme_init_collection_paths", (void **)&dll_scheme_init_collection_paths}, |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
664 {"scheme_malloc_immobile_box", (void **)&dll_scheme_malloc_immobile_box}, |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
665 {"scheme_free_immobile_box", (void **)&dll_scheme_free_immobile_box}, |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
666 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
667 # if MZSCHEME_VERSION_MAJOR >= 500 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
668 # if defined(IMPLEMENT_THREAD_LOCAL_VIA_WIN_TLS) || defined(IMPLEMENT_THREAD_LOCAL_EXTERNALLY_VIA_PROC) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
669 {"scheme_external_get_thread_local_variables", (void **)&dll_scheme_external_get_thread_local_variables}, |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
670 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
671 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
672 # if MZSCHEME_VERSION_MAJOR >= 600 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
673 {"scheme_embedded_load", (void **)&dll_scheme_embedded_load}, |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
674 {"scheme_register_embedded_load", (void **)&dll_scheme_register_embedded_load}, |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
675 {"scheme_set_config_path", (void **)&dll_scheme_set_config_path}, |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
676 # endif |
137 | 677 {NULL, NULL}}; |
678 | |
679 static HINSTANCE hMzGC = 0; | |
680 static HINSTANCE hMzSch = 0; | |
681 | |
682 static void dynamic_mzscheme_end(void); | |
683 static int mzscheme_runtime_link_init(char *sch_dll, char *gc_dll, | |
684 int verbose); | |
685 | |
686 static int | |
687 mzscheme_runtime_link_init(char *sch_dll, char *gc_dll, int verbose) | |
688 { | |
689 Thunk_Info *thunk = NULL; | |
690 | |
691 if (hMzGC && hMzSch) | |
692 return OK; | |
2612 | 693 hMzSch = vimLoadLib(sch_dll); |
694 hMzGC = vimLoadLib(gc_dll); | |
137 | 695 |
3348 | 696 if (!hMzGC) |
697 { | |
698 if (verbose) | |
699 EMSG2(_(e_loadlib), gc_dll); | |
700 return FAIL; | |
701 } | |
702 | |
137 | 703 if (!hMzSch) |
704 { | |
705 if (verbose) | |
706 EMSG2(_(e_loadlib), sch_dll); | |
707 return FAIL; | |
708 } | |
709 | |
710 for (thunk = mzsch_imports; thunk->name; thunk++) | |
711 { | |
344 | 712 if ((*thunk->ptr = |
137 | 713 (void *)GetProcAddress(hMzSch, thunk->name)) == NULL) |
714 { | |
715 FreeLibrary(hMzSch); | |
716 hMzSch = 0; | |
717 FreeLibrary(hMzGC); | |
718 hMzGC = 0; | |
719 if (verbose) | |
720 EMSG2(_(e_loadfunc), thunk->name); | |
721 return FAIL; | |
722 } | |
723 } | |
724 for (thunk = mzgc_imports; thunk->name; thunk++) | |
725 { | |
344 | 726 if ((*thunk->ptr = |
137 | 727 (void *)GetProcAddress(hMzGC, thunk->name)) == NULL) |
728 { | |
729 FreeLibrary(hMzSch); | |
730 hMzSch = 0; | |
731 FreeLibrary(hMzGC); | |
732 hMzGC = 0; | |
733 if (verbose) | |
734 EMSG2(_(e_loadfunc), thunk->name); | |
735 return FAIL; | |
736 } | |
737 } | |
738 return OK; | |
739 } | |
740 | |
741 int | |
742 mzscheme_enabled(int verbose) | |
743 { | |
744 return mzscheme_runtime_link_init( | |
745 DYNAMIC_MZSCH_DLL, DYNAMIC_MZGC_DLL, verbose) == OK; | |
746 } | |
747 | |
748 static void | |
749 dynamic_mzscheme_end(void) | |
750 { | |
751 if (hMzSch) | |
752 { | |
753 FreeLibrary(hMzSch); | |
754 hMzSch = 0; | |
755 } | |
756 if (hMzGC) | |
757 { | |
758 FreeLibrary(hMzGC); | |
759 hMzGC = 0; | |
760 } | |
761 } | |
762 #endif /* DYNAMIC_MZSCHEME */ | |
763 | |
4074 | 764 #if MZSCHEME_VERSION_MAJOR < 299 |
765 # define GUARANTEED_STRING_ARG(proc, num) GUARANTEE_STRING(proc, num) | |
766 #else | |
767 static Scheme_Object * | |
768 guaranteed_byte_string_arg(char *proc, int num, int argc, Scheme_Object **argv) | |
769 { | |
770 if (SCHEME_BYTE_STRINGP(argv[num])) | |
771 { | |
772 return argv[num]; | |
773 } | |
774 else if (SCHEME_CHAR_STRINGP(argv[num])) | |
775 { | |
776 Scheme_Object *tmp = NULL; | |
777 MZ_GC_DECL_REG(2); | |
778 MZ_GC_VAR_IN_REG(0, argv[num]); | |
779 MZ_GC_VAR_IN_REG(1, tmp); | |
780 MZ_GC_REG(); | |
781 tmp = scheme_char_string_to_byte_string(argv[num]); | |
782 MZ_GC_UNREG(); | |
783 return tmp; | |
784 } | |
785 else | |
786 scheme_wrong_type(proc, "string", num, argc, argv); | |
787 /* unreachable */ | |
788 return scheme_void; | |
789 } | |
790 # define GUARANTEED_STRING_ARG(proc, num) guaranteed_byte_string_arg(proc, num, argc, argv) | |
791 #endif | |
792 | |
1894 | 793 /* need to put it here for dynamic stuff to work */ |
1950 | 794 #if defined(INCLUDE_MZSCHEME_BASE) |
1894 | 795 # include "mzscheme_base.c" |
796 #endif | |
797 | |
14 | 798 /* |
799 *======================================================================== | |
800 * 1. MzScheme interpreter startup | |
801 *======================================================================== | |
802 */ | |
803 | |
804 static Scheme_Type mz_buffer_type; | |
805 static Scheme_Type mz_window_type; | |
806 | |
1894 | 807 static int initialized = FALSE; |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
808 #ifdef DYNAMIC_MZSCHEME |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
809 static int disabled = FALSE; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
810 #endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
811 static int load_base_module_failed = FALSE; |
14 | 812 |
813 /* global environment */ | |
814 static Scheme_Env *environment = NULL; | |
815 /* output/error handlers */ | |
816 static Scheme_Object *curout = NULL; | |
817 static Scheme_Object *curerr = NULL; | |
1894 | 818 /* exn:vim exception */ |
14 | 819 static Scheme_Object *exn_catching_apply = NULL; |
820 static Scheme_Object *exn_p = NULL; | |
821 static Scheme_Object *exn_message = NULL; | |
822 static Scheme_Object *vim_exn = NULL; /* Vim Error exception */ | |
1894 | 823 |
824 #if !defined(MZ_PRECISE_GC) || MZSCHEME_VERSION_MAJOR < 400 | |
825 static void *stack_base = NULL; | |
826 #endif | |
14 | 827 |
828 static long range_start; | |
829 static long range_end; | |
830 | |
831 /* MzScheme threads scheduling stuff */ | |
832 static int mz_threads_allow = 0; | |
833 | |
834 #if defined(FEAT_GUI_W32) | |
835 static void CALLBACK timer_proc(HWND, UINT, UINT, DWORD); | |
836 static UINT timer_id = 0; | |
837 #elif defined(FEAT_GUI_GTK) | |
838 static gint timer_proc(gpointer); | |
839 static guint timer_id = 0; | |
840 #elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA) | |
841 static void timer_proc(XtPointer, XtIntervalId *); | |
842 static XtIntervalId timer_id = (XtIntervalId)0; | |
843 #elif defined(FEAT_GUI_MAC) | |
844 pascal void timer_proc(EventLoopTimerRef, void *); | |
845 static EventLoopTimerRef timer_id = NULL; | |
846 static EventLoopTimerUPP timerUPP; | |
847 #endif | |
848 | |
849 #ifndef FEAT_GUI_W32 /* Win32 console and Unix */ | |
850 void | |
851 mzvim_check_threads(void) | |
852 { | |
853 /* Last time MzScheme threads were scheduled */ | |
854 static time_t mz_last_time = 0; | |
855 | |
856 if (mz_threads_allow && p_mzq > 0) | |
857 { | |
858 time_t now = time(NULL); | |
859 | |
860 if ((now - mz_last_time) * 1000 > p_mzq) | |
861 { | |
862 mz_last_time = now; | |
863 scheme_check_threads(); | |
864 } | |
865 } | |
866 } | |
867 #endif | |
868 | |
16 | 869 #ifdef MZSCHEME_GUI_THREADS |
870 static void setup_timer(void); | |
871 static void remove_timer(void); | |
872 | |
14 | 873 /* timers are presented in GUI only */ |
874 # if defined(FEAT_GUI_W32) | |
875 static void CALLBACK | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
876 timer_proc(HWND hwnd UNUSED, UINT uMsg UNUSED, UINT idEvent UNUSED, DWORD dwTime UNUSED) |
14 | 877 # elif defined(FEAT_GUI_GTK) |
878 static gint | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
879 timer_proc(gpointer data UNUSED) |
14 | 880 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA) |
881 static void | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
882 timer_proc(XtPointer timed_out UNUSED, XtIntervalId *interval_id UNUSED) |
14 | 883 # elif defined(FEAT_GUI_MAC) |
884 pascal void | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
885 timer_proc(EventLoopTimerRef theTimer UNUSED, void *userData UNUSED) |
14 | 886 # endif |
887 { | |
888 scheme_check_threads(); | |
889 # if defined(FEAT_GUI_GTK) | |
890 return TRUE; /* continue receiving notifications */ | |
891 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA) | |
892 /* renew timeout */ | |
893 if (mz_threads_allow && p_mzq > 0) | |
894 timer_id = XtAppAddTimeOut(app_context, p_mzq, | |
895 timer_proc, NULL); | |
896 # endif | |
897 } | |
898 | |
899 static void | |
900 setup_timer(void) | |
901 { | |
902 # if defined(FEAT_GUI_W32) | |
903 timer_id = SetTimer(NULL, 0, p_mzq, timer_proc); | |
904 # elif defined(FEAT_GUI_GTK) | |
905 timer_id = gtk_timeout_add((guint32)p_mzq, (GtkFunction)timer_proc, NULL); | |
906 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA) | |
907 timer_id = XtAppAddTimeOut(app_context, p_mzq, timer_proc, NULL); | |
908 # elif defined(FEAT_GUI_MAC) | |
909 timerUPP = NewEventLoopTimerUPP(timer_proc); | |
910 InstallEventLoopTimer(GetMainEventLoop(), p_mzq * kEventDurationMillisecond, | |
911 p_mzq * kEventDurationMillisecond, timerUPP, NULL, &timer_id); | |
912 # endif | |
913 } | |
914 | |
915 static void | |
916 remove_timer(void) | |
917 { | |
918 # if defined(FEAT_GUI_W32) | |
919 KillTimer(NULL, timer_id); | |
920 # elif defined(FEAT_GUI_GTK) | |
921 gtk_timeout_remove(timer_id); | |
922 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA) | |
923 XtRemoveTimeOut(timer_id); | |
924 # elif defined(FEAT_GUI_MAC) | |
925 RemoveEventLoopTimer(timer_id); | |
926 DisposeEventLoopTimerUPP(timerUPP); | |
927 # endif | |
928 timer_id = 0; | |
929 } | |
930 | |
931 void | |
932 mzvim_reset_timer(void) | |
933 { | |
934 if (timer_id != 0) | |
935 remove_timer(); | |
936 if (mz_threads_allow && p_mzq > 0 && gui.in_use) | |
937 setup_timer(); | |
938 } | |
939 | |
16 | 940 #endif /* MZSCHEME_GUI_THREADS */ |
14 | 941 |
942 static void | |
943 notify_multithread(int on) | |
944 { | |
945 mz_threads_allow = on; | |
16 | 946 #ifdef MZSCHEME_GUI_THREADS |
14 | 947 if (on && timer_id == 0 && p_mzq > 0 && gui.in_use) |
948 setup_timer(); | |
949 if (!on && timer_id != 0) | |
950 remove_timer(); | |
951 #endif | |
952 } | |
953 | |
954 void | |
955 mzscheme_end(void) | |
956 { | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
957 /* We can not unload the DLL. Racket's thread might be still alive. */ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
958 #if 0 |
137 | 959 #ifdef DYNAMIC_MZSCHEME |
960 dynamic_mzscheme_end(); | |
961 #endif | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
962 #endif |
14 | 963 } |
964 | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
965 #if HAVE_TLS_SPACE |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
966 # if defined(_MSC_VER) |
2628 | 967 static __declspec(thread) void *tls_space; |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
968 extern intptr_t _tls_index; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
969 # elif defined(__MINGW32__) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
970 static __thread void *tls_space; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
971 extern intptr_t _tls_index; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
972 # else |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
973 static THREAD_LOCAL void *tls_space; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
974 static intptr_t _tls_index = 0; |
3348 | 975 # endif |
976 #endif | |
977 | |
978 int | |
979 mzscheme_main(int argc, char** argv) | |
1894 | 980 { |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
981 #ifdef DYNAMIC_MZSCHEME |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
982 /* |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
983 * Racket requires trampolined startup. We can not load it later. |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
984 * If dynamic dll loading is failed, disable it. |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
985 */ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
986 if (!mzscheme_enabled(FALSE)) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
987 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
988 disabled = TRUE; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
989 return vim_main2(argc, argv); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
990 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
991 #endif |
6905 | 992 #ifdef HAVE_TLS_SPACE |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
993 scheme_register_tls_space(&tls_space, _tls_index); |
2628 | 994 #endif |
3348 | 995 #ifdef TRAMPOLINED_MZVIM_STARTUP |
996 return scheme_main_setup(TRUE, mzscheme_env_main, argc, argv); | |
1894 | 997 #else |
3348 | 998 return mzscheme_env_main(NULL, argc, argv); |
1894 | 999 #endif |
1000 } | |
1001 | |
1002 static int | |
3348 | 1003 mzscheme_env_main(Scheme_Env *env, int argc, char **argv) |
1894 | 1004 { |
3348 | 1005 int vim_main_result; |
1006 #ifdef TRAMPOLINED_MZVIM_STARTUP | |
1007 /* Scheme has created the environment for us */ | |
1008 environment = env; | |
1009 #else | |
1010 # ifdef MZ_PRECISE_GC | |
1894 | 1011 Scheme_Object *dummy = NULL; |
1012 MZ_GC_DECL_REG(1); | |
1013 MZ_GC_VAR_IN_REG(0, dummy); | |
1014 | |
1015 stack_base = &__gc_var_stack__; | |
1016 # else | |
1017 int dummy = 0; | |
1018 stack_base = (void *)&dummy; | |
3348 | 1019 # endif |
1894 | 1020 #endif |
3348 | 1021 |
1022 /* mzscheme_main is called as a trampoline from main. | |
1023 * We trampoline into vim_main2 | |
1024 * Passing argc, argv through from mzscheme_main | |
1025 */ | |
1026 vim_main_result = vim_main2(argc, argv); | |
1027 #if !defined(TRAMPOLINED_MZVIM_STARTUP) && defined(MZ_PRECISE_GC) | |
1894 | 1028 /* releasing dummy */ |
1029 MZ_GC_REG(); | |
1030 MZ_GC_UNREG(); | |
1031 #endif | |
3348 | 1032 return vim_main_result; |
1894 | 1033 } |
1034 | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1035 static Scheme_Object* |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1036 load_base_module(void *data) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1037 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1038 scheme_namespace_require(scheme_intern_symbol((char *)data)); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1039 return scheme_null; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1040 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1041 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1042 static Scheme_Object * |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1043 load_base_module_on_error(void *data) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1044 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1045 load_base_module_failed = TRUE; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1046 return scheme_null; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1047 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1048 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1049 static int |
14 | 1050 startup_mzscheme(void) |
1051 { | |
3348 | 1052 #ifndef TRAMPOLINED_MZVIM_STARTUP |
1894 | 1053 scheme_set_stack_base(stack_base, 1); |
1054 #endif | |
14 | 1055 |
4074 | 1056 #ifndef TRAMPOLINED_MZVIM_STARTUP |
1057 /* in newer versions of precise GC the initial env has been created */ | |
1058 environment = scheme_basic_env(); | |
1059 #endif | |
1060 | |
14 | 1061 MZ_REGISTER_STATIC(environment); |
1062 MZ_REGISTER_STATIC(curout); | |
1063 MZ_REGISTER_STATIC(curerr); | |
1064 MZ_REGISTER_STATIC(exn_catching_apply); | |
1065 MZ_REGISTER_STATIC(exn_p); | |
1066 MZ_REGISTER_STATIC(exn_message); | |
1067 MZ_REGISTER_STATIC(vim_exn); | |
1894 | 1068 |
1069 MZ_GC_CHECK(); | |
1070 | |
1071 #ifdef INCLUDE_MZSCHEME_BASE | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1072 /* invoke function from generated and included mzscheme_base.c */ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1073 declare_modules(environment); |
1894 | 1074 #endif |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1075 |
14 | 1076 /* setup 'current-library-collection-paths' parameter */ |
1307 | 1077 # if MZSCHEME_VERSION_MAJOR >= 299 |
1894 | 1078 { |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1079 Scheme_Object *coll_path = NULL; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1080 int mustfree = FALSE; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1081 char_u *s; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1082 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1083 MZ_GC_DECL_REG(1); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1084 MZ_GC_VAR_IN_REG(0, coll_path); |
1894 | 1085 MZ_GC_REG(); |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1086 /* workaround for dynamic loading on windows */ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1087 s = vim_getenv("PLTCOLLECTS", &mustfree); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1088 if (s != NULL) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1089 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1090 coll_path = scheme_make_path(s); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1091 MZ_GC_CHECK(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1092 if (mustfree) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1093 vim_free(s); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1094 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1095 # ifdef MZSCHEME_COLLECTS |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1096 if (coll_path == NULL) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1097 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1098 coll_path = scheme_make_path(MZSCHEME_COLLECTS); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1099 MZ_GC_CHECK(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1100 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1101 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1102 if (coll_path != NULL) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1103 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1104 scheme_set_collects_path(coll_path); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1105 MZ_GC_CHECK(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1106 } |
1894 | 1107 MZ_GC_UNREG(); |
1108 } | |
1307 | 1109 # else |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1110 # ifdef MZSCHEME_COLLECTS |
1894 | 1111 { |
1112 Scheme_Object *coll_string = NULL; | |
1113 Scheme_Object *coll_pair = NULL; | |
1114 Scheme_Config *config = NULL; | |
1115 | |
1116 MZ_GC_DECL_REG(3); | |
1117 MZ_GC_VAR_IN_REG(0, coll_string); | |
1118 MZ_GC_VAR_IN_REG(1, coll_pair); | |
1119 MZ_GC_VAR_IN_REG(2, config); | |
1120 MZ_GC_REG(); | |
4074 | 1121 coll_string = scheme_make_byte_string(MZSCHEME_COLLECTS); |
1894 | 1122 MZ_GC_CHECK(); |
1123 coll_pair = scheme_make_pair(coll_string, scheme_null); | |
1124 MZ_GC_CHECK(); | |
4074 | 1125 config = scheme_current_config(); |
1894 | 1126 MZ_GC_CHECK(); |
1127 scheme_set_param(config, MZCONFIG_COLLECTION_PATHS, coll_pair); | |
1128 MZ_GC_CHECK(); | |
1129 MZ_GC_UNREG(); | |
1130 } | |
1307 | 1131 # endif |
14 | 1132 #endif |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1133 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1134 # if MZSCHEME_VERSION_MAJOR >= 600 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1135 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1136 Scheme_Object *config_path = NULL; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1137 int mustfree = FALSE; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1138 char_u *s; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1139 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1140 MZ_GC_DECL_REG(1); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1141 MZ_GC_VAR_IN_REG(0, config_path); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1142 MZ_GC_REG(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1143 /* workaround for dynamic loading on windows */ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1144 s = vim_getenv("PLTCONFIGDIR", &mustfree); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1145 if (s != NULL) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1146 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1147 config_path = scheme_make_path(s); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1148 MZ_GC_CHECK(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1149 if (mustfree) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1150 vim_free(s); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1151 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1152 #ifdef MZSCHEME_CONFIGDIR |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1153 if (config_path == NULL) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1154 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1155 config_path = scheme_make_path(MZSCHEME_CONFIGDIR); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1156 MZ_GC_CHECK(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1157 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1158 #endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1159 if (config_path != NULL) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1160 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1161 scheme_set_config_path(config_path); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1162 MZ_GC_CHECK(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1163 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1164 MZ_GC_UNREG(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1165 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1166 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1167 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1168 #if MZSCHEME_VERSION_MAJOR >= 400 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1169 scheme_init_collection_paths(environment, scheme_null); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1170 #endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1171 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1172 /* |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1173 * versions 4.x do not provide Scheme bindings by default |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1174 * we need to add them explicitly |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1175 */ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1176 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1177 /* use error handler to avoid abort */ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1178 scheme_dynamic_wind(NULL, load_base_module, NULL, |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1179 load_base_module_on_error, "racket/base"); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1180 if (load_base_module_failed) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1181 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1182 load_base_module_failed = FALSE; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1183 scheme_dynamic_wind(NULL, load_base_module, NULL, |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1184 load_base_module_on_error, "scheme/base"); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1185 if (load_base_module_failed) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1186 return -1; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1187 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1188 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1189 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1190 register_vim_exn(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1191 /* use new environment to initialise exception handling */ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1192 init_exn_catching_apply(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1193 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1194 /* redirect output */ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1195 scheme_console_output = do_output; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1196 scheme_console_printf = do_printf; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1197 |
274 | 1198 #ifdef HAVE_SANDBOX |
1199 { | |
1894 | 1200 Scheme_Object *make_security_guard = NULL; |
1201 MZ_GC_DECL_REG(1); | |
1202 MZ_GC_VAR_IN_REG(0, make_security_guard); | |
1203 MZ_GC_REG(); | |
1204 | |
1205 #if MZSCHEME_VERSION_MAJOR < 400 | |
1206 { | |
1207 Scheme_Object *make_security_guard_symbol = NULL; | |
1208 MZ_GC_DECL_REG(1); | |
1209 MZ_GC_VAR_IN_REG(0, make_security_guard_symbol); | |
1210 MZ_GC_REG(); | |
1211 make_security_guard_symbol = scheme_intern_symbol("make-security-guard"); | |
1212 MZ_GC_CHECK(); | |
1213 make_security_guard = scheme_lookup_global( | |
1214 make_security_guard_symbol, environment); | |
1215 MZ_GC_UNREG(); | |
1216 } | |
1217 #else | |
1218 make_security_guard = scheme_builtin_value("make-security-guard"); | |
1219 MZ_GC_CHECK(); | |
1220 #endif | |
1221 | |
1222 /* setup sandbox guards */ | |
1223 if (make_security_guard != NULL) | |
1224 { | |
1225 Scheme_Object *args[3] = {NULL, NULL, NULL}; | |
1226 Scheme_Object *guard = NULL; | |
1227 Scheme_Config *config = NULL; | |
1228 MZ_GC_DECL_REG(5); | |
1229 MZ_GC_ARRAY_VAR_IN_REG(0, args, 3); | |
1230 MZ_GC_VAR_IN_REG(3, guard); | |
1231 MZ_GC_VAR_IN_REG(4, config); | |
1232 MZ_GC_REG(); | |
4074 | 1233 config = scheme_current_config(); |
1894 | 1234 MZ_GC_CHECK(); |
1235 args[0] = scheme_get_param(config, MZCONFIG_SECURITY_GUARD); | |
1236 MZ_GC_CHECK(); | |
1237 args[1] = scheme_make_prim_w_arity(sandbox_file_guard, | |
1238 "sandbox-file-guard", 3, 3); | |
1239 args[2] = scheme_make_prim_w_arity(sandbox_network_guard, | |
1240 "sandbox-network-guard", 4, 4); | |
1241 guard = scheme_apply(make_security_guard, 3, args); | |
1242 MZ_GC_CHECK(); | |
1243 scheme_set_param(config, MZCONFIG_SECURITY_GUARD, guard); | |
1244 MZ_GC_CHECK(); | |
1245 MZ_GC_UNREG(); | |
1246 } | |
1247 MZ_GC_UNREG(); | |
274 | 1248 } |
1249 #endif | |
14 | 1250 /* Create buffer and window types for use in Scheme code */ |
1251 mz_buffer_type = scheme_make_type("<vim-buffer>"); | |
1894 | 1252 MZ_GC_CHECK(); |
14 | 1253 mz_window_type = scheme_make_type("<vim-window>"); |
1894 | 1254 MZ_GC_CHECK(); |
1255 #ifdef MZ_PRECISE_GC | |
1256 GC_register_traversers(mz_buffer_type, | |
1257 buffer_size_proc, buffer_mark_proc, buffer_fixup_proc, | |
1258 TRUE, TRUE); | |
1259 GC_register_traversers(mz_window_type, | |
1260 window_size_proc, window_mark_proc, window_fixup_proc, | |
1261 TRUE, TRUE); | |
1262 #endif | |
1263 | |
1264 make_modules(); | |
14 | 1265 |
1266 /* | |
1267 * setup callback to receive notifications | |
1268 * whether thread scheduling is (or not) required | |
1269 */ | |
1270 scheme_notify_multithread = notify_multithread; | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1271 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1272 return 0; |
14 | 1273 } |
1274 | |
1275 /* | |
1276 * This routine is called for each new invocation of MzScheme | |
1277 * to make sure things are properly initialized. | |
1278 */ | |
1279 static int | |
1280 mzscheme_init(void) | |
1281 { | |
1282 if (!initialized) | |
1283 { | |
137 | 1284 #ifdef DYNAMIC_MZSCHEME |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1285 if (disabled || !mzscheme_enabled(TRUE)) |
137 | 1286 { |
1919 | 1287 EMSG(_("E815: Sorry, this command is disabled, the MzScheme libraries could not be loaded.")); |
137 | 1288 return -1; |
1289 } | |
1290 #endif | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1291 if (load_base_module_failed || startup_mzscheme()) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1292 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1293 EMSG(_("Exxx: Sorry, this command is disabled, the MzScheme's racket/base module could not be loaded.")); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1294 return -1; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1295 } |
1894 | 1296 initialized = TRUE; |
14 | 1297 } |
1298 { | |
1894 | 1299 Scheme_Config *config = NULL; |
1300 MZ_GC_DECL_REG(1); | |
1301 MZ_GC_VAR_IN_REG(0, config); | |
1302 MZ_GC_REG(); | |
4074 | 1303 config = scheme_current_config(); |
1894 | 1304 MZ_GC_CHECK(); |
2023 | 1305 /* recreate ports each call effectively clearing these ones */ |
4074 | 1306 curout = scheme_make_byte_string_output_port(); |
1894 | 1307 MZ_GC_CHECK(); |
4074 | 1308 curerr = scheme_make_byte_string_output_port(); |
1894 | 1309 MZ_GC_CHECK(); |
1310 scheme_set_param(config, MZCONFIG_OUTPUT_PORT, curout); | |
1311 MZ_GC_CHECK(); | |
1312 scheme_set_param(config, MZCONFIG_ERROR_PORT, curerr); | |
1313 MZ_GC_CHECK(); | |
1314 MZ_GC_UNREG(); | |
14 | 1315 } |
1316 | |
1317 return 0; | |
1318 } | |
1319 | |
1320 /* | |
1321 *======================================================================== | |
1322 * 2. External Interface | |
1323 *======================================================================== | |
1324 */ | |
1325 | |
1326 /* | |
1894 | 1327 * Evaluate command with exception handling |
14 | 1328 */ |
1329 static int | |
1894 | 1330 eval_with_exn_handling(void *data, Scheme_Closed_Prim *what, Scheme_Object **ret) |
14 | 1331 { |
1894 | 1332 Scheme_Object *value = NULL; |
1333 Scheme_Object *exn = NULL; | |
1334 Scheme_Object *prim = NULL; | |
1335 | |
1336 MZ_GC_DECL_REG(3); | |
1337 MZ_GC_VAR_IN_REG(0, value); | |
1338 MZ_GC_VAR_IN_REG(1, exn); | |
1339 MZ_GC_VAR_IN_REG(2, prim); | |
1340 MZ_GC_REG(); | |
1341 | |
1342 prim = scheme_make_closed_prim_w_arity(what, data, "mzvim", 0, 0); | |
1343 MZ_GC_CHECK(); | |
1344 value = _apply_thunk_catch_exceptions(prim, &exn); | |
1345 MZ_GC_CHECK(); | |
14 | 1346 |
1347 if (!value) | |
1348 { | |
1349 value = extract_exn_message(exn); | |
856 | 1350 /* Got an exn? */ |
14 | 1351 if (value) |
1352 { | |
1894 | 1353 scheme_display(value, curerr); /* Send to stderr-vim */ |
1354 MZ_GC_CHECK(); | |
14 | 1355 do_flush(); |
1356 } | |
1894 | 1357 MZ_GC_UNREG(); |
14 | 1358 /* `raise' was called on some arbitrary value */ |
1359 return FAIL; | |
1360 } | |
1361 | |
1362 if (ret != NULL) /* if pointer to retval supported give it up */ | |
1363 *ret = value; | |
1364 /* Print any result, as long as it's not a void */ | |
1365 else if (!SCHEME_VOIDP(value)) | |
1894 | 1366 { |
14 | 1367 scheme_display(value, curout); /* Send to stdout-vim */ |
1894 | 1368 MZ_GC_CHECK(); |
1369 } | |
14 | 1370 |
1371 do_flush(); | |
1894 | 1372 MZ_GC_UNREG(); |
14 | 1373 return OK; |
1374 } | |
1375 | |
1376 /* :mzscheme */ | |
1377 static int | |
1378 do_mzscheme_command(exarg_T *eap, void *data, Scheme_Closed_Prim *what) | |
1379 { | |
1380 if (mzscheme_init()) | |
1381 return FAIL; | |
1382 | |
1383 range_start = eap->line1; | |
1384 range_end = eap->line2; | |
1385 | |
1894 | 1386 return eval_with_exn_handling(data, what, NULL); |
14 | 1387 } |
1388 | |
1389 /* | |
1390 * Routine called by VIM when deleting a buffer | |
1391 */ | |
1392 void | |
1393 mzscheme_buffer_free(buf_T *buf) | |
1394 { | |
502 | 1395 if (buf->b_mzscheme_ref) |
14 | 1396 { |
4074 | 1397 vim_mz_buffer *bp = NULL; |
1398 MZ_GC_DECL_REG(1); | |
1399 MZ_GC_VAR_IN_REG(0, bp); | |
1400 MZ_GC_REG(); | |
1401 | |
1402 bp = BUFFER_REF(buf); | |
14 | 1403 bp->buf = INVALID_BUFFER_VALUE; |
4074 | 1404 #ifndef MZ_PRECISE_GC |
14 | 1405 scheme_gc_ptr_ok(bp); |
4074 | 1406 #else |
1407 scheme_free_immobile_box(buf->b_mzscheme_ref); | |
1408 #endif | |
1409 buf->b_mzscheme_ref = NULL; | |
1894 | 1410 MZ_GC_CHECK(); |
4074 | 1411 MZ_GC_UNREG(); |
14 | 1412 } |
1413 } | |
1414 | |
1415 /* | |
1416 * Routine called by VIM when deleting a Window | |
1417 */ | |
1418 void | |
1419 mzscheme_window_free(win_T *win) | |
1420 { | |
502 | 1421 if (win->w_mzscheme_ref) |
14 | 1422 { |
4074 | 1423 vim_mz_window *wp = NULL; |
1424 MZ_GC_DECL_REG(1); | |
1425 MZ_GC_VAR_IN_REG(0, wp); | |
1426 MZ_GC_REG(); | |
1427 wp = WINDOW_REF(win); | |
14 | 1428 wp->win = INVALID_WINDOW_VALUE; |
4074 | 1429 #ifndef MZ_PRECISE_GC |
14 | 1430 scheme_gc_ptr_ok(wp); |
4074 | 1431 #else |
1432 scheme_free_immobile_box(win->w_mzscheme_ref); | |
1433 #endif | |
1434 win->w_mzscheme_ref = NULL; | |
1894 | 1435 MZ_GC_CHECK(); |
4074 | 1436 MZ_GC_UNREG(); |
14 | 1437 } |
1438 } | |
1439 | |
1440 /* | |
1441 * ":mzscheme" (or ":mz") | |
1442 */ | |
1443 void | |
1444 ex_mzscheme(exarg_T *eap) | |
1445 { | |
1446 char_u *script; | |
1447 | |
1448 script = script_get(eap, eap->arg); | |
1449 if (!eap->skip) | |
1450 { | |
1451 if (script == NULL) | |
1452 do_mzscheme_command(eap, eap->arg, do_eval); | |
1453 else | |
1454 { | |
1455 do_mzscheme_command(eap, script, do_eval); | |
1456 vim_free(script); | |
1457 } | |
1458 } | |
1459 } | |
1460 | |
1461 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1462 do_load(void *data, int noargc UNUSED, Scheme_Object **noargv UNUSED) |
14 | 1463 { |
1894 | 1464 Scheme_Object *expr = NULL; |
1465 Scheme_Object *result = NULL; | |
1466 char *file = NULL; | |
1467 Port_Info *pinfo = (Port_Info *)data; | |
1468 | |
1469 MZ_GC_DECL_REG(3); | |
1470 MZ_GC_VAR_IN_REG(0, expr); | |
1471 MZ_GC_VAR_IN_REG(1, result); | |
1472 MZ_GC_VAR_IN_REG(2, file); | |
1473 MZ_GC_REG(); | |
1474 | |
1475 file = (char *)scheme_malloc_fail_ok(scheme_malloc_atomic, MAXPATHL + 1); | |
1476 MZ_GC_CHECK(); | |
14 | 1477 |
1478 /* make Vim expansion */ | |
1894 | 1479 expand_env((char_u *)pinfo->name, (char_u *)file, MAXPATHL); |
14 | 1480 pinfo->port = scheme_open_input_file(file, "mzfile"); |
1894 | 1481 MZ_GC_CHECK(); |
1482 scheme_count_lines(pinfo->port); /* to get accurate read error location*/ | |
1483 MZ_GC_CHECK(); | |
14 | 1484 |
1485 /* Like REPL but print only last result */ | |
1486 while (!SCHEME_EOFP(expr = scheme_read(pinfo->port))) | |
1894 | 1487 { |
1488 result = scheme_eval(expr, environment); | |
1489 MZ_GC_CHECK(); | |
1490 } | |
14 | 1491 |
2023 | 1492 /* errors will be caught in do_mzscheme_command and ex_mzfile */ |
14 | 1493 scheme_close_input_port(pinfo->port); |
1894 | 1494 MZ_GC_CHECK(); |
14 | 1495 pinfo->port = NULL; |
1894 | 1496 MZ_GC_UNREG(); |
14 | 1497 return result; |
1498 } | |
1499 | |
1500 /* :mzfile */ | |
1501 void | |
1502 ex_mzfile(exarg_T *eap) | |
1503 { | |
1894 | 1504 Port_Info pinfo = {NULL, NULL}; |
1505 | |
1506 MZ_GC_DECL_REG(1); | |
1507 MZ_GC_VAR_IN_REG(0, pinfo.port); | |
1508 MZ_GC_REG(); | |
14 | 1509 |
1510 pinfo.name = (char *)eap->arg; | |
1511 if (do_mzscheme_command(eap, &pinfo, do_load) != OK | |
1512 && pinfo.port != NULL) /* looks like port was not closed */ | |
1894 | 1513 { |
14 | 1514 scheme_close_input_port(pinfo.port); |
1894 | 1515 MZ_GC_CHECK(); |
1516 } | |
1517 MZ_GC_UNREG(); | |
14 | 1518 } |
1519 | |
1520 | |
1521 /* | |
1522 *======================================================================== | |
1523 * Exception handling code -- cribbed form the MzScheme sources and | |
1524 * Matthew Flatt's "Inside PLT MzScheme" document. | |
1525 *======================================================================== | |
1526 */ | |
1527 static void | |
1528 init_exn_catching_apply(void) | |
1529 { | |
1530 if (!exn_catching_apply) | |
1531 { | |
1532 char *e = | |
1533 "(lambda (thunk) " | |
856 | 1534 "(with-handlers ([void (lambda (exn) (cons #f exn))]) " |
14 | 1535 "(cons #t (thunk))))"; |
1536 | |
1894 | 1537 exn_catching_apply = scheme_eval_string(e, environment); |
1538 MZ_GC_CHECK(); | |
1539 exn_p = scheme_builtin_value("exn?"); | |
1540 MZ_GC_CHECK(); | |
1541 exn_message = scheme_builtin_value("exn-message"); | |
1542 MZ_GC_CHECK(); | |
14 | 1543 } |
1544 } | |
1545 | |
1546 /* | |
1547 * This function applies a thunk, returning the Scheme value if there's | |
1548 * no exception, otherwise returning NULL and setting *exn to the raised | |
1549 * value (usually an exn structure). | |
1550 */ | |
1551 static Scheme_Object * | |
1552 _apply_thunk_catch_exceptions(Scheme_Object *f, Scheme_Object **exn) | |
1553 { | |
1554 Scheme_Object *v; | |
1555 | |
1556 v = _scheme_apply(exn_catching_apply, 1, &f); | |
1557 /* v is a pair: (cons #t value) or (cons #f exn) */ | |
1558 | |
1559 if (SCHEME_TRUEP(SCHEME_CAR(v))) | |
1560 return SCHEME_CDR(v); | |
1561 else | |
1562 { | |
1563 *exn = SCHEME_CDR(v); | |
1564 return NULL; | |
1565 } | |
1566 } | |
1567 | |
1568 static Scheme_Object * | |
1569 extract_exn_message(Scheme_Object *v) | |
1570 { | |
1571 if (SCHEME_TRUEP(_scheme_apply(exn_p, 1, &v))) | |
1572 return _scheme_apply(exn_message, 1, &v); | |
1573 else | |
1574 return NULL; /* Not an exn structure */ | |
1575 } | |
1576 | |
1577 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1578 do_eval(void *s, int noargc UNUSED, Scheme_Object **noargv UNUSED) |
14 | 1579 { |
1894 | 1580 return scheme_eval_string_all((char *)s, environment, TRUE); |
14 | 1581 } |
1582 | |
1583 /* | |
1584 *======================================================================== | |
1585 * 3. MzScheme I/O Handlers | |
1586 *======================================================================== | |
1587 */ | |
1588 static void | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1589 do_intrnl_output(char *mesg, int error) |
14 | 1590 { |
1591 char *p, *prev; | |
1592 | |
1593 prev = mesg; | |
1594 p = strchr(prev, '\n'); | |
1595 while (p) | |
1596 { | |
1597 *p = '\0'; | |
1598 if (error) | |
1599 EMSG(prev); | |
1600 else | |
1601 MSG(prev); | |
1602 prev = p + 1; | |
1603 p = strchr(prev, '\n'); | |
1604 } | |
1605 | |
1606 if (error) | |
1607 EMSG(prev); | |
1608 else | |
1609 MSG(prev); | |
1610 } | |
1611 | |
1612 static void | |
4074 | 1613 do_output(char *mesg, OUTPUT_LEN_TYPE len UNUSED) |
14 | 1614 { |
3953 | 1615 /* TODO: use len, the string may not be NUL terminated */ |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1616 do_intrnl_output(mesg, 0); |
14 | 1617 } |
1618 | |
1619 static void | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1620 do_err_output(char *mesg) |
14 | 1621 { |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1622 do_intrnl_output(mesg, 1); |
14 | 1623 } |
1624 | |
1625 static void | |
1626 do_printf(char *format, ...) | |
1627 { | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1628 do_intrnl_output(format, 1); |
14 | 1629 } |
1630 | |
1631 static void | |
1632 do_flush(void) | |
1633 { | |
1634 char *buff; | |
4074 | 1635 OUTPUT_LEN_TYPE length; |
1636 | |
1637 buff = scheme_get_sized_byte_string_output(curerr, &length); | |
1894 | 1638 MZ_GC_CHECK(); |
14 | 1639 if (length) |
1640 { | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1641 do_err_output(buff); |
14 | 1642 return; |
1643 } | |
1644 | |
4074 | 1645 buff = scheme_get_sized_byte_string_output(curout, &length); |
1894 | 1646 MZ_GC_CHECK(); |
14 | 1647 if (length) |
1648 do_output(buff, length); | |
1649 } | |
1650 | |
1651 /* | |
1652 *======================================================================== | |
1653 * 4. Implementation of the Vim Features for MzScheme | |
1654 *======================================================================== | |
1655 */ | |
1656 | |
1657 /* (command {command-string}) */ | |
1658 static Scheme_Object * | |
1659 vim_command(void *data, int argc, Scheme_Object **argv) | |
1660 { | |
1661 Vim_Prim *prim = (Vim_Prim *)data; | |
4074 | 1662 Scheme_Object *cmd = NULL; |
1663 MZ_GC_DECL_REG(1); | |
1664 MZ_GC_VAR_IN_REG(0, cmd); | |
1665 MZ_GC_REG(); | |
1666 cmd = GUARANTEED_STRING_ARG(prim->name, 0); | |
14 | 1667 |
1668 /* may be use do_cmdline_cmd? */ | |
4074 | 1669 do_cmdline(BYTE_STRING_VALUE(cmd), NULL, NULL, DOCMD_NOWAIT|DOCMD_VERBOSE); |
14 | 1670 update_screen(VALID); |
1671 | |
4074 | 1672 MZ_GC_UNREG(); |
14 | 1673 raise_if_error(); |
1674 return scheme_void; | |
1675 } | |
1676 | |
1677 /* (eval {expr-string}) */ | |
1678 static Scheme_Object * | |
4082 | 1679 vim_eval(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1680 { |
1681 #ifdef FEAT_EVAL | |
1894 | 1682 Vim_Prim *prim = (Vim_Prim *)data; |
4074 | 1683 Scheme_Object *result = NULL; |
1894 | 1684 typval_T *vim_result; |
4074 | 1685 Scheme_Object *expr = NULL; |
1686 MZ_GC_DECL_REG(2); | |
1687 MZ_GC_VAR_IN_REG(0, result); | |
1688 MZ_GC_VAR_IN_REG(1, expr); | |
1894 | 1689 MZ_GC_REG(); |
4074 | 1690 expr = GUARANTEED_STRING_ARG(prim->name, 0); |
1691 | |
1692 vim_result = eval_expr(BYTE_STRING_VALUE(expr), NULL); | |
1894 | 1693 |
1694 if (vim_result == NULL) | |
14 | 1695 raise_vim_exn(_("invalid expression")); |
1696 | |
4074 | 1697 result = vim_to_mzscheme(vim_result); |
1698 MZ_GC_CHECK(); | |
1894 | 1699 free_tv(vim_result); |
1700 | |
1701 MZ_GC_UNREG(); | |
14 | 1702 return result; |
1703 #else | |
1704 raise_vim_exn(_("expressions disabled at compile time")); | |
1705 /* unreachable */ | |
1706 return scheme_false; | |
1707 #endif | |
1708 } | |
1709 | |
1710 /* (range-start) */ | |
1711 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1712 get_range_start(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1713 { |
1714 return scheme_make_integer(range_start); | |
1715 } | |
1716 | |
1717 /* (range-end) */ | |
1718 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1719 get_range_end(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1720 { |
1721 return scheme_make_integer(range_end); | |
1722 } | |
1723 | |
1724 /* (beep) */ | |
1725 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1726 mzscheme_beep(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1727 { |
6949 | 1728 vim_beep(BO_LANG); |
14 | 1729 return scheme_void; |
1730 } | |
1731 | |
1732 static Scheme_Object *M_global = NULL; | |
1733 | |
1734 /* (get-option {option-name}) [buffer/window] */ | |
1735 static Scheme_Object * | |
1736 get_option(void *data, int argc, Scheme_Object **argv) | |
1737 { | |
1738 Vim_Prim *prim = (Vim_Prim *)data; | |
1739 long value; | |
1894 | 1740 char *strval; |
14 | 1741 int rc; |
4074 | 1742 Scheme_Object *rval = NULL; |
1743 Scheme_Object *name = NULL; | |
14 | 1744 int opt_flags = 0; |
1745 buf_T *save_curb = curbuf; | |
1746 win_T *save_curw = curwin; | |
1747 | |
4074 | 1748 MZ_GC_DECL_REG(2); |
1749 MZ_GC_VAR_IN_REG(0, rval); | |
1750 MZ_GC_VAR_IN_REG(1, name); | |
1751 MZ_GC_REG(); | |
1752 | |
1753 name = GUARANTEED_STRING_ARG(prim->name, 0); | |
14 | 1754 |
1755 if (argc > 1) | |
1756 { | |
1757 if (M_global == NULL) | |
1758 { | |
1759 MZ_REGISTER_STATIC(M_global); | |
1760 M_global = scheme_intern_symbol("global"); | |
1894 | 1761 MZ_GC_CHECK(); |
14 | 1762 } |
1763 | |
1764 if (argv[1] == M_global) | |
1765 opt_flags = OPT_GLOBAL; | |
1766 else if (SCHEME_VIMBUFFERP(argv[1])) | |
1767 { | |
1768 curbuf = get_valid_buffer(argv[1]); | |
1769 opt_flags = OPT_LOCAL; | |
1770 } | |
1771 else if (SCHEME_VIMWINDOWP(argv[1])) | |
1772 { | |
1773 win_T *win = get_valid_window(argv[1]); | |
1774 | |
1775 curwin = win; | |
1776 curbuf = win->w_buffer; | |
1777 opt_flags = OPT_LOCAL; | |
1778 } | |
1779 else | |
1780 scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv); | |
1781 } | |
1782 | |
4074 | 1783 rc = get_option_value(BYTE_STRING_VALUE(name), &value, (char_u **)&strval, opt_flags); |
14 | 1784 curbuf = save_curb; |
1785 curwin = save_curw; | |
1786 | |
1787 switch (rc) | |
1788 { | |
1789 case 1: | |
4074 | 1790 MZ_GC_UNREG(); |
14 | 1791 return scheme_make_integer_value(value); |
1792 case 0: | |
4074 | 1793 rval = scheme_make_byte_string(strval); |
1894 | 1794 MZ_GC_CHECK(); |
14 | 1795 vim_free(strval); |
4074 | 1796 MZ_GC_UNREG(); |
14 | 1797 return rval; |
1798 case -1: | |
1799 case -2: | |
4074 | 1800 MZ_GC_UNREG(); |
856 | 1801 raise_vim_exn(_("hidden option")); |
14 | 1802 case -3: |
4074 | 1803 MZ_GC_UNREG(); |
856 | 1804 raise_vim_exn(_("unknown option")); |
14 | 1805 } |
1806 /* unreachable */ | |
1807 return scheme_void; | |
1808 } | |
1809 | |
1810 /* (set-option {option-changing-string} [buffer/window]) */ | |
1811 static Scheme_Object * | |
1812 set_option(void *data, int argc, Scheme_Object **argv) | |
1813 { | |
4074 | 1814 char_u *command = NULL; |
14 | 1815 int opt_flags = 0; |
1816 buf_T *save_curb = curbuf; | |
1817 win_T *save_curw = curwin; | |
1818 Vim_Prim *prim = (Vim_Prim *)data; | |
4074 | 1819 Scheme_Object *cmd = NULL; |
1820 | |
1821 MZ_GC_DECL_REG(1); | |
1822 MZ_GC_VAR_IN_REG(0, cmd); | |
1823 MZ_GC_REG(); | |
1824 cmd = GUARANTEED_STRING_ARG(prim->name, 0); | |
1825 | |
14 | 1826 if (argc > 1) |
1827 { | |
1828 if (M_global == NULL) | |
1829 { | |
1830 MZ_REGISTER_STATIC(M_global); | |
1831 M_global = scheme_intern_symbol("global"); | |
1894 | 1832 MZ_GC_CHECK(); |
14 | 1833 } |
1834 | |
1835 if (argv[1] == M_global) | |
1836 opt_flags = OPT_GLOBAL; | |
1837 else if (SCHEME_VIMBUFFERP(argv[1])) | |
1838 { | |
1839 curbuf = get_valid_buffer(argv[1]); | |
1840 opt_flags = OPT_LOCAL; | |
1841 } | |
1842 else if (SCHEME_VIMWINDOWP(argv[1])) | |
1843 { | |
1844 win_T *win = get_valid_window(argv[1]); | |
1845 curwin = win; | |
1846 curbuf = win->w_buffer; | |
1847 opt_flags = OPT_LOCAL; | |
1848 } | |
1849 else | |
1850 scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv); | |
1851 } | |
1852 | |
1853 /* do_set can modify cmd, make copy */ | |
4074 | 1854 command = vim_strsave(BYTE_STRING_VALUE(cmd)); |
1855 MZ_GC_UNREG(); | |
1856 do_set(command, opt_flags); | |
1857 vim_free(command); | |
14 | 1858 update_screen(NOT_VALID); |
1859 curbuf = save_curb; | |
1860 curwin = save_curw; | |
1861 raise_if_error(); | |
1862 return scheme_void; | |
1863 } | |
1864 | |
1865 /* | |
1866 *=========================================================================== | |
1867 * 5. Vim Window-related Manipulation Functions | |
1868 *=========================================================================== | |
1869 */ | |
1870 | |
1871 /* (curr-win) */ | |
1872 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1873 get_curr_win(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1874 { |
1875 return (Scheme_Object *)get_vim_curr_window(); | |
1876 } | |
1877 | |
1878 /* (win-count) */ | |
1879 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1880 get_window_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1881 { |
4082 | 1882 int n = 0; |
1883 #ifdef FEAT_WINDOWS | |
14 | 1884 win_T *w; |
1885 | |
671 | 1886 for (w = firstwin; w != NULL; w = w->w_next) |
4082 | 1887 #endif |
671 | 1888 ++n; |
14 | 1889 return scheme_make_integer(n); |
1890 } | |
1891 | |
1892 /* (get-win-list [buffer]) */ | |
1893 static Scheme_Object * | |
1894 get_window_list(void *data, int argc, Scheme_Object **argv) | |
1895 { | |
1896 Vim_Prim *prim = (Vim_Prim *)data; | |
1897 vim_mz_buffer *buf; | |
1898 Scheme_Object *list; | |
4082 | 1899 win_T *w = firstwin; |
14 | 1900 |
1901 buf = get_buffer_arg(prim->name, 0, argc, argv); | |
1902 list = scheme_null; | |
1903 | |
4082 | 1904 #ifdef FEAT_WINDOWS |
1905 for ( ; w != NULL; w = w->w_next) | |
1906 #endif | |
856 | 1907 if (w->w_buffer == buf->buf) |
1894 | 1908 { |
14 | 1909 list = scheme_make_pair(window_new(w), list); |
1894 | 1910 MZ_GC_CHECK(); |
1911 } | |
14 | 1912 |
1913 return list; | |
1914 } | |
1915 | |
1916 static Scheme_Object * | |
1917 window_new(win_T *win) | |
1918 { | |
1894 | 1919 vim_mz_window *self = NULL; |
1920 | |
1921 MZ_GC_DECL_REG(1); | |
1922 MZ_GC_VAR_IN_REG(0, self); | |
14 | 1923 |
1924 /* We need to handle deletion of windows underneath us. | |
502 | 1925 * If we add a "w_mzscheme_ref" field to the win_T structure, |
14 | 1926 * then we can get at it in win_free() in vim. |
1927 * | |
1928 * On a win_free() we set the Scheme object's win_T *field | |
1929 * to an invalid value. We trap all uses of a window | |
1930 * object, and reject them if the win_T *field is invalid. | |
1931 */ | |
502 | 1932 if (win->w_mzscheme_ref != NULL) |
4074 | 1933 return (Scheme_Object *)WINDOW_REF(win); |
1934 | |
1935 MZ_GC_REG(); | |
1936 self = scheme_malloc_fail_ok(scheme_malloc_tagged, sizeof(vim_mz_window)); | |
14 | 1937 vim_memset(self, 0, sizeof(vim_mz_window)); |
4074 | 1938 #ifndef MZ_PRECISE_GC |
14 | 1939 scheme_dont_gc_ptr(self); /* because win isn't visible to GC */ |
4074 | 1940 #else |
1941 win->w_mzscheme_ref = scheme_malloc_immobile_box(NULL); | |
1942 #endif | |
1894 | 1943 MZ_GC_CHECK(); |
4074 | 1944 WINDOW_REF(win) = self; |
1945 MZ_GC_CHECK(); | |
14 | 1946 self->win = win; |
1894 | 1947 self->so.type = mz_window_type; |
1948 | |
1949 MZ_GC_UNREG(); | |
4074 | 1950 return (Scheme_Object *)self; |
14 | 1951 } |
1952 | |
1953 /* (get-win-num [window]) */ | |
1954 static Scheme_Object * | |
4082 | 1955 get_window_num(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1956 { |
4082 | 1957 int nr = 1; |
1958 #ifdef FEAT_WINDOWS | |
14 | 1959 Vim_Prim *prim = (Vim_Prim *)data; |
1960 win_T *win = get_window_arg(prim->name, 0, argc, argv)->win; | |
1961 win_T *wp; | |
1962 | |
1963 for (wp = firstwin; wp != win; wp = wp->w_next) | |
4082 | 1964 #endif |
14 | 1965 ++nr; |
1966 | |
1967 return scheme_make_integer(nr); | |
1968 } | |
1969 | |
1970 /* (get-win-by-num {windownum}) */ | |
1971 static Scheme_Object * | |
1972 get_window_by_num(void *data, int argc, Scheme_Object **argv) | |
1973 { | |
1974 Vim_Prim *prim = (Vim_Prim *)data; | |
4082 | 1975 win_T *win = firstwin; |
14 | 1976 int fnum; |
1977 | |
1978 fnum = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
1979 if (fnum < 1) | |
1980 scheme_signal_error(_("window index is out of range")); | |
1981 | |
4082 | 1982 #ifdef FEAT_WINDOWS |
1983 for ( ; win != NULL; win = win->w_next, --fnum) | |
1984 #endif | |
856 | 1985 if (fnum == 1) /* to be 1-based */ |
14 | 1986 return window_new(win); |
1987 | |
1988 return scheme_false; | |
1989 } | |
1990 | |
1991 /* (get-win-buffer [window]) */ | |
1992 static Scheme_Object * | |
1993 get_window_buffer(void *data, int argc, Scheme_Object **argv) | |
1994 { | |
1995 Vim_Prim *prim = (Vim_Prim *)data; | |
1996 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv); | |
1997 | |
1998 return buffer_new(win->win->w_buffer); | |
1999 } | |
2000 | |
2001 /* (get-win-height [window]) */ | |
2002 static Scheme_Object * | |
2003 get_window_height(void *data, int argc, Scheme_Object **argv) | |
2004 { | |
2005 Vim_Prim *prim = (Vim_Prim *)data; | |
2006 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv); | |
2007 | |
2008 return scheme_make_integer(win->win->w_height); | |
2009 } | |
2010 | |
2011 /* (set-win-height {height} [window]) */ | |
2012 static Scheme_Object * | |
2013 set_window_height(void *data, int argc, Scheme_Object **argv) | |
2014 { | |
2015 Vim_Prim *prim = (Vim_Prim *)data; | |
2016 vim_mz_window *win; | |
2017 win_T *savewin; | |
2018 int height; | |
2019 | |
2020 win = get_window_arg(prim->name, 1, argc, argv); | |
2021 height = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
2022 | |
2023 #ifdef FEAT_GUI | |
2024 need_mouse_correct = TRUE; | |
2025 #endif | |
2026 | |
2027 savewin = curwin; | |
2028 curwin = win->win; | |
2029 win_setheight(height); | |
2030 curwin = savewin; | |
2031 | |
2032 raise_if_error(); | |
2033 return scheme_void; | |
2034 } | |
2035 | |
2036 #ifdef FEAT_VERTSPLIT | |
2037 /* (get-win-width [window]) */ | |
2038 static Scheme_Object * | |
2039 get_window_width(void *data, int argc, Scheme_Object **argv) | |
2040 { | |
2041 Vim_Prim *prim = (Vim_Prim *)data; | |
2042 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv); | |
2043 | |
2044 return scheme_make_integer(W_WIDTH(win->win)); | |
2045 } | |
2046 | |
2047 /* (set-win-width {width} [window]) */ | |
2048 static Scheme_Object * | |
2049 set_window_width(void *data, int argc, Scheme_Object **argv) | |
2050 { | |
2051 Vim_Prim *prim = (Vim_Prim *)data; | |
2052 vim_mz_window *win; | |
2053 win_T *savewin; | |
2054 int width = 0; | |
2055 | |
2056 win = get_window_arg(prim->name, 1, argc, argv); | |
2057 width = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
2058 | |
2059 # ifdef FEAT_GUI | |
2060 need_mouse_correct = TRUE; | |
2061 # endif | |
2062 | |
2063 savewin = curwin; | |
2064 curwin = win->win; | |
2065 win_setwidth(width); | |
2066 curwin = savewin; | |
2067 | |
2068 raise_if_error(); | |
2069 return scheme_void; | |
2070 } | |
2071 #endif | |
2072 | |
2073 /* (get-cursor [window]) -> (line . col) */ | |
2074 static Scheme_Object * | |
2075 get_cursor(void *data, int argc, Scheme_Object **argv) | |
2076 { | |
2077 Vim_Prim *prim = (Vim_Prim *)data; | |
2078 vim_mz_window *win; | |
2079 pos_T pos; | |
2080 | |
2081 win = get_window_arg(prim->name, 0, argc, argv); | |
2082 pos = win->win->w_cursor; | |
2083 return scheme_make_pair(scheme_make_integer_value((long)pos.lnum), | |
2084 scheme_make_integer_value((long)pos.col + 1)); | |
2085 } | |
2086 | |
2087 /* (set-cursor (line . col) [window]) */ | |
2088 static Scheme_Object * | |
2089 set_cursor(void *data, int argc, Scheme_Object **argv) | |
2090 { | |
2091 Vim_Prim *prim = (Vim_Prim *)data; | |
2092 vim_mz_window *win; | |
2093 long lnum = 0; | |
2094 long col = 0; | |
2095 | |
274 | 2096 #ifdef HAVE_SANDBOX |
2097 sandbox_check(); | |
2098 #endif | |
14 | 2099 win = get_window_arg(prim->name, 1, argc, argv); |
2100 GUARANTEE_PAIR(prim->name, 0); | |
2101 | |
2102 if (!SCHEME_INTP(SCHEME_CAR(argv[0])) | |
2103 || !SCHEME_INTP(SCHEME_CDR(argv[0]))) | |
2104 scheme_wrong_type(prim->name, "integer pair", 0, argc, argv); | |
2105 | |
2106 lnum = SCHEME_INT_VAL(SCHEME_CAR(argv[0])); | |
2107 col = SCHEME_INT_VAL(SCHEME_CDR(argv[0])) - 1; | |
2108 | |
2109 check_line_range(lnum, win->win->w_buffer); | |
2110 /* don't know how to catch invalid column value */ | |
2111 | |
2112 win->win->w_cursor.lnum = lnum; | |
2113 win->win->w_cursor.col = col; | |
2114 update_screen(VALID); | |
2115 | |
2116 raise_if_error(); | |
2117 return scheme_void; | |
2118 } | |
2119 /* | |
2120 *=========================================================================== | |
2121 * 6. Vim Buffer-related Manipulation Functions | |
2122 *=========================================================================== | |
2123 */ | |
2124 | |
2125 /* (open-buff {filename}) */ | |
2126 static Scheme_Object * | |
2127 mzscheme_open_buffer(void *data, int argc, Scheme_Object **argv) | |
2128 { | |
2129 Vim_Prim *prim = (Vim_Prim *)data; | |
2130 int num = 0; | |
4074 | 2131 Scheme_Object *onum = NULL; |
2132 Scheme_Object *buf = NULL; | |
2133 Scheme_Object *fname; | |
2134 | |
2135 MZ_GC_DECL_REG(3); | |
2136 MZ_GC_VAR_IN_REG(0, onum); | |
2137 MZ_GC_VAR_IN_REG(1, buf); | |
2138 MZ_GC_VAR_IN_REG(2, fname); | |
2139 MZ_GC_REG(); | |
2140 fname = GUARANTEED_STRING_ARG(prim->name, 0); | |
14 | 2141 |
274 | 2142 #ifdef HAVE_SANDBOX |
2143 sandbox_check(); | |
2144 #endif | |
14 | 2145 /* TODO make open existing file */ |
4074 | 2146 num = buflist_add(BYTE_STRING_VALUE(fname), BLN_LISTED | BLN_CURBUF); |
14 | 2147 |
2148 if (num == 0) | |
2149 raise_vim_exn(_("couldn't open buffer")); | |
2150 | |
2151 onum = scheme_make_integer(num); | |
4074 | 2152 buf = get_buffer_by_num(data, 1, &onum); |
2153 MZ_GC_UNREG(); | |
2154 return buf; | |
14 | 2155 } |
2156 | |
2157 /* (get-buff-by-num {buffernum}) */ | |
2158 static Scheme_Object * | |
2159 get_buffer_by_num(void *data, int argc, Scheme_Object **argv) | |
2160 { | |
2161 Vim_Prim *prim = (Vim_Prim *)data; | |
2162 buf_T *buf; | |
2163 int fnum; | |
2164 | |
2165 fnum = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
2166 | |
2167 for (buf = firstbuf; buf; buf = buf->b_next) | |
856 | 2168 if (buf->b_fnum == fnum) |
14 | 2169 return buffer_new(buf); |
2170 | |
2171 return scheme_false; | |
2172 } | |
2173 | |
2174 /* (get-buff-by-name {buffername}) */ | |
2175 static Scheme_Object * | |
2176 get_buffer_by_name(void *data, int argc, Scheme_Object **argv) | |
2177 { | |
2178 Vim_Prim *prim = (Vim_Prim *)data; | |
2179 buf_T *buf; | |
4074 | 2180 Scheme_Object *buffer = NULL; |
2181 Scheme_Object *fname = NULL; | |
2182 | |
2183 MZ_GC_DECL_REG(2); | |
2184 MZ_GC_VAR_IN_REG(0, buffer); | |
2185 MZ_GC_VAR_IN_REG(1, fname); | |
2186 MZ_GC_REG(); | |
2187 fname = GUARANTEED_STRING_ARG(prim->name, 0); | |
2188 buffer = scheme_false; | |
14 | 2189 |
2190 for (buf = firstbuf; buf; buf = buf->b_next) | |
4074 | 2191 { |
14 | 2192 if (buf->b_ffname == NULL || buf->b_sfname == NULL) |
2193 /* empty string */ | |
2194 { | |
4074 | 2195 if (BYTE_STRING_VALUE(fname)[0] == NUL) |
2196 buffer = buffer_new(buf); | |
14 | 2197 } |
4074 | 2198 else if (!fnamecmp(buf->b_ffname, BYTE_STRING_VALUE(fname)) |
2199 || !fnamecmp(buf->b_sfname, BYTE_STRING_VALUE(fname))) | |
2200 { | |
14 | 2201 /* either short or long filename matches */ |
4074 | 2202 buffer = buffer_new(buf); |
2203 } | |
2204 } | |
2205 | |
2206 MZ_GC_UNREG(); | |
2207 return buffer; | |
14 | 2208 } |
2209 | |
2210 /* (get-next-buff [buffer]) */ | |
2211 static Scheme_Object * | |
2212 get_next_buffer(void *data, int argc, Scheme_Object **argv) | |
2213 { | |
2214 Vim_Prim *prim = (Vim_Prim *)data; | |
2215 buf_T *buf = get_buffer_arg(prim->name, 0, argc, argv)->buf; | |
2216 | |
2217 if (buf->b_next == NULL) | |
2218 return scheme_false; | |
2219 else | |
2220 return buffer_new(buf->b_next); | |
2221 } | |
2222 | |
2223 /* (get-prev-buff [buffer]) */ | |
2224 static Scheme_Object * | |
2225 get_prev_buffer(void *data, int argc, Scheme_Object **argv) | |
2226 { | |
2227 Vim_Prim *prim = (Vim_Prim *)data; | |
2228 buf_T *buf = get_buffer_arg(prim->name, 0, argc, argv)->buf; | |
2229 | |
2230 if (buf->b_prev == NULL) | |
2231 return scheme_false; | |
2232 else | |
2233 return buffer_new(buf->b_prev); | |
2234 } | |
2235 | |
2236 /* (get-buff-num [buffer]) */ | |
2237 static Scheme_Object * | |
2238 get_buffer_num(void *data, int argc, Scheme_Object **argv) | |
2239 { | |
2240 Vim_Prim *prim = (Vim_Prim *)data; | |
2241 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv); | |
2242 | |
2243 return scheme_make_integer(buf->buf->b_fnum); | |
2244 } | |
2245 | |
2246 /* (buff-count) */ | |
2247 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
2248 get_buffer_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 2249 { |
2250 buf_T *b; | |
2251 int n = 0; | |
2252 | |
2253 for (b = firstbuf; b; b = b->b_next) ++n; | |
2254 return scheme_make_integer(n); | |
2255 } | |
2256 | |
2257 /* (get-buff-name [buffer]) */ | |
2258 static Scheme_Object * | |
2259 get_buffer_name(void *data, int argc, Scheme_Object **argv) | |
2260 { | |
2261 Vim_Prim *prim = (Vim_Prim *)data; | |
2262 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv); | |
2263 | |
4074 | 2264 return scheme_make_byte_string((char *)buf->buf->b_ffname); |
14 | 2265 } |
2266 | |
2267 /* (curr-buff) */ | |
2268 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
2269 get_curr_buffer(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 2270 { |
2271 return (Scheme_Object *)get_vim_curr_buffer(); | |
2272 } | |
2273 | |
2274 static Scheme_Object * | |
2275 buffer_new(buf_T *buf) | |
2276 { | |
1894 | 2277 vim_mz_buffer *self = NULL; |
2278 | |
2279 MZ_GC_DECL_REG(1); | |
2280 MZ_GC_VAR_IN_REG(0, self); | |
14 | 2281 |
2282 /* We need to handle deletion of buffers underneath us. | |
502 | 2283 * If we add a "b_mzscheme_ref" field to the buf_T structure, |
14 | 2284 * then we can get at it in buf_freeall() in vim. |
2285 */ | |
502 | 2286 if (buf->b_mzscheme_ref) |
4074 | 2287 return (Scheme_Object *)BUFFER_REF(buf); |
2288 | |
2289 MZ_GC_REG(); | |
2290 self = scheme_malloc_fail_ok(scheme_malloc_tagged, sizeof(vim_mz_buffer)); | |
14 | 2291 vim_memset(self, 0, sizeof(vim_mz_buffer)); |
4074 | 2292 #ifndef MZ_PRECISE_GC |
2293 scheme_dont_gc_ptr(self); /* because buf isn't visible to GC */ | |
2294 #else | |
2295 buf->b_mzscheme_ref = scheme_malloc_immobile_box(NULL); | |
2296 #endif | |
1894 | 2297 MZ_GC_CHECK(); |
4074 | 2298 BUFFER_REF(buf) = self; |
2299 MZ_GC_CHECK(); | |
14 | 2300 self->buf = buf; |
1894 | 2301 self->so.type = mz_buffer_type; |
2302 | |
2303 MZ_GC_UNREG(); | |
4074 | 2304 return (Scheme_Object *)self; |
14 | 2305 } |
2306 | |
2307 /* | |
2308 * (get-buff-size [buffer]) | |
2309 * | |
2310 * Get the size (number of lines) in the current buffer. | |
2311 */ | |
2312 static Scheme_Object * | |
2313 get_buffer_size(void *data, int argc, Scheme_Object **argv) | |
2314 { | |
2315 Vim_Prim *prim = (Vim_Prim *)data; | |
2316 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv); | |
2317 | |
2318 return scheme_make_integer(buf->buf->b_ml.ml_line_count); | |
2319 } | |
2320 | |
2321 /* | |
2322 * (get-buff-line {linenr} [buffer]) | |
2323 * | |
2324 * Get a line from the specified buffer. The line number is | |
2325 * in Vim format (1-based). The line is returned as a MzScheme | |
2326 * string object. | |
2327 */ | |
2328 static Scheme_Object * | |
2329 get_buffer_line(void *data, int argc, Scheme_Object **argv) | |
2330 { | |
2331 Vim_Prim *prim = (Vim_Prim *)data; | |
2332 vim_mz_buffer *buf; | |
2333 int linenr; | |
1894 | 2334 char_u *line; |
14 | 2335 |
2336 buf = get_buffer_arg(prim->name, 1, argc, argv); | |
2337 linenr = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
2338 line = ml_get_buf(buf->buf, (linenr_T)linenr, FALSE); | |
2339 | |
2340 raise_if_error(); | |
4074 | 2341 return scheme_make_byte_string((char *)line); |
14 | 2342 } |
2343 | |
2344 | |
2345 /* | |
2346 * (get-buff-line-list {start} {end} [buffer]) | |
2347 * | |
2348 * Get a list of lines from the specified buffer. The line numbers | |
2349 * are in Vim format (1-based). The range is from lo up to, but not | |
2350 * including, hi. The list is returned as a list of string objects. | |
2351 */ | |
2352 static Scheme_Object * | |
2353 get_buffer_line_list(void *data, int argc, Scheme_Object **argv) | |
2354 { | |
2355 Vim_Prim *prim = (Vim_Prim *)data; | |
2356 vim_mz_buffer *buf; | |
2357 int i, hi, lo, n; | |
1894 | 2358 Scheme_Object *list = NULL; |
2359 | |
2360 MZ_GC_DECL_REG(1); | |
2361 MZ_GC_VAR_IN_REG(0, list); | |
2362 MZ_GC_REG(); | |
14 | 2363 |
2364 buf = get_buffer_arg(prim->name, 2, argc, argv); | |
2365 list = scheme_null; | |
2366 hi = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 1)); | |
2367 lo = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
2368 | |
2369 /* | |
2370 * Handle some error conditions | |
2371 */ | |
2372 if (lo < 0) | |
856 | 2373 lo = 0; |
14 | 2374 |
2375 if (hi < 0) | |
2376 hi = 0; | |
2377 if (hi < lo) | |
856 | 2378 hi = lo; |
14 | 2379 |
2380 n = hi - lo; | |
2381 | |
2382 for (i = n; i >= 0; --i) | |
2383 { | |
4074 | 2384 Scheme_Object *str = scheme_make_byte_string( |
14 | 2385 (char *)ml_get_buf(buf->buf, (linenr_T)(lo+i), FALSE)); |
2386 raise_if_error(); | |
2387 | |
2388 /* Set the list item */ | |
2389 list = scheme_make_pair(str, list); | |
1894 | 2390 MZ_GC_CHECK(); |
14 | 2391 } |
1894 | 2392 MZ_GC_UNREG(); |
14 | 2393 return list; |
2394 } | |
2395 | |
2396 /* | |
2397 * (set-buff-line {linenr} {string/#f} [buffer]) | |
2398 * | |
2399 * Replace a line in the specified buffer. The line number is | |
2400 * in Vim format (1-based). The replacement line is given as | |
2401 * an MzScheme string object. The object is checked for validity | |
2402 * and correct format. An exception is thrown if the values are not | |
2403 * the correct format. | |
2404 * | |
2405 * It returns a Scheme Object that indicates the length of the | |
2406 * string changed. | |
2407 */ | |
2408 static Scheme_Object * | |
2409 set_buffer_line(void *data, int argc, Scheme_Object **argv) | |
2410 { | |
2023 | 2411 /* First of all, we check the value of the supplied MzScheme object. |
14 | 2412 * There are three cases: |
2413 * 1. #f - this is a deletion. | |
2414 * 2. A string - this is a replacement. | |
2415 * 3. Anything else - this is an error. | |
2416 */ | |
2417 Vim_Prim *prim = (Vim_Prim *)data; | |
2418 vim_mz_buffer *buf; | |
1894 | 2419 Scheme_Object *line = NULL; |
14 | 2420 char *save; |
2421 int n; | |
2422 | |
1894 | 2423 MZ_GC_DECL_REG(1); |
2424 MZ_GC_VAR_IN_REG(0, line); | |
2425 MZ_GC_REG(); | |
2426 | |
274 | 2427 #ifdef HAVE_SANDBOX |
2428 sandbox_check(); | |
2429 #endif | |
14 | 2430 n = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); |
2431 if (!SCHEME_STRINGP(argv[1]) && !SCHEME_FALSEP(argv[1])) | |
856 | 2432 scheme_wrong_type(prim->name, "string or #f", 1, argc, argv); |
14 | 2433 line = argv[1]; |
2434 buf = get_buffer_arg(prim->name, 2, argc, argv); | |
2435 | |
2436 check_line_range(n, buf->buf); | |
2437 | |
2438 if (SCHEME_FALSEP(line)) | |
2439 { | |
1894 | 2440 buf_T *savebuf = curbuf; |
2441 | |
14 | 2442 curbuf = buf->buf; |
2443 | |
2444 if (u_savedel((linenr_T)n, 1L) == FAIL) | |
2445 { | |
2446 curbuf = savebuf; | |
2447 raise_vim_exn(_("cannot save undo information")); | |
2448 } | |
2449 else if (ml_delete((linenr_T)n, FALSE) == FAIL) | |
2450 { | |
2451 curbuf = savebuf; | |
2452 raise_vim_exn(_("cannot delete line")); | |
2453 } | |
2454 if (buf->buf == curwin->w_buffer) | |
2455 mz_fix_cursor(n, n + 1, -1); | |
1929 | 2456 deleted_lines_mark((linenr_T)n, 1L); |
14 | 2457 |
2458 curbuf = savebuf; | |
2459 | |
1894 | 2460 MZ_GC_UNREG(); |
14 | 2461 raise_if_error(); |
2462 return scheme_void; | |
2463 } | |
1894 | 2464 else |
14 | 2465 { |
1894 | 2466 /* Otherwise it's a line */ |
2467 buf_T *savebuf = curbuf; | |
2468 | |
2469 save = string_to_line(line); | |
2470 | |
2471 curbuf = buf->buf; | |
2472 | |
2473 if (u_savesub((linenr_T)n) == FAIL) | |
2474 { | |
2475 curbuf = savebuf; | |
2476 vim_free(save); | |
2477 raise_vim_exn(_("cannot save undo information")); | |
2478 } | |
2479 else if (ml_replace((linenr_T)n, (char_u *)save, TRUE) == FAIL) | |
2480 { | |
2481 curbuf = savebuf; | |
2482 vim_free(save); | |
2483 raise_vim_exn(_("cannot replace line")); | |
2484 } | |
2485 else | |
2486 { | |
2487 vim_free(save); | |
2488 changed_bytes((linenr_T)n, 0); | |
2489 } | |
2490 | |
14 | 2491 curbuf = savebuf; |
1894 | 2492 |
2493 /* Check that the cursor is not beyond the end of the line now. */ | |
2494 if (buf->buf == curwin->w_buffer) | |
2495 check_cursor_col(); | |
2496 | |
2497 MZ_GC_UNREG(); | |
2498 raise_if_error(); | |
2499 return scheme_void; | |
14 | 2500 } |
1894 | 2501 } |
2502 | |
2503 static void | |
2504 free_array(char **array) | |
2505 { | |
2506 char **curr = array; | |
2507 while (*curr != NULL) | |
2508 vim_free(*curr++); | |
2509 vim_free(array); | |
14 | 2510 } |
2511 | |
2512 /* | |
2513 * (set-buff-line-list {start} {end} {string-list/#f/null} [buffer]) | |
2514 * | |
2515 * Replace a range of lines in the specified buffer. The line numbers are in | |
2516 * Vim format (1-based). The range is from lo up to, but not including, hi. | |
2517 * The replacement lines are given as a Scheme list of string objects. The | |
2518 * list is checked for validity and correct format. | |
2519 * | |
2520 * Errors are returned as a value of FAIL. The return value is OK on success. | |
2521 * If OK is returned and len_change is not NULL, *len_change is set to the | |
2522 * change in the buffer length. | |
2523 */ | |
2524 static Scheme_Object * | |
2525 set_buffer_line_list(void *data, int argc, Scheme_Object **argv) | |
2526 { | |
2527 /* First of all, we check the type of the supplied MzScheme object. | |
2528 * There are three cases: | |
2529 * 1. #f - this is a deletion. | |
2530 * 2. A list - this is a replacement. | |
2531 * 3. Anything else - this is an error. | |
2532 */ | |
2533 Vim_Prim *prim = (Vim_Prim *)data; | |
1894 | 2534 vim_mz_buffer *buf = NULL; |
2535 Scheme_Object *line_list = NULL; | |
14 | 2536 int i, old_len, new_len, hi, lo; |
2537 long extra; | |
2538 | |
1894 | 2539 MZ_GC_DECL_REG(1); |
2540 MZ_GC_VAR_IN_REG(0, line_list); | |
2541 MZ_GC_REG(); | |
2542 | |
274 | 2543 #ifdef HAVE_SANDBOX |
2544 sandbox_check(); | |
2545 #endif | |
14 | 2546 lo = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); |
2547 hi = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 1)); | |
2548 if (!SCHEME_PAIRP(argv[2]) | |
2549 && !SCHEME_FALSEP(argv[2]) && !SCHEME_NULLP(argv[2])) | |
2550 scheme_wrong_type(prim->name, "list or #f", 2, argc, argv); | |
2551 line_list = argv[2]; | |
2552 buf = get_buffer_arg(prim->name, 3, argc, argv); | |
2553 old_len = hi - lo; | |
2554 if (old_len < 0) /* process inverse values wisely */ | |
2555 { | |
2556 i = lo; | |
2557 lo = hi; | |
2558 hi = i; | |
2559 old_len = -old_len; | |
2560 } | |
2561 extra = 0; | |
2562 | |
2563 check_line_range(lo, buf->buf); /* inclusive */ | |
1228 | 2564 check_line_range(hi - 1, buf->buf); /* exclusive */ |
14 | 2565 |
2566 if (SCHEME_FALSEP(line_list) || SCHEME_NULLP(line_list)) | |
2567 { | |
1894 | 2568 buf_T *savebuf = curbuf; |
14 | 2569 curbuf = buf->buf; |
2570 | |
2571 if (u_savedel((linenr_T)lo, (long)old_len) == FAIL) | |
2572 { | |
2573 curbuf = savebuf; | |
2574 raise_vim_exn(_("cannot save undo information")); | |
2575 } | |
2576 else | |
2577 { | |
2578 for (i = 0; i < old_len; i++) | |
2579 if (ml_delete((linenr_T)lo, FALSE) == FAIL) | |
2580 { | |
2581 curbuf = savebuf; | |
2582 raise_vim_exn(_("cannot delete line")); | |
2583 } | |
2584 if (buf->buf == curwin->w_buffer) | |
2585 mz_fix_cursor(lo, hi, -old_len); | |
1929 | 2586 deleted_lines_mark((linenr_T)lo, (long)old_len); |
14 | 2587 } |
2588 | |
2589 curbuf = savebuf; | |
2590 | |
1894 | 2591 MZ_GC_UNREG(); |
14 | 2592 raise_if_error(); |
2593 return scheme_void; | |
2594 } | |
1894 | 2595 else |
14 | 2596 { |
1894 | 2597 buf_T *savebuf = curbuf; |
2598 | |
2599 /* List */ | |
2600 new_len = scheme_proper_list_length(line_list); | |
2601 MZ_GC_CHECK(); | |
2602 if (new_len < 0) /* improper or cyclic list */ | |
2603 scheme_wrong_type(prim->name, "proper list", | |
2604 2, argc, argv); | |
2605 else | |
14 | 2606 { |
1894 | 2607 char **array = NULL; |
2608 Scheme_Object *line = NULL; | |
2609 Scheme_Object *rest = NULL; | |
2610 | |
2611 MZ_GC_DECL_REG(2); | |
2612 MZ_GC_VAR_IN_REG(0, line); | |
2613 MZ_GC_VAR_IN_REG(1, rest); | |
2614 MZ_GC_REG(); | |
2615 | |
4074 | 2616 array = (char **)alloc((new_len+1)* sizeof(char *)); |
2617 vim_memset(array, 0, (new_len+1) * sizeof(char *)); | |
1894 | 2618 |
2619 rest = line_list; | |
2620 for (i = 0; i < new_len; ++i) | |
2621 { | |
2622 line = SCHEME_CAR(rest); | |
2623 rest = SCHEME_CDR(rest); | |
2624 if (!SCHEME_STRINGP(line)) | |
2625 { | |
2626 free_array(array); | |
2627 scheme_wrong_type(prim->name, "string-list", 2, argc, argv); | |
2628 } | |
2629 array[i] = string_to_line(line); | |
2630 } | |
2631 | |
2632 curbuf = buf->buf; | |
2633 | |
2634 if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL) | |
2635 { | |
2636 curbuf = savebuf; | |
2637 free_array(array); | |
2638 raise_vim_exn(_("cannot save undo information")); | |
2639 } | |
2640 | |
2641 /* | |
2642 * If the size of the range is reducing (ie, new_len < old_len) we | |
2643 * need to delete some old_len. We do this at the start, by | |
2644 * repeatedly deleting line "lo". | |
2645 */ | |
2646 for (i = 0; i < old_len - new_len; ++i) | |
2647 { | |
2648 if (ml_delete((linenr_T)lo, FALSE) == FAIL) | |
2649 { | |
2650 curbuf = savebuf; | |
2651 free_array(array); | |
2652 raise_vim_exn(_("cannot delete line")); | |
2653 } | |
2654 extra--; | |
2655 } | |
2656 | |
2657 /* | |
2658 * For as long as possible, replace the existing old_len with the | |
2659 * new old_len. This is a more efficient operation, as it requires | |
2660 * less memory allocation and freeing. | |
2661 */ | |
2662 for (i = 0; i < old_len && i < new_len; i++) | |
2663 if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], TRUE) == FAIL) | |
2664 { | |
2665 curbuf = savebuf; | |
2666 free_array(array); | |
2667 raise_vim_exn(_("cannot replace line")); | |
2668 } | |
2669 | |
2670 /* | |
2671 * Now we may need to insert the remaining new_len. We don't need to | |
2672 * free the string passed back because MzScheme has control of that | |
2673 * memory. | |
2674 */ | |
2675 while (i < new_len) | |
2676 { | |
2677 if (ml_append((linenr_T)(lo + i - 1), | |
2678 (char_u *)array[i], 0, FALSE) == FAIL) | |
2679 { | |
2680 curbuf = savebuf; | |
2681 free_array(array); | |
2682 raise_vim_exn(_("cannot insert line")); | |
2683 } | |
2684 ++i; | |
2685 ++extra; | |
2686 } | |
2687 MZ_GC_UNREG(); | |
2688 free_array(array); | |
14 | 2689 } |
1894 | 2690 |
2691 /* | |
2692 * Adjust marks. Invalidate any which lie in the | |
2693 * changed range, and move any in the remainder of the buffer. | |
2694 */ | |
2695 mark_adjust((linenr_T)lo, (linenr_T)(hi - 1), (long)MAXLNUM, (long)extra); | |
2696 changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra); | |
2697 | |
2698 if (buf->buf == curwin->w_buffer) | |
2699 mz_fix_cursor(lo, hi, extra); | |
2700 curbuf = savebuf; | |
2701 | |
2702 MZ_GC_UNREG(); | |
2703 raise_if_error(); | |
2704 return scheme_void; | |
14 | 2705 } |
2706 } | |
2707 | |
2708 /* | |
2709 * (insert-buff-line-list {linenr} {string/string-list} [buffer]) | |
2710 * | |
2023 | 2711 * Insert a number of lines into the specified buffer after the specified line. |
14 | 2712 * The line number is in Vim format (1-based). The lines to be inserted are |
2713 * given as an MzScheme list of string objects or as a single string. The lines | |
2714 * to be added are checked for validity and correct format. Errors are | |
2715 * returned as a value of FAIL. The return value is OK on success. | |
2716 * If OK is returned and len_change is not NULL, *len_change | |
2717 * is set to the change in the buffer length. | |
2718 */ | |
2719 static Scheme_Object * | |
2720 insert_buffer_line_list(void *data, int argc, Scheme_Object **argv) | |
2721 { | |
2722 Vim_Prim *prim = (Vim_Prim *)data; | |
1894 | 2723 vim_mz_buffer *buf = NULL; |
2724 Scheme_Object *list = NULL; | |
2725 char *str = NULL; | |
14 | 2726 int i, n, size; |
2727 | |
1894 | 2728 MZ_GC_DECL_REG(1); |
2729 MZ_GC_VAR_IN_REG(0, list); | |
2730 MZ_GC_REG(); | |
2731 | |
274 | 2732 #ifdef HAVE_SANDBOX |
2733 sandbox_check(); | |
2734 #endif | |
14 | 2735 /* |
2736 * First of all, we check the type of the supplied MzScheme object. | |
2737 * It must be a string or a list, or the call is in error. | |
2738 */ | |
2739 n = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
2740 list = argv[1]; | |
2741 | |
2742 if (!SCHEME_STRINGP(list) && !SCHEME_PAIRP(list)) | |
2743 scheme_wrong_type(prim->name, "string or list", 1, argc, argv); | |
2744 buf = get_buffer_arg(prim->name, 2, argc, argv); | |
2745 | |
2746 if (n != 0) /* 0 can be used in insert */ | |
856 | 2747 check_line_range(n, buf->buf); |
14 | 2748 if (SCHEME_STRINGP(list)) |
2749 { | |
1894 | 2750 buf_T *savebuf = curbuf; |
2751 | |
14 | 2752 str = string_to_line(list); |
2753 curbuf = buf->buf; | |
2754 | |
2755 if (u_save((linenr_T)n, (linenr_T)(n+1)) == FAIL) | |
2756 { | |
2757 curbuf = savebuf; | |
1894 | 2758 vim_free(str); |
14 | 2759 raise_vim_exn(_("cannot save undo information")); |
2760 } | |
2761 else if (ml_append((linenr_T)n, (char_u *)str, 0, FALSE) == FAIL) | |
2762 { | |
2763 curbuf = savebuf; | |
1894 | 2764 vim_free(str); |
14 | 2765 raise_vim_exn(_("cannot insert line")); |
2766 } | |
2767 else | |
1894 | 2768 { |
2769 vim_free(str); | |
14 | 2770 appended_lines_mark((linenr_T)n, 1L); |
1894 | 2771 } |
14 | 2772 |
2773 curbuf = savebuf; | |
2774 update_screen(VALID); | |
2775 | |
1894 | 2776 MZ_GC_UNREG(); |
14 | 2777 raise_if_error(); |
2778 return scheme_void; | |
2779 } | |
2780 | |
2781 /* List */ | |
2782 size = scheme_proper_list_length(list); | |
1894 | 2783 MZ_GC_CHECK(); |
14 | 2784 if (size < 0) /* improper or cyclic list */ |
2785 scheme_wrong_type(prim->name, "proper list", | |
2786 2, argc, argv); | |
2787 else | |
2788 { | |
1894 | 2789 Scheme_Object *line = NULL; |
2790 Scheme_Object *rest = NULL; | |
2791 char **array; | |
2792 buf_T *savebuf = curbuf; | |
2793 | |
2794 MZ_GC_DECL_REG(2); | |
2795 MZ_GC_VAR_IN_REG(0, line); | |
2796 MZ_GC_VAR_IN_REG(1, rest); | |
2797 MZ_GC_REG(); | |
2798 | |
4074 | 2799 array = (char **)alloc((size+1) * sizeof(char *)); |
2800 vim_memset(array, 0, (size+1) * sizeof(char *)); | |
1894 | 2801 |
2802 rest = list; | |
856 | 2803 for (i = 0; i < size; ++i) |
1894 | 2804 { |
2805 line = SCHEME_CAR(rest); | |
2806 rest = SCHEME_CDR(rest); | |
2807 array[i] = string_to_line(line); | |
2808 } | |
2809 | |
2810 curbuf = buf->buf; | |
2811 | |
2812 if (u_save((linenr_T)n, (linenr_T)(n + 1)) == FAIL) | |
2813 { | |
2814 curbuf = savebuf; | |
2815 free_array(array); | |
2816 raise_vim_exn(_("cannot save undo information")); | |
2817 } | |
2818 else | |
2819 { | |
2820 for (i = 0; i < size; ++i) | |
2821 if (ml_append((linenr_T)(n + i), (char_u *)array[i], | |
2822 0, FALSE) == FAIL) | |
2823 { | |
2824 curbuf = savebuf; | |
2825 free_array(array); | |
2826 raise_vim_exn(_("cannot insert line")); | |
2827 } | |
2828 | |
2829 if (i > 0) | |
2830 appended_lines_mark((linenr_T)n, (long)i); | |
2831 } | |
2832 free_array(array); | |
2833 MZ_GC_UNREG(); | |
2834 curbuf = savebuf; | |
2835 update_screen(VALID); | |
14 | 2836 } |
2837 | |
1894 | 2838 MZ_GC_UNREG(); |
14 | 2839 raise_if_error(); |
2840 return scheme_void; | |
2841 } | |
2842 | |
2843 /* | |
2844 * Predicates | |
2845 */ | |
2846 /* (buff? obj) */ | |
2847 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
2848 vim_bufferp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) |
14 | 2849 { |
2850 if (SCHEME_VIMBUFFERP(argv[0])) | |
2851 return scheme_true; | |
2852 else | |
2853 return scheme_false; | |
2854 } | |
2855 | |
2856 /* (win? obj) */ | |
2857 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
2858 vim_windowp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) |
14 | 2859 { |
2860 if (SCHEME_VIMWINDOWP(argv[0])) | |
2861 return scheme_true; | |
2862 else | |
2863 return scheme_false; | |
2864 } | |
2865 | |
2866 /* (buff-valid? obj) */ | |
2867 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
2868 vim_buffer_validp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) |
14 | 2869 { |
2870 if (SCHEME_VIMBUFFERP(argv[0]) | |
2871 && ((vim_mz_buffer *)argv[0])->buf != INVALID_BUFFER_VALUE) | |
2872 return scheme_true; | |
2873 else | |
2874 return scheme_false; | |
2875 } | |
2876 | |
2877 /* (win-valid? obj) */ | |
2878 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
2879 vim_window_validp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) |
14 | 2880 { |
2881 if (SCHEME_VIMWINDOWP(argv[0]) | |
2882 && ((vim_mz_window *)argv[0])->win != INVALID_WINDOW_VALUE) | |
2883 return scheme_true; | |
2884 else | |
2885 return scheme_false; | |
2886 } | |
2887 | |
2888 /* | |
2889 *=========================================================================== | |
2890 * Utilities | |
2891 *=========================================================================== | |
2892 */ | |
2893 | |
2894 /* | |
2895 * Convert an MzScheme string into a Vim line. | |
2896 * | |
1894 | 2897 * All internal nulls are replaced by newline characters. |
2898 * It is an error for the string to contain newline characters. | |
14 | 2899 * |
1894 | 2900 * Returns pointer to Vim allocated memory |
14 | 2901 */ |
2902 static char * | |
2903 string_to_line(Scheme_Object *obj) | |
2904 { | |
1894 | 2905 char *scheme_str = NULL; |
2906 char *vim_str = NULL; | |
4074 | 2907 OUTPUT_LEN_TYPE len; |
14 | 2908 int i; |
2909 | |
1894 | 2910 scheme_str = scheme_display_to_string(obj, &len); |
14 | 2911 |
2912 /* Error checking: String must not contain newlines, as we | |
2913 * are replacing a single line, and we must replace it with | |
2914 * a single line. | |
2915 */ | |
4074 | 2916 if (memchr(scheme_str, '\n', len)) |
14 | 2917 scheme_signal_error(_("string cannot contain newlines")); |
2918 | |
4074 | 2919 vim_str = (char *)alloc(len + 1); |
1894 | 2920 |
14 | 2921 /* Create a copy of the string, with internal nulls replaced by |
2922 * newline characters, as is the vim convention. | |
2923 */ | |
2924 for (i = 0; i < len; ++i) | |
2925 { | |
1894 | 2926 if (scheme_str[i] == '\0') |
2927 vim_str[i] = '\n'; | |
2928 else | |
2929 vim_str[i] = scheme_str[i]; | |
2930 } | |
2931 | |
2932 vim_str[i] = '\0'; | |
2933 | |
2934 MZ_GC_CHECK(); | |
2935 return vim_str; | |
2936 } | |
2937 | |
2938 #ifdef FEAT_EVAL | |
2939 /* | |
2940 * Convert Vim value into MzScheme, adopted from if_python.c | |
2941 */ | |
2942 static Scheme_Object * | |
4074 | 2943 vim_to_mzscheme(typval_T *vim_value) |
2944 { | |
2945 Scheme_Object *result = NULL; | |
2946 /* hash table to store visited values to avoid infinite loops */ | |
2947 Scheme_Hash_Table *visited = NULL; | |
2948 | |
2949 MZ_GC_DECL_REG(2); | |
2950 MZ_GC_VAR_IN_REG(0, result); | |
2951 MZ_GC_VAR_IN_REG(1, visited); | |
2952 MZ_GC_REG(); | |
2953 | |
2954 visited = scheme_make_hash_table(SCHEME_hash_ptr); | |
2955 MZ_GC_CHECK(); | |
2956 | |
2957 result = vim_to_mzscheme_impl(vim_value, 1, visited); | |
2958 | |
2959 MZ_GC_UNREG(); | |
2960 return result; | |
2961 } | |
2962 | |
2963 static Scheme_Object * | |
2964 vim_to_mzscheme_impl(typval_T *vim_value, int depth, Scheme_Hash_Table *visited) | |
1894 | 2965 { |
2966 Scheme_Object *result = NULL; | |
2967 int new_value = TRUE; | |
2968 | |
4074 | 2969 MZ_GC_DECL_REG(2); |
1894 | 2970 MZ_GC_VAR_IN_REG(0, result); |
4074 | 2971 MZ_GC_VAR_IN_REG(1, visited); |
1894 | 2972 MZ_GC_REG(); |
2973 | |
2974 /* Avoid infinite recursion */ | |
2975 if (depth > 100) | |
2976 { | |
2977 MZ_GC_UNREG(); | |
2978 return scheme_void; | |
2979 } | |
2980 | |
2981 /* Check if we run into a recursive loop. The item must be in visited | |
2982 * then and we can use it again. | |
2983 */ | |
2984 result = scheme_hash_get(visited, (Scheme_Object *)vim_value); | |
2985 MZ_GC_CHECK(); | |
2986 if (result != NULL) /* found, do nothing */ | |
2987 new_value = FALSE; | |
2988 else if (vim_value->v_type == VAR_STRING) | |
2989 { | |
4074 | 2990 result = scheme_make_byte_string((char *)vim_value->vval.v_string); |
1894 | 2991 MZ_GC_CHECK(); |
2992 } | |
2993 else if (vim_value->v_type == VAR_NUMBER) | |
2994 { | |
2995 result = scheme_make_integer((long)vim_value->vval.v_number); | |
2996 MZ_GC_CHECK(); | |
2997 } | |
2998 # ifdef FEAT_FLOAT | |
2999 else if (vim_value->v_type == VAR_FLOAT) | |
3000 { | |
3001 result = scheme_make_double((double)vim_value->vval.v_float); | |
3002 MZ_GC_CHECK(); | |
14 | 3003 } |
1894 | 3004 # endif |
3005 else if (vim_value->v_type == VAR_LIST) | |
3006 { | |
3007 list_T *list = vim_value->vval.v_list; | |
3008 listitem_T *curr; | |
3009 | |
3010 if (list == NULL || list->lv_first == NULL) | |
3011 result = scheme_null; | |
3012 else | |
3013 { | |
3014 Scheme_Object *obj = NULL; | |
3015 | |
3016 MZ_GC_DECL_REG(1); | |
3017 MZ_GC_VAR_IN_REG(0, obj); | |
3018 MZ_GC_REG(); | |
3019 | |
3020 curr = list->lv_last; | |
4074 | 3021 obj = vim_to_mzscheme_impl(&curr->li_tv, depth + 1, visited); |
1894 | 3022 result = scheme_make_pair(obj, scheme_null); |
3023 MZ_GC_CHECK(); | |
3024 | |
3025 while (curr != list->lv_first) | |
3026 { | |
3027 curr = curr->li_prev; | |
4074 | 3028 obj = vim_to_mzscheme_impl(&curr->li_tv, depth + 1, visited); |
1894 | 3029 result = scheme_make_pair(obj, result); |
3030 MZ_GC_CHECK(); | |
3031 } | |
3032 } | |
3033 MZ_GC_UNREG(); | |
3034 } | |
3035 else if (vim_value->v_type == VAR_DICT) | |
3036 { | |
3037 Scheme_Object *key = NULL; | |
3038 Scheme_Object *obj = NULL; | |
3039 | |
3040 MZ_GC_DECL_REG(2); | |
3041 MZ_GC_VAR_IN_REG(0, key); | |
3042 MZ_GC_VAR_IN_REG(1, obj); | |
3043 MZ_GC_REG(); | |
3044 | |
3045 result = (Scheme_Object *)scheme_make_hash_table(SCHEME_hash_ptr); | |
3046 MZ_GC_CHECK(); | |
3047 if (vim_value->vval.v_dict != NULL) | |
3048 { | |
3049 hashtab_T *ht = &vim_value->vval.v_dict->dv_hashtab; | |
3050 long_u todo = ht->ht_used; | |
3051 hashitem_T *hi; | |
3052 dictitem_T *di; | |
3053 | |
3054 for (hi = ht->ht_array; todo > 0; ++hi) | |
3055 { | |
3056 if (!HASHITEM_EMPTY(hi)) | |
3057 { | |
3058 --todo; | |
3059 | |
3060 di = dict_lookup(hi); | |
4074 | 3061 obj = vim_to_mzscheme_impl(&di->di_tv, depth + 1, visited); |
3062 key = scheme_make_byte_string((char *)hi->hi_key); | |
1894 | 3063 MZ_GC_CHECK(); |
3064 scheme_hash_set((Scheme_Hash_Table *)result, key, obj); | |
3065 MZ_GC_CHECK(); | |
3066 } | |
3067 } | |
3068 } | |
3069 MZ_GC_UNREG(); | |
3070 } | |
4074 | 3071 else if (vim_value->v_type == VAR_FUNC) |
3072 { | |
3073 Scheme_Object *funcname = NULL; | |
3074 | |
3075 MZ_GC_DECL_REG(1); | |
3076 MZ_GC_VAR_IN_REG(0, funcname); | |
3077 MZ_GC_REG(); | |
3078 | |
3079 funcname = scheme_make_byte_string((char *)vim_value->vval.v_string); | |
3080 MZ_GC_CHECK(); | |
3081 result = scheme_make_closed_prim_w_arity(vim_funcref, funcname, | |
3082 (const char *)BYTE_STRING_VALUE(funcname), 0, -1); | |
3083 MZ_GC_CHECK(); | |
3084 | |
3085 MZ_GC_UNREG(); | |
3086 } | |
1894 | 3087 else |
3088 { | |
3089 result = scheme_void; | |
3090 new_value = FALSE; | |
3091 } | |
3092 if (new_value) | |
3093 { | |
3094 scheme_hash_set(visited, (Scheme_Object *)vim_value, result); | |
3095 MZ_GC_CHECK(); | |
3096 } | |
3097 MZ_GC_UNREG(); | |
3098 return result; | |
14 | 3099 } |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3100 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3101 static int |
4074 | 3102 mzscheme_to_vim(Scheme_Object *obj, typval_T *tv) |
3103 { | |
3104 int i, status; | |
3105 Scheme_Hash_Table *visited = NULL; | |
3106 | |
3107 MZ_GC_DECL_REG(2); | |
3108 MZ_GC_VAR_IN_REG(0, obj); | |
3109 MZ_GC_VAR_IN_REG(1, visited); | |
3110 MZ_GC_REG(); | |
3111 | |
3112 visited = scheme_make_hash_table(SCHEME_hash_ptr); | |
3113 MZ_GC_CHECK(); | |
3114 | |
3115 status = mzscheme_to_vim_impl(obj, tv, 1, visited); | |
3116 for (i = 0; i < visited->size; ++i) | |
3117 { | |
3118 /* free up remembered objects */ | |
3119 if (visited->vals[i] != NULL) | |
3120 free_tv((typval_T *)visited->vals[i]); | |
3121 } | |
3122 | |
3123 MZ_GC_UNREG(); | |
3124 return status; | |
3125 } | |
3126 static int | |
3127 mzscheme_to_vim_impl(Scheme_Object *obj, typval_T *tv, int depth, | |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3128 Scheme_Hash_Table *visited) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3129 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3130 int status = OK; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3131 typval_T *found; |
4074 | 3132 |
3133 MZ_GC_DECL_REG(2); | |
3134 MZ_GC_VAR_IN_REG(0, obj); | |
3135 MZ_GC_VAR_IN_REG(1, visited); | |
3136 MZ_GC_REG(); | |
3137 | |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3138 MZ_GC_CHECK(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3139 if (depth > 100) /* limit the deepest recursion level */ |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3140 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3141 tv->v_type = VAR_NUMBER; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3142 tv->vval.v_number = 0; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3143 return FAIL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3144 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3145 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3146 found = (typval_T *)scheme_hash_get(visited, obj); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3147 if (found != NULL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3148 copy_tv(found, tv); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3149 else if (SCHEME_VOIDP(obj)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3150 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3151 tv->v_type = VAR_NUMBER; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3152 tv->vval.v_number = 0; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3153 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3154 else if (SCHEME_INTP(obj)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3155 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3156 tv->v_type = VAR_NUMBER; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3157 tv->vval.v_number = SCHEME_INT_VAL(obj); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3158 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3159 else if (SCHEME_BOOLP(obj)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3160 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3161 tv->v_type = VAR_NUMBER; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3162 tv->vval.v_number = SCHEME_TRUEP(obj); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3163 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3164 # ifdef FEAT_FLOAT |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3165 else if (SCHEME_DBLP(obj)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3166 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3167 tv->v_type = VAR_FLOAT; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3168 tv->vval.v_float = SCHEME_DBL_VAL(obj); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3169 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3170 # endif |
4074 | 3171 else if (SCHEME_BYTE_STRINGP(obj)) |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3172 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3173 tv->v_type = VAR_STRING; |
4074 | 3174 tv->vval.v_string = vim_strsave(BYTE_STRING_VALUE(obj)); |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3175 } |
4074 | 3176 # if MZSCHEME_VERSION_MAJOR >= 299 |
3177 else if (SCHEME_CHAR_STRINGP(obj)) | |
3178 { | |
3179 Scheme_Object *tmp = NULL; | |
3180 MZ_GC_DECL_REG(1); | |
3181 MZ_GC_VAR_IN_REG(0, tmp); | |
3182 MZ_GC_REG(); | |
3183 | |
3184 tmp = scheme_char_string_to_byte_string(obj); | |
3185 tv->v_type = VAR_STRING; | |
3186 tv->vval.v_string = vim_strsave(BYTE_STRING_VALUE(tmp)); | |
3187 MZ_GC_UNREG(); | |
3188 } | |
3189 #endif | |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3190 else if (SCHEME_VECTORP(obj) || SCHEME_NULLP(obj) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3191 || SCHEME_PAIRP(obj) || SCHEME_MUTABLE_PAIRP(obj)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3192 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3193 list_T *list = list_alloc(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3194 if (list == NULL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3195 status = FAIL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3196 else |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3197 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3198 int i; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3199 Scheme_Object *curr = NULL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3200 Scheme_Object *cval = NULL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3201 /* temporary var to hold current element of vectors and pairs */ |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3202 typval_T *v; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3203 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3204 MZ_GC_DECL_REG(2); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3205 MZ_GC_VAR_IN_REG(0, curr); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3206 MZ_GC_VAR_IN_REG(1, cval); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3207 MZ_GC_REG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3208 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3209 tv->v_type = VAR_LIST; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3210 tv->vval.v_list = list; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3211 ++list->lv_refcount; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3212 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3213 v = (typval_T *)alloc(sizeof(typval_T)); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3214 if (v == NULL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3215 status = FAIL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3216 else |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3217 { |
4352 | 3218 /* add the value in advance to allow handling of self-referential |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3219 * data structures */ |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3220 typval_T *visited_tv = (typval_T *)alloc(sizeof(typval_T)); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3221 copy_tv(tv, visited_tv); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3222 scheme_hash_set(visited, obj, (Scheme_Object *)visited_tv); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3223 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3224 if (SCHEME_VECTORP(obj)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3225 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3226 for (i = 0; i < SCHEME_VEC_SIZE(obj); ++i) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3227 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3228 cval = SCHEME_VEC_ELS(obj)[i]; |
4074 | 3229 status = mzscheme_to_vim_impl(cval, v, depth + 1, visited); |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3230 if (status == FAIL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3231 break; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3232 status = list_append_tv(list, v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3233 clear_tv(v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3234 if (status == FAIL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3235 break; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3236 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3237 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3238 else if (SCHEME_PAIRP(obj) || SCHEME_MUTABLE_PAIRP(obj)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3239 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3240 for (curr = obj; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3241 SCHEME_PAIRP(curr) || SCHEME_MUTABLE_PAIRP(curr); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3242 curr = SCHEME_CDR(curr)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3243 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3244 cval = SCHEME_CAR(curr); |
4074 | 3245 status = mzscheme_to_vim_impl(cval, v, depth + 1, visited); |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3246 if (status == FAIL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3247 break; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3248 status = list_append_tv(list, v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3249 clear_tv(v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3250 if (status == FAIL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3251 break; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3252 } |
4352 | 3253 /* improper list not terminated with null |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3254 * need to handle the last element */ |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3255 if (status == OK && !SCHEME_NULLP(curr)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3256 { |
4074 | 3257 status = mzscheme_to_vim_impl(cval, v, depth + 1, visited); |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3258 if (status == OK) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3259 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3260 status = list_append_tv(list, v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3261 clear_tv(v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3262 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3263 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3264 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3265 /* nothing to do for scheme_null */ |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3266 vim_free(v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3267 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3268 MZ_GC_UNREG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3269 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3270 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3271 else if (SCHEME_HASHTP(obj)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3272 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3273 int i; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3274 dict_T *dict; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3275 Scheme_Object *key = NULL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3276 Scheme_Object *val = NULL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3277 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3278 MZ_GC_DECL_REG(2); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3279 MZ_GC_VAR_IN_REG(0, key); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3280 MZ_GC_VAR_IN_REG(1, val); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3281 MZ_GC_REG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3282 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3283 dict = dict_alloc(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3284 if (dict == NULL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3285 status = FAIL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3286 else |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3287 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3288 typval_T *visited_tv = (typval_T *)alloc(sizeof(typval_T)); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3289 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3290 tv->v_type = VAR_DICT; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3291 tv->vval.v_dict = dict; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3292 ++dict->dv_refcount; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3293 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3294 copy_tv(tv, visited_tv); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3295 scheme_hash_set(visited, obj, (Scheme_Object *)visited_tv); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3296 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3297 for (i = 0; i < ((Scheme_Hash_Table *)obj)->size; ++i) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3298 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3299 if (((Scheme_Hash_Table *) obj)->vals[i] != NULL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3300 { |
4352 | 3301 /* generate item for `display'ed Scheme key */ |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3302 dictitem_T *item = dictitem_alloc((char_u *)string_to_line( |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3303 ((Scheme_Hash_Table *) obj)->keys[i])); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3304 /* convert Scheme val to Vim and add it to the dict */ |
4074 | 3305 if (mzscheme_to_vim_impl(((Scheme_Hash_Table *) obj)->vals[i], |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3306 &item->di_tv, depth + 1, visited) == FAIL |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3307 || dict_add(dict, item) == FAIL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3308 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3309 dictitem_free(item); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3310 status = FAIL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3311 break; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3312 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3313 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3314 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3315 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3316 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3317 MZ_GC_UNREG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3318 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3319 else |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3320 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3321 /* `display' any other value to string */ |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3322 tv->v_type = VAR_STRING; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3323 tv->vval.v_string = (char_u *)string_to_line(obj); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3324 } |
4074 | 3325 MZ_GC_UNREG(); |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3326 return status; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3327 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3328 |
4074 | 3329 /* Scheme prim procedure wrapping Vim funcref */ |
3330 static Scheme_Object * | |
3331 vim_funcref(void *name, int argc, Scheme_Object **argv) | |
3332 { | |
3333 int i; | |
3334 typval_T args; | |
3335 int status = OK; | |
3336 Scheme_Object *result = NULL; | |
3337 list_T *list = list_alloc(); | |
3338 | |
3339 MZ_GC_DECL_REG(1); | |
3340 MZ_GC_VAR_IN_REG(0, result); | |
3341 MZ_GC_REG(); | |
3342 | |
3343 result = scheme_void; | |
3344 if (list == NULL) | |
3345 status = FAIL; | |
3346 else | |
3347 { | |
3348 args.v_type = VAR_LIST; | |
3349 args.vval.v_list = list; | |
3350 ++list->lv_refcount; | |
3351 for (i = 0; status == OK && i < argc; ++i) | |
3352 { | |
3353 typval_T *v = (typval_T *)alloc(sizeof(typval_T)); | |
3354 if (v == NULL) | |
3355 status = FAIL; | |
3356 else | |
3357 { | |
3358 status = mzscheme_to_vim(argv[i], v); | |
3359 if (status == OK) | |
3360 { | |
3361 status = list_append_tv(list, v); | |
3362 clear_tv(v); | |
3363 } | |
3364 vim_free(v); | |
3365 } | |
3366 } | |
3367 if (status == OK) | |
3368 { | |
3369 typval_T ret; | |
3370 ret.v_type = VAR_UNKNOWN; | |
3371 | |
3372 mzscheme_call_vim(BYTE_STRING_VALUE((Scheme_Object *)name), &args, &ret); | |
3373 MZ_GC_CHECK(); | |
3374 result = vim_to_mzscheme(&ret); | |
3375 clear_tv(&ret); | |
3376 MZ_GC_CHECK(); | |
3377 } | |
3378 } | |
3379 clear_tv(&args); | |
3380 MZ_GC_UNREG(); | |
3381 if (status != OK) | |
3382 raise_vim_exn(_("error converting Scheme values to Vim")); | |
3383 else | |
3384 raise_if_error(); | |
3385 return result; | |
3386 } | |
3387 | |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3388 void |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3389 do_mzeval(char_u *str, typval_T *rettv) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3390 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3391 Scheme_Object *ret = NULL; |
4074 | 3392 |
3393 MZ_GC_DECL_REG(1); | |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3394 MZ_GC_VAR_IN_REG(0, ret); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3395 MZ_GC_REG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3396 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3397 if (mzscheme_init()) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3398 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3399 MZ_GC_UNREG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3400 return; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3401 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3402 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3403 MZ_GC_CHECK(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3404 if (eval_with_exn_handling(str, do_eval, &ret) == OK) |
4074 | 3405 mzscheme_to_vim(ret, rettv); |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3406 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3407 MZ_GC_UNREG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3408 } |
1894 | 3409 #endif |
14 | 3410 |
3411 /* | |
3412 * Check to see whether a Vim error has been reported, or a keyboard | |
3413 * interrupt (from vim --> got_int) has been detected. | |
3414 */ | |
3415 static int | |
3416 vim_error_check(void) | |
3417 { | |
3418 return (got_int || did_emsg); | |
3419 } | |
3420 | |
3421 /* | |
3422 * register Scheme exn:vim | |
3423 */ | |
3424 static void | |
1894 | 3425 register_vim_exn(void) |
14 | 3426 { |
1894 | 3427 int nc = 0; |
3428 int i; | |
3429 Scheme_Object *struct_exn = NULL; | |
3430 Scheme_Object *exn_name = NULL; | |
3431 | |
3432 MZ_GC_DECL_REG(2); | |
3433 MZ_GC_VAR_IN_REG(0, struct_exn); | |
3434 MZ_GC_VAR_IN_REG(1, exn_name); | |
3435 MZ_GC_REG(); | |
3436 | |
3437 exn_name = scheme_intern_symbol("exn:vim"); | |
3438 MZ_GC_CHECK(); | |
3439 struct_exn = scheme_builtin_value("struct:exn"); | |
3440 MZ_GC_CHECK(); | |
14 | 3441 |
3442 if (vim_exn == NULL) | |
3443 vim_exn = scheme_make_struct_type(exn_name, | |
1894 | 3444 struct_exn, NULL, 0, 0, NULL, NULL |
14 | 3445 #if MZSCHEME_VERSION_MAJOR >= 299 |
3446 , NULL | |
3447 #endif | |
3448 ); | |
3449 | |
1894 | 3450 |
14 | 3451 { |
1894 | 3452 Scheme_Object **tmp = NULL; |
3453 Scheme_Object *exn_names[5] = {NULL, NULL, NULL, NULL, NULL}; | |
3454 Scheme_Object *exn_values[5] = {NULL, NULL, NULL, NULL, NULL}; | |
3455 MZ_GC_DECL_REG(6); | |
3456 MZ_GC_ARRAY_VAR_IN_REG(0, exn_names, 5); | |
3457 MZ_GC_ARRAY_VAR_IN_REG(3, exn_values, 5); | |
3458 MZ_GC_REG(); | |
3459 | |
3460 tmp = scheme_make_struct_names(exn_name, scheme_null, 0, &nc); | |
3461 mch_memmove(exn_names, tmp, nc * sizeof(Scheme_Object *)); | |
3462 MZ_GC_CHECK(); | |
3463 | |
3464 tmp = scheme_make_struct_values(vim_exn, exn_names, nc, 0); | |
3465 mch_memmove(exn_values, tmp, nc * sizeof(Scheme_Object *)); | |
3466 MZ_GC_CHECK(); | |
3467 | |
3468 for (i = 0; i < nc; i++) | |
3469 { | |
3470 scheme_add_global_symbol(exn_names[i], | |
3471 exn_values[i], environment); | |
3472 MZ_GC_CHECK(); | |
3473 } | |
3474 MZ_GC_UNREG(); | |
14 | 3475 } |
1894 | 3476 MZ_GC_UNREG(); |
14 | 3477 } |
3478 | |
3479 /* | |
3480 * raise exn:vim, may be with additional info string | |
3481 */ | |
3482 void | |
3483 raise_vim_exn(const char *add_info) | |
3484 { | |
1894 | 3485 char *fmt = _("Vim error: ~a"); |
3486 Scheme_Object *argv[2] = {NULL, NULL}; | |
3487 Scheme_Object *exn = NULL; | |
4074 | 3488 Scheme_Object *byte_string = NULL; |
3489 | |
3490 MZ_GC_DECL_REG(5); | |
1894 | 3491 MZ_GC_ARRAY_VAR_IN_REG(0, argv, 2); |
3492 MZ_GC_VAR_IN_REG(3, exn); | |
4074 | 3493 MZ_GC_VAR_IN_REG(4, byte_string); |
1894 | 3494 MZ_GC_REG(); |
14 | 3495 |
3496 if (add_info != NULL) | |
3497 { | |
1894 | 3498 char *c_string = NULL; |
3499 Scheme_Object *info = NULL; | |
3500 | |
3501 MZ_GC_DECL_REG(3); | |
3502 MZ_GC_VAR_IN_REG(0, c_string); | |
3503 MZ_GC_VAR_IN_REG(2, info); | |
3504 MZ_GC_REG(); | |
3505 | |
4074 | 3506 info = scheme_make_byte_string(add_info); |
1894 | 3507 MZ_GC_CHECK(); |
4074 | 3508 c_string = scheme_format_utf8(fmt, STRLEN(fmt), 1, &info, NULL); |
1894 | 3509 MZ_GC_CHECK(); |
4074 | 3510 byte_string = scheme_make_byte_string(c_string); |
1894 | 3511 MZ_GC_CHECK(); |
3512 argv[0] = scheme_byte_string_to_char_string(byte_string); | |
274 | 3513 SCHEME_SET_IMMUTABLE(argv[0]); |
1894 | 3514 MZ_GC_UNREG(); |
14 | 3515 } |
3516 else | |
4074 | 3517 { |
3518 byte_string = scheme_make_byte_string(_("Vim error")); | |
3519 MZ_GC_CHECK(); | |
3520 argv[0] = scheme_byte_string_to_char_string(byte_string); | |
3521 MZ_GC_CHECK(); | |
3522 } | |
1894 | 3523 MZ_GC_CHECK(); |
14 | 3524 |
1284 | 3525 #if MZSCHEME_VERSION_MAJOR < 360 |
3526 argv[1] = scheme_current_continuation_marks(); | |
1894 | 3527 MZ_GC_CHECK(); |
1284 | 3528 #else |
1125 | 3529 argv[1] = scheme_current_continuation_marks(NULL); |
1894 | 3530 MZ_GC_CHECK(); |
1284 | 3531 #endif |
14 | 3532 |
1894 | 3533 exn = scheme_make_struct_instance(vim_exn, 2, argv); |
3534 MZ_GC_CHECK(); | |
3535 scheme_raise(exn); | |
3536 MZ_GC_UNREG(); | |
14 | 3537 } |
3538 | |
3539 void | |
3540 raise_if_error(void) | |
3541 { | |
3542 if (vim_error_check()) | |
3543 raise_vim_exn(NULL); | |
3544 } | |
3545 | |
3546 /* get buffer: | |
3547 * either current | |
3548 * or passed as argv[argnum] with checks | |
3549 */ | |
3550 static vim_mz_buffer * | |
3551 get_buffer_arg(const char *fname, int argnum, int argc, Scheme_Object **argv) | |
3552 { | |
3553 vim_mz_buffer *b; | |
3554 | |
3555 if (argc < argnum + 1) | |
3556 return get_vim_curr_buffer(); | |
3557 if (!SCHEME_VIMBUFFERP(argv[argnum])) | |
3558 scheme_wrong_type(fname, "vim-buffer", argnum, argc, argv); | |
3559 b = (vim_mz_buffer *)argv[argnum]; | |
3560 (void)get_valid_buffer(argv[argnum]); | |
3561 return b; | |
3562 } | |
3563 | |
3564 /* get window: | |
3565 * either current | |
3566 * or passed as argv[argnum] with checks | |
3567 */ | |
3568 static vim_mz_window * | |
3569 get_window_arg(const char *fname, int argnum, int argc, Scheme_Object **argv) | |
3570 { | |
3571 vim_mz_window *w; | |
3572 | |
3573 if (argc < argnum + 1) | |
3574 return get_vim_curr_window(); | |
3575 w = (vim_mz_window *)argv[argnum]; | |
3576 if (!SCHEME_VIMWINDOWP(argv[argnum])) | |
3577 scheme_wrong_type(fname, "vim-window", argnum, argc, argv); | |
3578 (void)get_valid_window(argv[argnum]); | |
3579 return w; | |
3580 } | |
3581 | |
3582 /* get valid Vim buffer from Scheme_Object* */ | |
3583 buf_T *get_valid_buffer(void *obj) | |
3584 { | |
3585 buf_T *buf = ((vim_mz_buffer *)obj)->buf; | |
3586 | |
3587 if (buf == INVALID_BUFFER_VALUE) | |
3588 scheme_signal_error(_("buffer is invalid")); | |
3589 return buf; | |
3590 } | |
3591 | |
3592 /* get valid Vim window from Scheme_Object* */ | |
3593 win_T *get_valid_window(void *obj) | |
3594 { | |
3595 win_T *win = ((vim_mz_window *)obj)->win; | |
3596 if (win == INVALID_WINDOW_VALUE) | |
3597 scheme_signal_error(_("window is invalid")); | |
3598 return win; | |
3599 } | |
3600 | |
3601 int | |
3602 mzthreads_allowed(void) | |
3603 { | |
3604 return mz_threads_allow; | |
3605 } | |
3606 | |
3607 static int | |
3608 line_in_range(linenr_T lnum, buf_T *buf) | |
3609 { | |
3610 return (lnum > 0 && lnum <= buf->b_ml.ml_line_count); | |
3611 } | |
3612 | |
3613 static void | |
3614 check_line_range(linenr_T lnum, buf_T *buf) | |
3615 { | |
3616 if (!line_in_range(lnum, buf)) | |
3617 scheme_signal_error(_("linenr out of range")); | |
3618 } | |
3619 | |
3620 /* | |
3621 * Check if deleting lines made the cursor position invalid | |
3622 * (or you'll get msg from Vim about invalid linenr). | |
3623 * Changed the lines from "lo" to "hi" and added "extra" lines (negative if | |
3624 * deleted). Got from if_python.c | |
3625 */ | |
3626 static void | |
3627 mz_fix_cursor(int lo, int hi, int extra) | |
3628 { | |
3629 if (curwin->w_cursor.lnum >= lo) | |
3630 { | |
3631 /* Adjust the cursor position if it's in/after the changed | |
3632 * lines. */ | |
3633 if (curwin->w_cursor.lnum >= hi) | |
3634 { | |
3635 curwin->w_cursor.lnum += extra; | |
3636 check_cursor_col(); | |
3637 } | |
3638 else if (extra < 0) | |
3639 { | |
3640 curwin->w_cursor.lnum = lo; | |
3641 check_cursor(); | |
3642 } | |
1894 | 3643 else |
3644 check_cursor_col(); | |
14 | 3645 changed_cline_bef_curs(); |
3646 } | |
3647 invalidate_botline(); | |
3648 } | |
3649 | |
3650 static Vim_Prim prims[]= | |
3651 { | |
3652 /* | |
3653 * Buffer-related commands | |
3654 */ | |
3655 {get_buffer_line, "get-buff-line", 1, 2}, | |
3656 {set_buffer_line, "set-buff-line", 2, 3}, | |
3657 {get_buffer_line_list, "get-buff-line-list", 2, 3}, | |
3658 {get_buffer_name, "get-buff-name", 0, 1}, | |
3659 {get_buffer_num, "get-buff-num", 0, 1}, | |
3660 {get_buffer_size, "get-buff-size", 0, 1}, | |
3661 {set_buffer_line_list, "set-buff-line-list", 3, 4}, | |
3662 {insert_buffer_line_list, "insert-buff-line-list", 2, 3}, | |
3663 {get_curr_buffer, "curr-buff", 0, 0}, | |
3664 {get_buffer_count, "buff-count", 0, 0}, | |
3665 {get_next_buffer, "get-next-buff", 0, 1}, | |
3666 {get_prev_buffer, "get-prev-buff", 0, 1}, | |
3667 {mzscheme_open_buffer, "open-buff", 1, 1}, | |
3668 {get_buffer_by_name, "get-buff-by-name", 1, 1}, | |
3669 {get_buffer_by_num, "get-buff-by-num", 1, 1}, | |
3670 /* | |
3671 * Window-related commands | |
3672 */ | |
3673 {get_curr_win, "curr-win", 0, 0}, | |
3674 {get_window_count, "win-count", 0, 0}, | |
3675 {get_window_by_num, "get-win-by-num", 1, 1}, | |
3676 {get_window_num, "get-win-num", 0, 1}, | |
3677 {get_window_buffer, "get-win-buffer", 0, 1}, | |
3678 {get_window_height, "get-win-height", 0, 1}, | |
3679 {set_window_height, "set-win-height", 1, 2}, | |
3680 #ifdef FEAT_VERTSPLIT | |
3681 {get_window_width, "get-win-width", 0, 1}, | |
3682 {set_window_width, "set-win-width", 1, 2}, | |
3683 #endif | |
3684 {get_cursor, "get-cursor", 0, 1}, | |
3685 {set_cursor, "set-cursor", 1, 2}, | |
3686 {get_window_list, "get-win-list", 0, 1}, | |
3687 /* | |
3688 * Vim-related commands | |
3689 */ | |
3690 {vim_command, "command", 1, 1}, | |
3691 {vim_eval, "eval", 1, 1}, | |
3692 {get_range_start, "range-start", 0, 0}, | |
3693 {get_range_end, "range-end", 0, 0}, | |
3694 {mzscheme_beep, "beep", 0, 0}, | |
3695 {get_option, "get-option", 1, 2}, | |
3696 {set_option, "set-option", 1, 2}, | |
3697 /* | |
3698 * small utilities | |
3699 */ | |
3700 {vim_bufferp, "buff?", 1, 1}, | |
3701 {vim_windowp, "win?", 1, 1}, | |
3702 {vim_buffer_validp, "buff-valid?", 1, 1}, | |
3703 {vim_window_validp, "win-valid?", 1, 1} | |
3704 }; | |
3705 | |
3706 /* return MzScheme wrapper for curbuf */ | |
3707 static vim_mz_buffer * | |
3708 get_vim_curr_buffer(void) | |
3709 { | |
502 | 3710 if (curbuf->b_mzscheme_ref == NULL) |
14 | 3711 return (vim_mz_buffer *)buffer_new(curbuf); |
3712 else | |
4074 | 3713 return BUFFER_REF(curbuf); |
14 | 3714 } |
3715 | |
3716 /* return MzScheme wrapper for curwin */ | |
3717 static vim_mz_window * | |
3718 get_vim_curr_window(void) | |
3719 { | |
502 | 3720 if (curwin->w_mzscheme_ref == NULL) |
14 | 3721 return (vim_mz_window *)window_new(curwin); |
3722 else | |
4074 | 3723 return WINDOW_REF(curwin); |
14 | 3724 } |
3725 | |
3726 static void | |
1894 | 3727 make_modules() |
14 | 3728 { |
1894 | 3729 int i; |
3730 Scheme_Env *mod = NULL; | |
3731 Scheme_Object *vimext_symbol = NULL; | |
3732 Scheme_Object *closed_prim = NULL; | |
3733 | |
3734 MZ_GC_DECL_REG(3); | |
3735 MZ_GC_VAR_IN_REG(0, mod); | |
3736 MZ_GC_VAR_IN_REG(1, vimext_symbol); | |
3737 MZ_GC_VAR_IN_REG(2, closed_prim); | |
3738 MZ_GC_REG(); | |
3739 | |
3740 vimext_symbol = scheme_intern_symbol("vimext"); | |
3741 MZ_GC_CHECK(); | |
3742 mod = scheme_primitive_module(vimext_symbol, environment); | |
3743 MZ_GC_CHECK(); | |
14 | 3744 /* all prims made closed so they can access their own names */ |
1894 | 3745 for (i = 0; i < (int)(sizeof(prims)/sizeof(prims[0])); i++) |
14 | 3746 { |
3747 Vim_Prim *prim = prims + i; | |
1894 | 3748 closed_prim = scheme_make_closed_prim_w_arity(prim->prim, prim, prim->name, |
3749 prim->mina, prim->maxa); | |
3750 scheme_add_global(prim->name, closed_prim, mod); | |
3751 MZ_GC_CHECK(); | |
14 | 3752 } |
3753 scheme_finish_primitive_module(mod); | |
1894 | 3754 MZ_GC_CHECK(); |
3755 MZ_GC_UNREG(); | |
14 | 3756 } |
344 | 3757 |
274 | 3758 #ifdef HAVE_SANDBOX |
3759 static Scheme_Object *M_write = NULL; | |
3760 static Scheme_Object *M_read = NULL; | |
3761 static Scheme_Object *M_execute = NULL; | |
3762 static Scheme_Object *M_delete = NULL; | |
3763 | |
3764 static void | |
1125 | 3765 sandbox_check(void) |
274 | 3766 { |
3767 if (sandbox) | |
3768 raise_vim_exn(_("not allowed in the Vim sandbox")); | |
3769 } | |
3770 | |
344 | 3771 /* security guards to force Vim's sandbox restrictions on MzScheme level */ |
274 | 3772 static Scheme_Object * |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
3773 sandbox_file_guard(int argc UNUSED, Scheme_Object **argv) |
274 | 3774 { |
3775 if (sandbox) | |
3776 { | |
3777 Scheme_Object *requested_access = argv[2]; | |
3778 | |
3779 if (M_write == NULL) | |
3780 { | |
3781 MZ_REGISTER_STATIC(M_write); | |
3782 M_write = scheme_intern_symbol("write"); | |
1894 | 3783 MZ_GC_CHECK(); |
274 | 3784 } |
3785 if (M_read == NULL) | |
3786 { | |
3787 MZ_REGISTER_STATIC(M_read); | |
3788 M_read = scheme_intern_symbol("read"); | |
1894 | 3789 MZ_GC_CHECK(); |
274 | 3790 } |
3791 if (M_execute == NULL) | |
3792 { | |
3793 MZ_REGISTER_STATIC(M_execute); | |
3794 M_execute = scheme_intern_symbol("execute"); | |
1894 | 3795 MZ_GC_CHECK(); |
274 | 3796 } |
3797 if (M_delete == NULL) | |
3798 { | |
3799 MZ_REGISTER_STATIC(M_delete); | |
3800 M_delete = scheme_intern_symbol("delete"); | |
1894 | 3801 MZ_GC_CHECK(); |
274 | 3802 } |
3803 | |
3804 while (!SCHEME_NULLP(requested_access)) | |
3805 { | |
3806 Scheme_Object *item = SCHEME_CAR(requested_access); | |
3807 if (scheme_eq(item, M_write) || scheme_eq(item, M_read) | |
3808 || scheme_eq(item, M_execute) || scheme_eq(item, M_delete)) | |
3809 { | |
3810 raise_vim_exn(_("not allowed in the Vim sandbox")); | |
3811 } | |
3812 requested_access = SCHEME_CDR(requested_access); | |
3813 } | |
3814 } | |
3815 return scheme_void; | |
3816 } | |
3817 | |
3818 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
3819 sandbox_network_guard(int argc UNUSED, Scheme_Object **argv UNUSED) |
274 | 3820 { |
3821 return scheme_void; | |
3822 } | |
3823 #endif | |
800 | 3824 |
3825 #endif |