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