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