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