Mercurial > vim
annotate src/if_mzsch.c @ 32996:dd8da8f1c2bc v9.0.1790
patch 9.0.1790: Redundant LSP Content-Type header
Commit: https://github.com/vim/vim/commit/8fbd9449e71f2ad93e594be575209a7424eb093e
Author: Magnus Gro? <magnus@mggross.com>
Date: Sun Aug 27 00:49:51 2023 +0200
patch 9.0.1790: Redundant LSP Content-Type header
Problem: The Content-Type header is an optional header that some LSP
servers struggle with and may crash when encountering it.
Solution: Drop the Content-Type header from all messages, because we use
the default value anyway.
Because pretty much all popular LSP clients (e.g. coc.nvim, VSCode) do
not send the Content-Type header, the LSP server ecosystem has developed
such that some LSP servers may even crash when encountering it.
To improve compatibility with these misbehaving LSP servers, we drop
this header as well.
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Magnus Gro? <magnus@mggross.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 27 Aug 2023 11:15:03 +0200 |
parents | 04d9dff67d99 |
children | 1a769647d661 |
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 | |
30645
101f08b49ed3
patch 9.0.0657: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
20 * to build with 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); | |
25475
038eb6d9003a
patch 8.2.3274: macro for printf format check can be simplified
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
142 static void do_printf(char *format, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2); |
14 | 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) | |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
671 semsg(_(e_could_not_load_library_str_str), gc_dll, GetWin32Error()); |
3348 | 672 return FAIL; |
673 } | |
674 | |
137 | 675 if (!hMzSch) |
676 { | |
677 if (verbose) | |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
678 semsg(_(e_could_not_load_library_str_str), sch_dll, GetWin32Error()); |
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) | |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
692 semsg(_(e_could_not_load_library_function_str), 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) | |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
706 semsg(_(e_could_not_load_library_function_str), 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; |
28303
9849df834f1d
patch 8.2.4677: the Athena GUI support is outdated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
812 #elif defined(FEAT_GUI_MOTIF) |
14 | 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) |
28303
9849df834f1d
patch 8.2.4677: the Athena GUI support is outdated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
848 # elif defined(FEAT_GUI_MOTIF) |
14 | 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 |
28303
9849df834f1d
patch 8.2.4677: the Athena GUI support is outdated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
856 # elif defined(FEAT_GUI_MOTIF) |
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); |
28303
9849df834f1d
patch 8.2.4677: the Athena GUI support is outdated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
871 # elif defined(FEAT_GUI_MOTIF) |
14 | 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); |
28303
9849df834f1d
patch 8.2.4677: the Athena GUI support is outdated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
883 # elif defined(FEAT_GUI_MOTIF) |
14 | 884 XtRemoveTimeOut(timer_id); |
885 # endif | |
886 timer_id = 0; | |
887 } | |
888 | |
32019
274e1b3fbc2a
patch 9.0.1341: build error with mzscheme but without GUI
Bram Moolenaar <Bram@vim.org>
parents:
31996
diff
changeset
|
889 #endif // MZSCHEME_GUI_THREADS |
274e1b3fbc2a
patch 9.0.1341: build error with mzscheme but without GUI
Bram Moolenaar <Bram@vim.org>
parents:
31996
diff
changeset
|
890 |
31996
ca6bc7c04163
patch 9.0.1330: handling new value of an option has a long "else if" chain
Bram Moolenaar <Bram@vim.org>
parents:
31702
diff
changeset
|
891 char * |
32019
274e1b3fbc2a
patch 9.0.1341: build error with mzscheme but without GUI
Bram Moolenaar <Bram@vim.org>
parents:
31996
diff
changeset
|
892 did_set_mzquantum(optset_T *args UNUSED) |
14 | 893 { |
32019
274e1b3fbc2a
patch 9.0.1341: build error with mzscheme but without GUI
Bram Moolenaar <Bram@vim.org>
parents:
31996
diff
changeset
|
894 #if defined(MZSCHEME_GUI_THREADS) |
31996
ca6bc7c04163
patch 9.0.1330: handling new value of an option has a long "else if" chain
Bram Moolenaar <Bram@vim.org>
parents:
31702
diff
changeset
|
895 // reset timer |
14 | 896 if (timer_id != 0) |
897 remove_timer(); | |
898 if (mz_threads_allow && p_mzq > 0 && gui.in_use) | |
899 setup_timer(); | |
32019
274e1b3fbc2a
patch 9.0.1341: build error with mzscheme but without GUI
Bram Moolenaar <Bram@vim.org>
parents:
31996
diff
changeset
|
900 #endif |
31996
ca6bc7c04163
patch 9.0.1330: handling new value of an option has a long "else if" chain
Bram Moolenaar <Bram@vim.org>
parents:
31702
diff
changeset
|
901 return NULL; |
14 | 902 } |
903 | |
904 static void | |
905 notify_multithread(int on) | |
906 { | |
907 mz_threads_allow = on; | |
16 | 908 #ifdef MZSCHEME_GUI_THREADS |
14 | 909 if (on && timer_id == 0 && p_mzq > 0 && gui.in_use) |
910 setup_timer(); | |
911 if (!on && timer_id != 0) | |
912 remove_timer(); | |
913 #endif | |
914 } | |
915 | |
916 void | |
917 mzscheme_end(void) | |
918 { | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
919 // 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
|
920 #if 0 |
137 | 921 #ifdef DYNAMIC_MZSCHEME |
922 dynamic_mzscheme_end(); | |
923 #endif | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
924 #endif |
14 | 925 } |
926 | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
927 #if HAVE_TLS_SPACE |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
928 # if defined(_MSC_VER) |
2628 | 929 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
|
930 extern intptr_t _tls_index; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
931 # elif defined(__MINGW32__) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
932 static __thread void *tls_space; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
933 extern intptr_t _tls_index; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
934 # else |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
935 static THREAD_LOCAL void *tls_space; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
936 static intptr_t _tls_index = 0; |
3348 | 937 # endif |
938 #endif | |
939 | |
9961
f4e903ba38d8
commit https://github.com/vim/vim/commit/54b6352c6f0617ff9c963588ccc7d31815348029
Christian Brabandt <cb@256bit.org>
parents:
9802
diff
changeset
|
940 /* |
f4e903ba38d8
commit https://github.com/vim/vim/commit/54b6352c6f0617ff9c963588ccc7d31815348029
Christian Brabandt <cb@256bit.org>
parents:
9802
diff
changeset
|
941 * 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
|
942 * 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
|
943 * 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
|
944 */ |
3348 | 945 int |
9961
f4e903ba38d8
commit https://github.com/vim/vim/commit/54b6352c6f0617ff9c963588ccc7d31815348029
Christian Brabandt <cb@256bit.org>
parents:
9802
diff
changeset
|
946 mzscheme_main(void) |
1894 | 947 { |
9802
4cb5ab124239
commit https://github.com/vim/vim/commit/a8e691d44937fd9d72dcbad2b8c673682277f13d
Christian Brabandt <cb@256bit.org>
parents:
9723
diff
changeset
|
948 int argc = 0; |
4cb5ab124239
commit https://github.com/vim/vim/commit/a8e691d44937fd9d72dcbad2b8c673682277f13d
Christian Brabandt <cb@256bit.org>
parents:
9723
diff
changeset
|
949 char *argv = NULL; |
4cb5ab124239
commit https://github.com/vim/vim/commit/a8e691d44937fd9d72dcbad2b8c673682277f13d
Christian Brabandt <cb@256bit.org>
parents:
9723
diff
changeset
|
950 |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
951 #ifdef DYNAMIC_MZSCHEME |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
952 /* |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
953 * 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
|
954 * 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
|
955 */ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
956 if (!mzscheme_enabled(FALSE)) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
957 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
958 disabled = TRUE; |
9802
4cb5ab124239
commit https://github.com/vim/vim/commit/a8e691d44937fd9d72dcbad2b8c673682277f13d
Christian Brabandt <cb@256bit.org>
parents:
9723
diff
changeset
|
959 return vim_main2(); |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
960 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
961 #endif |
6905 | 962 #ifdef HAVE_TLS_SPACE |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
963 scheme_register_tls_space(&tls_space, _tls_index); |
2628 | 964 #endif |
3348 | 965 #ifdef TRAMPOLINED_MZVIM_STARTUP |
9802
4cb5ab124239
commit https://github.com/vim/vim/commit/a8e691d44937fd9d72dcbad2b8c673682277f13d
Christian Brabandt <cb@256bit.org>
parents:
9723
diff
changeset
|
966 return scheme_main_setup(TRUE, mzscheme_env_main, argc, &argv); |
1894 | 967 #else |
9802
4cb5ab124239
commit https://github.com/vim/vim/commit/a8e691d44937fd9d72dcbad2b8c673682277f13d
Christian Brabandt <cb@256bit.org>
parents:
9723
diff
changeset
|
968 return mzscheme_env_main(NULL, argc, &argv); |
1894 | 969 #endif |
970 } | |
971 | |
972 static int | |
9961
f4e903ba38d8
commit https://github.com/vim/vim/commit/54b6352c6f0617ff9c963588ccc7d31815348029
Christian Brabandt <cb@256bit.org>
parents:
9802
diff
changeset
|
973 mzscheme_env_main(Scheme_Env *env, int argc UNUSED, char **argv UNUSED) |
1894 | 974 { |
3348 | 975 #ifdef TRAMPOLINED_MZVIM_STARTUP |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
976 // Scheme has created the environment for us |
3348 | 977 environment = env; |
978 #else | |
979 # ifdef MZ_PRECISE_GC | |
1894 | 980 Scheme_Object *dummy = NULL; |
981 MZ_GC_DECL_REG(1); | |
982 MZ_GC_VAR_IN_REG(0, dummy); | |
983 | |
984 stack_base = &__gc_var_stack__; | |
985 # else | |
986 int dummy = 0; | |
987 stack_base = (void *)&dummy; | |
3348 | 988 # endif |
1894 | 989 #endif |
3348 | 990 |
9961
f4e903ba38d8
commit https://github.com/vim/vim/commit/54b6352c6f0617ff9c963588ccc7d31815348029
Christian Brabandt <cb@256bit.org>
parents:
9802
diff
changeset
|
991 vim_main2(); |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
992 // 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
|
993 |
f4e903ba38d8
commit https://github.com/vim/vim/commit/54b6352c6f0617ff9c963588ccc7d31815348029
Christian Brabandt <cb@256bit.org>
parents:
9802
diff
changeset
|
994 return 0; |
1894 | 995 } |
996 | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
997 static Scheme_Object* |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
998 load_base_module(void *data) |
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 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
|
1001 return scheme_null; |
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 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1004 static Scheme_Object * |
8779
26495bd795d2
commit https://github.com/vim/vim/commit/8b29aba0192cc56294ef49bb3c01adff4b8f3a28
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1005 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
|
1006 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1007 load_base_module_failed = TRUE; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1008 return scheme_null; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1009 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1010 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1011 static int |
14 | 1012 startup_mzscheme(void) |
1013 { | |
3348 | 1014 #ifndef TRAMPOLINED_MZVIM_STARTUP |
1894 | 1015 scheme_set_stack_base(stack_base, 1); |
1016 #endif | |
14 | 1017 |
4074 | 1018 #ifndef TRAMPOLINED_MZVIM_STARTUP |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1019 // in newer versions of precise GC the initial env has been created |
4074 | 1020 environment = scheme_basic_env(); |
1021 #endif | |
1022 | |
14 | 1023 MZ_REGISTER_STATIC(environment); |
1024 MZ_REGISTER_STATIC(curout); | |
1025 MZ_REGISTER_STATIC(curerr); | |
1026 MZ_REGISTER_STATIC(exn_catching_apply); | |
1027 MZ_REGISTER_STATIC(exn_p); | |
1028 MZ_REGISTER_STATIC(exn_message); | |
1029 MZ_REGISTER_STATIC(vim_exn); | |
1894 | 1030 |
1031 MZ_GC_CHECK(); | |
1032 | |
1033 #ifdef INCLUDE_MZSCHEME_BASE | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1034 // 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
|
1035 declare_modules(environment); |
1894 | 1036 #endif |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1037 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1038 // setup 'current-library-collection-paths' parameter |
1307 | 1039 # if MZSCHEME_VERSION_MAJOR >= 299 |
1894 | 1040 { |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1041 Scheme_Object *coll_path = NULL; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1042 int mustfree = FALSE; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1043 char_u *s; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1044 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1045 MZ_GC_DECL_REG(1); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1046 MZ_GC_VAR_IN_REG(0, coll_path); |
1894 | 1047 MZ_GC_REG(); |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1048 // 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
|
1049 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
|
1050 if (s != NULL) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1051 { |
8110
d1974721ddc5
commit https://github.com/vim/vim/commit/74a97b1ea0fe2c729e26718d0eec4164c8bed151
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
1052 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
|
1053 MZ_GC_CHECK(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1054 if (mustfree) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1055 vim_free(s); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1056 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1057 # ifdef MZSCHEME_COLLECTS |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1058 if (coll_path == NULL) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1059 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1060 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
|
1061 MZ_GC_CHECK(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1062 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1063 # endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1064 if (coll_path != NULL) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1065 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1066 scheme_set_collects_path(coll_path); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1067 MZ_GC_CHECK(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1068 } |
1894 | 1069 MZ_GC_UNREG(); |
1070 } | |
1307 | 1071 # else |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1072 # ifdef MZSCHEME_COLLECTS |
1894 | 1073 { |
1074 Scheme_Object *coll_string = NULL; | |
1075 Scheme_Object *coll_pair = NULL; | |
1076 Scheme_Config *config = NULL; | |
1077 | |
1078 MZ_GC_DECL_REG(3); | |
1079 MZ_GC_VAR_IN_REG(0, coll_string); | |
1080 MZ_GC_VAR_IN_REG(1, coll_pair); | |
1081 MZ_GC_VAR_IN_REG(2, config); | |
1082 MZ_GC_REG(); | |
4074 | 1083 coll_string = scheme_make_byte_string(MZSCHEME_COLLECTS); |
1894 | 1084 MZ_GC_CHECK(); |
1085 coll_pair = scheme_make_pair(coll_string, scheme_null); | |
1086 MZ_GC_CHECK(); | |
4074 | 1087 config = scheme_current_config(); |
1894 | 1088 MZ_GC_CHECK(); |
1089 scheme_set_param(config, MZCONFIG_COLLECTION_PATHS, coll_pair); | |
1090 MZ_GC_CHECK(); | |
1091 MZ_GC_UNREG(); | |
1092 } | |
1307 | 1093 # endif |
14 | 1094 #endif |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1095 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1096 # if MZSCHEME_VERSION_MAJOR >= 600 |
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 Scheme_Object *config_path = NULL; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1099 int mustfree = FALSE; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1100 char_u *s; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1101 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1102 MZ_GC_DECL_REG(1); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1103 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
|
1104 MZ_GC_REG(); |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1105 // 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
|
1106 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
|
1107 if (s != NULL) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1108 { |
9289
29de7dda7a6a
commit https://github.com/vim/vim/commit/5b7d177e8994c003ae77ddab5bd54f8cd1ee181b
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
1109 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
|
1110 MZ_GC_CHECK(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1111 if (mustfree) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1112 vim_free(s); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1113 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1114 #ifdef MZSCHEME_CONFIGDIR |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1115 if (config_path == NULL) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1116 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1117 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
|
1118 MZ_GC_CHECK(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1119 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1120 #endif |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1121 if (config_path != NULL) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1122 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1123 scheme_set_config_path(config_path); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1124 MZ_GC_CHECK(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1125 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1126 MZ_GC_UNREG(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1127 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1128 # 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 #if MZSCHEME_VERSION_MAJOR >= 400 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1131 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
|
1132 #endif |
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 /* |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1135 * 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
|
1136 * we need to add them explicitly |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1137 */ |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1138 { |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1139 // 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
|
1140 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
|
1141 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
|
1142 if (load_base_module_failed) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1143 { |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1144 load_base_module_failed = FALSE; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1145 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
|
1146 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
|
1147 if (load_base_module_failed) |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1148 return -1; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1149 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1150 } |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1151 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1152 register_vim_exn(); |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1153 // 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
|
1154 init_exn_catching_apply(); |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1155 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1156 // redirect output |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1157 scheme_console_output = do_output; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1158 scheme_console_printf = do_printf; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1159 |
274 | 1160 #ifdef HAVE_SANDBOX |
1161 { | |
1894 | 1162 Scheme_Object *make_security_guard = NULL; |
1163 MZ_GC_DECL_REG(1); | |
1164 MZ_GC_VAR_IN_REG(0, make_security_guard); | |
1165 MZ_GC_REG(); | |
1166 | |
1167 #if MZSCHEME_VERSION_MAJOR < 400 | |
1168 { | |
1169 Scheme_Object *make_security_guard_symbol = NULL; | |
1170 MZ_GC_DECL_REG(1); | |
1171 MZ_GC_VAR_IN_REG(0, make_security_guard_symbol); | |
1172 MZ_GC_REG(); | |
1173 make_security_guard_symbol = scheme_intern_symbol("make-security-guard"); | |
1174 MZ_GC_CHECK(); | |
1175 make_security_guard = scheme_lookup_global( | |
1176 make_security_guard_symbol, environment); | |
1177 MZ_GC_UNREG(); | |
1178 } | |
1179 #else | |
1180 make_security_guard = scheme_builtin_value("make-security-guard"); | |
1181 MZ_GC_CHECK(); | |
1182 #endif | |
1183 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1184 // setup sandbox guards |
1894 | 1185 if (make_security_guard != NULL) |
1186 { | |
1187 Scheme_Object *args[3] = {NULL, NULL, NULL}; | |
1188 Scheme_Object *guard = NULL; | |
1189 Scheme_Config *config = NULL; | |
1190 MZ_GC_DECL_REG(5); | |
1191 MZ_GC_ARRAY_VAR_IN_REG(0, args, 3); | |
1192 MZ_GC_VAR_IN_REG(3, guard); | |
1193 MZ_GC_VAR_IN_REG(4, config); | |
1194 MZ_GC_REG(); | |
4074 | 1195 config = scheme_current_config(); |
1894 | 1196 MZ_GC_CHECK(); |
1197 args[0] = scheme_get_param(config, MZCONFIG_SECURITY_GUARD); | |
1198 MZ_GC_CHECK(); | |
1199 args[1] = scheme_make_prim_w_arity(sandbox_file_guard, | |
1200 "sandbox-file-guard", 3, 3); | |
1201 args[2] = scheme_make_prim_w_arity(sandbox_network_guard, | |
1202 "sandbox-network-guard", 4, 4); | |
1203 guard = scheme_apply(make_security_guard, 3, args); | |
1204 MZ_GC_CHECK(); | |
1205 scheme_set_param(config, MZCONFIG_SECURITY_GUARD, guard); | |
1206 MZ_GC_CHECK(); | |
1207 MZ_GC_UNREG(); | |
1208 } | |
1209 MZ_GC_UNREG(); | |
274 | 1210 } |
1211 #endif | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1212 // Create buffer and window types for use in Scheme code |
14 | 1213 mz_buffer_type = scheme_make_type("<vim-buffer>"); |
1894 | 1214 MZ_GC_CHECK(); |
14 | 1215 mz_window_type = scheme_make_type("<vim-window>"); |
1894 | 1216 MZ_GC_CHECK(); |
1217 #ifdef MZ_PRECISE_GC | |
1218 GC_register_traversers(mz_buffer_type, | |
1219 buffer_size_proc, buffer_mark_proc, buffer_fixup_proc, | |
1220 TRUE, TRUE); | |
1221 GC_register_traversers(mz_window_type, | |
1222 window_size_proc, window_mark_proc, window_fixup_proc, | |
1223 TRUE, TRUE); | |
1224 #endif | |
1225 | |
1226 make_modules(); | |
14 | 1227 |
1228 /* | |
1229 * setup callback to receive notifications | |
1230 * whether thread scheduling is (or not) required | |
1231 */ | |
1232 scheme_notify_multithread = notify_multithread; | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1233 |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1234 return 0; |
14 | 1235 } |
1236 | |
1237 /* | |
1238 * This routine is called for each new invocation of MzScheme | |
1239 * to make sure things are properly initialized. | |
1240 */ | |
1241 static int | |
1242 mzscheme_init(void) | |
1243 { | |
1244 if (!initialized) | |
1245 { | |
137 | 1246 #ifdef DYNAMIC_MZSCHEME |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1247 if (disabled || !mzscheme_enabled(TRUE)) |
137 | 1248 { |
26962
85866e069c24
patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1249 emsg(_(e_sorry_this_command_is_disabled_the_mzscheme_libraries_could_not_be_loaded)); |
137 | 1250 return -1; |
1251 } | |
1252 #endif | |
7609
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1253 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
|
1254 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
1255 emsg(_(e_sorry_this_command_is_disabled_the_mzscheme_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
|
1256 return -1; |
77a14f3bc18b
commit https://github.com/vim/vim/commit/4e640bd930d133889dbc9f9a77e29bab902e3b7d
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
1257 } |
1894 | 1258 initialized = TRUE; |
14 | 1259 } |
1260 { | |
1894 | 1261 Scheme_Config *config = NULL; |
1262 MZ_GC_DECL_REG(1); | |
1263 MZ_GC_VAR_IN_REG(0, config); | |
1264 MZ_GC_REG(); | |
4074 | 1265 config = scheme_current_config(); |
1894 | 1266 MZ_GC_CHECK(); |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1267 // recreate ports each call effectively clearing these ones |
4074 | 1268 curout = scheme_make_byte_string_output_port(); |
1894 | 1269 MZ_GC_CHECK(); |
4074 | 1270 curerr = scheme_make_byte_string_output_port(); |
1894 | 1271 MZ_GC_CHECK(); |
1272 scheme_set_param(config, MZCONFIG_OUTPUT_PORT, curout); | |
1273 MZ_GC_CHECK(); | |
1274 scheme_set_param(config, MZCONFIG_ERROR_PORT, curerr); | |
1275 MZ_GC_CHECK(); | |
1276 MZ_GC_UNREG(); | |
14 | 1277 } |
1278 | |
1279 return 0; | |
1280 } | |
1281 | |
1282 /* | |
1283 *======================================================================== | |
1284 * 2. External Interface | |
1285 *======================================================================== | |
1286 */ | |
1287 | |
1288 /* | |
1894 | 1289 * Evaluate command with exception handling |
14 | 1290 */ |
1291 static int | |
1894 | 1292 eval_with_exn_handling(void *data, Scheme_Closed_Prim *what, Scheme_Object **ret) |
14 | 1293 { |
1894 | 1294 Scheme_Object *value = NULL; |
1295 Scheme_Object *exn = NULL; | |
1296 Scheme_Object *prim = NULL; | |
1297 | |
1298 MZ_GC_DECL_REG(3); | |
1299 MZ_GC_VAR_IN_REG(0, value); | |
1300 MZ_GC_VAR_IN_REG(1, exn); | |
1301 MZ_GC_VAR_IN_REG(2, prim); | |
1302 MZ_GC_REG(); | |
1303 | |
1304 prim = scheme_make_closed_prim_w_arity(what, data, "mzvim", 0, 0); | |
1305 MZ_GC_CHECK(); | |
1306 value = _apply_thunk_catch_exceptions(prim, &exn); | |
1307 MZ_GC_CHECK(); | |
14 | 1308 |
1309 if (!value) | |
1310 { | |
1311 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
|
1312 // Got an exn? |
14 | 1313 if (value) |
1314 { | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1315 scheme_display(value, curerr); // Send to stderr-vim |
1894 | 1316 MZ_GC_CHECK(); |
14 | 1317 do_flush(); |
1318 } | |
1894 | 1319 MZ_GC_UNREG(); |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1320 // `raise' was called on some arbitrary value |
14 | 1321 return FAIL; |
1322 } | |
1323 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1324 if (ret != NULL) // if pointer to retval supported give it up |
14 | 1325 *ret = value; |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1326 // Print any result, as long as it's not a void |
14 | 1327 else if (!SCHEME_VOIDP(value)) |
1894 | 1328 { |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1329 scheme_display(value, curout); // Send to stdout-vim |
1894 | 1330 MZ_GC_CHECK(); |
1331 } | |
14 | 1332 |
1333 do_flush(); | |
1894 | 1334 MZ_GC_UNREG(); |
14 | 1335 return OK; |
1336 } | |
1337 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1338 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1339 * :mzscheme |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1340 */ |
14 | 1341 static int |
1342 do_mzscheme_command(exarg_T *eap, void *data, Scheme_Closed_Prim *what) | |
1343 { | |
1344 if (mzscheme_init()) | |
1345 return FAIL; | |
1346 | |
1347 range_start = eap->line1; | |
1348 range_end = eap->line2; | |
1349 | |
1894 | 1350 return eval_with_exn_handling(data, what, NULL); |
14 | 1351 } |
1352 | |
1353 /* | |
1354 * Routine called by VIM when deleting a buffer | |
1355 */ | |
1356 void | |
1357 mzscheme_buffer_free(buf_T *buf) | |
1358 { | |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1359 if (buf->b_mzscheme_ref == NULL) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1360 return; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1361 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1362 vim_mz_buffer *bp = NULL; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1363 MZ_GC_DECL_REG(1); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1364 MZ_GC_VAR_IN_REG(0, bp); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1365 MZ_GC_REG(); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1366 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1367 bp = BUFFER_REF(buf); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1368 bp->buf = INVALID_BUFFER_VALUE; |
4074 | 1369 #ifndef MZ_PRECISE_GC |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1370 scheme_gc_ptr_ok(bp); |
4074 | 1371 #else |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1372 scheme_free_immobile_box(buf->b_mzscheme_ref); |
4074 | 1373 #endif |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1374 buf->b_mzscheme_ref = NULL; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1375 MZ_GC_CHECK(); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1376 MZ_GC_UNREG(); |
14 | 1377 } |
1378 | |
1379 /* | |
1380 * Routine called by VIM when deleting a Window | |
1381 */ | |
1382 void | |
1383 mzscheme_window_free(win_T *win) | |
1384 { | |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1385 if (win->w_mzscheme_ref == NULL) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1386 return; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1387 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1388 vim_mz_window *wp = NULL; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1389 MZ_GC_DECL_REG(1); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1390 MZ_GC_VAR_IN_REG(0, wp); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1391 MZ_GC_REG(); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1392 wp = WINDOW_REF(win); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1393 wp->win = INVALID_WINDOW_VALUE; |
4074 | 1394 #ifndef MZ_PRECISE_GC |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1395 scheme_gc_ptr_ok(wp); |
4074 | 1396 #else |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1397 scheme_free_immobile_box(win->w_mzscheme_ref); |
4074 | 1398 #endif |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1399 win->w_mzscheme_ref = NULL; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1400 MZ_GC_CHECK(); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1401 MZ_GC_UNREG(); |
14 | 1402 } |
1403 | |
1404 /* | |
1405 * ":mzscheme" (or ":mz") | |
1406 */ | |
1407 void | |
1408 ex_mzscheme(exarg_T *eap) | |
1409 { | |
1410 char_u *script; | |
1411 | |
1412 script = script_get(eap, eap->arg); | |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1413 if (eap->skip) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1414 return; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1415 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1416 if (script == NULL) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1417 do_mzscheme_command(eap, eap->arg, do_eval); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1418 else |
14 | 1419 { |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1420 do_mzscheme_command(eap, script, do_eval); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1421 vim_free(script); |
14 | 1422 } |
1423 } | |
1424 | |
1425 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1426 do_load(void *data, int noargc UNUSED, Scheme_Object **noargv UNUSED) |
14 | 1427 { |
1894 | 1428 Scheme_Object *expr = NULL; |
1429 Scheme_Object *result = NULL; | |
1430 char *file = NULL; | |
1431 Port_Info *pinfo = (Port_Info *)data; | |
1432 | |
1433 MZ_GC_DECL_REG(3); | |
1434 MZ_GC_VAR_IN_REG(0, expr); | |
1435 MZ_GC_VAR_IN_REG(1, result); | |
1436 MZ_GC_VAR_IN_REG(2, file); | |
1437 MZ_GC_REG(); | |
1438 | |
1439 file = (char *)scheme_malloc_fail_ok(scheme_malloc_atomic, MAXPATHL + 1); | |
1440 MZ_GC_CHECK(); | |
14 | 1441 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1442 // make Vim expansion |
1894 | 1443 expand_env((char_u *)pinfo->name, (char_u *)file, MAXPATHL); |
14 | 1444 pinfo->port = scheme_open_input_file(file, "mzfile"); |
1894 | 1445 MZ_GC_CHECK(); |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1446 scheme_count_lines(pinfo->port); // to get accurate read error location |
1894 | 1447 MZ_GC_CHECK(); |
14 | 1448 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1449 // Like REPL but print only last result |
14 | 1450 while (!SCHEME_EOFP(expr = scheme_read(pinfo->port))) |
1894 | 1451 { |
1452 result = scheme_eval(expr, environment); | |
1453 MZ_GC_CHECK(); | |
1454 } | |
14 | 1455 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1456 // errors will be caught in do_mzscheme_command and ex_mzfile |
14 | 1457 scheme_close_input_port(pinfo->port); |
1894 | 1458 MZ_GC_CHECK(); |
14 | 1459 pinfo->port = NULL; |
1894 | 1460 MZ_GC_UNREG(); |
14 | 1461 return result; |
1462 } | |
1463 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1464 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1465 * :mzfile |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1466 */ |
14 | 1467 void |
1468 ex_mzfile(exarg_T *eap) | |
1469 { | |
1894 | 1470 Port_Info pinfo = {NULL, NULL}; |
1471 | |
1472 MZ_GC_DECL_REG(1); | |
1473 MZ_GC_VAR_IN_REG(0, pinfo.port); | |
1474 MZ_GC_REG(); | |
14 | 1475 |
1476 pinfo.name = (char *)eap->arg; | |
1477 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
|
1478 && pinfo.port != NULL) // looks like port was not closed |
1894 | 1479 { |
14 | 1480 scheme_close_input_port(pinfo.port); |
1894 | 1481 MZ_GC_CHECK(); |
1482 } | |
1483 MZ_GC_UNREG(); | |
14 | 1484 } |
1485 | |
1486 | |
1487 /* | |
1488 *======================================================================== | |
1489 * Exception handling code -- cribbed form the MzScheme sources and | |
1490 * Matthew Flatt's "Inside PLT MzScheme" document. | |
1491 *======================================================================== | |
1492 */ | |
1493 static void | |
1494 init_exn_catching_apply(void) | |
1495 { | |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1496 if (exn_catching_apply) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1497 return; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1498 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1499 char *e = |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1500 "(lambda (thunk) " |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1501 "(with-handlers ([void (lambda (exn) (cons #f exn))]) " |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1502 "(cons #t (thunk))))"; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1503 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1504 exn_catching_apply = scheme_eval_string(e, environment); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1505 MZ_GC_CHECK(); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1506 exn_p = scheme_builtin_value("exn?"); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1507 MZ_GC_CHECK(); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1508 exn_message = scheme_builtin_value("exn-message"); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1509 MZ_GC_CHECK(); |
14 | 1510 } |
1511 | |
1512 /* | |
1513 * This function applies a thunk, returning the Scheme value if there's | |
1514 * no exception, otherwise returning NULL and setting *exn to the raised | |
1515 * value (usually an exn structure). | |
1516 */ | |
1517 static Scheme_Object * | |
1518 _apply_thunk_catch_exceptions(Scheme_Object *f, Scheme_Object **exn) | |
1519 { | |
1520 Scheme_Object *v; | |
1521 | |
1522 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
|
1523 // v is a pair: (cons #t value) or (cons #f exn) |
14 | 1524 |
1525 if (SCHEME_TRUEP(SCHEME_CAR(v))) | |
1526 return SCHEME_CDR(v); | |
1527 else | |
1528 { | |
1529 *exn = SCHEME_CDR(v); | |
1530 return NULL; | |
1531 } | |
1532 } | |
1533 | |
1534 static Scheme_Object * | |
1535 extract_exn_message(Scheme_Object *v) | |
1536 { | |
1537 if (SCHEME_TRUEP(_scheme_apply(exn_p, 1, &v))) | |
1538 return _scheme_apply(exn_message, 1, &v); | |
1539 else | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1540 return NULL; // Not an exn structure |
14 | 1541 } |
1542 | |
1543 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1544 do_eval(void *s, int noargc UNUSED, Scheme_Object **noargv UNUSED) |
14 | 1545 { |
1894 | 1546 return scheme_eval_string_all((char *)s, environment, TRUE); |
14 | 1547 } |
1548 | |
1549 /* | |
1550 *======================================================================== | |
1551 * 3. MzScheme I/O Handlers | |
1552 *======================================================================== | |
1553 */ | |
1554 static void | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1555 do_intrnl_output(char *mesg, int error) |
14 | 1556 { |
1557 char *p, *prev; | |
1558 | |
1559 prev = mesg; | |
1560 p = strchr(prev, '\n'); | |
1561 while (p) | |
1562 { | |
1563 *p = '\0'; | |
1564 if (error) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15412
diff
changeset
|
1565 emsg(prev); |
14 | 1566 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1567 msg(prev); |
14 | 1568 prev = p + 1; |
1569 p = strchr(prev, '\n'); | |
1570 } | |
1571 | |
1572 if (error) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15412
diff
changeset
|
1573 emsg(prev); |
14 | 1574 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1575 msg(prev); |
14 | 1576 } |
1577 | |
1578 static void | |
4074 | 1579 do_output(char *mesg, OUTPUT_LEN_TYPE len UNUSED) |
14 | 1580 { |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1581 // 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
|
1582 do_intrnl_output(mesg, 0); |
14 | 1583 } |
1584 | |
1585 static void | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1586 do_err_output(char *mesg) |
14 | 1587 { |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1588 do_intrnl_output(mesg, 1); |
14 | 1589 } |
1590 | |
1591 static void | |
1592 do_printf(char *format, ...) | |
1593 { | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1594 do_intrnl_output(format, 1); |
14 | 1595 } |
1596 | |
1597 static void | |
1598 do_flush(void) | |
1599 { | |
1600 char *buff; | |
4074 | 1601 OUTPUT_LEN_TYPE length; |
1602 | |
1603 buff = scheme_get_sized_byte_string_output(curerr, &length); | |
1894 | 1604 MZ_GC_CHECK(); |
14 | 1605 if (length) |
1606 { | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1607 do_err_output(buff); |
14 | 1608 return; |
1609 } | |
1610 | |
4074 | 1611 buff = scheme_get_sized_byte_string_output(curout, &length); |
1894 | 1612 MZ_GC_CHECK(); |
14 | 1613 if (length) |
1614 do_output(buff, length); | |
1615 } | |
1616 | |
1617 /* | |
1618 *======================================================================== | |
1619 * 4. Implementation of the Vim Features for MzScheme | |
1620 *======================================================================== | |
1621 */ | |
1622 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1623 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1624 * (command {command-string}) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1625 */ |
14 | 1626 static Scheme_Object * |
1627 vim_command(void *data, int argc, Scheme_Object **argv) | |
1628 { | |
1629 Vim_Prim *prim = (Vim_Prim *)data; | |
4074 | 1630 Scheme_Object *cmd = NULL; |
1631 MZ_GC_DECL_REG(1); | |
1632 MZ_GC_VAR_IN_REG(0, cmd); | |
1633 MZ_GC_REG(); | |
1634 cmd = GUARANTEED_STRING_ARG(prim->name, 0); | |
14 | 1635 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1636 // may be use do_cmdline_cmd? |
4074 | 1637 do_cmdline(BYTE_STRING_VALUE(cmd), NULL, NULL, DOCMD_NOWAIT|DOCMD_VERBOSE); |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
28303
diff
changeset
|
1638 update_screen(UPD_VALID); |
14 | 1639 |
4074 | 1640 MZ_GC_UNREG(); |
14 | 1641 raise_if_error(); |
1642 return scheme_void; | |
1643 } | |
1644 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1645 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1646 * (eval {expr-string}) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1647 */ |
14 | 1648 static Scheme_Object * |
4082 | 1649 vim_eval(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1650 { |
1651 #ifdef FEAT_EVAL | |
1894 | 1652 Vim_Prim *prim = (Vim_Prim *)data; |
4074 | 1653 Scheme_Object *result = NULL; |
1894 | 1654 typval_T *vim_result; |
4074 | 1655 Scheme_Object *expr = NULL; |
1656 MZ_GC_DECL_REG(2); | |
1657 MZ_GC_VAR_IN_REG(0, result); | |
1658 MZ_GC_VAR_IN_REG(1, expr); | |
1894 | 1659 MZ_GC_REG(); |
4074 | 1660 expr = GUARANTEED_STRING_ARG(prim->name, 0); |
1661 | |
1662 vim_result = eval_expr(BYTE_STRING_VALUE(expr), NULL); | |
1894 | 1663 |
1664 if (vim_result == NULL) | |
14 | 1665 raise_vim_exn(_("invalid expression")); |
1666 | |
4074 | 1667 result = vim_to_mzscheme(vim_result); |
1668 MZ_GC_CHECK(); | |
1894 | 1669 free_tv(vim_result); |
1670 | |
1671 MZ_GC_UNREG(); | |
14 | 1672 return result; |
1673 #else | |
1674 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
|
1675 // unreachable |
14 | 1676 return scheme_false; |
1677 #endif | |
1678 } | |
1679 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1680 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1681 * (range-start) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1682 */ |
14 | 1683 static Scheme_Object * |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1684 get_range_start(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1685 { |
1686 return scheme_make_integer(range_start); | |
1687 } | |
1688 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1689 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1690 * (range-end) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1691 */ |
14 | 1692 static Scheme_Object * |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1693 get_range_end(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1694 { |
1695 return scheme_make_integer(range_end); | |
1696 } | |
1697 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1698 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1699 * (beep) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1700 */ |
14 | 1701 static Scheme_Object * |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1702 mzscheme_beep(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1703 { |
6949 | 1704 vim_beep(BO_LANG); |
14 | 1705 return scheme_void; |
1706 } | |
1707 | |
1708 static Scheme_Object *M_global = NULL; | |
1709 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1710 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1711 * (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
|
1712 */ |
14 | 1713 static Scheme_Object * |
1714 get_option(void *data, int argc, Scheme_Object **argv) | |
1715 { | |
1716 Vim_Prim *prim = (Vim_Prim *)data; | |
1717 long value; | |
1894 | 1718 char *strval; |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
21745
diff
changeset
|
1719 getoption_T rc; |
4074 | 1720 Scheme_Object *rval = NULL; |
1721 Scheme_Object *name = NULL; | |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
25475
diff
changeset
|
1722 int scope = 0; |
14 | 1723 buf_T *save_curb = curbuf; |
1724 win_T *save_curw = curwin; | |
1725 | |
4074 | 1726 MZ_GC_DECL_REG(2); |
1727 MZ_GC_VAR_IN_REG(0, rval); | |
1728 MZ_GC_VAR_IN_REG(1, name); | |
1729 MZ_GC_REG(); | |
1730 | |
1731 name = GUARANTEED_STRING_ARG(prim->name, 0); | |
14 | 1732 |
1733 if (argc > 1) | |
1734 { | |
1735 if (M_global == NULL) | |
1736 { | |
1737 MZ_REGISTER_STATIC(M_global); | |
1738 M_global = scheme_intern_symbol("global"); | |
1894 | 1739 MZ_GC_CHECK(); |
14 | 1740 } |
1741 | |
1742 if (argv[1] == M_global) | |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
25475
diff
changeset
|
1743 scope = OPT_GLOBAL; |
14 | 1744 else if (SCHEME_VIMBUFFERP(argv[1])) |
1745 { | |
1746 curbuf = get_valid_buffer(argv[1]); | |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
25475
diff
changeset
|
1747 scope = OPT_LOCAL; |
14 | 1748 } |
1749 else if (SCHEME_VIMWINDOWP(argv[1])) | |
1750 { | |
1751 win_T *win = get_valid_window(argv[1]); | |
1752 | |
1753 curwin = win; | |
1754 curbuf = win->w_buffer; | |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
25475
diff
changeset
|
1755 scope = OPT_LOCAL; |
14 | 1756 } |
1757 else | |
1758 scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv); | |
1759 } | |
1760 | |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
21745
diff
changeset
|
1761 rc = get_option_value(BYTE_STRING_VALUE(name), &value, (char_u **)&strval, |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
25475
diff
changeset
|
1762 NULL, scope); |
14 | 1763 curbuf = save_curb; |
1764 curwin = save_curw; | |
1765 | |
1766 switch (rc) | |
1767 { | |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
21745
diff
changeset
|
1768 case gov_bool: |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
21745
diff
changeset
|
1769 case gov_number: |
4074 | 1770 MZ_GC_UNREG(); |
14 | 1771 return scheme_make_integer_value(value); |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
21745
diff
changeset
|
1772 case gov_string: |
4074 | 1773 rval = scheme_make_byte_string(strval); |
1894 | 1774 MZ_GC_CHECK(); |
14 | 1775 vim_free(strval); |
4074 | 1776 MZ_GC_UNREG(); |
14 | 1777 return rval; |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
21745
diff
changeset
|
1778 case gov_hidden_bool: |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
21745
diff
changeset
|
1779 case gov_hidden_number: |
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
21745
diff
changeset
|
1780 case gov_hidden_string: |
4074 | 1781 MZ_GC_UNREG(); |
856 | 1782 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
|
1783 //NOTREACHED |
23422
bb0c53f4ef8b
patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents:
21745
diff
changeset
|
1784 case gov_unknown: |
4074 | 1785 MZ_GC_UNREG(); |
856 | 1786 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
|
1787 //NOTREACHED |
14 | 1788 } |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1789 // unreachable |
14 | 1790 return scheme_void; |
1791 } | |
1792 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1793 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1794 * (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
|
1795 */ |
14 | 1796 static Scheme_Object * |
1797 set_option(void *data, int argc, Scheme_Object **argv) | |
1798 { | |
4074 | 1799 char_u *command = NULL; |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
25475
diff
changeset
|
1800 int scope = 0; |
14 | 1801 buf_T *save_curb = curbuf; |
1802 win_T *save_curw = curwin; | |
1803 Vim_Prim *prim = (Vim_Prim *)data; | |
4074 | 1804 Scheme_Object *cmd = NULL; |
1805 | |
1806 MZ_GC_DECL_REG(1); | |
1807 MZ_GC_VAR_IN_REG(0, cmd); | |
1808 MZ_GC_REG(); | |
1809 cmd = GUARANTEED_STRING_ARG(prim->name, 0); | |
1810 | |
14 | 1811 if (argc > 1) |
1812 { | |
1813 if (M_global == NULL) | |
1814 { | |
1815 MZ_REGISTER_STATIC(M_global); | |
1816 M_global = scheme_intern_symbol("global"); | |
1894 | 1817 MZ_GC_CHECK(); |
14 | 1818 } |
1819 | |
1820 if (argv[1] == M_global) | |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
25475
diff
changeset
|
1821 scope = OPT_GLOBAL; |
14 | 1822 else if (SCHEME_VIMBUFFERP(argv[1])) |
1823 { | |
1824 curbuf = get_valid_buffer(argv[1]); | |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
25475
diff
changeset
|
1825 scope = OPT_LOCAL; |
14 | 1826 } |
1827 else if (SCHEME_VIMWINDOWP(argv[1])) | |
1828 { | |
1829 win_T *win = get_valid_window(argv[1]); | |
1830 curwin = win; | |
1831 curbuf = win->w_buffer; | |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
25475
diff
changeset
|
1832 scope = OPT_LOCAL; |
14 | 1833 } |
1834 else | |
1835 scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv); | |
1836 } | |
1837 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1838 // do_set can modify cmd, make copy |
4074 | 1839 command = vim_strsave(BYTE_STRING_VALUE(cmd)); |
1840 MZ_GC_UNREG(); | |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
25475
diff
changeset
|
1841 do_set(command, scope); |
4074 | 1842 vim_free(command); |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
28303
diff
changeset
|
1843 update_screen(UPD_NOT_VALID); |
14 | 1844 curbuf = save_curb; |
1845 curwin = save_curw; | |
1846 raise_if_error(); | |
1847 return scheme_void; | |
1848 } | |
1849 | |
1850 /* | |
1851 *=========================================================================== | |
1852 * 5. Vim Window-related Manipulation Functions | |
1853 *=========================================================================== | |
1854 */ | |
1855 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1856 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1857 * (curr-win) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1858 */ |
14 | 1859 static Scheme_Object * |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1860 get_curr_win(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1861 { |
1862 return (Scheme_Object *)get_vim_curr_window(); | |
1863 } | |
1864 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1865 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1866 * (win-count) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1867 */ |
14 | 1868 static Scheme_Object * |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
1869 get_window_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1870 { |
4082 | 1871 int n = 0; |
14 | 1872 win_T *w; |
1873 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9289
diff
changeset
|
1874 FOR_ALL_WINDOWS(w) |
671 | 1875 ++n; |
14 | 1876 return scheme_make_integer(n); |
1877 } | |
1878 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1879 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1880 * (get-win-list [buffer]) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1881 */ |
14 | 1882 static Scheme_Object * |
1883 get_window_list(void *data, int argc, Scheme_Object **argv) | |
1884 { | |
1885 Vim_Prim *prim = (Vim_Prim *)data; | |
1886 vim_mz_buffer *buf; | |
1887 Scheme_Object *list; | |
4082 | 1888 win_T *w = firstwin; |
14 | 1889 |
1890 buf = get_buffer_arg(prim->name, 0, argc, argv); | |
1891 list = scheme_null; | |
1892 | |
4082 | 1893 for ( ; w != NULL; w = w->w_next) |
856 | 1894 if (w->w_buffer == buf->buf) |
1894 | 1895 { |
14 | 1896 list = scheme_make_pair(window_new(w), list); |
1894 | 1897 MZ_GC_CHECK(); |
1898 } | |
14 | 1899 |
1900 return list; | |
1901 } | |
1902 | |
1903 static Scheme_Object * | |
1904 window_new(win_T *win) | |
1905 { | |
1894 | 1906 vim_mz_window *self = NULL; |
1907 | |
1908 MZ_GC_DECL_REG(1); | |
1909 MZ_GC_VAR_IN_REG(0, self); | |
14 | 1910 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1911 // 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
|
1912 // 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
|
1913 // 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
|
1914 // |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1915 // 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
|
1916 // 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
|
1917 // object, and reject them if the win_T *field is invalid. |
502 | 1918 if (win->w_mzscheme_ref != NULL) |
4074 | 1919 return (Scheme_Object *)WINDOW_REF(win); |
1920 | |
1921 MZ_GC_REG(); | |
1922 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
|
1923 CLEAR_POINTER(self); |
4074 | 1924 #ifndef MZ_PRECISE_GC |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1925 scheme_dont_gc_ptr(self); // because win isn't visible to GC |
4074 | 1926 #else |
1927 win->w_mzscheme_ref = scheme_malloc_immobile_box(NULL); | |
1928 #endif | |
1894 | 1929 MZ_GC_CHECK(); |
4074 | 1930 WINDOW_REF(win) = self; |
1931 MZ_GC_CHECK(); | |
14 | 1932 self->win = win; |
1894 | 1933 self->so.type = mz_window_type; |
1934 | |
1935 MZ_GC_UNREG(); | |
4074 | 1936 return (Scheme_Object *)self; |
14 | 1937 } |
1938 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1939 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1940 * (get-win-num [window]) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1941 */ |
14 | 1942 static Scheme_Object * |
4082 | 1943 get_window_num(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 1944 { |
4082 | 1945 int nr = 1; |
14 | 1946 Vim_Prim *prim = (Vim_Prim *)data; |
1947 win_T *win = get_window_arg(prim->name, 0, argc, argv)->win; | |
1948 win_T *wp; | |
1949 | |
1950 for (wp = firstwin; wp != win; wp = wp->w_next) | |
1951 ++nr; | |
1952 | |
1953 return scheme_make_integer(nr); | |
1954 } | |
1955 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1956 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1957 * (get-win-by-num {windownum}) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1958 */ |
14 | 1959 static Scheme_Object * |
1960 get_window_by_num(void *data, int argc, Scheme_Object **argv) | |
1961 { | |
1962 Vim_Prim *prim = (Vim_Prim *)data; | |
4082 | 1963 win_T *win = firstwin; |
14 | 1964 int fnum; |
1965 | |
1966 fnum = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
1967 if (fnum < 1) | |
1968 scheme_signal_error(_("window index is out of range")); | |
1969 | |
4082 | 1970 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
|
1971 if (fnum == 1) // to be 1-based |
14 | 1972 return window_new(win); |
1973 | |
1974 return scheme_false; | |
1975 } | |
1976 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1977 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1978 * (get-win-buffer [window]) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1979 */ |
14 | 1980 static Scheme_Object * |
1981 get_window_buffer(void *data, int argc, Scheme_Object **argv) | |
1982 { | |
1983 Vim_Prim *prim = (Vim_Prim *)data; | |
1984 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv); | |
1985 | |
1986 return buffer_new(win->win->w_buffer); | |
1987 } | |
1988 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1989 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1990 * (get-win-height [window]) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1991 */ |
14 | 1992 static Scheme_Object * |
1993 get_window_height(void *data, int argc, Scheme_Object **argv) | |
1994 { | |
1995 Vim_Prim *prim = (Vim_Prim *)data; | |
1996 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv); | |
1997 | |
1998 return scheme_make_integer(win->win->w_height); | |
1999 } | |
2000 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2001 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2002 * (set-win-height {height} [window]) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2003 */ |
14 | 2004 static Scheme_Object * |
2005 set_window_height(void *data, int argc, Scheme_Object **argv) | |
2006 { | |
2007 Vim_Prim *prim = (Vim_Prim *)data; | |
2008 vim_mz_window *win; | |
2009 win_T *savewin; | |
2010 int height; | |
2011 | |
2012 win = get_window_arg(prim->name, 1, argc, argv); | |
2013 height = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
2014 | |
2015 #ifdef FEAT_GUI | |
2016 need_mouse_correct = TRUE; | |
2017 #endif | |
2018 | |
2019 savewin = curwin; | |
2020 curwin = win->win; | |
2021 win_setheight(height); | |
2022 curwin = savewin; | |
2023 | |
2024 raise_if_error(); | |
2025 return scheme_void; | |
2026 } | |
2027 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2028 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2029 * (get-win-width [window]) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2030 */ |
14 | 2031 static Scheme_Object * |
2032 get_window_width(void *data, int argc, Scheme_Object **argv) | |
2033 { | |
2034 Vim_Prim *prim = (Vim_Prim *)data; | |
2035 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv); | |
2036 | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2037 return scheme_make_integer(win->win->w_width); |
14 | 2038 } |
2039 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2040 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2041 * (set-win-width {width} [window]) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2042 */ |
14 | 2043 static Scheme_Object * |
2044 set_window_width(void *data, int argc, Scheme_Object **argv) | |
2045 { | |
2046 Vim_Prim *prim = (Vim_Prim *)data; | |
2047 vim_mz_window *win; | |
2048 win_T *savewin; | |
2049 int width = 0; | |
2050 | |
2051 win = get_window_arg(prim->name, 1, argc, argv); | |
2052 width = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
2053 | |
2054 # ifdef FEAT_GUI | |
2055 need_mouse_correct = TRUE; | |
2056 # endif | |
2057 | |
2058 savewin = curwin; | |
2059 curwin = win->win; | |
2060 win_setwidth(width); | |
2061 curwin = savewin; | |
2062 | |
2063 raise_if_error(); | |
2064 return scheme_void; | |
2065 } | |
2066 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2067 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2068 * (get-cursor [window]) -> (line . col) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2069 */ |
14 | 2070 static Scheme_Object * |
2071 get_cursor(void *data, int argc, Scheme_Object **argv) | |
2072 { | |
2073 Vim_Prim *prim = (Vim_Prim *)data; | |
2074 vim_mz_window *win; | |
2075 pos_T pos; | |
2076 | |
2077 win = get_window_arg(prim->name, 0, argc, argv); | |
2078 pos = win->win->w_cursor; | |
2079 return scheme_make_pair(scheme_make_integer_value((long)pos.lnum), | |
2080 scheme_make_integer_value((long)pos.col + 1)); | |
2081 } | |
2082 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2083 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2084 * (set-cursor (line . col) [window]) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2085 */ |
14 | 2086 static Scheme_Object * |
2087 set_cursor(void *data, int argc, Scheme_Object **argv) | |
2088 { | |
2089 Vim_Prim *prim = (Vim_Prim *)data; | |
2090 vim_mz_window *win; | |
2091 long lnum = 0; | |
2092 long col = 0; | |
2093 | |
274 | 2094 #ifdef HAVE_SANDBOX |
2095 sandbox_check(); | |
2096 #endif | |
14 | 2097 win = get_window_arg(prim->name, 1, argc, argv); |
2098 GUARANTEE_PAIR(prim->name, 0); | |
2099 | |
2100 if (!SCHEME_INTP(SCHEME_CAR(argv[0])) | |
2101 || !SCHEME_INTP(SCHEME_CDR(argv[0]))) | |
2102 scheme_wrong_type(prim->name, "integer pair", 0, argc, argv); | |
2103 | |
2104 lnum = SCHEME_INT_VAL(SCHEME_CAR(argv[0])); | |
2105 col = SCHEME_INT_VAL(SCHEME_CDR(argv[0])) - 1; | |
2106 | |
2107 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
|
2108 // don't know how to catch invalid column value |
14 | 2109 |
2110 win->win->w_cursor.lnum = lnum; | |
2111 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
|
2112 win->win->w_set_curswant = TRUE; |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
28303
diff
changeset
|
2113 update_screen(UPD_VALID); |
14 | 2114 |
2115 raise_if_error(); | |
2116 return scheme_void; | |
2117 } | |
2118 /* | |
2119 *=========================================================================== | |
2120 * 6. Vim Buffer-related Manipulation Functions | |
2121 *=========================================================================== | |
2122 */ | |
2123 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2124 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2125 * (open-buff {filename}) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2126 */ |
14 | 2127 static Scheme_Object * |
2128 mzscheme_open_buffer(void *data, int argc, Scheme_Object **argv) | |
2129 { | |
2130 Vim_Prim *prim = (Vim_Prim *)data; | |
2131 int num = 0; | |
4074 | 2132 Scheme_Object *onum = NULL; |
2133 Scheme_Object *buf = NULL; | |
2134 Scheme_Object *fname; | |
2135 | |
2136 MZ_GC_DECL_REG(3); | |
2137 MZ_GC_VAR_IN_REG(0, onum); | |
2138 MZ_GC_VAR_IN_REG(1, buf); | |
2139 MZ_GC_VAR_IN_REG(2, fname); | |
2140 MZ_GC_REG(); | |
2141 fname = GUARANTEED_STRING_ARG(prim->name, 0); | |
14 | 2142 |
274 | 2143 #ifdef HAVE_SANDBOX |
2144 sandbox_check(); | |
2145 #endif | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2146 // TODO make open existing file |
4074 | 2147 num = buflist_add(BYTE_STRING_VALUE(fname), BLN_LISTED | BLN_CURBUF); |
14 | 2148 |
2149 if (num == 0) | |
2150 raise_vim_exn(_("couldn't open buffer")); | |
2151 | |
2152 onum = scheme_make_integer(num); | |
4074 | 2153 buf = get_buffer_by_num(data, 1, &onum); |
2154 MZ_GC_UNREG(); | |
2155 return buf; | |
14 | 2156 } |
2157 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2158 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2159 * (get-buff-by-num {buffernum}) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2160 */ |
14 | 2161 static Scheme_Object * |
2162 get_buffer_by_num(void *data, int argc, Scheme_Object **argv) | |
2163 { | |
2164 Vim_Prim *prim = (Vim_Prim *)data; | |
2165 buf_T *buf; | |
2166 int fnum; | |
2167 | |
2168 fnum = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
2169 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9289
diff
changeset
|
2170 FOR_ALL_BUFFERS(buf) |
856 | 2171 if (buf->b_fnum == fnum) |
14 | 2172 return buffer_new(buf); |
2173 | |
2174 return scheme_false; | |
2175 } | |
2176 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2177 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2178 * (get-buff-by-name {buffername}) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2179 */ |
14 | 2180 static Scheme_Object * |
2181 get_buffer_by_name(void *data, int argc, Scheme_Object **argv) | |
2182 { | |
2183 Vim_Prim *prim = (Vim_Prim *)data; | |
2184 buf_T *buf; | |
4074 | 2185 Scheme_Object *buffer = NULL; |
2186 Scheme_Object *fname = NULL; | |
2187 | |
2188 MZ_GC_DECL_REG(2); | |
2189 MZ_GC_VAR_IN_REG(0, buffer); | |
2190 MZ_GC_VAR_IN_REG(1, fname); | |
2191 MZ_GC_REG(); | |
2192 fname = GUARANTEED_STRING_ARG(prim->name, 0); | |
2193 buffer = scheme_false; | |
14 | 2194 |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9289
diff
changeset
|
2195 FOR_ALL_BUFFERS(buf) |
4074 | 2196 { |
14 | 2197 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
|
2198 // empty string |
14 | 2199 { |
4074 | 2200 if (BYTE_STRING_VALUE(fname)[0] == NUL) |
2201 buffer = buffer_new(buf); | |
14 | 2202 } |
4074 | 2203 else if (!fnamecmp(buf->b_ffname, BYTE_STRING_VALUE(fname)) |
2204 || !fnamecmp(buf->b_sfname, BYTE_STRING_VALUE(fname))) | |
2205 { | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2206 // either short or long filename matches |
4074 | 2207 buffer = buffer_new(buf); |
2208 } | |
2209 } | |
2210 | |
2211 MZ_GC_UNREG(); | |
2212 return buffer; | |
14 | 2213 } |
2214 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2215 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2216 * (get-next-buff [buffer]) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2217 */ |
14 | 2218 static Scheme_Object * |
2219 get_next_buffer(void *data, int argc, Scheme_Object **argv) | |
2220 { | |
2221 Vim_Prim *prim = (Vim_Prim *)data; | |
2222 buf_T *buf = get_buffer_arg(prim->name, 0, argc, argv)->buf; | |
2223 | |
2224 if (buf->b_next == NULL) | |
2225 return scheme_false; | |
2226 else | |
2227 return buffer_new(buf->b_next); | |
2228 } | |
2229 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2230 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2231 * (get-prev-buff [buffer]) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2232 */ |
14 | 2233 static Scheme_Object * |
2234 get_prev_buffer(void *data, int argc, Scheme_Object **argv) | |
2235 { | |
2236 Vim_Prim *prim = (Vim_Prim *)data; | |
2237 buf_T *buf = get_buffer_arg(prim->name, 0, argc, argv)->buf; | |
2238 | |
2239 if (buf->b_prev == NULL) | |
2240 return scheme_false; | |
2241 else | |
2242 return buffer_new(buf->b_prev); | |
2243 } | |
2244 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2245 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2246 * (get-buff-num [buffer]) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2247 */ |
14 | 2248 static Scheme_Object * |
2249 get_buffer_num(void *data, int argc, Scheme_Object **argv) | |
2250 { | |
2251 Vim_Prim *prim = (Vim_Prim *)data; | |
2252 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv); | |
2253 | |
2254 return scheme_make_integer(buf->buf->b_fnum); | |
2255 } | |
2256 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2257 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2258 * (buff-count) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2259 */ |
14 | 2260 static Scheme_Object * |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
2261 get_buffer_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 2262 { |
2263 buf_T *b; | |
2264 int n = 0; | |
2265 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9289
diff
changeset
|
2266 FOR_ALL_BUFFERS(b) ++n; |
14 | 2267 return scheme_make_integer(n); |
2268 } | |
2269 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2270 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2271 * (get-buff-name [buffer]) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2272 */ |
14 | 2273 static Scheme_Object * |
2274 get_buffer_name(void *data, int argc, Scheme_Object **argv) | |
2275 { | |
2276 Vim_Prim *prim = (Vim_Prim *)data; | |
2277 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv); | |
2278 | |
4074 | 2279 return scheme_make_byte_string((char *)buf->buf->b_ffname); |
14 | 2280 } |
2281 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2282 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2283 * (curr-buff) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2284 */ |
14 | 2285 static Scheme_Object * |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
2286 get_curr_buffer(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) |
14 | 2287 { |
2288 return (Scheme_Object *)get_vim_curr_buffer(); | |
2289 } | |
2290 | |
2291 static Scheme_Object * | |
2292 buffer_new(buf_T *buf) | |
2293 { | |
1894 | 2294 vim_mz_buffer *self = NULL; |
2295 | |
2296 MZ_GC_DECL_REG(1); | |
2297 MZ_GC_VAR_IN_REG(0, self); | |
14 | 2298 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2299 // 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
|
2300 // 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
|
2301 // then we can get at it in buf_freeall() in vim. |
502 | 2302 if (buf->b_mzscheme_ref) |
4074 | 2303 return (Scheme_Object *)BUFFER_REF(buf); |
2304 | |
2305 MZ_GC_REG(); | |
2306 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
|
2307 CLEAR_POINTER(self); |
4074 | 2308 #ifndef MZ_PRECISE_GC |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2309 scheme_dont_gc_ptr(self); // because buf isn't visible to GC |
4074 | 2310 #else |
2311 buf->b_mzscheme_ref = scheme_malloc_immobile_box(NULL); | |
2312 #endif | |
1894 | 2313 MZ_GC_CHECK(); |
4074 | 2314 BUFFER_REF(buf) = self; |
2315 MZ_GC_CHECK(); | |
14 | 2316 self->buf = buf; |
1894 | 2317 self->so.type = mz_buffer_type; |
2318 | |
2319 MZ_GC_UNREG(); | |
4074 | 2320 return (Scheme_Object *)self; |
14 | 2321 } |
2322 | |
2323 /* | |
2324 * (get-buff-size [buffer]) | |
2325 * | |
2326 * Get the size (number of lines) in the current buffer. | |
2327 */ | |
2328 static Scheme_Object * | |
2329 get_buffer_size(void *data, int argc, Scheme_Object **argv) | |
2330 { | |
2331 Vim_Prim *prim = (Vim_Prim *)data; | |
2332 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv); | |
2333 | |
2334 return scheme_make_integer(buf->buf->b_ml.ml_line_count); | |
2335 } | |
2336 | |
2337 /* | |
2338 * (get-buff-line {linenr} [buffer]) | |
2339 * | |
2340 * Get a line from the specified buffer. The line number is | |
2341 * in Vim format (1-based). The line is returned as a MzScheme | |
2342 * string object. | |
2343 */ | |
2344 static Scheme_Object * | |
2345 get_buffer_line(void *data, int argc, Scheme_Object **argv) | |
2346 { | |
2347 Vim_Prim *prim = (Vim_Prim *)data; | |
2348 vim_mz_buffer *buf; | |
2349 int linenr; | |
1894 | 2350 char_u *line; |
14 | 2351 |
2352 buf = get_buffer_arg(prim->name, 1, argc, argv); | |
2353 linenr = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
2354 line = ml_get_buf(buf->buf, (linenr_T)linenr, FALSE); | |
2355 | |
2356 raise_if_error(); | |
4074 | 2357 return scheme_make_byte_string((char *)line); |
14 | 2358 } |
2359 | |
2360 | |
2361 /* | |
2362 * (get-buff-line-list {start} {end} [buffer]) | |
2363 * | |
2364 * Get a list of lines from the specified buffer. The line numbers | |
2365 * are in Vim format (1-based). The range is from lo up to, but not | |
2366 * including, hi. The list is returned as a list of string objects. | |
2367 */ | |
2368 static Scheme_Object * | |
2369 get_buffer_line_list(void *data, int argc, Scheme_Object **argv) | |
2370 { | |
2371 Vim_Prim *prim = (Vim_Prim *)data; | |
2372 vim_mz_buffer *buf; | |
2373 int i, hi, lo, n; | |
1894 | 2374 Scheme_Object *list = NULL; |
2375 | |
2376 MZ_GC_DECL_REG(1); | |
2377 MZ_GC_VAR_IN_REG(0, list); | |
2378 MZ_GC_REG(); | |
14 | 2379 |
2380 buf = get_buffer_arg(prim->name, 2, argc, argv); | |
2381 list = scheme_null; | |
2382 hi = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 1)); | |
2383 lo = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
2384 | |
2385 /* | |
2386 * Handle some error conditions | |
2387 */ | |
2388 if (lo < 0) | |
856 | 2389 lo = 0; |
14 | 2390 |
2391 if (hi < 0) | |
2392 hi = 0; | |
2393 if (hi < lo) | |
856 | 2394 hi = lo; |
14 | 2395 |
2396 n = hi - lo; | |
2397 | |
2398 for (i = n; i >= 0; --i) | |
2399 { | |
4074 | 2400 Scheme_Object *str = scheme_make_byte_string( |
14 | 2401 (char *)ml_get_buf(buf->buf, (linenr_T)(lo+i), FALSE)); |
2402 raise_if_error(); | |
2403 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2404 // Set the list item |
14 | 2405 list = scheme_make_pair(str, list); |
1894 | 2406 MZ_GC_CHECK(); |
14 | 2407 } |
1894 | 2408 MZ_GC_UNREG(); |
14 | 2409 return list; |
2410 } | |
2411 | |
2412 /* | |
2413 * (set-buff-line {linenr} {string/#f} [buffer]) | |
2414 * | |
2415 * Replace a line in the specified buffer. The line number is | |
2416 * in Vim format (1-based). The replacement line is given as | |
2417 * an MzScheme string object. The object is checked for validity | |
2418 * and correct format. An exception is thrown if the values are not | |
2419 * the correct format. | |
2420 * | |
2421 * It returns a Scheme Object that indicates the length of the | |
2422 * string changed. | |
2423 */ | |
2424 static Scheme_Object * | |
2425 set_buffer_line(void *data, int argc, Scheme_Object **argv) | |
2426 { | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2427 // 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
|
2428 // There are three cases: |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2429 // 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
|
2430 // 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
|
2431 // 3. Anything else - this is an error. |
14 | 2432 Vim_Prim *prim = (Vim_Prim *)data; |
2433 vim_mz_buffer *buf; | |
1894 | 2434 Scheme_Object *line = NULL; |
14 | 2435 char *save; |
2436 int n; | |
2437 | |
1894 | 2438 MZ_GC_DECL_REG(1); |
2439 MZ_GC_VAR_IN_REG(0, line); | |
2440 MZ_GC_REG(); | |
2441 | |
274 | 2442 #ifdef HAVE_SANDBOX |
2443 sandbox_check(); | |
2444 #endif | |
14 | 2445 n = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); |
2446 if (!SCHEME_STRINGP(argv[1]) && !SCHEME_FALSEP(argv[1])) | |
856 | 2447 scheme_wrong_type(prim->name, "string or #f", 1, argc, argv); |
14 | 2448 line = argv[1]; |
2449 buf = get_buffer_arg(prim->name, 2, argc, argv); | |
2450 | |
2451 check_line_range(n, buf->buf); | |
2452 | |
2453 if (SCHEME_FALSEP(line)) | |
2454 { | |
1894 | 2455 buf_T *savebuf = curbuf; |
2456 | |
14 | 2457 curbuf = buf->buf; |
2458 | |
2459 if (u_savedel((linenr_T)n, 1L) == FAIL) | |
2460 { | |
2461 curbuf = savebuf; | |
2462 raise_vim_exn(_("cannot save undo information")); | |
2463 } | |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2464 else if (ml_delete((linenr_T)n) == FAIL) |
14 | 2465 { |
2466 curbuf = savebuf; | |
2467 raise_vim_exn(_("cannot delete line")); | |
2468 } | |
2469 if (buf->buf == curwin->w_buffer) | |
2470 mz_fix_cursor(n, n + 1, -1); | |
1929 | 2471 deleted_lines_mark((linenr_T)n, 1L); |
14 | 2472 |
2473 curbuf = savebuf; | |
2474 | |
1894 | 2475 MZ_GC_UNREG(); |
14 | 2476 raise_if_error(); |
2477 return scheme_void; | |
2478 } | |
1894 | 2479 else |
14 | 2480 { |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2481 // Otherwise it's a line |
1894 | 2482 buf_T *savebuf = curbuf; |
2483 | |
2484 save = string_to_line(line); | |
2485 | |
2486 curbuf = buf->buf; | |
2487 | |
2488 if (u_savesub((linenr_T)n) == FAIL) | |
2489 { | |
2490 curbuf = savebuf; | |
2491 vim_free(save); | |
2492 raise_vim_exn(_("cannot save undo information")); | |
2493 } | |
2494 else if (ml_replace((linenr_T)n, (char_u *)save, TRUE) == FAIL) | |
2495 { | |
2496 curbuf = savebuf; | |
2497 vim_free(save); | |
2498 raise_vim_exn(_("cannot replace line")); | |
2499 } | |
2500 else | |
2501 { | |
2502 vim_free(save); | |
2503 changed_bytes((linenr_T)n, 0); | |
2504 } | |
2505 | |
14 | 2506 curbuf = savebuf; |
1894 | 2507 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2508 // Check that the cursor is not beyond the end of the line now. |
1894 | 2509 if (buf->buf == curwin->w_buffer) |
2510 check_cursor_col(); | |
2511 | |
2512 MZ_GC_UNREG(); | |
2513 raise_if_error(); | |
2514 return scheme_void; | |
14 | 2515 } |
1894 | 2516 } |
2517 | |
2518 static void | |
2519 free_array(char **array) | |
2520 { | |
2521 char **curr = array; | |
2522 while (*curr != NULL) | |
2523 vim_free(*curr++); | |
2524 vim_free(array); | |
14 | 2525 } |
2526 | |
2527 /* | |
2528 * (set-buff-line-list {start} {end} {string-list/#f/null} [buffer]) | |
2529 * | |
2530 * Replace a range of lines in the specified buffer. The line numbers are in | |
2531 * Vim format (1-based). The range is from lo up to, but not including, hi. | |
2532 * The replacement lines are given as a Scheme list of string objects. The | |
2533 * list is checked for validity and correct format. | |
2534 * | |
2535 * Errors are returned as a value of FAIL. The return value is OK on success. | |
2536 * If OK is returned and len_change is not NULL, *len_change is set to the | |
2537 * change in the buffer length. | |
2538 */ | |
2539 static Scheme_Object * | |
2540 set_buffer_line_list(void *data, int argc, Scheme_Object **argv) | |
2541 { | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2542 // 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
|
2543 // There are three cases: |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2544 // 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
|
2545 // 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
|
2546 // 3. Anything else - this is an error. |
14 | 2547 Vim_Prim *prim = (Vim_Prim *)data; |
1894 | 2548 vim_mz_buffer *buf = NULL; |
2549 Scheme_Object *line_list = NULL; | |
14 | 2550 int i, old_len, new_len, hi, lo; |
2551 long extra; | |
2552 | |
1894 | 2553 MZ_GC_DECL_REG(1); |
2554 MZ_GC_VAR_IN_REG(0, line_list); | |
2555 MZ_GC_REG(); | |
2556 | |
274 | 2557 #ifdef HAVE_SANDBOX |
2558 sandbox_check(); | |
2559 #endif | |
14 | 2560 lo = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); |
2561 hi = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 1)); | |
2562 if (!SCHEME_PAIRP(argv[2]) | |
2563 && !SCHEME_FALSEP(argv[2]) && !SCHEME_NULLP(argv[2])) | |
2564 scheme_wrong_type(prim->name, "list or #f", 2, argc, argv); | |
2565 line_list = argv[2]; | |
2566 buf = get_buffer_arg(prim->name, 3, argc, argv); | |
2567 old_len = hi - lo; | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2568 if (old_len < 0) // process inverse values wisely |
14 | 2569 { |
2570 i = lo; | |
2571 lo = hi; | |
2572 hi = i; | |
2573 old_len = -old_len; | |
2574 } | |
2575 extra = 0; | |
2576 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2577 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
|
2578 check_line_range(hi - 1, buf->buf); // exclusive |
14 | 2579 |
2580 if (SCHEME_FALSEP(line_list) || SCHEME_NULLP(line_list)) | |
2581 { | |
1894 | 2582 buf_T *savebuf = curbuf; |
14 | 2583 curbuf = buf->buf; |
2584 | |
2585 if (u_savedel((linenr_T)lo, (long)old_len) == FAIL) | |
2586 { | |
2587 curbuf = savebuf; | |
2588 raise_vim_exn(_("cannot save undo information")); | |
2589 } | |
2590 else | |
2591 { | |
2592 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
|
2593 if (ml_delete((linenr_T)lo) == FAIL) |
14 | 2594 { |
2595 curbuf = savebuf; | |
2596 raise_vim_exn(_("cannot delete line")); | |
2597 } | |
2598 if (buf->buf == curwin->w_buffer) | |
2599 mz_fix_cursor(lo, hi, -old_len); | |
1929 | 2600 deleted_lines_mark((linenr_T)lo, (long)old_len); |
14 | 2601 } |
2602 | |
2603 curbuf = savebuf; | |
2604 | |
1894 | 2605 MZ_GC_UNREG(); |
14 | 2606 raise_if_error(); |
2607 return scheme_void; | |
2608 } | |
1894 | 2609 else |
14 | 2610 { |
1894 | 2611 buf_T *savebuf = curbuf; |
2612 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2613 // List |
1894 | 2614 new_len = scheme_proper_list_length(line_list); |
2615 MZ_GC_CHECK(); | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2616 if (new_len < 0) // improper or cyclic list |
1894 | 2617 scheme_wrong_type(prim->name, "proper list", |
2618 2, argc, argv); | |
2619 else | |
14 | 2620 { |
1894 | 2621 char **array = NULL; |
2622 Scheme_Object *line = NULL; | |
2623 Scheme_Object *rest = NULL; | |
2624 | |
2625 MZ_GC_DECL_REG(2); | |
2626 MZ_GC_VAR_IN_REG(0, line); | |
2627 MZ_GC_VAR_IN_REG(1, rest); | |
2628 MZ_GC_REG(); | |
2629 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2630 array = ALLOC_CLEAR_MULT(char *, new_len + 1); |
1894 | 2631 |
2632 rest = line_list; | |
2633 for (i = 0; i < new_len; ++i) | |
2634 { | |
2635 line = SCHEME_CAR(rest); | |
2636 rest = SCHEME_CDR(rest); | |
2637 if (!SCHEME_STRINGP(line)) | |
2638 { | |
2639 free_array(array); | |
2640 scheme_wrong_type(prim->name, "string-list", 2, argc, argv); | |
2641 } | |
2642 array[i] = string_to_line(line); | |
2643 } | |
2644 | |
2645 curbuf = buf->buf; | |
2646 | |
2647 if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL) | |
2648 { | |
2649 curbuf = savebuf; | |
2650 free_array(array); | |
2651 raise_vim_exn(_("cannot save undo information")); | |
2652 } | |
2653 | |
2654 /* | |
2655 * If the size of the range is reducing (ie, new_len < old_len) we | |
2656 * need to delete some old_len. We do this at the start, by | |
2657 * repeatedly deleting line "lo". | |
2658 */ | |
2659 for (i = 0; i < old_len - new_len; ++i) | |
2660 { | |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2661 if (ml_delete((linenr_T)lo) == FAIL) |
1894 | 2662 { |
2663 curbuf = savebuf; | |
2664 free_array(array); | |
2665 raise_vim_exn(_("cannot delete line")); | |
2666 } | |
2667 extra--; | |
2668 } | |
2669 | |
2670 /* | |
2671 * For as long as possible, replace the existing old_len with the | |
2672 * new old_len. This is a more efficient operation, as it requires | |
2673 * less memory allocation and freeing. | |
2674 */ | |
2675 for (i = 0; i < old_len && i < new_len; i++) | |
2676 if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], TRUE) == FAIL) | |
2677 { | |
2678 curbuf = savebuf; | |
2679 free_array(array); | |
2680 raise_vim_exn(_("cannot replace line")); | |
2681 } | |
2682 | |
2683 /* | |
2684 * Now we may need to insert the remaining new_len. We don't need to | |
2685 * free the string passed back because MzScheme has control of that | |
2686 * memory. | |
2687 */ | |
2688 while (i < new_len) | |
2689 { | |
2690 if (ml_append((linenr_T)(lo + i - 1), | |
2691 (char_u *)array[i], 0, FALSE) == FAIL) | |
2692 { | |
2693 curbuf = savebuf; | |
2694 free_array(array); | |
2695 raise_vim_exn(_("cannot insert line")); | |
2696 } | |
2697 ++i; | |
2698 ++extra; | |
2699 } | |
2700 MZ_GC_UNREG(); | |
2701 free_array(array); | |
14 | 2702 } |
1894 | 2703 |
2704 /* | |
2705 * Adjust marks. Invalidate any which lie in the | |
2706 * changed range, and move any in the remainder of the buffer. | |
2707 */ | |
9228
ea504064c996
commit https://github.com/vim/vim/commit/fd89d7ea81b18d32363456b16258174dc9e095dc
Christian Brabandt <cb@256bit.org>
parents:
9173
diff
changeset
|
2708 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
|
2709 (long)MAXLNUM, (long)extra); |
1894 | 2710 changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra); |
2711 | |
2712 if (buf->buf == curwin->w_buffer) | |
2713 mz_fix_cursor(lo, hi, extra); | |
2714 curbuf = savebuf; | |
2715 | |
2716 MZ_GC_UNREG(); | |
2717 raise_if_error(); | |
2718 return scheme_void; | |
14 | 2719 } |
2720 } | |
2721 | |
2722 /* | |
2723 * (insert-buff-line-list {linenr} {string/string-list} [buffer]) | |
2724 * | |
2023 | 2725 * Insert a number of lines into the specified buffer after the specified line. |
14 | 2726 * The line number is in Vim format (1-based). The lines to be inserted are |
2727 * given as an MzScheme list of string objects or as a single string. The lines | |
2728 * to be added are checked for validity and correct format. Errors are | |
2729 * returned as a value of FAIL. The return value is OK on success. | |
2730 * If OK is returned and len_change is not NULL, *len_change | |
2731 * is set to the change in the buffer length. | |
2732 */ | |
2733 static Scheme_Object * | |
2734 insert_buffer_line_list(void *data, int argc, Scheme_Object **argv) | |
2735 { | |
2736 Vim_Prim *prim = (Vim_Prim *)data; | |
1894 | 2737 vim_mz_buffer *buf = NULL; |
2738 Scheme_Object *list = NULL; | |
2739 char *str = NULL; | |
14 | 2740 int i, n, size; |
2741 | |
1894 | 2742 MZ_GC_DECL_REG(1); |
2743 MZ_GC_VAR_IN_REG(0, list); | |
2744 MZ_GC_REG(); | |
2745 | |
274 | 2746 #ifdef HAVE_SANDBOX |
2747 sandbox_check(); | |
2748 #endif | |
14 | 2749 /* |
2750 * First of all, we check the type of the supplied MzScheme object. | |
2751 * It must be a string or a list, or the call is in error. | |
2752 */ | |
2753 n = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); | |
2754 list = argv[1]; | |
2755 | |
2756 if (!SCHEME_STRINGP(list) && !SCHEME_PAIRP(list)) | |
2757 scheme_wrong_type(prim->name, "string or list", 1, argc, argv); | |
2758 buf = get_buffer_arg(prim->name, 2, argc, argv); | |
2759 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2760 if (n != 0) // 0 can be used in insert |
856 | 2761 check_line_range(n, buf->buf); |
14 | 2762 if (SCHEME_STRINGP(list)) |
2763 { | |
1894 | 2764 buf_T *savebuf = curbuf; |
2765 | |
14 | 2766 str = string_to_line(list); |
2767 curbuf = buf->buf; | |
2768 | |
2769 if (u_save((linenr_T)n, (linenr_T)(n+1)) == FAIL) | |
2770 { | |
2771 curbuf = savebuf; | |
1894 | 2772 vim_free(str); |
14 | 2773 raise_vim_exn(_("cannot save undo information")); |
2774 } | |
2775 else if (ml_append((linenr_T)n, (char_u *)str, 0, FALSE) == FAIL) | |
2776 { | |
2777 curbuf = savebuf; | |
1894 | 2778 vim_free(str); |
14 | 2779 raise_vim_exn(_("cannot insert line")); |
2780 } | |
2781 else | |
1894 | 2782 { |
2783 vim_free(str); | |
14 | 2784 appended_lines_mark((linenr_T)n, 1L); |
1894 | 2785 } |
14 | 2786 |
2787 curbuf = savebuf; | |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
28303
diff
changeset
|
2788 update_screen(UPD_VALID); |
14 | 2789 |
1894 | 2790 MZ_GC_UNREG(); |
14 | 2791 raise_if_error(); |
2792 return scheme_void; | |
2793 } | |
2794 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2795 // List |
14 | 2796 size = scheme_proper_list_length(list); |
1894 | 2797 MZ_GC_CHECK(); |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2798 if (size < 0) // improper or cyclic list |
14 | 2799 scheme_wrong_type(prim->name, "proper list", |
2800 2, argc, argv); | |
2801 else | |
2802 { | |
1894 | 2803 Scheme_Object *line = NULL; |
2804 Scheme_Object *rest = NULL; | |
2805 char **array; | |
2806 buf_T *savebuf = curbuf; | |
2807 | |
2808 MZ_GC_DECL_REG(2); | |
2809 MZ_GC_VAR_IN_REG(0, line); | |
2810 MZ_GC_VAR_IN_REG(1, rest); | |
2811 MZ_GC_REG(); | |
2812 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2813 array = ALLOC_CLEAR_MULT(char *, size + 1); |
1894 | 2814 |
2815 rest = list; | |
856 | 2816 for (i = 0; i < size; ++i) |
1894 | 2817 { |
2818 line = SCHEME_CAR(rest); | |
2819 rest = SCHEME_CDR(rest); | |
2820 array[i] = string_to_line(line); | |
2821 } | |
2822 | |
2823 curbuf = buf->buf; | |
2824 | |
2825 if (u_save((linenr_T)n, (linenr_T)(n + 1)) == FAIL) | |
2826 { | |
2827 curbuf = savebuf; | |
2828 free_array(array); | |
2829 raise_vim_exn(_("cannot save undo information")); | |
2830 } | |
2831 else | |
2832 { | |
2833 for (i = 0; i < size; ++i) | |
2834 if (ml_append((linenr_T)(n + i), (char_u *)array[i], | |
2835 0, FALSE) == FAIL) | |
2836 { | |
2837 curbuf = savebuf; | |
2838 free_array(array); | |
2839 raise_vim_exn(_("cannot insert line")); | |
2840 } | |
2841 | |
2842 if (i > 0) | |
2843 appended_lines_mark((linenr_T)n, (long)i); | |
2844 } | |
2845 free_array(array); | |
2846 MZ_GC_UNREG(); | |
2847 curbuf = savebuf; | |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
28303
diff
changeset
|
2848 update_screen(UPD_VALID); |
14 | 2849 } |
2850 | |
1894 | 2851 MZ_GC_UNREG(); |
14 | 2852 raise_if_error(); |
2853 return scheme_void; | |
2854 } | |
2855 | |
2856 /* | |
2857 * Predicates | |
2858 */ | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2859 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2860 * (buff? obj) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2861 */ |
14 | 2862 static Scheme_Object * |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
2863 vim_bufferp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) |
14 | 2864 { |
2865 if (SCHEME_VIMBUFFERP(argv[0])) | |
2866 return scheme_true; | |
2867 else | |
2868 return scheme_false; | |
2869 } | |
2870 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2871 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2872 * (win? obj) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2873 */ |
14 | 2874 static Scheme_Object * |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
2875 vim_windowp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) |
14 | 2876 { |
2877 if (SCHEME_VIMWINDOWP(argv[0])) | |
2878 return scheme_true; | |
2879 else | |
2880 return scheme_false; | |
2881 } | |
2882 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2883 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2884 * (buff-valid? obj) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2885 */ |
14 | 2886 static Scheme_Object * |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
2887 vim_buffer_validp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) |
14 | 2888 { |
2889 if (SCHEME_VIMBUFFERP(argv[0]) | |
2890 && ((vim_mz_buffer *)argv[0])->buf != INVALID_BUFFER_VALUE) | |
2891 return scheme_true; | |
2892 else | |
2893 return scheme_false; | |
2894 } | |
2895 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2896 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2897 * (win-valid? obj) |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2898 */ |
14 | 2899 static Scheme_Object * |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
2900 vim_window_validp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) |
14 | 2901 { |
2902 if (SCHEME_VIMWINDOWP(argv[0]) | |
2903 && ((vim_mz_window *)argv[0])->win != INVALID_WINDOW_VALUE) | |
2904 return scheme_true; | |
2905 else | |
2906 return scheme_false; | |
2907 } | |
2908 | |
2909 /* | |
2910 *=========================================================================== | |
2911 * Utilities | |
2912 *=========================================================================== | |
2913 */ | |
2914 | |
2915 /* | |
2916 * Convert an MzScheme string into a Vim line. | |
2917 * | |
1894 | 2918 * All internal nulls are replaced by newline characters. |
2919 * It is an error for the string to contain newline characters. | |
14 | 2920 * |
1894 | 2921 * Returns pointer to Vim allocated memory |
14 | 2922 */ |
2923 static char * | |
2924 string_to_line(Scheme_Object *obj) | |
2925 { | |
1894 | 2926 char *scheme_str = NULL; |
2927 char *vim_str = NULL; | |
4074 | 2928 OUTPUT_LEN_TYPE len; |
14 | 2929 int i; |
2930 | |
1894 | 2931 scheme_str = scheme_display_to_string(obj, &len); |
14 | 2932 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2933 // 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
|
2934 // 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
|
2935 // a single line. |
4074 | 2936 if (memchr(scheme_str, '\n', len)) |
14 | 2937 scheme_signal_error(_("string cannot contain newlines")); |
2938 | |
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
|
2939 vim_str = alloc(len + 1); |
1894 | 2940 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2941 // 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
|
2942 // newline characters, as is the vim convention. |
14 | 2943 for (i = 0; i < len; ++i) |
2944 { | |
1894 | 2945 if (scheme_str[i] == '\0') |
2946 vim_str[i] = '\n'; | |
2947 else | |
2948 vim_str[i] = scheme_str[i]; | |
2949 } | |
2950 | |
2951 vim_str[i] = '\0'; | |
2952 | |
2953 MZ_GC_CHECK(); | |
2954 return vim_str; | |
2955 } | |
2956 | |
2957 #ifdef FEAT_EVAL | |
2958 /* | |
2959 * Convert Vim value into MzScheme, adopted from if_python.c | |
2960 */ | |
2961 static Scheme_Object * | |
4074 | 2962 vim_to_mzscheme(typval_T *vim_value) |
2963 { | |
2964 Scheme_Object *result = NULL; | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2965 // hash table to store visited values to avoid infinite loops |
4074 | 2966 Scheme_Hash_Table *visited = NULL; |
2967 | |
2968 MZ_GC_DECL_REG(2); | |
2969 MZ_GC_VAR_IN_REG(0, result); | |
2970 MZ_GC_VAR_IN_REG(1, visited); | |
2971 MZ_GC_REG(); | |
2972 | |
2973 visited = scheme_make_hash_table(SCHEME_hash_ptr); | |
2974 MZ_GC_CHECK(); | |
2975 | |
2976 result = vim_to_mzscheme_impl(vim_value, 1, visited); | |
2977 | |
2978 MZ_GC_UNREG(); | |
2979 return result; | |
2980 } | |
2981 | |
2982 static Scheme_Object * | |
2983 vim_to_mzscheme_impl(typval_T *vim_value, int depth, Scheme_Hash_Table *visited) | |
1894 | 2984 { |
2985 Scheme_Object *result = NULL; | |
2986 int new_value = TRUE; | |
2987 | |
4074 | 2988 MZ_GC_DECL_REG(2); |
1894 | 2989 MZ_GC_VAR_IN_REG(0, result); |
4074 | 2990 MZ_GC_VAR_IN_REG(1, visited); |
1894 | 2991 MZ_GC_REG(); |
2992 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2993 // Avoid infinite recursion |
1894 | 2994 if (depth > 100) |
2995 { | |
2996 MZ_GC_UNREG(); | |
2997 return scheme_void; | |
2998 } | |
2999 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3000 // 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
|
3001 // then and we can use it again. |
1894 | 3002 result = scheme_hash_get(visited, (Scheme_Object *)vim_value); |
3003 MZ_GC_CHECK(); | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3004 if (result != NULL) // found, do nothing |
1894 | 3005 new_value = FALSE; |
3006 else if (vim_value->v_type == VAR_STRING) | |
3007 { | |
4074 | 3008 result = scheme_make_byte_string((char *)vim_value->vval.v_string); |
1894 | 3009 MZ_GC_CHECK(); |
3010 } | |
3011 else if (vim_value->v_type == VAR_NUMBER) | |
3012 { | |
3013 result = scheme_make_integer((long)vim_value->vval.v_number); | |
3014 MZ_GC_CHECK(); | |
3015 } | |
3016 else if (vim_value->v_type == VAR_FLOAT) | |
3017 { | |
3018 result = scheme_make_double((double)vim_value->vval.v_float); | |
3019 MZ_GC_CHECK(); | |
14 | 3020 } |
1894 | 3021 else if (vim_value->v_type == VAR_LIST) |
3022 { | |
3023 list_T *list = vim_value->vval.v_list; | |
3024 listitem_T *curr; | |
3025 | |
3026 if (list == NULL || list->lv_first == NULL) | |
3027 result = scheme_null; | |
3028 else | |
3029 { | |
3030 Scheme_Object *obj = NULL; | |
3031 | |
3032 MZ_GC_DECL_REG(1); | |
3033 MZ_GC_VAR_IN_REG(0, obj); | |
3034 MZ_GC_REG(); | |
3035 | |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
3036 curr = list->lv_u.mat.lv_last; |
4074 | 3037 obj = vim_to_mzscheme_impl(&curr->li_tv, depth + 1, visited); |
1894 | 3038 result = scheme_make_pair(obj, scheme_null); |
3039 MZ_GC_CHECK(); | |
3040 | |
3041 while (curr != list->lv_first) | |
3042 { | |
3043 curr = curr->li_prev; | |
4074 | 3044 obj = vim_to_mzscheme_impl(&curr->li_tv, depth + 1, visited); |
1894 | 3045 result = scheme_make_pair(obj, result); |
3046 MZ_GC_CHECK(); | |
3047 } | |
3048 } | |
3049 MZ_GC_UNREG(); | |
3050 } | |
3051 else if (vim_value->v_type == VAR_DICT) | |
3052 { | |
3053 Scheme_Object *key = NULL; | |
3054 Scheme_Object *obj = NULL; | |
3055 | |
3056 MZ_GC_DECL_REG(2); | |
3057 MZ_GC_VAR_IN_REG(0, key); | |
3058 MZ_GC_VAR_IN_REG(1, obj); | |
3059 MZ_GC_REG(); | |
3060 | |
3061 result = (Scheme_Object *)scheme_make_hash_table(SCHEME_hash_ptr); | |
3062 MZ_GC_CHECK(); | |
3063 if (vim_value->vval.v_dict != NULL) | |
3064 { | |
3065 hashtab_T *ht = &vim_value->vval.v_dict->dv_hashtab; | |
3066 long_u todo = ht->ht_used; | |
3067 hashitem_T *hi; | |
3068 dictitem_T *di; | |
3069 | |
32118
04d9dff67d99
patch 9.0.1390: FOR_ALL_ macros are defined in an unexpected file
Bram Moolenaar <Bram@vim.org>
parents:
32019
diff
changeset
|
3070 FOR_ALL_HASHTAB_ITEMS(ht, hi, todo) |
1894 | 3071 { |
3072 if (!HASHITEM_EMPTY(hi)) | |
3073 { | |
3074 --todo; | |
3075 | |
3076 di = dict_lookup(hi); | |
4074 | 3077 obj = vim_to_mzscheme_impl(&di->di_tv, depth + 1, visited); |
3078 key = scheme_make_byte_string((char *)hi->hi_key); | |
1894 | 3079 MZ_GC_CHECK(); |
3080 scheme_hash_set((Scheme_Hash_Table *)result, key, obj); | |
3081 MZ_GC_CHECK(); | |
3082 } | |
3083 } | |
3084 } | |
3085 MZ_GC_UNREG(); | |
3086 } | |
4074 | 3087 else if (vim_value->v_type == VAR_FUNC) |
3088 { | |
3089 Scheme_Object *funcname = NULL; | |
3090 | |
3091 MZ_GC_DECL_REG(1); | |
3092 MZ_GC_VAR_IN_REG(0, funcname); | |
3093 MZ_GC_REG(); | |
3094 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3095 // FIXME: func_ref() and func_unref() are needed. |
4074 | 3096 funcname = scheme_make_byte_string((char *)vim_value->vval.v_string); |
3097 MZ_GC_CHECK(); | |
3098 result = scheme_make_closed_prim_w_arity(vim_funcref, funcname, | |
3099 (const char *)BYTE_STRING_VALUE(funcname), 0, -1); | |
3100 MZ_GC_CHECK(); | |
3101 | |
3102 MZ_GC_UNREG(); | |
3103 } | |
8800
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3104 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
|
3105 { |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3106 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
|
3107 result = scheme_null; |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3108 else |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3109 { |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3110 Scheme_Object *funcname = NULL; |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3111 |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3112 MZ_GC_DECL_REG(1); |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3113 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
|
3114 MZ_GC_REG(); |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3115 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3116 // 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
|
3117 // 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
|
3118 funcname = scheme_make_byte_string( |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
3119 (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
|
3120 MZ_GC_CHECK(); |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3121 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
|
3122 (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
|
3123 MZ_GC_CHECK(); |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3124 |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3125 MZ_GC_UNREG(); |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3126 } |
f57949e1e9f1
commit https://github.com/vim/vim/commit/67c2c058ea34628bd575aac7ddba4cd3b244ed57
Christian Brabandt <cb@256bit.org>
parents:
8779
diff
changeset
|
3127 } |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
18798
diff
changeset
|
3128 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
|
3129 { |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7609
diff
changeset
|
3130 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
|
3131 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
|
3132 else |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7609
diff
changeset
|
3133 result = scheme_null; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7609
diff
changeset
|
3134 MZ_GC_CHECK(); |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7609
diff
changeset
|
3135 } |
1894 | 3136 else |
3137 { | |
3138 result = scheme_void; | |
3139 new_value = FALSE; | |
3140 } | |
3141 if (new_value) | |
3142 { | |
3143 scheme_hash_set(visited, (Scheme_Object *)vim_value, result); | |
3144 MZ_GC_CHECK(); | |
3145 } | |
3146 MZ_GC_UNREG(); | |
3147 return result; | |
14 | 3148 } |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3149 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3150 static int |
4074 | 3151 mzscheme_to_vim(Scheme_Object *obj, typval_T *tv) |
3152 { | |
3153 int i, status; | |
3154 Scheme_Hash_Table *visited = NULL; | |
3155 | |
3156 MZ_GC_DECL_REG(2); | |
3157 MZ_GC_VAR_IN_REG(0, obj); | |
3158 MZ_GC_VAR_IN_REG(1, visited); | |
3159 MZ_GC_REG(); | |
3160 | |
3161 visited = scheme_make_hash_table(SCHEME_hash_ptr); | |
3162 MZ_GC_CHECK(); | |
3163 | |
3164 status = mzscheme_to_vim_impl(obj, tv, 1, visited); | |
3165 for (i = 0; i < visited->size; ++i) | |
3166 { | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3167 // free up remembered objects |
4074 | 3168 if (visited->vals[i] != NULL) |
3169 free_tv((typval_T *)visited->vals[i]); | |
3170 } | |
3171 | |
3172 MZ_GC_UNREG(); | |
3173 return status; | |
3174 } | |
3175 static int | |
3176 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
|
3177 Scheme_Hash_Table *visited) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3178 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3179 int status = OK; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3180 typval_T *found; |
4074 | 3181 |
3182 MZ_GC_DECL_REG(2); | |
3183 MZ_GC_VAR_IN_REG(0, obj); | |
3184 MZ_GC_VAR_IN_REG(1, visited); | |
3185 MZ_GC_REG(); | |
3186 | |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3187 MZ_GC_CHECK(); |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3188 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
|
3189 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3190 tv->v_type = VAR_NUMBER; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3191 tv->vval.v_number = 0; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3192 return FAIL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3193 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3194 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3195 found = (typval_T *)scheme_hash_get(visited, obj); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3196 if (found != NULL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3197 copy_tv(found, tv); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3198 else if (SCHEME_VOIDP(obj)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3199 { |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7609
diff
changeset
|
3200 tv->v_type = VAR_SPECIAL; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7609
diff
changeset
|
3201 tv->vval.v_number = VVAL_NULL; |
2050
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_INTP(obj)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3204 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3205 tv->v_type = VAR_NUMBER; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3206 tv->vval.v_number = SCHEME_INT_VAL(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 else if (SCHEME_BOOLP(obj)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3209 { |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
18798
diff
changeset
|
3210 tv->v_type = VAR_BOOL; |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3211 tv->vval.v_number = SCHEME_TRUEP(obj); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3212 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3213 else if (SCHEME_DBLP(obj)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3214 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3215 tv->v_type = VAR_FLOAT; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3216 tv->vval.v_float = SCHEME_DBL_VAL(obj); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3217 } |
4074 | 3218 else if (SCHEME_BYTE_STRINGP(obj)) |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3219 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3220 tv->v_type = VAR_STRING; |
4074 | 3221 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
|
3222 } |
4074 | 3223 # if MZSCHEME_VERSION_MAJOR >= 299 |
3224 else if (SCHEME_CHAR_STRINGP(obj)) | |
3225 { | |
3226 Scheme_Object *tmp = NULL; | |
3227 MZ_GC_DECL_REG(1); | |
3228 MZ_GC_VAR_IN_REG(0, tmp); | |
3229 MZ_GC_REG(); | |
3230 | |
3231 tmp = scheme_char_string_to_byte_string(obj); | |
3232 tv->v_type = VAR_STRING; | |
3233 tv->vval.v_string = vim_strsave(BYTE_STRING_VALUE(tmp)); | |
3234 MZ_GC_UNREG(); | |
3235 } | |
3236 #endif | |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3237 else if (SCHEME_VECTORP(obj) || SCHEME_NULLP(obj) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3238 || SCHEME_PAIRP(obj) || SCHEME_MUTABLE_PAIRP(obj)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3239 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3240 list_T *list = list_alloc(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3241 if (list == NULL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3242 status = FAIL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3243 else |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3244 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3245 int i; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3246 Scheme_Object *curr = NULL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3247 Scheme_Object *cval = NULL; |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3248 // 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
|
3249 typval_T *v; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3250 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3251 MZ_GC_DECL_REG(2); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3252 MZ_GC_VAR_IN_REG(0, curr); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3253 MZ_GC_VAR_IN_REG(1, cval); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3254 MZ_GC_REG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3255 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3256 tv->v_type = VAR_LIST; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3257 tv->vval.v_list = list; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3258 ++list->lv_refcount; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3259 |
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
|
3260 v = ALLOC_ONE(typval_T); |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3261 if (v == NULL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3262 status = FAIL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3263 else |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3264 { |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3265 // 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
|
3266 // 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
|
3267 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
|
3268 copy_tv(tv, visited_tv); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3269 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
|
3270 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3271 if (SCHEME_VECTORP(obj)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3272 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3273 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
|
3274 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3275 cval = SCHEME_VEC_ELS(obj)[i]; |
4074 | 3276 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
|
3277 if (status == FAIL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3278 break; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3279 status = list_append_tv(list, v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3280 clear_tv(v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3281 if (status == FAIL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3282 break; |
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 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3285 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
|
3286 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3287 for (curr = obj; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3288 SCHEME_PAIRP(curr) || SCHEME_MUTABLE_PAIRP(curr); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3289 curr = SCHEME_CDR(curr)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3290 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3291 cval = SCHEME_CAR(curr); |
4074 | 3292 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
|
3293 if (status == FAIL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3294 break; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3295 status = list_append_tv(list, v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3296 clear_tv(v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3297 if (status == FAIL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3298 break; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3299 } |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3300 // 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
|
3301 // need to handle the last element |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3302 if (status == OK && !SCHEME_NULLP(curr)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3303 { |
4074 | 3304 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
|
3305 if (status == OK) |
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 status = list_append_tv(list, v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3308 clear_tv(v); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3309 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3310 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3311 } |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3312 // nothing to do for scheme_null |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3313 vim_free(v); |
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 MZ_GC_UNREG(); |
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 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3318 else if (SCHEME_HASHTP(obj)) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3319 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3320 int i; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3321 dict_T *dict; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3322 Scheme_Object *key = NULL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3323 Scheme_Object *val = NULL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3324 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3325 MZ_GC_DECL_REG(2); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3326 MZ_GC_VAR_IN_REG(0, key); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3327 MZ_GC_VAR_IN_REG(1, val); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3328 MZ_GC_REG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3329 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3330 dict = dict_alloc(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3331 if (dict == NULL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3332 status = FAIL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3333 else |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3334 { |
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
|
3335 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
|
3336 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3337 tv->v_type = VAR_DICT; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3338 tv->vval.v_dict = dict; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3339 ++dict->dv_refcount; |
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 copy_tv(tv, visited_tv); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3342 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
|
3343 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3344 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
|
3345 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3346 if (((Scheme_Hash_Table *) obj)->vals[i] != NULL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3347 { |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3348 // generate item for `display'ed Scheme key |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3349 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
|
3350 ((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
|
3351 // convert Scheme val to Vim and add it to the dict |
4074 | 3352 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
|
3353 &item->di_tv, depth + 1, visited) == FAIL |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3354 || dict_add(dict, item) == FAIL) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3355 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3356 dictitem_free(item); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3357 status = FAIL; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3358 break; |
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 |
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 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3364 MZ_GC_UNREG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3365 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3366 else |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3367 { |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3368 // `display' any other value to string |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3369 tv->v_type = VAR_STRING; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3370 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
|
3371 } |
4074 | 3372 MZ_GC_UNREG(); |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3373 return status; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3374 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3375 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3376 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3377 * 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
|
3378 */ |
4074 | 3379 static Scheme_Object * |
3380 vim_funcref(void *name, int argc, Scheme_Object **argv) | |
3381 { | |
3382 int i; | |
3383 typval_T args; | |
3384 int status = OK; | |
3385 Scheme_Object *result = NULL; | |
3386 list_T *list = list_alloc(); | |
3387 | |
3388 MZ_GC_DECL_REG(1); | |
3389 MZ_GC_VAR_IN_REG(0, result); | |
3390 MZ_GC_REG(); | |
3391 | |
3392 result = scheme_void; | |
3393 if (list == NULL) | |
3394 status = FAIL; | |
3395 else | |
3396 { | |
3397 args.v_type = VAR_LIST; | |
3398 args.vval.v_list = list; | |
3399 ++list->lv_refcount; | |
3400 for (i = 0; status == OK && i < argc; ++i) | |
3401 { | |
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
|
3402 typval_T *v = ALLOC_ONE(typval_T); |
4074 | 3403 if (v == NULL) |
3404 status = FAIL; | |
3405 else | |
3406 { | |
3407 status = mzscheme_to_vim(argv[i], v); | |
3408 if (status == OK) | |
3409 { | |
3410 status = list_append_tv(list, v); | |
3411 clear_tv(v); | |
3412 } | |
3413 vim_free(v); | |
3414 } | |
3415 } | |
3416 if (status == OK) | |
3417 { | |
3418 typval_T ret; | |
3419 ret.v_type = VAR_UNKNOWN; | |
3420 | |
3421 mzscheme_call_vim(BYTE_STRING_VALUE((Scheme_Object *)name), &args, &ret); | |
3422 MZ_GC_CHECK(); | |
3423 result = vim_to_mzscheme(&ret); | |
3424 clear_tv(&ret); | |
3425 MZ_GC_CHECK(); | |
3426 } | |
3427 } | |
3428 clear_tv(&args); | |
3429 MZ_GC_UNREG(); | |
3430 if (status != OK) | |
3431 raise_vim_exn(_("error converting Scheme values to Vim")); | |
3432 else | |
3433 raise_if_error(); | |
3434 return result; | |
3435 } | |
3436 | |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3437 void |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3438 do_mzeval(char_u *str, typval_T *rettv) |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3439 { |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3440 Scheme_Object *ret = NULL; |
4074 | 3441 |
3442 MZ_GC_DECL_REG(1); | |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3443 MZ_GC_VAR_IN_REG(0, ret); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3444 MZ_GC_REG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3445 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3446 if (mzscheme_init()) |
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 MZ_GC_UNREG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3449 return; |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3450 } |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3451 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3452 MZ_GC_CHECK(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3453 if (eval_with_exn_handling(str, do_eval, &ret) == OK) |
4074 | 3454 mzscheme_to_vim(ret, rettv); |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3455 |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3456 MZ_GC_UNREG(); |
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
2023
diff
changeset
|
3457 } |
1894 | 3458 #endif |
14 | 3459 |
3460 /* | |
3461 * Check to see whether a Vim error has been reported, or a keyboard | |
3462 * interrupt (from vim --> got_int) has been detected. | |
3463 */ | |
3464 static int | |
3465 vim_error_check(void) | |
3466 { | |
3467 return (got_int || did_emsg); | |
3468 } | |
3469 | |
3470 /* | |
3471 * register Scheme exn:vim | |
3472 */ | |
3473 static void | |
1894 | 3474 register_vim_exn(void) |
14 | 3475 { |
1894 | 3476 int nc = 0; |
3477 int i; | |
3478 Scheme_Object *struct_exn = NULL; | |
3479 Scheme_Object *exn_name = NULL; | |
3480 | |
3481 MZ_GC_DECL_REG(2); | |
3482 MZ_GC_VAR_IN_REG(0, struct_exn); | |
3483 MZ_GC_VAR_IN_REG(1, exn_name); | |
3484 MZ_GC_REG(); | |
3485 | |
3486 exn_name = scheme_intern_symbol("exn:vim"); | |
3487 MZ_GC_CHECK(); | |
3488 struct_exn = scheme_builtin_value("struct:exn"); | |
3489 MZ_GC_CHECK(); | |
14 | 3490 |
3491 if (vim_exn == NULL) | |
3492 vim_exn = scheme_make_struct_type(exn_name, | |
1894 | 3493 struct_exn, NULL, 0, 0, NULL, NULL |
14 | 3494 #if MZSCHEME_VERSION_MAJOR >= 299 |
3495 , NULL | |
3496 #endif | |
3497 ); | |
3498 | |
1894 | 3499 |
14 | 3500 { |
1894 | 3501 Scheme_Object **tmp = NULL; |
3502 Scheme_Object *exn_names[5] = {NULL, NULL, NULL, NULL, NULL}; | |
3503 Scheme_Object *exn_values[5] = {NULL, NULL, NULL, NULL, NULL}; | |
3504 MZ_GC_DECL_REG(6); | |
3505 MZ_GC_ARRAY_VAR_IN_REG(0, exn_names, 5); | |
3506 MZ_GC_ARRAY_VAR_IN_REG(3, exn_values, 5); | |
3507 MZ_GC_REG(); | |
3508 | |
3509 tmp = scheme_make_struct_names(exn_name, scheme_null, 0, &nc); | |
3510 mch_memmove(exn_names, tmp, nc * sizeof(Scheme_Object *)); | |
3511 MZ_GC_CHECK(); | |
3512 | |
3513 tmp = scheme_make_struct_values(vim_exn, exn_names, nc, 0); | |
3514 mch_memmove(exn_values, tmp, nc * sizeof(Scheme_Object *)); | |
3515 MZ_GC_CHECK(); | |
3516 | |
3517 for (i = 0; i < nc; i++) | |
3518 { | |
3519 scheme_add_global_symbol(exn_names[i], | |
3520 exn_values[i], environment); | |
3521 MZ_GC_CHECK(); | |
3522 } | |
3523 MZ_GC_UNREG(); | |
14 | 3524 } |
1894 | 3525 MZ_GC_UNREG(); |
14 | 3526 } |
3527 | |
3528 /* | |
3529 * raise exn:vim, may be with additional info string | |
3530 */ | |
3531 void | |
3532 raise_vim_exn(const char *add_info) | |
3533 { | |
1894 | 3534 char *fmt = _("Vim error: ~a"); |
3535 Scheme_Object *argv[2] = {NULL, NULL}; | |
3536 Scheme_Object *exn = NULL; | |
4074 | 3537 Scheme_Object *byte_string = NULL; |
3538 | |
3539 MZ_GC_DECL_REG(5); | |
1894 | 3540 MZ_GC_ARRAY_VAR_IN_REG(0, argv, 2); |
3541 MZ_GC_VAR_IN_REG(3, exn); | |
4074 | 3542 MZ_GC_VAR_IN_REG(4, byte_string); |
1894 | 3543 MZ_GC_REG(); |
14 | 3544 |
3545 if (add_info != NULL) | |
3546 { | |
1894 | 3547 char *c_string = NULL; |
3548 Scheme_Object *info = NULL; | |
3549 | |
3550 MZ_GC_DECL_REG(3); | |
3551 MZ_GC_VAR_IN_REG(0, c_string); | |
3552 MZ_GC_VAR_IN_REG(2, info); | |
3553 MZ_GC_REG(); | |
3554 | |
4074 | 3555 info = scheme_make_byte_string(add_info); |
1894 | 3556 MZ_GC_CHECK(); |
9159
6b003ff07234
commit https://github.com/vim/vim/commit/9b0ac229bcfc91acabd35fc576055a94c1687c32
Christian Brabandt <cb@256bit.org>
parents:
8800
diff
changeset
|
3557 c_string = scheme_format_utf8(fmt, (int)STRLEN(fmt), 1, &info, NULL); |
1894 | 3558 MZ_GC_CHECK(); |
4074 | 3559 byte_string = scheme_make_byte_string(c_string); |
1894 | 3560 MZ_GC_CHECK(); |
3561 argv[0] = scheme_byte_string_to_char_string(byte_string); | |
274 | 3562 SCHEME_SET_IMMUTABLE(argv[0]); |
1894 | 3563 MZ_GC_UNREG(); |
14 | 3564 } |
3565 else | |
4074 | 3566 { |
3567 byte_string = scheme_make_byte_string(_("Vim error")); | |
3568 MZ_GC_CHECK(); | |
3569 argv[0] = scheme_byte_string_to_char_string(byte_string); | |
3570 MZ_GC_CHECK(); | |
3571 } | |
1894 | 3572 MZ_GC_CHECK(); |
14 | 3573 |
1284 | 3574 #if MZSCHEME_VERSION_MAJOR < 360 |
3575 argv[1] = scheme_current_continuation_marks(); | |
1894 | 3576 MZ_GC_CHECK(); |
1284 | 3577 #else |
1125 | 3578 argv[1] = scheme_current_continuation_marks(NULL); |
1894 | 3579 MZ_GC_CHECK(); |
1284 | 3580 #endif |
14 | 3581 |
1894 | 3582 exn = scheme_make_struct_instance(vim_exn, 2, argv); |
3583 MZ_GC_CHECK(); | |
3584 scheme_raise(exn); | |
3585 MZ_GC_UNREG(); | |
14 | 3586 } |
3587 | |
3588 void | |
3589 raise_if_error(void) | |
3590 { | |
3591 if (vim_error_check()) | |
3592 raise_vim_exn(NULL); | |
3593 } | |
3594 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3595 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3596 * get buffer: |
14 | 3597 * either current |
3598 * or passed as argv[argnum] with checks | |
3599 */ | |
3600 static vim_mz_buffer * | |
3601 get_buffer_arg(const char *fname, int argnum, int argc, Scheme_Object **argv) | |
3602 { | |
3603 vim_mz_buffer *b; | |
3604 | |
3605 if (argc < argnum + 1) | |
3606 return get_vim_curr_buffer(); | |
3607 if (!SCHEME_VIMBUFFERP(argv[argnum])) | |
3608 scheme_wrong_type(fname, "vim-buffer", argnum, argc, argv); | |
3609 b = (vim_mz_buffer *)argv[argnum]; | |
3610 (void)get_valid_buffer(argv[argnum]); | |
3611 return b; | |
3612 } | |
3613 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3614 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3615 * get window: |
14 | 3616 * either current |
3617 * or passed as argv[argnum] with checks | |
3618 */ | |
3619 static vim_mz_window * | |
3620 get_window_arg(const char *fname, int argnum, int argc, Scheme_Object **argv) | |
3621 { | |
3622 vim_mz_window *w; | |
3623 | |
3624 if (argc < argnum + 1) | |
3625 return get_vim_curr_window(); | |
3626 w = (vim_mz_window *)argv[argnum]; | |
3627 if (!SCHEME_VIMWINDOWP(argv[argnum])) | |
3628 scheme_wrong_type(fname, "vim-window", argnum, argc, argv); | |
3629 (void)get_valid_window(argv[argnum]); | |
3630 return w; | |
3631 } | |
3632 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3633 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3634 * 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
|
3635 */ |
14 | 3636 buf_T *get_valid_buffer(void *obj) |
3637 { | |
3638 buf_T *buf = ((vim_mz_buffer *)obj)->buf; | |
3639 | |
3640 if (buf == INVALID_BUFFER_VALUE) | |
3641 scheme_signal_error(_("buffer is invalid")); | |
3642 return buf; | |
3643 } | |
3644 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3645 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3646 * 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
|
3647 */ |
14 | 3648 win_T *get_valid_window(void *obj) |
3649 { | |
3650 win_T *win = ((vim_mz_window *)obj)->win; | |
3651 if (win == INVALID_WINDOW_VALUE) | |
3652 scheme_signal_error(_("window is invalid")); | |
3653 return win; | |
3654 } | |
3655 | |
3656 int | |
3657 mzthreads_allowed(void) | |
3658 { | |
3659 return mz_threads_allow; | |
3660 } | |
3661 | |
3662 static int | |
3663 line_in_range(linenr_T lnum, buf_T *buf) | |
3664 { | |
3665 return (lnum > 0 && lnum <= buf->b_ml.ml_line_count); | |
3666 } | |
3667 | |
3668 static void | |
3669 check_line_range(linenr_T lnum, buf_T *buf) | |
3670 { | |
3671 if (!line_in_range(lnum, buf)) | |
3672 scheme_signal_error(_("linenr out of range")); | |
3673 } | |
3674 | |
3675 /* | |
3676 * Check if deleting lines made the cursor position invalid | |
3677 * (or you'll get msg from Vim about invalid linenr). | |
3678 * Changed the lines from "lo" to "hi" and added "extra" lines (negative if | |
3679 * deleted). Got from if_python.c | |
3680 */ | |
3681 static void | |
3682 mz_fix_cursor(int lo, int hi, int extra) | |
3683 { | |
3684 if (curwin->w_cursor.lnum >= lo) | |
3685 { | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3686 // 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
|
3687 // lines. |
14 | 3688 if (curwin->w_cursor.lnum >= hi) |
3689 { | |
3690 curwin->w_cursor.lnum += extra; | |
3691 check_cursor_col(); | |
3692 } | |
3693 else if (extra < 0) | |
3694 { | |
3695 curwin->w_cursor.lnum = lo; | |
3696 check_cursor(); | |
3697 } | |
1894 | 3698 else |
3699 check_cursor_col(); | |
14 | 3700 changed_cline_bef_curs(); |
3701 } | |
3702 invalidate_botline(); | |
3703 } | |
3704 | |
3705 static Vim_Prim prims[]= | |
3706 { | |
3707 /* | |
3708 * Buffer-related commands | |
3709 */ | |
3710 {get_buffer_line, "get-buff-line", 1, 2}, | |
3711 {set_buffer_line, "set-buff-line", 2, 3}, | |
3712 {get_buffer_line_list, "get-buff-line-list", 2, 3}, | |
3713 {get_buffer_name, "get-buff-name", 0, 1}, | |
3714 {get_buffer_num, "get-buff-num", 0, 1}, | |
3715 {get_buffer_size, "get-buff-size", 0, 1}, | |
3716 {set_buffer_line_list, "set-buff-line-list", 3, 4}, | |
3717 {insert_buffer_line_list, "insert-buff-line-list", 2, 3}, | |
3718 {get_curr_buffer, "curr-buff", 0, 0}, | |
3719 {get_buffer_count, "buff-count", 0, 0}, | |
3720 {get_next_buffer, "get-next-buff", 0, 1}, | |
3721 {get_prev_buffer, "get-prev-buff", 0, 1}, | |
3722 {mzscheme_open_buffer, "open-buff", 1, 1}, | |
3723 {get_buffer_by_name, "get-buff-by-name", 1, 1}, | |
3724 {get_buffer_by_num, "get-buff-by-num", 1, 1}, | |
3725 /* | |
3726 * Window-related commands | |
3727 */ | |
3728 {get_curr_win, "curr-win", 0, 0}, | |
3729 {get_window_count, "win-count", 0, 0}, | |
3730 {get_window_by_num, "get-win-by-num", 1, 1}, | |
3731 {get_window_num, "get-win-num", 0, 1}, | |
3732 {get_window_buffer, "get-win-buffer", 0, 1}, | |
3733 {get_window_height, "get-win-height", 0, 1}, | |
3734 {set_window_height, "set-win-height", 1, 2}, | |
3735 {get_window_width, "get-win-width", 0, 1}, | |
3736 {set_window_width, "set-win-width", 1, 2}, | |
3737 {get_cursor, "get-cursor", 0, 1}, | |
3738 {set_cursor, "set-cursor", 1, 2}, | |
3739 {get_window_list, "get-win-list", 0, 1}, | |
3740 /* | |
3741 * Vim-related commands | |
3742 */ | |
3743 {vim_command, "command", 1, 1}, | |
3744 {vim_eval, "eval", 1, 1}, | |
3745 {get_range_start, "range-start", 0, 0}, | |
3746 {get_range_end, "range-end", 0, 0}, | |
3747 {mzscheme_beep, "beep", 0, 0}, | |
3748 {get_option, "get-option", 1, 2}, | |
3749 {set_option, "set-option", 1, 2}, | |
3750 /* | |
3751 * small utilities | |
3752 */ | |
3753 {vim_bufferp, "buff?", 1, 1}, | |
3754 {vim_windowp, "win?", 1, 1}, | |
3755 {vim_buffer_validp, "buff-valid?", 1, 1}, | |
3756 {vim_window_validp, "win-valid?", 1, 1} | |
3757 }; | |
3758 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3759 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3760 * return MzScheme wrapper for curbuf |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3761 */ |
14 | 3762 static vim_mz_buffer * |
3763 get_vim_curr_buffer(void) | |
3764 { | |
502 | 3765 if (curbuf->b_mzscheme_ref == NULL) |
14 | 3766 return (vim_mz_buffer *)buffer_new(curbuf); |
3767 else | |
4074 | 3768 return BUFFER_REF(curbuf); |
14 | 3769 } |
3770 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3771 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3772 * return MzScheme wrapper for curwin |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3773 */ |
14 | 3774 static vim_mz_window * |
3775 get_vim_curr_window(void) | |
3776 { | |
502 | 3777 if (curwin->w_mzscheme_ref == NULL) |
14 | 3778 return (vim_mz_window *)window_new(curwin); |
3779 else | |
4074 | 3780 return WINDOW_REF(curwin); |
14 | 3781 } |
3782 | |
3783 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7813
diff
changeset
|
3784 make_modules(void) |
14 | 3785 { |
1894 | 3786 int i; |
3787 Scheme_Env *mod = NULL; | |
3788 Scheme_Object *vimext_symbol = NULL; | |
3789 Scheme_Object *closed_prim = NULL; | |
3790 | |
3791 MZ_GC_DECL_REG(3); | |
3792 MZ_GC_VAR_IN_REG(0, mod); | |
3793 MZ_GC_VAR_IN_REG(1, vimext_symbol); | |
3794 MZ_GC_VAR_IN_REG(2, closed_prim); | |
3795 MZ_GC_REG(); | |
3796 | |
3797 vimext_symbol = scheme_intern_symbol("vimext"); | |
3798 MZ_GC_CHECK(); | |
3799 mod = scheme_primitive_module(vimext_symbol, environment); | |
3800 MZ_GC_CHECK(); | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3801 // all prims made closed so they can access their own names |
24768
7334bf933510
patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
3802 for (i = 0; i < (int)ARRAY_LENGTH(prims); i++) |
14 | 3803 { |
3804 Vim_Prim *prim = prims + i; | |
1894 | 3805 closed_prim = scheme_make_closed_prim_w_arity(prim->prim, prim, prim->name, |
3806 prim->mina, prim->maxa); | |
3807 scheme_add_global(prim->name, closed_prim, mod); | |
3808 MZ_GC_CHECK(); | |
14 | 3809 } |
3810 scheme_finish_primitive_module(mod); | |
1894 | 3811 MZ_GC_CHECK(); |
3812 MZ_GC_UNREG(); | |
14 | 3813 } |
344 | 3814 |
274 | 3815 #ifdef HAVE_SANDBOX |
3816 static Scheme_Object *M_write = NULL; | |
3817 static Scheme_Object *M_read = NULL; | |
3818 static Scheme_Object *M_execute = NULL; | |
3819 static Scheme_Object *M_delete = NULL; | |
3820 | |
3821 static void | |
1125 | 3822 sandbox_check(void) |
274 | 3823 { |
3824 if (sandbox) | |
3825 raise_vim_exn(_("not allowed in the Vim sandbox")); | |
3826 } | |
3827 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3828 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3829 * 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
|
3830 */ |
274 | 3831 static Scheme_Object * |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
3832 sandbox_file_guard(int argc UNUSED, Scheme_Object **argv) |
274 | 3833 { |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3834 if (!sandbox) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3835 return scheme_void; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3836 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3837 Scheme_Object *requested_access = argv[2]; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3838 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3839 if (M_write == NULL) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3840 { |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3841 MZ_REGISTER_STATIC(M_write); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3842 M_write = scheme_intern_symbol("write"); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3843 MZ_GC_CHECK(); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3844 } |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3845 if (M_read == NULL) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3846 { |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3847 MZ_REGISTER_STATIC(M_read); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3848 M_read = scheme_intern_symbol("read"); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3849 MZ_GC_CHECK(); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3850 } |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3851 if (M_execute == NULL) |
274 | 3852 { |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3853 MZ_REGISTER_STATIC(M_execute); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3854 M_execute = scheme_intern_symbol("execute"); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3855 MZ_GC_CHECK(); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3856 } |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3857 if (M_delete == NULL) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3858 { |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3859 MZ_REGISTER_STATIC(M_delete); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3860 M_delete = scheme_intern_symbol("delete"); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3861 MZ_GC_CHECK(); |
274 | 3862 } |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3863 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3864 while (!SCHEME_NULLP(requested_access)) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3865 { |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3866 Scheme_Object *item = SCHEME_CAR(requested_access); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3867 if (scheme_eq(item, M_write) || scheme_eq(item, M_read) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3868 || scheme_eq(item, M_execute) || scheme_eq(item, M_delete)) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3869 raise_vim_exn(_("not allowed in the Vim sandbox")); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3870 requested_access = SCHEME_CDR(requested_access); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3871 } |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
3872 |
274 | 3873 return scheme_void; |
3874 } | |
3875 | |
3876 static Scheme_Object * | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2050
diff
changeset
|
3877 sandbox_network_guard(int argc UNUSED, Scheme_Object **argv UNUSED) |
274 | 3878 { |
3879 return scheme_void; | |
3880 } | |
3881 #endif | |
800 | 3882 |
3883 #endif |