23 static LISP bashnum =
NIL;
25 static LISP array_gc_relocate(LISP ptr)
29 memcpy(nw,ptr,
sizeof(
struct obj));
32 static void array_gc_scan(LISP ptr)
35 for(j=0;j < ptr->storage_as.lisp_array.dim; ++j)
36 ptr->storage_as.lisp_array.data[j] =
39 static LISP array_gc_mark(LISP ptr)
42 for(j=0;j < ptr->storage_as.lisp_array.dim; ++j)
43 gc_mark(ptr->storage_as.lisp_array.data[j]);
46 static
void array_gc_free(LISP ptr)
49 wfree(ptr->storage_as.string.data);
52 wfree(ptr->storage_as.double_array.data);
55 wfree(ptr->storage_as.long_array.data);
58 wfree(ptr->storage_as.lisp_array.data);
61 static void array_prin1(LISP ptr,FILE *
f)
66 fput_st(f,ptr->storage_as.string.data);
71 for(j=0; j < ptr->storage_as.double_array.dim; ++j)
72 {sprintf(
tkbuffer,
"%g",ptr->storage_as.double_array.data[j]);
74 if ((j + 1) < ptr->storage_as.double_array.dim)
80 for(j=0; j < ptr->storage_as.long_array.dim; ++j)
81 {sprintf(
tkbuffer,
"%ld",ptr->storage_as.long_array.data[j]);
83 if ((j + 1) < ptr->storage_as.long_array.dim)
89 for(j=0; j < ptr->storage_as.lisp_array.dim; ++j)
90 {
lprin1f(ptr->storage_as.lisp_array.data[j],f);
91 if ((j + 1) < ptr->storage_as.lisp_array.dim)
96 static LISP aref1(LISP a,LISP i)
100 if (k < 0)
err("negative
index to aref",i);
103 if (k >= a->storage_as.string.dim)
err(
"index too large",i);
104 return(
flocons((
double) a->storage_as.string.data[k]));
106 if (k >= a->storage_as.double_array.dim)
err(
"index too large",i);
107 return(
flocons(a->storage_as.double_array.data[k]));
109 if (k >= a->storage_as.long_array.dim)
err(
"index too large",i);
110 return(
flocons(a->storage_as.long_array.data[k]));
112 if (k >= a->storage_as.lisp_array.dim)
err(
"index too large",i);
113 return(a->storage_as.lisp_array.data[k]);
115 err(
"invalid argument to aref",a);}}
117 static void err1_aset1(LISP i)
118 {
err(
"index to aset too large",i);}
120 static void err2_aset1(LISP v)
121 {
err(
"bad value to store in array",v);}
123 static LISP aset1(LISP a,LISP i,LISP v)
127 if (k < 0)
err("negative
index to aset",i);
131 if (k >= a->storage_as.
string.dim) err1_aset1(i);
132 a->storage_as.
string.data[k] = (
char)
FLONM(v);
136 if (k >= a->storage_as.double_array.dim) err1_aset1(i);
137 a->storage_as.double_array.data[k] =
FLONM(v);
141 if (k >= a->storage_as.long_array.dim) err1_aset1(i);
142 a->storage_as.long_array.data[k] = (
long)
FLONM(v);
145 if (k >= a->storage_as.lisp_array.dim) err1_aset1(i);
146 a->storage_as.lisp_array.data[k] = v;
149 err("invalid argument to aset",a);}}
151 static LISP cons_array(LISP dim,LISP kind)
155 err(
"bad dimension to cons-array",dim);
157 n = (long)
FLONM(dim);
162 a->storage_as.double_array.dim = n;
163 a->storage_as.double_array.data = (
double *)
must_malloc(n *
165 for(j=0;j<n;++j) a->storage_as.double_array.data[j] = 0.0;}
168 a->storage_as.long_array.dim = n;
169 a->storage_as.long_array.data = (
long *)
must_malloc(n *
sizeof(
long));
170 for(j=0;j<n;++j) a->storage_as.long_array.data[j] = 0;}
173 a->storage_as.double_array.dim = n+1;
174 a->storage_as.string.data = (
char *)
must_malloc(n+1);
175 a->storage_as.string.data[n] = 0;
176 for(j=0;j<n;++j) a->storage_as.string.data[j] =
' ';}
179 a->storage_as.lisp_array.dim = n;
180 a->storage_as.lisp_array.data = (LISP *)
must_malloc(n *
sizeof(LISP));
181 for(j=0;j<n;++j) a->storage_as.lisp_array.data[j] = NIL;}
183 err(
"bad type of array",kind);
187 #define HASH_COMBINE(_h1,_h2,_mod) ((((_h1) * 17 + 1) ^ (_h2)) % (_mod)) 189 static long c_sxhash(LISP
obj,
long n)
206 for(hash=0,s=(
unsigned char *)
PNAME(obj);*s;++s)
217 for(hash=0,s=(
unsigned char *) obj->storage_as.subr.name;*s;++s)
221 return(((
unsigned long)
FLONM(obj)) % n);
229 static LISP sxhash(LISP
obj,LISP n)
232 static LISP array_equal(LISP a,LISP b)
236 len = a->storage_as.string.dim;
237 if (len != b->storage_as.string.dim)
return(NIL);
238 if (memcmp(a->storage_as.string.data,b->storage_as.string.data,len) == 0)
243 len = a->storage_as.long_array.dim;
244 if (len != b->storage_as.long_array.dim)
return(NIL);
245 if (memcmp(a->storage_as.long_array.data,
246 b->storage_as.long_array.data,
247 len *
sizeof(
long)) == 0)
252 len = a->storage_as.double_array.dim;
253 if (len != b->storage_as.double_array.dim)
return(NIL);
255 if (a->storage_as.double_array.data[j] !=
256 b->storage_as.double_array.data[j])
260 len = a->storage_as.lisp_array.dim;
261 if (len != b->storage_as.lisp_array.dim)
return(NIL);
263 if NULLP(
equal(a->storage_as.lisp_array.data[j],
264 b->storage_as.lisp_array.data[j]))
270 static long array_sxhash(LISP a,
long n)
272 unsigned char *char_data;
273 unsigned long *long_data;
277 len = a->storage_as.string.dim;
278 for(j=0,hash=0,char_data=(
unsigned char *)a->storage_as.string.data;
284 len = a->storage_as.long_array.dim;
285 for(j=0,hash=0,long_data=(
unsigned long *)a->storage_as.long_array.data;
291 len = a->storage_as.double_array.dim;
292 for(j=0,hash=0,double_data=a->storage_as.double_array.data;
295 hash =
HASH_COMBINE(hash,(
unsigned long)*double_data % n,n);
298 len = a->storage_as.lisp_array.dim;
299 for(j=0,hash=0; j < len; ++j)
301 c_sxhash(a->storage_as.lisp_array.data[j],n),
308 static long href_index(LISP table,LISP key)
311 index =
c_sxhash(key,table->storage_as.lisp_array.dim);
312 if ((index < 0) || (index >= table->storage_as.lisp_array.dim))
313 {
err(
"sxhash inconsistency",table);
318 static LISP href(LISP table,LISP key)
320 table->storage_as.lisp_array.data[href_index(table,key)])));}
322 static LISP hset(LISP table,LISP key,LISP value)
325 index = href_index(table,key);
326 l = table->storage_as.lisp_array.data[
index];
328 return(
setcdr(cell,value));
329 cell =
cons(key,value);
330 table->storage_as.lisp_array.data[
index] =
cons(cell,l);
333 static LISP make_list(LISP x,LISP v)
339 {l =
cons(v,l); --n;}
342 static void put_long(
long i,FILE *f)
343 {
if (fwrite(&i,
sizeof(
long),1,f) != 1)
344 cerr <<
"Could not put long to file" << endl;
347 static long get_long(FILE *f)
349 if (fread(&i,
sizeof(
long),1,f) != 1)
350 cerr <<
"Could not get long" << endl;
353 static long fast_print_table(LISP obj,LISP table)
359 index = href(ht,obj);
367 FLONM(bashnum) = 1.0;
393 for(tmp=obj;
CONSP(tmp);tmp=
CDR(tmp))
398 for(tmp=obj;
CONSP(tmp);tmp=
CDR(tmp))
404 fwrite(&obj->storage_as.flonum.data,
405 sizeof(obj->storage_as.flonum.data),
410 if (fast_print_table(obj,table))
412 len = strlen(
PNAME(obj));
414 err(
"symbol name too long",obj);
416 fwrite(
PNAME(obj),len,1,f);
425 err(
"cannot fast-print",obj);}}
435 if (c == EOF)
return(table);
439 FLONM(bashnum) = len;
440 return(href(
car(
cdr(table)),bashnum));
454 FLONM(bashnum) = len;
455 l = make_list(bashnum,NIL);
467 if (fread(&tmp->storage_as.flonum.data,
468 sizeof(tmp->storage_as.flonum.data),
471 cerr <<
"Could not read float from file" << endl;
476 err(
"symbol name too long",NIL);
478 cerr <<
"Could not read symbol" << endl;
488 static LISP array_fast_print(LISP ptr,LISP table)
495 len = ptr->storage_as.string.dim;
497 fwrite(ptr->storage_as.string.data,len,1,f);
501 len = ptr->storage_as.double_array.dim *
sizeof(double);
503 fwrite(ptr->storage_as.double_array.data,len,1,f);
507 len = ptr->storage_as.long_array.dim *
sizeof(long);
509 fwrite(ptr->storage_as.long_array.data,len,1,f);
513 len = ptr->storage_as.lisp_array.dim;
515 for(j=0; j < len; ++j)
516 fast_print(ptr->storage_as.lisp_array.data[j],table);
521 static LISP array_fast_read(
int code,LISP table)
530 if (fread(ptr->storage_as.string.data,len,1,f) != 1)
531 cerr <<
"Could not read string" << endl;
532 ptr->storage_as.string.data[len] = 0;
538 ptr->storage_as.double_array.dim = len;
539 ptr->storage_as.double_array.data =
541 if (fread(ptr->storage_as.double_array.data,
sizeof(
double),len,f) != (
long unsigned)len)
542 cerr <<
"Could not read double array" << endl;
549 ptr->storage_as.long_array.dim = len;
550 ptr->storage_as.long_array.data =
552 if (fread(ptr->storage_as.long_array.data,
sizeof(
long),len,f) != (
long unsigned) len)
553 cerr <<
"Could not read long array" << endl;
558 FLONM(bashnum) = len;
559 ptr = cons_array(bashnum,NIL);
560 for(j=0; j < len; ++j)
561 ptr->storage_as.lisp_array.data[j] =
fast_read(table);
566 static void init_storage_xtr1(
long type)
581 p->
equal = array_equal;
584 static void init_storage_xtr(
void)
598 "(aref ARRAY INDEX)\n\ 599 Return ARRAY[INDEX]");
601 "(aset ARRAY INDEX VAL)\n\ 602 Set ARRAY[INDEX] = VAL");
604 "(cons-array DIM KIND)\n\ 605 Construct array of size DIM and type KIND. Where KIND may be one of\n\ 606 double, long, string or lisp.");
609 Return hashing value for OBJ, in range n.");
612 Return value in hash table TABLE with KEY.");
614 "(hset TABLE KEY VALUE)\n\ 615 Set hash table TABLE KEY to VALUE.");
617 "(fast-read TABLE)\n\ 620 "(fast-print P TABLE)\n\ 623 "(make-list SIZE VALUE)\n\ 624 Return list of SIZE with each member VALUE.");
LISP(* fast_print)(LISP, LISP)
#define INTERRUPT_CHECK()
long int get_c_int(LISP x)
#define STACK_CHECK(_ptr)
#define HASH_COMBINE(_h1, _h2, _mod)
void init_subr_2(const char *name, LISP(*fcn)(LISP, LISP), const char *doc)
LISP strcons(long length, const char *data)
void set_print_hooks(long type, void(*prin1)(LISP, FILE *), void(*print_string)(LISP, char *))
int index(EST_TList< T > &l, T &val, bool(*eq)(const EST_UItem *, const EST_UItem *)=NULL)
LISP setcdr(LISP cell, LISP value)
FILE * get_c_file(LISP p, FILE *deflt)
void err(const char *message, LISP x) EST_NORETURN
void errswitch(void) EST_NORETURN
LISP(* equal)(LISP, LISP)
LISP cintern(const char *name)
LISP cons(LISP x, LISP y)
void fput_st(FILE *f, const char *st)
void init_subrs_xtr(void)
LISP assoc(LISP x, LISP alist)
void init_subr_1(const char *name, LISP(*fcn)(LISP), const char *doc)
long no_interrupt(long n)
LISP setcar(LISP cell, LISP value)
LISP(* fast_read)(int, LISP)
void init_subr_3(const char *name, LISP(*fcn)(LISP, LISP, LISP), const char *doc)
LISP rintern(const char *name)
char * must_malloc(unsigned long size)
struct user_type_hooks * get_user_type_hooks(long type)
void gc_fatal_error(void)
void gc_protect(LISP *location)
LISP lprin1f(LISP exp, FILE *f)
void set_gc_hooks(long type, int gc_free_once, LISP(*rel)(LISP), LISP(*mark)(LISP), void(*scan)(LISP), void(*free)(LISP), void(*clear)(LISP), long *kind)
long(* c_sxhash)(LISP, long)