Mercurial > vim
annotate src/if_mzsch.c @ 9561:8b20e3f947c7
Added tag v7.4.2057 for changeset 1e68dfd7931b08c0c9e2311e35a3999243966d1c
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 17 Jul 2016 16:00:05 +0200 |
parents | 29de7dda7a6a |
children | fd9727ae3c49 |
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 **); | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8218
diff
changeset
|
148 #ifdef FEAT_WINDOWS |
14 | 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) |
9159
6b003ff07234
commit https://github.com/vim/vim/commit/9b0ac229bcfc91acabd35fc576055a94c1687c32
Christian Brabandt <cb@256bit.org>
parents:
8800
diff
changeset
|
548 /* define as function for macro in schthread.h */ |
7609
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) | |
9173
b64c314a4990
commit https://github.com/vim/vim/commit/dec6c7beda5491b28f67f430fc9d01467050c1ca
Christian Brabandt <cb@256bit.org>
parents:
9159
diff
changeset
|
852 static void CALLBACK timer_proc(HWND, UINT, UINT_PTR, DWORD); |
14 | 853 static UINT timer_id = 0; |
854 #elif defined(FEAT_GUI_GTK) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8110
diff
changeset
|
855 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8110
diff
changeset
|
856 static gboolean timer_proc(gpointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8110
diff
changeset
|
857 # else |
14 | 858 static gint timer_proc(gpointer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8110
diff
changeset
|
859 # endif |
14 | 860 static guint timer_id = 0; |
861 #elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA) | |
862 static void timer_proc(XtPointer, XtIntervalId *); | |
863 static XtIntervalId timer_id = (XtIntervalId)0; | |
864 #elif defined(FEAT_GUI_MAC) | |
865 pascal void timer_proc(EventLoopTimerRef, void *); | |
866 static EventLoopTimerRef timer_id = NULL; | |
867 static EventLoopTimerUPP timerUPP; | |
868 #endif | |
869 | |
870 #ifndef FEAT_GUI_W32 /* Win32 console and Unix */ | |
871 void | |
872 mzvim_check_threads(void) | |
873 { | |
874 /* Last time MzScheme threads were scheduled */ | |
875 static time_t mz_last_time = 0; | |
876 | |
877 if (mz_threads_allow && p_mzq > 0) | |
878 { | |
879 time_t now = time(NULL); | |
880 | |
881 if ((now - mz_last_time) * 1000 > p_mzq) | |
882 { | |
883 mz_last_time = now; | |
884 scheme_check_threads(); | |
885 } | |
886 } | |
887 } | |
888 #endif | |
889 | |
7813
744c66477ba9
commit https://github.com/vim/vim/commit/4349c57543a98dc417b74da5a08c326337aa0bd3
Christian Brabandt <cb@256bit.org>
parents:
7728
diff
changeset
|
890 #if defined(MZSCHEME_GUI_THREADS) || defined(PROTO) |
16 | 891 static void setup_timer(void); |
892 static void remove_timer(void); | |
893 | |
14 | 894 /* timers are presented in GUI only */ |
895 # if defined(FEAT_GUI_W32) | |
896 static void CALLBACK | |
9159
6b003ff07234
commit https://github.com/vim/vim/commit/9b0ac229bcfc91acabd35fc576055a94c1687c32
Christian Brabandt <cb@256bit.org>
parents:
8800
diff
changeset
|
897 timer_proc(HWND hwnd UNUSED, UINT uMsg UNUSED, UINT_PTR idEvent UNUSED, DWORD dwTime UNUSED) |
14 | 898 # elif defined(FEAT_GUI_GTK) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8110
diff
changeset
|
899 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8110
diff
changeset
|
900 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8110
diff
changeset
|
901 # else |
14 | 902 static gint |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8110
diff
changeset
|
903 # endif |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
904 timer_proc(gpointer data UNUSED) |
14 | 905 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA) |
906 static void | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
907 timer_proc(XtPointer timed_out UNUSED, XtIntervalId *interval_id UNUSED) |
14 | 908 # elif defined(FEAT_GUI_MAC) |
909 pascal void | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
910 timer_proc(EventLoopTimerRef theTimer UNUSED, void *userData UNUSED) |
14 | 911 # endif |
912 { | |
913 scheme_check_threads(); | |
914 # if defined(FEAT_GUI_GTK) | |
915 return TRUE; /* continue receiving notifications */ | |
916 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA) | |
917 /* renew timeout */ | |
918 if (mz_threads_allow && p_mzq > 0) | |
919 timer_id = XtAppAddTimeOut(app_context, p_mzq, | |
920 timer_proc, NULL); | |
921 # endif | |
922 } | |
923 | |
924 static void | |
925 setup_timer(void) | |
926 { | |
927 # if defined(FEAT_GUI_W32) | |
928 timer_id = SetTimer(NULL, 0, p_mzq, timer_proc); | |
929 # elif defined(FEAT_GUI_GTK) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8110
diff
changeset
|
930 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8110
diff
changeset
|
931 timer_id = g_timeout_add((guint)p_mzq, (GSourceFunc)timer_proc, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8110
diff
changeset
|
932 # else |
14 | 933 timer_id = gtk_timeout_add((guint32)p_mzq, (GtkFunction)timer_proc, NULL); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8110
diff
changeset
|
934 # endif |
14 | 935 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA) |
936 timer_id = XtAppAddTimeOut(app_context, p_mzq, timer_proc, NULL); | |
937 # elif defined(FEAT_GUI_MAC) | |
938 timerUPP = NewEventLoopTimerUPP(timer_proc); | |
939 InstallEventLoopTimer(GetMainEventLoop(), p_mzq * kEventDurationMillisecond, | |
940 p_mzq * kEventDurationMillisecond, timerUPP, NULL, &timer_id); | |
941 # endif | |
942 } | |
943 | |
944 static void | |
945 remove_timer(void) | |
946 { | |
947 # if defined(FEAT_GUI_W32) | |
948 KillTimer(NULL, timer_id); | |
949 # elif defined(FEAT_GUI_GTK) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8110
diff
changeset
|
950 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8110
diff
changeset
|
951 g_source_remove(timer_id); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8110
diff
changeset
|
952 # else |
14 | 953 gtk_timeout_remove(timer_id); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
8110
diff
changeset
|
954 # endif |
14 | 955 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA) |
956 XtRemoveTimeOut(timer_id); | |
957 # elif defined(FEAT_GUI_MAC) | |
958 RemoveEventLoopTimer(timer_id); | |
959 DisposeEventLoopTimerUPP(timerUPP); | |
960 # endif | |
961 timer_id = 0; | |
962 } | |
963 | |
964 void | |
965 mzvim_reset_timer(void) | |
966 { | |
967 if (timer_id != 0) | |
968 remove_timer(); | |
969 if (mz_threads_allow && p_mzq > 0 && gui.in_use) | |
970 setup_timer(); | |
971 } | |
972 | |
16 | 973 #endif /* MZSCHEME_GUI_THREADS */ |
14 | 974 |
975 static void | |
976 notify_multithread(int on) | |
977 { | |
978 mz_threads_allow = on; | |
16 | 979 #ifdef MZSCHEME_GUI_THREADS |
14 | 980 if (on && timer_id == 0 && p_mzq > 0 && gui.in_use) |
981 setup_timer(); | |
982 if (!on && timer_id != 0) | |
983 remove_timer(); | |
984 #endif | |
985 } | |
986 | |
987 void | |
988 mzscheme_end(void) | |
989 { | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
990 /* 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
|
991 #if 0 |
137 | 992 #ifdef DYNAMIC_MZSCHEME |
993 dynamic_mzscheme_end(); | |
994 #endif | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
995 #endif |
14 | 996 } |
997 | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
998 #if HAVE_TLS_SPACE |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
999 # if defined(_MSC_VER) |
2628 | 1000 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
|
1001 extern intptr_t _tls_index; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1002 # elif defined(__MINGW32__) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1003 static __thread void *tls_space; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1004 extern intptr_t _tls_index; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1005 # else |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1006 static THREAD_LOCAL void *tls_space; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1007 static intptr_t _tls_index = 0; |
3348 | 1008 # endif |
1009 #endif | |
1010 | |
1011 int | |
1012 mzscheme_main(int argc, char** argv) | |
1894 | 1013 { |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1014 #ifdef DYNAMIC_MZSCHEME |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1015 /* |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1016 * 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
|
1017 * 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
|
1018 */ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1019 if (!mzscheme_enabled(FALSE)) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1020 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1021 disabled = TRUE; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1022 return vim_main2(argc, argv); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1023 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1024 #endif |
6905 | 1025 #ifdef HAVE_TLS_SPACE |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1026 scheme_register_tls_space(&tls_space, _tls_index); |
2628 | 1027 #endif |
3348 | 1028 #ifdef TRAMPOLINED_MZVIM_STARTUP |
1029 return scheme_main_setup(TRUE, mzscheme_env_main, argc, argv); | |
1894 | 1030 #else |
3348 | 1031 return mzscheme_env_main(NULL, argc, argv); |
1894 | 1032 #endif |
1033 } | |
1034 | |
1035 static int | |
3348 | 1036 mzscheme_env_main(Scheme_Env *env, int argc, char **argv) |
1894 | 1037 { |
3348 | 1038 int vim_main_result; |
1039 #ifdef TRAMPOLINED_MZVIM_STARTUP | |
1040 /* Scheme has created the environment for us */ | |
1041 environment = env; | |
1042 #else | |
1043 # ifdef MZ_PRECISE_GC | |
1894 | 1044 Scheme_Object *dummy = NULL; |
1045 MZ_GC_DECL_REG(1); | |
1046 MZ_GC_VAR_IN_REG(0, dummy); | |
1047 | |
1048 stack_base = &__gc_var_stack__; | |
1049 # else | |
1050 int dummy = 0; | |
1051 stack_base = (void *)&dummy; | |
3348 | 1052 # endif |
1894 | 1053 #endif |
3348 | 1054 |
1055 /* mzscheme_main is called as a trampoline from main. | |
1056 * We trampoline into vim_main2 | |
1057 * Passing argc, argv through from mzscheme_main | |
1058 */ | |
1059 vim_main_result = vim_main2(argc, argv); | |
1060 #if !defined(TRAMPOLINED_MZVIM_STARTUP) && defined(MZ_PRECISE_GC) | |
1894 | 1061 /* releasing dummy */ |
1062 MZ_GC_REG(); | |
1063 MZ_GC_UNREG(); | |
1064 #endif | |
3348 | 1065 return vim_main_result; |
1894 | 1066 } |
1067 | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1068 static Scheme_Object* |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1069 load_base_module(void *data) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1070 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1071 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
|
1072 return scheme_null; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1073 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1074 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1075 static Scheme_Object * |
8779
26495bd795d2
commit https://github.com/vim/vim/commit/8b29aba0192cc56294ef49bb3c01adff4b8f3a28
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1076 load_base_module_on_error(void *data UNUSED) |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1077 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1078 load_base_module_failed = TRUE; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1079 return scheme_null; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1080 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1081 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1082 static int |
14 | 1083 startup_mzscheme(void) |
1084 { | |
3348 | 1085 #ifndef TRAMPOLINED_MZVIM_STARTUP |
1894 | 1086 scheme_set_stack_base(stack_base, 1); |
1087 #endif | |
14 | 1088 |
4074 | 1089 #ifndef TRAMPOLINED_MZVIM_STARTUP |
1090 /* in newer versions of precise GC the initial env has been created */ | |
1091 environment = scheme_basic_env(); | |
1092 #endif | |
1093 | |
14 | 1094 MZ_REGISTER_STATIC(environment); |
1095 MZ_REGISTER_STATIC(curout); | |
1096 MZ_REGISTER_STATIC(curerr); | |
1097 MZ_REGISTER_STATIC(exn_catching_apply); | |
1098 MZ_REGISTER_STATIC(exn_p); | |
1099 MZ_REGISTER_STATIC(exn_message); | |
1100 MZ_REGISTER_STATIC(vim_exn); | |
1894 | 1101 |
1102 MZ_GC_CHECK(); | |
1103 | |
1104 #ifdef INCLUDE_MZSCHEME_BASE | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1105 /* 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
|
1106 declare_modules(environment); |
1894 | 1107 #endif |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1108 |
14 | 1109 /* setup 'current-library-collection-paths' parameter */ |
1307 | 1110 # if MZSCHEME_VERSION_MAJOR >= 299 |
1894 | 1111 { |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1112 Scheme_Object *coll_path = NULL; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1113 int mustfree = FALSE; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1114 char_u *s; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1115 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1116 MZ_GC_DECL_REG(1); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1117 MZ_GC_VAR_IN_REG(0, coll_path); |
1894 | 1118 MZ_GC_REG(); |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1119 /* workaround for dynamic loading on windows */ |
8110
d1974721ddc5
commit https://github.com/vim/vim/commit/74a97b1ea0fe2c729e26718d0eec4164c8bed151
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
1120 s = vim_getenv((char_u *)"PLTCOLLECTS", &mustfree); |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1121 if (s != NULL) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1122 { |
8110
d1974721ddc5
commit https://github.com/vim/vim/commit/74a97b1ea0fe2c729e26718d0eec4164c8bed151
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
1123 coll_path = scheme_make_path((char *)s); |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1124 MZ_GC_CHECK(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1125 if (mustfree) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1126 vim_free(s); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1127 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1128 # ifdef MZSCHEME_COLLECTS |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1129 if (coll_path == NULL) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1130 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1131 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
|
1132 MZ_GC_CHECK(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1133 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1134 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1135 if (coll_path != NULL) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1136 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1137 scheme_set_collects_path(coll_path); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1138 MZ_GC_CHECK(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1139 } |
1894 | 1140 MZ_GC_UNREG(); |
1141 } | |
1307 | 1142 # else |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1143 # ifdef MZSCHEME_COLLECTS |
1894 | 1144 { |
1145 Scheme_Object *coll_string = NULL; | |
1146 Scheme_Object *coll_pair = NULL; | |
1147 Scheme_Config *config = NULL; | |
1148 | |
1149 MZ_GC_DECL_REG(3); | |
1150 MZ_GC_VAR_IN_REG(0, coll_string); | |
1151 MZ_GC_VAR_IN_REG(1, coll_pair); | |
1152 MZ_GC_VAR_IN_REG(2, config); | |
1153 MZ_GC_REG(); | |
4074 | 1154 coll_string = scheme_make_byte_string(MZSCHEME_COLLECTS); |
1894 | 1155 MZ_GC_CHECK(); |
1156 coll_pair = scheme_make_pair(coll_string, scheme_null); | |
1157 MZ_GC_CHECK(); | |
4074 | 1158 config = scheme_current_config(); |
1894 | 1159 MZ_GC_CHECK(); |
1160 scheme_set_param(config, MZCONFIG_COLLECTION_PATHS, coll_pair); | |
1161 MZ_GC_CHECK(); | |
1162 MZ_GC_UNREG(); | |
1163 } | |
1307 | 1164 # endif |
14 | 1165 #endif |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1166 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1167 # if MZSCHEME_VERSION_MAJOR >= 600 |
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 Scheme_Object *config_path = NULL; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1170 int mustfree = FALSE; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1171 char_u *s; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1172 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1173 MZ_GC_DECL_REG(1); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1174 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
|
1175 MZ_GC_REG(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1176 /* workaround for dynamic loading on windows */ |
9289
29de7dda7a6a
commit https://github.com/vim/vim/commit/5b7d177e8994c003ae77ddab5bd54f8cd1ee181b
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
1177 s = vim_getenv((char_u *)"PLTCONFIGDIR", &mustfree); |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1178 if (s != NULL) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1179 { |
9289
29de7dda7a6a
commit https://github.com/vim/vim/commit/5b7d177e8994c003ae77ddab5bd54f8cd1ee181b
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
1180 config_path = scheme_make_path((char *)s); |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1181 MZ_GC_CHECK(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1182 if (mustfree) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1183 vim_free(s); |
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 #ifdef MZSCHEME_CONFIGDIR |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1186 if (config_path == NULL) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1187 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1188 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
|
1189 MZ_GC_CHECK(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1190 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1191 #endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1192 if (config_path != NULL) |
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 scheme_set_config_path(config_path); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1195 MZ_GC_CHECK(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1196 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1197 MZ_GC_UNREG(); |
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 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1200 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1201 #if MZSCHEME_VERSION_MAJOR >= 400 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1202 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
|
1203 #endif |
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 * 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
|
1207 * we need to add them explicitly |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1208 */ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1209 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1210 /* use error handler to avoid abort */ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1211 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
|
1212 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
|
1213 if (load_base_module_failed) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1214 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1215 load_base_module_failed = FALSE; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1216 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
|
1217 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
|
1218 if (load_base_module_failed) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1219 return -1; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1220 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1221 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1222 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1223 register_vim_exn(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1224 /* 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
|
1225 init_exn_catching_apply(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1226 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1227 /* redirect output */ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1228 scheme_console_output = do_output; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1229 scheme_console_printf = do_printf; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1230 |
274 | 1231 #ifdef HAVE_SANDBOX |
1232 { | |
1894 | 1233 Scheme_Object *make_security_guard = NULL; |
1234 MZ_GC_DECL_REG(1); | |
1235 MZ_GC_VAR_IN_REG(0, make_security_guard); | |
1236 MZ_GC_REG(); | |
1237 | |
1238 #if MZSCHEME_VERSION_MAJOR < 400 | |
1239 { | |
1240 Scheme_Object *make_security_guard_symbol = NULL; | |
1241 MZ_GC_DECL_REG(1); | |
1242 MZ_GC_VAR_IN_REG(0, make_security_guard_symbol); | |
1243 MZ_GC_REG(); | |
1244 make_security_guard_symbol = scheme_intern_symbol("make-security-guard"); | |
1245 MZ_GC_CHECK(); | |
1246 make_security_guard = scheme_lookup_global( | |
1247 make_security_guard_symbol, environment); | |
1248 MZ_GC_UNREG(); | |
1249 } | |
1250 #else | |
1251 make_security_guard = scheme_builtin_value("make-security-guard"); | |
1252 MZ_GC_CHECK(); | |
1253 #endif | |
1254 | |
1255 /* setup sandbox guards */ | |
1256 if (make_security_guard != NULL) | |
1257 { | |
1258 Scheme_Object *args[3] = {NULL, NULL, NULL}; | |
1259 Scheme_Object *guard = NULL; | |
1260 Scheme_Config *config = NULL; | |
1261 MZ_GC_DECL_REG(5); | |
1262 MZ_GC_ARRAY_VAR_IN_REG(0, args, 3); | |
1263 MZ_GC_VAR_IN_REG(3, guard); | |
1264 MZ_GC_VAR_IN_REG(4, config); | |
1265 MZ_GC_REG(); | |
4074 | 1266 config = scheme_current_config(); |
1894 | 1267 MZ_GC_CHECK(); |
1268 args[0] = scheme_get_param(config, MZCONFIG_SECURITY_GUARD); | |
1269 MZ_GC_CHECK(); | |
1270 args[1] = scheme_make_prim_w_arity(sandbox_file_guard, | |
1271 "sandbox-file-guard", 3, 3); | |
1272 args[2] = scheme_make_prim_w_arity(sandbox_network_guard, | |
1273 "sandbox-network-guard", 4, 4); | |
1274 guard = scheme_apply(make_security_guard, 3, args); | |
1275 MZ_GC_CHECK(); | |
1276 scheme_set_param(config, MZCONFIG_SECURITY_GUARD, guard); | |
1277 MZ_GC_CHECK(); | |
1278 MZ_GC_UNREG(); | |
1279 } | |
1280 MZ_GC_UNREG(); | |
274 | 1281 } |
1282 #endif | |
14 | 1283 /* Create buffer and window types for use in Scheme code */ |
1284 mz_buffer_type = scheme_make_type("<vim-buffer>"); | |
1894 | 1285 MZ_GC_CHECK(); |
14 | 1286 mz_window_type = scheme_make_type("<vim-window>"); |
1894 | 1287 MZ_GC_CHECK(); |
1288 #ifdef MZ_PRECISE_GC | |
1289 GC_register_traversers(mz_buffer_type, | |
1290 buffer_size_proc, buffer_mark_proc, buffer_fixup_proc, | |
1291 TRUE, TRUE); | |
1292 GC_register_traversers(mz_window_type, | |
1293 window_size_proc, window_mark_proc, window_fixup_proc, | |
1294 TRUE, TRUE); | |
1295 #endif | |
1296 | |
1297 make_modules(); | |
14 | 1298 |
1299 /* | |
1300 * setup callback to receive notifications | |
1301 * whether thread scheduling is (or not) required | |
1302 */ | |
1303 scheme_notify_multithread = notify_multithread; | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1304 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1305 return 0; |
14 | 1306 } |
1307 | |
1308 /* | |
1309 * This routine is called for each new invocation of MzScheme | |
1310 * to make sure things are properly initialized. | |
1311 */ | |
1312 static int | |
1313 mzscheme_init(void) | |
1314 { | |
1315 if (!initialized) | |
1316 { | |
137 | 1317 #ifdef DYNAMIC_MZSCHEME |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1318 if (disabled || !mzscheme_enabled(TRUE)) |
137 | 1319 { |
1919 | 1320 EMSG(_("E815: Sorry, this command is disabled, the MzScheme libraries could not be loaded.")); |
137 | 1321 return -1; |
1322 } | |
1323 #endif | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1324 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
|
1325 { |
7728
e493c5dd85b3
commit https://github.com/vim/vim/commit/9e3be26872307f9c53a9f37647a659091bdffb1f
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
1326 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
|
1327 return -1; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1328 } |
1894 | 1329 initialized = TRUE; |
14 | 1330 } |
1331 { | |
1894 | 1332 Scheme_Config *config = NULL; |
1333 MZ_GC_DECL_REG(1); | |
1334 MZ_GC_VAR_IN_REG(0, config); | |
1335 MZ_GC_REG(); | |
4074 | 1336 config = scheme_current_config(); |
1894 | 1337 MZ_GC_CHECK(); |
2023 | 1338 /* recreate ports each call effectively clearing these ones */ |
4074 | 1339 curout = scheme_make_byte_string_output_port(); |
1894 | 1340 MZ_GC_CHECK(); |
4074 | 1341 curerr = scheme_make_byte_string_output_port(); |
1894 | 1342 MZ_GC_CHECK(); |
1343 scheme_set_param(config, MZCONFIG_OUTPUT_PORT, curout); | |
1344 MZ_GC_CHECK(); | |
1345 scheme_set_param(config, MZCONFIG_ERROR_PORT, curerr); | |
1346 MZ_GC_CHECK(); | |
1347 MZ_GC_UNREG(); | |
14 | 1348 } |
1349 | |
1350 return 0; | |
1351 } | |
1352 | |
1353 /* | |
1354 *======================================================================== | |
1355 * 2. External Interface | |
1356 *======================================================================== | |
1357 */ | |
1358 | |
1359 /* | |
1894 | 1360 * Evaluate command with exception handling |
14 | 1361 */ |
1362 static int | |
1894 | 1363 eval_with_exn_handling(void *data, Scheme_Closed_Prim *what, Scheme_Object **ret) |
14 | 1364 { |
1894 | 1365 Scheme_Object *value = NULL; |
1366 Scheme_Object *exn = NULL; | |
1367 Scheme_Object *prim = NULL; | |
1368 | |
1369 MZ_GC_DECL_REG(3); | |
1370 MZ_GC_VAR_IN_REG(0, value); | |
1371 MZ_GC_VAR_IN_REG(1, exn); | |
1372 MZ_GC_VAR_IN_REG(2, prim); | |
1373 MZ_GC_REG(); | |
1374 | |
1375 prim = scheme_make_closed_prim_w_arity(what, data, "mzvim", 0, 0); | |
1376 MZ_GC_CHECK(); | |
1377 value = _apply_thunk_catch_exceptions(prim, &exn); | |
1378 MZ_GC_CHECK(); | |
14 | 1379 |
1380 if (!value) | |
1381 { | |
1382 value = extract_exn_message(exn); | |
856 | 1383 /* Got an exn? */ |
14 | 1384 if (value) |
1385 { | |
1894 | 1386 scheme_display(value, curerr); /* Send to stderr-vim */ |
1387 MZ_GC_CHECK(); | |
14 | 1388 do_flush(); |
1389 } | |
1894 | 1390 MZ_GC_UNREG(); |
14 | 1391 /* `raise' was called on some arbitrary value */ |
1392 return FAIL; | |
1393 } | |
1394 | |
1395 if (ret != NULL) /* if pointer to retval supported give it up */ | |
1396 *ret = value; | |
1397 /* Print any result, as long as it's not a void */ | |
1398 else if (!SCHEME_VOIDP(value)) | |
1894 | 1399 { |
14 | 1400 scheme_display(value, curout); /* Send to stdout-vim */ |
1894 | 1401 MZ_GC_CHECK(); |
1402 } | |
14 | 1403 |
1404 do_flush(); | |
1894 | 1405 MZ_GC_UNREG(); |
14 | 1406 return OK; |
1407 } | |
1408 | |
1409 /* :mzscheme */ | |
1410 static int | |
1411 do_mzscheme_command(exarg_T *eap, void *data, Scheme_Closed_Prim *what) | |
1412 { | |
1413 if (mzscheme_init()) | |
1414 return FAIL; | |
1415 | |
1416 range_start = eap->line1; | |
1417 range_end = eap->line2; | |
1418 | |
1894 | 1419 return eval_with_exn_handling(data, what, NULL); |
14 | 1420 } |
1421 | |
1422 /* | |
1423 * Routine called by VIM when deleting a buffer | |
1424 */ | |
1425 void | |
1426 mzscheme_buffer_free(buf_T *buf) | |
1427 { | |
502 | 1428 if (buf->b_mzscheme_ref) |
14 | 1429 { |
4074 | 1430 vim_mz_buffer *bp = NULL; |
1431 MZ_GC_DECL_REG(1); | |
1432 MZ_GC_VAR_IN_REG(0, bp); | |
1433 MZ_GC_REG(); | |
1434 | |
1435 bp = BUFFER_REF(buf); | |
14 | 1436 bp->buf = INVALID_BUFFER_VALUE; |
4074 | 1437 #ifndef MZ_PRECISE_GC |
14 | 1438 scheme_gc_ptr_ok(bp); |
4074 | 1439 #else |
1440 scheme_free_immobile_box(buf->b_mzscheme_ref); | |
1441 #endif | |
1442 buf->b_mzscheme_ref = NULL; | |
1894 | 1443 MZ_GC_CHECK(); |
4074 | 1444 MZ_GC_UNREG(); |
14 | 1445 } |
1446 } | |
1447 | |
1448 /* | |
1449 * Routine called by VIM when deleting a Window | |
1450 */ | |
1451 void | |
1452 mzscheme_window_free(win_T *win) | |
1453 { | |
502 | 1454 if (win->w_mzscheme_ref) |
14 | 1455 { |
4074 | 1456 vim_mz_window *wp = NULL; |
1457 MZ_GC_DECL_REG(1); | |
1458 MZ_GC_VAR_IN_REG(0, wp); | |
1459 MZ_GC_REG(); | |
1460 wp = WINDOW_REF(win); | |
14 | 1461 wp->win = INVALID_WINDOW_VALUE; |
4074 | 1462 #ifndef MZ_PRECISE_GC |
14 | 1463 scheme_gc_ptr_ok(wp); |
4074 | 1464 #else |
1465 scheme_free_immobile_box(win->w_mzscheme_ref); | |
1466 #endif | |
1467 win->w_mzscheme_ref = NULL; | |
1894 | 1468 MZ_GC_CHECK(); |
4074 | 1469 MZ_GC_UNREG(); |
14 | 1470 } |
1471 } | |
1472 | |
1473 /* | |
1474 * ":mzscheme" (or ":mz") | |
1475 */ | |
1476 void | |
1477 ex_mzscheme(exarg_T *eap) | |
1478 { | |
1479 char_u *script; | |
1480 | |
1481 script = script_get(eap, eap->arg); | |
1482 if (!eap->skip) | |
1483 { | |
1484 if (script == NULL) | |
1485 do_mzscheme_command(eap, eap->arg, do_eval); | |
1486 else | |
1487 { | |
1488 do_mzscheme_command(eap, script, do_eval); | |
1489 vim_free(script); | |
1490 } | |
1491 } | |
1492 } | |
1493 | |
1494 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1495 do_load(void *data, int noargc UNUSED, Scheme_Object **noargv UNUSED) |
14 | 1496 { |
1894 | 1497 Scheme_Object *expr = NULL; |
1498 Scheme_Object *result = NULL; | |
1499 char *file = NULL; | |
1500 Port_Info *pinfo = (Port_Info *)data; | |
1501 | |
1502 MZ_GC_DECL_REG(3); | |
1503 MZ_GC_VAR_IN_REG(0, expr); | |
1504 MZ_GC_VAR_IN_REG(1, result); | |
1505 MZ_GC_VAR_IN_REG(2, file); | |
1506 MZ_GC_REG(); | |
1507 | |
1508 file = (char *)scheme_malloc_fail_ok(scheme_malloc_atomic, MAXPATHL + 1); | |
1509 MZ_GC_CHECK(); | |
14 | 1510 |
1511 /* make Vim expansion */ | |
1894 | 1512 expand_env((char_u *)pinfo->name, (char_u *)file, MAXPATHL); |
14 | 1513 pinfo->port = scheme_open_input_file(file, "mzfile"); |
1894 | 1514 MZ_GC_CHECK(); |
1515 scheme_count_lines(pinfo->port); /* to get accurate read error location*/ | |
1516 MZ_GC_CHECK(); | |
14 | 1517 |
1518 /* Like REPL but print only last result */ | |
1519 while (!SCHEME_EOFP(expr = scheme_read(pinfo->port))) | |
1894 | 1520 { |
1521 result = scheme_eval(expr, environment); | |
1522 MZ_GC_CHECK(); | |
1523 } | |
14 | 1524 |
2023 | 1525 /* errors will be caught in do_mzscheme_command and ex_mzfile */ |
14 | 1526 scheme_close_input_port(pinfo->port); |
1894 | 1527 MZ_GC_CHECK(); |
14 | 1528 pinfo->port = NULL; |
1894 | 1529 MZ_GC_UNREG(); |
14 | 1530 return result; |
1531 } | |
1532 | |
1533 /* :mzfile */ | |
1534 void | |
1535 ex_mzfile(exarg_T *eap) | |
1536 { | |
1894 | 1537 Port_Info pinfo = {NULL, NULL}; |
1538 | |
1539 MZ_GC_DECL_REG(1); | |
1540 MZ_GC_VAR_IN_REG(0, pinfo.port); | |
1541 MZ_GC_REG(); | |
14 | 1542 |
1543 pinfo.name = (char *)eap->arg; | |
1544 if (do_mzscheme_command(eap, &pinfo, do_load) != OK | |
1545 && pinfo.port != NULL) /* looks like port was not closed */ | |
1894 | 1546 { |
14 | 1547 scheme_close_input_port(pinfo.port); |
1894 | 1548 MZ_GC_CHECK(); |
1549 } | |
1550 MZ_GC_UNREG(); | |
14 | 1551 } |
1552 | |
1553 | |
1554 /* | |
1555 *======================================================================== | |
1556 * Exception handling code -- cribbed form the MzScheme sources and | |
1557 * Matthew Flatt's "Inside PLT MzScheme" document. | |
1558 *======================================================================== | |
1559 */ | |
1560 static void | |
1561 init_exn_catching_apply(void) | |
1562 { | |
1563 if (!exn_catching_apply) | |
1564 { | |
1565 char *e = | |
1566 "(lambda (thunk) " | |
856 | 1567 "(with-handlers ([void (lambda (exn) (cons #f exn))]) " |
14 | 1568 "(cons #t (thunk))))"; |
1569 | |
1894 | 1570 exn_catching_apply = scheme_eval_string(e, environment); |
1571 MZ_GC_CHECK(); | |
1572 exn_p = scheme_builtin_value("exn?"); | |
1573 MZ_GC_CHECK(); | |
1574 exn_message = scheme_builtin_value("exn-message"); | |
1575 MZ_GC_CHECK(); | |
14 | 1576 } |
1577 } | |
1578 | |
1579 /* | |
1580 * This function applies a thunk, returning the Scheme value if there's | |
1581 * no exception, otherwise returning NULL and setting *exn to the raised | |
1582 * value (usually an exn structure). | |
1583 */ | |
1584 static Scheme_Object * | |
1585 _apply_thunk_catch_exceptions(Scheme_Object *f, Scheme_Object **exn) | |
1586 { | |
1587 Scheme_Object *v; | |
1588 | |
1589 v = _scheme_apply(exn_catching_apply, 1, &f); | |
1590 /* v is a pair: (cons #t value) or (cons #f exn) */ | |
1591 | |
1592 if (SCHEME_TRUEP(SCHEME_CAR(v))) | |
1593 return SCHEME_CDR(v); | |
1594 else | |
1595 { | |
1596 *exn = SCHEME_CDR(v); | |
1597 return NULL; | |
1598 } | |
1599 } | |
1600 | |
1601 static Scheme_Object * | |
1602 extract_exn_message(Scheme_Object *v) | |
1603 { | |
1604 if (SCHEME_TRUEP(_scheme_apply(exn_p, 1, &v))) | |
1605 return _scheme_apply(exn_message, 1, &v); | |
1606 else | |
1607 return NULL; /* Not an exn structure */ | |
1608 } | |
1609 | |
1610 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1611 do_eval(void *s, int noargc UNUSED, Scheme_Object **noargv UNUSED) |
14 | 1612 { |
1894 | 1613 return scheme_eval_string_all((char *)s, environment, TRUE); |
14 | 1614 } |
1615 | |
1616 /* | |
1617 *======================================================================== | |
1618 * 3. MzScheme I/O Handlers | |
1619 *======================================================================== | |
1620 */ | |
1621 static void | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1622 do_intrnl_output(char *mesg, int error) |
14 | 1623 { |
1624 char *p, *prev; | |
1625 | |
1626 prev = mesg; | |
1627 p = strchr(prev, '\n'); | |
1628 while (p) | |
1629 { | |
1630 *p = '\0'; | |
1631 if (error) | |
1632 EMSG(prev); | |
1633 else | |
1634 MSG(prev); | |
1635 prev = p + 1; | |
1636 p = strchr(prev, '\n'); | |
1637 } | |
1638 | |
1639 if (error) | |
1640 EMSG(prev); | |
1641 else | |
1642 MSG(prev); | |
1643 } | |
1644 | |
1645 static void | |
4074 | 1646 do_output(char *mesg, OUTPUT_LEN_TYPE len UNUSED) |
14 | 1647 { |
3953 | 1648 /* 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
|
1649 do_intrnl_output(mesg, 0); |
14 | 1650 } |
1651 | |
1652 static void | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1653 do_err_output(char *mesg) |
14 | 1654 { |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1655 do_intrnl_output(mesg, 1); |
14 | 1656 } |
1657 | |
1658 static void | |
1659 do_printf(char *format, ...) | |
1660 { | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1661 do_intrnl_output(format, 1); |
14 | 1662 } |
1663 | |
1664 static void | |
1665 do_flush(void) | |
1666 { | |
1667 char *buff; | |
4074 | 1668 OUTPUT_LEN_TYPE length; |
1669 | |
1670 buff = scheme_get_sized_byte_string_output(curerr, &length); | |
1894 | 1671 MZ_GC_CHECK(); |
14 | 1672 if (length) |
1673 { | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1674 do_err_output(buff); |
14 | 1675 return; |
1676 } | |
1677 | |
4074 | 1678 buff = scheme_get_sized_byte_string_output(curout, &length); |
1894 | 1679 MZ_GC_CHECK(); |
14 | 1680 if (length) |
1681 do_output(buff, length); | |
1682 } | |
1683 | |
1684 /* | |
1685 *======================================================================== | |
1686 * 4. Implementation of the Vim Features for MzScheme | |
1687 *======================================================================== | |
1688 */ | |
1689 | |
1690 /* (command {command-string}) */ | |
1691 static Scheme_Object * | |
1692 vim_command(void *data, int argc, Scheme_Object **argv) | |
1693 { | |
1694 Vim_Prim *prim = (Vim_Prim *)data; | |
4074 | 1695 Scheme_Object *cmd = NULL; |
1696 MZ_GC_DECL_REG(1); | |
1697 MZ_GC_VAR_IN_REG(0, cmd); | |
1698 MZ_GC_REG(); | |
1699 cmd = GUARANTEED_STRING_ARG(prim->name, 0); | |
14 | 1700 |
1701 /* may be use do_cmdline_cmd? */ | |
4074 | 1702 do_cmdline(BYTE_STRING_VALUE(cmd), NULL, NULL, DOCMD_NOWAIT|DOCMD_VERBOSE); |
14 | 1703 update_screen(VALID); |
1704 | |
4074 | 1705 MZ_GC_UNREG(); |
14 | 1706 raise_if_error(); |
1707 return scheme_void; | |
1708 } | |
1709 | |
1710 /* (eval {expr-string}) */ | |
1711 static Scheme_Object * | |
4082 | 1712 vim_eval(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1713 { |
1714 #ifdef FEAT_EVAL | |
1894 | 1715 Vim_Prim *prim = (Vim_Prim *)data; |
4074 | 1716 Scheme_Object *result = NULL; |
1894 | 1717 typval_T *vim_result; |
4074 | 1718 Scheme_Object *expr = NULL; |
1719 MZ_GC_DECL_REG(2); | |
1720 MZ_GC_VAR_IN_REG(0, result); | |
1721 MZ_GC_VAR_IN_REG(1, expr); | |
1894 | 1722 MZ_GC_REG(); |
4074 | 1723 expr = GUARANTEED_STRING_ARG(prim->name, 0); |
1724 | |
1725 vim_result = eval_expr(BYTE_STRING_VALUE(expr), NULL); | |
1894 | 1726 |
1727 if (vim_result == NULL) | |
14 | 1728 raise_vim_exn(_("invalid expression")); |
1729 | |
4074 | 1730 result = vim_to_mzscheme(vim_result); |
1731 MZ_GC_CHECK(); | |
1894 | 1732 free_tv(vim_result); |
1733 | |
1734 MZ_GC_UNREG(); | |
14 | 1735 return result; |
1736 #else | |
1737 raise_vim_exn(_("expressions disabled at compile time")); | |
1738 /* unreachable */ | |
1739 return scheme_false; | |
1740 #endif | |
1741 } | |
1742 | |
1743 /* (range-start) */ | |
1744 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1745 get_range_start(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1746 { |
1747 return scheme_make_integer(range_start); | |
1748 } | |
1749 | |
1750 /* (range-end) */ | |
1751 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1752 get_range_end(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1753 { |
1754 return scheme_make_integer(range_end); | |
1755 } | |
1756 | |
1757 /* (beep) */ | |
1758 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1759 mzscheme_beep(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1760 { |
6949 | 1761 vim_beep(BO_LANG); |
14 | 1762 return scheme_void; |
1763 } | |
1764 | |
1765 static Scheme_Object *M_global = NULL; | |
1766 | |
1767 /* (get-option {option-name}) [buffer/window] */ | |
1768 static Scheme_Object * | |
1769 get_option(void *data, int argc, Scheme_Object **argv) | |
1770 { | |
1771 Vim_Prim *prim = (Vim_Prim *)data; | |
1772 long value; | |
1894 | 1773 char *strval; |
14 | 1774 int rc; |
4074 | 1775 Scheme_Object *rval = NULL; |
1776 Scheme_Object *name = NULL; | |
14 | 1777 int opt_flags = 0; |
1778 buf_T *save_curb = curbuf; | |
1779 win_T *save_curw = curwin; | |
1780 | |
4074 | 1781 MZ_GC_DECL_REG(2); |
1782 MZ_GC_VAR_IN_REG(0, rval); | |
1783 MZ_GC_VAR_IN_REG(1, name); | |
1784 MZ_GC_REG(); | |
1785 | |
1786 name = GUARANTEED_STRING_ARG(prim->name, 0); | |
14 | 1787 |
1788 if (argc > 1) | |
1789 { | |
1790 if (M_global == NULL) | |
1791 { | |
1792 MZ_REGISTER_STATIC(M_global); | |
1793 M_global = scheme_intern_symbol("global"); | |
1894 | 1794 MZ_GC_CHECK(); |
14 | 1795 } |
1796 | |
1797 if (argv[1] == M_global) | |
1798 opt_flags = OPT_GLOBAL; | |
1799 else if (SCHEME_VIMBUFFERP(argv[1])) | |
1800 { | |
1801 curbuf = get_valid_buffer(argv[1]); | |
1802 opt_flags = OPT_LOCAL; | |
1803 } | |
1804 else if (SCHEME_VIMWINDOWP(argv[1])) | |
1805 { | |
1806 win_T *win = get_valid_window(argv[1]); | |
1807 | |
1808 curwin = win; | |
1809 curbuf = win->w_buffer; | |
1810 opt_flags = OPT_LOCAL; | |
1811 } | |
1812 else | |
1813 scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv); | |
1814 } | |
1815 | |
4074 | 1816 rc = get_option_value(BYTE_STRING_VALUE(name), &value, (char_u **)&strval, opt_flags); |
14 | 1817 curbuf = save_curb; |
1818 curwin = save_curw; | |
1819 | |
1820 switch (rc) | |
1821 { | |
1822 case 1: | |
4074 | 1823 MZ_GC_UNREG(); |
14 | 1824 return scheme_make_integer_value(value); |
1825 case 0: | |
4074 | 1826 rval = scheme_make_byte_string(strval); |
1894 | 1827 MZ_GC_CHECK(); |
14 | 1828 vim_free(strval); |
4074 | 1829 MZ_GC_UNREG(); |
14 | 1830 return rval; |
1831 case -1: | |
1832 case -2: | |
4074 | 1833 MZ_GC_UNREG(); |
856 | 1834 raise_vim_exn(_("hidden option")); |
14 | 1835 case -3: |
4074 | 1836 MZ_GC_UNREG(); |
856 | 1837 raise_vim_exn(_("unknown option")); |
14 | 1838 } |
1839 /* unreachable */ | |
1840 return scheme_void; | |
1841 } | |
1842 | |
1843 /* (set-option {option-changing-string} [buffer/window]) */ | |
1844 static Scheme_Object * | |
1845 set_option(void *data, int argc, Scheme_Object **argv) | |
1846 { | |
4074 | 1847 char_u *command = NULL; |
14 | 1848 int opt_flags = 0; |
1849 buf_T *save_curb = curbuf; | |
1850 win_T *save_curw = curwin; | |
1851 Vim_Prim *prim = (Vim_Prim *)data; | |
4074 | 1852 Scheme_Object *cmd = NULL; |
1853 | |
1854 MZ_GC_DECL_REG(1); | |
1855 MZ_GC_VAR_IN_REG(0, cmd); | |
1856 MZ_GC_REG(); | |
1857 cmd = GUARANTEED_STRING_ARG(prim->name, 0); | |
1858 | |
14 | 1859 if (argc > 1) |
1860 { | |
1861 if (M_global == NULL) | |
1862 { | |
1863 MZ_REGISTER_STATIC(M_global); | |
1864 M_global = scheme_intern_symbol("global"); | |
1894 | 1865 MZ_GC_CHECK(); |
14 | 1866 } |
1867 | |
1868 if (argv[1] == M_global) | |
1869 opt_flags = OPT_GLOBAL; | |
1870 else if (SCHEME_VIMBUFFERP(argv[1])) | |
1871 { | |
1872 curbuf = get_valid_buffer(argv[1]); | |
1873 opt_flags = OPT_LOCAL; | |
1874 } | |
1875 else if (SCHEME_VIMWINDOWP(argv[1])) | |
1876 { | |
1877 win_T *win = get_valid_window(argv[1]); | |
1878 curwin = win; | |
1879 curbuf = win->w_buffer; | |
1880 opt_flags = OPT_LOCAL; | |
1881 } | |
1882 else | |
1883 scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv); | |
1884 } | |
1885 | |
1886 /* do_set can modify cmd, make copy */ | |
4074 | 1887 command = vim_strsave(BYTE_STRING_VALUE(cmd)); |
1888 MZ_GC_UNREG(); | |
1889 do_set(command, opt_flags); | |
1890 vim_free(command); | |
14 | 1891 update_screen(NOT_VALID); |
1892 curbuf = save_curb; | |
1893 curwin = save_curw; | |
1894 raise_if_error(); | |
1895 return scheme_void; | |
1896 } | |
1897 | |
1898 /* | |
1899 *=========================================================================== | |
1900 * 5. Vim Window-related Manipulation Functions | |
1901 *=========================================================================== | |
1902 */ | |
1903 | |
1904 /* (curr-win) */ | |
1905 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1906 get_curr_win(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1907 { |
1908 return (Scheme_Object *)get_vim_curr_window(); | |
1909 } | |
1910 | |
1911 /* (win-count) */ | |
1912 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1913 get_window_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1914 { |
4082 | 1915 int n = 0; |
1916 #ifdef FEAT_WINDOWS | |
14 | 1917 win_T *w; |
1918 | |
671 | 1919 for (w = firstwin; w != NULL; w = w->w_next) |
4082 | 1920 #endif |
671 | 1921 ++n; |
14 | 1922 return scheme_make_integer(n); |
1923 } | |
1924 | |
1925 /* (get-win-list [buffer]) */ | |
1926 static Scheme_Object * | |
1927 get_window_list(void *data, int argc, Scheme_Object **argv) | |
1928 { | |
1929 Vim_Prim *prim = (Vim_Prim *)data; | |
1930 vim_mz_buffer *buf; | |
1931 Scheme_Object *list; | |
4082 | 1932 win_T *w = firstwin; |
14 | 1933 |
1934 buf = get_buffer_arg(prim->name, 0, argc, argv); | |
1935 list = scheme_null; | |
1936 | |
4082 | 1937 #ifdef FEAT_WINDOWS |
1938 for ( ; w != NULL; w = w->w_next) | |
1939 #endif | |
856 | 1940 if (w->w_buffer == buf->buf) |
1894 | 1941 { |
14 | 1942 list = scheme_make_pair(window_new(w), list); |
1894 | 1943 MZ_GC_CHECK(); |
1944 } | |
14 | 1945 |
1946 return list; | |
1947 } | |
1948 | |
1949 static Scheme_Object * | |
1950 window_new(win_T *win) | |
1951 { | |
1894 | 1952 vim_mz_window *self = NULL; |
1953 | |
1954 MZ_GC_DECL_REG(1); | |
1955 MZ_GC_VAR_IN_REG(0, self); | |
14 | 1956 |
1957 /* We need to handle deletion of windows underneath us. | |
502 | 1958 * If we add a "w_mzscheme_ref" field to the win_T structure, |
14 | 1959 * then we can get at it in win_free() in vim. |
1960 * | |
1961 * On a win_free() we set the Scheme object's win_T *field | |
1962 * to an invalid value. We trap all uses of a window | |
1963 * object, and reject them if the win_T *field is invalid. | |
1964 */ | |
502 | 1965 if (win->w_mzscheme_ref != NULL) |
4074 | 1966 return (Scheme_Object *)WINDOW_REF(win); |
1967 | |
1968 MZ_GC_REG(); | |
1969 self = scheme_malloc_fail_ok(scheme_malloc_tagged, sizeof(vim_mz_window)); | |
14 | 1970 vim_memset(self, 0, sizeof(vim_mz_window)); |
4074 | 1971 #ifndef MZ_PRECISE_GC |
14 | 1972 scheme_dont_gc_ptr(self); /* because win isn't visible to GC */ |
4074 | 1973 #else |
1974 win->w_mzscheme_ref = scheme_malloc_immobile_box(NULL); | |
1975 #endif | |
1894 | 1976 MZ_GC_CHECK(); |
4074 | 1977 WINDOW_REF(win) = self; |
1978 MZ_GC_CHECK(); | |
14 | 1979 self->win = win; |
1894 | 1980 self->so.type = mz_window_type; |
1981 | |
1982 MZ_GC_UNREG(); | |
4074 | 1983 return (Scheme_Object *)self; |
14 | 1984 } |
1985 | |
1986 /* (get-win-num [window]) */ | |
1987 static Scheme_Object * | |
4082 | 1988 get_window_num(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1989 { |
4082 | 1990 int nr = 1; |
1991 #ifdef FEAT_WINDOWS | |
14 | 1992 Vim_Prim *prim = (Vim_Prim *)data; |
1993 win_T *win = get_window_arg(prim->name, 0, argc, argv)->win; | |
1994 win_T *wp; | |
1995 | |
1996 for (wp = firstwin; wp != win; wp = wp->w_next) | |
4082 | 1997 #endif |
14 | 1998 ++nr; |
1999 | |
2000 return scheme_make_integer(nr); | |
2001 } | |
2002 | |
2003 /* (get-win-by-num {windownum}) */ | |
2004 static Scheme_Object * | |
2005 get_window_by_num(void *data, int argc, Scheme_Object **argv) | |
2006 { | |
2007 Vim_Prim *prim = (Vim_Prim *)data; | |
4082 | 2008 win_T *win = firstwin; |
14 | 2009 int fnum; |
2010 | |
2011 fnum = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
2012 if (fnum < 1) | |
2013 scheme_signal_error(_("window index is out of range")); | |
2014 | |
4082 | 2015 #ifdef FEAT_WINDOWS |
2016 for ( ; win != NULL; win = win->w_next, --fnum) | |
2017 #endif | |
856 | 2018 if (fnum == 1) /* to be 1-based */ |
14 | 2019 return window_new(win); |
2020 | |
2021 return scheme_false; | |
2022 } | |
2023 | |
2024 /* (get-win-buffer [window]) */ | |
2025 static Scheme_Object * | |
2026 get_window_buffer(void *data, int argc, Scheme_Object **argv) | |
2027 { | |
2028 Vim_Prim *prim = (Vim_Prim *)data; | |
2029 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv); | |
2030 | |
2031 return buffer_new(win->win->w_buffer); | |
2032 } | |
2033 | |
2034 /* (get-win-height [window]) */ | |
2035 static Scheme_Object * | |
2036 get_window_height(void *data, int argc, Scheme_Object **argv) | |
2037 { | |
2038 Vim_Prim *prim = (Vim_Prim *)data; | |
2039 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv); | |
2040 | |
2041 return scheme_make_integer(win->win->w_height); | |
2042 } | |
2043 | |
2044 /* (set-win-height {height} [window]) */ | |
2045 static Scheme_Object * | |
2046 set_window_height(void *data, int argc, Scheme_Object **argv) | |
2047 { | |
2048 Vim_Prim *prim = (Vim_Prim *)data; | |
2049 vim_mz_window *win; | |
2050 win_T *savewin; | |
2051 int height; | |
2052 | |
2053 win = get_window_arg(prim->name, 1, argc, argv); | |
2054 height = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
2055 | |
2056 #ifdef FEAT_GUI | |
2057 need_mouse_correct = TRUE; | |
2058 #endif | |
2059 | |
2060 savewin = curwin; | |
2061 curwin = win->win; | |
2062 win_setheight(height); | |
2063 curwin = savewin; | |
2064 | |
2065 raise_if_error(); | |
2066 return scheme_void; | |
2067 } | |
2068 | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8218
diff
changeset
|
2069 #ifdef FEAT_WINDOWS |
14 | 2070 /* (get-win-width [window]) */ |
2071 static Scheme_Object * | |
2072 get_window_width(void *data, int argc, Scheme_Object **argv) | |
2073 { | |
2074 Vim_Prim *prim = (Vim_Prim *)data; | |
2075 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv); | |
2076 | |
2077 return scheme_make_integer(W_WIDTH(win->win)); | |
2078 } | |
2079 | |
2080 /* (set-win-width {width} [window]) */ | |
2081 static Scheme_Object * | |
2082 set_window_width(void *data, int argc, Scheme_Object **argv) | |
2083 { | |
2084 Vim_Prim *prim = (Vim_Prim *)data; | |
2085 vim_mz_window *win; | |
2086 win_T *savewin; | |
2087 int width = 0; | |
2088 | |
2089 win = get_window_arg(prim->name, 1, argc, argv); | |
2090 width = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
2091 | |
2092 # ifdef FEAT_GUI | |
2093 need_mouse_correct = TRUE; | |
2094 # endif | |
2095 | |
2096 savewin = curwin; | |
2097 curwin = win->win; | |
2098 win_setwidth(width); | |
2099 curwin = savewin; | |
2100 | |
2101 raise_if_error(); | |
2102 return scheme_void; | |
2103 } | |
2104 #endif | |
2105 | |
2106 /* (get-cursor [window]) -> (line . col) */ | |
2107 static Scheme_Object * | |
2108 get_cursor(void *data, int argc, Scheme_Object **argv) | |
2109 { | |
2110 Vim_Prim *prim = (Vim_Prim *)data; | |
2111 vim_mz_window *win; | |
2112 pos_T pos; | |
2113 | |
2114 win = get_window_arg(prim->name, 0, argc, argv); | |
2115 pos = win->win->w_cursor; | |
2116 return scheme_make_pair(scheme_make_integer_value((long)pos.lnum), | |
2117 scheme_make_integer_value((long)pos.col + 1)); | |
2118 } | |
2119 | |
2120 /* (set-cursor (line . col) [window]) */ | |
2121 static Scheme_Object * | |
2122 set_cursor(void *data, int argc, Scheme_Object **argv) | |
2123 { | |
2124 Vim_Prim *prim = (Vim_Prim *)data; | |
2125 vim_mz_window *win; | |
2126 long lnum = 0; | |
2127 long col = 0; | |
2128 | |
274 | 2129 #ifdef HAVE_SANDBOX |
2130 sandbox_check(); | |
2131 #endif | |
14 | 2132 win = get_window_arg(prim->name, 1, argc, argv); |
2133 GUARANTEE_PAIR(prim->name, 0); | |
2134 | |
2135 if (!SCHEME_INTP(SCHEME_CAR(argv[0])) | |
2136 || !SCHEME_INTP(SCHEME_CDR(argv[0]))) | |
2137 scheme_wrong_type(prim->name, "integer pair", 0, argc, argv); | |
2138 | |
2139 lnum = SCHEME_INT_VAL(SCHEME_CAR(argv[0])); | |
2140 col = SCHEME_INT_VAL(SCHEME_CDR(argv[0])) - 1; | |
2141 | |
2142 check_line_range(lnum, win->win->w_buffer); | |
2143 /* don't know how to catch invalid column value */ | |
2144 | |
2145 win->win->w_cursor.lnum = lnum; | |
2146 win->win->w_cursor.col = col; | |
2147 update_screen(VALID); | |
2148 | |
2149 raise_if_error(); | |
2150 return scheme_void; | |
2151 } | |
2152 /* | |
2153 *=========================================================================== | |
2154 * 6. Vim Buffer-related Manipulation Functions | |
2155 *=========================================================================== | |
2156 */ | |
2157 | |
2158 /* (open-buff {filename}) */ | |
2159 static Scheme_Object * | |
2160 mzscheme_open_buffer(void *data, int argc, Scheme_Object **argv) | |
2161 { | |
2162 Vim_Prim *prim = (Vim_Prim *)data; | |
2163 int num = 0; | |
4074 | 2164 Scheme_Object *onum = NULL; |
2165 Scheme_Object *buf = NULL; | |
2166 Scheme_Object *fname; | |
2167 | |
2168 MZ_GC_DECL_REG(3); | |
2169 MZ_GC_VAR_IN_REG(0, onum); | |
2170 MZ_GC_VAR_IN_REG(1, buf); | |
2171 MZ_GC_VAR_IN_REG(2, fname); | |
2172 MZ_GC_REG(); | |
2173 fname = GUARANTEED_STRING_ARG(prim->name, 0); | |
14 | 2174 |
274 | 2175 #ifdef HAVE_SANDBOX |
2176 sandbox_check(); | |
2177 #endif | |
14 | 2178 /* TODO make open existing file */ |
4074 | 2179 num = buflist_add(BYTE_STRING_VALUE(fname), BLN_LISTED | BLN_CURBUF); |
14 | 2180 |
2181 if (num == 0) | |
2182 raise_vim_exn(_("couldn't open buffer")); | |
2183 | |
2184 onum = scheme_make_integer(num); | |
4074 | 2185 buf = get_buffer_by_num(data, 1, &onum); |
2186 MZ_GC_UNREG(); | |
2187 return buf; | |
14 | 2188 } |
2189 | |
2190 /* (get-buff-by-num {buffernum}) */ | |
2191 static Scheme_Object * | |
2192 get_buffer_by_num(void *data, int argc, Scheme_Object **argv) | |
2193 { | |
2194 Vim_Prim *prim = (Vim_Prim *)data; | |
2195 buf_T *buf; | |
2196 int fnum; | |
2197 | |
2198 fnum = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
2199 | |
2200 for (buf = firstbuf; buf; buf = buf->b_next) | |
856 | 2201 if (buf->b_fnum == fnum) |
14 | 2202 return buffer_new(buf); |
2203 | |
2204 return scheme_false; | |
2205 } | |
2206 | |
2207 /* (get-buff-by-name {buffername}) */ | |
2208 static Scheme_Object * | |
2209 get_buffer_by_name(void *data, int argc, Scheme_Object **argv) | |
2210 { | |
2211 Vim_Prim *prim = (Vim_Prim *)data; | |
2212 buf_T *buf; | |
4074 | 2213 Scheme_Object *buffer = NULL; |
2214 Scheme_Object *fname = NULL; | |
2215 | |
2216 MZ_GC_DECL_REG(2); | |
2217 MZ_GC_VAR_IN_REG(0, buffer); | |
2218 MZ_GC_VAR_IN_REG(1, fname); | |
2219 MZ_GC_REG(); | |
2220 fname = GUARANTEED_STRING_ARG(prim->name, 0); | |
2221 buffer = scheme_false; | |
14 | 2222 |
2223 for (buf = firstbuf; buf; buf = buf->b_next) | |
4074 | 2224 { |
14 | 2225 if (buf->b_ffname == NULL || buf->b_sfname == NULL) |
2226 /* empty string */ | |
2227 { | |
4074 | 2228 if (BYTE_STRING_VALUE(fname)[0] == NUL) |
2229 buffer = buffer_new(buf); | |
14 | 2230 } |
4074 | 2231 else if (!fnamecmp(buf->b_ffname, BYTE_STRING_VALUE(fname)) |
2232 || !fnamecmp(buf->b_sfname, BYTE_STRING_VALUE(fname))) | |
2233 { | |
14 | 2234 /* either short or long filename matches */ |
4074 | 2235 buffer = buffer_new(buf); |
2236 } | |
2237 } | |
2238 | |
2239 MZ_GC_UNREG(); | |
2240 return buffer; | |
14 | 2241 } |
2242 | |
2243 /* (get-next-buff [buffer]) */ | |
2244 static Scheme_Object * | |
2245 get_next_buffer(void *data, int argc, Scheme_Object **argv) | |
2246 { | |
2247 Vim_Prim *prim = (Vim_Prim *)data; | |
2248 buf_T *buf = get_buffer_arg(prim->name, 0, argc, argv)->buf; | |
2249 | |
2250 if (buf->b_next == NULL) | |
2251 return scheme_false; | |
2252 else | |
2253 return buffer_new(buf->b_next); | |
2254 } | |
2255 | |
2256 /* (get-prev-buff [buffer]) */ | |
2257 static Scheme_Object * | |
2258 get_prev_buffer(void *data, int argc, Scheme_Object **argv) | |
2259 { | |
2260 Vim_Prim *prim = (Vim_Prim *)data; | |
2261 buf_T *buf = get_buffer_arg(prim->name, 0, argc, argv)->buf; | |
2262 | |
2263 if (buf->b_prev == NULL) | |
2264 return scheme_false; | |
2265 else | |
2266 return buffer_new(buf->b_prev); | |
2267 } | |
2268 | |
2269 /* (get-buff-num [buffer]) */ | |
2270 static Scheme_Object * | |
2271 get_buffer_num(void *data, int argc, Scheme_Object **argv) | |
2272 { | |
2273 Vim_Prim *prim = (Vim_Prim *)data; | |
2274 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv); | |
2275 | |
2276 return scheme_make_integer(buf->buf->b_fnum); | |
2277 } | |
2278 | |
2279 /* (buff-count) */ | |
2280 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
2281 get_buffer_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 2282 { |
2283 buf_T *b; | |
2284 int n = 0; | |
2285 | |
2286 for (b = firstbuf; b; b = b->b_next) ++n; | |
2287 return scheme_make_integer(n); | |
2288 } | |
2289 | |
2290 /* (get-buff-name [buffer]) */ | |
2291 static Scheme_Object * | |
2292 get_buffer_name(void *data, int argc, Scheme_Object **argv) | |
2293 { | |
2294 Vim_Prim *prim = (Vim_Prim *)data; | |
2295 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv); | |
2296 | |
4074 | 2297 return scheme_make_byte_string((char *)buf->buf->b_ffname); |
14 | 2298 } |
2299 | |
2300 /* (curr-buff) */ | |
2301 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
2302 get_curr_buffer(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 2303 { |
2304 return (Scheme_Object *)get_vim_curr_buffer(); | |
2305 } | |
2306 | |
2307 static Scheme_Object * | |
2308 buffer_new(buf_T *buf) | |
2309 { | |
1894 | 2310 vim_mz_buffer *self = NULL; |
2311 | |
2312 MZ_GC_DECL_REG(1); | |
2313 MZ_GC_VAR_IN_REG(0, self); | |
14 | 2314 |
2315 /* We need to handle deletion of buffers underneath us. | |
502 | 2316 * If we add a "b_mzscheme_ref" field to the buf_T structure, |
14 | 2317 * then we can get at it in buf_freeall() in vim. |
2318 */ | |
502 | 2319 if (buf->b_mzscheme_ref) |
4074 | 2320 return (Scheme_Object *)BUFFER_REF(buf); |
2321 | |
2322 MZ_GC_REG(); | |
2323 self = scheme_malloc_fail_ok(scheme_malloc_tagged, sizeof(vim_mz_buffer)); | |
14 | 2324 vim_memset(self, 0, sizeof(vim_mz_buffer)); |
4074 | 2325 #ifndef MZ_PRECISE_GC |
2326 scheme_dont_gc_ptr(self); /* because buf isn't visible to GC */ | |
2327 #else | |
2328 buf->b_mzscheme_ref = scheme_malloc_immobile_box(NULL); | |
2329 #endif | |
1894 | 2330 MZ_GC_CHECK(); |
4074 | 2331 BUFFER_REF(buf) = self; |
2332 MZ_GC_CHECK(); | |
14 | 2333 self->buf = buf; |
1894 | 2334 self->so.type = mz_buffer_type; |
2335 | |
2336 MZ_GC_UNREG(); | |
4074 | 2337 return (Scheme_Object *)self; |
14 | 2338 } |
2339 | |
2340 /* | |
2341 * (get-buff-size [buffer]) | |
2342 * | |
2343 * Get the size (number of lines) in the current buffer. | |
2344 */ | |
2345 static Scheme_Object * | |
2346 get_buffer_size(void *data, int argc, Scheme_Object **argv) | |
2347 { | |
2348 Vim_Prim *prim = (Vim_Prim *)data; | |
2349 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv); | |
2350 | |
2351 return scheme_make_integer(buf->buf->b_ml.ml_line_count); | |
2352 } | |
2353 | |
2354 /* | |
2355 * (get-buff-line {linenr} [buffer]) | |
2356 * | |
2357 * Get a line from the specified buffer. The line number is | |
2358 * in Vim format (1-based). The line is returned as a MzScheme | |
2359 * string object. | |
2360 */ | |
2361 static Scheme_Object * | |
2362 get_buffer_line(void *data, int argc, Scheme_Object **argv) | |
2363 { | |
2364 Vim_Prim *prim = (Vim_Prim *)data; | |
2365 vim_mz_buffer *buf; | |
2366 int linenr; | |
1894 | 2367 char_u *line; |
14 | 2368 |
2369 buf = get_buffer_arg(prim->name, 1, argc, argv); | |
2370 linenr = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
2371 line = ml_get_buf(buf->buf, (linenr_T)linenr, FALSE); | |
2372 | |
2373 raise_if_error(); | |
4074 | 2374 return scheme_make_byte_string((char *)line); |
14 | 2375 } |
2376 | |
2377 | |
2378 /* | |
2379 * (get-buff-line-list {start} {end} [buffer]) | |
2380 * | |
2381 * Get a list of lines from the specified buffer. The line numbers | |
2382 * are in Vim format (1-based). The range is from lo up to, but not | |
2383 * including, hi. The list is returned as a list of string objects. | |
2384 */ | |
2385 static Scheme_Object * | |
2386 get_buffer_line_list(void *data, int argc, Scheme_Object **argv) | |
2387 { | |
2388 Vim_Prim *prim = (Vim_Prim *)data; | |
2389 vim_mz_buffer *buf; | |
2390 int i, hi, lo, n; | |
1894 | 2391 Scheme_Object *list = NULL; |
2392 | |
2393 MZ_GC_DECL_REG(1); | |
2394 MZ_GC_VAR_IN_REG(0, list); | |
2395 MZ_GC_REG(); | |
14 | 2396 |
2397 buf = get_buffer_arg(prim->name, 2, argc, argv); | |
2398 list = scheme_null; | |
2399 hi = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 1)); | |
2400 lo = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
2401 | |
2402 /* | |
2403 * Handle some error conditions | |
2404 */ | |
2405 if (lo < 0) | |
856 | 2406 lo = 0; |
14 | 2407 |
2408 if (hi < 0) | |
2409 hi = 0; | |
2410 if (hi < lo) | |
856 | 2411 hi = lo; |
14 | 2412 |
2413 n = hi - lo; | |
2414 | |
2415 for (i = n; i >= 0; --i) | |
2416 { | |
4074 | 2417 Scheme_Object *str = scheme_make_byte_string( |
14 | 2418 (char *)ml_get_buf(buf->buf, (linenr_T)(lo+i), FALSE)); |
2419 raise_if_error(); | |
2420 | |
2421 /* Set the list item */ | |
2422 list = scheme_make_pair(str, list); | |
1894 | 2423 MZ_GC_CHECK(); |
14 | 2424 } |
1894 | 2425 MZ_GC_UNREG(); |
14 | 2426 return list; |
2427 } | |
2428 | |
2429 /* | |
2430 * (set-buff-line {linenr} {string/#f} [buffer]) | |
2431 * | |
2432 * Replace a line in the specified buffer. The line number is | |
2433 * in Vim format (1-based). The replacement line is given as | |
2434 * an MzScheme string object. The object is checked for validity | |
2435 * and correct format. An exception is thrown if the values are not | |
2436 * the correct format. | |
2437 * | |
2438 * It returns a Scheme Object that indicates the length of the | |
2439 * string changed. | |
2440 */ | |
2441 static Scheme_Object * | |
2442 set_buffer_line(void *data, int argc, Scheme_Object **argv) | |
2443 { | |
2023 | 2444 /* First of all, we check the value of the supplied MzScheme object. |
14 | 2445 * There are three cases: |
2446 * 1. #f - this is a deletion. | |
2447 * 2. A string - this is a replacement. | |
2448 * 3. Anything else - this is an error. | |
2449 */ | |
2450 Vim_Prim *prim = (Vim_Prim *)data; | |
2451 vim_mz_buffer *buf; | |
1894 | 2452 Scheme_Object *line = NULL; |
14 | 2453 char *save; |
2454 int n; | |
2455 | |
1894 | 2456 MZ_GC_DECL_REG(1); |
2457 MZ_GC_VAR_IN_REG(0, line); | |
2458 MZ_GC_REG(); | |
2459 | |
274 | 2460 #ifdef HAVE_SANDBOX |
2461 sandbox_check(); | |
2462 #endif | |
14 | 2463 n = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); |
2464 if (!SCHEME_STRINGP(argv[1]) && !SCHEME_FALSEP(argv[1])) | |
856 | 2465 scheme_wrong_type(prim->name, "string or #f", 1, argc, argv); |
14 | 2466 line = argv[1]; |
2467 buf = get_buffer_arg(prim->name, 2, argc, argv); | |
2468 | |
2469 check_line_range(n, buf->buf); | |
2470 | |
2471 if (SCHEME_FALSEP(line)) | |
2472 { | |
1894 | 2473 buf_T *savebuf = curbuf; |
2474 | |
14 | 2475 curbuf = buf->buf; |
2476 | |
2477 if (u_savedel((linenr_T)n, 1L) == FAIL) | |
2478 { | |
2479 curbuf = savebuf; | |
2480 raise_vim_exn(_("cannot save undo information")); | |
2481 } | |
2482 else if (ml_delete((linenr_T)n, FALSE) == FAIL) | |
2483 { | |
2484 curbuf = savebuf; | |
2485 raise_vim_exn(_("cannot delete line")); | |
2486 } | |
2487 if (buf->buf == curwin->w_buffer) | |
2488 mz_fix_cursor(n, n + 1, -1); | |
1929 | 2489 deleted_lines_mark((linenr_T)n, 1L); |
14 | 2490 |
2491 curbuf = savebuf; | |
2492 | |
1894 | 2493 MZ_GC_UNREG(); |
14 | 2494 raise_if_error(); |
2495 return scheme_void; | |
2496 } | |
1894 | 2497 else |
14 | 2498 { |
1894 | 2499 /* Otherwise it's a line */ |
2500 buf_T *savebuf = curbuf; | |
2501 | |
2502 save = string_to_line(line); | |
2503 | |
2504 curbuf = buf->buf; | |
2505 | |
2506 if (u_savesub((linenr_T)n) == FAIL) | |
2507 { | |
2508 curbuf = savebuf; | |
2509 vim_free(save); | |
2510 raise_vim_exn(_("cannot save undo information")); | |
2511 } | |
2512 else if (ml_replace((linenr_T)n, (char_u *)save, TRUE) == FAIL) | |
2513 { | |
2514 curbuf = savebuf; | |
2515 vim_free(save); | |
2516 raise_vim_exn(_("cannot replace line")); | |
2517 } | |
2518 else | |
2519 { | |
2520 vim_free(save); | |
2521 changed_bytes((linenr_T)n, 0); | |
2522 } | |
2523 | |
14 | 2524 curbuf = savebuf; |
1894 | 2525 |
2526 /* Check that the cursor is not beyond the end of the line now. */ | |
2527 if (buf->buf == curwin->w_buffer) | |
2528 check_cursor_col(); | |
2529 | |
2530 MZ_GC_UNREG(); | |
2531 raise_if_error(); | |
2532 return scheme_void; | |
14 | 2533 } |
1894 | 2534 } |
2535 | |
2536 static void | |
2537 free_array(char **array) | |
2538 { | |
2539 char **curr = array; | |
2540 while (*curr != NULL) | |
2541 vim_free(*curr++); | |
2542 vim_free(array); | |
14 | 2543 } |
2544 | |
2545 /* | |
2546 * (set-buff-line-list {start} {end} {string-list/#f/null} [buffer]) | |
2547 * | |
2548 * Replace a range of lines in the specified buffer. The line numbers are in | |
2549 * Vim format (1-based). The range is from lo up to, but not including, hi. | |
2550 * The replacement lines are given as a Scheme list of string objects. The | |
2551 * list is checked for validity and correct format. | |
2552 * | |
2553 * Errors are returned as a value of FAIL. The return value is OK on success. | |
2554 * If OK is returned and len_change is not NULL, *len_change is set to the | |
2555 * change in the buffer length. | |
2556 */ | |
2557 static Scheme_Object * | |
2558 set_buffer_line_list(void *data, int argc, Scheme_Object **argv) | |
2559 { | |
2560 /* First of all, we check the type of the supplied MzScheme object. | |
2561 * There are three cases: | |
2562 * 1. #f - this is a deletion. | |
2563 * 2. A list - this is a replacement. | |
2564 * 3. Anything else - this is an error. | |
2565 */ | |
2566 Vim_Prim *prim = (Vim_Prim *)data; | |
1894 | 2567 vim_mz_buffer *buf = NULL; |
2568 Scheme_Object *line_list = NULL; | |
14 | 2569 int i, old_len, new_len, hi, lo; |
2570 long extra; | |
2571 | |
1894 | 2572 MZ_GC_DECL_REG(1); |
2573 MZ_GC_VAR_IN_REG(0, line_list); | |
2574 MZ_GC_REG(); | |
2575 | |
274 | 2576 #ifdef HAVE_SANDBOX |
2577 sandbox_check(); | |
2578 #endif | |
14 | 2579 lo = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); |
2580 hi = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 1)); | |
2581 if (!SCHEME_PAIRP(argv[2]) | |
2582 && !SCHEME_FALSEP(argv[2]) && !SCHEME_NULLP(argv[2])) | |
2583 scheme_wrong_type(prim->name, "list or #f", 2, argc, argv); | |
2584 line_list = argv[2]; | |
2585 buf = get_buffer_arg(prim->name, 3, argc, argv); | |
2586 old_len = hi - lo; | |
2587 if (old_len < 0) /* process inverse values wisely */ | |
2588 { | |
2589 i = lo; | |
2590 lo = hi; | |
2591 hi = i; | |
2592 old_len = -old_len; | |
2593 } | |
2594 extra = 0; | |
2595 | |
2596 check_line_range(lo, buf->buf); /* inclusive */ | |
1228 | 2597 check_line_range(hi - 1, buf->buf); /* exclusive */ |
14 | 2598 |
2599 if (SCHEME_FALSEP(line_list) || SCHEME_NULLP(line_list)) | |
2600 { | |
1894 | 2601 buf_T *savebuf = curbuf; |
14 | 2602 curbuf = buf->buf; |
2603 | |
2604 if (u_savedel((linenr_T)lo, (long)old_len) == FAIL) | |
2605 { | |
2606 curbuf = savebuf; | |
2607 raise_vim_exn(_("cannot save undo information")); | |
2608 } | |
2609 else | |
2610 { | |
2611 for (i = 0; i < old_len; i++) | |
2612 if (ml_delete((linenr_T)lo, FALSE) == FAIL) | |
2613 { | |
2614 curbuf = savebuf; | |
2615 raise_vim_exn(_("cannot delete line")); | |
2616 } | |
2617 if (buf->buf == curwin->w_buffer) | |
2618 mz_fix_cursor(lo, hi, -old_len); | |
1929 | 2619 deleted_lines_mark((linenr_T)lo, (long)old_len); |
14 | 2620 } |
2621 | |
2622 curbuf = savebuf; | |
2623 | |
1894 | 2624 MZ_GC_UNREG(); |
14 | 2625 raise_if_error(); |
2626 return scheme_void; | |
2627 } | |
1894 | 2628 else |
14 | 2629 { |
1894 | 2630 buf_T *savebuf = curbuf; |
2631 | |
2632 /* List */ | |
2633 new_len = scheme_proper_list_length(line_list); | |
2634 MZ_GC_CHECK(); | |
2635 if (new_len < 0) /* improper or cyclic list */ | |
2636 scheme_wrong_type(prim->name, "proper list", | |
2637 2, argc, argv); | |
2638 else | |
14 | 2639 { |
1894 | 2640 char **array = NULL; |
2641 Scheme_Object *line = NULL; | |
2642 Scheme_Object *rest = NULL; | |
2643 | |
2644 MZ_GC_DECL_REG(2); | |
2645 MZ_GC_VAR_IN_REG(0, line); | |
2646 MZ_GC_VAR_IN_REG(1, rest); | |
2647 MZ_GC_REG(); | |
2648 | |
4074 | 2649 array = (char **)alloc((new_len+1)* sizeof(char *)); |
2650 vim_memset(array, 0, (new_len+1) * sizeof(char *)); | |
1894 | 2651 |
2652 rest = line_list; | |
2653 for (i = 0; i < new_len; ++i) | |
2654 { | |
2655 line = SCHEME_CAR(rest); | |
2656 rest = SCHEME_CDR(rest); | |
2657 if (!SCHEME_STRINGP(line)) | |
2658 { | |
2659 free_array(array); | |
2660 scheme_wrong_type(prim->name, "string-list", 2, argc, argv); | |
2661 } | |
2662 array[i] = string_to_line(line); | |
2663 } | |
2664 | |
2665 curbuf = buf->buf; | |
2666 | |
2667 if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL) | |
2668 { | |
2669 curbuf = savebuf; | |
2670 free_array(array); | |
2671 raise_vim_exn(_("cannot save undo information")); | |
2672 } | |
2673 | |
2674 /* | |
2675 * If the size of the range is reducing (ie, new_len < old_len) we | |
2676 * need to delete some old_len. We do this at the start, by | |
2677 * repeatedly deleting line "lo". | |
2678 */ | |
2679 for (i = 0; i < old_len - new_len; ++i) | |
2680 { | |
2681 if (ml_delete((linenr_T)lo, FALSE) == FAIL) | |
2682 { | |
2683 curbuf = savebuf; | |
2684 free_array(array); | |
2685 raise_vim_exn(_("cannot delete line")); | |
2686 } | |
2687 extra--; | |
2688 } | |
2689 | |
2690 /* | |
2691 * For as long as possible, replace the existing old_len with the | |
2692 * new old_len. This is a more efficient operation, as it requires | |
2693 * less memory allocation and freeing. | |
2694 */ | |
2695 for (i = 0; i < old_len && i < new_len; i++) | |
2696 if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], TRUE) == FAIL) | |
2697 { | |
2698 curbuf = savebuf; | |
2699 free_array(array); | |
2700 raise_vim_exn(_("cannot replace line")); | |
2701 } | |
2702 | |
2703 /* | |
2704 * Now we may need to insert the remaining new_len. We don't need to | |
2705 * free the string passed back because MzScheme has control of that | |
2706 * memory. | |
2707 */ | |
2708 while (i < new_len) | |
2709 { | |
2710 if (ml_append((linenr_T)(lo + i - 1), | |
2711 (char_u *)array[i], 0, FALSE) == FAIL) | |
2712 { | |
2713 curbuf = savebuf; | |
2714 free_array(array); | |
2715 raise_vim_exn(_("cannot insert line")); | |
2716 } | |
2717 ++i; | |
2718 ++extra; | |
2719 } | |
2720 MZ_GC_UNREG(); | |
2721 free_array(array); | |
14 | 2722 } |
1894 | 2723 |
2724 /* | |
2725 * Adjust marks. Invalidate any which lie in the | |
2726 * changed range, and move any in the remainder of the buffer. | |
2727 */ | |
9228
ea504064c996
commit https://github.com/vim/vim/commit/fd89d7ea81b18d32363456b16258174dc9e095dc
Christian Brabandt <cb@256bit.org>
parents:
9173
diff
changeset
|
2728 mark_adjust((linenr_T)lo, (linenr_T)(hi - 1), |
ea504064c996
commit https://github.com/vim/vim/commit/fd89d7ea81b18d32363456b16258174dc9e095dc
Christian Brabandt <cb@256bit.org>
parents:
9173
diff
changeset
|
2729 (long)MAXLNUM, (long)extra); |
1894 | 2730 changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra); |
2731 | |
2732 if (buf->buf == curwin->w_buffer) | |
2733 mz_fix_cursor(lo, hi, extra); | |
2734 curbuf = savebuf; | |
2735 | |
2736 MZ_GC_UNREG(); | |
2737 raise_if_error(); | |
2738 return scheme_void; | |
14 | 2739 } |
2740 } | |
2741 | |
2742 /* | |
2743 * (insert-buff-line-list {linenr} {string/string-list} [buffer]) | |
2744 * | |
2023 | 2745 * Insert a number of lines into the specified buffer after the specified line. |
14 | 2746 * The line number is in Vim format (1-based). The lines to be inserted are |
2747 * given as an MzScheme list of string objects or as a single string. The lines | |
2748 * to be added are checked for validity and correct format. Errors are | |
2749 * returned as a value of FAIL. The return value is OK on success. | |
2750 * If OK is returned and len_change is not NULL, *len_change | |
2751 * is set to the change in the buffer length. | |
2752 */ | |
2753 static Scheme_Object * | |
2754 insert_buffer_line_list(void *data, int argc, Scheme_Object **argv) | |
2755 { | |
2756 Vim_Prim *prim = (Vim_Prim *)data; | |
1894 | 2757 vim_mz_buffer *buf = NULL; |
2758 Scheme_Object *list = NULL; | |
2759 char *str = NULL; | |
14 | 2760 int i, n, size; |
2761 | |
1894 | 2762 MZ_GC_DECL_REG(1); |
2763 MZ_GC_VAR_IN_REG(0, list); | |
2764 MZ_GC_REG(); | |
2765 | |
274 | 2766 #ifdef HAVE_SANDBOX |
2767 sandbox_check(); | |
2768 #endif | |
14 | 2769 /* |
2770 * First of all, we check the type of the supplied MzScheme object. | |
2771 * It must be a string or a list, or the call is in error. | |
2772 */ | |
2773 n = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
2774 list = argv[1]; | |
2775 | |
2776 if (!SCHEME_STRINGP(list) && !SCHEME_PAIRP(list)) | |
2777 scheme_wrong_type(prim->name, "string or list", 1, argc, argv); | |
2778 buf = get_buffer_arg(prim->name, 2, argc, argv); | |
2779 | |
2780 if (n != 0) /* 0 can be used in insert */ | |
856 | 2781 check_line_range(n, buf->buf); |
14 | 2782 if (SCHEME_STRINGP(list)) |
2783 { | |
1894 | 2784 buf_T *savebuf = curbuf; |
2785 | |
14 | 2786 str = string_to_line(list); |
2787 curbuf = buf->buf; | |
2788 | |
2789 if (u_save((linenr_T)n, (linenr_T)(n+1)) == FAIL) | |
2790 { | |
2791 curbuf = savebuf; | |
1894 | 2792 vim_free(str); |
14 | 2793 raise_vim_exn(_("cannot save undo information")); |
2794 } | |
2795 else if (ml_append((linenr_T)n, (char_u *)str, 0, FALSE) == FAIL) | |
2796 { | |
2797 curbuf = savebuf; | |
1894 | 2798 vim_free(str); |
14 | 2799 raise_vim_exn(_("cannot insert line")); |
2800 } | |
2801 else | |
1894 | 2802 { |
2803 vim_free(str); | |
14 | 2804 appended_lines_mark((linenr_T)n, 1L); |
1894 | 2805 } |
14 | 2806 |
2807 curbuf = savebuf; | |
2808 update_screen(VALID); | |
2809 | |
1894 | 2810 MZ_GC_UNREG(); |
14 | 2811 raise_if_error(); |
2812 return scheme_void; | |
2813 } | |
2814 | |
2815 /* List */ | |
2816 size = scheme_proper_list_length(list); | |
1894 | 2817 MZ_GC_CHECK(); |
14 | 2818 if (size < 0) /* improper or cyclic list */ |
2819 scheme_wrong_type(prim->name, "proper list", | |
2820 2, argc, argv); | |
2821 else | |
2822 { | |
1894 | 2823 Scheme_Object *line = NULL; |
2824 Scheme_Object *rest = NULL; | |
2825 char **array; | |
2826 buf_T *savebuf = curbuf; | |
2827 | |
2828 MZ_GC_DECL_REG(2); | |
2829 MZ_GC_VAR_IN_REG(0, line); | |
2830 MZ_GC_VAR_IN_REG(1, rest); | |
2831 MZ_GC_REG(); | |
2832 | |
4074 | 2833 array = (char **)alloc((size+1) * sizeof(char *)); |
2834 vim_memset(array, 0, (size+1) * sizeof(char *)); | |
1894 | 2835 |
2836 rest = list; | |
856 | 2837 for (i = 0; i < size; ++i) |
1894 | 2838 { |
2839 line = SCHEME_CAR(rest); | |
2840 rest = SCHEME_CDR(rest); | |
2841 array[i] = string_to_line(line); | |
2842 } | |
2843 | |
2844 curbuf = buf->buf; | |
2845 | |
2846 if (u_save((linenr_T)n, (linenr_T)(n + 1)) == FAIL) | |
2847 { | |
2848 curbuf = savebuf; | |
2849 free_array(array); | |
2850 raise_vim_exn(_("cannot save undo information")); | |
2851 } | |
2852 else | |
2853 { | |
2854 for (i = 0; i < size; ++i) | |
2855 if (ml_append((linenr_T)(n + i), (char_u *)array[i], | |
2856 0, FALSE) == FAIL) | |
2857 { | |
2858 curbuf = savebuf; | |
2859 free_array(array); | |
2860 raise_vim_exn(_("cannot insert line")); | |
2861 } | |
2862 | |
2863 if (i > 0) | |
2864 appended_lines_mark((linenr_T)n, (long)i); | |
2865 } | |
2866 free_array(array); | |
2867 MZ_GC_UNREG(); | |
2868 curbuf = savebuf; | |
2869 update_screen(VALID); | |
14 | 2870 } |
2871 | |
1894 | 2872 MZ_GC_UNREG(); |
14 | 2873 raise_if_error(); |
2874 return scheme_void; | |
2875 } | |
2876 | |
2877 /* | |
2878 * Predicates | |
2879 */ | |
2880 /* (buff? obj) */ | |
2881 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
2882 vim_bufferp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) |
14 | 2883 { |
2884 if (SCHEME_VIMBUFFERP(argv[0])) | |
2885 return scheme_true; | |
2886 else | |
2887 return scheme_false; | |
2888 } | |
2889 | |
2890 /* (win? obj) */ | |
2891 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
2892 vim_windowp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) |
14 | 2893 { |
2894 if (SCHEME_VIMWINDOWP(argv[0])) | |
2895 return scheme_true; | |
2896 else | |
2897 return scheme_false; | |
2898 } | |
2899 | |
2900 /* (buff-valid? obj) */ | |
2901 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
2902 vim_buffer_validp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) |
14 | 2903 { |
2904 if (SCHEME_VIMBUFFERP(argv[0]) | |
2905 && ((vim_mz_buffer *)argv[0])->buf != INVALID_BUFFER_VALUE) | |
2906 return scheme_true; | |
2907 else | |
2908 return scheme_false; | |
2909 } | |
2910 | |
2911 /* (win-valid? obj) */ | |
2912 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
2913 vim_window_validp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) |
14 | 2914 { |
2915 if (SCHEME_VIMWINDOWP(argv[0]) | |
2916 && ((vim_mz_window *)argv[0])->win != INVALID_WINDOW_VALUE) | |
2917 return scheme_true; | |
2918 else | |
2919 return scheme_false; | |
2920 } | |
2921 | |
2922 /* | |
2923 *=========================================================================== | |
2924 * Utilities | |
2925 *=========================================================================== | |
2926 */ | |
2927 | |
2928 /* | |
2929 * Convert an MzScheme string into a Vim line. | |
2930 * | |
1894 | 2931 * All internal nulls are replaced by newline characters. |
2932 * It is an error for the string to contain newline characters. | |
14 | 2933 * |
1894 | 2934 * Returns pointer to Vim allocated memory |
14 | 2935 */ |
2936 static char * | |
2937 string_to_line(Scheme_Object *obj) | |
2938 { | |
1894 | 2939 char *scheme_str = NULL; |
2940 char *vim_str = NULL; | |
4074 | 2941 OUTPUT_LEN_TYPE len; |
14 | 2942 int i; |
2943 | |
1894 | 2944 scheme_str = scheme_display_to_string(obj, &len); |
14 | 2945 |
2946 /* Error checking: String must not contain newlines, as we | |
2947 * are replacing a single line, and we must replace it with | |
2948 * a single line. | |
2949 */ | |
4074 | 2950 if (memchr(scheme_str, '\n', len)) |
14 | 2951 scheme_signal_error(_("string cannot contain newlines")); |
2952 | |
4074 | 2953 vim_str = (char *)alloc(len + 1); |
1894 | 2954 |
14 | 2955 /* Create a copy of the string, with internal nulls replaced by |
2956 * newline characters, as is the vim convention. | |
2957 */ | |
2958 for (i = 0; i < len; ++i) | |
2959 { | |
1894 | 2960 if (scheme_str[i] == '\0') |
2961 vim_str[i] = '\n'; | |
2962 else | |
2963 vim_str[i] = scheme_str[i]; | |
2964 } | |
2965 | |
2966 vim_str[i] = '\0'; | |
2967 | |
2968 MZ_GC_CHECK(); | |
2969 return vim_str; | |
2970 } | |
2971 | |
2972 #ifdef FEAT_EVAL | |
2973 /* | |
2974 * Convert Vim value into MzScheme, adopted from if_python.c | |
2975 */ | |
2976 static Scheme_Object * | |
4074 | 2977 vim_to_mzscheme(typval_T *vim_value) |
2978 { | |
2979 Scheme_Object *result = NULL; | |
2980 /* hash table to store visited values to avoid infinite loops */ | |
2981 Scheme_Hash_Table *visited = NULL; | |
2982 | |
2983 MZ_GC_DECL_REG(2); | |
2984 MZ_GC_VAR_IN_REG(0, result); | |
2985 MZ_GC_VAR_IN_REG(1, visited); | |
2986 MZ_GC_REG(); | |
2987 | |
2988 visited = scheme_make_hash_table(SCHEME_hash_ptr); | |
2989 MZ_GC_CHECK(); | |
2990 | |
2991 result = vim_to_mzscheme_impl(vim_value, 1, visited); | |
2992 | |
2993 MZ_GC_UNREG(); | |
2994 return result; | |
2995 } | |
2996 | |
2997 static Scheme_Object * | |
2998 vim_to_mzscheme_impl(typval_T *vim_value, int depth, Scheme_Hash_Table *visited) | |
1894 | 2999 { |
3000 Scheme_Object *result = NULL; | |
3001 int new_value = TRUE; | |
3002 | |
4074 | 3003 MZ_GC_DECL_REG(2); |
1894 | 3004 MZ_GC_VAR_IN_REG(0, result); |
4074 | 3005 MZ_GC_VAR_IN_REG(1, visited); |
1894 | 3006 MZ_GC_REG(); |
3007 | |
3008 /* Avoid infinite recursion */ | |
3009 if (depth > 100) | |
3010 { | |
3011 MZ_GC_UNREG(); | |
3012 return scheme_void; | |
3013 } | |
3014 | |
3015 /* Check if we run into a recursive loop. The item must be in visited | |
3016 * then and we can use it again. | |
3017 */ | |
3018 result = scheme_hash_get(visited, (Scheme_Object *)vim_value); | |
3019 MZ_GC_CHECK(); | |
3020 if (result != NULL) /* found, do nothing */ | |
3021 new_value = FALSE; | |
3022 else if (vim_value->v_type == VAR_STRING) | |
3023 { | |
4074 | 3024 result = scheme_make_byte_string((char *)vim_value->vval.v_string); |
1894 | 3025 MZ_GC_CHECK(); |
3026 } | |
3027 else if (vim_value->v_type == VAR_NUMBER) | |
3028 { | |
3029 result = scheme_make_integer((long)vim_value->vval.v_number); | |
3030 MZ_GC_CHECK(); | |
3031 } | |
3032 # ifdef FEAT_FLOAT | |
3033 else if (vim_value->v_type == VAR_FLOAT) | |
3034 { | |
3035 result = scheme_make_double((double)vim_value->vval.v_float); | |
3036 MZ_GC_CHECK(); | |
14 | 3037 } |
1894 | 3038 # endif |
3039 else if (vim_value->v_type == VAR_LIST) | |
3040 { | |
3041 list_T *list = vim_value->vval.v_list; | |
3042 listitem_T *curr; | |
3043 | |
3044 if (list == NULL || list->lv_first == NULL) | |
3045 result = scheme_null; | |
3046 else | |
3047 { | |
3048 Scheme_Object *obj = NULL; | |
3049 | |
3050 MZ_GC_DECL_REG(1); | |
3051 MZ_GC_VAR_IN_REG(0, obj); | |
3052 MZ_GC_REG(); | |
3053 | |
3054 curr = list->lv_last; | |
4074 | 3055 obj = vim_to_mzscheme_impl(&curr->li_tv, depth + 1, visited); |
1894 | 3056 result = scheme_make_pair(obj, scheme_null); |
3057 MZ_GC_CHECK(); | |
3058 | |
3059 while (curr != list->lv_first) | |
3060 { | |
3061 curr = curr->li_prev; | |
4074 | 3062 obj = vim_to_mzscheme_impl(&curr->li_tv, depth + 1, visited); |
1894 | 3063 result = scheme_make_pair(obj, result); |
3064 MZ_GC_CHECK(); | |
3065 } | |
3066 } | |
3067 MZ_GC_UNREG(); | |
3068 } | |
3069 else if (vim_value->v_type == VAR_DICT) | |
3070 { | |
3071 Scheme_Object *key = NULL; | |
3072 Scheme_Object *obj = NULL; | |
3073 | |
3074 MZ_GC_DECL_REG(2); | |
3075 MZ_GC_VAR_IN_REG(0, key); | |
3076 MZ_GC_VAR_IN_REG(1, obj); | |
3077 MZ_GC_REG(); | |
3078 | |
3079 result = (Scheme_Object *)scheme_make_hash_table(SCHEME_hash_ptr); | |
3080 MZ_GC_CHECK(); | |
3081 if (vim_value->vval.v_dict != NULL) | |
3082 { | |
3083 hashtab_T *ht = &vim_value->vval.v_dict->dv_hashtab; | |
3084 long_u todo = ht->ht_used; | |
3085 hashitem_T *hi; | |
3086 dictitem_T *di; | |
3087 | |
3088 for (hi = ht->ht_array; todo > 0; ++hi) | |
3089 { | |
3090 if (!HASHITEM_EMPTY(hi)) | |
3091 { | |
3092 --todo; | |
3093 | |
3094 di = dict_lookup(hi); | |
4074 | 3095 obj = vim_to_mzscheme_impl(&di->di_tv, depth + 1, visited); |
3096 key = scheme_make_byte_string((char *)hi->hi_key); | |
1894 | 3097 MZ_GC_CHECK(); |
3098 scheme_hash_set((Scheme_Hash_Table *)result, key, obj); | |
3099 MZ_GC_CHECK(); | |
3100 } | |
3101 } | |
3102 } | |
3103 MZ_GC_UNREG(); | |
3104 } | |
4074 | 3105 else if (vim_value->v_type == VAR_FUNC) |
3106 { | |
3107 Scheme_Object *funcname = NULL; | |
3108 | |
3109 MZ_GC_DECL_REG(1); | |
3110 MZ_GC_VAR_IN_REG(0, funcname); | |
3111 MZ_GC_REG(); | |
3112 | |
8800
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3113 /* FIXME: func_ref() and func_unref() are needed. */ |
4074 | 3114 funcname = scheme_make_byte_string((char *)vim_value->vval.v_string); |
3115 MZ_GC_CHECK(); | |
3116 result = scheme_make_closed_prim_w_arity(vim_funcref, funcname, | |
3117 (const char *)BYTE_STRING_VALUE(funcname), 0, -1); | |
3118 MZ_GC_CHECK(); | |
3119 | |
3120 MZ_GC_UNREG(); | |
3121 } | |
8800
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3122 else if (vim_value->v_type == VAR_PARTIAL) |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3123 { |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3124 if (vim_value->vval.v_partial == NULL) |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3125 result = scheme_null; |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3126 else |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3127 { |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3128 Scheme_Object *funcname = NULL; |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3129 |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3130 MZ_GC_DECL_REG(1); |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3131 MZ_GC_VAR_IN_REG(0, funcname); |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3132 MZ_GC_REG(); |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3133 |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3134 /* FIXME: func_ref() and func_unref() are needed. */ |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3135 /* TODO: Support pt_dict and pt_argv. */ |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3136 funcname = scheme_make_byte_string( |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3137 (char *)vim_value->vval.v_partial->pt_name); |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3138 MZ_GC_CHECK(); |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3139 result = scheme_make_closed_prim_w_arity(vim_funcref, funcname, |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3140 (const char *)BYTE_STRING_VALUE(funcname), 0, -1); |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3141 MZ_GC_CHECK(); |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3142 |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3143 MZ_GC_UNREG(); |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3144 } |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3145 } |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7609
diff
changeset
|
3146 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
|
3147 { |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7609
diff
changeset
|
3148 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
|
3149 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
|
3150 else |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7609
diff
changeset
|
3151 result = scheme_null; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7609
diff
changeset
|
3152 MZ_GC_CHECK(); |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7609
diff
changeset
|
3153 } |
1894 | 3154 else |
3155 { | |
3156 result = scheme_void; | |
3157 new_value = FALSE; | |
3158 } | |
3159 if (new_value) | |
3160 { | |
3161 scheme_hash_set(visited, (Scheme_Object *)vim_value, result); | |
3162 MZ_GC_CHECK(); | |
3163 } | |
3164 MZ_GC_UNREG(); | |
3165 return result; | |
14 | 3166 } |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3167 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3168 static int |
4074 | 3169 mzscheme_to_vim(Scheme_Object *obj, typval_T *tv) |
3170 { | |
3171 int i, status; | |
3172 Scheme_Hash_Table *visited = NULL; | |
3173 | |
3174 MZ_GC_DECL_REG(2); | |
3175 MZ_GC_VAR_IN_REG(0, obj); | |
3176 MZ_GC_VAR_IN_REG(1, visited); | |
3177 MZ_GC_REG(); | |
3178 | |
3179 visited = scheme_make_hash_table(SCHEME_hash_ptr); | |
3180 MZ_GC_CHECK(); | |
3181 | |
3182 status = mzscheme_to_vim_impl(obj, tv, 1, visited); | |
3183 for (i = 0; i < visited->size; ++i) | |
3184 { | |
3185 /* free up remembered objects */ | |
3186 if (visited->vals[i] != NULL) | |
3187 free_tv((typval_T *)visited->vals[i]); | |
3188 } | |
3189 | |
3190 MZ_GC_UNREG(); | |
3191 return status; | |
3192 } | |
3193 static int | |
3194 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
|
3195 Scheme_Hash_Table *visited) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3196 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3197 int status = OK; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3198 typval_T *found; |
4074 | 3199 |
3200 MZ_GC_DECL_REG(2); | |
3201 MZ_GC_VAR_IN_REG(0, obj); | |
3202 MZ_GC_VAR_IN_REG(1, visited); | |
3203 MZ_GC_REG(); | |
3204 | |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3205 MZ_GC_CHECK(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3206 if (depth > 100) /* limit the deepest recursion level */ |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3207 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3208 tv->v_type = VAR_NUMBER; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3209 tv->vval.v_number = 0; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3210 return FAIL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3211 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3212 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3213 found = (typval_T *)scheme_hash_get(visited, obj); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3214 if (found != NULL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3215 copy_tv(found, tv); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3216 else if (SCHEME_VOIDP(obj)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3217 { |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7609
diff
changeset
|
3218 tv->v_type = VAR_SPECIAL; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7609
diff
changeset
|
3219 tv->vval.v_number = VVAL_NULL; |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3220 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3221 else if (SCHEME_INTP(obj)) |
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 tv->v_type = VAR_NUMBER; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3224 tv->vval.v_number = SCHEME_INT_VAL(obj); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3225 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3226 else if (SCHEME_BOOLP(obj)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3227 { |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7609
diff
changeset
|
3228 tv->v_type = VAR_SPECIAL; |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3229 tv->vval.v_number = SCHEME_TRUEP(obj); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3230 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3231 # ifdef FEAT_FLOAT |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3232 else if (SCHEME_DBLP(obj)) |
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_FLOAT; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3235 tv->vval.v_float = SCHEME_DBL_VAL(obj); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3236 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3237 # endif |
4074 | 3238 else if (SCHEME_BYTE_STRINGP(obj)) |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3239 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3240 tv->v_type = VAR_STRING; |
4074 | 3241 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
|
3242 } |
4074 | 3243 # if MZSCHEME_VERSION_MAJOR >= 299 |
3244 else if (SCHEME_CHAR_STRINGP(obj)) | |
3245 { | |
3246 Scheme_Object *tmp = NULL; | |
3247 MZ_GC_DECL_REG(1); | |
3248 MZ_GC_VAR_IN_REG(0, tmp); | |
3249 MZ_GC_REG(); | |
3250 | |
3251 tmp = scheme_char_string_to_byte_string(obj); | |
3252 tv->v_type = VAR_STRING; | |
3253 tv->vval.v_string = vim_strsave(BYTE_STRING_VALUE(tmp)); | |
3254 MZ_GC_UNREG(); | |
3255 } | |
3256 #endif | |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3257 else if (SCHEME_VECTORP(obj) || SCHEME_NULLP(obj) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3258 || SCHEME_PAIRP(obj) || SCHEME_MUTABLE_PAIRP(obj)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3259 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3260 list_T *list = list_alloc(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3261 if (list == NULL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3262 status = FAIL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3263 else |
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 int i; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3266 Scheme_Object *curr = NULL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3267 Scheme_Object *cval = NULL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3268 /* 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
|
3269 typval_T *v; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3270 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3271 MZ_GC_DECL_REG(2); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3272 MZ_GC_VAR_IN_REG(0, curr); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3273 MZ_GC_VAR_IN_REG(1, cval); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3274 MZ_GC_REG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3275 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3276 tv->v_type = VAR_LIST; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3277 tv->vval.v_list = list; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3278 ++list->lv_refcount; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3279 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3280 v = (typval_T *)alloc(sizeof(typval_T)); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3281 if (v == NULL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3282 status = FAIL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3283 else |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3284 { |
4352 | 3285 /* 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
|
3286 * data structures */ |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3287 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
|
3288 copy_tv(tv, visited_tv); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3289 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
|
3290 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3291 if (SCHEME_VECTORP(obj)) |
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 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
|
3294 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3295 cval = SCHEME_VEC_ELS(obj)[i]; |
4074 | 3296 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
|
3297 if (status == FAIL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3298 break; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3299 status = list_append_tv(list, v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3300 clear_tv(v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3301 if (status == FAIL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3302 break; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3303 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3304 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3305 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
|
3306 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3307 for (curr = obj; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3308 SCHEME_PAIRP(curr) || SCHEME_MUTABLE_PAIRP(curr); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3309 curr = SCHEME_CDR(curr)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3310 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3311 cval = SCHEME_CAR(curr); |
4074 | 3312 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
|
3313 if (status == FAIL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3314 break; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3315 status = list_append_tv(list, v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3316 clear_tv(v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3317 if (status == FAIL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3318 break; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3319 } |
4352 | 3320 /* improper list not terminated with null |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3321 * need to handle the last element */ |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3322 if (status == OK && !SCHEME_NULLP(curr)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3323 { |
4074 | 3324 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
|
3325 if (status == OK) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3326 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3327 status = list_append_tv(list, v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3328 clear_tv(v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3329 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3330 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3331 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3332 /* nothing to do for scheme_null */ |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3333 vim_free(v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3334 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3335 MZ_GC_UNREG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3336 } |
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 else if (SCHEME_HASHTP(obj)) |
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 int i; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3341 dict_T *dict; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3342 Scheme_Object *key = NULL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3343 Scheme_Object *val = NULL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3344 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3345 MZ_GC_DECL_REG(2); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3346 MZ_GC_VAR_IN_REG(0, key); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3347 MZ_GC_VAR_IN_REG(1, val); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3348 MZ_GC_REG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3349 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3350 dict = dict_alloc(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3351 if (dict == NULL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3352 status = FAIL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3353 else |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3354 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3355 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
|
3356 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3357 tv->v_type = VAR_DICT; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3358 tv->vval.v_dict = dict; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3359 ++dict->dv_refcount; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3360 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3361 copy_tv(tv, visited_tv); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3362 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
|
3363 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3364 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
|
3365 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3366 if (((Scheme_Hash_Table *) obj)->vals[i] != NULL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3367 { |
4352 | 3368 /* generate item for `display'ed Scheme key */ |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3369 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
|
3370 ((Scheme_Hash_Table *) obj)->keys[i])); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3371 /* convert Scheme val to Vim and add it to the dict */ |
4074 | 3372 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
|
3373 &item->di_tv, depth + 1, visited) == FAIL |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3374 || dict_add(dict, item) == FAIL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3375 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3376 dictitem_free(item); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3377 status = FAIL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3378 break; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3379 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3380 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3381 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3382 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3383 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3384 MZ_GC_UNREG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3385 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3386 else |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3387 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3388 /* `display' any other value to string */ |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3389 tv->v_type = VAR_STRING; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3390 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
|
3391 } |
4074 | 3392 MZ_GC_UNREG(); |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3393 return status; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3394 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3395 |
4074 | 3396 /* Scheme prim procedure wrapping Vim funcref */ |
3397 static Scheme_Object * | |
3398 vim_funcref(void *name, int argc, Scheme_Object **argv) | |
3399 { | |
3400 int i; | |
3401 typval_T args; | |
3402 int status = OK; | |
3403 Scheme_Object *result = NULL; | |
3404 list_T *list = list_alloc(); | |
3405 | |
3406 MZ_GC_DECL_REG(1); | |
3407 MZ_GC_VAR_IN_REG(0, result); | |
3408 MZ_GC_REG(); | |
3409 | |
3410 result = scheme_void; | |
3411 if (list == NULL) | |
3412 status = FAIL; | |
3413 else | |
3414 { | |
3415 args.v_type = VAR_LIST; | |
3416 args.vval.v_list = list; | |
3417 ++list->lv_refcount; | |
3418 for (i = 0; status == OK && i < argc; ++i) | |
3419 { | |
3420 typval_T *v = (typval_T *)alloc(sizeof(typval_T)); | |
3421 if (v == NULL) | |
3422 status = FAIL; | |
3423 else | |
3424 { | |
3425 status = mzscheme_to_vim(argv[i], v); | |
3426 if (status == OK) | |
3427 { | |
3428 status = list_append_tv(list, v); | |
3429 clear_tv(v); | |
3430 } | |
3431 vim_free(v); | |
3432 } | |
3433 } | |
3434 if (status == OK) | |
3435 { | |
3436 typval_T ret; | |
3437 ret.v_type = VAR_UNKNOWN; | |
3438 | |
3439 mzscheme_call_vim(BYTE_STRING_VALUE((Scheme_Object *)name), &args, &ret); | |
3440 MZ_GC_CHECK(); | |
3441 result = vim_to_mzscheme(&ret); | |
3442 clear_tv(&ret); | |
3443 MZ_GC_CHECK(); | |
3444 } | |
3445 } | |
3446 clear_tv(&args); | |
3447 MZ_GC_UNREG(); | |
3448 if (status != OK) | |
3449 raise_vim_exn(_("error converting Scheme values to Vim")); | |
3450 else | |
3451 raise_if_error(); | |
3452 return result; | |
3453 } | |
3454 | |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3455 void |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3456 do_mzeval(char_u *str, typval_T *rettv) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3457 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3458 Scheme_Object *ret = NULL; |
4074 | 3459 |
3460 MZ_GC_DECL_REG(1); | |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3461 MZ_GC_VAR_IN_REG(0, ret); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3462 MZ_GC_REG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3463 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3464 if (mzscheme_init()) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3465 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3466 MZ_GC_UNREG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3467 return; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3468 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3469 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3470 MZ_GC_CHECK(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3471 if (eval_with_exn_handling(str, do_eval, &ret) == OK) |
4074 | 3472 mzscheme_to_vim(ret, rettv); |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3473 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3474 MZ_GC_UNREG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3475 } |
1894 | 3476 #endif |
14 | 3477 |
3478 /* | |
3479 * Check to see whether a Vim error has been reported, or a keyboard | |
3480 * interrupt (from vim --> got_int) has been detected. | |
3481 */ | |
3482 static int | |
3483 vim_error_check(void) | |
3484 { | |
3485 return (got_int || did_emsg); | |
3486 } | |
3487 | |
3488 /* | |
3489 * register Scheme exn:vim | |
3490 */ | |
3491 static void | |
1894 | 3492 register_vim_exn(void) |
14 | 3493 { |
1894 | 3494 int nc = 0; |
3495 int i; | |
3496 Scheme_Object *struct_exn = NULL; | |
3497 Scheme_Object *exn_name = NULL; | |
3498 | |
3499 MZ_GC_DECL_REG(2); | |
3500 MZ_GC_VAR_IN_REG(0, struct_exn); | |
3501 MZ_GC_VAR_IN_REG(1, exn_name); | |
3502 MZ_GC_REG(); | |
3503 | |
3504 exn_name = scheme_intern_symbol("exn:vim"); | |
3505 MZ_GC_CHECK(); | |
3506 struct_exn = scheme_builtin_value("struct:exn"); | |
3507 MZ_GC_CHECK(); | |
14 | 3508 |
3509 if (vim_exn == NULL) | |
3510 vim_exn = scheme_make_struct_type(exn_name, | |
1894 | 3511 struct_exn, NULL, 0, 0, NULL, NULL |
14 | 3512 #if MZSCHEME_VERSION_MAJOR >= 299 |
3513 , NULL | |
3514 #endif | |
3515 ); | |
3516 | |
1894 | 3517 |
14 | 3518 { |
1894 | 3519 Scheme_Object **tmp = NULL; |
3520 Scheme_Object *exn_names[5] = {NULL, NULL, NULL, NULL, NULL}; | |
3521 Scheme_Object *exn_values[5] = {NULL, NULL, NULL, NULL, NULL}; | |
3522 MZ_GC_DECL_REG(6); | |
3523 MZ_GC_ARRAY_VAR_IN_REG(0, exn_names, 5); | |
3524 MZ_GC_ARRAY_VAR_IN_REG(3, exn_values, 5); | |
3525 MZ_GC_REG(); | |
3526 | |
3527 tmp = scheme_make_struct_names(exn_name, scheme_null, 0, &nc); | |
3528 mch_memmove(exn_names, tmp, nc * sizeof(Scheme_Object *)); | |
3529 MZ_GC_CHECK(); | |
3530 | |
3531 tmp = scheme_make_struct_values(vim_exn, exn_names, nc, 0); | |
3532 mch_memmove(exn_values, tmp, nc * sizeof(Scheme_Object *)); | |
3533 MZ_GC_CHECK(); | |
3534 | |
3535 for (i = 0; i < nc; i++) | |
3536 { | |
3537 scheme_add_global_symbol(exn_names[i], | |
3538 exn_values[i], environment); | |
3539 MZ_GC_CHECK(); | |
3540 } | |
3541 MZ_GC_UNREG(); | |
14 | 3542 } |
1894 | 3543 MZ_GC_UNREG(); |
14 | 3544 } |
3545 | |
3546 /* | |
3547 * raise exn:vim, may be with additional info string | |
3548 */ | |
3549 void | |
3550 raise_vim_exn(const char *add_info) | |
3551 { | |
1894 | 3552 char *fmt = _("Vim error: ~a"); |
3553 Scheme_Object *argv[2] = {NULL, NULL}; | |
3554 Scheme_Object *exn = NULL; | |
4074 | 3555 Scheme_Object *byte_string = NULL; |
3556 | |
3557 MZ_GC_DECL_REG(5); | |
1894 | 3558 MZ_GC_ARRAY_VAR_IN_REG(0, argv, 2); |
3559 MZ_GC_VAR_IN_REG(3, exn); | |
4074 | 3560 MZ_GC_VAR_IN_REG(4, byte_string); |
1894 | 3561 MZ_GC_REG(); |
14 | 3562 |
3563 if (add_info != NULL) | |
3564 { | |
1894 | 3565 char *c_string = NULL; |
3566 Scheme_Object *info = NULL; | |
3567 | |
3568 MZ_GC_DECL_REG(3); | |
3569 MZ_GC_VAR_IN_REG(0, c_string); | |
3570 MZ_GC_VAR_IN_REG(2, info); | |
3571 MZ_GC_REG(); | |
3572 | |
4074 | 3573 info = scheme_make_byte_string(add_info); |
1894 | 3574 MZ_GC_CHECK(); |
9159
6b003ff07234
commit https://github.com/vim/vim/commit/9b0ac229bcfc91acabd35fc576055a94c1687c32
Christian Brabandt <cb@256bit.org>
parents:
8800
diff
changeset
|
3575 c_string = scheme_format_utf8(fmt, (int)STRLEN(fmt), 1, &info, NULL); |
1894 | 3576 MZ_GC_CHECK(); |
4074 | 3577 byte_string = scheme_make_byte_string(c_string); |
1894 | 3578 MZ_GC_CHECK(); |
3579 argv[0] = scheme_byte_string_to_char_string(byte_string); | |
274 | 3580 SCHEME_SET_IMMUTABLE(argv[0]); |
1894 | 3581 MZ_GC_UNREG(); |
14 | 3582 } |
3583 else | |
4074 | 3584 { |
3585 byte_string = scheme_make_byte_string(_("Vim error")); | |
3586 MZ_GC_CHECK(); | |
3587 argv[0] = scheme_byte_string_to_char_string(byte_string); | |
3588 MZ_GC_CHECK(); | |
3589 } | |
1894 | 3590 MZ_GC_CHECK(); |
14 | 3591 |
1284 | 3592 #if MZSCHEME_VERSION_MAJOR < 360 |
3593 argv[1] = scheme_current_continuation_marks(); | |
1894 | 3594 MZ_GC_CHECK(); |
1284 | 3595 #else |
1125 | 3596 argv[1] = scheme_current_continuation_marks(NULL); |
1894 | 3597 MZ_GC_CHECK(); |
1284 | 3598 #endif |
14 | 3599 |
1894 | 3600 exn = scheme_make_struct_instance(vim_exn, 2, argv); |
3601 MZ_GC_CHECK(); | |
3602 scheme_raise(exn); | |
3603 MZ_GC_UNREG(); | |
14 | 3604 } |
3605 | |
3606 void | |
3607 raise_if_error(void) | |
3608 { | |
3609 if (vim_error_check()) | |
3610 raise_vim_exn(NULL); | |
3611 } | |
3612 | |
3613 /* get buffer: | |
3614 * either current | |
3615 * or passed as argv[argnum] with checks | |
3616 */ | |
3617 static vim_mz_buffer * | |
3618 get_buffer_arg(const char *fname, int argnum, int argc, Scheme_Object **argv) | |
3619 { | |
3620 vim_mz_buffer *b; | |
3621 | |
3622 if (argc < argnum + 1) | |
3623 return get_vim_curr_buffer(); | |
3624 if (!SCHEME_VIMBUFFERP(argv[argnum])) | |
3625 scheme_wrong_type(fname, "vim-buffer", argnum, argc, argv); | |
3626 b = (vim_mz_buffer *)argv[argnum]; | |
3627 (void)get_valid_buffer(argv[argnum]); | |
3628 return b; | |
3629 } | |
3630 | |
3631 /* get window: | |
3632 * either current | |
3633 * or passed as argv[argnum] with checks | |
3634 */ | |
3635 static vim_mz_window * | |
3636 get_window_arg(const char *fname, int argnum, int argc, Scheme_Object **argv) | |
3637 { | |
3638 vim_mz_window *w; | |
3639 | |
3640 if (argc < argnum + 1) | |
3641 return get_vim_curr_window(); | |
3642 w = (vim_mz_window *)argv[argnum]; | |
3643 if (!SCHEME_VIMWINDOWP(argv[argnum])) | |
3644 scheme_wrong_type(fname, "vim-window", argnum, argc, argv); | |
3645 (void)get_valid_window(argv[argnum]); | |
3646 return w; | |
3647 } | |
3648 | |
3649 /* get valid Vim buffer from Scheme_Object* */ | |
3650 buf_T *get_valid_buffer(void *obj) | |
3651 { | |
3652 buf_T *buf = ((vim_mz_buffer *)obj)->buf; | |
3653 | |
3654 if (buf == INVALID_BUFFER_VALUE) | |
3655 scheme_signal_error(_("buffer is invalid")); | |
3656 return buf; | |
3657 } | |
3658 | |
3659 /* get valid Vim window from Scheme_Object* */ | |
3660 win_T *get_valid_window(void *obj) | |
3661 { | |
3662 win_T *win = ((vim_mz_window *)obj)->win; | |
3663 if (win == INVALID_WINDOW_VALUE) | |
3664 scheme_signal_error(_("window is invalid")); | |
3665 return win; | |
3666 } | |
3667 | |
3668 int | |
3669 mzthreads_allowed(void) | |
3670 { | |
3671 return mz_threads_allow; | |
3672 } | |
3673 | |
3674 static int | |
3675 line_in_range(linenr_T lnum, buf_T *buf) | |
3676 { | |
3677 return (lnum > 0 && lnum <= buf->b_ml.ml_line_count); | |
3678 } | |
3679 | |
3680 static void | |
3681 check_line_range(linenr_T lnum, buf_T *buf) | |
3682 { | |
3683 if (!line_in_range(lnum, buf)) | |
3684 scheme_signal_error(_("linenr out of range")); | |
3685 } | |
3686 | |
3687 /* | |
3688 * Check if deleting lines made the cursor position invalid | |
3689 * (or you'll get msg from Vim about invalid linenr). | |
3690 * Changed the lines from "lo" to "hi" and added "extra" lines (negative if | |
3691 * deleted). Got from if_python.c | |
3692 */ | |
3693 static void | |
3694 mz_fix_cursor(int lo, int hi, int extra) | |
3695 { | |
3696 if (curwin->w_cursor.lnum >= lo) | |
3697 { | |
3698 /* Adjust the cursor position if it's in/after the changed | |
3699 * lines. */ | |
3700 if (curwin->w_cursor.lnum >= hi) | |
3701 { | |
3702 curwin->w_cursor.lnum += extra; | |
3703 check_cursor_col(); | |
3704 } | |
3705 else if (extra < 0) | |
3706 { | |
3707 curwin->w_cursor.lnum = lo; | |
3708 check_cursor(); | |
3709 } | |
1894 | 3710 else |
3711 check_cursor_col(); | |
14 | 3712 changed_cline_bef_curs(); |
3713 } | |
3714 invalidate_botline(); | |
3715 } | |
3716 | |
3717 static Vim_Prim prims[]= | |
3718 { | |
3719 /* | |
3720 * Buffer-related commands | |
3721 */ | |
3722 {get_buffer_line, "get-buff-line", 1, 2}, | |
3723 {set_buffer_line, "set-buff-line", 2, 3}, | |
3724 {get_buffer_line_list, "get-buff-line-list", 2, 3}, | |
3725 {get_buffer_name, "get-buff-name", 0, 1}, | |
3726 {get_buffer_num, "get-buff-num", 0, 1}, | |
3727 {get_buffer_size, "get-buff-size", 0, 1}, | |
3728 {set_buffer_line_list, "set-buff-line-list", 3, 4}, | |
3729 {insert_buffer_line_list, "insert-buff-line-list", 2, 3}, | |
3730 {get_curr_buffer, "curr-buff", 0, 0}, | |
3731 {get_buffer_count, "buff-count", 0, 0}, | |
3732 {get_next_buffer, "get-next-buff", 0, 1}, | |
3733 {get_prev_buffer, "get-prev-buff", 0, 1}, | |
3734 {mzscheme_open_buffer, "open-buff", 1, 1}, | |
3735 {get_buffer_by_name, "get-buff-by-name", 1, 1}, | |
3736 {get_buffer_by_num, "get-buff-by-num", 1, 1}, | |
3737 /* | |
3738 * Window-related commands | |
3739 */ | |
3740 {get_curr_win, "curr-win", 0, 0}, | |
3741 {get_window_count, "win-count", 0, 0}, | |
3742 {get_window_by_num, "get-win-by-num", 1, 1}, | |
3743 {get_window_num, "get-win-num", 0, 1}, | |
3744 {get_window_buffer, "get-win-buffer", 0, 1}, | |
3745 {get_window_height, "get-win-height", 0, 1}, | |
3746 {set_window_height, "set-win-height", 1, 2}, | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8218
diff
changeset
|
3747 #ifdef FEAT_WINDOWS |
14 | 3748 {get_window_width, "get-win-width", 0, 1}, |
3749 {set_window_width, "set-win-width", 1, 2}, | |
3750 #endif | |
3751 {get_cursor, "get-cursor", 0, 1}, | |
3752 {set_cursor, "set-cursor", 1, 2}, | |
3753 {get_window_list, "get-win-list", 0, 1}, | |
3754 /* | |
3755 * Vim-related commands | |
3756 */ | |
3757 {vim_command, "command", 1, 1}, | |
3758 {vim_eval, "eval", 1, 1}, | |
3759 {get_range_start, "range-start", 0, 0}, | |
3760 {get_range_end, "range-end", 0, 0}, | |
3761 {mzscheme_beep, "beep", 0, 0}, | |
3762 {get_option, "get-option", 1, 2}, | |
3763 {set_option, "set-option", 1, 2}, | |
3764 /* | |
3765 * small utilities | |
3766 */ | |
3767 {vim_bufferp, "buff?", 1, 1}, | |
3768 {vim_windowp, "win?", 1, 1}, | |
3769 {vim_buffer_validp, "buff-valid?", 1, 1}, | |
3770 {vim_window_validp, "win-valid?", 1, 1} | |
3771 }; | |
3772 | |
3773 /* return MzScheme wrapper for curbuf */ | |
3774 static vim_mz_buffer * | |
3775 get_vim_curr_buffer(void) | |
3776 { | |
502 | 3777 if (curbuf->b_mzscheme_ref == NULL) |
14 | 3778 return (vim_mz_buffer *)buffer_new(curbuf); |
3779 else | |
4074 | 3780 return BUFFER_REF(curbuf); |
14 | 3781 } |
3782 | |
3783 /* return MzScheme wrapper for curwin */ | |
3784 static vim_mz_window * | |
3785 get_vim_curr_window(void) | |
3786 { | |
502 | 3787 if (curwin->w_mzscheme_ref == NULL) |
14 | 3788 return (vim_mz_window *)window_new(curwin); |
3789 else | |
4074 | 3790 return WINDOW_REF(curwin); |
14 | 3791 } |
3792 | |
3793 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7813
diff
changeset
|
3794 make_modules(void) |
14 | 3795 { |
1894 | 3796 int i; |
3797 Scheme_Env *mod = NULL; | |
3798 Scheme_Object *vimext_symbol = NULL; | |
3799 Scheme_Object *closed_prim = NULL; | |
3800 | |
3801 MZ_GC_DECL_REG(3); | |
3802 MZ_GC_VAR_IN_REG(0, mod); | |
3803 MZ_GC_VAR_IN_REG(1, vimext_symbol); | |
3804 MZ_GC_VAR_IN_REG(2, closed_prim); | |
3805 MZ_GC_REG(); | |
3806 | |
3807 vimext_symbol = scheme_intern_symbol("vimext"); | |
3808 MZ_GC_CHECK(); | |
3809 mod = scheme_primitive_module(vimext_symbol, environment); | |
3810 MZ_GC_CHECK(); | |
14 | 3811 /* all prims made closed so they can access their own names */ |
1894 | 3812 for (i = 0; i < (int)(sizeof(prims)/sizeof(prims[0])); i++) |
14 | 3813 { |
3814 Vim_Prim *prim = prims + i; | |
1894 | 3815 closed_prim = scheme_make_closed_prim_w_arity(prim->prim, prim, prim->name, |
3816 prim->mina, prim->maxa); | |
3817 scheme_add_global(prim->name, closed_prim, mod); | |
3818 MZ_GC_CHECK(); | |
14 | 3819 } |
3820 scheme_finish_primitive_module(mod); | |
1894 | 3821 MZ_GC_CHECK(); |
3822 MZ_GC_UNREG(); | |
14 | 3823 } |
344 | 3824 |
274 | 3825 #ifdef HAVE_SANDBOX |
3826 static Scheme_Object *M_write = NULL; | |
3827 static Scheme_Object *M_read = NULL; | |
3828 static Scheme_Object *M_execute = NULL; | |
3829 static Scheme_Object *M_delete = NULL; | |
3830 | |
3831 static void | |
1125 | 3832 sandbox_check(void) |
274 | 3833 { |
3834 if (sandbox) | |
3835 raise_vim_exn(_("not allowed in the Vim sandbox")); | |
3836 } | |
3837 | |
344 | 3838 /* security guards to force Vim's sandbox restrictions on MzScheme level */ |
274 | 3839 static Scheme_Object * |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
3840 sandbox_file_guard(int argc UNUSED, Scheme_Object **argv) |
274 | 3841 { |
3842 if (sandbox) | |
3843 { | |
3844 Scheme_Object *requested_access = argv[2]; | |
3845 | |
3846 if (M_write == NULL) | |
3847 { | |
3848 MZ_REGISTER_STATIC(M_write); | |
3849 M_write = scheme_intern_symbol("write"); | |
1894 | 3850 MZ_GC_CHECK(); |
274 | 3851 } |
3852 if (M_read == NULL) | |
3853 { | |
3854 MZ_REGISTER_STATIC(M_read); | |
3855 M_read = scheme_intern_symbol("read"); | |
1894 | 3856 MZ_GC_CHECK(); |
274 | 3857 } |
3858 if (M_execute == NULL) | |
3859 { | |
3860 MZ_REGISTER_STATIC(M_execute); | |
3861 M_execute = scheme_intern_symbol("execute"); | |
1894 | 3862 MZ_GC_CHECK(); |
274 | 3863 } |
3864 if (M_delete == NULL) | |
3865 { | |
3866 MZ_REGISTER_STATIC(M_delete); | |
3867 M_delete = scheme_intern_symbol("delete"); | |
1894 | 3868 MZ_GC_CHECK(); |
274 | 3869 } |
3870 | |
3871 while (!SCHEME_NULLP(requested_access)) | |
3872 { | |
3873 Scheme_Object *item = SCHEME_CAR(requested_access); | |
3874 if (scheme_eq(item, M_write) || scheme_eq(item, M_read) | |
3875 || scheme_eq(item, M_execute) || scheme_eq(item, M_delete)) | |
3876 { | |
3877 raise_vim_exn(_("not allowed in the Vim sandbox")); | |
3878 } | |
3879 requested_access = SCHEME_CDR(requested_access); | |
3880 } | |
3881 } | |
3882 return scheme_void; | |
3883 } | |
3884 | |
3885 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
3886 sandbox_network_guard(int argc UNUSED, Scheme_Object **argv UNUSED) |
274 | 3887 { |
3888 return scheme_void; | |
3889 } | |
3890 #endif | |
800 | 3891 |
3892 #endif |