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