#include "libguile/strports.h"
#include "libguile/vectors.h"
#include "libguile/lang.h"
+#include "libguile/numbers.h"
#include "libguile/validate.h"
#include "libguile/print.h"
"#nil"
};
-/* This table must agree with the list of SCM_IM_ constants in tags.h */
-char *scm_isymnames[] =
-{
- /* Short instructions */
-
- "#@and",
- "#@begin",
- "#@case",
- "#@cond",
- "#@do",
- "#@if",
- "#@lambda",
- "#@let",
- "#@let*",
- "#@letrec",
- "#@or",
- "#@quote",
- "#@set!",
-
-
- /* Long instructions */
-
- "#@define",
- "#@apply",
- "#@call-with-current-continuation",
- "#@dispatch",
- "#@slot-ref",
- "#@slot-set!",
- "#@delay",
- "#@future",
- "#@call-with-values",
- "#@else",
- "#@arrow",
-
- /* Multi-language support */
- "#@nil-cond",
- "#@bind"
-};
-
scm_t_option scm_print_opts[] = {
{ SCM_OPTION_SCM, "closure-hook", SCM_UNPACK (SCM_BOOL_F),
"Hook for printing closures (should handle macros as well)." },
do { \
register unsigned long i; \
for (i = 0; i < pstate->top; ++i) \
- if (SCM_EQ_P (pstate->ref_stack[i], (obj))) \
+ if (scm_is_eq (pstate->ref_stack[i], (obj))) \
goto label; \
if (pstate->fancyp) \
{ \
}
scm_i_plugin_mutex_unlock (&print_state_mutex);
- return SCM_FALSEP (answer) ? make_print_state () : answer;
+ return scm_is_false (answer) ? make_print_state () : answer;
}
void
while (i > 0)
{
if (!SCM_CONSP (pstate->ref_stack[i - 1])
- || !SCM_EQ_P (SCM_CDR (pstate->ref_stack[i - 1]),
- pstate->ref_stack[i]))
+ || !scm_is_eq (SCM_CDR (pstate->ref_stack[i - 1]),
+ pstate->ref_stack[i]))
break;
--i;
}
self = i;
}
for (i = pstate->top - 1; 1; --i)
- if (SCM_EQ_P (pstate->ref_stack[i], ref))
+ if (scm_is_eq (pstate->ref_stack[i], ref))
break;
scm_putc ('#', port);
scm_intprint (i - self, 10, port);
* weird because of other characters, backslahes need to be escaped too.
* The first time we see a backslash, we set maybe_weird, and mw_pos points
* to the backslash. Then if the name turns out to be weird, we re-process
- * everything starting from mw_pos. */
+ * everything starting from mw_pos.
+ * We could instead make backslashes always weird. This is not necessary
+ * to ensure that the output is (read)-able, but it would make this code
+ * simpler and faster. */
int maybe_weird = 0;
size_t mw_pos = 0;
- /* If the name is purely numeric, then it's weird as a whole, even though
- * none of the individual characters is weird. But we won't know this
- * until we reach the end of the name. This flag describes the part of the
- * name we've looked at so far. */
- int all_digits = 1;
- if (len == 0 || str[0] == '\'' || str[0] == ':' || str[len-1] == ':')
+ if (len == 0 || str[0] == '\'' || str[0] == '`' || str[0] == ',' ||
+ str[0] == ':' || str[len-1] == ':' || (str[0] == '.' && len == 1) ||
+ scm_is_true (scm_i_mem2number(str, len, 10)))
{
scm_lfwrite ("#{", 2, port);
weird = 1;
case '#':
case SCM_WHITE_SPACES:
case SCM_LINE_INCREMENTORS:
- all_digits = 0;
weird_handler:
if (maybe_weird)
{
pos = end + 1;
break;
case '\\':
- all_digits = 0;
if (weird)
goto weird_handler;
if (!maybe_weird)
mw_pos = pos;
}
break;
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- break;
default:
- all_digits = 0;
break;
}
- if (all_digits)
- {
- scm_lfwrite ("#{", 2, port);
- weird = 1;
- }
if (pos < end)
scm_lfwrite (str + pos, end - pos, port);
if (weird)
break;
case scm_tc3_int_1:
case scm_tc3_int_2:
- scm_intprint (SCM_INUM (exp), 10, port);
+ scm_intprint (SCM_I_INUM (exp), 10, port);
break;
case scm_tc3_imm24:
if (SCM_CHARP (exp))
{
scm_puts (iflagnames [SCM_IFLAGNUM (exp)], port);
}
- else if (SCM_ISYMP (exp)
- && ((size_t) SCM_ISYMNUM (exp) < (sizeof scm_isymnames / sizeof (char *))))
+ else if (SCM_ISYMP (exp))
{
- scm_puts (SCM_ISYMCHARS (exp), port);
+ scm_i_print_isym (exp, port);
}
else if (SCM_ILOCP (exp))
{
- scm_puts ("#@", port);
- scm_intprint ((long) SCM_IFRAME (exp), 10, port);
- scm_putc (SCM_ICDRP (exp) ? '-' : '+', port);
- scm_intprint ((long) SCM_IDIST (exp), 10, port);
+ scm_i_print_iloc (exp, port);
}
else
{
print_circref (port, pstate, exp);
break;
case scm_tcs_closures:
- if (SCM_FALSEP (scm_procedure_p (SCM_PRINT_CLOSURE))
- || SCM_FALSEP (scm_printer_apply (SCM_PRINT_CLOSURE,
+ if (scm_is_false (scm_procedure_p (SCM_PRINT_CLOSURE))
+ || scm_is_false (scm_printer_apply (SCM_PRINT_CLOSURE,
exp, port, pstate)))
{
SCM formals = SCM_CLOSURE_FORMALS (exp);
{
SCM env = SCM_ENV (exp);
SCM xenv = SCM_EXTEND_ENV (formals, SCM_EOL, env);
- SCM src = scm_unmemocopy (SCM_CODE (exp), xenv);
+ SCM src = scm_i_unmemocopy_body (SCM_CODE (exp), xenv);
ENTER_NESTED_DATA (pstate, exp, circref);
scm_iprin1 (src, port, pstate);
EXIT_NESTED_DATA (pstate);
case scm_tc16_complex:
scm_print_complex (exp, port, pstate);
break;
+ case scm_tc16_fraction:
+ scm_i_print_fraction (exp, port, pstate);
+ break;
}
break;
case scm_tc7_string:
scm_putc ('"', port);
for (i = 0; i < SCM_STRING_LENGTH (exp); ++i)
- switch (SCM_STRING_CHARS (exp)[i])
- {
- case '"':
- case '\\':
- scm_putc ('\\', port);
- default:
- scm_putc (SCM_STRING_CHARS (exp)[i], port);
- }
+ {
+ unsigned char ch = SCM_STRING_CHARS (exp)[i];
+ if ((ch < 32 && ch != '\n') || (127 <= ch && ch < 148))
+ {
+ static char const hex[]="0123456789abcdef";
+ scm_putc ('\\', port);
+ scm_putc ('x', port);
+ scm_putc (hex [ch / 16], port);
+ scm_putc (hex [ch % 16], port);
+ }
+ else
+ {
+ if (ch == '"' || ch == '\\')
+ scm_putc ('\\', port);
+ scm_putc (ch, port);
+ }
+ }
scm_putc ('"', port);
- break;
}
else
- scm_lfwrite (SCM_STRING_CHARS (exp), SCM_STRING_LENGTH (exp), port);
+ scm_lfwrite (SCM_STRING_CHARS (exp), SCM_STRING_LENGTH (exp),
+ port);
break;
case scm_tc7_symbol:
if (SCM_SYMBOL_INTERNED_P (exp))
case scm_tc7_cclo:
{
SCM proc = SCM_CCLO_SUBR (exp);
- if (SCM_EQ_P (proc, scm_f_gsubr_apply))
+ if (scm_is_eq (proc, scm_f_gsubr_apply))
{
/* Print gsubrs as primitives */
SCM name = scm_procedure_name (exp);
scm_puts ("#<primitive-procedure", port);
- if (!SCM_FALSEP (name))
+ if (scm_is_true (name))
{
scm_putc (' ', port);
scm_puts (SCM_SYMBOL_CHARS (name), port);
scm_puts ("#<procedure-with-setter", port);
{
SCM name = scm_procedure_name (exp);
- if (!SCM_FALSEP (name))
+ if (scm_is_true (name))
{
scm_putc (' ', port);
scm_display (name, port);
print_state_pool = SCM_CDR (print_state_pool);
}
scm_i_plugin_mutex_unlock (&print_state_mutex);
- if (SCM_FALSEP (handle))
+ if (scm_is_false (handle))
handle = scm_list_1 (make_print_state ());
pstate_scm = SCM_CAR (handle);
}
/* Return print state to pool if it has been created above and
hasn't escaped to Scheme. */
- if (!SCM_FALSEP (handle) && !pstate->revealed)
+ if (scm_is_true (handle) && !pstate->revealed)
{
scm_i_plugin_mutex_lock (&print_state_mutex);
SCM_SETCDR (handle, print_state_pool);
tortoise = exp;
while (SCM_CONSP (hare))
{
- if (SCM_EQ_P (hare, tortoise))
+ if (scm_is_eq (hare, tortoise))
goto fancy_printing;
hare = SCM_CDR (hare);
if (!SCM_CONSP (hare))
register long i;
for (i = floor; i >= 0; --i)
- if (SCM_EQ_P (pstate->ref_stack[i], exp))
+ if (scm_is_eq (pstate->ref_stack[i], exp))
goto circref;
PUSH_REF (pstate, exp);
scm_putc (' ', port);
register unsigned long i;
for (i = 0; i < pstate->top; ++i)
- if (SCM_EQ_P (pstate->ref_stack[i], exp))
+ if (scm_is_eq (pstate->ref_stack[i], exp))
goto fancy_circref;
if (pstate->fancyp)
{
char *end;
char *p;
- if (SCM_EQ_P (destination, SCM_BOOL_T))
+ if (scm_is_eq (destination, SCM_BOOL_T))
{
destination = port = scm_cur_outp;
}
- else if (SCM_FALSEP (destination))
+ else if (scm_is_false (destination))
{
fReturnString = 1;
port = scm_mkstrport (SCM_INUM0,
}
scm_lfwrite (start, p - start, port);
- if (!SCM_EQ_P (args, SCM_EOL))
+ if (!scm_is_eq (args, SCM_EOL))
SCM_MISC_ERROR ("FORMAT: ~A superfluous arguments",
scm_list_1 (scm_length (args)));