txlyre 5 月之前
父節點
當前提交
b8ce38a3c0
共有 1 個文件被更改,包括 74 次插入65 次删除
  1. 74 65
      jk.c

+ 74 - 65
jk.c

@@ -90,7 +90,7 @@ P li(Lst*list,SZ index){Z length;
   if(le(list))R NULL;
   if(index==0)R list->value;
   length=ll(list);
-  if(index<0)index +=((SZ)length);
+  if(index<0)index+=((SZ)length);
   if(index<0||index>=length)R NULL;
   for(Z i=0;i<((Z)index);i++)list=list->next;R list->value;}
 Lst*lp(Lst*list,P value){Lst*head=list;
@@ -113,7 +113,7 @@ P lP(Lst*list){if(le(list))R NULL;
     list=list->next;}
   R NULL;}
 P ls(Lst*list,SZ index,P value){Z length=ll(list);
-  if(index<0)index +=((SZ)length);
+  if(index<0)index+=((SZ)length);
   if(index==((SZ)length)){lp(list,value);R value;}
   if(index<0||index>=length)R NULL;
   for(Z i=0;i<((Z)index);i++)list=list->next;
@@ -121,7 +121,7 @@ P ls(Lst*list,SZ index,P value){Z length=ll(list);
 Lst*lI(Lst**list,SZ index,P value){Lst*head=*list;
   if(index==-1)R lp(head,value);
   Z length=ll(head);
-  if(index<0)index +=(SZ)length;
+  if(index<0)index+=(SZ)length;
   if(index<0||index>length)R NULL;
   if(index==-1)R lp(head,value);
   if(index==0){if(le(head))R lp(head,value);
@@ -138,7 +138,7 @@ Lst*lI(Lst**list,SZ index,P value){Lst*head=*list;
 Lst*ld(Lst**list,SZ index){Lst*head=*list;
   if(le(head))R NULL;
   Z length=ll(head);
-  if(index<0)index +=(SZ)length;
+  if(index<0)index+=(SZ)length;
   if(index<0||index>=length)R NULL;
   if(index==0){head->value=NULL;
     if(!head->next)R head;
@@ -260,87 +260,87 @@ static U64 MM86128(P key,const I len,U32 seed){const uint8_t*data=(const uint8_t
     k1*= c1;
     k1=ROTL32(k1,15);
     k1*= c2;
-    h1 ^= k1;
+    h1^=k1;
     h1=ROTL32(h1,19);
-    h1 += h2;
+    h1+=h2;
     h1=h1*5+0x561ccd1b;
     k2*= c2;
     k2=ROTL32(k2,16);
     k2*= c3;
-    h2 ^= k2;
+    h2^=k2;
     h2=ROTL32(h2,17);
-    h2 += h3;
+    h2+=h3;
     h2=h2*5+0x0bcaa747;
     k3*= c3;
     k3=ROTL32(k3,17);
     k3*= c4;
-    h3 ^= k3;
+    h3^=k3;
     h3=ROTL32(h3,15);
-    h3 += h4;
+    h3+=h4;
     h3=h3*5+0x96cd1c35;
     k4*= c4;
     k4=ROTL32(k4,18);
     k4*= c1;
-    h4 ^= k4;
+    h4^=k4;
     h4=ROTL32(h4,13);
-    h4 += h1;
+    h4+=h1;
     h4=h4*5+0x32ac3b17;}
   const uint8_t*tail=(const uint8_t*)(data+nblocks*16);
   U32 k1=0;
   U32 k2=0;
   U32 k3=0;
   U32 k4=0;
-  SW(len & 15){CS 15:k4 ^= tail[14] << 16;
-  CS 14:k4 ^= tail[13] << 8;
-  CS 13:k4 ^= tail[12] << 0;
+  SW(len & 15){CS 15:k4^=tail[14] << 16;
+  CS 14:k4^=tail[13] << 8;
+  CS 13:k4^=tail[12] << 0;
     k4*= c4;
     k4=ROTL32(k4,18);
     k4*= c1;
-    h4 ^= k4;
-  CS 12:k3 ^= tail[11] << 24;
-  CS 11:k3 ^= tail[10] << 16;
-  CS 10:k3 ^= tail[9] << 8;
-  CS 9:k3 ^= tail[8] << 0;
+    h4^=k4;
+  CS 12:k3^=tail[11] << 24;
+  CS 11:k3^=tail[10] << 16;
+  CS 10:k3^=tail[9] << 8;
+  CS 9:k3^=tail[8] << 0;
     k3*= c3;
     k3=ROTL32(k3,17);
     k3*= c4;
-    h3 ^= k3;
-  CS 8:k2 ^= tail[7] << 24;
-  CS 7:k2 ^= tail[6] << 16;
-  CS 6:k2 ^= tail[5] << 8;
-  CS 5:k2 ^= tail[4] << 0;
+    h3^=k3;
+  CS 8:k2^=tail[7] << 24;
+  CS 7:k2^=tail[6] << 16;
+  CS 6:k2^=tail[5] << 8;
+  CS 5:k2^=tail[4] << 0;
     k2*= c2;
     k2=ROTL32(k2,16);
     k2*= c3;
-    h2 ^= k2;
-  CS 4:k1 ^= tail[3] << 24;
-  CS 3:k1 ^= tail[2] << 16;
-  CS 2:k1 ^= tail[1] << 8;
-  CS 1:k1 ^= tail[0] << 0;
+    h2^=k2;
+  CS 4:k1^=tail[3] << 24;
+  CS 3:k1^=tail[2] << 16;
+  CS 2:k1^=tail[1] << 8;
+  CS 1:k1^=tail[0] << 0;
     k1*= c1;
     k1=ROTL32(k1,15);
     k1*= c2;
-    h1 ^= k1;}
-  h1 ^= len;
-  h2 ^= len;
-  h3 ^= len;
-  h4 ^= len;
-  h1 += h2;
-  h1 += h3;
-  h1 += h4;
-  h2 += h1;
-  h3 += h1;
-  h4 += h1;
+    h1^=k1;}
+  h1^=len;
+  h2^=len;
+  h3^=len;
+  h4^=len;
+  h1+=h2;
+  h1+=h3;
+  h1+=h4;
+  h2+=h1;
+  h3+=h1;
+  h4+=h1;
   FMIX32(h1);
   FMIX32(h2);
   FMIX32(h3);
   FMIX32(h4);
-  h1 += h2;
-  h1 += h3;
-  h1 += h4;
-  h2 += h1;
-  h3 += h1;
-  h4 += h1;R(((U64)h2)<< 32)| h1;}
+  h1+=h2;
+  h1+=h3;
+  h1+=h4;
+  h2+=h1;
+  h3+=h1;
+  h4+=h1;R(((U64)h2)<< 32)| h1;}
 static U32 HASH_SEED=0;
 P Tget(Tt*table,S key){if(Tempty(table))R NULL;
   U64 hash=MM86128(key,strlen(key),HASH_SEED);
@@ -459,12 +459,12 @@ B Vequals(Vt*x,Vt*y){if(xt!=yt)R F;
   CS CHAR:R x==y;
   CS NIL:CS UDF:BR;}
   R T;}
-B is_char_array(Lst*a){if(le(a))R F;
+B Cap(Lst*a){if(le(a))R F;
   WH(a){Vt*v=a->value;
     if(v->tag!=CHAR||!isprint(v->val._char))R F;
     a=a->next;}
   R T;}
-B is_arrays_array(Lst*a){if(le(a))R F;
+B Aap(Lst*a){if(le(a))R F;
   WH(a){Vt*v=a->value;
     if(v->tag!=ARRAY)R F;
     a=a->next;}
@@ -478,11 +478,11 @@ S show_array(Vt*v){if(v->tag!=ARRAY)R Vshow(v);
     S ts=Vshow(t->value);
     BappendS(buf,ts);
     FR(ts);R Bread(buf);}
-  if(is_char_array(t)){WH(t){Vt*c=t->value;
+  if(Cap(t)){WH(t){Vt*c=t->value;
       Bappend(buf,c->val._char);
       t=t->next;}
     R Bread(buf);}
-  if(!is_arrays_array(t)){WH(t){S ts=Vshow(t->value);
+  if(!Aap(t)){WH(t){S ts=Vshow(t->value);
       BappendS(buf,ts);
       FR(ts);
       t=t->next;
@@ -805,7 +805,7 @@ Vt*vobverse(St*st,vt*self,Vt*x,Vt*y){if(xt==VERB&&yt==VERB){vt*vx=xV;
   R st->udf;}
 Vt*vflip(St*st,vt*self,Vt*x){if(xt!=ARRAY||le(xa))R st->udf;
   Lst*t=xa;
-  if(!is_arrays_array(t))R st->udf;
+  if(!Aap(t))R st->udf;
   Lst*r=ln();
   Vt*c0=t->value;
   Lst*c0t=c0->val.array;
@@ -861,7 +861,7 @@ D nroot(D base,I n){if(n==1)R base;
   elif(n<=0||base<0)R NAN;
   else{D delta,x=base/n;
     do{delta=(base/npower(x,n-1)-x)/n;
-      x += delta;}WH(fabs(delta)>=1e-8);R x;}}
+      x+=delta;}WH(fabs(delta)>=1e-8);R x;}}
 Vt*vsqrt(St*st,vt*self,Vt*x){if(xt==NUM)R Vnn(sqrt(xn));R _NAN;}
 Vt*vroot(St*st,vt*self,Vt*x,Vt*y){if(xt==NUM&&yt==NUM)R Vnn(nroot(yn,xn));R _NAN;}
 Vt*vhalve(St*st,vt*self,Vt*x){if(xt==NUM)R Vnn(xn/2);R _NAN;}
@@ -915,13 +915,13 @@ Vt*vchunks(St*st,vt*self,Vt*x,Vt*y){if(xt!=NUM)R st->udf;
   Lst*r=ln();
   Z l=ll(ya);
   Z cl=fabs(xn);
-  for(Z i=0;i<l;i += cl)lp(r,vtake(st,NULL,Vnn(cl),vdrop(st,NULL,Vnn(i),y)));R Vna(r);}
+  for(Z i=0;i<l;i+=cl)lp(r,vtake(st,NULL,Vnn(cl),vdrop(st,NULL,Vnn(i),y)));R Vna(r);}
 Vt*vexp(St*st,vt*self,Vt*x){if(xt==NUM)R Vnn(exp(xn));R _NAN;}
 Vt*vpower(St*st,vt*self,Vt*x,Vt*y){if(xt==NUM&&yt==NUM)R Vnn(pow(xn,yn));R _NAN;}
 Vt*vnlog(St*st,vt*self,Vt*x){if(xt==NUM)R Vnn(log(xn));R _NAN;}
 Vt*vlog(St*st,vt*self,Vt*x,Vt*y){if(xt==NUM&&yt==NUM)R Vnn(log(yn)/log(xn));R _NAN;}
 I bits_needed(U32 value){I bits=0;
-  for(I bit_test=16;bit_test>0;bit_test >>= 1){if(value >> bit_test!=0){bits += bit_test;
+  for(I bit_test=16;bit_test>0;bit_test >>= 1){if(value >> bit_test!=0){bits+=bit_test;
       value >>= bit_test;}}
   R bits+value;}
 Vt*vbits(St*st,vt*self,Vt*x){if(xt==NUM){I n=xn;
@@ -935,7 +935,7 @@ Vt*vbase(St*st,vt*self,Vt*x,Vt*y){if(xt==NUM&&yt==NUM){Z v=fabs(yn);
     if(b<2)R st->udf;
     Lst*r=ln();
     WH(v>0){r=lI(&r,0,Vnn(v%b));
-      v /= b;}
+      v/=b;}
     R Vna(r);}
   R st->udf;}
 SZ indexOf(Lst*l,Vt*x){if(le(l))R -1;
@@ -1101,7 +1101,7 @@ Vt*vunbits(St*st,vt*self,Vt*x){if(xt!=ARRAY)x=venlist(st,NULL,x);
   I n=0;
   I i=0;
   Lst*t=xa;
-  WH(t){if(VTp(t->value))n |=(int)1 << i;
+  WH(t){if(VTp(t->value))n|=(int)1 << i;
     else n &= ~((int)1 << i);
     t=t->next;
     i++;}
@@ -1409,7 +1409,6 @@ Vt*vbin(St*st,vt*self,Vt*x,Vt*y){if(xt!=ARRAY)x=venlist(st,self,x);
     for(Z j=0;j<bl;j++){b=li(bins,j);
       D*s=b->value;
       D*e=b->next->value;
-      
       if(itv>=(*s)&&itv<(*e)){v=j;BR;}}
     if(!isnan(v))lp(r,Vnn(v));}
   WH(bins){Lst*tmp=bins->next;
@@ -1470,7 +1469,7 @@ Vt*vsymbol(St*st,vt*self,Vt*x){S s=Vshow(x);R Vny(s);}
 Vt*vapply1(St*st,vt*self,Vt*x,Vt*y){R apM(st,x,y);}
 Vt*vapply2(St*st,vt*self,Vt*x,Vt*y){if(yt!=ARRAY||le(ya)||!ya->next)R st->udf;R apD(st,x,ya->value,ya->next->value);}
 Vt*vshape(St*st,vt*self,Vt*x){if(xt!=ARRAY||le(xa))R st->unit;
-  if(!is_arrays_array(xa))R venlist(st,NULL,vcount(st,NULL,x));
+  if(!Aap(xa))R venlist(st,NULL,vcount(st,NULL,x));
   if(!xa->next)R venlist(st,NULL,vshape(st,NULL,xa->value));R venpair(st,NULL,vcount(st,NULL,x),vcount(st,NULL,xa->value));}
 Vt*vreshape(St*st,vt*self,Vt*x,Vt*y){if(yt!=ARRAY)y=venlist(st,NULL,y);
   elif(le(ya))R y;
@@ -1548,7 +1547,7 @@ U64 fibonacci(U64 n){U64 a=0;
   U64 b=1;
   WH(n-->1){U64 t=a;
     a=b;
-    b += t;}
+    b+=t;}
   R b;}
 Vt*vfibonacci(St*st,vt*self,Vt*x){if(xt==NUM)R Vnn(fibonacci((U64)fabs(xn)));R _NAN;}
 Vt*viota(St*st,vt*self,Vt*x){if(Vequals(x,NUMS[1]))R venlist(st,NULL,NUMS[1]);
@@ -1577,7 +1576,17 @@ Vt*vroll(St*st,vt*self,Vt*x,Vt*y){if(xt==NUM&&yt==NUM){Lst*r=ln();
 Vt*vtype(St*st,vt*self,Vt*x){R NUMS[xt];}
 Vt*vcast(St*st,vt*self,Vt*x,Vt*y){if(xt==NUM){I t=fabs(xn);
     if(yt==t)R y;
-    SW(t){CS NUM:if(yt==CHAR)R Vnn(y->val._char);BR;
+    SW(t){CS ARRAY:if(yt==SYM){S s=yY;
+        Lst*r=ln();
+        WH(*s)lp(r,Vnc(*s++));R Vna(r);}BR;
+    CS NUM:if(yt==CHAR)R Vnn(y->val._char);
+      elif(yt==ARRAY&&Cap(ya)){Bt*buf=Bnew();
+        Lst*t=ya;
+        WH(t){Bappend(buf,((Vt*)t->value)->val._char);
+          t=t->next;}
+        S s=Bread(buf);
+        D r=strtod(s,NULL);
+        FR(s);R Vnn(r);}BR;
     CS CHAR:if(yt==NUM)R Vnc(yn);BR;}}
   R st->udf;}
 Vt*vprint(St*st,vt*self,Vt*x){S s=Vshow(x);
@@ -1643,7 +1652,7 @@ Vt*vsystem(St*st,vt*self,Vt*x){S cmd=Vshow(x);
   LOOP{bytes_received=fread(chunk,1,1024,pd);
     if(bytes_received==0)BR;
     Z head=Bsize;
-    Bsize += bytes_received;
+    Bsize+=bytes_received;
     if(Bsize>Ballocated){Ballocated=Bsize;
       if(!buffer)buffer=ma(Ballocated);
       else buffer=mrea(buffer,Ballocated);     
@@ -1725,7 +1734,7 @@ Vt*vsystem2(St*st,vt*self,Vt*x,Vt*y){S cmd=Vshow(y);
   LOOP{bytes_received=fread(chunk,1,1024,pd->out);
     if(bytes_received==0)BR;
     Z head=Bsize;
-    Bsize += bytes_received;
+    Bsize+=bytes_received;
     if(Bsize>Ballocated){Ballocated=Bsize;
       if(!buffer)buffer=ma(Ballocated);
       else buffer=mrea(buffer,Ballocated);     
@@ -1747,7 +1756,7 @@ Vt*vbnot(St*st,vt*self,Vt*x){if(xt==NUM)R Vnn(~(int)xn);R _NAN;}
 Lst*prime_factors(D n){Lst*factors=ln();
   D divisor=2;
   WH(n>=2){if(fmod(n,divisor)==0){lp(factors,Vnn(divisor));
-      n /= divisor;}else divisor++;}
+      n/=divisor;}else divisor++;}
   R factors;}
 Vt*vfactors(St*st,vt*self,Vt*x){if(xt==NUM&&!is_bad_num(xn))R Vna(prime_factors(xn));R st->udf;}
 Vt*vcombine(St*st,vt*self,Vt*x,Vt*y){if(xt==NUM&&yt==NUM&&!is_bad_num(xn)&&!is_bad_num(yn)){Vt*n=venpair(st,NULL,x,y);R vunbase(st,NULL,NUMS[10],n);}
@@ -2170,7 +2179,7 @@ Nt*_PPnoun(Pt*parser){Nt*n;
   Nt*a=PPatom(parser);
   if(a->tag==N_LITERAL&&a->v->tag==NUM &&(n=PPa(parser,a,T_NUM)))R n;
   elif(a->tag==N_LITERAL&&a->v->tag==SYM &&(n=PPa(parser,a,T_NAME)))R n;
-  elif(a->tag==N_LITERAL&&a->v->tag==ARRAY &&is_char_array(a->v->val.array)&&(n=PPa(parser,a,T_QUOTE)))R n;R a;}
+  elif(a->tag==N_LITERAL&&a->v->tag==ARRAY &&Cap(a->v->val.array)&&(n=PPa(parser,a,T_QUOTE)))R n;R a;}
 Nt*PPnoun(Pt*parser,B flat){Nt*a=flat?PPatom(parser):_PPnoun(parser);
   Tkt*tok;
   if((tok=Plook(parser,0))&&tok->tag==T_PUNCT &&strcmp(tok->text,",:")==0){Peat(parser);