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