-/* Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
+/* Copyright (C) 1995-1999 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
#include "unif.h"
#include "alist.h"
#include "struct.h"
+#include "objects.h"
#include "print.h"
\f
"#<undefined>",
"#<eof>",
"()",
- "#<unspecified>"
+ "#<unspecified>",
+ "#@dispatch",
+ "#@slot-ref",
+ "#@slot-set!",
+
+ /* Multi-language support */
+
+ "#@nil-cond",
+ "#@nil-ify",
+ "#@t-ify",
+ "#@0-cond",
+ "#@0-ify",
+ "#@1-ify",
+ "#@bind",
+
+ "#@delay"
};
scm_option scm_print_opts[] = {
return answer ? answer : make_print_state ();
}
-static char s_print_state_printer[] = "print-state-printer";
-static SCM
-print_state_printer (obj, port)
- SCM obj;
- SCM port;
-{
- /* This function can be made visible by means of struct-ref, so
- we need to make sure that it gets what it wants. */
- SCM_ASSERT (SCM_NIMP (obj) && SCM_PRINT_STATE_P (obj),
- obj,
- SCM_ARG1,
- s_print_state_printer);
- SCM_ASSERT (scm_valid_oport_value_p (port),
- port,
- SCM_ARG2,
- s_print_state_printer);
- port = SCM_COERCE_OUTPORT (port);
- scm_puts ("#<print-state ", port);
- scm_intprint (obj, 16, port);
- scm_putc ('>', port);
- return SCM_UNSPECIFIED;
-}
-
void
scm_free_print_state (print_state)
SCM print_state;
/* Print generally. Handles both write and display according to PSTATE.
*/
-
+SCM_GPROC(s_write, "write", 1, 1, 0, scm_write, g_write);
+SCM_GPROC(s_display, "display", 1, 1, 0, scm_display, g_display);
void
scm_iprin1 (exp, port, pstate)
if (SCM_CDR (SCM_CAR (exp) - 1L) == 0)
{
ENTER_NESTED_DATA (pstate, exp, circref);
- scm_print_struct (exp, port, pstate);
+ if (SCM_OBJ_CLASS_FLAGS (exp) & SCM_CLASSF_GOOPS)
+ {
+ SCM pwps, print = pstate->writingp ? g_write : g_display;
+ if (!print)
+ goto print_struct;
+ SCM_NEWSMOB (pwps,
+ scm_tc16_port_with_ps,
+ scm_cons (port, pstate->handle));
+ scm_call_generic_2 (print, exp, pwps);
+ }
+ else
+ {
+ print_struct:
+ scm_print_struct (exp, port, pstate);
+ }
EXIT_NESTED_DATA (pstate);
break;
}
}
EXIT_NESTED_DATA (pstate);
break;
+#ifdef HAVE_ARRAYS
case scm_tc7_bvect:
case scm_tc7_byvect:
case scm_tc7_svect:
case scm_tc7_fvect:
case scm_tc7_dvect:
case scm_tc7_cvect:
-#ifdef LONGLONGS
+#ifdef HAVE_LONG_LONGS
case scm_tc7_llvect:
#endif
scm_raprin1 (exp, port, pstate);
break;
+#endif
case scm_tcs_subrs:
- scm_puts ("#<primitive-procedure ", port);
+ scm_puts (SCM_SUBR_GENERIC (exp) && *SCM_SUBR_GENERIC (exp)
+ ? "#<primitive-generic "
+ : "#<primitive-procedure ",
+ port);
scm_puts (SCM_CHARS (SCM_SNAME (exp)), port);
scm_putc ('>', port);
break;
#ifdef CCLO
case scm_tc7_cclo:
- scm_puts ("#<compiled-closure ", port);
- scm_iprin1 (SCM_CCLO_SUBR (exp), port, pstate);
- scm_putc ('>', port);
+ {
+ SCM proc = SCM_CCLO_SUBR (exp);
+ if (proc == scm_f_gsubr_apply)
+ {
+ /* Print gsubrs as primitives */
+ SCM name = scm_procedure_name (exp);
+ scm_puts ("#<primitive-procedure", port);
+ if (SCM_NFALSEP (name))
+ {
+ scm_putc (' ', port);
+ scm_puts (SCM_CHARS (name), port);
+ }
+ }
+ else
+ {
+ scm_puts ("#<compiled-closure ", port);
+ scm_iprin1 (proc, port, pstate);
+ }
+ scm_putc ('>', port);
+ }
break;
#endif
+ case scm_tc7_pws:
+ scm_puts ("#<procedure-with-setter", port);
+ {
+ SCM name = scm_procedure_name (exp);
+ if (SCM_NFALSEP (name))
+ {
+ scm_putc (' ', port);
+ scm_puts (SCM_ROCHARS (name), port);
+ }
+ }
+ scm_putc ('>', port);
+ break;
case scm_tc7_contin:
scm_puts ("#<continuation ", port);
scm_intprint (SCM_LENGTH (exp), 10, port);
/* If PORT is a print-state/port pair, use that. Else create a new
print-state. */
- if (SCM_NIMP (port) && SCM_CONSP (port))
+ if (SCM_NIMP (port) && SCM_PORT_WITH_PS_P (port))
{
- pstate_scm = SCM_CDR (port);
- port = SCM_CAR (port);
+ pstate_scm = SCM_PORT_WITH_PS_PS (port);
+ port = SCM_PORT_WITH_PS_PORT (port);
}
else
{
{
return (SCM_NIMP (val)
&& (SCM_OPOUTPORTP (val)
- || (SCM_CONSP (val)
- && SCM_NIMP (SCM_CAR (val))
- && SCM_OPOUTPORTP (SCM_CAR (val))
- && SCM_NIMP (SCM_CDR (val))
- && SCM_PRINT_STATE_P (SCM_CDR (val)))));
+ || (SCM_PORT_WITH_PS_P (val)
+ && SCM_OPOUTPORTP (SCM_PORT_WITH_PS_PORT (val)))));
}
-SCM_PROC(s_write, "write", 1, 1, 0, scm_write);
+/* SCM_GPROC(s_write, "write", 1, 1, 0, scm_write, g_write); */
SCM
scm_write (obj, port)
{
if (SCM_UNBNDP (port))
port = scm_cur_outp;
- else
- SCM_ASSERT (scm_valid_oport_value_p (port), port, SCM_ARG2, s_write);
+
+ SCM_ASSERT (scm_valid_oport_value_p (port), port, SCM_ARG2, s_write);
scm_prin1 (obj, port, 1);
#ifdef HAVE_PIPE
}
-SCM_PROC(s_display, "display", 1, 1, 0, scm_display);
+/* SCM_GPROC(s_display, "display", 1, 1, 0, scm_display, g_display); */
SCM
scm_display (obj, port)
{
if (SCM_UNBNDP (port))
port = scm_cur_outp;
- else
- SCM_ASSERT (scm_valid_oport_value_p (port), port, SCM_ARG2, s_display);
+
+ SCM_ASSERT (scm_valid_oport_value_p (port), port, SCM_ARG2, s_display);
scm_prin1 (obj, port, 0);
#ifdef HAVE_PIPE
{
if (SCM_UNBNDP (port))
port = scm_cur_outp;
- else
- SCM_ASSERT (scm_valid_oport_value_p (port), port, SCM_ARG1, s_newline);
+
+ SCM_ASSERT (scm_valid_oport_value_p (port), port, SCM_ARG1, s_newline);
scm_putc ('\n', SCM_COERCE_OUTPORT (port));
-#ifdef HAVE_PIPE
-# ifdef EPIPE
- if (EPIPE == errno)
- scm_close_port (port);
- else
-# endif
-#endif
- if (port == scm_cur_outp)
- scm_fflush (port);
return SCM_UNSPECIFIED;
}
{
if (SCM_UNBNDP (port))
port = scm_cur_outp;
- else
- SCM_ASSERT (scm_valid_oport_value_p (port), port, SCM_ARG2, s_write_char);
+
+ SCM_ASSERT (scm_valid_oport_value_p (port), port, SCM_ARG2, s_write_char);
SCM_ASSERT (SCM_ICHRP (chr), chr, SCM_ARG1, s_write_char);
scm_putc ((int) SCM_ICHR (chr), SCM_COERCE_OUTPORT (port));
\f
/* Call back to Scheme code to do the printing of special objects
-(like structs). SCM_PRINTER_APPLY applies PROC to EXP and a pair
-containing PORT and PSTATE. This pair can be used as the port for
-display/write etc to continue the current print chain. The REVEALED
-field of PSTATE is set to true to indicate that the print state has
-escaped to Scheme and thus has to be freed by the GC. */
+ * (like structs). SCM_PRINTER_APPLY applies PROC to EXP and a smob
+ * containing PORT and PSTATE. This object can be used as the port for
+ * display/write etc to continue the current print chain. The REVEALED
+ * field of PSTATE is set to true to indicate that the print state has
+ * escaped to Scheme and thus has to be freed by the GC.
+ */
+
+long scm_tc16_port_with_ps;
+
+/* Print exactly as the port itself would */
+
+static int
+print_port_with_ps (SCM obj, SCM port, scm_print_state *pstate)
+{
+ obj = SCM_PORT_WITH_PS_PORT (obj);
+ return scm_ptobs[SCM_PTOBNUM (obj)].print (obj, port, pstate);
+}
SCM
scm_printer_apply (proc, exp, port, pstate)
SCM proc, exp, port;
scm_print_state *pstate;
{
+ SCM pwps;
SCM pair = scm_cons (port, pstate->handle);
+ SCM_NEWSMOB (pwps, scm_tc16_port_with_ps, pair);
pstate->revealed = 1;
- return scm_apply (proc, exp, scm_cons (pair, scm_listofnull));
+ return scm_apply (proc, exp, scm_cons (pwps, scm_listofnull));
+}
+
+SCM_PROC (s_port_with_print_state, "port-with-print-state", 2, 0, 0, scm_port_with_print_state);
+
+SCM
+scm_port_with_print_state (SCM port, SCM pstate)
+{
+ SCM pwps;
+ SCM_ASSERT (scm_valid_oport_value_p (port),
+ port, SCM_ARG1, s_port_with_print_state);
+ SCM_ASSERT (SCM_NIMP (pstate) && SCM_PRINT_STATE_P (pstate),
+ pstate, SCM_ARG2, s_port_with_print_state);
+ port = SCM_COERCE_OUTPORT (port);
+ SCM_NEWSMOB (pwps, scm_tc16_port_with_ps, scm_cons (port, pstate));
+ return pwps;
+}
+
+SCM_PROC (s_get_print_state, "get-print-state", 1, 0, 0, scm_get_print_state);
+
+SCM
+scm_get_print_state (SCM port)
+{
+ if (SCM_NIMP (port))
+ {
+ if (SCM_PORT_WITH_PS_P (port))
+ return SCM_PORT_WITH_PS_PS (port);
+ if (SCM_OUTPORTP (port))
+ return SCM_BOOL_F;
+ }
+ return scm_wta (port, (char *) SCM_ARG1, s_get_print_state);
}
\f
void
scm_init_print ()
{
- SCM vtable, layout, printer, type;
+ SCM vtable, layout, type;
scm_init_opts (scm_print_options, scm_print_opts, SCM_N_PRINT_OPTIONS);
vtable = scm_make_vtable_vtable (scm_make_struct_layout (scm_nullstr),
SCM_INUM0,
SCM_EOL);
layout = scm_make_struct_layout (scm_makfrom0str (SCM_PRINT_STATE_LAYOUT));
- printer = scm_make_subr_opt (s_print_state_printer,
- scm_tc7_subr_2,
- (SCM (*) ()) print_state_printer,
- 0 /* Don't bind the name. */);
- type = scm_make_struct (vtable, SCM_INUM0, SCM_LIST2 (layout, printer));
+ type = scm_make_struct (vtable, SCM_INUM0, SCM_LIST1 (layout));
+ scm_set_struct_vtable_name_x (type, SCM_CAR (scm_intern0 ("print-state")));
print_state_pool = scm_permanent_object (scm_cons (type, SCM_EOL));
scm_print_state_vtable = type;
+ /* Don't want to bind a wrapper class in GOOPS, so pass 0 as arg1. */
+ scm_tc16_port_with_ps = scm_make_smob_type (0, 0);
+ scm_set_smob_mark (scm_tc16_port_with_ps, scm_markcdr);
+ scm_set_smob_print (scm_tc16_port_with_ps, print_port_with_ps);
+
#include "print.x"
}