1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

Removed redundant code.

This commit is contained in:
Keisuke Nishida 2001-02-06 02:12:10 +00:00
parent 5f17c66f82
commit bf8f092280
4 changed files with 83 additions and 131 deletions

View file

@ -1,3 +1,12 @@
2001-02-05 Keisuke Nishida <kxn30@po.cwru.edu>
* dump.c (scm_store_cell_object, scm_restore_cell_object): Removed.
(scm_dump_cell_update): Removed.
(scm_dump_update): Renamed from scm_dump_object_update.
(scm_restore_string, scm_restore_bytes, scm_restore_word): Takes
a pointer instead of returning a value.
* keywords.c (keyword_undump): Updated.
2001-02-05 Keisuke Nishida <kxn30@po.cwru.edu>
* dump.c, dump.h: Modified a lot.

View file

@ -75,17 +75,10 @@ struct scm_dump_header {
/* or immediate value */
};
struct scm_dump_object_update {
struct scm_dump_update {
scm_bits_t id; /* object identifier */
scm_bits_t *addr; /* object address */
struct scm_dump_object_update *next; /* next update */
};
struct scm_dump_cell_update {
scm_bits_t id; /* object identifier */
SCM cell; /* cell */
int n; /* 0-3 */
struct scm_dump_cell_update *next; /* next update */
struct scm_dump_update *next; /* next update */
};
@ -96,27 +89,20 @@ struct scm_dump_cell_update {
static scm_bits_t scm_tc16_dstate;
struct scm_dstate {
/* Memory image */
int mmapped;
scm_sizet image_size;
int image_index;
char *image_base;
/* Object table */
char *image_base; /* Memory image */
int table_index;
SCM table;
/* Update schedule */
struct scm_dump_object_update *object_updates;
struct scm_dump_cell_update *cell_updates;
SCM table; /* Object table */
struct scm_dump_update *updates; /* Update schedule */
};
#define SCM_DSTATE_DATA(d) ((struct scm_dstate *) SCM_SMOB_DATA (d))
#define SCM_DSTATE_TABLE(d) (SCM_DSTATE_DATA (d)->table)
#define SCM_DSTATE_TABLE_REF(d,i) (SCM_VELTS (SCM_DSTATE_TABLE (d))[i])
#define SCM_DSTATE_TABLE_SET(d,i,x) (SCM_VELTS (SCM_DSTATE_TABLE (d))[i] = (x))
#define SCM_DSTATE_OBJECT_UPDATES(d)(SCM_DSTATE_DATA (d)->object_updates)
#define SCM_DSTATE_CELL_UPDATES(d) (SCM_DSTATE_DATA (d)->cell_updates)
#define SCM_DSTATE_UPDATES(d) (SCM_DSTATE_DATA (d)->updates)
static SCM
make_dstate ()
@ -129,8 +115,7 @@ make_dstate ()
p->image_base = SCM_MUST_MALLOC (p->image_size);
p->table_index = 0;
p->table = SCM_BOOL_F;
p->object_updates = 0;
p->cell_updates = 0;
p->updates = 0;
SCM_RETURN_NEWSMOB (scm_tc16_dstate, p);
}
#undef FUNC_NAME
@ -158,8 +143,7 @@ make_dstate_by_mmap (int fd)
p->image_base = addr;
p->table_index = 0;
p->table = SCM_BOOL_F;
p->object_updates = 0;
p->cell_updates = 0;
p->updates = 0;
SCM_RETURN_NEWSMOB (scm_tc16_dstate, p);
}
#undef FUNC_NAME
@ -193,19 +177,12 @@ dstate_free (SCM obj)
}
/* Free update schedules */
while (p->object_updates)
while (p->updates)
{
struct scm_dump_object_update *next = p->object_updates->next;
scm_must_free (p->object_updates);
size += sizeof (struct scm_dump_object_update);
p->object_updates = next;
}
while (p->cell_updates)
{
struct scm_dump_cell_update *next = p->cell_updates->next;
scm_must_free (p->cell_updates);
size += sizeof (struct scm_dump_cell_update);
p->cell_updates = next;
struct scm_dump_update *next = p->updates->next;
scm_must_free (p->updates);
size += sizeof (struct scm_dump_update);
p->updates = next;
}
scm_must_free (p);
@ -309,98 +286,69 @@ scm_store_object (SCM obj, SCM dstate)
{
/* OBJ is not stored yet. Do it later */
struct scm_dstate *p = SCM_DSTATE_DATA (dstate);
struct scm_dump_object_update *update =
scm_must_malloc (sizeof (struct scm_dump_object_update),
struct scm_dump_update *update =
scm_must_malloc (sizeof (struct scm_dump_update),
"scm_store_object");
update->id = SCM_UNPACK (obj);
update->addr = (scm_bits_t *) p->image_index;
update->next = p->object_updates;
p->object_updates = update;
update->next = p->updates;
p->updates = update;
}
scm_store_word (id, dstate);
}
void
scm_store_cell_object (SCM cell, int n, SCM dstate)
{
scm_store_object (SCM_CELL_OBJECT (cell, n), dstate);
}
/* restore functions */
static void
scm_restore_pad (SCM dstate)
scm_restore_pad (struct scm_dstate *p)
{
struct scm_dstate *p = SCM_DSTATE_DATA (dstate);
while (p->image_index % sizeof (scm_bits_t) != 0)
p->image_index++;
}
const char *
scm_restore_string (scm_sizet *sizep, SCM dstate)
void
scm_restore_string (const char **pp, scm_sizet *sizep, SCM dstate)
{
struct scm_dstate *p = SCM_DSTATE_DATA (dstate);
const char *addr = p->image_base + p->image_index;
*sizep = strlen (addr);
*pp = p->image_base + p->image_index;
*sizep = strlen (*pp);
p->image_index += *sizep + 1;
scm_restore_pad (dstate);
return addr;
scm_restore_pad (p);
}
const void *
scm_restore_bytes (scm_sizet size, SCM dstate)
void
scm_restore_bytes (const void **pp, scm_sizet size, SCM dstate)
{
struct scm_dstate *p = SCM_DSTATE_DATA (dstate);
const void *addr = p->image_base + p->image_index;
*pp = p->image_base + p->image_index;
p->image_index += size;
scm_restore_pad (dstate);
return addr;
scm_restore_pad (p);
}
scm_bits_t
scm_restore_word (SCM dstate)
void
scm_restore_word (scm_bits_t *wordp, SCM dstate)
{
struct scm_dstate *p = SCM_DSTATE_DATA (dstate);
scm_bits_t word = *(scm_bits_t *) (p->image_base + p->image_index);
*wordp = *(scm_bits_t *) (p->image_base + p->image_index);
p->image_index += sizeof (scm_bits_t);
return word;
}
void
scm_restore_object (SCM *objp, SCM dstate)
{
scm_bits_t id = scm_restore_word (dstate);
scm_bits_t id;
scm_restore_word (&id, dstate);
*objp = scm_indicator_object (id, dstate);
if (SCM_UNBNDP (*objp))
{
struct scm_dump_object_update *update =
scm_must_malloc (sizeof (struct scm_dump_object_update),
struct scm_dump_update *update =
scm_must_malloc (sizeof (struct scm_dump_update),
"scm_restore_object");
update->id = id;
update->addr = (scm_bits_t *) objp;
update->next = SCM_DSTATE_OBJECT_UPDATES (dstate);
SCM_DSTATE_OBJECT_UPDATES (dstate) = update;
}
}
void
scm_restore_cell_object (SCM cell, int n, SCM dstate)
{
scm_bits_t id = scm_restore_word (dstate);
SCM obj = scm_indicator_object (id, dstate);
SCM_SET_CELL_OBJECT (cell, n, obj);
if (SCM_UNBNDP (obj))
{
struct scm_dump_cell_update *update =
scm_must_malloc (sizeof (struct scm_dump_cell_update),
"scm_restore_cell_object");
update->id = id;
update->cell = cell;
update->n = n;
update->next = SCM_DSTATE_CELL_UPDATES (dstate);
SCM_DSTATE_CELL_UPDATES (dstate) = update;
update->next = SCM_DSTATE_UPDATES (dstate);
SCM_DSTATE_UPDATES (dstate) = update;
}
}
@ -427,8 +375,8 @@ scm_dump (SCM obj, SCM dstate)
scm_store_word (scm_tc3_cons, dstate);
/* Store cdr first in order to avoid a possible deep recursion
* with a long list */
scm_store_cell_object (obj, 1, dstate);
scm_store_cell_object (obj, 0, dstate);
scm_store_object (SCM_CDR (obj), dstate);
scm_store_object (SCM_CAR (obj), dstate);
goto next_dump;
}
switch (SCM_TYP7 (obj))
@ -478,10 +426,10 @@ scm_dump (SCM obj, SCM dstate)
}
next_dump:
while (p->object_updates)
while (p->updates)
{
struct scm_dump_object_update *update = p->object_updates;
p->object_updates = update->next;
struct scm_dump_update *update = p->updates;
p->updates = update->next;
scm_dump (SCM_PACK (update->id), dstate);
*(scm_bits_t *) (p->image_base + (int) update->addr) =
scm_object_indicator (SCM_PACK (update->id), dstate);
@ -493,15 +441,17 @@ static void
scm_undump (SCM dstate)
{
struct scm_dstate *p = SCM_DSTATE_DATA (dstate);
scm_bits_t tc = scm_restore_word (dstate);
scm_bits_t tc;
SCM obj;
scm_restore_word (&tc, dstate);
if (SCM_ITAG3 (SCM_PACK (tc)) == scm_tc3_cons)
{
SCM_NEWCELL (obj);
/* cdr was stored first */
scm_restore_cell_object (obj, 1, dstate);
scm_restore_cell_object (obj, 0, dstate);
scm_restore_object ((SCM *) &SCM_CDR (obj), dstate);
scm_restore_object ((SCM *) &SCM_CAR (obj), dstate);
goto store_object;
}
@ -510,22 +460,25 @@ scm_undump (SCM dstate)
case scm_tc7_symbol:
{
int len;
const char *mem = scm_restore_string (&len, dstate);
const char *mem;
scm_restore_string (&mem, &len, dstate);
obj = scm_mem2symbol (mem, len);
goto store_object;
}
case scm_tc7_string:
{
int len;
const char *mem = scm_restore_string (&len, dstate);
const char *mem;
scm_restore_string (&mem, &len, dstate);
obj = scm_makfromstr (mem, len, 0);
goto store_object;
}
case scm_tc7_vector:
{
int i;
int len = scm_restore_word (dstate);
scm_bits_t len;
SCM *base;
scm_restore_word (&len, dstate);
obj = scm_c_make_vector (len, SCM_BOOL_F);
base = SCM_VELTS (obj);
for (i = 0; i < len; i++)
@ -638,23 +591,13 @@ SCM_DEFINE (scm_binary_read, "binary-read", 0, 1, 0,
scm_undump (dstate);
/* Update references */
while (p->object_updates)
while (p->updates)
{
struct scm_dump_object_update *update = p->object_updates;
p->object_updates = update->next;
struct scm_dump_update *update = p->updates;
p->updates = update->next;
*(update->addr) = SCM_UNPACK (scm_indicator_object (update->id, dstate));
scm_must_free (update);
}
/* Link objects */
while (p->cell_updates)
{
struct scm_dump_cell_update *update = p->cell_updates;
p->cell_updates = update->next;
SCM_SET_CELL_OBJECT (update->cell,
update->n,
scm_indicator_object (update->id, dstate));
scm_must_free (update);
}
/* Return */
{

View file

@ -49,13 +49,11 @@ extern void scm_store_string (const char *addr, scm_sizet size, SCM dstate);
extern void scm_store_bytes (const void *addr, scm_sizet size, SCM dstate);
extern void scm_store_word (const scm_bits_t word, SCM dstate);
extern void scm_store_object (SCM obj, SCM dstate);
extern void scm_store_cell_object (SCM cell, int n, SCM dstate);
extern const char *scm_restore_string (scm_sizet *sizep, SCM dstate);
extern const void *scm_restore_bytes (scm_sizet size, SCM dstate);
extern scm_bits_t scm_restore_word (SCM dstate);
extern void scm_restore_string (const char **pp, scm_sizet *sizep, SCM dstate);
extern void scm_restore_bytes (const void **pp, scm_sizet size, SCM dstate);
extern void scm_restore_word (scm_bits_t *wordp, SCM dstate);
extern void scm_restore_object (SCM *objp, SCM dstate);
extern void scm_restore_cell_object (SCM cell, int n, SCM dstate);
extern SCM scm_binary_write (SCM obj, SCM port);
extern SCM scm_binary_read (SCM port);

View file

@ -81,8 +81,10 @@ static SCM
keyword_undump (SCM dstate)
{
int len;
const char *mem = scm_restore_string (&len, dstate);
SCM sym = scm_mem2symbol (mem, len);
const char *mem;
SCM sym;
scm_restore_string (&mem, &len, dstate);
sym = scm_mem2symbol (mem, len);
return scm_make_keyword_from_dash_symbol (sym);
}