You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

98 lines
6.7 KiB

#include"a.h" // ngn/k, (c) 2019-2021 ngn, GNU AGPLv3 - https://codeberg.org/ngn/k/raw/branch/master/LICENSE
S A1(sam,x)S A2(com,AK(yK,AT(tq,a2(x,y))))VS;OC Tz[]={Tzv},TZ[]={TZv},TT[]={TTv},TX[]={TXv},Tk[]={Tkv};
A1(mkn,XmMA(eac1f(x,mkn))Ay=_R(cn[xt]);Xt(x(y))rsh(xN,x(y)))I _K(Ax/*0*/)_(xtu||xtw?1:xtv?2:xte?x>>48&7:xtF?xk:0) //_K:arity
A2(id_,/*00*/x==CAT?_R(ce[ce[yt]?yt:tA]):xtv&&xv<11&&xv?_R(ci[ytdD][T((C)4,0,0,1,1,2,2,3,3,2,4)[xv]]):mkn(fir(yR)))
AX(prj,XmMA(x8(a,n))Ik=max(n,xK);i(n,k-=a[i]!=PLH)
x=(xtp?val:a1)(xR);Ii=0,j=1;W(i<n&&j<xn,I(xA[j]==PLH,xA[j]=a[i++])j++)W(i<n,xq(a[i++]))P(xn>9,ez1(x))AT(tp,AK(k,x)))
AAL(ii,/*0*/XA(_R(xa))XC(ac(xc))XB(ai(xb))XH(ai(xh))XI(ai(xi))XL(al(xl))XD(ad(xd))XS(as(xi))Xm(ii(xy,i))
XM(Ay=xy,z=aA(yn);Q(ytA);j(zn,zA[j]=ii(yA[j],i))am(_R(xx),sqz(z)))xR)
S AAL(io,/*0*/xtt||in(i,xN)?ii(x,i):xN?mkn(ii(x,0)):xtm?io(xy,i):_R(cn[xt]))A1(fir,x(io(x,0)))A1(las,x(io(x,xN-1)))
#define G(T,U) (32/(SZ(T)>SZ(U)?SZ(T):SZ(U)))
#define iF(f,T,U,R,e...) S L f(OV*RE a,Lm,OV*RE b,V*RE c,Nn)_(O T*p=a;O U*q=b;R*r=c;LN(p)LN(q)LN(r)e;n)
#define iC_(U) iF( iC##U,C,U,C,i(PD(n,q),r[i]=in(q[i],m)?p[q[i]]:32))
#define iS_(U) iF( iS##U,I,U,I,i(PD(n,q),Iv=in(q[i],m);r[i]=v*p[v*q[i]]))
#define iD_(U) iF( iD##U,D,U,D,i(n,r[i]=in(q[i],m)?p[q[i]]:ND))
#define j_(T,U)iF(j##T##U,T,U,L,i(n,r[i]=in(q[i],m)?p[q[i]]:NL))
#define i_(T,U)iF(i##T##U,T,U,T,UI g=G(T,U);U k[g];\
i(n/g,j(g,k[j]=q[j])U o=0;j(g,o|=!in(k[j],m))P(o,i*g)j(g,r[j]=p[k[j]])q+=g;r+=g)\
L l=n/g*g;j(n-l,P(!in(q[j],m),l))j(n-l,r[j]=p[q[j]]))
iC_(I)iC_(L)i_(B,I)j_(B,I)i_(B,L)j_(B,L)i_(H,I)j_(H,I)i_(H,L)j_(H,L)i_(I,I)j_(I,I)i_(I,L)j_(I,L)j_(L,I)j_(L,L)
iD_(I)iD_(L)iS_(I)iS_(L)
S A2(i1,/*01*/
Xt(y(xR))
P(y==PLH||y==au,xR)
P(xtm||xtM&&ytsS,i1(xy,N(fnd(_R(xx),y))))
Yzc(io(x,gl(y)))
Yt(et1(y))
YmM(Az=kv(&y);am(y,Ny(i1(x,z))))
YA(ear2(xR,y,AP1))
I(!ytL&&!ytI,y=N(cI(y)))
Nn=yn;P(xtA||xtM,Az=oA;I(ytL,i(n,zq(io(x,yl))))E(i(n,zq(io(x,yi))))y(z))
Az=xtL&&ytL&&yr==1?y:an(xt,n);
Lm=T(&iBI,iHI,iII,jLI,iDI,iCI,iSI,iBL,iHL,iIL,jLL,iDL,iCL,iSL)[xt-tB+7*ytL](xV,xn,yV,zV,n);
I(m<n,z=z(aL(n));T(&jBI,jHI,jII,jBL,jHL,jIL)[xt-tB+3*ytL](xV,xn,yV,zV,n))
y-z?y(z):z)
S A3(i2,/*011*/Cb=ytT||y==PLH||y==au;x=Nz(i1(x,y));P(!b,x(i1(x,z)))K(".\\:",x,a1(z)))
S AX(i8,Ay=*a;P(n==1,i1(x,y))P(n==2,i2(x,y,a[1]))
a++;n--;Cb=ytT||y==PLH||y==au;x=i1(x,y);P(!n,x)P(!x,mrn(n,a);x)P(!b,x(i8(x,a,n)))K(".\\:",x,aV(tA,n,a)))
S A1(qt,x(al(now())))
S A1(qer,XC(x=str0(x);e1(x,xV))e1(x,"err"))
S A1(qar,Ay=oA;Q*p=argv;W(*p,yq(aCz(*p++)))ap1(y,x))
S A1(qen,Ay=oS,z=oA;Q*e=env;W(*e,Qp=*e++,q=p+si(p,'=');yq(cS(aCm(p,q)));zq(aCz(q+!!*q)))y=am(y,z);x-au?ap1(y,x):y)
S A1(qex,exit(xtz?gl(x):1);0)
S A1(qr,x(ai(xr)))
S A1(qjs,XC(Cb[ZP];In=js_eval(xC,xn,b,SZ b);x(0);aCn(b,n))XA(eac1f(x,qjs))et1(x))
S A1(qp,XC(x=str0(x);x(pk(xV)))et1(x))
A2(_1,/*01*/P(!xtt,i1(x,y))Xz(dex(Ny(v1c(xR,y)),x))
Xs(S O C s[][4]={"","k","j","p","t","x","hex","err","epr","argv","env","exit","js","prng","sin","cos","exp","ln","r"};
Li=fI(s,ZZ(s),xv);T(&ser,kst,js1,qp,qt,frk,hex,qer,epr,qar,qen,qex,qjs,prng,ksin,kcos,kexp,klog,qr,ed1)[i<0?ZZ(s):i](y))
Ik=xK;P(1<k,prj(x,&y,1))Xo(run(x,&y,1))Xv(en1(y))Xr(adv(x,&y,1))Xe(((A1*)(x<<16>>16))(y))
Xp(P(xn+k>9,er1(y))Im=xn-1,j=0;Ab8;i(m,b[i]=xA[i+1]==PLH&&!j?j++,y:_R(xA[i+1]))I l=max(0,1-j);Mc(b+m,&y,8*l);_8(xx,b,m+l))
Xq(_1(xx,N(_1(xy,y))))P(1>k,er1(y))Xu(v1[xv](y))Xw(AK(0<xv&&xv<4&&yK==2?1:ytF?yK:1,AW(xv,aV(tr,1,&y))))et1(y))
A3(_2,/*011*/P(!xtt,i2(x,y,z))A a[]={y,z};Ik=xK;P(2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u,xt,tw),ai(xv))P(c3(to,xt,tq),AT(tA,mut(x)))et1(x))
A2(idx,x(i1(x,y)))
A2(ap1,x(x1(y)))
A2(dot,Ym(et2(x,y))Nn=yN;P(!n,y(x))P(n>8,ez2(x,y))y=mRa(Nx(cA(y)));x(y(x8(yA,n))))
S I knd(Ax/*0*/)_(Xz(ti)XZ(tI)xt)
S A set(Ax,Li,Ay/*1i1*/)_(Q(xr==1);XA(Az=xa;xa=z(y);ytt&&!ytF?sqz(x):x)
XM(Az=kv(&x);z=mut(z);Q(ztA);I(ytT&&yN-zn,x(el2(y,z)))Ij=i;i(zn,za=set(mut(za),j,ii(y,i));P(!za,za=au;x(y(z(0)))))y(aM(x,z)))
P(knd(x)-knd(y)-tC+tc,set(cA(x),i,y))
I(xtZ,N(sup(&x,&y)))C w=Tz[xt];w==0?xb=yv:w==1?xh=yv:w==2?xi=yv:(xl=gl(y));x)
S I stp(Li,Ax/*0*/,A**p)_(Ay=**p;P(!ytm,ed1(x))**p=y=mut(y);Az=yx;P(!ztS,ed1(x))Lj=fpI(&yx,xI[i+1]);
z=yy;P(!ztA,ed1(x))yy=j==zn?zq(aa0()):mut(z);Q(_r(yy)==1);*p=(A*)_V(yy)+j;1)
S A*pth(Ax/*1*/)_(Xt(pth(enl(x)))
Li=fI(gk,gn,*xI);I(i<0||!gv[i],gk[i=gn]=*xI;gv[gn++]=xn>1?aa0():au)A*p=gv+i;i(xn-1,P(!stp(i,x,&p),(A*)0))x(0);p)
A mnd(OA*a,In,AA*f)_(A*p=pth(*a);P(!p,mrn(n-1,a+1);0)Ab8;*b=*p;Mc(b+1,a+1,(n-1)*8);*p=au;*p=_R(N(f(b,n))))
AA(am8,Ax=*a,y=a[1];
XT(P(y==au,Ab8;Mc(b,a,n*8);b[1]=tilL(xN);am8(b,n))
Yz(Li=gl_(y);P(!in(i,xn),ei8(a,n))x=mut(y(x));Ab8;Az=a[2];*b=ii(x,i);Mc(b+1,a+3,8*n-24);set(x,i,Nx(z(z8(b,n-2)))))
I(ytZ&&n==4,Az=a[2],u=a[3];
P(xtZ&&ztv&&utzZ&&zv<11,ara(x,y,z,u))
P(xtC&&z==av&&utcC,x=mut(x);y=cL(y);I d=utT;u=enla(u);P(d&&yn-un,el2(x(y),u))
x=ye(ue(i(yn,Lj=yl;B(!in(j,xn),x=0)xC[j]=uC[d*i])x));P(!x,ei0())x))
Yt(et8(a,n))
fld(AP1,a,n))
XM(Ab8;i(n,Ax=a[i];b[i]=xtM?flp(x):x;Q(b[i]))flp(N(eac(AP1,b,n))))
Xm(Az=kv(&x),u=fnd(xR,yR);P(!u,mrn(n-1,a+1);x(z(0)))
I(utlL,Q(ur==1);i(uN,I(ul==NL,ul=xN;xq(utt?yR:ii(y,i));zq(id_(a[2],z)))))
Ab8;*b=y(z);b[1]=u;Mc(b+2,a+2,8*n-16);am(x,Nx(am8(b,n))))
XF(Q(n>1)x(_8(x,a+1,n-1)))
et8(a,n))
S A3(am3,am8(A(x,y,z),3))S A4(am4,am8(A(x,y,z,u),4))S A am5(Ax,Ay,Az,Au,A v)_(am8(A(x,y,z,u,v),5))
A3(dm3,Nm=yN;P(y==au||!m,z(z1(y(x) )))P(m==1,am3(x,fir(y),z ))yR;am4(x,fir(y),prj(DOT,A(PLH,drp(1,y)),2),z))
A4(dm4,Nm=yN;P(y==au||!m,z(z2(y(x),u)))P(m==1,am4(x,fir(y),z,u))yR;am5(x,fir(y),prj(DOT,A(PLH,drp(1,y)),2),z,u))
AA(dm8,n==4?dm4(*a,a[1],a[2],a[3]):n==3?dm3(*a,a[1],a[2]):en8(a,n))
AA(dmd,Ax=*a;XsS(mnd(a,n,dm8))I(n==3,XF(try(x,a[1],a[2])))dm8(a,n))
SN A K0i(A*p,Qs)_(*p=evs(s);I(!*p,die(s))cns=apd(cns,*p))
A K0(A*p,Qs,OA*a,In)_(I(!*p,K0i(p,s))_8(*p,a,n))