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.
 
 
 
 
 
 
k/a.c

64 lines
6.4 KiB

#include"a.h"// ngn/k, (c) 2019-2022 ngn, GNU AGPLv3 - https://codeberg.org/ngn/k/raw/branch/master/LICENSE
S A1(sam,x)V_;T_;I _K(Ax/*0*/)_(xtu||xtw?1:xtv?2:xtx?x>>48&7:xtU?xk:0)
A1(mkn,XmMA(e1f(mkn,x))Ay=_R(cn[xt]);Xt(x(y))x(rsz(xn,y)))
A2(ie,/*00*/x==CAT?_R(ce[ce[yt]?yt:tA]):xtv&&LH(1,xv,10)?_R(ci[ytfF][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:aA1)(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)))
S A iM(Ax,Li,AAL*f)_(Q(xtM);Ay=xy,z=aA(yn);Q(ytA);j(zn,zA[j]=f(yA[j],i))am(_R(xx),sqz(z)))
AAL(ii,/*0*/XA(_R(xa))XC(ac(xc))XB(ai(xb))XH(ai(xh))XI(ai(xi))XL(al(xl))XF(af(xf))XS(as(xi))Xm(ii(xy,i))XM(iM(x,i,ii))xR)
AAL(io,/*0*/XT(in(i,xn)?ii(x,i):xn?mkn(ii(x,0)):xtA?_R(xx):_R(cn[xt]))Xt(xR)Xm(io(xy,i))XM(iM(x,i,io))Q(0);0)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;LI(p)LI(q)LI(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 iF_(U) iF( iF##U,F,U,F,i(n,r[i]=in(q[i],m)?p[q[i]]:NF))
#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)iF_(I)iF_(L)iS_(I)iS_(L)
A2(i1,/*01*/Xt(y(xR))P(y==PLH||y==au,xR)P(xtm||xtM&&ytsS,i1(xy,N(fnd(xx,y))))Yzc(io(x,gl(y)))Yt(et1(y))YmM(Az=kv(&y);am(y,Ny(i1(x,z))))YA(r2(AP1,x,y))
I(!ytL&&!ytI,y=N(cI(y)))Nn=yn;P(xtA||xtM,Az=aA(n);I(ytL,i(n|!n,za=io(x,yl)))E(i(n|!n,za=io(x,yi)))y(0);I(!n,zx=mkn(zx))sqz(z))
Az=xtL&&ytL&&yr==1?y:an(n,xt);Lm=T(&iBI,iHI,iII,jLI,iFI,iCI,iSI,iBL,iHL,iIL,jLL,iFL,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,/*001*/Cb=ytT||y==PLH||y==au;x=Nz(i1(x,yR));P(!b,x(x1(z)))x(l2f(dot,x,aA1(z))))
S AX(i8,Ay=*a;P(n==1,i1(x,y))P(n==2,y(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)))x(l2f(dot,x,aV(tA,n,a))))
L iw(Ax/*0*/,I w,Li)_(S4(w,_(xb),_(xh),_(xi),_(xl))0)
S A1(qa,Ay=oA;Q*p=argv;W(*p,yq(aCz(*p++)))y(y1(x)))S A1(qe,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?x(x1(y)):y)
S A1(qx,exit(xtz?gl(x):1);0)S A1(qj,XC(Cb[PG];In=js_eval(xC,xn,b,SZ b);x(0);aCn(b,n))XA(e1f(qj,x))et1(x))S A1(qp,XC(x=str0(x);x(pk(xV)))et1(x))S A1(qr,x(ai(xr)))S A1(qt,x(al(now())))
A2(_1,/*01*/P(!xtt,i1(x,y))S O C s[][4]={"","k","j","p","t","x","hex","err","argv","env","exit","js","prng","sin","cos","exp","ln","r","pri"};
Xs(Li=fI(s,LEN(s),xv);T(&ser,kst,js1,qp,qt,frk,hex,err,qa,qe,qx,qj,prng,ksin,kcos,kexp,klog,qr,qpri,ed1)[i<0?LEN(s):i](y))
Ik=xK;P(1<k,k==2&&!xtp?prj(x,A(y,PLH),2):prj(x,&y,1))Xo(run(x,&y,1))Xr(w1(x,y))Xx(((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:ytU?yK:1,AW(xv,aV(tr,1,&y))))et1(y))
A3(_2,/*001*/P(!xtt,i2(x,y,z))A a[]={y,z};Ik=xK;P(2<k,yR;prj(x,a,2))Xv(v2[xv](y,z))Xo(yR;run(x,a,2))Xr(z(w2(x,yR,z)))Xw(xv?en1(x):AK(zK,AT(tq,aA2(yR,z))))
Xp(P(xn+k>9,er1(z))yR;Im=xn-1,j=0;Ab8;i(m,b[i]=xA[i+1]==PLH&&j<2?a[j++]:_R(xA[i+1]))I l=max(0,2-j);Mc(b+m,a+j,8*l);_8(xx,b,m+l))
Xq(_1(xx,N(_2(xy,y,z))))P(2>k,er1(z))Xx(((A2*)(x<<16>>16))(yR,z))et1(z))
AX(_8,/*11..1*/Q(n)P(n==1,x1(*a))P(n==2&&!xtp,Ay=*a;y(x2(y,a[1])))P(!xtt,i8(x,a,n))Ik=xK;P(n<k,prj(x,a,n))Xo(run(x,a,n))Xv(x=v8[xv](a,n);mrn(n-1,a+1);x)Xr(w8(x,a,n))Xq(_1(xx,N(_8(xy,a,n))))
Xp(P(xn+k>9,er8(a,n))Im=xn-1,j=0;Ab8;i(m,b[i]=xA[i+1]==PLH&&j<n?a[j++]:_R(xA[i+1]))I l=max(0,n-j);Mc(b+m,a+j,8*l);_8(xx,b,m+l))P(n>k,er8(a,n))Xw(en8(a,n))Xx(en8(a,n))et8(a,n))
A1(jS,cS(jc('.',str(x))))//join symbols with "."
A1(val,XS(P(!xn,x(0);Ax=oS,y=oA;i(gn,I(gv[i],xq(as(gk[i]));yq(_R(gv[i]))))am(x,y))val(jS(x)))Xs(Li=fI(gk,gn,xv);i<0||!gv[i]?ev0():_R(gv[i]))XC(x=str0(x);x(evs(xV)))Xc(evs((V*)&x))XmM(x(_R(xy)))
XA(P(!xn,x)P(xn==1,fir(x))P(xn>9,ez1(x))x=mut(x);Ay=_8(xx,&xy,xn-1);AN(1,x);x(y))Xr(cat11(AT(tA,mut(x)),aw+xE))P(LH(tu,xt,tw),ai(xv))P(LH(to,xt,tq),AT(tA,mut(x)))et1(x))
A2(dot,/*01*/Ym(et1(y))Nn=yN;P(!n,y(xR))P(n>8,ez1(y))y=mRa(N(c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,Az,Au,A v/*10000*/)_(a8(A(x,y,z,u,v),5))
S A3(d3,/*100*/Nm=yN;P(y==au||!m,z1(x))P(m==1,y=fir(yR);y(a3(x,y,z)))Au=prj(DOT,A(PLH,drp(1,yR)),2);y=fir(y);y(u(a4(x,y,u,z))))
A4(d4,/*1000*/Nm=yN;P(y==au||!m,x(z2(x,uR)))P(m==1,y=fir(yR);y(a4(x,y,z,u)))A v=prj(DOT,A(PLH,drp(1,yR)),2);y=fir(yR);A r=y(a5(x,y,v,z,u));mr(v);r)
S AA(d8_,/*10..0*/Ax=*a,y=a[1],z=a[2];P(n==4,d4(x,y,z,a[3]))P(n==3,d3(x,y,z))en1(x))
AA(d8,/*10..0*/Ax=*a;XsS(Iv=_v(xts?x:jS(x));Li=fI(gk,gn,v);I(i<0,gk[i=gn++]=v)A*p=gv+i;I(!*p,*p=au)Ab8;*b=*p;Mc(b+1,a+1,n-1<<3);*p=au;*p=_R(N(d8_(b,n))))
I(n==3,Ay=a[1],z=a[2];XU(x(try(x,y,zR))))d8_(a,n))
SN A ki(A*p,Qs)_(*p=evs(s);I(!*p,die(s))cns=apd(cns,*p))
A k1(A*p,Qs,Ax)_(I(!*p,ki(p,s))_1(*p,x))
A k2(A*p,Qs,Ax,Ay)_(I(!*p,ki(p,s))_2(*p,x,y))
A k8(A*p,Qs,OA*a,In)_(I(!*p,ki(p,s))n?_8(*p,a,n):*p)
AA(no8,/*10..0*/en1(*a))