1 /* Copyright (C) 1995-1999 Free Software Foundation, Inc.
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
15 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 * Boston, MA 02111-1307 USA
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
21 * The exception is that, if you link the GUILE library with other files
22 * to produce an executable, this does not by itself cause the
23 * resulting executable to be covered by the GNU General Public License.
24 * Your use of that executable is in no way restricted on account of
25 * linking the GUILE library code into it.
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
30 * This exception applies only to the code released by the
31 * Free Software Foundation under the name GUILE. If you copy
32 * code from other Free Software Foundation releases into a copy of
33 * GUILE, as the General Public License permits, the exception does
34 * not apply to the code that you add in this way. To avoid misleading
35 * anyone as to the status of such modified files, you must delete
36 * this exception notice from them.
38 * If you write modifications of your own for GUILE, it is your choice
39 * whether to permit this exception to apply to your modifications.
40 * If you do not wish that, delete this exception notice. */
61 /* {Names of immediate symbols}
63 * This table must agree with the declarations in scm.h: {Immediate Symbols}.
66 char *scm_isymnames
[] =
68 /* This table must agree with the declarations */
84 "#@literal-variable-ref",
85 "#@literal-variable-set!",
88 "#@call-with-current-continuation",
90 /* user visible ISYMS */
104 /* Multi-language support */
115 scm_option scm_print_opts
[] = {
116 { SCM_OPTION_SCM
, "closure-hook", SCM_BOOL_F
,
117 "Hook for printing closures." },
118 { SCM_OPTION_BOOLEAN
, "source", 0,
119 "Print closures with source." }
122 SCM_PROC (s_print_options
, "print-options-interface", 0, 1, 0, scm_print_options
);
125 scm_print_options (setting
)
128 SCM ans
= scm_options (setting
,
136 /* {Printing of Scheme Objects}
139 /* Detection of circular references.
141 * Due to other constraints in the implementation, this code has bad
142 * time complexity (O (depth * N)), The printer code will be
143 * completely rewritten before next release of Guile. The new code
146 #define PUSH_REF(pstate, obj) \
148 pstate->ref_stack[pstate->top++] = (obj); \
149 if (pstate->top == pstate->ceiling) \
150 grow_ref_stack (pstate); \
153 #define ENTER_NESTED_DATA(pstate, obj, label) \
155 register unsigned long i; \
156 for (i = 0; i < pstate->top; ++i) \
157 if (pstate->ref_stack[i] == (obj)) \
159 if (pstate->fancyp) \
161 if (pstate->top - pstate->list_offset >= pstate->level) \
163 scm_putc ('#', port); \
167 PUSH_REF(pstate, obj); \
170 #define EXIT_NESTED_DATA(pstate) { --pstate->top; }
172 SCM scm_print_state_vtable
;
174 static SCM print_state_pool
;
176 #ifdef GUILE_DEBUG /* Used for debugging purposes */
177 SCM_PROC(s_current_pstate
, "current-pstate", 0, 0, 0, scm_current_pstate
);
180 scm_current_pstate ()
182 return SCM_CADR (print_state_pool
);
186 #define PSTATE_SIZE 50L
188 static SCM make_print_state
SCM_P ((void));
193 SCM print_state
= scm_make_struct (SCM_CAR (print_state_pool
), /* pstate type */
196 scm_print_state
*pstate
= SCM_PRINT_STATE (print_state
);
197 pstate
->ref_vect
= scm_make_vector (SCM_MAKINUM (PSTATE_SIZE
),
199 pstate
->ref_stack
= SCM_VELTS (pstate
->ref_vect
);
200 pstate
->ceiling
= SCM_LENGTH (pstate
->ref_vect
);
205 scm_make_print_state ()
209 /* First try to allocate a print state from the pool */
211 if (SCM_NNULLP (SCM_CDR (print_state_pool
)))
213 answer
= SCM_CADR (print_state_pool
);
214 SCM_SETCDR (print_state_pool
, SCM_CDDR (print_state_pool
));
218 return answer
? answer
: make_print_state ();
222 scm_free_print_state (print_state
)
226 scm_print_state
*pstate
= SCM_PRINT_STATE (print_state
);
227 /* Cleanup before returning print state to pool.
228 * It is better to do it here. Doing it in scm_prin1
229 * would cost more since that function is called much more
233 pstate
->revealed
= 0;
234 SCM_NEWCELL (handle
);
236 SCM_SETCAR (handle
, print_state
);
237 SCM_SETCDR (handle
, SCM_CDR (print_state_pool
));
238 SCM_SETCDR (print_state_pool
, handle
);
242 static void grow_ref_stack
SCM_P ((scm_print_state
*pstate
));
245 grow_ref_stack (pstate
)
246 scm_print_state
*pstate
;
248 int new_size
= 2 * pstate
->ceiling
;
249 scm_vector_set_length_x (pstate
->ref_vect
, SCM_MAKINUM (new_size
));
250 pstate
->ref_stack
= SCM_VELTS (pstate
->ref_vect
);
251 pstate
->ceiling
= new_size
;
255 static void print_circref
SCM_P ((SCM port
, scm_print_state
*pstate
, SCM ref
));
258 print_circref (port
, pstate
, ref
)
260 scm_print_state
*pstate
;
264 int self
= pstate
->top
- 1;
266 if (SCM_CONSP (pstate
->ref_stack
[i
]))
270 if (SCM_NCONSP (pstate
->ref_stack
[i
- 1])
271 || SCM_CDR (pstate
->ref_stack
[i
- 1]) != pstate
->ref_stack
[i
])
277 for (i
= pstate
->top
- 1; 1; --i
)
278 if (pstate
->ref_stack
[i
] == ref
)
280 scm_putc ('#', port
);
281 scm_intprint (i
- self
, 10, port
);
282 scm_putc ('#', port
);
285 /* Print generally. Handles both write and display according to PSTATE.
287 SCM_GPROC(s_write
, "write", 1, 1, 0, scm_write
, g_write
);
288 SCM_GPROC(s_display
, "display", 1, 1, 0, scm_display
, g_display
);
291 scm_iprin1 (exp
, port
, pstate
)
294 scm_print_state
*pstate
;
297 switch (7 & (int) exp
)
301 scm_intprint (SCM_INUM (exp
), 10, port
);
309 if (SCM_WRITINGP (pstate
))
311 scm_puts ("#\\", port
);
312 if ((i
>= 0) && (i
<= ' ') && scm_charnames
[i
])
313 scm_puts (scm_charnames
[i
], port
);
314 else if (i
< 0 || i
> '\177')
315 scm_intprint (i
, 8, port
);
322 else if (SCM_IFLAGP (exp
)
323 && ((size_t) SCM_ISYMNUM (exp
) < (sizeof scm_isymnames
/ sizeof (char *))))
324 scm_puts (SCM_ISYMCHARS (exp
), port
);
325 else if (SCM_ILOCP (exp
))
327 scm_puts ("#@", port
);
328 scm_intprint ((long) SCM_IFRAME (exp
), 10, port
);
329 scm_putc (SCM_ICDRP (exp
) ? '-' : '+', port
);
330 scm_intprint ((long) SCM_IDIST (exp
), 10, port
);
337 scm_puts ("#@", port
);
338 exp
= SCM_CAR (exp
- 1);
342 scm_ipruk ("immediate", exp
, port
);
345 switch (SCM_TYP7 (exp
))
347 case scm_tcs_cons_gloc
:
349 if (SCM_CDR (SCM_CAR (exp
) - 1L) == 0)
351 ENTER_NESTED_DATA (pstate
, exp
, circref
);
352 if (SCM_OBJ_CLASS_FLAGS (exp
) & SCM_CLASSF_GOOPS
)
354 SCM pwps
, print
= pstate
->writingp
? g_write
: g_display
;
358 scm_tc16_port_with_ps
,
359 scm_cons (port
, pstate
->handle
));
360 scm_call_generic_2 (print
, exp
, pwps
);
365 scm_print_struct (exp
, port
, pstate
);
367 EXIT_NESTED_DATA (pstate
);
371 case scm_tcs_cons_imcar
:
372 case scm_tcs_cons_nimcar
:
373 ENTER_NESTED_DATA (pstate
, exp
, circref
);
374 scm_iprlist ("(", exp
, ')', port
, pstate
);
375 EXIT_NESTED_DATA (pstate
);
378 print_circref (port
, pstate
, exp
);
381 if (!SCM_CLOSUREP (SCM_CDR (exp
)))
383 case scm_tcs_closures
:
384 /* The user supplied print closure procedure must handle
385 macro closures as well. */
386 if (SCM_FALSEP (scm_procedure_p (SCM_PRINT_CLOSURE
))
387 || SCM_FALSEP (scm_printer_apply (SCM_PRINT_CLOSURE
,
391 if (SCM_TYP16 (exp
) == scm_tc16_macro
)
393 /* Printing a macro. */
395 name
= scm_macro_name (exp
);
396 if (!SCM_CLOSUREP (SCM_CDR (exp
)))
399 scm_puts ("#<primitive-", port
);
403 code
= SCM_CODE (SCM_CDR (exp
));
404 env
= SCM_ENV (SCM_CDR (exp
));
405 scm_puts ("#<", port
);
407 if (SCM_CAR (exp
) & (3L << 16))
408 scm_puts ("macro", port
);
410 scm_puts ("syntax", port
);
411 if (SCM_CAR (exp
) & (2L << 16))
412 scm_putc ('!', port
);
416 /* Printing a closure. */
417 name
= scm_procedure_name (exp
);
418 code
= SCM_CODE (exp
);
420 scm_puts ("#<procedure", port
);
422 if (SCM_NIMP (name
) && SCM_ROSTRINGP (name
))
424 scm_putc (' ', port
);
425 scm_puts (SCM_ROCHARS (name
), port
);
429 if (SCM_PRINT_SOURCE_P
)
431 code
= scm_unmemocopy (code
,
432 SCM_EXTEND_ENV (SCM_CAR (code
),
435 ENTER_NESTED_DATA (pstate
, exp
, circref
);
436 scm_iprlist (" ", code
, '>', port
, pstate
);
437 EXIT_NESTED_DATA (pstate
);
441 if (SCM_TYP16 (exp
) != scm_tc16_macro
)
443 scm_putc (' ', port
);
444 scm_iprin1 (SCM_CAR (code
), port
, pstate
);
446 scm_putc ('>', port
);
450 scm_putc ('>', port
);
453 case scm_tc7_substring
:
455 if (SCM_WRITINGP (pstate
))
459 scm_putc ('"', port
);
460 for (i
= 0; i
< SCM_ROLENGTH (exp
); ++i
)
461 switch (SCM_ROCHARS (exp
)[i
])
465 scm_putc ('\\', port
);
467 scm_putc (SCM_ROCHARS (exp
)[i
], port
);
469 scm_putc ('"', port
);
473 scm_lfwrite (SCM_ROCHARS (exp
), (scm_sizet
) SCM_ROLENGTH (exp
),
476 case scm_tcs_symbols
:
486 len
= SCM_LENGTH (exp
);
487 str
= SCM_CHARS (exp
);
494 scm_lfwrite ("#{}#", 4, port
);
496 for (end
= pos
; end
< len
; ++end
)
499 #ifdef BRACKETS_AS_PARENS
507 case SCM_WHITE_SPACES
:
508 case SCM_LINE_INCREMENTORS
:
517 scm_lfwrite ("#{", 2, port
);
522 scm_lfwrite (str
+ pos
, end
- pos
, port
);
528 scm_lfwrite (buf
, 2, port
);
550 scm_lfwrite (str
+ pos
, end
- pos
, port
);
552 scm_lfwrite ("}#", 2, port
);
556 ENTER_NESTED_DATA (pstate
, exp
, circref
);
557 if (SCM_IS_WHVEC (exp
))
558 scm_puts ("#wh(", port
);
560 scm_puts ("#w(", port
);
561 goto common_vector_printer
;
564 ENTER_NESTED_DATA (pstate
, exp
, circref
);
565 scm_puts ("#(", port
);
566 common_vector_printer
:
569 int last
= SCM_LENGTH (exp
) - 1;
571 if (pstate
->fancyp
&& SCM_LENGTH (exp
) > pstate
->length
)
573 last
= pstate
->length
- 1;
576 for (i
= 0; i
< last
; ++i
)
579 scm_iprin1 (SCM_VELTS (exp
)[i
], port
, pstate
);
580 scm_putc (' ', port
);
585 scm_iprin1 (SCM_VELTS (exp
)[i
], port
, pstate
);
588 scm_puts (" ...", port
);
589 scm_putc (')', port
);
591 EXIT_NESTED_DATA (pstate
);
604 scm_raprin1 (exp
, port
, pstate
);
607 scm_puts (SCM_SUBR_GENERIC (exp
) && *SCM_SUBR_GENERIC (exp
)
608 ? "#<primitive-generic "
609 : "#<primitive-procedure ",
611 scm_puts (SCM_CHARS (SCM_SNAME (exp
)), port
);
612 scm_putc ('>', port
);
617 SCM proc
= SCM_CCLO_SUBR (exp
);
618 if (proc
== scm_f_gsubr_apply
)
620 /* Print gsubrs as primitives */
621 SCM name
= scm_procedure_name (exp
);
622 scm_puts ("#<primitive-procedure", port
);
623 if (SCM_NFALSEP (name
))
625 scm_putc (' ', port
);
626 scm_puts (SCM_CHARS (name
), port
);
631 scm_puts ("#<compiled-closure ", port
);
632 scm_iprin1 (proc
, port
, pstate
);
634 scm_putc ('>', port
);
639 scm_puts ("#<procedure-with-setter", port
);
641 SCM name
= scm_procedure_name (exp
);
642 if (SCM_NFALSEP (name
))
644 scm_putc (' ', port
);
645 scm_puts (SCM_ROCHARS (name
), port
);
648 scm_putc ('>', port
);
651 scm_puts ("#<continuation ", port
);
652 scm_intprint (SCM_LENGTH (exp
), 10, port
);
653 scm_puts (" @ ", port
);
654 scm_intprint ((long) SCM_CHARS (exp
), 16, port
);
655 scm_putc ('>', port
);
659 register long i
= SCM_PTOBNUM (exp
);
661 && scm_ptobs
[i
].print
662 && (scm_ptobs
[i
].print
) (exp
, port
, pstate
))
669 ENTER_NESTED_DATA (pstate
, exp
, circref
);
670 i
= SCM_SMOBNUM (exp
);
671 if (i
< scm_numsmob
&& scm_smobs
[i
].print
672 && (scm_smobs
[i
].print
) (exp
, port
, pstate
))
674 EXIT_NESTED_DATA (pstate
);
677 EXIT_NESTED_DATA (pstate
);
678 /* Macros have their print field set to NULL. They are
679 handled at the same place as closures in order to achieve
680 non-redundancy. Placing the condition here won't slow
681 down printing of other smobs. */
682 if (SCM_TYP16 (exp
) == scm_tc16_macro
)
687 scm_ipruk ("type", exp
, port
);
692 /* Print states are necessary for circular reference safe printing.
693 * They are also expensive to allocate. Therefore print states are
694 * kept in a pool so that they can be reused.
697 /* The PORT argument can also be a print-state/port pair, which will
698 * then be used instead of allocating a new print state. This is
699 * useful for continuing a chain of print calls from Scheme. */
702 scm_prin1 (exp
, port
, writingp
)
707 SCM handle
= SCM_BOOL_F
; /* Will GC protect the handle whilst unlinked */
709 scm_print_state
*pstate
;
711 /* If PORT is a print-state/port pair, use that. Else create a new
714 if (SCM_NIMP (port
) && SCM_PORT_WITH_PS_P (port
))
716 pstate_scm
= SCM_PORT_WITH_PS_PS (port
);
717 port
= SCM_PORT_WITH_PS_PORT (port
);
721 /* First try to allocate a print state from the pool */
723 if (SCM_NNULLP (SCM_CDR (print_state_pool
)))
725 handle
= SCM_CDR (print_state_pool
);
726 SCM_SETCDR (print_state_pool
, SCM_CDDR (print_state_pool
));
729 if (handle
== SCM_BOOL_F
)
730 handle
= scm_cons (make_print_state (), SCM_EOL
);
731 pstate_scm
= SCM_CAR (handle
);
734 pstate
= SCM_PRINT_STATE (pstate_scm
);
735 pstate
->writingp
= writingp
;
736 scm_iprin1 (exp
, port
, pstate
);
738 /* Return print state to pool if it has been created above and
739 hasn't escaped to Scheme. */
741 if (handle
!= SCM_BOOL_F
&& !pstate
->revealed
)
744 SCM_SETCDR (handle
, SCM_CDR (print_state_pool
));
745 SCM_SETCDR (print_state_pool
, handle
);
755 scm_intprint (n
, radix
, port
)
760 char num_buf
[SCM_INTBUFLEN
];
761 scm_lfwrite (num_buf
, scm_iint2str (n
, radix
, num_buf
), port
);
764 /* Print an object of unrecognized type.
768 scm_ipruk (hdr
, ptr
, port
)
773 scm_puts ("#<unknown-", port
);
774 scm_puts (hdr
, port
);
777 scm_puts (" (0x", port
);
778 scm_intprint (SCM_CAR (ptr
), 16, port
);
779 scm_puts (" . 0x", port
);
780 scm_intprint (SCM_CDR (ptr
), 16, port
);
781 scm_puts (") @", port
);
783 scm_puts (" 0x", port
);
784 scm_intprint (ptr
, 16, port
);
785 scm_putc ('>', port
);
793 scm_iprlist (hdr
, exp
, tlr
, port
, pstate
)
798 scm_print_state
*pstate
;
800 register SCM hare
, tortoise
;
801 int floor
= pstate
->top
- 2;
802 scm_puts (hdr
, port
);
807 /* Run a hare and tortoise so that total time complexity will be
808 O(depth * N) instead of O(N^2). */
809 hare
= SCM_CDR (exp
);
811 while (SCM_NIMP (hare
) && SCM_ECONSP (hare
))
813 if (hare
== tortoise
)
815 hare
= SCM_CDR (hare
);
816 if (SCM_IMP (hare
) || SCM_NECONSP (hare
))
818 hare
= SCM_CDR (hare
);
819 tortoise
= SCM_CDR (tortoise
);
822 /* No cdr cycles intrinsic to this list */
823 scm_iprin1 (SCM_CAR (exp
), port
, pstate
);
825 for (; SCM_NIMP (exp
); exp
= SCM_CDR (exp
))
829 if (SCM_NECONSP (exp
))
831 for (i
= floor
; i
>= 0; --i
)
832 if (pstate
->ref_stack
[i
] == exp
)
834 PUSH_REF (pstate
, exp
);
835 scm_putc (' ', port
);
837 scm_iprin1 (SCM_CAR (exp
), port
, pstate
);
839 if (SCM_NNULLP (exp
))
841 scm_puts (" . ", port
);
842 scm_iprin1 (exp
, port
, pstate
);
846 scm_putc (tlr
, port
);
847 pstate
->top
= floor
+ 2;
852 int n
= pstate
->length
;
854 scm_iprin1 (SCM_CAR (exp
), port
, pstate
);
855 exp
= SCM_CDR (exp
); --n
;
856 for (; SCM_NIMP (exp
); exp
= SCM_CDR (exp
))
858 register unsigned long i
;
860 if (SCM_NECONSP (exp
))
862 for (i
= 0; i
< pstate
->top
; ++i
)
863 if (pstate
->ref_stack
[i
] == exp
)
869 scm_puts (" ...", port
);
875 PUSH_REF(pstate
, exp
);
876 ++pstate
->list_offset
;
877 scm_putc (' ', port
);
879 scm_iprin1 (SCM_CAR (exp
), port
, pstate
);
882 if (SCM_NNULLP (exp
))
884 scm_puts (" . ", port
);
885 scm_iprin1 (exp
, port
, pstate
);
888 pstate
->list_offset
-= pstate
->top
- floor
- 2;
892 pstate
->list_offset
-= pstate
->top
- floor
- 2;
895 scm_puts (" . ", port
);
896 print_circref (port
, pstate
, exp
);
903 scm_valid_oport_value_p (SCM val
)
905 return (SCM_NIMP (val
)
906 && (SCM_OPOUTPORTP (val
)
907 || (SCM_PORT_WITH_PS_P (val
)
908 && SCM_OPOUTPORTP (SCM_PORT_WITH_PS_PORT (val
)))));
911 /* SCM_GPROC(s_write, "write", 1, 1, 0, scm_write, g_write); */
914 scm_write (obj
, port
)
918 if (SCM_UNBNDP (port
))
921 SCM_ASSERT (scm_valid_oport_value_p (port
), port
, SCM_ARG2
, s_write
);
923 scm_prin1 (obj
, port
, 1);
927 scm_close_port (port
);
930 return SCM_UNSPECIFIED
;
934 /* SCM_GPROC(s_display, "display", 1, 1, 0, scm_display, g_display); */
937 scm_display (obj
, port
)
941 if (SCM_UNBNDP (port
))
944 SCM_ASSERT (scm_valid_oport_value_p (port
), port
, SCM_ARG2
, s_display
);
946 scm_prin1 (obj
, port
, 0);
950 scm_close_port (port
);
953 return SCM_UNSPECIFIED
;
956 SCM_PROC(s_newline
, "newline", 0, 1, 0, scm_newline
);
962 if (SCM_UNBNDP (port
))
965 SCM_ASSERT (scm_valid_oport_value_p (port
), port
, SCM_ARG1
, s_newline
);
967 scm_putc ('\n', SCM_COERCE_OUTPORT (port
));
968 return SCM_UNSPECIFIED
;
971 SCM_PROC(s_write_char
, "write-char", 1, 1, 0, scm_write_char
);
974 scm_write_char (chr
, port
)
978 if (SCM_UNBNDP (port
))
981 SCM_ASSERT (scm_valid_oport_value_p (port
), port
, SCM_ARG2
, s_write_char
);
983 SCM_ASSERT (SCM_ICHRP (chr
), chr
, SCM_ARG1
, s_write_char
);
984 scm_putc ((int) SCM_ICHR (chr
), SCM_COERCE_OUTPORT (port
));
988 scm_close_port (port
);
991 return SCM_UNSPECIFIED
;
996 /* Call back to Scheme code to do the printing of special objects
997 * (like structs). SCM_PRINTER_APPLY applies PROC to EXP and a smob
998 * containing PORT and PSTATE. This object can be used as the port for
999 * display/write etc to continue the current print chain. The REVEALED
1000 * field of PSTATE is set to true to indicate that the print state has
1001 * escaped to Scheme and thus has to be freed by the GC.
1004 long scm_tc16_port_with_ps
;
1006 /* Print exactly as the port itself would */
1009 print_port_with_ps (SCM obj
, SCM port
, scm_print_state
*pstate
)
1011 obj
= SCM_PORT_WITH_PS_PORT (obj
);
1012 return scm_ptobs
[SCM_PTOBNUM (obj
)].print (obj
, port
, pstate
);
1016 scm_printer_apply (proc
, exp
, port
, pstate
)
1017 SCM proc
, exp
, port
;
1018 scm_print_state
*pstate
;
1021 SCM pair
= scm_cons (port
, pstate
->handle
);
1022 SCM_NEWSMOB (pwps
, scm_tc16_port_with_ps
, pair
);
1023 pstate
->revealed
= 1;
1024 return scm_apply (proc
, exp
, scm_cons (pwps
, scm_listofnull
));
1027 SCM_PROC (s_port_with_print_state
, "port-with-print-state", 2, 0, 0, scm_port_with_print_state
);
1030 scm_port_with_print_state (SCM port
, SCM pstate
)
1033 SCM_ASSERT (scm_valid_oport_value_p (port
),
1034 port
, SCM_ARG1
, s_port_with_print_state
);
1035 SCM_ASSERT (SCM_NIMP (pstate
) && SCM_PRINT_STATE_P (pstate
),
1036 pstate
, SCM_ARG2
, s_port_with_print_state
);
1037 port
= SCM_COERCE_OUTPORT (port
);
1038 SCM_NEWSMOB (pwps
, scm_tc16_port_with_ps
, scm_cons (port
, pstate
));
1042 SCM_PROC (s_get_print_state
, "get-print-state", 1, 0, 0, scm_get_print_state
);
1045 scm_get_print_state (SCM port
)
1047 if (SCM_NIMP (port
))
1049 if (SCM_PORT_WITH_PS_P (port
))
1050 return SCM_PORT_WITH_PS_PS (port
);
1051 if (SCM_OUTPORTP (port
))
1054 return scm_wta (port
, (char *) SCM_ARG1
, s_get_print_state
);
1062 SCM vtable
, layout
, type
;
1064 scm_init_opts (scm_print_options
, scm_print_opts
, SCM_N_PRINT_OPTIONS
);
1065 vtable
= scm_make_vtable_vtable (scm_make_struct_layout (scm_nullstr
),
1068 layout
= scm_make_struct_layout (scm_makfrom0str (SCM_PRINT_STATE_LAYOUT
));
1069 type
= scm_make_struct (vtable
, SCM_INUM0
, SCM_LIST1 (layout
));
1070 scm_set_struct_vtable_name_x (type
, SCM_CAR (scm_intern0 ("print-state")));
1071 print_state_pool
= scm_permanent_object (scm_cons (type
, SCM_EOL
));
1073 scm_print_state_vtable
= type
;
1075 /* Don't want to bind a wrapper class in GOOPS, so pass 0 as arg1. */
1076 scm_tc16_port_with_ps
= scm_make_smob_type (0, 0);
1077 scm_set_smob_mark (scm_tc16_port_with_ps
, scm_markcdr
);
1078 scm_set_smob_print (scm_tc16_port_with_ps
, print_port_with_ps
);