more exo stuff.

This commit is contained in:
Vitor Santos Costa 2013-05-01 11:34:55 -05:00
parent 923be33404
commit 34bf9bb311
2 changed files with 14 additions and 13 deletions

21
C/exo.c
View File

@ -222,7 +222,7 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
UInt ncls = ap->cs.p_code.NOfClauses, j; UInt ncls = ap->cs.p_code.NOfClauses, j;
CELL *base = NULL; CELL *base = NULL;
struct index_t *i; struct index_t *i;
size_t sz; size_t sz, dsz;
yamop *ptr; yamop *ptr;
UInt *bnds = LOCAL_ibnds; UInt *bnds = LOCAL_ibnds;
@ -244,21 +244,22 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
i->bmap = bmap; i->bmap = bmap;
i->is_key = FALSE; i->is_key = FALSE;
i->hsize = 2*ncls; i->hsize = 2*ncls;
dsz = sizeof(BITS32)*(ncls+i->hsize);
if (count) { if (count) {
if (!(base = (CELL *)Yap_AllocCodeSpace(sizeof(BITS32)*(ncls+i->hsize)))) { if (!(base = (CELL *)Yap_AllocCodeSpace(dsz))) {
CACHE_REGS CACHE_REGS
save_machine_regs(); save_machine_regs();
LOCAL_Error_Size = sizeof(CELL)*(ncls+i->hsize); LOCAL_Error_Size = dsz;
LOCAL_ErrorMessage = "not enough space to generate indices"; LOCAL_ErrorMessage = "not enough space to generate indices";
Yap_FreeCodeSpace((void *)i); Yap_FreeCodeSpace((void *)i);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage); Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return NULL; return NULL;
} }
bzero(base, sizeof(CELL)*(ncls+i->hsize)); bzero(base, dsz);
} }
i->size = sizeof(CELL)*(ncls+i->hsize)+sz+sizeof(struct index_t); i->size = sz+dsz+sizeof(struct index_t);
i->key = (CELL *)base; i->key = (BITS32 *)base;
i->links = (CELL *)(base+i->hsize); i->links = (BITS32 *)(base+i->hsize);
i->ncollisions = i->nentries = i->ntrys = 0; i->ncollisions = i->nentries = i->ntrys = 0;
i->cls = (CELL *)((ADDR)ap->cs.p_code.FirstClause+2*sizeof(struct index_t *)); i->cls = (CELL *)((ADDR)ap->cs.p_code.FirstClause+2*sizeof(struct index_t *));
*ip = i; *ip = i;
@ -271,7 +272,7 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
} else { } else {
sz = (ncls+i->hsize)*sizeof(BITS32); sz = (ncls+i->hsize)*sizeof(BITS32);
} }
if (base != realloc(base, sz)) if (base != (CELL *)Yap_ReallocCodeSpace((char *)base, sz))
return FALSE; return FALSE;
bzero(base, sz); bzero(base, sz);
i->key = (CELL *)base; i->key = (CELL *)base;
@ -284,7 +285,7 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
#endif #endif
if (!i->ntrys && !i->is_key) { if (!i->ntrys && !i->is_key) {
i->is_key = TRUE; i->is_key = TRUE;
if (base != realloc(base, i->hsize*sizeof(BITS32))) if (base != (CELL *)Yap_ReallocCodeSpace((char *)base, i->hsize*sizeof(BITS32)))
return FALSE; return FALSE;
} }
/* our hash table is just too large */ /* our hash table is just too large */
@ -296,7 +297,7 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
} else { } else {
sz = (ncls+i->hsize)*sizeof(BITS32); sz = (ncls+i->hsize)*sizeof(BITS32);
} }
if (base != realloc(base, sz)) if (base != (CELL *)Yap_ReallocCodeSpace((char *)base, sz))
return FALSE; return FALSE;
bzero(base, sz); bzero(base, sz);
i->key = (CELL *)base; i->key = (CELL *)base;

View File

@ -79,7 +79,7 @@ compare(const BITS32 *ip, Int j USES_REGS) {
/* handle ll variables */ /* handle ll variables */
sz = sizeof(BITS32)*(ncls); sz = sizeof(BITS32)*(ncls);
/* allocate space */ /* allocate space */
if (!(it->udi_data = malloc(sz))) if (!(it->udi_data = (BITS32*)Yap_AllocCodeSpace(sz)))
return; return;
sorted = (BITS32*)it->udi_data; sorted = (BITS32*)it->udi_data;
for (i=0; i< ncls; i++) for (i=0; i< ncls; i++)
@ -92,7 +92,7 @@ compare(const BITS32 *ip, Int j USES_REGS) {
/* be conservative */ /* be conservative */
sz = sizeof(BITS32)*(2*it->ntrys+it->nentries); sz = sizeof(BITS32)*(2*it->ntrys+it->nentries);
/* allocate space */ /* allocate space */
if (!(it->udi_data = malloc(sz))) if (!(it->udi_data = (BITS32*)Yap_AllocCodeSpace(sz)))
return; return;
sorted0 = sorted = (BITS32 *)it->udi_data; sorted0 = sorted = (BITS32 *)it->udi_data;
sorted++; /* leave an initial hole */ sorted++; /* leave an initial hole */
@ -120,7 +120,7 @@ compare(const BITS32 *ip, Int j USES_REGS) {
} }
} }
sz = sizeof(BITS32)*(sorted-sorted0); sz = sizeof(BITS32)*(sorted-sorted0);
it->udi_data = (BITS32 *)realloc(it->udi_data, sz); it->udi_data = (BITS32 *)Yap_ReallocCodeSpace((char *)it->udi_data, sz);
} }
it->is_udi = i+1; it->is_udi = i+1;
code = it->code; code = it->code;