17 #define bitref(vec,index) (((vec)->c.ivec.iv[(index)/64] >> ((index)%64)) & 1L)
18 #define bitset(vec,index,val) \
19 (val?((vec)->c.ivec.iv[(index)/64] |= (1L<<((index)%64))): \
20 ((vec)->c.ivec.iv[(index)/64] &= ~(1L<<((index)%64))))
21 #define MAX_SEQUENCE_COUNT 100000000
23 #define bitref(vec,index) (((vec)->c.ivec.iv[(index)/32] >> ((index)%32)) & 1)
24 #define bitset(vec,index,val) \
25 (val?((vec)->c.ivec.iv[(index)/32] |= (1<<((index)%32))): \
26 ((vec)->c.ivec.iv[(index)/32] &= ~(1<<((index)%32))))
27 #define MAX_SEQUENCE_COUNT 1000000
48 { vpush(arg1); vpush(arg2);
66 {
register byte *p=vec->c.str.chars;
71 switch(elmtypeof(vec)) {
72 case ELM_FOREIGN: p=vec->c.foreign.chars;
74 case ELM_INT: ival=vec->c.ivec.iv[
index];
75 return(mkbigint(ival));
82 case ELM_POINTER:
return(vec->c.vec.v[
index]);} }
89 switch(elmtypeof(vec)) {
92 case ELM_POINTER: pointer_update(vec->c.vec.v[
index],val);
return;
93 case ELM_CHAR:
case ELM_BYTE:
98 else vec->c.ivec.iv[
index/64] &= ~(1L<<
index%64);
102 else vec->c.ivec.iv[
index/32] &= ~(1<<
index%32);
105 case ELM_FOREIGN: p=vec->c.foreign.chars;
131 else if (islist(
a)) {
132 while (islist(
a) && i++<
s)
a=ccdr(
a);
137 if (!islist(
a))
break;
138 ckpush(ccar(
a));
a=ccdr(
a); i++;
s++;}}
139 else while (islist(
a)) { ckpush(ccar(
a));
a=ccdr(
a); i++;}
141 else if (isarray(
a)) {
150 switch(elmtypeof(
a)) {
155 case ELM_BYTE:
case ELM_CHAR:
157 memcpy(&r->c.str.chars[i], &
a->c.str.chars[
s],
count);
162 p=
a->c.foreign.chars;
163 memcpy(&r->c.str.chars[i], &p[
s],
count);
178 register int i=0,
s,k;
183 else if (islist(
a)) {
184 while (islist(
a)) { ckpush(ccar(
a));
a=ccdr(
a); i++;}
186 while (i-->0) r=
cons(ctx,vpop(),r);
188 else if (isarray(
a)) {
193 if (isvector(
a)) { k=vecsize(
a);
s=0;}
196 switch(elmtypeof(
a)) {
199 for (i=0; i<k;
s++, i++) bitset(r,i,bitref(
a,
s));
203 p=
a->c.foreign.chars;
206 case ELM_BYTE:
case ELM_CHAR:
226 else if (islist(
a)) {
227 while (islist(
a)) { r=
cons(ctx,ccar(
a),r);
a=ccdr(
a);}
229 else if (isarray(
a)) {
234 else if (isvector(
a)) { k=vecsize(
a);
s=0;}
238 switch(elmtypeof(
a)) {
239 case ELM_BIT:
for (i=0; i<k;
s++,i++) bitset(r,k-i-1,bitref(
a,
s));
242 case ELM_CHAR:
case ELM_BYTE:
243 for (i=0; i<k;
s++,i++) r->c.str.chars[k-i-1]=p[
s];
245 default: for (i=0; i<k;
s++,i++) pointer_update(r->c.vec.v[k-i-1],
a->c.vec.v[
s]);
258 else if (islist(
a)) {
260 while (islist(r)) { ckpush(ccar(r)); r=ccdr(r); i++;}
262 while (i>0) { pointer_update(ccar(r),vpop()); r=ccdr(r); i--;}
264 else if (isarray(
a)) {
269 else if (isvector(
a)) { k=vecsize(
a);
s=0;}
271 kk=k/2; vp=
a->c.vec.v;
273 switch(elmtypeof(
a)) {
275 for(i=0; i<kk; i++,
s++) {
278 #if (WORD_SIZE == 64)
279 if (y)
a->c.ivec.iv[
s/64] |= (1L<<(
s%64));
280 else a->c.ivec.iv[
s/64] &= ~(1L<<(
s%64));
281 if (x)
a->c.ivec.iv[(k-i-1)/64] |= (1L<<((k-i-1)%64));
282 else a->c.ivec.iv[(k-i-1)/64] &= ~(1L<<((k-i-1)%64));
284 if (y)
a->c.ivec.iv[
s/32] |= (1<<(
s%32));
285 else a->c.ivec.iv[
s/32] &= ~(1<<(
s%32));
286 if (x)
a->c.ivec.iv[(k-i-1)/32] |= (1<<((k-i-1)%32));
287 else a->c.ivec.iv[(k-i-1)/32] &= ~(1<<((k-i-1)%32));
291 case ELM_FOREIGN: cp=
a->c.foreign.chars;
292 case ELM_CHAR:
case ELM_BYTE:
293 for(i=0; i<kk; i++,
s++) {
294 x=cp[
s]; cp[
s]=cp[k-i-1]; cp[k-i-1]=x;}
298 for(i=0; i<kk; i++,
s++) {
299 r=vp[
s]; pointer_update(vp[
s],vp[k-i-1]); vp[k-i-1]=r;}
306 register int offset,
count;
311 if (
a==
NIL)
return(0);
312 else if (iscons(
a)) {
314 while (
count-->0 && iscons(
a)) { ckpush(ccar(
a));
a=ccdr(
a); len++;}
320 offset+=
intval(
a->c.ary.offset);
a=
a->c.ary.entity;}
322 i=0; len=vecsize(
a)-offset; len=
min(len,
count);
324 switch(elmtypeof(
a)) {
325 case ELM_FOREIGN: p=
a->c.foreign.chars;
326 case ELM_CHAR:
case ELM_BYTE:
while (i<len) ckpush(
makeint(p[offset+i++]));
328 case ELM_INT:
while (i<len) {
329 x=
a->c.ivec.iv[offset+i++];
332 case ELM_FLOAT:
while (i<len) ckpush(
makeflt(
a->c.fvec.fv[offset+i++]));
336 #if (WORD_SIZE == 64)
337 m= 1L<<((offset+i)%64);
338 b=
a->c.ivec.iv[(offset+i)/64] & m;
340 m= 1<<((offset+i)%32);
341 b=
a->c.ivec.iv[(offset+i)/32] & m;
346 case ELM_POINTER:
while (i<len) ckpush(
a->c.vec.v[offset+i++]);
363 pointer_update(x->
c.
cons.
car,vpop());
369 switch(elmtypeof(r)) {
372 case ELM_FLOAT:
while (--
n>=0) {
376 case ELM_POINTER:
while (--
n>=0) pointer_update(r->
c.
vec.
v[
n],vpop());
378 case ELM_CHAR:
case ELM_BYTE:
381 case ELM_BIT:
while (--
n>=0)
382 #if (WORD_SIZE == 64)
394 {
register int i,
argc=1,resultlen=0;
395 if (
n<=1)
return(
NIL);
410 offset=
intval(
a->c.ary.offset);
413 else { offset=0;
count=MAX_SEQUENCE_COUNT;}
422 register pointer seq=argv[0], item=argv[1];
429 start=ckintval(argv[2]);
end=ckintval(argv[3]);
431 while (i++<
start && islist(seq)) seq=ccdr(seq);
433 if (!iscons(seq))
break;
434 pointer_update(ccar(seq),item); seq=ccdr(seq);
437 else if (isvector(seq))
end=
min(
end,vecsize(seq));
438 else if (isarray(seq)) {
444 switch (elmtypeof(seq)) {
448 case ELM_FLOAT: fval=
ckfltval(item);
452 case ELM_CHAR:
case ELM_BYTE:
458 #if (WORD_SIZE == 64)
463 for (i=0; i<
count; i++)
471 for (i=0; i<
count; i++)
490 register pointer func=argv[1], argseq,r;
499 if (iscons(argseq)) {
500 ckpush(ccar(argseq));
501 argv[
argc+2]=ccdr(argseq);}
503 if (isarray(argseq)) {
505 offset=
intval(argseq->c.ary.offset);
506 argseq=argseq->c.ary.entity;}
508 if (isvector(argseq) && vecsize(argseq)>rcount+offset)
509 ckpush(
fastvref(argseq,rcount+offset));
510 else { ctx->vsp-=
argc;
goto makeresult;} }
517 if (isclass(argv[0]))
return(
makesequence(ctx,rcount,argv[0]));
518 else { ctx->vsp-=rcount;
return(
NIL);}}
524 {
register pointer item=argv[0],seq=argv[1],element;
525 pointer test=argv[2],testnot=argv[3],
key=argv[4];
526 pointer iftest=argv[5],ifnottest=argv[6];
530 start=ckintval(argv[7]);
end=ckintval(argv[8]);
count=ckintval(argv[9]);
532 if (seq==
NIL)
return(
NIL);
533 else if (islist(seq)) {
534 while (i++<
start && islist(seq)) seq=ccdr(seq);
535 if (!islist(seq))
return(
NIL);}
536 else if (isvector(seq))
end=
min(
end,vecsize(seq));
537 else if (isarray(seq)) {
539 seq=seq->c.ary.entity;
end=
min(
end,vecsize(seq));}
543 if (seq==
NIL)
return(
NIL);
544 else if (iscons(seq)) { element=ccar(seq); seq=ccdr(seq);}
547 if (ifnottest!=
NIL) {
549 else if (iftest!=
NIL) {
551 else if (testnot!=
NIL) {
553 else if (test!=
QEQ) {
563 {
register pointer item=argv[0],seq=argv[1],element,testelement;
564 pointer test=argv[2],testnot=argv[3],
key=argv[4];
565 pointer iftest=argv[5],ifnottest=argv[6];
569 start=ckintval(argv[7]);
end=ckintval(argv[8]);
571 if (seq==
NIL)
return(
NIL);
572 else if (islist(seq)) {
573 while (i++<
start && islist(seq)) seq=ccdr(seq);
574 if (!islist(seq))
return(
NIL);}
578 seq=seq->c.ary.entity;}
579 if (isvector(seq))
end=
min(
end,vecsize(seq));
583 if (seq==
NIL)
return(
NIL);
584 else if (iscons(seq)) { element=ccar(seq); seq=ccdr(seq);}
587 else testelement=element;
588 if (ifnottest!=
NIL) {
589 if (
call1(ctx,ifnottest,testelement)==
NIL)
return(element);}
590 else if (iftest!=
NIL) {
591 if (
call1(ctx,iftest,testelement)!=
NIL)
return(element);}
592 else if (testnot!=
NIL) {
593 if (
call2(ctx,testnot,item,testelement)==
NIL)
return(element);}
594 else if (test!=
QEQ) {
595 if (
call2(ctx,test,item,testelement)!=
NIL)
return(element);}
596 else if (item==testelement)
return(element);
604 {
register pointer item=argv[0],seq=argv[1],element,testelement;
605 pointer test=argv[2],testnot=argv[3],
key=argv[4];
606 pointer iftest=argv[5],ifnottest=argv[6];
610 start=ckintval(argv[7]);
end=ckintval(argv[8]);
613 else if (islist(seq)) {
614 while (i++<
start && islist(seq)) seq=ccdr(seq);
615 if (!islist(seq))
return(
NIL);}
619 seq=seq->c.ary.entity;}
620 if (isvector(seq))
end=
min(
end,vecsize(seq));
626 else if (iscons(seq)) { element=ccar(seq); seq=ccdr(seq);}
629 if (ifnottest!=
NIL) {
630 if (
call1(ctx,ifnottest,testelement)==
NIL) i++;}
631 else if (iftest!=
NIL) {
632 if (
call1(ctx,iftest,testelement)!=
NIL) i++;}
633 else if (testnot!=
NIL) {
634 if (
call2(ctx,testnot,item,testelement)==
NIL) i++;}
635 else if (test!=
QEQ) {
636 if (
call2(ctx,test,item,testelement)!=
NIL) i++;}
637 else if (item==testelement) i++;
645 {
pointer item=argv[0],seq=argv[1],test=argv[2],testnot=argv[3],
key=argv[4];
646 pointer iftest=argv[5],ifnottest=argv[6];
647 register pointer element,testelement;
651 start=ckintval(argv[7]);
end=ckintval(argv[8]);
count=ckintval(argv[9]);
652 if (seq==
NIL)
return(
NIL);
656 seq=seq->c.ary.entity;}
657 if (isvector(seq))
end=
min(
end,vecsize(seq));
661 while (start<end && count>0) {
662 if (iscons(seq)) { element=ccar(seq); seq=ccdr(seq);}
667 if (ifnottest!=
NIL) testresult=(
call1(ctx,ifnottest,testelement)==
NIL);
668 else if (iftest!=
NIL) testresult=(
call1(ctx,iftest,testelement)!=
NIL);
669 else if (testnot!=
NIL) testresult=(
call2(ctx,testnot,item,testelement)==
NIL);
670 else if (test!=
QEQ) testresult=(
call2(ctx,test,item,testelement)!=
NIL);
671 else testresult=(item==testelement);
672 if (testresult) {
count--;}
673 else { ckpush(element); pushcount++;}}
674 if (iscons(argv[1])) {
675 while (pushcount-->0) seq=
cons(ctx,vpop(),seq);
685 {
pointer seq=argv[0],test=argv[1],testnot=argv[2],
key=argv[3];
686 register pointer element,testelement,seq2,element2;
690 start=ckintval(argv[4]);
end=ckintval(argv[5]);
691 if (seq==
NIL)
return(
NIL);
692 if (isvector(seq))
end=
min(
end,vecsize(seq));
698 if (iscons(seq)) { element=ccar(seq); seq=ccdr(seq);}
703 i=
start; seq2=seq; testresult=0;
705 if (seq2==
NIL)
break;
706 else if (iscons(seq2)) { element2=ccar(seq2); seq2=ccdr(seq2); }
707 else if (isvector(seq2)) element2=
fastvref(seq2,i);
711 if (testnot!=
NIL) testresult=(
call2(ctx,testnot,testelement,element2)==
NIL);
712 else if (test!=
QEQ) testresult=(
call2(ctx,test,testelement,element2)!=
NIL);
713 else testresult=(testelement==element2);
714 if (testresult)
break;}
715 if (!testresult) {ckpush(element); pushcount++;} }
716 if (iscons(argv[0])) {
717 while (pushcount-->0) seq=
cons(ctx,vpop(),seq);
727 {
pointer item=argv[0],seq=argv[1],test=argv[2],testnot=argv[3],
key=argv[4];
728 pointer iftest=argv[5],ifnottest=argv[6];
729 register pointer element,testelement,result=seq,lastseq;
733 start=ckintval(argv[7]);
end=ckintval(argv[8]);
count=ckintval(argv[9]);
735 if (seq==
NIL)
return(
NIL);
738 seq=seq->c.ary.entity;}
739 if (isvector(seq))
end=
min(
end,vecsize(seq));
746 while (start<end && count>0) {
747 if (iscons(seq)) element=ccar(seq);
751 if (ifnottest!=
NIL) testresult=(
call1(ctx,ifnottest,testelement)==
NIL);
752 else if (iftest!=
NIL) testresult=(
call1(ctx,iftest,testelement)!=
NIL);
753 else if (testnot!=
NIL) testresult=(
call2(ctx,testnot,item,testelement)==
NIL);
754 else if (test!=
QEQ) testresult=(
call2(ctx,test,item,testelement)!=
NIL);
755 else testresult=(item==testelement);
756 if (iscons(result)) {
759 if (first) { result=ccdr(seq);}
760 else { ccdr(lastseq)=ccdr(seq); first=0;}}
761 else { lastseq = seq; first=0;}
763 else if (isvector(seq)) {
764 if (testresult) {
count--;}
777 {
pointer newitem=argv[0], olditem=argv[1], seq=argv[2];
778 pointer test=argv[3],testnot=argv[4],
key=argv[5];
779 pointer iftest=argv[6],ifnottest=argv[7];
780 register pointer element,testelement;
784 start=ckintval(argv[8]);
end=ckintval(argv[9]);
count=ckintval(argv[10]);
785 if (seq==
NIL)
return(
NIL);
788 seq=seq->c.ary.entity;}
789 if (isvector(seq))
end=
min(
end,vecsize(seq));
793 while (start<end && count>0) {
794 if (iscons(seq)) { element=ccar(seq); seq=ccdr(seq);}
799 if (ifnottest!=
NIL) testresult=(
call1(ctx,ifnottest,testelement)==
NIL);
800 else if (iftest!=
NIL) testresult=(
call1(ctx,iftest,testelement)!=
NIL);
801 else if (testnot!=
NIL) testresult=(
call2(ctx,testnot,olditem,testelement)==
NIL);
802 else if (test!=
QEQ) testresult=(
call2(ctx,test,olditem,testelement)!=
NIL);
803 else testresult=(olditem==testelement);
805 if (testresult) {
count--; ckpush(newitem);}
806 else { ckpush(element);}
808 if (iscons(argv[2])) {
809 while (pushcount-->0) seq=
cons(ctx,vpop(),seq);
819 {
pointer newitem=argv[0], olditem=argv[1], seq=argv[2];
820 pointer test=argv[3],testnot=argv[4],
key=argv[5];
821 pointer iftest=argv[6],ifnottest=argv[7];
822 register pointer element,testelement;
826 start=ckintval(argv[8]);
end=ckintval(argv[9]);
count=ckintval(argv[10]);
827 if (seq==
NIL)
return(
NIL);
830 seq=seq->c.ary.entity;}
831 if (isvector(seq))
end=
min(
end,vecsize(seq));
836 while (start<end && count>0) {
837 if (iscons(seq)) element=ccar(seq);
841 if (ifnottest!=
NIL) testresult=(
call1(ctx,ifnottest,testelement)==
NIL);
842 else if (iftest!=
NIL) testresult=(
call1(ctx,iftest,testelement)!=
NIL);
843 else if (testnot!=
NIL) testresult=(
call2(ctx,testnot,olditem,testelement)==
NIL);
844 else if (test!=
QEQ) testresult=(
call2(ctx,test,olditem,testelement)!=
NIL);
845 else testresult=(olditem==testelement);
848 if (iscons(seq)) {pointer_update(ccar(seq),newitem);}
851 if (iscons(seq)) seq=ccdr(seq);
862 {
register int i,
count;
864 register byte *p, *p2;
865 int srcelmt,destelmt;
870 dest=argv[0];
if (isarray(dest)) dest=dest->
c.
ary.
entity;
871 src=argv[1];
if (isarray(src)) src=src->
c.
ary.
entity;
873 ds=(
n==2)?0:ckintval(argv[2]);
874 de=(
n<=3)?vecsize(dest):ckintval(argv[3]);
875 ss=(
n<=4)?0:ckintval(argv[4]);
876 se=(
n<=5)?vecsize(src):ckintval(argv[5]);
880 srcelmt=elmtypeof(src);
881 destelmt=elmtypeof(dest);
882 if (srcelmt==ELM_BIT) {
883 #if (WORD_SIZE == 64)
884 if (destelmt==ELM_BIT && ss==0 && ds==0 && ((
count%64) == 0)) {
889 if (destelmt==ELM_BIT && ss==0 && ds==0 && ((
count%32) == 0)) {
894 else goto general_replace;}
895 if (srcelmt==destelmt ||
896 (srcelmt==ELM_BYTE || srcelmt==ELM_CHAR || srcelmt==ELM_FOREIGN) &&
897 (destelmt==ELM_BYTE || destelmt==ELM_CHAR || destelmt==ELM_FOREIGN)) {
899 if (srcelmt!=ELM_BYTE && srcelmt!=ELM_CHAR && srcelmt!=ELM_FOREIGN)
905 if (srcelmt==ELM_FOREIGN || destelmt==ELM_FOREIGN)
906 for (i=0; i<
count; i++) *p2++ = *p++;
907 else memcpy((
void *)p2, (
void *)p, (
size_t)
count);
917 case ELM_INT:
while (
count-->0)
920 case ELM_FLOAT:
while (
count-->0) {
924 case ELM_POINTER:
while (
count-->0) {--de;pointer_update(dest->
c.
vec.
v[de],vpop());}
926 case ELM_CHAR:
case ELM_BYTE:
case ELM_FOREIGN:
929 case ELM_BIT:
while (
count-->0) {
931 #if (WORD_SIZE == 64)
933 dest->
c.
ivec.
iv[de/64] |= 1L << (de%64);
934 else dest->
c.
ivec.
iv[de/64] &= ~(1L << (de%64));
937 dest->
c.
ivec.
iv[de/32] |= 1 << (de%32);
938 else dest->
c.
ivec.
iv[de/32] &= ~(1 << (de%32));
960 case ELM_CHAR:
case ELM_BYTE:
966 default: xx= *x; yy= *y;}
978 if (result==
NIL)
return(1);
else return(-1);}
986 register int i,width;
989 if (seq==
NIL)
return(
NIL);
1001 while (islist(work)) { ckpush(ccar(work)); work=ccdr(work);
n++;}
1005 for (i=0; i<
n; i++) { pointer_update(ccar(work),*xsp++); work=ccdr(work);}
1007 else if (isvector(seq)) {
1012 qsort(seq->
c.
vec.
v,vecsize(seq),width,(
int (*)())
compar);}
1027 else if (piscons(
a)) {
1029 while (islist(
a)) {
l++;
a=ccdr(
a);}
1031 else if (pisarray(
a)) {
1033 if (
a->c.ary.fillpointer==
NIL)
return(
a->c.ary.dim[0]);
1034 else return(
a->c.ary.fillpointer);}
1035 else if (elmtypeof(
a))
return(
a->c.vec.size);
1047 while (i-->0 && islist(
a))
a=ccdr(
a);
1048 if (islist(
a))
return(ccar(
a));
1051 else if (isarray(
a) &&
a->c.ary.rank==
makeint(1))
1064 while (i-->0 && islist(
a))
a=ccdr(
a);
1065 if (islist(
a)) {pointer_update(ccar(
a),argv[2]);
return(argv[2]);}
1067 else {
vset(
a,i,argv[2]);
return(argv[2]);}}