252c095
To: vim-dev@vim.org
252c095
Subject: Patch 7.2.336
252c095
Fcc: outbox
252c095
From: Bram Moolenaar <Bram@moolenaar.net>
252c095
Mime-Version: 1.0
252c095
Content-Type: text/plain; charset=UTF-8
252c095
Content-Transfer-Encoding: 8bit
252c095
------------
252c095
252c095
Patch 7.2.336
252c095
Problem:    MzScheme interface can't evaluate an expression.
252c095
Solution:   Add mzeval(). (Sergey Khorev)
252c095
Files:	    runtime/doc/eval.txt, runtime/doc/if_mzsch.txt,
252c095
	    runtime/doc/usr_41.txt, src/eval.c, src/if_mzsch.c,
252c095
	    src/proto/eval.pro, src/proto/if_mzsch.pro,
252c095
	    src/testdir/Make_dos.mak, src/testdir/Make_ming.mak,
252c095
	    src/testdir/Makefile, src/testdir/main.aap, src/testdir/test1.in,
252c095
	    src/testdir/test70.in, src/testdir/test70.ok
252c095
252c095
252c095
*** ../vim-7.2.335/runtime/doc/eval.txt	2009-11-17 12:20:30.000000000 +0100
252c095
--- runtime/doc/eval.txt	2010-01-19 15:30:50.000000000 +0100
252c095
***************
252c095
*** 1815,1825 ****
252c095
  				List	match and submatches of {pat} in {expr}
252c095
  matchstr( {expr}, {pat}[, {start}[, {count}]])
252c095
  				String	{count}'th match of {pat} in {expr}
252c095
! max({list})			Number	maximum value of items in {list}
252c095
! min({list})			Number	minimum value of items in {list}
252c095
! mkdir({name} [, {path} [, {prot}]])
252c095
  				Number	create directory {name}
252c095
  mode( [expr])			String	current editing mode
252c095
  nextnonblank( {lnum})		Number	line nr of non-blank line >= {lnum}
252c095
  nr2char( {expr})		String	single char with ASCII value {expr}
252c095
  pathshorten( {expr})		String	shorten directory names in a path
252c095
--- 1821,1832 ----
252c095
  				List	match and submatches of {pat} in {expr}
252c095
  matchstr( {expr}, {pat}[, {start}[, {count}]])
252c095
  				String	{count}'th match of {pat} in {expr}
252c095
! max( {list})			Number	maximum value of items in {list}
252c095
! min( {list})			Number	minimum value of items in {list}
252c095
! mkdir( {name} [, {path} [, {prot}]])
252c095
  				Number	create directory {name}
252c095
  mode( [expr])			String	current editing mode
252c095
+ mzeval( {expr})			any	evaluate |MzScheme| expression
252c095
  nextnonblank( {lnum})		Number	line nr of non-blank line >= {lnum}
252c095
  nr2char( {expr})		String	single char with ASCII value {expr}
252c095
  pathshorten( {expr})		String	shorten directory names in a path
252c095
***************
252c095
*** 4090,4095 ****
252c095
--- 4103,4125 ----
252c095
  		"c" or "n".
252c095
  		Also see |visualmode()|.
252c095
  
252c095
+ mzeval({expr})							*mzeval()*
252c095
+ 		Evaluate MzScheme expression {expr} and return its result
252c095
+ 		convert to Vim data structures.
252c095
+ 		Numbers and strings are returned as they are.
252c095
+ 		Pairs (including lists and improper lists) and vectors are
252c095
+ 		returned as Vim |Lists|.
252c095
+ 		Hash tables are represented as Vim |Dictionary| type with keys
252c095
+ 		converted to strings.
252c095
+ 		All other types are converted to string with display function.
252c095
+ 		Examples: >
252c095
+ 		    :mz (define l (list 1 2 3))
252c095
+ 		    :mz (define h (make-hash)) (hash-set! h "list" l)
252c095
+ 		    :echo mzeval("l")
252c095
+ 		    :echo mzeval("h")
252c095
+ <
252c095
+ 		{only available when compiled with the |+mzscheme| feature}
252c095
+ 
252c095
  nextnonblank({lnum})					*nextnonblank()*
252c095
  		Return the line number of the first line at or below {lnum}
252c095
  		that is not blank.  Example: >
252c095
*** ../vim-7.2.335/runtime/doc/if_mzsch.txt	2009-06-24 17:51:01.000000000 +0200
252c095
--- runtime/doc/if_mzsch.txt	2010-01-19 15:33:00.000000000 +0100
252c095
***************
252c095
*** 1,4 ****
252c095
! *if_mzsch.txt*  For Vim version 7.2.  Last change: 2009 Jun 24
252c095
  
252c095
  
252c095
  		  VIM REFERENCE MANUAL    by Sergey Khorev
252c095
--- 1,4 ----
252c095
! *if_mzsch.txt*  For Vim version 7.2.  Last change: 2010 Jan 19
252c095
  
252c095
  
252c095
  		  VIM REFERENCE MANUAL    by Sergey Khorev
252c095
***************
252c095
*** 9,16 ****
252c095
  1. Commands				|mzscheme-commands|
252c095
  2. Examples				|mzscheme-examples|
252c095
  3. Threads				|mzscheme-threads|
252c095
! 4. The Vim access procedures		|mzscheme-vim|
252c095
! 5. Dynamic loading			|mzscheme-dynamic|
252c095
  
252c095
  {Vi does not have any of these commands}
252c095
  
252c095
--- 9,17 ----
252c095
  1. Commands				|mzscheme-commands|
252c095
  2. Examples				|mzscheme-examples|
252c095
  3. Threads				|mzscheme-threads|
252c095
! 4. Vim access from MzScheme		|mzscheme-vim|
252c095
! 5. mzeval() Vim function		|mzscheme-mzeval|
252c095
! 6. Dynamic loading			|mzscheme-dynamic|
252c095
  
252c095
  {Vi does not have any of these commands}
252c095
  
252c095
***************
252c095
*** 142,148 ****
252c095
  GUI version.
252c095
  
252c095
  ==============================================================================
252c095
! 5. VIM Functions					*mzscheme-vim*
252c095
  
252c095
  							*mzscheme-vimext*
252c095
  The 'vimext' module provides access to procedures defined in the MzScheme
252c095
--- 143,149 ----
252c095
  GUI version.
252c095
  
252c095
  ==============================================================================
252c095
! 4. Vim access from MzScheme				*mzscheme-vim*
252c095
  
252c095
  							*mzscheme-vimext*
252c095
  The 'vimext' module provides access to procedures defined in the MzScheme
252c095
***************
252c095
*** 231,237 ****
252c095
      (set-cursor (line . col) [window])  Set cursor position.
252c095
  
252c095
  ==============================================================================
252c095
! 5. Dynamic loading				    *mzscheme-dynamic* *E815*
252c095
  
252c095
  On MS-Windows the MzScheme libraries can be loaded dynamically. The |:version|
252c095
  output then includes |+mzscheme/dyn|.
252c095
--- 232,244 ----
252c095
      (set-cursor (line . col) [window])  Set cursor position.
252c095
  
252c095
  ==============================================================================
252c095
! 5. mzeval() Vim function				    *mzscheme-mzeval*
252c095
! 
252c095
! To facilitate bi-directional interface, you can use |mzeval| function to
252c095
! evaluate MzScheme expressions and pass their values to VimL.
252c095
! 
252c095
! ==============================================================================
252c095
! 6. Dynamic loading				    *mzscheme-dynamic* *E815*
252c095
  
252c095
  On MS-Windows the MzScheme libraries can be loaded dynamically. The |:version|
252c095
  output then includes |+mzscheme/dyn|.
252c095
*** ../vim-7.2.335/runtime/doc/usr_41.txt	2008-08-09 19:36:54.000000000 +0200
252c095
--- runtime/doc/usr_41.txt	2010-01-19 15:29:01.000000000 +0100
252c095
***************
252c095
*** 868,873 ****
252c095
--- 868,875 ----
252c095
  	taglist()		get list of matching tags
252c095
  	tagfiles()		get a list of tags files
252c095
  
252c095
+ 	mzeval()		evaluate |MzScheme| expression
252c095
+ 
252c095
  ==============================================================================
252c095
  *41.7*	Defining a function
252c095
  
252c095
*** ../vim-7.2.335/src/eval.c	2010-01-19 12:46:51.000000000 +0100
252c095
--- src/eval.c	2010-01-19 15:48:12.000000000 +0100
252c095
***************
252c095
*** 433,439 ****
252c095
  static long list_find_nr __ARGS((list_T *l, long idx, int *errorp));
252c095
  static long list_idx_of_item __ARGS((list_T *l, listitem_T *item));
252c095
  static void list_append __ARGS((list_T *l, listitem_T *item));
252c095
- static int list_append_tv __ARGS((list_T *l, typval_T *tv));
252c095
  static int list_append_number __ARGS((list_T *l, varnumber_T n));
252c095
  static int list_insert_tv __ARGS((list_T *l, typval_T *tv, listitem_T *item));
252c095
  static int list_extend __ARGS((list_T	*l1, list_T *l2, listitem_T *bef));
252c095
--- 433,438 ----
252c095
***************
252c095
*** 448,459 ****
252c095
  static void set_ref_in_item __ARGS((typval_T *tv, int copyID));
252c095
  static void dict_unref __ARGS((dict_T *d));
252c095
  static void dict_free __ARGS((dict_T *d, int recurse));
252c095
- static dictitem_T *dictitem_alloc __ARGS((char_u *key));
252c095
  static dictitem_T *dictitem_copy __ARGS((dictitem_T *org));
252c095
  static void dictitem_remove __ARGS((dict_T *dict, dictitem_T *item));
252c095
- static void dictitem_free __ARGS((dictitem_T *item));
252c095
  static dict_T *dict_copy __ARGS((dict_T *orig, int deep, int copyID));
252c095
- static int dict_add __ARGS((dict_T *d, dictitem_T *item));
252c095
  static long dict_len __ARGS((dict_T *d));
252c095
  static dictitem_T *dict_find __ARGS((dict_T *d, char_u *key, int len));
252c095
  static char_u *dict2string __ARGS((typval_T *tv, int copyID));
252c095
--- 447,455 ----
252c095
***************
252c095
*** 628,633 ****
252c095
--- 624,632 ----
252c095
  static void f_mkdir __ARGS((typval_T *argvars, typval_T *rettv));
252c095
  #endif
252c095
  static void f_mode __ARGS((typval_T *argvars, typval_T *rettv));
252c095
+ #ifdef FEAT_MZSCHEME
252c095
+ static void f_mzeval __ARGS((typval_T *argvars, typval_T *rettv));
252c095
+ #endif
252c095
  static void f_nextnonblank __ARGS((typval_T *argvars, typval_T *rettv));
252c095
  static void f_nr2char __ARGS((typval_T *argvars, typval_T *rettv));
252c095
  static void f_pathshorten __ARGS((typval_T *argvars, typval_T *rettv));
252c095
***************
252c095
*** 764,770 ****
252c095
  static int var_check_ro __ARGS((int flags, char_u *name));
252c095
  static int var_check_fixed __ARGS((int flags, char_u *name));
252c095
  static int tv_check_lock __ARGS((int lock, char_u *name));
252c095
- static void copy_tv __ARGS((typval_T *from, typval_T *to));
252c095
  static int item_copy __ARGS((typval_T *from, typval_T *to, int deep, int copyID));
252c095
  static char_u *find_option_end __ARGS((char_u **arg, int *opt_flags));
252c095
  static char_u *trans_function_name __ARGS((char_u **pp, int skip, int flags, funcdict_T *fd));
252c095
--- 763,768 ----
252c095
***************
252c095
*** 6155,6161 ****
252c095
   * Append typval_T "tv" to the end of list "l".
252c095
   * Return FAIL when out of memory.
252c095
   */
252c095
!     static int
252c095
  list_append_tv(l, tv)
252c095
      list_T	*l;
252c095
      typval_T	*tv;
252c095
--- 6153,6159 ----
252c095
   * Append typval_T "tv" to the end of list "l".
252c095
   * Return FAIL when out of memory.
252c095
   */
252c095
!     int
252c095
  list_append_tv(l, tv)
252c095
      list_T	*l;
252c095
      typval_T	*tv;
252c095
***************
252c095
*** 6812,6818 ****
252c095
   * Note that the value of the item "di_tv" still needs to be initialized!
252c095
   * Returns NULL when out of memory.
252c095
   */
252c095
!     static dictitem_T *
252c095
  dictitem_alloc(key)
252c095
      char_u	*key;
252c095
  {
252c095
--- 6810,6816 ----
252c095
   * Note that the value of the item "di_tv" still needs to be initialized!
252c095
   * Returns NULL when out of memory.
252c095
   */
252c095
!     dictitem_T *
252c095
  dictitem_alloc(key)
252c095
      char_u	*key;
252c095
  {
252c095
***************
252c095
*** 6868,6874 ****
252c095
  /*
252c095
   * Free a dict item.  Also clears the value.
252c095
   */
252c095
!     static void
252c095
  dictitem_free(item)
252c095
      dictitem_T *item;
252c095
  {
252c095
--- 6866,6872 ----
252c095
  /*
252c095
   * Free a dict item.  Also clears the value.
252c095
   */
252c095
!     void
252c095
  dictitem_free(item)
252c095
      dictitem_T *item;
252c095
  {
252c095
***************
252c095
*** 6948,6954 ****
252c095
   * Add item "item" to Dictionary "d".
252c095
   * Returns FAIL when out of memory and when key already existed.
252c095
   */
252c095
!     static int
252c095
  dict_add(d, item)
252c095
      dict_T	*d;
252c095
      dictitem_T	*item;
252c095
--- 6946,6952 ----
252c095
   * Add item "item" to Dictionary "d".
252c095
   * Returns FAIL when out of memory and when key already existed.
252c095
   */
252c095
!     int
252c095
  dict_add(d, item)
252c095
      dict_T	*d;
252c095
      dictitem_T	*item;
252c095
***************
252c095
*** 7699,7704 ****
252c095
--- 7697,7705 ----
252c095
      {"mkdir",		1, 3, f_mkdir},
252c095
  #endif
252c095
      {"mode",		0, 1, f_mode},
252c095
+ #ifdef FEAT_MZSCHEME
252c095
+     {"mzeval",		1, 1, f_mzeval},
252c095
+ #endif
252c095
      {"nextnonblank",	1, 1, f_nextnonblank},
252c095
      {"nr2char",		1, 1, f_nr2char},
252c095
      {"pathshorten",	1, 1, f_pathshorten},
252c095
***************
252c095
*** 13591,13596 ****
252c095
--- 13592,13614 ----
252c095
      rettv->v_type = VAR_STRING;
252c095
  }
252c095
  
252c095
+ #ifdef FEAT_MZSCHEME
252c095
+ /*
252c095
+  * "mzeval()" function
252c095
+  */
252c095
+     static void
252c095
+ f_mzeval(argvars, rettv)
252c095
+     typval_T	*argvars;
252c095
+     typval_T	*rettv;
252c095
+ {
252c095
+     char_u	*str;
252c095
+     char_u	buf[NUMBUFLEN];
252c095
+ 
252c095
+     str = get_tv_string_buf(&argvars[0], buf);
252c095
+     do_mzeval(str, rettv);
252c095
+ }
252c095
+ #endif
252c095
+ 
252c095
  /*
252c095
   * "nextnonblank()" function
252c095
   */
252c095
***************
252c095
*** 19274,19280 ****
252c095
   * It is OK for "from" and "to" to point to the same item.  This is used to
252c095
   * make a copy later.
252c095
   */
252c095
!     static void
252c095
  copy_tv(from, to)
252c095
      typval_T *from;
252c095
      typval_T *to;
252c095
--- 19292,19298 ----
252c095
   * It is OK for "from" and "to" to point to the same item.  This is used to
252c095
   * make a copy later.
252c095
   */
252c095
!     void
252c095
  copy_tv(from, to)
252c095
      typval_T *from;
252c095
      typval_T *to;
252c095
*** ../vim-7.2.335/src/if_mzsch.c	2009-12-16 19:02:05.000000000 +0100
252c095
--- src/if_mzsch.c	2010-01-19 15:43:05.000000000 +0100
252c095
***************
252c095
*** 170,175 ****
252c095
--- 170,177 ----
252c095
  #ifdef FEAT_EVAL
252c095
  static Scheme_Object *vim_to_mzscheme(typval_T *vim_value, int depth,
252c095
  	Scheme_Hash_Table *visited);
252c095
+ static int mzscheme_to_vim(Scheme_Object *obj, typval_T *tv, int depth,
252c095
+ 	Scheme_Hash_Table *visited);
252c095
  #endif
252c095
  
252c095
  #ifdef MZ_PRECISE_GC
252c095
***************
252c095
*** 2733,2738 ****
252c095
--- 2735,2959 ----
252c095
      MZ_GC_UNREG();
252c095
      return result;
252c095
  }
252c095
+ 
252c095
+     static int
252c095
+ mzscheme_to_vim(Scheme_Object *obj, typval_T *tv, int depth,
252c095
+ 	Scheme_Hash_Table *visited)
252c095
+ {
252c095
+     int		status = OK;
252c095
+     typval_T	*found;
252c095
+     MZ_GC_CHECK();
252c095
+     if (depth > 100) /* limit the deepest recursion level */
252c095
+     {
252c095
+ 	tv->v_type = VAR_NUMBER;
252c095
+ 	tv->vval.v_number = 0;
252c095
+ 	return FAIL;
252c095
+     }
252c095
+ 
252c095
+     found = (typval_T *)scheme_hash_get(visited, obj);
252c095
+     if (found != NULL)
252c095
+ 	copy_tv(found, tv);
252c095
+     else if (SCHEME_VOIDP(obj))
252c095
+     {
252c095
+ 	tv->v_type = VAR_NUMBER;
252c095
+ 	tv->vval.v_number = 0;
252c095
+     }
252c095
+     else if (SCHEME_INTP(obj))
252c095
+     {
252c095
+ 	tv->v_type = VAR_NUMBER;
252c095
+ 	tv->vval.v_number = SCHEME_INT_VAL(obj);
252c095
+     }
252c095
+     else if (SCHEME_BOOLP(obj))
252c095
+     {
252c095
+ 	tv->v_type = VAR_NUMBER;
252c095
+ 	tv->vval.v_number = SCHEME_TRUEP(obj);
252c095
+     }
252c095
+ # ifdef FEAT_FLOAT
252c095
+     else if (SCHEME_DBLP(obj))
252c095
+     {
252c095
+ 	tv->v_type = VAR_FLOAT;
252c095
+ 	tv->vval.v_float = SCHEME_DBL_VAL(obj);
252c095
+     }
252c095
+ # endif
252c095
+     else if (SCHEME_STRINGP(obj))
252c095
+     {
252c095
+ 	tv->v_type = VAR_STRING;
252c095
+ 	tv->vval.v_string = vim_strsave((char_u *)SCHEME_STR_VAL(obj));
252c095
+     }
252c095
+     else if (SCHEME_VECTORP(obj) || SCHEME_NULLP(obj)
252c095
+ 	    || SCHEME_PAIRP(obj) || SCHEME_MUTABLE_PAIRP(obj))
252c095
+     {
252c095
+ 	list_T  *list = list_alloc();
252c095
+ 	if (list == NULL)
252c095
+ 	    status = FAIL;
252c095
+ 	else
252c095
+ 	{
252c095
+ 	    int		    i;
252c095
+ 	    Scheme_Object   *curr = NULL;
252c095
+ 	    Scheme_Object   *cval = NULL;
252c095
+ 	    /* temporary var to hold current element of vectors and pairs */
252c095
+ 	    typval_T	    *v;
252c095
+ 
252c095
+ 	    MZ_GC_DECL_REG(2);
252c095
+ 	    MZ_GC_VAR_IN_REG(0, curr);
252c095
+ 	    MZ_GC_VAR_IN_REG(1, cval);
252c095
+ 	    MZ_GC_REG();
252c095
+ 
252c095
+ 	    tv->v_type = VAR_LIST;
252c095
+ 	    tv->vval.v_list = list;
252c095
+ 	    ++list->lv_refcount;
252c095
+ 
252c095
+ 	    v = (typval_T *)alloc(sizeof(typval_T));
252c095
+ 	    if (v == NULL)
252c095
+ 		status = FAIL;
252c095
+ 	    else
252c095
+ 	    {
252c095
+ 		/* add the value in advance to allow handling of self-referencial
252c095
+ 		 * data structures */
252c095
+ 		typval_T    *visited_tv = (typval_T *)alloc(sizeof(typval_T));
252c095
+ 		copy_tv(tv, visited_tv);
252c095
+ 		scheme_hash_set(visited, obj, (Scheme_Object *)visited_tv);
252c095
+ 
252c095
+ 		if (SCHEME_VECTORP(obj))
252c095
+ 		{
252c095
+ 		    for (i = 0; i < SCHEME_VEC_SIZE(obj); ++i)
252c095
+ 		    {
252c095
+ 			cval = SCHEME_VEC_ELS(obj)[i];
252c095
+ 			status = mzscheme_to_vim(cval, v, depth + 1, visited);
252c095
+ 			if (status == FAIL)
252c095
+ 			    break;
252c095
+ 			status = list_append_tv(list, v);
252c095
+ 			clear_tv(v);
252c095
+ 			if (status == FAIL)
252c095
+ 			    break;
252c095
+ 		    }
252c095
+ 		}
252c095
+ 		else if (SCHEME_PAIRP(obj) || SCHEME_MUTABLE_PAIRP(obj))
252c095
+ 		{
252c095
+ 		    for (curr = obj;
252c095
+ 			    SCHEME_PAIRP(curr) || SCHEME_MUTABLE_PAIRP(curr);
252c095
+ 			    curr = SCHEME_CDR(curr))
252c095
+ 		    {
252c095
+ 			cval = SCHEME_CAR(curr);
252c095
+ 			status = mzscheme_to_vim(cval, v, depth + 1, visited);
252c095
+ 			if (status == FAIL)
252c095
+ 			    break;
252c095
+ 			status = list_append_tv(list, v);
252c095
+ 			clear_tv(v);
252c095
+ 			if (status == FAIL)
252c095
+ 			    break;
252c095
+ 		    }
252c095
+ 		    /* impoper list not terminated with null
252c095
+ 		     * need to handle the last element */
252c095
+ 		    if (status == OK && !SCHEME_NULLP(curr))
252c095
+ 		    {
252c095
+ 			status = mzscheme_to_vim(cval, v, depth + 1, visited);
252c095
+ 			if (status == OK)
252c095
+ 			{
252c095
+ 			    status = list_append_tv(list, v);
252c095
+ 			    clear_tv(v);
252c095
+ 			}
252c095
+ 		    }
252c095
+ 		}
252c095
+ 		/* nothing to do for scheme_null */
252c095
+ 		vim_free(v);
252c095
+ 	    }
252c095
+ 	    MZ_GC_UNREG();
252c095
+ 	}
252c095
+     }
252c095
+     else if (SCHEME_HASHTP(obj))
252c095
+     {
252c095
+ 	int		i;
252c095
+ 	dict_T		*dict;
252c095
+ 	Scheme_Object   *key = NULL;
252c095
+ 	Scheme_Object   *val = NULL;
252c095
+ 
252c095
+ 	MZ_GC_DECL_REG(2);
252c095
+ 	MZ_GC_VAR_IN_REG(0, key);
252c095
+ 	MZ_GC_VAR_IN_REG(1, val);
252c095
+ 	MZ_GC_REG();
252c095
+ 
252c095
+ 	dict = dict_alloc();
252c095
+ 	if (dict == NULL)
252c095
+ 	    status = FAIL;
252c095
+ 	else
252c095
+ 	{
252c095
+ 	    typval_T    *visited_tv = (typval_T *)alloc(sizeof(typval_T));
252c095
+ 
252c095
+ 	    tv->v_type = VAR_DICT;
252c095
+ 	    tv->vval.v_dict = dict;
252c095
+ 	    ++dict->dv_refcount;
252c095
+ 
252c095
+ 	    copy_tv(tv, visited_tv);
252c095
+ 	    scheme_hash_set(visited, obj, (Scheme_Object *)visited_tv);
252c095
+ 
252c095
+ 	    for (i = 0; i < ((Scheme_Hash_Table *)obj)->size; ++i)
252c095
+ 	    {
252c095
+ 		if (((Scheme_Hash_Table *) obj)->vals[i] != NULL)
252c095
+ 		{
252c095
+ 		    /* generate item for `diplay'ed Scheme key */
252c095
+ 		    dictitem_T  *item = dictitem_alloc((char_u *)string_to_line(
252c095
+ 				((Scheme_Hash_Table *) obj)->keys[i]));
252c095
+ 		    /* convert Scheme val to Vim and add it to the dict */
252c095
+ 		    if (mzscheme_to_vim(((Scheme_Hash_Table *) obj)->vals[i],
252c095
+ 				    &item->di_tv, depth + 1, visited) == FAIL
252c095
+ 			    || dict_add(dict, item) == FAIL)
252c095
+ 		    {
252c095
+ 			dictitem_free(item);
252c095
+ 			status = FAIL;
252c095
+ 			break;
252c095
+ 		    }
252c095
+ 		}
252c095
+ 
252c095
+ 	    }
252c095
+ 	}
252c095
+ 	MZ_GC_UNREG();
252c095
+     }
252c095
+     else
252c095
+     {
252c095
+ 	/* `display' any other value to string */
252c095
+ 	tv->v_type = VAR_STRING;
252c095
+ 	tv->vval.v_string = (char_u *)string_to_line(obj);
252c095
+     }
252c095
+     return status;
252c095
+ }
252c095
+ 
252c095
+     void
252c095
+ do_mzeval(char_u *str, typval_T *rettv)
252c095
+ {
252c095
+     int i;
252c095
+     Scheme_Object	*ret = NULL;
252c095
+     Scheme_Hash_Table	*visited = NULL;
252c095
+ 
252c095
+     MZ_GC_DECL_REG(2);
252c095
+     MZ_GC_VAR_IN_REG(0, ret);
252c095
+     MZ_GC_VAR_IN_REG(0, visited);
252c095
+     MZ_GC_REG();
252c095
+ 
252c095
+     if (mzscheme_init())
252c095
+     {
252c095
+ 	MZ_GC_UNREG();
252c095
+ 	return;
252c095
+     }
252c095
+ 
252c095
+     MZ_GC_CHECK();
252c095
+     visited = scheme_make_hash_table(SCHEME_hash_ptr);
252c095
+     MZ_GC_CHECK();
252c095
+ 
252c095
+     if (eval_with_exn_handling(str, do_eval, &ret) == OK)
252c095
+ 	mzscheme_to_vim(ret, rettv, 1, visited);
252c095
+ 
252c095
+     for (i = 0; i < visited->size; ++i)
252c095
+     {
252c095
+ 	/* free up remembered objects */
252c095
+ 	if (visited->vals[i] != NULL)
252c095
+ 	{
252c095
+ 	    free_tv((typval_T *)visited->vals[i]);
252c095
+ 	}
252c095
+     }
252c095
+ 
252c095
+     MZ_GC_UNREG();
252c095
+ }
252c095
  #endif
252c095
  
252c095
  /*
252c095
*** ../vim-7.2.335/src/proto/eval.pro	2009-09-30 15:15:33.000000000 +0200
252c095
--- src/proto/eval.pro	2010-01-19 15:45:39.000000000 +0100
252c095
***************
252c095
*** 47,56 ****
252c095
--- 47,60 ----
252c095
  void list_free __ARGS((list_T *l, int recurse));
252c095
  dictitem_T *dict_lookup __ARGS((hashitem_T *hi));
252c095
  char_u *list_find_str __ARGS((list_T *l, long idx));
252c095
+ int list_append_tv __ARGS((list_T *l, typval_T *tv));
252c095
  int list_append_dict __ARGS((list_T *list, dict_T *dict));
252c095
  int list_append_string __ARGS((list_T *l, char_u *str, int len));
252c095
  int garbage_collect __ARGS((void));
252c095
  dict_T *dict_alloc __ARGS((void));
252c095
+ dictitem_T *dictitem_alloc __ARGS((char_u *key));
252c095
+ void dictitem_free __ARGS((dictitem_T *item));
252c095
+ int dict_add __ARGS((dict_T *d, dictitem_T *item));
252c095
  int dict_add_nr_str __ARGS((dict_T *d, char *key, long nr, char_u *str));
252c095
  char_u *get_dict_string __ARGS((dict_T *d, char_u *key, int save));
252c095
  long get_dict_number __ARGS((dict_T *d, char_u *key));
252c095
***************
252c095
*** 77,82 ****
252c095
--- 81,87 ----
252c095
  void new_script_vars __ARGS((scid_T id));
252c095
  void init_var_dict __ARGS((dict_T *dict, dictitem_T *dict_var));
252c095
  void vars_clear __ARGS((hashtab_T *ht));
252c095
+ void copy_tv __ARGS((typval_T *from, typval_T *to));
252c095
  void ex_echo __ARGS((exarg_T *eap));
252c095
  void ex_echohl __ARGS((exarg_T *eap));
252c095
  void ex_execute __ARGS((exarg_T *eap));
252c095
*** ../vim-7.2.335/src/proto/if_mzsch.pro	2009-12-16 19:02:05.000000000 +0100
252c095
--- src/proto/if_mzsch.pro	2010-01-19 15:29:01.000000000 +0100
252c095
***************
252c095
*** 15,18 ****
252c095
--- 15,19 ----
252c095
  void *mzvim_eval_string __ARGS((char_u *str));
252c095
  int mzthreads_allowed __ARGS((void));
252c095
  void mzscheme_main __ARGS((void));
252c095
+ void do_mzeval __ARGS((char_u *str, typval_T *rettv));
252c095
  /* vim: set ft=c : */
252c095
*** ../vim-7.2.335/src/testdir/Make_dos.mak	2009-11-17 17:57:10.000000000 +0100
252c095
--- src/testdir/Make_dos.mak	2010-01-19 15:43:48.000000000 +0100
252c095
***************
252c095
*** 29,35 ****
252c095
  		test42.out test52.out test65.out test66.out test67.out \
252c095
  		test68.out test69.out
252c095
  
252c095
! SCRIPTS32 =	test50.out
252c095
  
252c095
  SCRIPTS_GUI = test16.out
252c095
  
252c095
--- 29,35 ----
252c095
  		test42.out test52.out test65.out test66.out test67.out \
252c095
  		test68.out test69.out
252c095
  
252c095
! SCRIPTS32 =	test50.out test70.out
252c095
  
252c095
  SCRIPTS_GUI = test16.out
252c095
  
252c095
*** ../vim-7.2.335/src/testdir/Make_ming.mak	2009-11-17 17:57:10.000000000 +0100
252c095
--- src/testdir/Make_ming.mak	2010-01-19 15:29:01.000000000 +0100
252c095
***************
252c095
*** 48,54 ****
252c095
  		test42.out test52.out test65.out test66.out test67.out \
252c095
  		test68.out test69.out
252c095
  
252c095
! SCRIPTS32 =	test50.out
252c095
  
252c095
  SCRIPTS_GUI = test16.out
252c095
  
252c095
--- 48,54 ----
252c095
  		test42.out test52.out test65.out test66.out test67.out \
252c095
  		test68.out test69.out
252c095
  
252c095
! SCRIPTS32 =	test50.out test70.out
252c095
  
252c095
  SCRIPTS_GUI = test16.out
252c095
  
252c095
***************
252c095
*** 78,83 ****
252c095
--- 78,84 ----
252c095
  	-$(DEL) small.vim
252c095
  	-$(DEL) tiny.vim
252c095
  	-$(DEL) mbyte.vim
252c095
+ 	-$(DEL) mzscheme.vim
252c095
  	-$(DEL) X*
252c095
  	-$(DEL) viminfo
252c095
  
252c095
*** ../vim-7.2.335/src/testdir/Makefile	2009-11-17 17:40:34.000000000 +0100
252c095
--- src/testdir/Makefile	2010-01-19 15:29:01.000000000 +0100
252c095
***************
252c095
*** 23,29 ****
252c095
  		test54.out test55.out test56.out test57.out test58.out \
252c095
  		test59.out test60.out test61.out test62.out test63.out \
252c095
  		test64.out test65.out test66.out test67.out test68.out \
252c095
! 		test69.out
252c095
  
252c095
  SCRIPTS_GUI = test16.out
252c095
  
252c095
--- 23,29 ----
252c095
  		test54.out test55.out test56.out test57.out test58.out \
252c095
  		test59.out test60.out test61.out test62.out test63.out \
252c095
  		test64.out test65.out test66.out test67.out test68.out \
252c095
! 		test69.out test70.out
252c095
  
252c095
  SCRIPTS_GUI = test16.out
252c095
  
252c095
***************
252c095
*** 44,53 ****
252c095
  $(SCRIPTS) $(SCRIPTS_GUI): $(VIMPROG)
252c095
  
252c095
  clean:
252c095
! 	-rm -rf *.out *.failed *.rej *.orig test.log tiny.vim small.vim mbyte.vim test.ok X* valgrind.pid* viminfo
252c095
  
252c095
  test1.out: test1.in
252c095
! 	-rm -f $*.failed tiny.vim small.vim mbyte.vim test.ok X* viminfo
252c095
  	$(VALGRIND) $(VIMPROG) -u unix.vim -U NONE --noplugin -s dotest.in $*.in
252c095
  	@/bin/sh -c "if diff test.out $*.ok; \
252c095
  		then mv -f test.out $*.out; \
252c095
--- 44,53 ----
252c095
  $(SCRIPTS) $(SCRIPTS_GUI): $(VIMPROG)
252c095
  
252c095
  clean:
252c095
! 	-rm -rf *.out *.failed *.rej *.orig test.log tiny.vim small.vim mbyte.vim mzscheme.vim test.ok X* valgrind.pid* viminfo
252c095
  
252c095
  test1.out: test1.in
252c095
! 	-rm -f $*.failed tiny.vim small.vim mbyte.vim mzscheme.vim test.ok X* viminfo
252c095
  	$(VALGRIND) $(VIMPROG) -u unix.vim -U NONE --noplugin -s dotest.in $*.in
252c095
  	@/bin/sh -c "if diff test.out $*.ok; \
252c095
  		then mv -f test.out $*.out; \
252c095
*** ../vim-7.2.335/src/testdir/main.aap	2004-06-13 21:05:31.000000000 +0200
252c095
--- src/testdir/main.aap	2010-01-19 15:29:01.000000000 +0100
252c095
***************
252c095
*** 32,42 ****
252c095
  $Scripts $ScriptsGUI: $VimProg
252c095
  
252c095
  clean:
252c095
! 	:del {r}{force} *.out test.log tiny.vim small.vim mbyte.vim test.ok X*
252c095
  
252c095
  # test1 is special, it checks for features
252c095
  test1.out: test1.in
252c095
! 	:del {force} test1.failed tiny.vim small.vim mbyte.vim
252c095
  	:sys {i} $VimProg -u unix.vim -U NONE --noplugin -s dotest.in test1.in
252c095
  	@if os.system("diff test.out test1.ok") != 0:
252c095
  		:error test1 FAILED - Something basic is wrong
252c095
--- 32,42 ----
252c095
  $Scripts $ScriptsGUI: $VimProg
252c095
  
252c095
  clean:
252c095
! 	:del {r}{force} *.out test.log tiny.vim small.vim mbyte.vim mzscheme.vim test.ok X*
252c095
  
252c095
  # test1 is special, it checks for features
252c095
  test1.out: test1.in
252c095
! 	:del {force} test1.failed tiny.vim small.vim mbyte.vim mzscheme.vim
252c095
  	:sys {i} $VimProg -u unix.vim -U NONE --noplugin -s dotest.in test1.in
252c095
  	@if os.system("diff test.out test1.ok") != 0:
252c095
  		:error test1 FAILED - Something basic is wrong
252c095
*** ../vim-7.2.335/src/testdir/test1.in	2004-06-13 20:19:23.000000000 +0200
252c095
--- src/testdir/test1.in	2010-01-19 15:38:44.000000000 +0100
252c095
***************
252c095
*** 13,18 ****
252c095
--- 13,19 ----
252c095
  
252c095
  If Vim was not compiled with the +multi_byte feature, the mbyte.vim script will be set like small.vim above.  mbyte.vim is sourced by tests that require the
252c095
  +multi_byte feature.
252c095
+ Similar logic is applied to the +mzscheme feature, using mzscheme.vim.
252c095
  
252c095
  STARTTEST
252c095
  :" Write a single line to test.out to check if testing works at all.
252c095
***************
252c095
*** 25,32 ****
252c095
--- 26,36 ----
252c095
  w! test.out
252c095
  qa!
252c095
  ?:w! mbyte.vim
252c095
+ :w! mzscheme.vim
252c095
  :" If +multi_byte feature supported, make mbyte.vim empty.
252c095
  :if has("multi_byte") | sp another | w! mbyte.vim | q | endif
252c095
+ :" If +mzscheme feature supported, make mzscheme.vim empty.
252c095
+ :if has("mzscheme") | sp another | w! mzscheme.vim | q | endif
252c095
  :" If +eval feature supported quit here, leaving tiny.vim and small.vim empty.
252c095
  :" Otherwise write small.vim to skip the test.
252c095
  :if 1 | q! | endif
252c095
*** ../vim-7.2.335/src/testdir/test70.in	2010-01-19 15:47:24.000000000 +0100
252c095
--- src/testdir/test70.in	2010-01-19 15:29:01.000000000 +0100
252c095
***************
252c095
*** 0 ****
252c095
--- 1,53 ----
252c095
+ Smoke test for MzScheme interface and mzeval() function
252c095
+ 
252c095
+ STARTTEST
252c095
+ :so mzscheme.vim
252c095
+ :set nocompatible viminfo+=nviminfo
252c095
+ :function! MzRequire()
252c095
+ :redir => l:mzversion
252c095
+ :mz (version)
252c095
+ :redir END
252c095
+ :if strpart(l:mzversion, 1, 1) < "4"
252c095
+ :" MzScheme versions < 4.x:
252c095
+ :mz (require (prefix vim- vimext))
252c095
+ :else
252c095
+ :" newer versions:
252c095
+ :mz (require (prefix-in vim- 'vimext))
252c095
+ :mz (require r5rs)
252c095
+ :endif
252c095
+ :endfunction
252c095
+ :silent call MzRequire()
252c095
+ :mz (define l '("item0" "dictionary with list OK" "item2"))
252c095
+ :mz (define h (make-hash))
252c095
+ :mz (hash-set! h "list" l)
252c095
+ /^1
252c095
+ :" change buffer contents
252c095
+ :mz (vim-set-buff-line (vim-eval "line('.')") "1 changed line 1")
252c095
+ :" scalar test
252c095
+ :let tmp_string = mzeval('"string"')
252c095
+ :let tmp_1000 = mzeval('1000')
252c095
+ :if tmp_string . tmp_1000 == "string1000"
252c095
+ :let scalar_res = "OK"
252c095
+ :else
252c095
+ :let scalar_res = "FAILED"
252c095
+ :endif
252c095
+ :call append(search("^1"), "scalar test " . scalar_res)
252c095
+ :" dictionary containing a list
252c095
+ :let tmp = mzeval("h")["list"][1]
252c095
+ :/^2/put =tmp
252c095
+ :" circular list (at the same time test lists containing lists)
252c095
+ :mz (set-car! (cddr l) l)
252c095
+ :let l2 = mzeval("h")["list"]
252c095
+ :if l2[2] == l2
252c095
+ :let res = "OK"
252c095
+ :else
252c095
+ :let res = "FAILED"
252c095
+ :endif
252c095
+ :call setline(search("^3"), "circular test " . res)
252c095
+ :?^1?,$w! test.out
252c095
+ :qa!
252c095
+ ENDTEST
252c095
+ 
252c095
+ 1 line 1
252c095
+ 2 line 2
252c095
+ 3 line 3
252c095
*** ../vim-7.2.335/src/testdir/test70.ok	2010-01-19 15:47:24.000000000 +0100
252c095
--- src/testdir/test70.ok	2010-01-19 15:29:01.000000000 +0100
252c095
***************
252c095
*** 0 ****
252c095
--- 1,5 ----
252c095
+ 1 changed line 1
252c095
+ scalar test OK
252c095
+ 2 line 2
252c095
+ dictionary with list OK
252c095
+ circular test OK
252c095
*** ../vim-7.2.335/src/version.c	2010-01-19 15:23:38.000000000 +0100
252c095
--- src/version.c	2010-01-19 15:46:44.000000000 +0100
252c095
***************
252c095
*** 683,684 ****
252c095
--- 683,686 ----
252c095
  {   /* Add new patch number below this line */
252c095
+ /**/
252c095
+     336,
252c095
  /**/
252c095
252c095
-- 
252c095
"Computers in the future may weigh no more than 1.5 tons."
252c095
                                   Popular Mechanics, 1949
252c095
252c095
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
252c095
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
252c095
\\\        download, build and distribute -- http://www.A-A-P.org        ///
252c095
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///