(SCM_GC8MARKP, SCM_SETGC8MARK, SCM_CLRGC8MARK):
[bpt/guile.git] / libguile / print.c
index 64bd23e..f0b8ec1 100644 (file)
@@ -1,43 +1,19 @@
-/* Copyright (C) 1995-1999,2000,2001 Free Software Foundation, Inc.
+/* Copyright (C) 1995-1999,2000,2001, 2002, 2003 Free Software Foundation, Inc.
  * 
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this software; see the file COPYING.  If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307 USA
- *
- * As a special exception, the Free Software Foundation gives permission
- * for additional uses of the text contained in its release of GUILE.
- *
- * The exception is that, if you link the GUILE library with other files
- * to produce an executable, this does not by itself cause the
- * resulting executable to be covered by the GNU General Public License.
- * Your use of that executable is in no way restricted on account of
- * linking the GUILE library code into it.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This exception does not however invalidate any other reasons why
- * the executable file might be covered by the GNU General Public License.
- *
- * This exception applies only to the code released by the
- * Free Software Foundation under the name GUILE.  If you copy
- * code from other Free Software Foundation releases into a copy of
- * GUILE, as the General Public License permits, the exception does
- * not apply to the code that you add in this way.  To avoid misleading
- * anyone as to the status of such modified files, you must delete
- * this exception notice from them.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * If you write modifications of your own for GUILE, it is your choice
- * whether to permit this exception to apply to your modifications.
- * If you do not wish that, delete this exception notice.  */
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
 
 
 \f
@@ -62,6 +38,7 @@
 #include "libguile/strings.h"
 #include "libguile/strports.h"
 #include "libguile/vectors.h"
+#include "libguile/lang.h"
 
 #include "libguile/validate.h"
 #include "libguile/print.h"
@@ -74,7 +51,7 @@
 
 char *scm_isymnames[] =
 {
-  /* This table must agree with the declarations */
+  /* This table must agree with the list of SCM_IM_ constants in tags.h */
   "#@and",
   "#@begin",
   "#@case",
@@ -113,17 +90,18 @@ char *scm_isymnames[] =
   /* Multi-language support */
   
   "#@nil-cond",
-  "#@nil-ify",
-  "#@t-ify",
-  "#@0-cond",
-  "#@0-ify",
-  "#@1-ify",
   "#@bind",
   
   "#@delay",
+  "#@future",
   "#@call-with-values",
 
-  "#<unbound>"
+  "#<unbound>",
+
+  /* Elisp nil value.  This is its Scheme name; whenever it's printed
+     in Elisp, it should appear as the symbol `nil'. */
+
+  "#nil"
 };
 
 scm_t_option scm_print_opts[] = {
@@ -215,7 +193,7 @@ make_print_state (void)
     = scm_make_struct (scm_print_state_vtable, SCM_INUM0, SCM_EOL);
   scm_print_state *pstate = SCM_PRINT_STATE (print_state);
   pstate->ref_vect = scm_c_make_vector (PSTATE_SIZE, SCM_UNDEFINED);
-  pstate->ref_stack = SCM_VELTS (pstate->ref_vect);
+  pstate->ref_stack = SCM_WRITABLE_VELTS (pstate->ref_vect);
   pstate->ceiling = SCM_VECTOR_LENGTH (pstate->ref_vect);
   return print_state;
 }
@@ -259,23 +237,22 @@ static void
 grow_ref_stack (scm_print_state *pstate)
 {
   unsigned long int old_size = SCM_VECTOR_LENGTH (pstate->ref_vect);
-  SCM *old_elts = SCM_VELTS (pstate->ref_vect);
+  SCM const *old_elts = SCM_VELTS (pstate->ref_vect);
   unsigned long int new_size = 2 * pstate->ceiling;
   SCM new_vect = scm_c_make_vector (new_size, SCM_UNDEFINED);
-  SCM *new_elts = SCM_VELTS (new_vect);
   unsigned long int i;
 
   for (i = 0; i != old_size; ++i)
-    new_elts [i] = old_elts [i];
+    SCM_VECTOR_SET (new_vect, i, old_elts [i]);
 
   pstate->ref_vect = new_vect;
-  pstate->ref_stack = new_elts;
+  pstate->ref_stack = SCM_WRITABLE_VELTS(new_vect);
   pstate->ceiling = new_size;
 }
 
 
 static void
-print_circref (SCM port,scm_print_state *pstate,SCM ref)
+print_circref (SCM port, scm_print_state *pstate, SCM ref)
 {
   register long i;
   long self = pstate->top - 1;
@@ -526,10 +503,23 @@ scm_iprin1 (SCM exp, SCM port, scm_print_state *pstate)
            scm_lfwrite (SCM_STRING_CHARS (exp), SCM_STRING_LENGTH (exp), port);
          break;
        case scm_tc7_symbol:
-         scm_print_symbol_name (SCM_SYMBOL_CHARS (exp),
-                                SCM_SYMBOL_LENGTH (exp),
-                                port);
-         scm_remember_upto_here_1 (exp);
+         if (SCM_SYMBOL_INTERNED_P (exp))
+           {
+             scm_print_symbol_name (SCM_SYMBOL_CHARS (exp),
+                                    SCM_SYMBOL_LENGTH (exp),
+                                    port);
+             scm_remember_upto_here_1 (exp);
+           }
+         else
+           {
+             scm_puts ("#<uninterned-symbol ", port);
+             scm_print_symbol_name (SCM_SYMBOL_CHARS (exp),
+                                    SCM_SYMBOL_LENGTH (exp),
+                                    port);
+             scm_putc (' ', port);
+             scm_intprint ((long)exp, 16, port);
+             scm_putc ('>', port);
+           }
          break;
        case scm_tc7_variable:
          scm_i_variable_print (exp, port, pstate);
@@ -572,7 +562,7 @@ scm_iprin1 (SCM exp, SCM port, scm_print_state *pstate)
          }
          EXIT_NESTED_DATA (pstate);
          break;
-#ifdef HAVE_ARRAYS
+#if SCM_HAVE_ARRAYS
        case scm_tc7_bvect:
        case scm_tc7_byvect:
        case scm_tc7_svect:
@@ -581,14 +571,14 @@ scm_iprin1 (SCM exp, SCM port, scm_print_state *pstate)
        case scm_tc7_fvect:
        case scm_tc7_dvect:
        case scm_tc7_cvect:
-#ifdef HAVE_LONG_LONGS
+#if SCM_SIZEOF_LONG_LONG != 0
        case scm_tc7_llvect:
 #endif
          scm_raprin1 (exp, port, pstate);
          break;
 #endif
        case scm_tcs_subrs:
-         scm_puts (SCM_SUBR_GENERIC (exp) && *SCM_SUBR_GENERIC (exp)
+         scm_puts (SCM_SUBR_GENERIC (exp)
                    ? "#<primitive-generic "
                    : "#<primitive-procedure ",
                    port);
@@ -667,6 +657,7 @@ scm_prin1 (SCM exp, SCM port, int writingp)
   SCM handle = SCM_BOOL_F; /* Will GC protect the handle whilst unlinked */
   SCM pstate_scm;
   scm_print_state *pstate;
+  int old_writingp;
 
   /* If PORT is a print-state/port pair, use that.  Else create a new
      print-state. */
@@ -692,8 +683,10 @@ scm_prin1 (SCM exp, SCM port, int writingp)
     }
 
   pstate = SCM_PRINT_STATE (pstate_scm);
+  old_writingp = pstate->writingp;
   pstate->writingp = writingp;
   scm_iprin1 (exp, port, pstate);
+  pstate->writingp = old_writingp;
 
   /* Return print state to pool if it has been created above and
      hasn't escaped to Scheme. */
@@ -726,7 +719,7 @@ scm_ipruk (char *hdr, SCM ptr, SCM port)
 {
   scm_puts ("#<unknown-", port);
   scm_puts (hdr, port);
-  if (scm_cellp (ptr))
+  if (scm_in_heap_p (ptr))
     {
       scm_puts (" (0x", port);
       scm_intprint (SCM_CELL_WORD_0 (ptr), 16, port);
@@ -743,7 +736,7 @@ scm_ipruk (char *hdr, SCM ptr, SCM port)
 /* Print a list.
  */
 void 
-scm_iprlist (char *hdr,SCM exp,int tlr,SCM port,scm_print_state *pstate)
+scm_iprlist (char *hdr, SCM exp, int tlr, SCM port, scm_print_state *pstate)
 {
   register SCM hare, tortoise;
   long floor = pstate->top - 2;
@@ -781,7 +774,7 @@ scm_iprlist (char *hdr,SCM exp,int tlr,SCM port,scm_print_state *pstate)
       /* CHECK_INTS; */
       scm_iprin1 (SCM_CAR (exp), port, pstate);
     }
-  if (!SCM_NULLP (exp))
+  if (!SCM_NULL_OR_NIL_P (exp))
     {
       scm_puts (" . ", port);
       scm_iprin1 (exp, port, pstate);
@@ -822,7 +815,7 @@ fancy_printing:
        scm_iprin1 (SCM_CAR (exp), port, pstate);
       }
   }
-  if (!SCM_NULLP (exp))
+  if (!SCM_NULL_OR_NIL_P (exp))
     {
       scm_puts (" . ", port);
       scm_iprin1 (exp, port, pstate);
@@ -955,6 +948,7 @@ SCM_DEFINE (scm_simple_format, "simple-format", 2, 0, 1,
            start = p + 1;
            continue;
          case '%':
+           scm_lfwrite (start, p - start - 1, destination);
            scm_newline (destination);
            start = p + 1;
            continue;
@@ -997,7 +991,7 @@ SCM_DEFINE (scm_newline, "newline", 0, 1, 0,
   if (SCM_UNBNDP (port))
     port = scm_cur_outp;
 
-  SCM_VALIDATE_OPORT_VALUE (1,port);
+  SCM_VALIDATE_OPORT_VALUE (1, port);
 
   scm_putc ('\n', SCM_COERCE_OUTPORT (port));
   return SCM_UNSPECIFIED;
@@ -1012,8 +1006,8 @@ SCM_DEFINE (scm_write_char, "write-char", 1, 1, 0,
   if (SCM_UNBNDP (port))
     port = scm_cur_outp;
 
-  SCM_VALIDATE_CHAR (1,chr);
-  SCM_VALIDATE_OPORT_VALUE (2,port);
+  SCM_VALIDATE_CHAR (1, chr);
+  SCM_VALIDATE_OPORT_VALUE (2, port);
 
   scm_putc ((int) SCM_CHAR (chr), SCM_COERCE_OUTPORT (port));
 #ifdef HAVE_PIPE
@@ -1064,8 +1058,8 @@ SCM_DEFINE (scm_port_with_print_state, "port-with-print-state", 2, 0, 0,
 #define FUNC_NAME s_scm_port_with_print_state
 {
   SCM pwps;
-  SCM_VALIDATE_OPORT_VALUE (1,port);
-  SCM_VALIDATE_PRINTSTATE (2,pstate);
+  SCM_VALIDATE_OPORT_VALUE (1, port);
+  SCM_VALIDATE_PRINTSTATE (2, pstate);
   port = SCM_COERCE_OUTPORT (port);
   SCM_NEWSMOB (pwps, scm_tc16_port_with_ps, SCM_UNPACK (scm_cons (port, pstate)));
   return pwps;
@@ -1108,9 +1102,7 @@ scm_init_print ()
   scm_set_smob_mark (scm_tc16_port_with_ps, scm_markcdr);
   scm_set_smob_print (scm_tc16_port_with_ps, port_with_ps_print);
   
-#ifndef SCM_MAGIC_SNARFER
 #include "libguile/print.x"
-#endif
 }
 
 /*