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