1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

Fix bitvectors and non-zero lower bound arrays in truncated-print

* module/ice-9/arrays.scm (array-print-prefix): New private function.
* libguile/arrays.c (scm_i_print_array): Reuse (array-print-prefix) from
  (ice-9 arrays). Make sure to release the array handle.
* module/ice-9/pretty-print.scm (truncated-print): Support
  bitvectors.
  Don't try to guess the array prefix but call array-print-prefix from
  (ice-9 arrays) instead.
  Fix call to print-sequence to support non-zero lower bound arrays.
* test-suite/tests/arrays.test: Test that arrays print properly.
* test-suite/tests/print.test: Test truncated-print with bitvectors,
  non-zero lower bound arrays.
This commit is contained in:
Daniel Llorens 2017-02-21 12:23:35 +01:00
parent f52fc0566f
commit e0bcda4ad9
5 changed files with 169 additions and 56 deletions

View file

@ -908,50 +908,17 @@ scm_i_print_array_dimension (scm_t_array_handle *h, int dim, int pos,
return 1;
}
/* Print an array.
*/
int
scm_i_print_array (SCM array, SCM port, scm_print_state *pstate)
{
scm_t_array_handle h;
size_t i;
int print_lbnds = 0, zero_size = 0, print_lens = 0;
int d;
scm_call_2 (scm_c_private_ref ("ice-9 arrays", "array-print-prefix"),
array, port);
scm_array_get_handle (array, &h);
scm_putc ('#', port);
if (SCM_I_ARRAYP (array))
scm_intprint (h.ndims, 10, port);
if (h.element_type != SCM_ARRAY_ELEMENT_TYPE_SCM)
scm_write (scm_array_handle_element_type (&h), port);
for (i = 0; i < h.ndims; i++)
{
if (h.dims[i].lbnd != 0)
print_lbnds = 1;
if (h.dims[i].ubnd - h.dims[i].lbnd + 1 == 0)
zero_size = 1;
else if (zero_size)
print_lens = 1;
}
if (print_lbnds || print_lens)
for (i = 0; i < h.ndims; i++)
{
if (print_lbnds)
{
scm_putc ('@', port);
scm_intprint (h.dims[i].lbnd, 10, port);
}
if (print_lens)
{
scm_putc (':', port);
scm_intprint (h.dims[i].ubnd - h.dims[i].lbnd + 1,
10, port);
}
}
if (h.ndims == 0)
{
/* Rank zero arrays, which are really just scalars, are printed
@ -977,10 +944,13 @@ scm_i_print_array (SCM array, SCM port, scm_print_state *pstate)
scm_putc ('(', port);
scm_i_print_array_dimension (&h, 0, 0, port, pstate);
scm_putc (')', port);
return 1;
d = 1;
}
else
return scm_i_print_array_dimension (&h, 0, 0, port, pstate);
d = scm_i_print_array_dimension (&h, 0, 0, port, pstate);
scm_array_handle_release (&h);
return d;
}
void