comparison src/if_mzsch.c @ 18798:f0f9692d4487 v8.1.2387

patch 8.1.2387: using old C style comments Commit: https://github.com/vim/vim/commit/2ab2e8608f9b2c85432715bb9a7f226fdbf8cd35 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Dec 4 21:24:53 2019 +0100 patch 8.1.2387: using old C style comments Problem: Using old C style comments. Solution: Use // comments where appropriate.
author Bram Moolenaar <Bram@vim.org>
date Wed, 04 Dec 2019 21:30:04 +0100
parents ce04ebdf26b8
children ba9f50bfda83
comparison
equal deleted inserted replaced
18797:76af6d0ea316 18798:f0f9692d4487
23 23
24 #include "vim.h" 24 #include "vim.h"
25 25
26 #include "if_mzsch.h" 26 #include "if_mzsch.h"
27 27
28 /* Only do the following when the feature is enabled. Needed for "make 28 // Only do the following when the feature is enabled. Needed for "make
29 * depend". */ 29 // depend".
30 #if defined(FEAT_MZSCHEME) || defined(PROTO) 30 #if defined(FEAT_MZSCHEME) || defined(PROTO)
31 31
32 #ifdef PROTO 32 #ifdef PROTO
33 typedef int Scheme_Object; 33 typedef int Scheme_Object;
34 typedef int Scheme_Closed_Prim; 34 typedef int Scheme_Closed_Prim;
61 || MZSCHEME_VERSION_MAJOR >= 500 \ 61 || MZSCHEME_VERSION_MAJOR >= 500 \
62 && (defined(MZ_USE_FUTURES) || defined(MZ_USE_PLACES)) 62 && (defined(MZ_USE_FUTURES) || defined(MZ_USE_PLACES))
63 # define TRAMPOLINED_MZVIM_STARTUP 63 # define TRAMPOLINED_MZVIM_STARTUP
64 #endif 64 #endif
65 65
66 /* Base data structures */ 66 // Base data structures
67 #define SCHEME_VIMBUFFERP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_buffer_type) 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) 68 #define SCHEME_VIMWINDOWP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_window_type)
69 69
70 typedef struct 70 typedef struct
71 { 71 {
88 */ 88 */
89 typedef struct 89 typedef struct
90 { 90 {
91 Scheme_Closed_Prim *prim; 91 Scheme_Closed_Prim *prim;
92 char *name; 92 char *name;
93 int mina; /* arity information */ 93 int mina; // arity information
94 int maxa; 94 int maxa;
95 } Vim_Prim; 95 } Vim_Prim;
96 96
97 typedef struct 97 typedef struct
98 { 98 {
113 #ifdef HAVE_SANDBOX 113 #ifdef HAVE_SANDBOX
114 static Scheme_Object *sandbox_file_guard(int, Scheme_Object **); 114 static Scheme_Object *sandbox_file_guard(int, Scheme_Object **);
115 static Scheme_Object *sandbox_network_guard(int, Scheme_Object **); 115 static Scheme_Object *sandbox_network_guard(int, Scheme_Object **);
116 static void sandbox_check(void); 116 static void sandbox_check(void);
117 #endif 117 #endif
118 /* Buffer-related commands */ 118 // Buffer-related commands
119 static Scheme_Object *buffer_new(buf_T *buf); 119 static Scheme_Object *buffer_new(buf_T *buf);
120 static Scheme_Object *get_buffer_by_num(void *, int, Scheme_Object **); 120 static Scheme_Object *get_buffer_by_num(void *, int, Scheme_Object **);
121 static vim_mz_buffer *get_vim_curr_buffer(void); 121 static vim_mz_buffer *get_vim_curr_buffer(void);
122 122
123 /* Window-related commands */ 123 // Window-related commands
124 static Scheme_Object *window_new(win_T *win); 124 static Scheme_Object *window_new(win_T *win);
125 static vim_mz_window *get_vim_curr_window(void); 125 static vim_mz_window *get_vim_curr_window(void);
126 126
127 /* 127 /*
128 *======================================================================== 128 *========================================================================
180 { 180 {
181 return buffer_size_proc(obj); 181 return buffer_size_proc(obj);
182 } 182 }
183 static int buffer_fixup_proc(void *obj) 183 static int buffer_fixup_proc(void *obj)
184 { 184 {
185 /* apparently not needed as the object will be uncollectable while 185 // apparently not needed as the object will be uncollectable while
186 * the buffer is alive 186 // the buffer is alive
187 */ 187 // vim_mz_buffer* buf = (vim_mz_buffer*) obj;
188 /* 188 // buf->buf->b_mzscheme_ref = GC_fixup_self(obj);
189 vim_mz_buffer* buf = (vim_mz_buffer*) obj; 189
190 buf->buf->b_mzscheme_ref = GC_fixup_self(obj);
191 */
192 return buffer_size_proc(obj); 190 return buffer_size_proc(obj);
193 } 191 }
194 static int window_size_proc(void *obj UNUSED) 192 static int window_size_proc(void *obj UNUSED)
195 { 193 {
196 return gcBYTES_TO_WORDS(sizeof(vim_mz_window)); 194 return gcBYTES_TO_WORDS(sizeof(vim_mz_window));
199 { 197 {
200 return window_size_proc(obj); 198 return window_size_proc(obj);
201 } 199 }
202 static int window_fixup_proc(void *obj) 200 static int window_fixup_proc(void *obj)
203 { 201 {
204 /* apparently not needed as the object will be uncollectable while 202 // apparently not needed as the object will be uncollectable while
205 * the window is alive 203 // the window is alive
206 */ 204 // vim_mz_window* win = (vim_mz_window*) obj;
207 /* 205 // win->win->w_mzscheme_ref = GC_fixup_self(obj);
208 vim_mz_window* win = (vim_mz_window*) obj; 206 //
209 win->win->w_mzscheme_ref = GC_fixup_self(obj);
210 */
211 return window_size_proc(obj); 207 return window_size_proc(obj);
212 } 208 }
213 /* with precise GC, w_mzscheme_ref and b_mzscheme_ref are immobile boxes 209 // with precise GC, w_mzscheme_ref and b_mzscheme_ref are immobile boxes
214 * containing pointers to a window/buffer 210 // containing pointers to a window/buffer
215 * with conservative GC these are simply pointers*/ 211 // with conservative GC these are simply pointers
216 # define WINDOW_REF(win) *(vim_mz_window **)((win)->w_mzscheme_ref) 212 # define WINDOW_REF(win) *(vim_mz_window **)((win)->w_mzscheme_ref)
217 # define BUFFER_REF(buf) *(vim_mz_buffer **)((buf)->b_mzscheme_ref) 213 # define BUFFER_REF(buf) *(vim_mz_buffer **)((buf)->b_mzscheme_ref)
218 #else 214 #else
219 # define WINDOW_REF(win) (vim_mz_window *)((win)->w_mzscheme_ref) 215 # define WINDOW_REF(win) (vim_mz_window *)((win)->w_mzscheme_ref)
220 # define BUFFER_REF(buf) (vim_mz_buffer *)((buf)->b_mzscheme_ref) 216 # define BUFFER_REF(buf) (vim_mz_buffer *)((buf)->b_mzscheme_ref)
376 static void (*dll_scheme_embedded_load)(intptr_t len, const char *s, int predefined); 372 static void (*dll_scheme_embedded_load)(intptr_t len, const char *s, int predefined);
377 static void (*dll_scheme_register_embedded_load)(intptr_t len, const char *s); 373 static void (*dll_scheme_register_embedded_load)(intptr_t len, const char *s);
378 static void (*dll_scheme_set_config_path)(Scheme_Object *p); 374 static void (*dll_scheme_set_config_path)(Scheme_Object *p);
379 # endif 375 # endif
380 376
381 #if defined(DYNAMIC_MZSCHEME) /* not when defined(PROTO) */ 377 #if defined(DYNAMIC_MZSCHEME) // not when defined(PROTO)
382 378
383 /* arrays are imported directly */ 379 // arrays are imported directly
384 # define scheme_eof dll_scheme_eof 380 # define scheme_eof dll_scheme_eof
385 # define scheme_false dll_scheme_false 381 # define scheme_false dll_scheme_false
386 # define scheme_void dll_scheme_void 382 # define scheme_void dll_scheme_void
387 # define scheme_null dll_scheme_null 383 # define scheme_null dll_scheme_null
388 # define scheme_true dll_scheme_true 384 # define scheme_true dll_scheme_true
389 385
390 /* pointers are GetProceAddress'ed as pointers to pointer */ 386 // pointers are GetProceAddress'ed as pointers to pointer
391 #if !defined(USE_THREAD_LOCAL) && !defined(LINK_EXTENSIONS_BY_TABLE) 387 #if !defined(USE_THREAD_LOCAL) && !defined(LINK_EXTENSIONS_BY_TABLE)
392 # define scheme_current_thread (*dll_scheme_current_thread_ptr) 388 # define scheme_current_thread (*dll_scheme_current_thread_ptr)
393 # endif 389 # endif
394 # define scheme_console_printf (*dll_scheme_console_printf_ptr) 390 # define scheme_console_printf (*dll_scheme_console_printf_ptr)
395 # define scheme_console_output (*dll_scheme_console_output_ptr) 391 # define scheme_console_output (*dll_scheme_console_output_ptr)
396 # define scheme_notify_multithread (*dll_scheme_notify_multithread_ptr) 392 # define scheme_notify_multithread (*dll_scheme_notify_multithread_ptr)
397 393
398 /* and functions in a usual way */ 394 // and functions in a usual way
399 # define GC_malloc dll_GC_malloc 395 # define GC_malloc dll_GC_malloc
400 # define GC_malloc_atomic dll_GC_malloc_atomic 396 # define GC_malloc_atomic dll_GC_malloc_atomic
401 397
402 # define scheme_add_global dll_scheme_add_global 398 # define scheme_add_global dll_scheme_add_global
403 # define scheme_add_global_symbol dll_scheme_add_global_symbol 399 # define scheme_add_global_symbol dll_scheme_add_global_symbol
502 # define scheme_set_config_path dll_scheme_set_config_path 498 # define scheme_set_config_path dll_scheme_set_config_path
503 # endif 499 # endif
504 500
505 # if MZSCHEME_VERSION_MAJOR >= 500 501 # if MZSCHEME_VERSION_MAJOR >= 500
506 # if defined(IMPLEMENT_THREAD_LOCAL_VIA_WIN_TLS) || defined(IMPLEMENT_THREAD_LOCAL_EXTERNALLY_VIA_PROC) 502 # if defined(IMPLEMENT_THREAD_LOCAL_VIA_WIN_TLS) || defined(IMPLEMENT_THREAD_LOCAL_EXTERNALLY_VIA_PROC)
507 /* define as function for macro in schthread.h */ 503 // define as function for macro in schthread.h
508 Thread_Local_Variables * 504 Thread_Local_Variables *
509 scheme_external_get_thread_local_variables(void) 505 scheme_external_get_thread_local_variables(void)
510 { 506 {
511 return dll_scheme_external_get_thread_local_variables(); 507 return dll_scheme_external_get_thread_local_variables();
512 } 508 }
733 { 729 {
734 FreeLibrary(hMzGC); 730 FreeLibrary(hMzGC);
735 hMzGC = 0; 731 hMzGC = 0;
736 } 732 }
737 } 733 }
738 #endif /* DYNAMIC_MZSCHEME */ 734 #endif // DYNAMIC_MZSCHEME
739 735
740 #if MZSCHEME_VERSION_MAJOR < 299 736 #if MZSCHEME_VERSION_MAJOR < 299
741 # define GUARANTEED_STRING_ARG(proc, num) GUARANTEE_STRING(proc, num) 737 # define GUARANTEED_STRING_ARG(proc, num) GUARANTEE_STRING(proc, num)
742 #else 738 #else
743 static Scheme_Object * 739 static Scheme_Object *
758 MZ_GC_UNREG(); 754 MZ_GC_UNREG();
759 return tmp; 755 return tmp;
760 } 756 }
761 else 757 else
762 scheme_wrong_type(proc, "string", num, argc, argv); 758 scheme_wrong_type(proc, "string", num, argc, argv);
763 /* unreachable */ 759 // unreachable
764 return scheme_void; 760 return scheme_void;
765 } 761 }
766 # define GUARANTEED_STRING_ARG(proc, num) guaranteed_byte_string_arg(proc, num, argc, argv) 762 # define GUARANTEED_STRING_ARG(proc, num) guaranteed_byte_string_arg(proc, num, argc, argv)
767 #endif 763 #endif
768 764
769 /* need to put it here for dynamic stuff to work */ 765 // need to put it here for dynamic stuff to work
770 #if defined(INCLUDE_MZSCHEME_BASE) 766 #if defined(INCLUDE_MZSCHEME_BASE)
771 # include "mzscheme_base.c" 767 # include "mzscheme_base.c"
772 #endif 768 #endif
773 769
774 /* 770 /*
784 #ifdef DYNAMIC_MZSCHEME 780 #ifdef DYNAMIC_MZSCHEME
785 static int disabled = FALSE; 781 static int disabled = FALSE;
786 #endif 782 #endif
787 static int load_base_module_failed = FALSE; 783 static int load_base_module_failed = FALSE;
788 784
789 /* global environment */ 785 // global environment
790 static Scheme_Env *environment = NULL; 786 static Scheme_Env *environment = NULL;
791 /* output/error handlers */ 787 // output/error handlers
792 static Scheme_Object *curout = NULL; 788 static Scheme_Object *curout = NULL;
793 static Scheme_Object *curerr = NULL; 789 static Scheme_Object *curerr = NULL;
794 /* exn:vim exception */ 790 // exn:vim exception
795 static Scheme_Object *exn_catching_apply = NULL; 791 static Scheme_Object *exn_catching_apply = NULL;
796 static Scheme_Object *exn_p = NULL; 792 static Scheme_Object *exn_p = NULL;
797 static Scheme_Object *exn_message = NULL; 793 static Scheme_Object *exn_message = NULL;
798 static Scheme_Object *vim_exn = NULL; /* Vim Error exception */ 794 static Scheme_Object *vim_exn = NULL; // Vim Error exception
799 795
800 #if !defined(MZ_PRECISE_GC) || MZSCHEME_VERSION_MAJOR < 400 796 #if !defined(MZ_PRECISE_GC) || MZSCHEME_VERSION_MAJOR < 400
801 static void *stack_base = NULL; 797 static void *stack_base = NULL;
802 #endif 798 #endif
803 799
804 static long range_start; 800 static long range_start;
805 static long range_end; 801 static long range_end;
806 802
807 /* MzScheme threads scheduling stuff */ 803 // MzScheme threads scheduling stuff
808 static int mz_threads_allow = 0; 804 static int mz_threads_allow = 0;
809 805
810 #if defined(FEAT_GUI_MSWIN) 806 #if defined(FEAT_GUI_MSWIN)
811 static void CALLBACK timer_proc(HWND, UINT, UINT_PTR, DWORD); 807 static void CALLBACK timer_proc(HWND, UINT, UINT_PTR, DWORD);
812 static UINT timer_id = 0; 808 static UINT timer_id = 0;
820 pascal void timer_proc(EventLoopTimerRef, void *); 816 pascal void timer_proc(EventLoopTimerRef, void *);
821 static EventLoopTimerRef timer_id = NULL; 817 static EventLoopTimerRef timer_id = NULL;
822 static EventLoopTimerUPP timerUPP; 818 static EventLoopTimerUPP timerUPP;
823 #endif 819 #endif
824 820
825 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) /* Win32 console and Unix */ 821 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) // Win32 console and Unix
826 void 822 void
827 mzvim_check_threads(void) 823 mzvim_check_threads(void)
828 { 824 {
829 /* Last time MzScheme threads were scheduled */ 825 // Last time MzScheme threads were scheduled
830 static time_t mz_last_time = 0; 826 static time_t mz_last_time = 0;
831 827
832 if (mz_threads_allow && p_mzq > 0) 828 if (mz_threads_allow && p_mzq > 0)
833 { 829 {
834 time_t now = time(NULL); 830 time_t now = time(NULL);
844 840
845 #if defined(MZSCHEME_GUI_THREADS) || defined(PROTO) 841 #if defined(MZSCHEME_GUI_THREADS) || defined(PROTO)
846 static void setup_timer(void); 842 static void setup_timer(void);
847 static void remove_timer(void); 843 static void remove_timer(void);
848 844
849 /* timers are presented in GUI only */ 845 // timers are presented in GUI only
850 # if defined(FEAT_GUI_MSWIN) 846 # if defined(FEAT_GUI_MSWIN)
851 static void CALLBACK 847 static void CALLBACK
852 timer_proc(HWND hwnd UNUSED, UINT uMsg UNUSED, UINT_PTR idEvent UNUSED, DWORD dwTime UNUSED) 848 timer_proc(HWND hwnd UNUSED, UINT uMsg UNUSED, UINT_PTR idEvent UNUSED, DWORD dwTime UNUSED)
853 # elif defined(FEAT_GUI_GTK) 849 # elif defined(FEAT_GUI_GTK)
854 static gboolean 850 static gboolean
861 timer_proc(EventLoopTimerRef theTimer UNUSED, void *userData UNUSED) 857 timer_proc(EventLoopTimerRef theTimer UNUSED, void *userData UNUSED)
862 # endif 858 # endif
863 { 859 {
864 scheme_check_threads(); 860 scheme_check_threads();
865 # if defined(FEAT_GUI_GTK) 861 # if defined(FEAT_GUI_GTK)
866 return TRUE; /* continue receiving notifications */ 862 return TRUE; // continue receiving notifications
867 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA) 863 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)
868 /* renew timeout */ 864 // renew timeout
869 if (mz_threads_allow && p_mzq > 0) 865 if (mz_threads_allow && p_mzq > 0)
870 timer_id = XtAppAddTimeOut(app_context, p_mzq, 866 timer_id = XtAppAddTimeOut(app_context, p_mzq,
871 timer_proc, NULL); 867 timer_proc, NULL);
872 # endif 868 # endif
873 } 869 }
911 remove_timer(); 907 remove_timer();
912 if (mz_threads_allow && p_mzq > 0 && gui.in_use) 908 if (mz_threads_allow && p_mzq > 0 && gui.in_use)
913 setup_timer(); 909 setup_timer();
914 } 910 }
915 911
916 #endif /* MZSCHEME_GUI_THREADS */ 912 #endif // MZSCHEME_GUI_THREADS
917 913
918 static void 914 static void
919 notify_multithread(int on) 915 notify_multithread(int on)
920 { 916 {
921 mz_threads_allow = on; 917 mz_threads_allow = on;
928 } 924 }
929 925
930 void 926 void
931 mzscheme_end(void) 927 mzscheme_end(void)
932 { 928 {
933 /* We can not unload the DLL. Racket's thread might be still alive. */ 929 // We can not unload the DLL. Racket's thread might be still alive.
934 #if 0 930 #if 0
935 #ifdef DYNAMIC_MZSCHEME 931 #ifdef DYNAMIC_MZSCHEME
936 dynamic_mzscheme_end(); 932 dynamic_mzscheme_end();
937 #endif 933 #endif
938 #endif 934 #endif
985 981
986 static int 982 static int
987 mzscheme_env_main(Scheme_Env *env, int argc UNUSED, char **argv UNUSED) 983 mzscheme_env_main(Scheme_Env *env, int argc UNUSED, char **argv UNUSED)
988 { 984 {
989 #ifdef TRAMPOLINED_MZVIM_STARTUP 985 #ifdef TRAMPOLINED_MZVIM_STARTUP
990 /* Scheme has created the environment for us */ 986 // Scheme has created the environment for us
991 environment = env; 987 environment = env;
992 #else 988 #else
993 # ifdef MZ_PRECISE_GC 989 # ifdef MZ_PRECISE_GC
994 Scheme_Object *dummy = NULL; 990 Scheme_Object *dummy = NULL;
995 MZ_GC_DECL_REG(1); 991 MZ_GC_DECL_REG(1);
1001 stack_base = (void *)&dummy; 997 stack_base = (void *)&dummy;
1002 # endif 998 # endif
1003 #endif 999 #endif
1004 1000
1005 vim_main2(); 1001 vim_main2();
1006 /* not reached, vim_main2() will loop until exit() */ 1002 // not reached, vim_main2() will loop until exit()
1007 1003
1008 return 0; 1004 return 0;
1009 } 1005 }
1010 1006
1011 static Scheme_Object* 1007 static Scheme_Object*
1028 #ifndef TRAMPOLINED_MZVIM_STARTUP 1024 #ifndef TRAMPOLINED_MZVIM_STARTUP
1029 scheme_set_stack_base(stack_base, 1); 1025 scheme_set_stack_base(stack_base, 1);
1030 #endif 1026 #endif
1031 1027
1032 #ifndef TRAMPOLINED_MZVIM_STARTUP 1028 #ifndef TRAMPOLINED_MZVIM_STARTUP
1033 /* in newer versions of precise GC the initial env has been created */ 1029 // in newer versions of precise GC the initial env has been created
1034 environment = scheme_basic_env(); 1030 environment = scheme_basic_env();
1035 #endif 1031 #endif
1036 1032
1037 MZ_REGISTER_STATIC(environment); 1033 MZ_REGISTER_STATIC(environment);
1038 MZ_REGISTER_STATIC(curout); 1034 MZ_REGISTER_STATIC(curout);
1043 MZ_REGISTER_STATIC(vim_exn); 1039 MZ_REGISTER_STATIC(vim_exn);
1044 1040
1045 MZ_GC_CHECK(); 1041 MZ_GC_CHECK();
1046 1042
1047 #ifdef INCLUDE_MZSCHEME_BASE 1043 #ifdef INCLUDE_MZSCHEME_BASE
1048 /* invoke function from generated and included mzscheme_base.c */ 1044 // invoke function from generated and included mzscheme_base.c
1049 declare_modules(environment); 1045 declare_modules(environment);
1050 #endif 1046 #endif
1051 1047
1052 /* setup 'current-library-collection-paths' parameter */ 1048 // setup 'current-library-collection-paths' parameter
1053 # if MZSCHEME_VERSION_MAJOR >= 299 1049 # if MZSCHEME_VERSION_MAJOR >= 299
1054 { 1050 {
1055 Scheme_Object *coll_path = NULL; 1051 Scheme_Object *coll_path = NULL;
1056 int mustfree = FALSE; 1052 int mustfree = FALSE;
1057 char_u *s; 1053 char_u *s;
1058 1054
1059 MZ_GC_DECL_REG(1); 1055 MZ_GC_DECL_REG(1);
1060 MZ_GC_VAR_IN_REG(0, coll_path); 1056 MZ_GC_VAR_IN_REG(0, coll_path);
1061 MZ_GC_REG(); 1057 MZ_GC_REG();
1062 /* workaround for dynamic loading on windows */ 1058 // workaround for dynamic loading on windows
1063 s = vim_getenv((char_u *)"PLTCOLLECTS", &mustfree); 1059 s = vim_getenv((char_u *)"PLTCOLLECTS", &mustfree);
1064 if (s != NULL) 1060 if (s != NULL)
1065 { 1061 {
1066 coll_path = scheme_make_path((char *)s); 1062 coll_path = scheme_make_path((char *)s);
1067 MZ_GC_CHECK(); 1063 MZ_GC_CHECK();
1114 char_u *s; 1110 char_u *s;
1115 1111
1116 MZ_GC_DECL_REG(1); 1112 MZ_GC_DECL_REG(1);
1117 MZ_GC_VAR_IN_REG(0, config_path); 1113 MZ_GC_VAR_IN_REG(0, config_path);
1118 MZ_GC_REG(); 1114 MZ_GC_REG();
1119 /* workaround for dynamic loading on windows */ 1115 // workaround for dynamic loading on windows
1120 s = vim_getenv((char_u *)"PLTCONFIGDIR", &mustfree); 1116 s = vim_getenv((char_u *)"PLTCONFIGDIR", &mustfree);
1121 if (s != NULL) 1117 if (s != NULL)
1122 { 1118 {
1123 config_path = scheme_make_path((char *)s); 1119 config_path = scheme_make_path((char *)s);
1124 MZ_GC_CHECK(); 1120 MZ_GC_CHECK();
1148 /* 1144 /*
1149 * versions 4.x do not provide Scheme bindings by default 1145 * versions 4.x do not provide Scheme bindings by default
1150 * we need to add them explicitly 1146 * we need to add them explicitly
1151 */ 1147 */
1152 { 1148 {
1153 /* use error handler to avoid abort */ 1149 // use error handler to avoid abort
1154 scheme_dynamic_wind(NULL, load_base_module, NULL, 1150 scheme_dynamic_wind(NULL, load_base_module, NULL,
1155 load_base_module_on_error, "racket/base"); 1151 load_base_module_on_error, "racket/base");
1156 if (load_base_module_failed) 1152 if (load_base_module_failed)
1157 { 1153 {
1158 load_base_module_failed = FALSE; 1154 load_base_module_failed = FALSE;
1162 return -1; 1158 return -1;
1163 } 1159 }
1164 } 1160 }
1165 1161
1166 register_vim_exn(); 1162 register_vim_exn();
1167 /* use new environment to initialise exception handling */ 1163 // use new environment to initialise exception handling
1168 init_exn_catching_apply(); 1164 init_exn_catching_apply();
1169 1165
1170 /* redirect output */ 1166 // redirect output
1171 scheme_console_output = do_output; 1167 scheme_console_output = do_output;
1172 scheme_console_printf = do_printf; 1168 scheme_console_printf = do_printf;
1173 1169
1174 #ifdef HAVE_SANDBOX 1170 #ifdef HAVE_SANDBOX
1175 { 1171 {
1193 #else 1189 #else
1194 make_security_guard = scheme_builtin_value("make-security-guard"); 1190 make_security_guard = scheme_builtin_value("make-security-guard");
1195 MZ_GC_CHECK(); 1191 MZ_GC_CHECK();
1196 #endif 1192 #endif
1197 1193
1198 /* setup sandbox guards */ 1194 // setup sandbox guards
1199 if (make_security_guard != NULL) 1195 if (make_security_guard != NULL)
1200 { 1196 {
1201 Scheme_Object *args[3] = {NULL, NULL, NULL}; 1197 Scheme_Object *args[3] = {NULL, NULL, NULL};
1202 Scheme_Object *guard = NULL; 1198 Scheme_Object *guard = NULL;
1203 Scheme_Config *config = NULL; 1199 Scheme_Config *config = NULL;
1221 MZ_GC_UNREG(); 1217 MZ_GC_UNREG();
1222 } 1218 }
1223 MZ_GC_UNREG(); 1219 MZ_GC_UNREG();
1224 } 1220 }
1225 #endif 1221 #endif
1226 /* Create buffer and window types for use in Scheme code */ 1222 // Create buffer and window types for use in Scheme code
1227 mz_buffer_type = scheme_make_type("<vim-buffer>"); 1223 mz_buffer_type = scheme_make_type("<vim-buffer>");
1228 MZ_GC_CHECK(); 1224 MZ_GC_CHECK();
1229 mz_window_type = scheme_make_type("<vim-window>"); 1225 mz_window_type = scheme_make_type("<vim-window>");
1230 MZ_GC_CHECK(); 1226 MZ_GC_CHECK();
1231 #ifdef MZ_PRECISE_GC 1227 #ifdef MZ_PRECISE_GC
1276 MZ_GC_DECL_REG(1); 1272 MZ_GC_DECL_REG(1);
1277 MZ_GC_VAR_IN_REG(0, config); 1273 MZ_GC_VAR_IN_REG(0, config);
1278 MZ_GC_REG(); 1274 MZ_GC_REG();
1279 config = scheme_current_config(); 1275 config = scheme_current_config();
1280 MZ_GC_CHECK(); 1276 MZ_GC_CHECK();
1281 /* recreate ports each call effectively clearing these ones */ 1277 // recreate ports each call effectively clearing these ones
1282 curout = scheme_make_byte_string_output_port(); 1278 curout = scheme_make_byte_string_output_port();
1283 MZ_GC_CHECK(); 1279 MZ_GC_CHECK();
1284 curerr = scheme_make_byte_string_output_port(); 1280 curerr = scheme_make_byte_string_output_port();
1285 MZ_GC_CHECK(); 1281 MZ_GC_CHECK();
1286 scheme_set_param(config, MZCONFIG_OUTPUT_PORT, curout); 1282 scheme_set_param(config, MZCONFIG_OUTPUT_PORT, curout);
1321 MZ_GC_CHECK(); 1317 MZ_GC_CHECK();
1322 1318
1323 if (!value) 1319 if (!value)
1324 { 1320 {
1325 value = extract_exn_message(exn); 1321 value = extract_exn_message(exn);
1326 /* Got an exn? */ 1322 // Got an exn?
1327 if (value) 1323 if (value)
1328 { 1324 {
1329 scheme_display(value, curerr); /* Send to stderr-vim */ 1325 scheme_display(value, curerr); // Send to stderr-vim
1330 MZ_GC_CHECK(); 1326 MZ_GC_CHECK();
1331 do_flush(); 1327 do_flush();
1332 } 1328 }
1333 MZ_GC_UNREG(); 1329 MZ_GC_UNREG();
1334 /* `raise' was called on some arbitrary value */ 1330 // `raise' was called on some arbitrary value
1335 return FAIL; 1331 return FAIL;
1336 } 1332 }
1337 1333
1338 if (ret != NULL) /* if pointer to retval supported give it up */ 1334 if (ret != NULL) // if pointer to retval supported give it up
1339 *ret = value; 1335 *ret = value;
1340 /* Print any result, as long as it's not a void */ 1336 // Print any result, as long as it's not a void
1341 else if (!SCHEME_VOIDP(value)) 1337 else if (!SCHEME_VOIDP(value))
1342 { 1338 {
1343 scheme_display(value, curout); /* Send to stdout-vim */ 1339 scheme_display(value, curout); // Send to stdout-vim
1344 MZ_GC_CHECK(); 1340 MZ_GC_CHECK();
1345 } 1341 }
1346 1342
1347 do_flush(); 1343 do_flush();
1348 MZ_GC_UNREG(); 1344 MZ_GC_UNREG();
1349 return OK; 1345 return OK;
1350 } 1346 }
1351 1347
1352 /* :mzscheme */ 1348 /*
1349 * :mzscheme
1350 */
1353 static int 1351 static int
1354 do_mzscheme_command(exarg_T *eap, void *data, Scheme_Closed_Prim *what) 1352 do_mzscheme_command(exarg_T *eap, void *data, Scheme_Closed_Prim *what)
1355 { 1353 {
1356 if (mzscheme_init()) 1354 if (mzscheme_init())
1357 return FAIL; 1355 return FAIL;
1449 MZ_GC_REG(); 1447 MZ_GC_REG();
1450 1448
1451 file = (char *)scheme_malloc_fail_ok(scheme_malloc_atomic, MAXPATHL + 1); 1449 file = (char *)scheme_malloc_fail_ok(scheme_malloc_atomic, MAXPATHL + 1);
1452 MZ_GC_CHECK(); 1450 MZ_GC_CHECK();
1453 1451
1454 /* make Vim expansion */ 1452 // make Vim expansion
1455 expand_env((char_u *)pinfo->name, (char_u *)file, MAXPATHL); 1453 expand_env((char_u *)pinfo->name, (char_u *)file, MAXPATHL);
1456 pinfo->port = scheme_open_input_file(file, "mzfile"); 1454 pinfo->port = scheme_open_input_file(file, "mzfile");
1457 MZ_GC_CHECK(); 1455 MZ_GC_CHECK();
1458 scheme_count_lines(pinfo->port); /* to get accurate read error location*/ 1456 scheme_count_lines(pinfo->port); // to get accurate read error location
1459 MZ_GC_CHECK(); 1457 MZ_GC_CHECK();
1460 1458
1461 /* Like REPL but print only last result */ 1459 // Like REPL but print only last result
1462 while (!SCHEME_EOFP(expr = scheme_read(pinfo->port))) 1460 while (!SCHEME_EOFP(expr = scheme_read(pinfo->port)))
1463 { 1461 {
1464 result = scheme_eval(expr, environment); 1462 result = scheme_eval(expr, environment);
1465 MZ_GC_CHECK(); 1463 MZ_GC_CHECK();
1466 } 1464 }
1467 1465
1468 /* errors will be caught in do_mzscheme_command and ex_mzfile */ 1466 // errors will be caught in do_mzscheme_command and ex_mzfile
1469 scheme_close_input_port(pinfo->port); 1467 scheme_close_input_port(pinfo->port);
1470 MZ_GC_CHECK(); 1468 MZ_GC_CHECK();
1471 pinfo->port = NULL; 1469 pinfo->port = NULL;
1472 MZ_GC_UNREG(); 1470 MZ_GC_UNREG();
1473 return result; 1471 return result;
1474 } 1472 }
1475 1473
1476 /* :mzfile */ 1474 /*
1475 * :mzfile
1476 */
1477 void 1477 void
1478 ex_mzfile(exarg_T *eap) 1478 ex_mzfile(exarg_T *eap)
1479 { 1479 {
1480 Port_Info pinfo = {NULL, NULL}; 1480 Port_Info pinfo = {NULL, NULL};
1481 1481
1483 MZ_GC_VAR_IN_REG(0, pinfo.port); 1483 MZ_GC_VAR_IN_REG(0, pinfo.port);
1484 MZ_GC_REG(); 1484 MZ_GC_REG();
1485 1485
1486 pinfo.name = (char *)eap->arg; 1486 pinfo.name = (char *)eap->arg;
1487 if (do_mzscheme_command(eap, &pinfo, do_load) != OK 1487 if (do_mzscheme_command(eap, &pinfo, do_load) != OK
1488 && pinfo.port != NULL) /* looks like port was not closed */ 1488 && pinfo.port != NULL) // looks like port was not closed
1489 { 1489 {
1490 scheme_close_input_port(pinfo.port); 1490 scheme_close_input_port(pinfo.port);
1491 MZ_GC_CHECK(); 1491 MZ_GC_CHECK();
1492 } 1492 }
1493 MZ_GC_UNREG(); 1493 MZ_GC_UNREG();
1528 _apply_thunk_catch_exceptions(Scheme_Object *f, Scheme_Object **exn) 1528 _apply_thunk_catch_exceptions(Scheme_Object *f, Scheme_Object **exn)
1529 { 1529 {
1530 Scheme_Object *v; 1530 Scheme_Object *v;
1531 1531
1532 v = _scheme_apply(exn_catching_apply, 1, &f); 1532 v = _scheme_apply(exn_catching_apply, 1, &f);
1533 /* v is a pair: (cons #t value) or (cons #f exn) */ 1533 // v is a pair: (cons #t value) or (cons #f exn)
1534 1534
1535 if (SCHEME_TRUEP(SCHEME_CAR(v))) 1535 if (SCHEME_TRUEP(SCHEME_CAR(v)))
1536 return SCHEME_CDR(v); 1536 return SCHEME_CDR(v);
1537 else 1537 else
1538 { 1538 {
1545 extract_exn_message(Scheme_Object *v) 1545 extract_exn_message(Scheme_Object *v)
1546 { 1546 {
1547 if (SCHEME_TRUEP(_scheme_apply(exn_p, 1, &v))) 1547 if (SCHEME_TRUEP(_scheme_apply(exn_p, 1, &v)))
1548 return _scheme_apply(exn_message, 1, &v); 1548 return _scheme_apply(exn_message, 1, &v);
1549 else 1549 else
1550 return NULL; /* Not an exn structure */ 1550 return NULL; // Not an exn structure
1551 } 1551 }
1552 1552
1553 static Scheme_Object * 1553 static Scheme_Object *
1554 do_eval(void *s, int noargc UNUSED, Scheme_Object **noargv UNUSED) 1554 do_eval(void *s, int noargc UNUSED, Scheme_Object **noargv UNUSED)
1555 { 1555 {
1586 } 1586 }
1587 1587
1588 static void 1588 static void
1589 do_output(char *mesg, OUTPUT_LEN_TYPE len UNUSED) 1589 do_output(char *mesg, OUTPUT_LEN_TYPE len UNUSED)
1590 { 1590 {
1591 /* TODO: use len, the string may not be NUL terminated */ 1591 // TODO: use len, the string may not be NUL terminated
1592 do_intrnl_output(mesg, 0); 1592 do_intrnl_output(mesg, 0);
1593 } 1593 }
1594 1594
1595 static void 1595 static void
1596 do_err_output(char *mesg) 1596 do_err_output(char *mesg)
1628 *======================================================================== 1628 *========================================================================
1629 * 4. Implementation of the Vim Features for MzScheme 1629 * 4. Implementation of the Vim Features for MzScheme
1630 *======================================================================== 1630 *========================================================================
1631 */ 1631 */
1632 1632
1633 /* (command {command-string}) */ 1633 /*
1634 * (command {command-string})
1635 */
1634 static Scheme_Object * 1636 static Scheme_Object *
1635 vim_command(void *data, int argc, Scheme_Object **argv) 1637 vim_command(void *data, int argc, Scheme_Object **argv)
1636 { 1638 {
1637 Vim_Prim *prim = (Vim_Prim *)data; 1639 Vim_Prim *prim = (Vim_Prim *)data;
1638 Scheme_Object *cmd = NULL; 1640 Scheme_Object *cmd = NULL;
1639 MZ_GC_DECL_REG(1); 1641 MZ_GC_DECL_REG(1);
1640 MZ_GC_VAR_IN_REG(0, cmd); 1642 MZ_GC_VAR_IN_REG(0, cmd);
1641 MZ_GC_REG(); 1643 MZ_GC_REG();
1642 cmd = GUARANTEED_STRING_ARG(prim->name, 0); 1644 cmd = GUARANTEED_STRING_ARG(prim->name, 0);
1643 1645
1644 /* may be use do_cmdline_cmd? */ 1646 // may be use do_cmdline_cmd?
1645 do_cmdline(BYTE_STRING_VALUE(cmd), NULL, NULL, DOCMD_NOWAIT|DOCMD_VERBOSE); 1647 do_cmdline(BYTE_STRING_VALUE(cmd), NULL, NULL, DOCMD_NOWAIT|DOCMD_VERBOSE);
1646 update_screen(VALID); 1648 update_screen(VALID);
1647 1649
1648 MZ_GC_UNREG(); 1650 MZ_GC_UNREG();
1649 raise_if_error(); 1651 raise_if_error();
1650 return scheme_void; 1652 return scheme_void;
1651 } 1653 }
1652 1654
1653 /* (eval {expr-string}) */ 1655 /*
1656 * (eval {expr-string})
1657 */
1654 static Scheme_Object * 1658 static Scheme_Object *
1655 vim_eval(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) 1659 vim_eval(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED)
1656 { 1660 {
1657 #ifdef FEAT_EVAL 1661 #ifdef FEAT_EVAL
1658 Vim_Prim *prim = (Vim_Prim *)data; 1662 Vim_Prim *prim = (Vim_Prim *)data;
1676 1680
1677 MZ_GC_UNREG(); 1681 MZ_GC_UNREG();
1678 return result; 1682 return result;
1679 #else 1683 #else
1680 raise_vim_exn(_("expressions disabled at compile time")); 1684 raise_vim_exn(_("expressions disabled at compile time"));
1681 /* unreachable */ 1685 // unreachable
1682 return scheme_false; 1686 return scheme_false;
1683 #endif 1687 #endif
1684 } 1688 }
1685 1689
1686 /* (range-start) */ 1690 /*
1691 * (range-start)
1692 */
1687 static Scheme_Object * 1693 static Scheme_Object *
1688 get_range_start(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) 1694 get_range_start(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED)
1689 { 1695 {
1690 return scheme_make_integer(range_start); 1696 return scheme_make_integer(range_start);
1691 } 1697 }
1692 1698
1693 /* (range-end) */ 1699 /*
1700 * (range-end)
1701 */
1694 static Scheme_Object * 1702 static Scheme_Object *
1695 get_range_end(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) 1703 get_range_end(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED)
1696 { 1704 {
1697 return scheme_make_integer(range_end); 1705 return scheme_make_integer(range_end);
1698 } 1706 }
1699 1707
1700 /* (beep) */ 1708 /*
1709 * (beep)
1710 */
1701 static Scheme_Object * 1711 static Scheme_Object *
1702 mzscheme_beep(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) 1712 mzscheme_beep(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED)
1703 { 1713 {
1704 vim_beep(BO_LANG); 1714 vim_beep(BO_LANG);
1705 return scheme_void; 1715 return scheme_void;
1706 } 1716 }
1707 1717
1708 static Scheme_Object *M_global = NULL; 1718 static Scheme_Object *M_global = NULL;
1709 1719
1710 /* (get-option {option-name}) [buffer/window] */ 1720 /*
1721 * (get-option {option-name}) [buffer/window]
1722 */
1711 static Scheme_Object * 1723 static Scheme_Object *
1712 get_option(void *data, int argc, Scheme_Object **argv) 1724 get_option(void *data, int argc, Scheme_Object **argv)
1713 { 1725 {
1714 Vim_Prim *prim = (Vim_Prim *)data; 1726 Vim_Prim *prim = (Vim_Prim *)data;
1715 long value; 1727 long value;
1773 return rval; 1785 return rval;
1774 case -1: 1786 case -1:
1775 case -2: 1787 case -2:
1776 MZ_GC_UNREG(); 1788 MZ_GC_UNREG();
1777 raise_vim_exn(_("hidden option")); 1789 raise_vim_exn(_("hidden option"));
1778 /*NOTREACHED*/ 1790 //NOTREACHED
1779 case -3: 1791 case -3:
1780 MZ_GC_UNREG(); 1792 MZ_GC_UNREG();
1781 raise_vim_exn(_("unknown option")); 1793 raise_vim_exn(_("unknown option"));
1782 /*NOTREACHED*/ 1794 //NOTREACHED
1783 } 1795 }
1784 /* unreachable */ 1796 // unreachable
1785 return scheme_void; 1797 return scheme_void;
1786 } 1798 }
1787 1799
1788 /* (set-option {option-changing-string} [buffer/window]) */ 1800 /*
1801 * (set-option {option-changing-string} [buffer/window])
1802 */
1789 static Scheme_Object * 1803 static Scheme_Object *
1790 set_option(void *data, int argc, Scheme_Object **argv) 1804 set_option(void *data, int argc, Scheme_Object **argv)
1791 { 1805 {
1792 char_u *command = NULL; 1806 char_u *command = NULL;
1793 int opt_flags = 0; 1807 int opt_flags = 0;
1826 } 1840 }
1827 else 1841 else
1828 scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv); 1842 scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv);
1829 } 1843 }
1830 1844
1831 /* do_set can modify cmd, make copy */ 1845 // do_set can modify cmd, make copy
1832 command = vim_strsave(BYTE_STRING_VALUE(cmd)); 1846 command = vim_strsave(BYTE_STRING_VALUE(cmd));
1833 MZ_GC_UNREG(); 1847 MZ_GC_UNREG();
1834 do_set(command, opt_flags); 1848 do_set(command, opt_flags);
1835 vim_free(command); 1849 vim_free(command);
1836 update_screen(NOT_VALID); 1850 update_screen(NOT_VALID);
1844 *=========================================================================== 1858 *===========================================================================
1845 * 5. Vim Window-related Manipulation Functions 1859 * 5. Vim Window-related Manipulation Functions
1846 *=========================================================================== 1860 *===========================================================================
1847 */ 1861 */
1848 1862
1849 /* (curr-win) */ 1863 /*
1864 * (curr-win)
1865 */
1850 static Scheme_Object * 1866 static Scheme_Object *
1851 get_curr_win(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) 1867 get_curr_win(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED)
1852 { 1868 {
1853 return (Scheme_Object *)get_vim_curr_window(); 1869 return (Scheme_Object *)get_vim_curr_window();
1854 } 1870 }
1855 1871
1856 /* (win-count) */ 1872 /*
1873 * (win-count)
1874 */
1857 static Scheme_Object * 1875 static Scheme_Object *
1858 get_window_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) 1876 get_window_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED)
1859 { 1877 {
1860 int n = 0; 1878 int n = 0;
1861 win_T *w; 1879 win_T *w;
1863 FOR_ALL_WINDOWS(w) 1881 FOR_ALL_WINDOWS(w)
1864 ++n; 1882 ++n;
1865 return scheme_make_integer(n); 1883 return scheme_make_integer(n);
1866 } 1884 }
1867 1885
1868 /* (get-win-list [buffer]) */ 1886 /*
1887 * (get-win-list [buffer])
1888 */
1869 static Scheme_Object * 1889 static Scheme_Object *
1870 get_window_list(void *data, int argc, Scheme_Object **argv) 1890 get_window_list(void *data, int argc, Scheme_Object **argv)
1871 { 1891 {
1872 Vim_Prim *prim = (Vim_Prim *)data; 1892 Vim_Prim *prim = (Vim_Prim *)data;
1873 vim_mz_buffer *buf; 1893 vim_mz_buffer *buf;
1893 vim_mz_window *self = NULL; 1913 vim_mz_window *self = NULL;
1894 1914
1895 MZ_GC_DECL_REG(1); 1915 MZ_GC_DECL_REG(1);
1896 MZ_GC_VAR_IN_REG(0, self); 1916 MZ_GC_VAR_IN_REG(0, self);
1897 1917
1898 /* We need to handle deletion of windows underneath us. 1918 // We need to handle deletion of windows underneath us.
1899 * If we add a "w_mzscheme_ref" field to the win_T structure, 1919 // If we add a "w_mzscheme_ref" field to the win_T structure,
1900 * then we can get at it in win_free() in vim. 1920 // then we can get at it in win_free() in vim.
1901 * 1921 //
1902 * On a win_free() we set the Scheme object's win_T *field 1922 // On a win_free() we set the Scheme object's win_T *field
1903 * to an invalid value. We trap all uses of a window 1923 // to an invalid value. We trap all uses of a window
1904 * object, and reject them if the win_T *field is invalid. 1924 // object, and reject them if the win_T *field is invalid.
1905 */
1906 if (win->w_mzscheme_ref != NULL) 1925 if (win->w_mzscheme_ref != NULL)
1907 return (Scheme_Object *)WINDOW_REF(win); 1926 return (Scheme_Object *)WINDOW_REF(win);
1908 1927
1909 MZ_GC_REG(); 1928 MZ_GC_REG();
1910 self = scheme_malloc_fail_ok(scheme_malloc_tagged, sizeof(vim_mz_window)); 1929 self = scheme_malloc_fail_ok(scheme_malloc_tagged, sizeof(vim_mz_window));
1911 vim_memset(self, 0, sizeof(vim_mz_window)); 1930 vim_memset(self, 0, sizeof(vim_mz_window));
1912 #ifndef MZ_PRECISE_GC 1931 #ifndef MZ_PRECISE_GC
1913 scheme_dont_gc_ptr(self); /* because win isn't visible to GC */ 1932 scheme_dont_gc_ptr(self); // because win isn't visible to GC
1914 #else 1933 #else
1915 win->w_mzscheme_ref = scheme_malloc_immobile_box(NULL); 1934 win->w_mzscheme_ref = scheme_malloc_immobile_box(NULL);
1916 #endif 1935 #endif
1917 MZ_GC_CHECK(); 1936 MZ_GC_CHECK();
1918 WINDOW_REF(win) = self; 1937 WINDOW_REF(win) = self;
1922 1941
1923 MZ_GC_UNREG(); 1942 MZ_GC_UNREG();
1924 return (Scheme_Object *)self; 1943 return (Scheme_Object *)self;
1925 } 1944 }
1926 1945
1927 /* (get-win-num [window]) */ 1946 /*
1947 * (get-win-num [window])
1948 */
1928 static Scheme_Object * 1949 static Scheme_Object *
1929 get_window_num(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) 1950 get_window_num(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED)
1930 { 1951 {
1931 int nr = 1; 1952 int nr = 1;
1932 Vim_Prim *prim = (Vim_Prim *)data; 1953 Vim_Prim *prim = (Vim_Prim *)data;
1937 ++nr; 1958 ++nr;
1938 1959
1939 return scheme_make_integer(nr); 1960 return scheme_make_integer(nr);
1940 } 1961 }
1941 1962
1942 /* (get-win-by-num {windownum}) */ 1963 /*
1964 * (get-win-by-num {windownum})
1965 */
1943 static Scheme_Object * 1966 static Scheme_Object *
1944 get_window_by_num(void *data, int argc, Scheme_Object **argv) 1967 get_window_by_num(void *data, int argc, Scheme_Object **argv)
1945 { 1968 {
1946 Vim_Prim *prim = (Vim_Prim *)data; 1969 Vim_Prim *prim = (Vim_Prim *)data;
1947 win_T *win = firstwin; 1970 win_T *win = firstwin;
1950 fnum = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); 1973 fnum = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
1951 if (fnum < 1) 1974 if (fnum < 1)
1952 scheme_signal_error(_("window index is out of range")); 1975 scheme_signal_error(_("window index is out of range"));
1953 1976
1954 for ( ; win != NULL; win = win->w_next, --fnum) 1977 for ( ; win != NULL; win = win->w_next, --fnum)
1955 if (fnum == 1) /* to be 1-based */ 1978 if (fnum == 1) // to be 1-based
1956 return window_new(win); 1979 return window_new(win);
1957 1980
1958 return scheme_false; 1981 return scheme_false;
1959 } 1982 }
1960 1983
1961 /* (get-win-buffer [window]) */ 1984 /*
1985 * (get-win-buffer [window])
1986 */
1962 static Scheme_Object * 1987 static Scheme_Object *
1963 get_window_buffer(void *data, int argc, Scheme_Object **argv) 1988 get_window_buffer(void *data, int argc, Scheme_Object **argv)
1964 { 1989 {
1965 Vim_Prim *prim = (Vim_Prim *)data; 1990 Vim_Prim *prim = (Vim_Prim *)data;
1966 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv); 1991 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv);
1967 1992
1968 return buffer_new(win->win->w_buffer); 1993 return buffer_new(win->win->w_buffer);
1969 } 1994 }
1970 1995
1971 /* (get-win-height [window]) */ 1996 /*
1997 * (get-win-height [window])
1998 */
1972 static Scheme_Object * 1999 static Scheme_Object *
1973 get_window_height(void *data, int argc, Scheme_Object **argv) 2000 get_window_height(void *data, int argc, Scheme_Object **argv)
1974 { 2001 {
1975 Vim_Prim *prim = (Vim_Prim *)data; 2002 Vim_Prim *prim = (Vim_Prim *)data;
1976 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv); 2003 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv);
1977 2004
1978 return scheme_make_integer(win->win->w_height); 2005 return scheme_make_integer(win->win->w_height);
1979 } 2006 }
1980 2007
1981 /* (set-win-height {height} [window]) */ 2008 /*
2009 * (set-win-height {height} [window])
2010 */
1982 static Scheme_Object * 2011 static Scheme_Object *
1983 set_window_height(void *data, int argc, Scheme_Object **argv) 2012 set_window_height(void *data, int argc, Scheme_Object **argv)
1984 { 2013 {
1985 Vim_Prim *prim = (Vim_Prim *)data; 2014 Vim_Prim *prim = (Vim_Prim *)data;
1986 vim_mz_window *win; 2015 vim_mz_window *win;
2001 2030
2002 raise_if_error(); 2031 raise_if_error();
2003 return scheme_void; 2032 return scheme_void;
2004 } 2033 }
2005 2034
2006 /* (get-win-width [window]) */ 2035 /*
2036 * (get-win-width [window])
2037 */
2007 static Scheme_Object * 2038 static Scheme_Object *
2008 get_window_width(void *data, int argc, Scheme_Object **argv) 2039 get_window_width(void *data, int argc, Scheme_Object **argv)
2009 { 2040 {
2010 Vim_Prim *prim = (Vim_Prim *)data; 2041 Vim_Prim *prim = (Vim_Prim *)data;
2011 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv); 2042 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv);
2012 2043
2013 return scheme_make_integer(win->win->w_width); 2044 return scheme_make_integer(win->win->w_width);
2014 } 2045 }
2015 2046
2016 /* (set-win-width {width} [window]) */ 2047 /*
2048 * (set-win-width {width} [window])
2049 */
2017 static Scheme_Object * 2050 static Scheme_Object *
2018 set_window_width(void *data, int argc, Scheme_Object **argv) 2051 set_window_width(void *data, int argc, Scheme_Object **argv)
2019 { 2052 {
2020 Vim_Prim *prim = (Vim_Prim *)data; 2053 Vim_Prim *prim = (Vim_Prim *)data;
2021 vim_mz_window *win; 2054 vim_mz_window *win;
2036 2069
2037 raise_if_error(); 2070 raise_if_error();
2038 return scheme_void; 2071 return scheme_void;
2039 } 2072 }
2040 2073
2041 /* (get-cursor [window]) -> (line . col) */ 2074 /*
2075 * (get-cursor [window]) -> (line . col)
2076 */
2042 static Scheme_Object * 2077 static Scheme_Object *
2043 get_cursor(void *data, int argc, Scheme_Object **argv) 2078 get_cursor(void *data, int argc, Scheme_Object **argv)
2044 { 2079 {
2045 Vim_Prim *prim = (Vim_Prim *)data; 2080 Vim_Prim *prim = (Vim_Prim *)data;
2046 vim_mz_window *win; 2081 vim_mz_window *win;
2050 pos = win->win->w_cursor; 2085 pos = win->win->w_cursor;
2051 return scheme_make_pair(scheme_make_integer_value((long)pos.lnum), 2086 return scheme_make_pair(scheme_make_integer_value((long)pos.lnum),
2052 scheme_make_integer_value((long)pos.col + 1)); 2087 scheme_make_integer_value((long)pos.col + 1));
2053 } 2088 }
2054 2089
2055 /* (set-cursor (line . col) [window]) */ 2090 /*
2091 * (set-cursor (line . col) [window])
2092 */
2056 static Scheme_Object * 2093 static Scheme_Object *
2057 set_cursor(void *data, int argc, Scheme_Object **argv) 2094 set_cursor(void *data, int argc, Scheme_Object **argv)
2058 { 2095 {
2059 Vim_Prim *prim = (Vim_Prim *)data; 2096 Vim_Prim *prim = (Vim_Prim *)data;
2060 vim_mz_window *win; 2097 vim_mz_window *win;
2073 2110
2074 lnum = SCHEME_INT_VAL(SCHEME_CAR(argv[0])); 2111 lnum = SCHEME_INT_VAL(SCHEME_CAR(argv[0]));
2075 col = SCHEME_INT_VAL(SCHEME_CDR(argv[0])) - 1; 2112 col = SCHEME_INT_VAL(SCHEME_CDR(argv[0])) - 1;
2076 2113
2077 check_line_range(lnum, win->win->w_buffer); 2114 check_line_range(lnum, win->win->w_buffer);
2078 /* don't know how to catch invalid column value */ 2115 // don't know how to catch invalid column value
2079 2116
2080 win->win->w_cursor.lnum = lnum; 2117 win->win->w_cursor.lnum = lnum;
2081 win->win->w_cursor.col = col; 2118 win->win->w_cursor.col = col;
2082 win->win->w_set_curswant = TRUE; 2119 win->win->w_set_curswant = TRUE;
2083 update_screen(VALID); 2120 update_screen(VALID);
2089 *=========================================================================== 2126 *===========================================================================
2090 * 6. Vim Buffer-related Manipulation Functions 2127 * 6. Vim Buffer-related Manipulation Functions
2091 *=========================================================================== 2128 *===========================================================================
2092 */ 2129 */
2093 2130
2094 /* (open-buff {filename}) */ 2131 /*
2132 * (open-buff {filename})
2133 */
2095 static Scheme_Object * 2134 static Scheme_Object *
2096 mzscheme_open_buffer(void *data, int argc, Scheme_Object **argv) 2135 mzscheme_open_buffer(void *data, int argc, Scheme_Object **argv)
2097 { 2136 {
2098 Vim_Prim *prim = (Vim_Prim *)data; 2137 Vim_Prim *prim = (Vim_Prim *)data;
2099 int num = 0; 2138 int num = 0;
2109 fname = GUARANTEED_STRING_ARG(prim->name, 0); 2148 fname = GUARANTEED_STRING_ARG(prim->name, 0);
2110 2149
2111 #ifdef HAVE_SANDBOX 2150 #ifdef HAVE_SANDBOX
2112 sandbox_check(); 2151 sandbox_check();
2113 #endif 2152 #endif
2114 /* TODO make open existing file */ 2153 // TODO make open existing file
2115 num = buflist_add(BYTE_STRING_VALUE(fname), BLN_LISTED | BLN_CURBUF); 2154 num = buflist_add(BYTE_STRING_VALUE(fname), BLN_LISTED | BLN_CURBUF);
2116 2155
2117 if (num == 0) 2156 if (num == 0)
2118 raise_vim_exn(_("couldn't open buffer")); 2157 raise_vim_exn(_("couldn't open buffer"));
2119 2158
2121 buf = get_buffer_by_num(data, 1, &onum); 2160 buf = get_buffer_by_num(data, 1, &onum);
2122 MZ_GC_UNREG(); 2161 MZ_GC_UNREG();
2123 return buf; 2162 return buf;
2124 } 2163 }
2125 2164
2126 /* (get-buff-by-num {buffernum}) */ 2165 /*
2166 * (get-buff-by-num {buffernum})
2167 */
2127 static Scheme_Object * 2168 static Scheme_Object *
2128 get_buffer_by_num(void *data, int argc, Scheme_Object **argv) 2169 get_buffer_by_num(void *data, int argc, Scheme_Object **argv)
2129 { 2170 {
2130 Vim_Prim *prim = (Vim_Prim *)data; 2171 Vim_Prim *prim = (Vim_Prim *)data;
2131 buf_T *buf; 2172 buf_T *buf;
2138 return buffer_new(buf); 2179 return buffer_new(buf);
2139 2180
2140 return scheme_false; 2181 return scheme_false;
2141 } 2182 }
2142 2183
2143 /* (get-buff-by-name {buffername}) */ 2184 /*
2185 * (get-buff-by-name {buffername})
2186 */
2144 static Scheme_Object * 2187 static Scheme_Object *
2145 get_buffer_by_name(void *data, int argc, Scheme_Object **argv) 2188 get_buffer_by_name(void *data, int argc, Scheme_Object **argv)
2146 { 2189 {
2147 Vim_Prim *prim = (Vim_Prim *)data; 2190 Vim_Prim *prim = (Vim_Prim *)data;
2148 buf_T *buf; 2191 buf_T *buf;
2157 buffer = scheme_false; 2200 buffer = scheme_false;
2158 2201
2159 FOR_ALL_BUFFERS(buf) 2202 FOR_ALL_BUFFERS(buf)
2160 { 2203 {
2161 if (buf->b_ffname == NULL || buf->b_sfname == NULL) 2204 if (buf->b_ffname == NULL || buf->b_sfname == NULL)
2162 /* empty string */ 2205 // empty string
2163 { 2206 {
2164 if (BYTE_STRING_VALUE(fname)[0] == NUL) 2207 if (BYTE_STRING_VALUE(fname)[0] == NUL)
2165 buffer = buffer_new(buf); 2208 buffer = buffer_new(buf);
2166 } 2209 }
2167 else if (!fnamecmp(buf->b_ffname, BYTE_STRING_VALUE(fname)) 2210 else if (!fnamecmp(buf->b_ffname, BYTE_STRING_VALUE(fname))
2168 || !fnamecmp(buf->b_sfname, BYTE_STRING_VALUE(fname))) 2211 || !fnamecmp(buf->b_sfname, BYTE_STRING_VALUE(fname)))
2169 { 2212 {
2170 /* either short or long filename matches */ 2213 // either short or long filename matches
2171 buffer = buffer_new(buf); 2214 buffer = buffer_new(buf);
2172 } 2215 }
2173 } 2216 }
2174 2217
2175 MZ_GC_UNREG(); 2218 MZ_GC_UNREG();
2176 return buffer; 2219 return buffer;
2177 } 2220 }
2178 2221
2179 /* (get-next-buff [buffer]) */ 2222 /*
2223 * (get-next-buff [buffer])
2224 */
2180 static Scheme_Object * 2225 static Scheme_Object *
2181 get_next_buffer(void *data, int argc, Scheme_Object **argv) 2226 get_next_buffer(void *data, int argc, Scheme_Object **argv)
2182 { 2227 {
2183 Vim_Prim *prim = (Vim_Prim *)data; 2228 Vim_Prim *prim = (Vim_Prim *)data;
2184 buf_T *buf = get_buffer_arg(prim->name, 0, argc, argv)->buf; 2229 buf_T *buf = get_buffer_arg(prim->name, 0, argc, argv)->buf;
2187 return scheme_false; 2232 return scheme_false;
2188 else 2233 else
2189 return buffer_new(buf->b_next); 2234 return buffer_new(buf->b_next);
2190 } 2235 }
2191 2236
2192 /* (get-prev-buff [buffer]) */ 2237 /*
2238 * (get-prev-buff [buffer])
2239 */
2193 static Scheme_Object * 2240 static Scheme_Object *
2194 get_prev_buffer(void *data, int argc, Scheme_Object **argv) 2241 get_prev_buffer(void *data, int argc, Scheme_Object **argv)
2195 { 2242 {
2196 Vim_Prim *prim = (Vim_Prim *)data; 2243 Vim_Prim *prim = (Vim_Prim *)data;
2197 buf_T *buf = get_buffer_arg(prim->name, 0, argc, argv)->buf; 2244 buf_T *buf = get_buffer_arg(prim->name, 0, argc, argv)->buf;
2200 return scheme_false; 2247 return scheme_false;
2201 else 2248 else
2202 return buffer_new(buf->b_prev); 2249 return buffer_new(buf->b_prev);
2203 } 2250 }
2204 2251
2205 /* (get-buff-num [buffer]) */ 2252 /*
2253 * (get-buff-num [buffer])
2254 */
2206 static Scheme_Object * 2255 static Scheme_Object *
2207 get_buffer_num(void *data, int argc, Scheme_Object **argv) 2256 get_buffer_num(void *data, int argc, Scheme_Object **argv)
2208 { 2257 {
2209 Vim_Prim *prim = (Vim_Prim *)data; 2258 Vim_Prim *prim = (Vim_Prim *)data;
2210 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv); 2259 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv);
2211 2260
2212 return scheme_make_integer(buf->buf->b_fnum); 2261 return scheme_make_integer(buf->buf->b_fnum);
2213 } 2262 }
2214 2263
2215 /* (buff-count) */ 2264 /*
2265 * (buff-count)
2266 */
2216 static Scheme_Object * 2267 static Scheme_Object *
2217 get_buffer_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) 2268 get_buffer_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED)
2218 { 2269 {
2219 buf_T *b; 2270 buf_T *b;
2220 int n = 0; 2271 int n = 0;
2221 2272
2222 FOR_ALL_BUFFERS(b) ++n; 2273 FOR_ALL_BUFFERS(b) ++n;
2223 return scheme_make_integer(n); 2274 return scheme_make_integer(n);
2224 } 2275 }
2225 2276
2226 /* (get-buff-name [buffer]) */ 2277 /*
2278 * (get-buff-name [buffer])
2279 */
2227 static Scheme_Object * 2280 static Scheme_Object *
2228 get_buffer_name(void *data, int argc, Scheme_Object **argv) 2281 get_buffer_name(void *data, int argc, Scheme_Object **argv)
2229 { 2282 {
2230 Vim_Prim *prim = (Vim_Prim *)data; 2283 Vim_Prim *prim = (Vim_Prim *)data;
2231 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv); 2284 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv);
2232 2285
2233 return scheme_make_byte_string((char *)buf->buf->b_ffname); 2286 return scheme_make_byte_string((char *)buf->buf->b_ffname);
2234 } 2287 }
2235 2288
2236 /* (curr-buff) */ 2289 /*
2290 * (curr-buff)
2291 */
2237 static Scheme_Object * 2292 static Scheme_Object *
2238 get_curr_buffer(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) 2293 get_curr_buffer(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED)
2239 { 2294 {
2240 return (Scheme_Object *)get_vim_curr_buffer(); 2295 return (Scheme_Object *)get_vim_curr_buffer();
2241 } 2296 }
2246 vim_mz_buffer *self = NULL; 2301 vim_mz_buffer *self = NULL;
2247 2302
2248 MZ_GC_DECL_REG(1); 2303 MZ_GC_DECL_REG(1);
2249 MZ_GC_VAR_IN_REG(0, self); 2304 MZ_GC_VAR_IN_REG(0, self);
2250 2305
2251 /* We need to handle deletion of buffers underneath us. 2306 // We need to handle deletion of buffers underneath us.
2252 * If we add a "b_mzscheme_ref" field to the buf_T structure, 2307 // If we add a "b_mzscheme_ref" field to the buf_T structure,
2253 * then we can get at it in buf_freeall() in vim. 2308 // then we can get at it in buf_freeall() in vim.
2254 */
2255 if (buf->b_mzscheme_ref) 2309 if (buf->b_mzscheme_ref)
2256 return (Scheme_Object *)BUFFER_REF(buf); 2310 return (Scheme_Object *)BUFFER_REF(buf);
2257 2311
2258 MZ_GC_REG(); 2312 MZ_GC_REG();
2259 self = scheme_malloc_fail_ok(scheme_malloc_tagged, sizeof(vim_mz_buffer)); 2313 self = scheme_malloc_fail_ok(scheme_malloc_tagged, sizeof(vim_mz_buffer));
2260 vim_memset(self, 0, sizeof(vim_mz_buffer)); 2314 vim_memset(self, 0, sizeof(vim_mz_buffer));
2261 #ifndef MZ_PRECISE_GC 2315 #ifndef MZ_PRECISE_GC
2262 scheme_dont_gc_ptr(self); /* because buf isn't visible to GC */ 2316 scheme_dont_gc_ptr(self); // because buf isn't visible to GC
2263 #else 2317 #else
2264 buf->b_mzscheme_ref = scheme_malloc_immobile_box(NULL); 2318 buf->b_mzscheme_ref = scheme_malloc_immobile_box(NULL);
2265 #endif 2319 #endif
2266 MZ_GC_CHECK(); 2320 MZ_GC_CHECK();
2267 BUFFER_REF(buf) = self; 2321 BUFFER_REF(buf) = self;
2352 { 2406 {
2353 Scheme_Object *str = scheme_make_byte_string( 2407 Scheme_Object *str = scheme_make_byte_string(
2354 (char *)ml_get_buf(buf->buf, (linenr_T)(lo+i), FALSE)); 2408 (char *)ml_get_buf(buf->buf, (linenr_T)(lo+i), FALSE));
2355 raise_if_error(); 2409 raise_if_error();
2356 2410
2357 /* Set the list item */ 2411 // Set the list item
2358 list = scheme_make_pair(str, list); 2412 list = scheme_make_pair(str, list);
2359 MZ_GC_CHECK(); 2413 MZ_GC_CHECK();
2360 } 2414 }
2361 MZ_GC_UNREG(); 2415 MZ_GC_UNREG();
2362 return list; 2416 return list;
2375 * string changed. 2429 * string changed.
2376 */ 2430 */
2377 static Scheme_Object * 2431 static Scheme_Object *
2378 set_buffer_line(void *data, int argc, Scheme_Object **argv) 2432 set_buffer_line(void *data, int argc, Scheme_Object **argv)
2379 { 2433 {
2380 /* First of all, we check the value of the supplied MzScheme object. 2434 // First of all, we check the value of the supplied MzScheme object.
2381 * There are three cases: 2435 // There are three cases:
2382 * 1. #f - this is a deletion. 2436 // 1. #f - this is a deletion.
2383 * 2. A string - this is a replacement. 2437 // 2. A string - this is a replacement.
2384 * 3. Anything else - this is an error. 2438 // 3. Anything else - this is an error.
2385 */
2386 Vim_Prim *prim = (Vim_Prim *)data; 2439 Vim_Prim *prim = (Vim_Prim *)data;
2387 vim_mz_buffer *buf; 2440 vim_mz_buffer *buf;
2388 Scheme_Object *line = NULL; 2441 Scheme_Object *line = NULL;
2389 char *save; 2442 char *save;
2390 int n; 2443 int n;
2430 raise_if_error(); 2483 raise_if_error();
2431 return scheme_void; 2484 return scheme_void;
2432 } 2485 }
2433 else 2486 else
2434 { 2487 {
2435 /* Otherwise it's a line */ 2488 // Otherwise it's a line
2436 buf_T *savebuf = curbuf; 2489 buf_T *savebuf = curbuf;
2437 2490
2438 save = string_to_line(line); 2491 save = string_to_line(line);
2439 2492
2440 curbuf = buf->buf; 2493 curbuf = buf->buf;
2457 changed_bytes((linenr_T)n, 0); 2510 changed_bytes((linenr_T)n, 0);
2458 } 2511 }
2459 2512
2460 curbuf = savebuf; 2513 curbuf = savebuf;
2461 2514
2462 /* Check that the cursor is not beyond the end of the line now. */ 2515 // Check that the cursor is not beyond the end of the line now.
2463 if (buf->buf == curwin->w_buffer) 2516 if (buf->buf == curwin->w_buffer)
2464 check_cursor_col(); 2517 check_cursor_col();
2465 2518
2466 MZ_GC_UNREG(); 2519 MZ_GC_UNREG();
2467 raise_if_error(); 2520 raise_if_error();
2491 * change in the buffer length. 2544 * change in the buffer length.
2492 */ 2545 */
2493 static Scheme_Object * 2546 static Scheme_Object *
2494 set_buffer_line_list(void *data, int argc, Scheme_Object **argv) 2547 set_buffer_line_list(void *data, int argc, Scheme_Object **argv)
2495 { 2548 {
2496 /* First of all, we check the type of the supplied MzScheme object. 2549 // First of all, we check the type of the supplied MzScheme object.
2497 * There are three cases: 2550 // There are three cases:
2498 * 1. #f - this is a deletion. 2551 // 1. #f - this is a deletion.
2499 * 2. A list - this is a replacement. 2552 // 2. A list - this is a replacement.
2500 * 3. Anything else - this is an error. 2553 // 3. Anything else - this is an error.
2501 */
2502 Vim_Prim *prim = (Vim_Prim *)data; 2554 Vim_Prim *prim = (Vim_Prim *)data;
2503 vim_mz_buffer *buf = NULL; 2555 vim_mz_buffer *buf = NULL;
2504 Scheme_Object *line_list = NULL; 2556 Scheme_Object *line_list = NULL;
2505 int i, old_len, new_len, hi, lo; 2557 int i, old_len, new_len, hi, lo;
2506 long extra; 2558 long extra;
2518 && !SCHEME_FALSEP(argv[2]) && !SCHEME_NULLP(argv[2])) 2570 && !SCHEME_FALSEP(argv[2]) && !SCHEME_NULLP(argv[2]))
2519 scheme_wrong_type(prim->name, "list or #f", 2, argc, argv); 2571 scheme_wrong_type(prim->name, "list or #f", 2, argc, argv);
2520 line_list = argv[2]; 2572 line_list = argv[2];
2521 buf = get_buffer_arg(prim->name, 3, argc, argv); 2573 buf = get_buffer_arg(prim->name, 3, argc, argv);
2522 old_len = hi - lo; 2574 old_len = hi - lo;
2523 if (old_len < 0) /* process inverse values wisely */ 2575 if (old_len < 0) // process inverse values wisely
2524 { 2576 {
2525 i = lo; 2577 i = lo;
2526 lo = hi; 2578 lo = hi;
2527 hi = i; 2579 hi = i;
2528 old_len = -old_len; 2580 old_len = -old_len;
2529 } 2581 }
2530 extra = 0; 2582 extra = 0;
2531 2583
2532 check_line_range(lo, buf->buf); /* inclusive */ 2584 check_line_range(lo, buf->buf); // inclusive
2533 check_line_range(hi - 1, buf->buf); /* exclusive */ 2585 check_line_range(hi - 1, buf->buf); // exclusive
2534 2586
2535 if (SCHEME_FALSEP(line_list) || SCHEME_NULLP(line_list)) 2587 if (SCHEME_FALSEP(line_list) || SCHEME_NULLP(line_list))
2536 { 2588 {
2537 buf_T *savebuf = curbuf; 2589 buf_T *savebuf = curbuf;
2538 curbuf = buf->buf; 2590 curbuf = buf->buf;
2563 } 2615 }
2564 else 2616 else
2565 { 2617 {
2566 buf_T *savebuf = curbuf; 2618 buf_T *savebuf = curbuf;
2567 2619
2568 /* List */ 2620 // List
2569 new_len = scheme_proper_list_length(line_list); 2621 new_len = scheme_proper_list_length(line_list);
2570 MZ_GC_CHECK(); 2622 MZ_GC_CHECK();
2571 if (new_len < 0) /* improper or cyclic list */ 2623 if (new_len < 0) // improper or cyclic list
2572 scheme_wrong_type(prim->name, "proper list", 2624 scheme_wrong_type(prim->name, "proper list",
2573 2, argc, argv); 2625 2, argc, argv);
2574 else 2626 else
2575 { 2627 {
2576 char **array = NULL; 2628 char **array = NULL;
2711 2763
2712 if (!SCHEME_STRINGP(list) && !SCHEME_PAIRP(list)) 2764 if (!SCHEME_STRINGP(list) && !SCHEME_PAIRP(list))
2713 scheme_wrong_type(prim->name, "string or list", 1, argc, argv); 2765 scheme_wrong_type(prim->name, "string or list", 1, argc, argv);
2714 buf = get_buffer_arg(prim->name, 2, argc, argv); 2766 buf = get_buffer_arg(prim->name, 2, argc, argv);
2715 2767
2716 if (n != 0) /* 0 can be used in insert */ 2768 if (n != 0) // 0 can be used in insert
2717 check_line_range(n, buf->buf); 2769 check_line_range(n, buf->buf);
2718 if (SCHEME_STRINGP(list)) 2770 if (SCHEME_STRINGP(list))
2719 { 2771 {
2720 buf_T *savebuf = curbuf; 2772 buf_T *savebuf = curbuf;
2721 2773
2746 MZ_GC_UNREG(); 2798 MZ_GC_UNREG();
2747 raise_if_error(); 2799 raise_if_error();
2748 return scheme_void; 2800 return scheme_void;
2749 } 2801 }
2750 2802
2751 /* List */ 2803 // List
2752 size = scheme_proper_list_length(list); 2804 size = scheme_proper_list_length(list);
2753 MZ_GC_CHECK(); 2805 MZ_GC_CHECK();
2754 if (size < 0) /* improper or cyclic list */ 2806 if (size < 0) // improper or cyclic list
2755 scheme_wrong_type(prim->name, "proper list", 2807 scheme_wrong_type(prim->name, "proper list",
2756 2, argc, argv); 2808 2, argc, argv);
2757 else 2809 else
2758 { 2810 {
2759 Scheme_Object *line = NULL; 2811 Scheme_Object *line = NULL;
2811 } 2863 }
2812 2864
2813 /* 2865 /*
2814 * Predicates 2866 * Predicates
2815 */ 2867 */
2816 /* (buff? obj) */ 2868 /*
2869 * (buff? obj)
2870 */
2817 static Scheme_Object * 2871 static Scheme_Object *
2818 vim_bufferp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) 2872 vim_bufferp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv)
2819 { 2873 {
2820 if (SCHEME_VIMBUFFERP(argv[0])) 2874 if (SCHEME_VIMBUFFERP(argv[0]))
2821 return scheme_true; 2875 return scheme_true;
2822 else 2876 else
2823 return scheme_false; 2877 return scheme_false;
2824 } 2878 }
2825 2879
2826 /* (win? obj) */ 2880 /*
2881 * (win? obj)
2882 */
2827 static Scheme_Object * 2883 static Scheme_Object *
2828 vim_windowp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) 2884 vim_windowp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv)
2829 { 2885 {
2830 if (SCHEME_VIMWINDOWP(argv[0])) 2886 if (SCHEME_VIMWINDOWP(argv[0]))
2831 return scheme_true; 2887 return scheme_true;
2832 else 2888 else
2833 return scheme_false; 2889 return scheme_false;
2834 } 2890 }
2835 2891
2836 /* (buff-valid? obj) */ 2892 /*
2893 * (buff-valid? obj)
2894 */
2837 static Scheme_Object * 2895 static Scheme_Object *
2838 vim_buffer_validp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) 2896 vim_buffer_validp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv)
2839 { 2897 {
2840 if (SCHEME_VIMBUFFERP(argv[0]) 2898 if (SCHEME_VIMBUFFERP(argv[0])
2841 && ((vim_mz_buffer *)argv[0])->buf != INVALID_BUFFER_VALUE) 2899 && ((vim_mz_buffer *)argv[0])->buf != INVALID_BUFFER_VALUE)
2842 return scheme_true; 2900 return scheme_true;
2843 else 2901 else
2844 return scheme_false; 2902 return scheme_false;
2845 } 2903 }
2846 2904
2847 /* (win-valid? obj) */ 2905 /*
2906 * (win-valid? obj)
2907 */
2848 static Scheme_Object * 2908 static Scheme_Object *
2849 vim_window_validp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) 2909 vim_window_validp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv)
2850 { 2910 {
2851 if (SCHEME_VIMWINDOWP(argv[0]) 2911 if (SCHEME_VIMWINDOWP(argv[0])
2852 && ((vim_mz_window *)argv[0])->win != INVALID_WINDOW_VALUE) 2912 && ((vim_mz_window *)argv[0])->win != INVALID_WINDOW_VALUE)
2877 OUTPUT_LEN_TYPE len; 2937 OUTPUT_LEN_TYPE len;
2878 int i; 2938 int i;
2879 2939
2880 scheme_str = scheme_display_to_string(obj, &len); 2940 scheme_str = scheme_display_to_string(obj, &len);
2881 2941
2882 /* Error checking: String must not contain newlines, as we 2942 // Error checking: String must not contain newlines, as we
2883 * are replacing a single line, and we must replace it with 2943 // are replacing a single line, and we must replace it with
2884 * a single line. 2944 // a single line.
2885 */
2886 if (memchr(scheme_str, '\n', len)) 2945 if (memchr(scheme_str, '\n', len))
2887 scheme_signal_error(_("string cannot contain newlines")); 2946 scheme_signal_error(_("string cannot contain newlines"));
2888 2947
2889 vim_str = alloc(len + 1); 2948 vim_str = alloc(len + 1);
2890 2949
2891 /* Create a copy of the string, with internal nulls replaced by 2950 // Create a copy of the string, with internal nulls replaced by
2892 * newline characters, as is the vim convention. 2951 // newline characters, as is the vim convention.
2893 */
2894 for (i = 0; i < len; ++i) 2952 for (i = 0; i < len; ++i)
2895 { 2953 {
2896 if (scheme_str[i] == '\0') 2954 if (scheme_str[i] == '\0')
2897 vim_str[i] = '\n'; 2955 vim_str[i] = '\n';
2898 else 2956 else
2911 */ 2969 */
2912 static Scheme_Object * 2970 static Scheme_Object *
2913 vim_to_mzscheme(typval_T *vim_value) 2971 vim_to_mzscheme(typval_T *vim_value)
2914 { 2972 {
2915 Scheme_Object *result = NULL; 2973 Scheme_Object *result = NULL;
2916 /* hash table to store visited values to avoid infinite loops */ 2974 // hash table to store visited values to avoid infinite loops
2917 Scheme_Hash_Table *visited = NULL; 2975 Scheme_Hash_Table *visited = NULL;
2918 2976
2919 MZ_GC_DECL_REG(2); 2977 MZ_GC_DECL_REG(2);
2920 MZ_GC_VAR_IN_REG(0, result); 2978 MZ_GC_VAR_IN_REG(0, result);
2921 MZ_GC_VAR_IN_REG(1, visited); 2979 MZ_GC_VAR_IN_REG(1, visited);
2939 MZ_GC_DECL_REG(2); 2997 MZ_GC_DECL_REG(2);
2940 MZ_GC_VAR_IN_REG(0, result); 2998 MZ_GC_VAR_IN_REG(0, result);
2941 MZ_GC_VAR_IN_REG(1, visited); 2999 MZ_GC_VAR_IN_REG(1, visited);
2942 MZ_GC_REG(); 3000 MZ_GC_REG();
2943 3001
2944 /* Avoid infinite recursion */ 3002 // Avoid infinite recursion
2945 if (depth > 100) 3003 if (depth > 100)
2946 { 3004 {
2947 MZ_GC_UNREG(); 3005 MZ_GC_UNREG();
2948 return scheme_void; 3006 return scheme_void;
2949 } 3007 }
2950 3008
2951 /* Check if we run into a recursive loop. The item must be in visited 3009 // Check if we run into a recursive loop. The item must be in visited
2952 * then and we can use it again. 3010 // then and we can use it again.
2953 */
2954 result = scheme_hash_get(visited, (Scheme_Object *)vim_value); 3011 result = scheme_hash_get(visited, (Scheme_Object *)vim_value);
2955 MZ_GC_CHECK(); 3012 MZ_GC_CHECK();
2956 if (result != NULL) /* found, do nothing */ 3013 if (result != NULL) // found, do nothing
2957 new_value = FALSE; 3014 new_value = FALSE;
2958 else if (vim_value->v_type == VAR_STRING) 3015 else if (vim_value->v_type == VAR_STRING)
2959 { 3016 {
2960 result = scheme_make_byte_string((char *)vim_value->vval.v_string); 3017 result = scheme_make_byte_string((char *)vim_value->vval.v_string);
2961 MZ_GC_CHECK(); 3018 MZ_GC_CHECK();
3044 3101
3045 MZ_GC_DECL_REG(1); 3102 MZ_GC_DECL_REG(1);
3046 MZ_GC_VAR_IN_REG(0, funcname); 3103 MZ_GC_VAR_IN_REG(0, funcname);
3047 MZ_GC_REG(); 3104 MZ_GC_REG();
3048 3105
3049 /* FIXME: func_ref() and func_unref() are needed. */ 3106 // FIXME: func_ref() and func_unref() are needed.
3050 funcname = scheme_make_byte_string((char *)vim_value->vval.v_string); 3107 funcname = scheme_make_byte_string((char *)vim_value->vval.v_string);
3051 MZ_GC_CHECK(); 3108 MZ_GC_CHECK();
3052 result = scheme_make_closed_prim_w_arity(vim_funcref, funcname, 3109 result = scheme_make_closed_prim_w_arity(vim_funcref, funcname,
3053 (const char *)BYTE_STRING_VALUE(funcname), 0, -1); 3110 (const char *)BYTE_STRING_VALUE(funcname), 0, -1);
3054 MZ_GC_CHECK(); 3111 MZ_GC_CHECK();
3065 3122
3066 MZ_GC_DECL_REG(1); 3123 MZ_GC_DECL_REG(1);
3067 MZ_GC_VAR_IN_REG(0, funcname); 3124 MZ_GC_VAR_IN_REG(0, funcname);
3068 MZ_GC_REG(); 3125 MZ_GC_REG();
3069 3126
3070 /* FIXME: func_ref() and func_unref() are needed. */ 3127 // FIXME: func_ref() and func_unref() are needed.
3071 /* TODO: Support pt_dict and pt_argv. */ 3128 // TODO: Support pt_dict and pt_argv.
3072 funcname = scheme_make_byte_string( 3129 funcname = scheme_make_byte_string(
3073 (char *)partial_name(vim_value->vval.v_partial)); 3130 (char *)partial_name(vim_value->vval.v_partial));
3074 MZ_GC_CHECK(); 3131 MZ_GC_CHECK();
3075 result = scheme_make_closed_prim_w_arity(vim_funcref, funcname, 3132 result = scheme_make_closed_prim_w_arity(vim_funcref, funcname,
3076 (const char *)BYTE_STRING_VALUE(funcname), 0, -1); 3133 (const char *)BYTE_STRING_VALUE(funcname), 0, -1);
3116 MZ_GC_CHECK(); 3173 MZ_GC_CHECK();
3117 3174
3118 status = mzscheme_to_vim_impl(obj, tv, 1, visited); 3175 status = mzscheme_to_vim_impl(obj, tv, 1, visited);
3119 for (i = 0; i < visited->size; ++i) 3176 for (i = 0; i < visited->size; ++i)
3120 { 3177 {
3121 /* free up remembered objects */ 3178 // free up remembered objects
3122 if (visited->vals[i] != NULL) 3179 if (visited->vals[i] != NULL)
3123 free_tv((typval_T *)visited->vals[i]); 3180 free_tv((typval_T *)visited->vals[i]);
3124 } 3181 }
3125 3182
3126 MZ_GC_UNREG(); 3183 MZ_GC_UNREG();
3137 MZ_GC_VAR_IN_REG(0, obj); 3194 MZ_GC_VAR_IN_REG(0, obj);
3138 MZ_GC_VAR_IN_REG(1, visited); 3195 MZ_GC_VAR_IN_REG(1, visited);
3139 MZ_GC_REG(); 3196 MZ_GC_REG();
3140 3197
3141 MZ_GC_CHECK(); 3198 MZ_GC_CHECK();
3142 if (depth > 100) /* limit the deepest recursion level */ 3199 if (depth > 100) // limit the deepest recursion level
3143 { 3200 {
3144 tv->v_type = VAR_NUMBER; 3201 tv->v_type = VAR_NUMBER;
3145 tv->vval.v_number = 0; 3202 tv->vval.v_number = 0;
3146 return FAIL; 3203 return FAIL;
3147 } 3204 }
3199 else 3256 else
3200 { 3257 {
3201 int i; 3258 int i;
3202 Scheme_Object *curr = NULL; 3259 Scheme_Object *curr = NULL;
3203 Scheme_Object *cval = NULL; 3260 Scheme_Object *cval = NULL;
3204 /* temporary var to hold current element of vectors and pairs */ 3261 // temporary var to hold current element of vectors and pairs
3205 typval_T *v; 3262 typval_T *v;
3206 3263
3207 MZ_GC_DECL_REG(2); 3264 MZ_GC_DECL_REG(2);
3208 MZ_GC_VAR_IN_REG(0, curr); 3265 MZ_GC_VAR_IN_REG(0, curr);
3209 MZ_GC_VAR_IN_REG(1, cval); 3266 MZ_GC_VAR_IN_REG(1, cval);
3216 v = ALLOC_ONE(typval_T); 3273 v = ALLOC_ONE(typval_T);
3217 if (v == NULL) 3274 if (v == NULL)
3218 status = FAIL; 3275 status = FAIL;
3219 else 3276 else
3220 { 3277 {
3221 /* add the value in advance to allow handling of self-referential 3278 // add the value in advance to allow handling of self-referential
3222 * data structures */ 3279 // data structures
3223 typval_T *visited_tv = ALLOC_ONE(typval_T); 3280 typval_T *visited_tv = ALLOC_ONE(typval_T);
3224 copy_tv(tv, visited_tv); 3281 copy_tv(tv, visited_tv);
3225 scheme_hash_set(visited, obj, (Scheme_Object *)visited_tv); 3282 scheme_hash_set(visited, obj, (Scheme_Object *)visited_tv);
3226 3283
3227 if (SCHEME_VECTORP(obj)) 3284 if (SCHEME_VECTORP(obj))
3251 status = list_append_tv(list, v); 3308 status = list_append_tv(list, v);
3252 clear_tv(v); 3309 clear_tv(v);
3253 if (status == FAIL) 3310 if (status == FAIL)
3254 break; 3311 break;
3255 } 3312 }
3256 /* improper list not terminated with null 3313 // improper list not terminated with null
3257 * need to handle the last element */ 3314 // need to handle the last element
3258 if (status == OK && !SCHEME_NULLP(curr)) 3315 if (status == OK && !SCHEME_NULLP(curr))
3259 { 3316 {
3260 status = mzscheme_to_vim_impl(cval, v, depth + 1, visited); 3317 status = mzscheme_to_vim_impl(cval, v, depth + 1, visited);
3261 if (status == OK) 3318 if (status == OK)
3262 { 3319 {
3263 status = list_append_tv(list, v); 3320 status = list_append_tv(list, v);
3264 clear_tv(v); 3321 clear_tv(v);
3265 } 3322 }
3266 } 3323 }
3267 } 3324 }
3268 /* nothing to do for scheme_null */ 3325 // nothing to do for scheme_null
3269 vim_free(v); 3326 vim_free(v);
3270 } 3327 }
3271 MZ_GC_UNREG(); 3328 MZ_GC_UNREG();
3272 } 3329 }
3273 } 3330 }
3299 3356
3300 for (i = 0; i < ((Scheme_Hash_Table *)obj)->size; ++i) 3357 for (i = 0; i < ((Scheme_Hash_Table *)obj)->size; ++i)
3301 { 3358 {
3302 if (((Scheme_Hash_Table *) obj)->vals[i] != NULL) 3359 if (((Scheme_Hash_Table *) obj)->vals[i] != NULL)
3303 { 3360 {
3304 /* generate item for `display'ed Scheme key */ 3361 // generate item for `display'ed Scheme key
3305 dictitem_T *item = dictitem_alloc((char_u *)string_to_line( 3362 dictitem_T *item = dictitem_alloc((char_u *)string_to_line(
3306 ((Scheme_Hash_Table *) obj)->keys[i])); 3363 ((Scheme_Hash_Table *) obj)->keys[i]));
3307 /* convert Scheme val to Vim and add it to the dict */ 3364 // convert Scheme val to Vim and add it to the dict
3308 if (mzscheme_to_vim_impl(((Scheme_Hash_Table *) obj)->vals[i], 3365 if (mzscheme_to_vim_impl(((Scheme_Hash_Table *) obj)->vals[i],
3309 &item->di_tv, depth + 1, visited) == FAIL 3366 &item->di_tv, depth + 1, visited) == FAIL
3310 || dict_add(dict, item) == FAIL) 3367 || dict_add(dict, item) == FAIL)
3311 { 3368 {
3312 dictitem_free(item); 3369 dictitem_free(item);
3319 } 3376 }
3320 MZ_GC_UNREG(); 3377 MZ_GC_UNREG();
3321 } 3378 }
3322 else 3379 else
3323 { 3380 {
3324 /* `display' any other value to string */ 3381 // `display' any other value to string
3325 tv->v_type = VAR_STRING; 3382 tv->v_type = VAR_STRING;
3326 tv->vval.v_string = (char_u *)string_to_line(obj); 3383 tv->vval.v_string = (char_u *)string_to_line(obj);
3327 } 3384 }
3328 MZ_GC_UNREG(); 3385 MZ_GC_UNREG();
3329 return status; 3386 return status;
3330 } 3387 }
3331 3388
3332 /* Scheme prim procedure wrapping Vim funcref */ 3389 /*
3390 * Scheme prim procedure wrapping Vim funcref
3391 */
3333 static Scheme_Object * 3392 static Scheme_Object *
3334 vim_funcref(void *name, int argc, Scheme_Object **argv) 3393 vim_funcref(void *name, int argc, Scheme_Object **argv)
3335 { 3394 {
3336 int i; 3395 int i;
3337 typval_T args; 3396 typval_T args;
3544 { 3603 {
3545 if (vim_error_check()) 3604 if (vim_error_check())
3546 raise_vim_exn(NULL); 3605 raise_vim_exn(NULL);
3547 } 3606 }
3548 3607
3549 /* get buffer: 3608 /*
3609 * get buffer:
3550 * either current 3610 * either current
3551 * or passed as argv[argnum] with checks 3611 * or passed as argv[argnum] with checks
3552 */ 3612 */
3553 static vim_mz_buffer * 3613 static vim_mz_buffer *
3554 get_buffer_arg(const char *fname, int argnum, int argc, Scheme_Object **argv) 3614 get_buffer_arg(const char *fname, int argnum, int argc, Scheme_Object **argv)
3562 b = (vim_mz_buffer *)argv[argnum]; 3622 b = (vim_mz_buffer *)argv[argnum];
3563 (void)get_valid_buffer(argv[argnum]); 3623 (void)get_valid_buffer(argv[argnum]);
3564 return b; 3624 return b;
3565 } 3625 }
3566 3626
3567 /* get window: 3627 /*
3628 * get window:
3568 * either current 3629 * either current
3569 * or passed as argv[argnum] with checks 3630 * or passed as argv[argnum] with checks
3570 */ 3631 */
3571 static vim_mz_window * 3632 static vim_mz_window *
3572 get_window_arg(const char *fname, int argnum, int argc, Scheme_Object **argv) 3633 get_window_arg(const char *fname, int argnum, int argc, Scheme_Object **argv)
3580 scheme_wrong_type(fname, "vim-window", argnum, argc, argv); 3641 scheme_wrong_type(fname, "vim-window", argnum, argc, argv);
3581 (void)get_valid_window(argv[argnum]); 3642 (void)get_valid_window(argv[argnum]);
3582 return w; 3643 return w;
3583 } 3644 }
3584 3645
3585 /* get valid Vim buffer from Scheme_Object* */ 3646 /*
3647 * get valid Vim buffer from Scheme_Object*
3648 */
3586 buf_T *get_valid_buffer(void *obj) 3649 buf_T *get_valid_buffer(void *obj)
3587 { 3650 {
3588 buf_T *buf = ((vim_mz_buffer *)obj)->buf; 3651 buf_T *buf = ((vim_mz_buffer *)obj)->buf;
3589 3652
3590 if (buf == INVALID_BUFFER_VALUE) 3653 if (buf == INVALID_BUFFER_VALUE)
3591 scheme_signal_error(_("buffer is invalid")); 3654 scheme_signal_error(_("buffer is invalid"));
3592 return buf; 3655 return buf;
3593 } 3656 }
3594 3657
3595 /* get valid Vim window from Scheme_Object* */ 3658 /*
3659 * get valid Vim window from Scheme_Object*
3660 */
3596 win_T *get_valid_window(void *obj) 3661 win_T *get_valid_window(void *obj)
3597 { 3662 {
3598 win_T *win = ((vim_mz_window *)obj)->win; 3663 win_T *win = ((vim_mz_window *)obj)->win;
3599 if (win == INVALID_WINDOW_VALUE) 3664 if (win == INVALID_WINDOW_VALUE)
3600 scheme_signal_error(_("window is invalid")); 3665 scheme_signal_error(_("window is invalid"));
3629 static void 3694 static void
3630 mz_fix_cursor(int lo, int hi, int extra) 3695 mz_fix_cursor(int lo, int hi, int extra)
3631 { 3696 {
3632 if (curwin->w_cursor.lnum >= lo) 3697 if (curwin->w_cursor.lnum >= lo)
3633 { 3698 {
3634 /* Adjust the cursor position if it's in/after the changed 3699 // Adjust the cursor position if it's in/after the changed
3635 * lines. */ 3700 // lines.
3636 if (curwin->w_cursor.lnum >= hi) 3701 if (curwin->w_cursor.lnum >= hi)
3637 { 3702 {
3638 curwin->w_cursor.lnum += extra; 3703 curwin->w_cursor.lnum += extra;
3639 check_cursor_col(); 3704 check_cursor_col();
3640 } 3705 }
3702 {vim_windowp, "win?", 1, 1}, 3767 {vim_windowp, "win?", 1, 1},
3703 {vim_buffer_validp, "buff-valid?", 1, 1}, 3768 {vim_buffer_validp, "buff-valid?", 1, 1},
3704 {vim_window_validp, "win-valid?", 1, 1} 3769 {vim_window_validp, "win-valid?", 1, 1}
3705 }; 3770 };
3706 3771
3707 /* return MzScheme wrapper for curbuf */ 3772 /*
3773 * return MzScheme wrapper for curbuf
3774 */
3708 static vim_mz_buffer * 3775 static vim_mz_buffer *
3709 get_vim_curr_buffer(void) 3776 get_vim_curr_buffer(void)
3710 { 3777 {
3711 if (curbuf->b_mzscheme_ref == NULL) 3778 if (curbuf->b_mzscheme_ref == NULL)
3712 return (vim_mz_buffer *)buffer_new(curbuf); 3779 return (vim_mz_buffer *)buffer_new(curbuf);
3713 else 3780 else
3714 return BUFFER_REF(curbuf); 3781 return BUFFER_REF(curbuf);
3715 } 3782 }
3716 3783
3717 /* return MzScheme wrapper for curwin */ 3784 /*
3785 * return MzScheme wrapper for curwin
3786 */
3718 static vim_mz_window * 3787 static vim_mz_window *
3719 get_vim_curr_window(void) 3788 get_vim_curr_window(void)
3720 { 3789 {
3721 if (curwin->w_mzscheme_ref == NULL) 3790 if (curwin->w_mzscheme_ref == NULL)
3722 return (vim_mz_window *)window_new(curwin); 3791 return (vim_mz_window *)window_new(curwin);
3740 3809
3741 vimext_symbol = scheme_intern_symbol("vimext"); 3810 vimext_symbol = scheme_intern_symbol("vimext");
3742 MZ_GC_CHECK(); 3811 MZ_GC_CHECK();
3743 mod = scheme_primitive_module(vimext_symbol, environment); 3812 mod = scheme_primitive_module(vimext_symbol, environment);
3744 MZ_GC_CHECK(); 3813 MZ_GC_CHECK();
3745 /* all prims made closed so they can access their own names */ 3814 // all prims made closed so they can access their own names
3746 for (i = 0; i < (int)(sizeof(prims)/sizeof(prims[0])); i++) 3815 for (i = 0; i < (int)(sizeof(prims)/sizeof(prims[0])); i++)
3747 { 3816 {
3748 Vim_Prim *prim = prims + i; 3817 Vim_Prim *prim = prims + i;
3749 closed_prim = scheme_make_closed_prim_w_arity(prim->prim, prim, prim->name, 3818 closed_prim = scheme_make_closed_prim_w_arity(prim->prim, prim, prim->name,
3750 prim->mina, prim->maxa); 3819 prim->mina, prim->maxa);
3767 { 3836 {
3768 if (sandbox) 3837 if (sandbox)
3769 raise_vim_exn(_("not allowed in the Vim sandbox")); 3838 raise_vim_exn(_("not allowed in the Vim sandbox"));
3770 } 3839 }
3771 3840
3772 /* security guards to force Vim's sandbox restrictions on MzScheme level */ 3841 /*
3842 * security guards to force Vim's sandbox restrictions on MzScheme level
3843 */
3773 static Scheme_Object * 3844 static Scheme_Object *
3774 sandbox_file_guard(int argc UNUSED, Scheme_Object **argv) 3845 sandbox_file_guard(int argc UNUSED, Scheme_Object **argv)
3775 { 3846 {
3776 if (sandbox) 3847 if (sandbox)
3777 { 3848 {