mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-16 08:40:19 +02:00
* struct.c (scm_struct_ref, scm_struct_set_x): Use
scm_struct_i_n_words to get the number of fields, not -scm_struct_n_extra_words. On the route to fancier struct printing: * struct.c (scm_print_struct): New function to print a structure. Include "genio.h" to support it. This function doesn't do anything interesting right now, but I think it should be here anyway. * struct.h: Include "print.h" and add prototype for scm_print_struct. * print.c (scm_iprin1): Call scm_print_struct instead of trying to print structures ourself.
This commit is contained in:
parent
ede1d9bf57
commit
bafcafb270
3 changed files with 41 additions and 5 deletions
|
@ -320,9 +320,7 @@ taloop:
|
||||||
|
|
||||||
if (SCM_CDR (SCM_CAR (exp) - 1L) == 0)
|
if (SCM_CDR (SCM_CAR (exp) - 1L) == 0)
|
||||||
{
|
{
|
||||||
scm_gen_write (scm_regular_string, "#<struct ", sizeof ("#<struct ") - 1, port);
|
scm_print_struct (exp, port, pstate);
|
||||||
scm_intprint(exp, 16, port);
|
|
||||||
scm_gen_putc ('>', port);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "_scm.h"
|
#include "_scm.h"
|
||||||
#include "chars.h"
|
#include "chars.h"
|
||||||
|
#include "genio.h"
|
||||||
|
|
||||||
#include "struct.h"
|
#include "struct.h"
|
||||||
|
|
||||||
|
@ -434,7 +435,7 @@ scm_struct_ref (handle, pos)
|
||||||
p = SCM_INUM (pos);
|
p = SCM_INUM (pos);
|
||||||
|
|
||||||
fields_desc = (unsigned char *)SCM_CHARS (layout);
|
fields_desc = (unsigned char *)SCM_CHARS (layout);
|
||||||
n_fields = data[- scm_struct_n_extra_words] - scm_struct_n_extra_words;
|
n_fields = data[scm_struct_i_n_words] - scm_struct_n_extra_words;
|
||||||
|
|
||||||
SCM_ASSERT (p < n_fields, pos, SCM_OUTOFRANGE, s_struct_ref);
|
SCM_ASSERT (p < n_fields, pos, SCM_OUTOFRANGE, s_struct_ref);
|
||||||
|
|
||||||
|
@ -516,7 +517,7 @@ scm_struct_set_x (handle, pos, val)
|
||||||
p = SCM_INUM (pos);
|
p = SCM_INUM (pos);
|
||||||
|
|
||||||
fields_desc = (unsigned char *)SCM_CHARS (layout);
|
fields_desc = (unsigned char *)SCM_CHARS (layout);
|
||||||
n_fields = data[- scm_struct_n_extra_words] - scm_struct_n_extra_words;
|
n_fields = data[scm_struct_i_n_words] - scm_struct_n_extra_words;
|
||||||
|
|
||||||
SCM_ASSERT (p < n_fields, pos, SCM_OUTOFRANGE, s_struct_set_x);
|
SCM_ASSERT (p < n_fields, pos, SCM_OUTOFRANGE, s_struct_set_x);
|
||||||
|
|
||||||
|
@ -595,6 +596,41 @@ scm_struct_vtable_tag (handle)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
scm_print_struct (exp, port, pstate)
|
||||||
|
SCM exp;
|
||||||
|
SCM port;
|
||||||
|
scm_print_state *pstate;
|
||||||
|
{
|
||||||
|
#if 0 /* XXX - too verbose */
|
||||||
|
SCM * data;
|
||||||
|
SCM layout;
|
||||||
|
int p;
|
||||||
|
int n_fields;
|
||||||
|
unsigned char * fields_desc;
|
||||||
|
unsigned char field_type;
|
||||||
|
|
||||||
|
layout = SCM_STRUCT_LAYOUT (exp);
|
||||||
|
data = SCM_STRUCT_DATA (exp);
|
||||||
|
|
||||||
|
fields_desc = (unsigned char *)SCM_CHARS (layout);
|
||||||
|
n_fields = data[scm_struct_i_n_words] - scm_struct_n_extra_words;
|
||||||
|
|
||||||
|
scm_gen_write (scm_regular_string, "#<struct ", sizeof ("#<struct ") - 1, port);
|
||||||
|
for (p = 0; p < n_fields; p++)
|
||||||
|
{
|
||||||
|
if (fields_desc[2*p] == 'p')
|
||||||
|
scm_iprin1 (data[p], port, pstate);
|
||||||
|
if (p < n_fields-1)
|
||||||
|
scm_gen_putc (' ', port);
|
||||||
|
}
|
||||||
|
scm_gen_putc ('>', port);
|
||||||
|
#else
|
||||||
|
scm_gen_write (scm_regular_string, "#<struct ", sizeof ("#<struct ") - 1, port);
|
||||||
|
scm_intprint (exp, 16, port);
|
||||||
|
scm_gen_putc ('>', port);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
scm_init_struct ()
|
scm_init_struct ()
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "libguile/__scm.h"
|
#include "libguile/__scm.h"
|
||||||
|
#include "libguile/print.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,6 +82,7 @@ extern SCM scm_struct_ref SCM_P ((SCM handle, SCM pos));
|
||||||
extern SCM scm_struct_set_x SCM_P ((SCM handle, SCM pos, SCM val));
|
extern SCM scm_struct_set_x SCM_P ((SCM handle, SCM pos, SCM val));
|
||||||
extern SCM scm_struct_vtable SCM_P ((SCM handle));
|
extern SCM scm_struct_vtable SCM_P ((SCM handle));
|
||||||
extern SCM scm_struct_vtable_tag SCM_P ((SCM handle));
|
extern SCM scm_struct_vtable_tag SCM_P ((SCM handle));
|
||||||
|
extern void scm_print_struct SCM_P ((SCM exp, SCM port, scm_print_state *));
|
||||||
extern void scm_init_struct SCM_P ((void));
|
extern void scm_init_struct SCM_P ((void));
|
||||||
|
|
||||||
#endif /* STRUCTH */
|
#endif /* STRUCTH */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue