will 5 ماه پیش
والد
کامیت
ec7759d2e7
17فایلهای تغییر یافته به همراه110 افزوده شده و 922 حذف شده
  1. 0 25
      TTExample.csv
  2. 18 0
      compiler.k
  3. 0 3
      example_hardcode.k
  4. BIN
      k
  5. BIN
      kjr/a
  6. 0 40
      kjr/a.c
  7. 0 127
      kjr/a.h
  8. 0 47
      kjr/v2/a.c
  9. 0 170
      kjr/v2/a.h
  10. 0 35
      kjr/v2/a.k
  11. 0 183
      ngncheat.txt
  12. 0 237
      repl.k
  13. 27 0
      st.k
  14. 25 0
      tempST.csv
  15. 20 0
      test.k
  16. 20 0
      testST.k
  17. 0 55
      transpiler.py

+ 0 - 25
TTExample.csv

@@ -1,25 +0,0 @@
-tempST,State Table,,,,,,
-States/Events,,E1,E2,E3,E4,E5,E6
-Off,S1,"4, 5","1, 2","2, 3","3, 4","5, 6","-, 1"
-FanLow,S2,"4, 5","-, 2","2, 3","3, 4","5, 6","6, 1"
-FanMedium,S3,"4, 5","1, 2","-, 3","3, 4","5, 6","6, 1"
-FanHigh,S4,"4, 5","1, 2","2, 3","-, 4","5, 6","6, 1"
-Heating,S5,"-, 5","1, 2","2, 3","3, 4","5, 6","6, 1"
-Cooling,S6,"4, 5","1, 2","2, 3","3, 4","-, 6","6, 1"
-Events,,E1,E2,E3,E4,E5,E6
-T < 18,C1,Y,N,N,N,N,N
-T >= 18 & T < 22,C2,N,Y,N,N,N,N
-T >= 22 & T < 26,C3,N,N,Y,N,N,N
-T >= 26 & T < 30,C4,N,N,N,Y,N,N
-T >= 30,C5,N,N,N,N,Y,N
-isOff,C6,N,N,N,N,N,Y
-Actions,,,,,,,
-setFan(low),A1,,,,,,
-setFan(medium),A2,,,,,,
-setFan(high),A3,,,,,,
-heaterOn(1),A4,,,,,,
-ACOn(1),A5,,,,,,
-setAll(0),A6,,,,,,
-next,A7,,,,,,
-exit,A8,,,,,,
-error,A9,,,,,,

+ 18 - 0
compiler.k

@@ -0,0 +1,18 @@
+/ csv parser - e exclusive
+getrange: {[str;s;e] s_(e-1)#str};
+
+lines: 0: "tempST.csv";
+
+/csv parser
+parsel: {[l] comi: &l=",";comi+:1;r: 2':!#comi;r: comi@r;r: (1 2#(0;r[0;0])),r;getrange[l].'r}
+parsel'lines
+
+/ / how the parser works
+/ t: lines[0];
+/ comi: &t=","; / commas idx
+/ comi+:1; / help exlude commas (later use -1 on upper)
+/
+/ r: 2':!#comi; / ranges of comma separated parts
+/ r: comi@r; / apply ranges to comma idx
+/ r: (1 2#(0;r[0;0])),r; / add 0-first comma range
+/ getrange[t].'r

+ 0 - 3
example_hardcode.k

@@ -1,3 +0,0 @@
-/ instantiate, represent, evaluate
-tempST: {x+1}
-:tempST



+ 0 - 40
kjr/a.c

@@ -1,40 +0,0 @@
-#define R(t,n,z) r(t_(t,n),z) //:+-*%&|<>=~$.!@?#_^, '/\ 0bcieE
-#include"a.h"//ACDEMNOPS|FGIQRTUW (HJKL[XYZ]) At B Cut Equal Flipflop Less More Num Order Prd q Ret Sum t u Vcat Writework
-typedef float complex Float;float fabsf(float),sqrtf(float),expf(float),logf(float),log2f(float),cabsf(Float);Float csqrtf(Float),cexpf(Float),clogf(Float);Ze rf(ee){return 1/e;}ZE crf(EE){return 1/E;}
-double atof();void*malloc(),free(),*memcpy();long write(),read();int abs(),atoi(),stat(),open(),close(),sprintf(char*,const char*,...);G(mc,(u)memcpy((char*)f,sa,x))nu(vc,++T;sx[nx++]=n;x)
-G(w_,write(f,sa,x))G(_w,read(f,sa,x))f(_h,close(x))F(h,stat(sa,sx))F(h_,open(sa,x))f(W_,(u)malloc(x))f(_W,free(sx);0)f(w,127>x?w_(2,(u)&x,1):w_(2,x,sl(sx)))f(uz,5>ax?ix:_(EE=Ex;*(u*)&E))
-u(t_,ii=(u)n<<lt[t];T+=i;ux=W_(8+n3(i)*8+(2==t));*(u*)x=t<<24|(u)n<<32;x+8,it,in)f(_t,T-=Nx;_W(x-8);0)f(r_,pax?x:(++xr,x))f(_r,pax?0:(1<<24)-1&xr?(--xr,0):_(if(!tx)N(_r(xu))_t(x)))
-f(v,R(ax,1,*(u*)r=uz(x)))ns(kns,mc(t_(2,n),(u)s,n))us(ks,kns(sl(s),s))nu(nz,ua=uz(x);if(3>ax)(a|=a<<8,a|=a<<16);if(5>ax)a|=a<<32;R(ax,n,i(n3(Nr),ru=a)))
-f(wx,_x(w_(2,x,nx));0)F(err,w(a);w(58);w(x);w(10);Q)ns(prr,w((u)s);w(10);wx(vc(94,nz(n,tc(32))));w(10);Q)f(s_,in=0;N(n+=xc)n)f(m_,in=0;N(n=m(n,xi))n)
-Zu at(),es(),ws();f(qf,!ax&&!tx&&1==nx&&2==txx)us(def,r(v(ks(s)),sr[nr]=0))F(fa,U[23]=x;es(xx))f(foo,ws("a:2")) //U[0]=def("x");0) //ws("a"))
-u(tE,ua=*(u*)&E;a>>32?a:1l<<63|a,EE)u(_n,r3(n,i),in)G(c,mc(t_(tx,a),x+(f<<lx),a<<lx))iu(a_,tx?t(tx,ci,xe,xE):r_(xu))u(e1,T0(g(a_(i,x))),_ g,ux)u(e2,QZ,_ g,ua,ux)
-F(A,_ax(R(ta,nx,C4(la,i(nx,sr[i]=sa[xi]),,i(nx,re=((float*)a)[xi]),i(nx,rE=((Float*)a)[xi])))))
-F(V,_a(R(tx,na+nx,mc(r,a,Na);mc(r+Na,x,Nx))))F(cC,_x(R(2,0,N(r=vc(a,V(r,xu))))))nu(cv,V(v(tc(n)),x))us(i$,ti(atoi(s)))us(e$,te(atof(s)))ns(E$,tE((float)atof(s)+I*atof(s+n)))
-u($i,kns(sprintf(b,"%d",i),b),int i)u($e,kns(sprintf(b,"%g",e&&1e-6<fabsf(e)?e:0.),b),ee)f($E,ua=ix?$e(ex):0;x>>=32;x=x?$e(ex):0;a?x?V(vc(58,a),x):a:cv(46,x))
-f($,px?ks("?"):ax?4>ax?$i(x):5>ax?$e(ex):$E(x):2==tx?x:e1($,x))f($_,pax||!lx?$(x):tx?cC(32,e1($,x)):ks("."))f(w$,wx(vc(10,pax||tx?$_(x):cC(10,e1($_,x)))))f(wo,w$(r_(x));x)
-f(ind,_x(R(3,s_(x),unsigned*s=(unsigned*)sr;N(if(xc)*s++=i))))nu(ec,r1(nx,n==xc))F(C,_a(T0(c(xi,(i+1<nx?((unsigned*)x)[i+1]:na)-xi-1,a))))f(Cc,ua=ec(sx[nx-1],x);a=_a(c(-1,na,a));*sa=1;C(x,ind(a)))
-tu(Ua,t(t,ix,ix,4>ax?ix:ex))tu(Ut,T(t,xc,xc,xi,4>tx?xi:xe))f(q0,ax&&!uz(x))iu(set,u*a=U+i;_r(*a);*a=r_(x))
-#define a(g,t,a,v) f(g,ax?ue(t,a):tx?uE(t,v):e1(g,x))
-#define a4(f,c,d) a(f,4,5>ax?te(c(ex)):tE(d(Ex)),5>tx?R4(c(xe)):R5(d(xE)))
-a(_e,0,tb(!ix),R1(!ci))a(_s,2,t(ax,-ix,-ex,-Ex),T(tx,-xc,-xi,-xe,-xE))a(ab,0,3>ax?x:4>ax?ti(abs((int)ix)):te(5>ax?fabsf(ex):cabsf(Ex)),3>tx?x:4>tx?R3(abs((int)xi)):R5(5>tx?fabsf(xe):cabsf(xE)))
-a(_d,4,5>ax?tE(I*ex):4l<<51|x>>32,5>tx?R5(I*xe):R4(((float*)x)[2*i+1]))a4(_p,rf,crf)a4(_l,expf,cexpf)a4(q_,sqrtf,csqrtf)a4(l_,logf,clogf)f($q,1+ix?q_(x):tE(I))f($l,1+ix?l_(x):tE(I*pi))
-#define SP(g,o) F(g,ax?aa?uu(ue(2,t(ax,ia o ix,ea o ex,Ea o Ex))):g(x,a):(aa?:ta)&&tx?UU(uE(2,T(tx,ai o xc,ai o xi,ae o xe,aE o xE))):e2(g,a,x))
-#define LE(g,o) F(g,ax?aa?uu(tb((int)ia o(int)ix)):L_==g?g(_s(x),_s(a)):g(x,a):(aa?:ta)&&tx?UU(R1((int)ai o(int)ci)):e2(g,a,x))
-#define LM(g,o) F(g,Qt(1!=(aa?:ta)||1!=(ax?:tx))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a,x):A_(a,x))
-Zs vm="+    - *  %    &and  |or   <    >     =      ~not $ . !index @at    ?find #take  _drop ^cut   ,\n+abs - *e %log &flip |flop <asc >desc =group ~not $ . !index @first ?nub  #count _sqrt ^order ,";
-Zs//!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~  {"0a([.(while if :)
-B=" m_pkdet  casblu__________  gihon                           v rq __________________________ f j";us(ps,i(sl(s),P(58==si?26u<=s[i-1]-97:33>B[si-32],prr(i,s)))0)f(p,x=31&B[x-32];31>x?x:0)
-us(np,P(34==*s,is(34,s+1)+1)st=s;W(13u>*++t-46&&47-*t);t-s)ns(nq,P(34==*s,kns(n-2,s+1))mc((u)b,(u)s,n=l(21,n));b[n]=0;n=is(58,b);n?E$(n,s):is(46,b)?e$(s):i$(s))
-us(e,P(58==s[1],q(e(s+2))set(*s-97,x))ua=p(*s)?:26u>*s-97?r_(U[*s-97]):r(nq(a=np(s),s),s+=a-1);!*++s?a:32>a||!p(*s)?_(q(e(s))32>a?f[a](x):at(a,x)):_(q(e(s+1))F[p(*s)](a,x)))
-us(es,q(92-*s?e(s):ys(s+1))58==s[1]?_x(0):x)us(ws,if(92-*s)Q(ps(s))q(es(s))x?w$(x):0)us(ts,if(92-*s)Q(ps(s))in=1e6;uf=ut()+30*n;i(n,q(es(s))_r(x))ti((m(f,ut())-f)/(O?2.4e6:2.4e4)))
-us(f1,ux[18];in=!h((u)s,(u)x)&&1&((int*)x)[O?6:1]>>15?x[O?6:12]:0;Qs(!n,s)R(2,n,ii=h_((u)s,0);_w(i,r,n);_h(i)))us(f0,q(f1(s))Cc(x))
-us(ls,q(f0(s))ii=-1;W(++i<nx&&nxu)if(39!=*sxu)Q(ws(sxu))_x(0))us(ys,c4(is(*s,"ltw"),ks(vm),ls(s+2),ts(s+2),ti(T)))int main(int _,char**a){O=(u)a>>46;bu(ia32_ldmxcsr)(0x9fc0);
-foo(0);*++a?ls(*a):(w((u)"k/fun (c)atw "__DATE__),w(10));char b[64];W(1)w(32),b[_w(0,(u)b,64)-1]=0,*b?ws(b):0;}
-

+ 0 - 127
kjr/a.h

@@ -1,127 +0,0 @@
-#define Zi static unsigned
-#define Ze static float
-#define Zu static u // ubcieE [paieEtnNs][ax] [rax][ucieE] w[ucieE] //clang -Os -oa a.c -lm
-typedef unsigned long(*_)(),u;Zi lt[]={3,0,0,2,2,3,3},O,T;Zu Q=128,U[26],ys();Ze pi=3.1415927;
-static char b[64];Zu __attribute((naked))ut(){asm(".quad 0xd53be04031420aeb,0xc148310fd65f03c0,0xc3d0094820e2");}
-#define ty x(y,tx)
-#define xx *(u*)x
-#define txx y(xx,ty)
-#define q(z) ux=z;Q(x)
-#define T0(z)  _x(R(0,nx,i(nx,ru=z)))
-#define r1(n,z) R(1,n,i(n,sr[i]=z))
-#define r3(n,z) R(3,n,i(n,ri=z))
-#define r4(n,z) R(4,n,i(n,re=z))
-#define r5(n,z) R(5,n,i(n,rE=_(z)))
-#define T(t,c,h,e,E) _x(R(t,nx,C4(t-2,i(nx,sr[i]=c),i(nx,ri=h),i(nx,re=e),i(nx,rE=E))))
-#define t(t,i,e,E) c4(t-2,tc(i),ti(i),te(e),tE(E))
-#define ue(t,z) _(x=t>ax?Ua(t,x):x;z)
-#define uE(t,z) _(x=t>tx?Ut(t,x):x;z)
-#define uu(e) _(if(aa!=ax){if(aa<ax)a=Ua(ax,a);else x=Ua(aa,x);}e)
-#define UU(e) _a(it=aa?:ta;if(t!=tx){if(t<tx)a=aa?Ua(tx,a):Ut(tx,a);else x=Ut(t,x);}e)
-
-#define _(e) ({e;})
-#define f(g,e) u(g,e,ux)
-#define i(n,e) {unsigned $n=n;ii=0;for(;i<$n;++i){e;}}
-#define l(a,e) _(typeof(e)e_=e;(a)<e_?(a):e_)
-#define m(a,e) _(typeof(e)e_=e;(a)>e_?(a):e_)
-#define r(a,e) _(typeof(a)r=a;e;r)
-#define u(g,e,x...) Zu g(x){return _(e);}
-#define x(a,e) _(typeof(a)x=a;e)
-#define y(a,e) _(typeof(a)y=a;e)
-#define F(g,e) u(g,e,ua,ux)
-#define G(g,e) u(g,e,uf,ua,ux)
-#define Q(e) if(Q==(e))return Q;
-#define N(e) i(nx,e)
-#define P(b,e) if(b)return _(e);
-#define W(z) while(z)
-#define ii unsigned i
-#define in unsigned n
-#define ss char*s
-#define us(g,e) u(g,e,ss)
-#define ns(g,e) u(g,e,in,ss)
-#define _a(e) r(_(e),_r(a))
-#define _x(e) r(_(e),_r(x))
-#define _ax(e) _a(_x(e))
-#define n3(z) ((7+(z))>>3)
-#define ex (*(float*)&x)
-#define Ex (*(Float*)&x) 
-#define ax l(5,x>>51)
-#define pax (px||ax)
-#define xc sx[i]
-#define sx ((char*)x)
-#define px (31>x)
-#define xE ((Float*)x)[i]
-#define aE x(a,ax?Ex:xE)
-#define Ea x(a,Ex)
-#define ci (lx?xi:sx[i])
-#define ix (unsigned)x
-#define lx lt[tx]
-#define Nx (nx<<lx)
-#define tx sx[-5]
-#define xr ((unsigned*)x)[-2]
-#define nx ((unsigned*)x)[-1]
-#define xi ((unsigned*)x)[i]
-#define xe ((float*)x)[i]
-#define xu ((u*)x)[i]
-#define iu(g,e) u(g,e,ii,ux)
-#define nu(g,e) u(g,e,in,ux)
-#define tu(g,e) u(g,e,it,ux)
-#define Qs(e,s) if(e)return err((u)__func__,(u)s);
-#define Qz(e) Qs(e,"nyi")
-#define Qr(e) Qs(e,"rank")
-#define Qt(e) Qs(e,"type")
-#define Qd(e) Qs(e,"domain")
-#define QZ Qz(1)0
-#define oo w((u)"oo\n")
-#define uf u f
-#define ua u a
-#define ux u x
-#define st char*t
-#define it unsigned t
-#define EE Float E
-#define ee float e
-#define nxu ((unsigned*)xu)[-1]
-#define sxu ((char*)xu)
-#define si s[i]
-#define sr x(r,sx)
-#define nr x(r,nx)
-#define Nr x(r,Nx)
-#define ai x(a,ax?ix:xi)
-#define ae x(a,ax?ex:xe)
-#define ea x(a,ex)
-#define sa x(a,sx)
-#define la x(a,lx)
-#define pa x(a,px)
-#define aa x(a,ax)
-#define ia x(a,ix)
-#define na x(a,nx)
-#define ta x(a,tx)
-#define Na x(a,Nx)
-#define c4(z,a,b,c,d)   _(unsigned o=z;!o?a:1==o?b:2==o?c:_(d))
-#define C4(z,a,b,c,d)   unsigned o=z;if(!o)_(a);else if(1==o)_(b);else if(2==o)_(c);else _(d);
-#define Z_ static _
-#define Zs static char*
-#define ZE static Float
-#define l2(z) (64-bu(clzl)(z))
-#define R1(z) _x(r1(nx,z))
-#define R3(z) _x(r3(nx,z))
-#define R4(z) _x(r4(nx,z))
-#define R5(z) _x(r5(nx,z))
-#define tb(z) (1l<<51|(z))
-#define tc(z) (2l<<51|(char)(z))
-#define ti(z) (3l<<51|(unsigned)(z))
-#define te(z) (4l<<51|_(float _=z;*(unsigned*)&_))
-#define ru ((u*)r)[i]
-#define ri ((unsigned*)r)[i]
-#define re ((float*)r)[i]
-#define rE ((Float*)r)[i]
-#define wu(z) r((u)(z),nw(sprintf(b,"%lx\n",r),b))
-#define wi(z) r((int)(z),nw(sprintf(b,"%d\n",r),b))
-#define we(z) r((float)(z),nw(sprintf(b,"%g\n",r),b))
-#define wE(z) r((Float)(z),float*a=&r;nw(sprintf(b,"%g:%g\n",*a,a[1]),b))
-#define bu(o) __builtin_##o
-us(sl,ii=0;W(si)++i;i)ns(is,i(sl(s),P(n==si,i+1))0)
-#if __arm64 
-static void __builtin_ia32_ldmxcsr(int x){asm("msr fpcr,%0"::"r"(3l<<23));}
-#endif
-#include<complex.h>

+ 0 - 47
kjr/v2/a.c

@@ -1,47 +0,0 @@
-#include"a.h"//k(c)2024 arthur whitney(l)MIT ! #$%&'()*+,-./:;<=>?@[\]^_{|}~ [rrit]n A
-vV(b_,o(pmovmskb)(a))vV(b2,o(movmskps)(a))V(bl,v&a|~v&b,Vv,Va,Vb)VF(a0,bl(I0/16==b/16,i0(a,b),i0(o(permvarsi)(a,4+I0/4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gi,qr,ra,gE,_t,ge,v_,$)Z_(H,ff,rr,_o,o_,og,no,dt,n_,_v,ou,_n,_t,or,v_,$)
-g(a1,P(20>f,Qr(px&&17>f-1)$6(f,x,3==tx?++x:jJ(1,ti(1),x),3==tx?--x:jJ(1,ti(-1),x),jJ(3,r_(x),x),j4(-1,x),(tx?h:H)[f-5](x)))LMS(f-20,x))Z_(G,No,Dt,N_,0,0,0,0,_C,C_,qr)
-G(a2,P(20>f,P(pa||px,Qr(13!=f)a1(a,x))10>f?jJ(f,a,x):4>f-13?(15>f?AA:NN)(1&f-1,a,x):G[f-10](a,x))Qz(29>f)f-=29;!f&&9>a-11?vk(f1(H[a-5],x)):$3(ta-2,c3,i3,p3)(f,a,x))U(v,_r(*_);*_=x,U*_,Ux)
-#define A() (_&&23<j?_+j-24:D+j)
-U(z_,Ua=x;x=xx;Ur;_W(ij=xc%32;Q(r=*c=$5(xc/32,--c;20>j?j:ti(j-20),j?a1(j,r):(--i,j=xc%32,r_(v(A(),r))),a2(j,r,*++c),--c;r_(*A()),--c;a_(j,a))))*c++,U*_,Ux)
-Zc*P_=" L OSDE]  CARBK^@ GIHNM _ QP F J",*_P=":+-*%&|<>=~.!@?#_^,$LMSAVD...'/\\;()[]";f(_p,B3(90+(V){},10>O-20,O+28,96<O,O,a0(*(V*)_P,O%32)))g(_bp,_(bp(f,x)))
-f(p_,B3(O,10>O-48,O-28,26>O-97,O,bl(26>O-65,55+(V){},a0(*(V*)P_,O-B-(57<O&10)-(90<O&26)-(122<O&27))-B)))f(Ba,0)f(a$,0)f(Bp,0)f(p$,0)f(Bd,0)f(d$,0)f(Bb,0)f(b$,0)f(t3,qg(58,x)?2:qg(46,x)||qg(101,x))
-f(Bq,qg(34,x)?_bp(0,bC(34==O)):0)f(Bt,_bp(5,bC(Vv=10>O-48;v|s(-1,v)&s(1,v)&(46==O|58==O|101==O|B==O))))g(qn,_bp(f,bC(1!=O/32&224>O)))f(Bn,qn(5,x))f(Bo,bC(3>O-61))f(Bv,qn(7,x))
-f(t$,P(qg(B,x),x=Ss(vc(B,x));it=0;n(t=m(t,t3(xU)))v0(3+t,fr(_$,t,x)))_$(t3(x),x))f(n$,V_(nz(n-1,tc(77)),x))f(r$,r(rr(x),*sr+=32))f(v$,B==sx[1]?x:r$(x))f(o$,*sx-=1==*sx/32?32:0;r$(x))
-#define c(z) _(cc[256];Ur=(U)c;ns(e(z)-(U)c,c))
-Z_(P,Bq,Bt,Ba,Bp,Bd,Bb,Bn,Bo,Bv)Z_(R,0,t$,a$,p$,d$,b$,n$,o$,v$)ZU rd();g(fd,Ua=P[f](x);P(!a,x)a=n_(f?_bp(10,a):a);P(!na,_r(a);x)rd(f,a,x))f(pz,i(6,x=fd(3+i,x))x)
-G(rd,_ $=R[f];c(ij=0;i(na,ik=au-1;r=dn(r,k-j,x+j);j=++i<na?au:nx;S[n]=a(ns(j-k-2*!$,sx+k+!$),$?$(a):a);*sr++=(3>f?128:7>f?192:224)+n++)dn(r,nx-j,x+j)))
-F(pS,n(IF(192>xc,*sa++=xc)a=pS(a,S[xc%32]))a)Us(ps,Ux=xs(s);n=1;i(3,x=fd(i,x))x=p_(x);x=pz(x);x=c(pS(r,x));K(n,i?S[i]:x))
-Us(zs,P(92==*s,ys(s+1))ii=is(s[1],2,": ");P(qa(*s)&&2>i,v(D+*s%32,(i?ps:zs)(s+2));0)Qx(ps)_(z_(0,x)))Us(os,P(!*s||39==*s,0)Qx(zs)x?wx(x):0)Us(ls,Qx(_0)n(Ua=xU;Q(na?os(sa):_(96)))_(0))
-int main(int n,char**_){A=(U)$>N;M[29]=m_(0,n0<<30,3,A?0x1042:0x4022,0,0);M_(0);W=0;if(*++_)ls(*_);cc[256];W(1)wc(B),c[_w(0,(U)c,256)-1]=0,*c?os(c):0;}
-Zc*pP="+-*sqr %sqrt &flip |flop <asc >desc =group ~ . !index @first ?nub  #count _floor ^order ,$\n+-*    %     &and  |or   <    >     =      ~ . !index @at    ?find #take  _drop  ^cut   ,$";
-g(ts,Q(x)Ua=ut();i(f,Q(_r(z_(0,x))))_(ti(((ut()-a)/(A?2.4e3:2.4e6)-f/2e5))))Us(ys,if(!*s)_k(0);$5(is(*s,4,"ltvw"),ls(s+2),ii=is(B,20,s);si=0;ts(i?zs(s+2):1,ps(s+i+1)),QZ,ti(W),xs(pP)))
-f(_z,px||tx||!Lx?$(x):qf(x)?$(_v(x)):sS(B,f1(_z,x)))f(wx,x=sS(10,px||tx||Tx||qf(x)?v_(_z(x)):f1(_z,x));w_(2,x,nx);_(0))

+ 0 - 170
kjr/v2/a.h

@@ -1,170 +0,0 @@
-#define _s(o)   i(l0-2,a=o##i(a,s(4<<i,a))) //a=o##i(a,s(4,a));a=o##i(a,s(8,a));a=o##i(a,s(16,a));a=o##i(a,s(32,a))
-#define s_(t,o) a(t##0,i(nN(Nx),a=o##i(a,O))_s(o)a)[b(l0-2)]
-#define S_(t,o) e(V##t b=t##0;N(V##t a=O;_s(o)b=a+b[b(l0-2)]))
-#define A() (_&&23<j?_+j-24:D+j)
-#define B3(b,c,d,e,f,g) _N(bl(127<O,b,bl(c,d,bl(e,f,g))))
-#define l0 5
-#define ZU static U//abc.efg.ij.lmno..r.t...x..
-#define ZV static V//..C..FG......NOPQR.TUVW...
-#define AV(n) __attribute((vector_size(1<<n),aligned(1)))
-typedef char V AV(l0);typedef unsigned u,vu AV(l0-1),Vu AV(l0);typedef unsigned long(*_)(),U,U4 AV(4),VU AV(l0),UU AV(l0+1);typedef int Vi AV(l0);typedef float Ve AV(l0);
-ZU w_(U,...),prr(),b_(),T(),_r(),r_(),a2(),ys(),pz(),wx(),_p(),z_(),W,M[30],D[32],S[1<<10],*c=S+(1<<10);static Ve e0;static VU U0;static Vu u0,I2={0,1,2,3,4,5,6,7}; //,8,9,10,11,12,13,14,15};
-ZV I0={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};//,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63};
-#define D(g,z) U(g,z,_ $,Ua,Ux)
-#define o(f) bu(ia32_##f##256) 
-#define n0 (1L<<l0)
-#define nN(z) (n0-1+(z)>>l0)
-#define bI(z)    R(1,nx,i(nN(Nx),rc=b2(e(z))))
-#define bC(z)    R(1,nx,i(nN(Nx),ru=b_(e(z))))
-#define K(n,z)   R(0,n,i(x(r,nx),rU=e(z)))
-#define L(t,n,z) R(t,n,i(x(r,nN(Nx)),rV=e(z)))
-#define _(z) r(e(z),_r(x))
-#define __(z) r(e(z),_r(x);_r(a))
-#define a(z,y) e(typeof(z)a=z;y)
-#define b(z) ((1l<<(z))-1)
-#define e(_) ({_;})
-#define f(g,z) U(g,z,Ux)
-#define g(g,z) U(g,z,uf,Ux)
-#define i(a,z) {unsigned _n=a;ii=-1;W(++i<_n){z;}}
-#define j(a,z) {unsigned _n=a;ij=-1;W(++j<_n){z;}}
-#define l(a,z) e(typeof(z)e_=z;(a)<e_?(a):e_)
-#define m(a,z) e(typeof(z)e_=z;(a)>e_?(a):e_)
-#define n(z)   i(nx,z)
-#define r(z,y) e(typeof(z)r=z;y;r)
-#define t(t,x) ((U)(t)<<61|(x))
-#define x(z,y) e(typeof(z)x=z;y)
-#define C(t,x) bu(convertvector)(x,t)
-#define F(g,z) U(g,z,Ua,Ux)
-#define G(g,z) U(g,z,uf,Ua,Ux)
-#define N(z) L(Tx,nx,z)
-#define O ((V*)x)[i]
-#define P(b,z) if(e(b))return e(z);
-#define Q(z...) P(96==(z),96)
-#define R(t,n,z)  r(T(t,n),z)
-#define U(g,z,x...) ZU g(x){return e(z);}
-#define V(g,z,x...) ZV g(x){return e(z);}
-#define W(z) while(e(z))
-#define _N(z)     _(N(z))
-#define _K(n,z)   _(K(n,z))
-#define _R(t,n,z) _(R(t,n,z))
-#define _T(t,z)   _(L(t,nx,z))
-#define q3(o) Qd(1!=f&&1<f-5)f-=5;P(Bx,b##o(f,x))Qz(2!=Lx)
-#define i0(a,b) o(pshufb)(a,b)
-#define i2(a,b) o(pshufd)(a,b)
-#define VF(g,z) V(g,z,Va,Vb)
-#define ai(a,b) (a)+(b)
-#define v1($,z) f($,tx?e(Q(x=$(  v_(x)))_v(x)):Tx?e(z):f1($,  x))
-#define V1($,z) F($,tx?e(Q(x=$(a,v_(x)))_v(x)):Tx?e(z):fr($,a,x))
-#define bu(f) __builtin_##f
-#define AN(f,s,x...) __attribute((naked))U f(x){asm(s);}
-#define _W(z) ii=nx;W(i--){z;}
-#define Ui(g,z) U(g,z,ii)
-#define Us(g,z) U(g,z,ss)
-#define Zs(g,a,x...) static char*g(x){return e(a);}
-#define nb(z) bu(popcountl)(z)
-#define ib(z) bu(ctzl)(z)
-#define lb(z) bu(clzl)(z)
-#define a3(t) $3(f-1,t##a+t##x,t##a-t##x,t##a*t##x)
-#define b3(a,x) $3(f-7,(a)<x,(a)>x,(a)==x)
-#define N6(z) i(63+nx>>6,z)
-#define nS(g,z) U(g,z,in,ss)
-#define ve(g,z) U(g,z,ee)
-#define vV(g,z) U(g,z,Va)
-#define IU(a) r(ib(a),a&=a-1)
-#define Z_(f,x...) static _ f[]={x};
-#define Qx(f) Ux=f(s);Q(x)
-#define Qs(e,s) P(e,err((U)__func__,(U)s))
-#define QZ e(Qz(1)0)
-#define Nx tn(Tx,nx)
-#define Uu     C(VU,((vu*)x)[i])
-#define _u (Ve)C(Vu,((UU*)x)[i])
-#define u_ (Ve)C(Vu,((UU*)x)[i]>>32)
-#define Ix (Vu)Cx
-#define Ex (Ve)Cx
-#define Ux U x
-#define Vv V v
-#define Va V a
-#define Vb V b
-#define ax a(x,xx)
-#define xx *UX
-#define mx sx[-6]
-#define R_ UR[-1]
-#define si s[i]
-#define xb sx[i/32]
-#define Ca x(a,tx?cx:Cx)
-#define Ia x(a,tx?ux:Ix)
-#define Ea x(a,tx?ex:Ex)
-#define ca x(a,cx)
-#define AU r_(aU)
-#define XU r_(xU)
-#define UR ((U*)r)
-#define UA ((U*)a)
-#define UX ((U*)x)
-#define aU ((U*)a)[i]
-#define rU ((U*)r)[i]
-#define xU ((U*)x)[i]
-#define na ((u*)a)[-1]
-#define nx ((u*)x)[-1]
-#define xc sx[i]
-#define rc (sr)[i]
-#define ru ((u*)r)[i]
-#define xu ((u*)x)[i]
-#define rV ((V*)r)[i]
-#define aV ((V*)a)[i]
-#define sr (char*)r
-#define sa (char*)a
-#define sx ((char*)x)
-#define rx ((u*)x)[-2]
-#define Tx sx[-5]
-#define Bx (1==Tx)
-#define tx (x>>61)
-#define Cx O
-#define ss char*s
-#define cc char c
-#define ee float e
-#define uf unsigned f
-#define ii unsigned i
-#define ij unsigned j
-#define ik unsigned k
-#define im unsigned m
-#define in unsigned n
-#define it unsigned t
-#define Ur U r
-#define Ua U a
-#define Un U n
-#define oo ws("oo\n")
-#define x_ sx[nx-1]
-#define Zc static char
-#define Zu static u
-#define S(f,i) static AN(f,"mov %rcx,%r10;mov $"#i",%rax;syscall;ret",Ux,...)
-AN(_start,"lea 8(%rsp),%rsi;call main")AN(ut,"rdtsc;shl $32,%rdx;or%rdx,%rax;ret")S(_w,0)S(w_,1)S(f_,2)S(_f,3)S(_l,4)S(m_,9)S(_k,60)
-Zc*_P,B=32;Zu n,A,M1=65535,N=1<<31,L[]={3,0,0,2,2,3},g=95<<23;static float E[]={1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9};Ui(tb,t(1,i))Ui(tc,t(2,i))Ui(ti,t(3,i))f(l2,64-lb(x-1))
-ve(ue,*(u*)&e)ve(te,t(4,ue(e)))ve(eq,1-1e-6<e&&1+1e-6>e)f(qe,2==Tx&&32>x_%128)f(qf,!Tx&&qe(xx))g(tn,1==f?7+x>>3:x<<L[f])f(sb,ii=nx/64;if(nx%64)xU&=b(nx%64);r(0,N6(r+=nb(xU))))
-Ui(g_,ij=N&i;j>>2|b(29)&m(g,i)-g)f(G_,g_(x)|g_(x>>32)<<30)Ui(_g,ij=i&b(29);j?N&i<<2|j+g:0)f(_G,_g(x)|_g(x>>30)<<32)f(z4,64/4-lb(x)/4)f(q0,10>x-48)f(qa,26>x-97)
-Us(sl,ii=0;W(si)++i;i)Zs(ws,w_(2,(U)s,sl(s));s,ss)f(wc,w_(2,(U)&x,1))F(err,if(a)ws(sa);wc(58);ws(sx);wc(10);96)U(OO,ws("OO\n");_k(0))
-U(dn,i(nN(n),rV=O)r+n,Ur,Un,Ux)U(is,i(nN(n),Ua=b_(c==O);P(a,l(n,n0*i+ib(a))))n,cc,in,V*x)g(ig,is(f,nx,sx))g(qg,nx>ig(f,x))nS(ns,R(2,n,dn(r,n,(U)s)))Us(xs,ns(sl(s),s))
-#define ix ux
-#define ia ua
-#define cx (char)x
-#define px (128>x)
-#define lx L[tx]
-#define Lx L[Tx]
-#define ux (unsigned)x
-#define ex a(ux,*(float*)&a)
-#define au x(a,xu)
-#define pa x(a,px)
-#define ta x(a,tx)
-#define ua x(a,ux)
-#define ea x(a,ex)
-#define Ta x(a,Tx)
-#define Qz(e) Qs(e,"nyi")
-#define Qr(e) Qs(e,"rank")
-#define Qt(e) Qs(e,"type")
-#define Qn(e) Qs(e,"count")
-#define Qd(e) Qs(e,"domain")
-#define $3(z,a,b,c)       e(unsigned y=z;!y?e(a):1==y?e(b):e(c))
-#define $4(z,a,b,c,d)     e(unsigned y=z;!y?e(a):1==y?e(b):2==y?e(c):e(d))
-#define $5(z,a,b,c,d,x)   e(unsigned y=z;!y?e(a):1==y?e(b):2==y?e(c):3==y?e(d):e(x))
-#define $6(z,a,b,c,d,x,f) e(unsigned y=z;!y?e(a):1==y?e(b):2==y?e(c):3==y?e(d):4==y?e(x):e(f))
-#define C6(z,a,b,c,d,e,f) switch(z){case 0:{a;break;}case 1:{b;break;}case 2:{c;break;}case 3:{d;break;}case 4:{e;break;}default:{f;}}
-#define IF(z,a) if(z){a;}else  //f(wi,cc[21];ss=c+20;*s=10;do*--s=48+x%10;W(x/=10);w_(2,s,c+21-s);x)f(Y,wx(r_(x));x)

+ 0 - 35
kjr/v2/a.k

@@ -1,35 +0,0 @@
-m:1000000
-\t:m 2
-\t:m ----------2
-\t:m 2-2-2-2-2-2
-\t:m @,@,@,@,@,2
-v:!4000
-m:_1e9%#v
-\t:m 2=v
-\t:m +/v
-\t:m |/v
-\t:m 2+v
-\t:10?m 2%v
-\t:10?m %v
-\t:10?m +\v
-
-todo
-Ia2E3  !(;;)
-Waa:-a (:a)/..
-(:a)/(:a:a-1)
-+
-+/
-x+*
-+/'!'2 3
-A1>_#9
-A2>_(x+*)/x:#9
-
-a'b while(a)b
-A'B if(a)b if(c)d else e 
-2b|~2b
-?n
-^?<>= 
-x.y
-sql
-^x [a/deepmind]
-

+ 0 - 183
ngncheat.txt

@@ -1,183 +0,0 @@
-ngn/k, (c) 2019-2022 ngn, GNU AGPLv3. (codeberg.org/ngn/k)
-: SET      RETURN    '  each|slide|bin
-+ add      flip      /  fold|join |dec|comment
-- subtract negate    \  scan|split|enc|trace
-* multiply first     ': eachprior
-% divide   sqrt      /: eachright
-! mod|dict enum|key  \: eachleft
-& min|and  where
-| max|or   reverse   /
-< less     ascend    multiline comment
-> more     descend   \
-= equal    group
-~ match    not       0: lines i/o
-, concat   enlist    1: bytes i/o
-^ without  null
-# reshape  length
-_ drop|cut floor
-$ cast     string    $[c;t;f]     COND
-? find|rnd uniq      ?[a;i;b]     splice
-@ apply(1) type      @[x;i;[f;]y] amend
-. apply(n) eval      .[x;i;[f;]y] drill
-grammar:  E:E;e|e e:nve|te| t:n|v v:tA|V n:t[E]|(E)|{E}|N
-limits: 8 locals/args, 256 bytecode
---------------------------------------------------------------------------------
-Types:
-list atom
- `A        generic list   ()   ,"ab"   (0;`1;"2";{3};%)
- `I   `i   int            0N -9223372036854775807 01b
- `D   `d   float          -0w -0.0 0.0 0w 1.2e308 0n
- `C   `c   char           "a"   0x6263   "d\0\"\n\r\t"
- `S   `s   symbol         `   `a   `"file.txt"   `b`cd`"ef"
- `M   `m   table&dict     +`a`b!(0 1;"23")   (0#`)!()
-      `o   lambda         {1+x*y#z}  {[a;b]+/*/2#,a,b}
-      `p   projection     1+   {z}[0;1]   @[;i;;]
-      `q   composition    *|:   {1+x*y}@
-      `r   derived verb   +/   2\   {y,x}':
-      `u   monadic verb   +:   0::
-      `v   dyadic  verb   +   0:
-      `w   adverb         '   /:
-      `e   external func
---------------------------------------------------------------------------------
-I/O verbs
-  0:x read  lines
-x 0:y write lines
-  1:x read  bytes
-x 1:y write bytes
-   <s open          fd:<`"file.txt"
-   >i close         >fd
-
-x can be a file descriptor (int) or symbol or string such as
- "file.txt"
- "/path/to/file"
- "host:port"
- ":port"         /host defaults to 127.0.0.1
---------------------------------------------------------------------------------
-Verbs:    : + - * % ! & | < > = ~ , ^ # _ $ ? @ . 0: 1:
-notation: [c]har [i]nt [n]umber(int|float) [s]ymbol [a]tom [d]ict
-          [f]unc(monad) [F]unc(dyad) [xyz]any
-special:  var:y     set    a:1;a -> 1
-          (v;..):y  unpack (b;(c;d)):(2 3;4 5);c -> 4
-          :x        return {:x+1;2}[3] -> 4
-          $[x;y;..] cond   $[0;`a;"\0";`b;`;`c;();`d;`e] -> `e
-          o[..]     recur  {$[x<2;x;+/o'x-1 2]}9 -> 34
-          [..]      progn  [0;1;2;3] -> 3
-
-::  self      ::12 -> 12
- :  right     1 :2 -> 2   "abc":'"d" -> "ddd"
- +x flip      +("ab";"cd") -> ("ac";"bd")
-N+N add       1 2+3 -> 4 5
- -N negate    - 1 2 -> -1 -2
-N-N subtract  1-2 3 -> -1 -2
- *x first     *`a`b -> `a   *(0 1;"cd") -> 0 1
-N*N multiply  1 2*3 4 -> 3 8
- %N sqrt      %25 -> 5.0   %-1 -> 0n
-N%N divide    2 3%4 -> 0.5 0.75
- !i enum      !3 -> 0 1 2   !-3 -> -3 -2 -1
- !I odometer  !2 3 -> (0 0 0 1 1 1;0 1 2 0 1 2)
- !d keys      !`a`b!0 1 -> `a`b
- !S ns keys   a.b.c:1;a.b.d:2;!`a`b -> ``c`d
-x!y dict      `a`b!1 2 -> `a`b!1 2
-i!I div       -10!1234 567 -> 123 56
-i!I mod       10!1234 567 -> 4 7
- &I where     &3 -> 0 0 0   &1 0 1 4 2 -> 0 2 3 3 3 3 4 4
- &x deepwhere &(0 1 0;1 0 0;1 1 1) -> (0 1 2 2 2;1 0 0 1 2)
-N&N min/and   2&-1 3 -> -1 2   0 0 1 1&0 1 0 1 -> 0 0 0 1
- |x reverse   |"abc" -> "cba"   |12 -> 12
-N|N max/or    2|-1 3 -> 2 3   0 0 1 1|0 1 0 1 -> 0 1 1 1
- <X ascend    <"abacus" -> 0 2 1 3 5 4
- >X descend   >"abacus" -> 4 5 3 1 0 2
- <s open      fd:<`"/path/to/file.txt"
- >i close     >fd
-N<N less      0 2<1 -> 1 0
-N>N more      0 1>0 2 -> 0 0
- =X group     ="abracadabra" -> "abrcd"!(0 3 5 7 10;1 8;2 9;,4;,6)
- =i unitmat   =3 -> (1 0 0;0 1 0;0 0 1)
-N=N equal     0 1 2=0 1 3 -> 1 1 0
- ~x not       ~(0 2;``a;"a \0";::;{}) -> (1 0;1 0;0 0 1;1;0)
-x~y match     2 3~2 3 -> 1   "4"~4 -> 0   0~0.0 -> 0
- ,x enlist    ,0 -> ,0   ,0 1 -> ,0 1   ,`a!1 -> +(,`a)!,,1
-x,y concat    0,1 2 -> 0 1 2  "a",1 -> ("a";1)
-d,d merge     (`a`b!0 1),`b`c!2 3 -> `a`b`c!0 2 3
- ^x null      ^(" a";0 1 0N;``a;0.0 0n) -> (1 0;0 0 1;1 0;0 1)
-a^y fill      1^0 0N 2 3 0N -> 0 1 2 3 1   "b"^" " -> "b"
-X^y without   "abracadabra"^"bc" -> "araadara"
- #x length    #"abc" -> 3   #4 -> 1   #`a`b`c!0 1 0 -> 3
-i#y reshape   3#2 -> 2 2 2
-I#y reshape   2 3#` -> (```;```)
-f#y replicate (3>#:')#(0;2 1 3;5 4) -> (0;5 4)   {2}#"ab" -> "aabb"
-x#d take      `c`d`f#`a`b`c`d!1 2 3 4 -> `c`d`f!3 4 0N
- _n floor     _12.34 -12.34 -> 12 -13
- _c lowercase _"Ab" -> "ab"
-i_Y drop      2_"abcde" -> "cde"   `a`c_`a`b`c!0 1 2 -> (,`b)!,1
-I_Y cut       2 4 4_"abcde" -> ("cd";"";,"e")
-f_Y weed out  (3>#:')_(0;2 1 3;5 4) -> ,2 1 3
-X_i delete    "abcde"_2 -> "abde"
- $x string    $(12;"ab";`cd;+) -> ("12";(,"a";,"b");"cd";,"+")
-i$C pad       5$"abc" -> "abc  "   -3$"a" -> "  a"
-s$y cast      `c$97 -> "a"   `i$-1.2 -> -1   `$"a" -> `a
-s$y int       `I$"-12" -> -12
- ?X uniq      ?"abacus" -> "abcus"
- ?i uniform   ?2 -> 0.6438163747387873 0.8852656305774402 /random
-X?y find      "abcde"?"bfe" -> 1 0N 4
-i?x roll      3?1000 -> 11 398 293   1?0 -> ,-8164324247243690787
-i?x deal      -3?1000 -> 11 398 293 /guaranteed distinct
- @x type      @1 -> `b   @"ab" -> `C   @() -> `A   @(@) -> `v
-x@y apply(1)  {x+1}@2 -> 3   "abc"@1 -> "b"   (`a`b!0 1)@`b -> 1
- .S get       a:1;.`a -> 1   b.c:2;.`b`c -> 2
- .C eval      ."1+2" -> 3
- .d values    .`a`b!0 1 -> 0 1
-x.y apply(n)  {x*y+1}. 2 3 -> 8   (`a`b`c;`d`e`f). 1 0 -> `d
-
-@[x;y;f]   amend  @["ABC";1;_:] -> "AbC"   @[2 3;1;{-x}] -> 2 -3
-@[x;y;F;z] amend  @["abc";1;:;"x"] -> "axc"   @[2 3;0;+;4] -> 6 3
-.[x;y;f]   drill  .[("AB";"CD");1 0;_:] -> ("AB";"cD")
-.[x;y;F;z] drill  .[("ab";"cd");1 0;:;"x"] -> ("ab";"xd")
-.[f;y;f]   try    .[+;1 2;"E:",] -> 3   .[+;1,`;"E:",] -> "E:'type\n"
-?[x;y;z]   splice ?["abcd";1 3;"xyz"] -> "axyzd"
---------------------------------------------------------------------------------
-Special symbols:
-    `@x serialize    ` 7 8 9 -> 0x020300000000000000070809
-    `?C deserialize  `?0x020300000000000000070809 -> 7 8 9
-   `j?C parse json   `j?"{\"a\":1,\"b\":[true,\"c\"]}" -> `a`b!(1.0;(1;,"c"))
-   `k@x pretty-print `k("ab";2 3) -> "(\"ab\";2 3)"
-   `p@C parse k
- `hex@C hexadecimal  `hex"ab" -> "6162"
-   `x@x fork-exec    `x(("/bin/wc";"-l");"a\nbc\nd\n") -> "3\n"
-   `t[] current time (microseconds)
-`argv[] list of cmd line args
- `env[] dict of env variables
-`prng[] `prng@I get/set pseudo-random number generator internal state
-                     s:`prng[];r:9?0;`prng s;r~9?0 -> 1
-        `prng@0 use current time to set state
- `err@C throw error
-Special symbols available only in an interpreter built with "make k-libc":
- `sin@N trigonometry `sin 12.34 -> -0.22444212919135995
- `exp@N exponential  `exp 1 -> 2.7182818284590455
-  `ln@N logarithm    `ln 2 -> 0.6931471805599453
---------------------------------------------------------------------------------
-Adverbs:   ' / \ ': /: \:
-   f' each1     #'("abc";3 4 5 6) -> 3 4
- x F' each2     2 3#'"ab" -> ("aa";"bbb")
-   X' binsearch 1 3 5 7 9'8 9 0 -> 3 4 -1
-   F/ fold      +/1 2 3 -> 6
-   F\ scan      +\1 2 3 -> 1 3 6
- x F/ seeded /  10+/1 2 3 -> 16
- x F\ seeded \  10+\1 2 3 -> 11 13 16
- i f/ n-do      5(2*)/1 -> 32
- i f\ n-dos     5(2*)\1 -> 1 2 4 8 16 32
- f f/ while     (1<){$[2!x;1+3*x;-2!x]}/3 -> 1
- f f\ whiles    (1<){$[2!x;1+3*x;-2!x]}\3 -> 3 10 5 16 8 4 2 1
-   f/ converge  {1+1.0%x}/1 -> 1.618033988749895
-   f\ converges (-2!)\100 -> 100 50 25 12 6 3 1 0
-   C/ join      "ra"/("ab";"cadab";"") -> "abracadabra"
-   C\ split     "ra"\"abracadabra" -> ("ab";"cadab";"")
-   I/ decode    24 60 60/1 2 3 -> 3723   2/1 1 0 1 -> 13
-   I\ encode    24 60 60\3723 -> 1 2 3   2\13 -> 1 1 0 1
-  i': window    3':"abcdef" -> ("abc";"bcd";"cde";"def")
-i f': stencil   3{x,"."}':"abcde" -> ("abc.";"bcd.";"cde.")
-  F': eachprior -':12 13 11 17 14 -> 12 1 -2 6 -3
-x F': seeded ': 10-':12 13 11 17 14 -> 2 1 -2 6 -3
-x F/: eachright 1 2*/:3 4 -> (3 6;4 8)
-x F\: eachleft  1 2*\:3 4 -> (3 4;6 8)
---------------------------------------------------------------------------------

+ 0 - 237
repl.k

@@ -1,237 +0,0 @@
-#!k
-\d repl
-banner:"ngn/k, (c) 2019-2024 ngn, GNU AGPLv3. type \\ for more info\n"
-prompt:," " /use 0x0720 for emacs integration
-(opn;sem;cls):"(;)"
-(opn;sem;cls):("( ";" ; ";" )") /uncomment this line for extra spacing
-lines:cols:999
-upd:{(lines;cols)::`I$"\n"\`x(("/usr/bin/env";"tput";"-S");"lines\ncols\n")}
-lim:{(x<#y)(x#)/y}
-dd:{(x<#y)(,[;".."](x-2)#)/y}
-fmt:{upd[];$[(::)~x;"";(1<#x)&|/`m`M`A=@x;mMA x;(dd[cols]`k@lim[cols]x),"\n"]}
-fmtx:{$[(::)~x;"";`k[x],"\n"]}
-mMA:{(P;f;q):((,"!/+(";dct;,")");(("+![";" +(");tbl;")]");(,,"(";lst;,")"))`m`M`A?t:@x
- w:cols-#*P;u:w-#q;h:lines-2
- x:$[h<(`M=t)+#x;,[;,".."](h-1)#f[w;u;h#x];f[w;u;x]]
- ,[;"\n"]@"\n"/@[;-1+#x;,;q]P[!#x],'x}
-lst:{[w;u;x](((-1+#x)#w),u)dd'`k'lim[cols]'x}
-dct:{[w;u;x]k:(|/#'k)$k:`k'!x;par'(((-1+#x)#w-3),u-3)dd'sem/'+(k;`k'.x)}
-tbl:{[w;u;x]h:`k'!x;d:`k''.x;W:(#'h)|/'#''d
- r:,$[`S~@!x;dd[w](""opn),(""sem)/;par@dd[w-2]@sem/]W$'h
- r,par'dd[w-2]'sem/'+@[W;&~^`i`d?_@'.x;-:]$'d}
-cell:{$[|/`i`d=@y;-x;x]$z}
-par:{opn,x,cls}
-cmds:(,"a")!{`1:1:joinpath[dirname`argv 0]"LICENSE";}
-basename:{*|"/"\x}
-dirname:{$[#x:"/"/-1_"/"\x;x;,"."]}
-joinpath:{$[x~,".";y;"/"~*|x;x,y;x,"/",y]}
-line0:{c:{0x07~*-2#*x}{(l;r):x;(1:1;r,,(-2_l))}/(x;());"\n"/(*|c),,*c}
-line1:{$[#x;;:0];x:-1_x;$[(3>#x)&("\\"=*x)&~^(!cmds)?x 1;cmds[x 1]x 1;.[`1:(fmt;fmtx)[" "~*x]@.:;,x;{`0:`err[]}]];`1:prompt;1}
-line:line1@line0@
-$["repl.k"~basename`argv 1;{cmds::@[cmds;x[1]1;:;{y;`0:x}2_x]}'{(&x~\:80#"-")_x:(1+*&x~\:,"/")_-1_x}@0:`argv 1;];
-run:{`1:banner,prompt;{line@1:`}::/`;}
-\d .
-
-$[(~"kw"~`argv 0)&~"--non-interactive"~*x;repl.run[];]
-
-/
---------------------------------------------------------------------------------
-
-\   help               \\         exit
-\a  license(AGPLv3)    \l file.k  load
-\0  types              \d foo     set namespace; restore with  \d .
-\+  verbs              \t:n expr  time(elapsed milliseconds after n runs)
-\:  I/O verbs          \v         variables
-\'  adverbs            \f         functions
-\`  symbols            \cd path   change directory
-\h  summary            \other     command(through /bin/sh)
---------------------------------------------------------------------------------
-\0
-Types:
-list atom
- `A        generic list   ()   ,"ab"   (0;`1;"2";{3};%)
- `I   `i   int            0N -9223372036854775807 01b
- `F   `f   float          -0w -0.0 0.0 0w 1.2e308 0n
- `C   `c   char           "a"   0x6263   "d\0\"\n\r\t"
- `S   `s   symbol         `   `a   `"file.txt"   `b`cd`"ef"
- `M   `m   table&dict     +`a`b!(0 1;"23")   (0#`)!()
-      `o   lambda         {1+x*y#z}  {[a;b]+/*/2#,a,b}
-      `p   projection     1+   {z}[0;1]   @[;i;;]
-      `q   composition    *|:   1+{x*y}@
-      `r   derived verb   +/   2\   {y,x}':
-      `u   monadic verb   +:   0::
-      `v   dyadic  verb   +   0:
-      `w   adverb         '   /:
-      `x   external func
---------------------------------------------------------------------------------
-\:
-I/O verbs
-  0:x read  lines
-x 0:y write lines
-  1:x read  bytes
-x 1:y write bytes
-   <s open          fd:<`"file.txt"
-   >i close         >fd
-
-x can be a file descriptor (int) or symbol or string such as
- "file.txt"
- "/path/to/file"
- "host:port"
- ":port"         /host defaults to 127.0.0.1
---------------------------------------------------------------------------------
-\+
-Verbs:    : + - * % ! & | < > = ~ , ^ # _ $ ? @ . 0: 1:
-notation: [c]har [i]nt [n]umber(int|float|char) [s]ymbol [a]tom [d]ict
-          [f]unc(monad) [F]unc(dyad) [xyz]any
-special:  var:y     set    a:1;a -> 1
-          var::y    global a:1;{a::2}[];a -> 2
-          (v;..):y  unpack (b;(c;d)):(2 3;4 5);c -> 4
-          :x        return {:x+1;2}[3] -> 4
-          :[x;y;..] cond   :[0;`a;"\0";`b;`;`c;();`d;`e] -> `e
-          o[..]     recur  {:[x<2;x;+/o'x-1 2]}9 -> 34
-          [..]      progn  [0;1;2;3] -> 3
-
-::  self      f:(::);f 12 -> 12
- :  right     f:(:);f[1;2] -> 2   "abc":'"d" -> "ddd"
- +x flip      +("ab";"cd") -> ("ac";"bd")
-N+N add       1 2+3 -> 4 5
- -N negate    - 1 2 -> -1 -2
-N-N subtract  1-2 3 -> -1 -2
- *x first     *`a`b -> `a   *(0 1;"cd") -> 0 1
-N*N multiply  1 2*3 4 -> 3 8
- %N sqrt      %25 -> 5.0   %-1 -> 0n
-N%N divide    2 3%4 -> 0.5 0.75
- !i enum      !3 -> 0 1 2   !-3 -> -3 -2 -1
- !I odometer  !2 3 -> (0 0 0 1 1 1;0 1 2 0 1 2)
- !d keys      !`a`b!0 1 -> `a`b
- !S ns keys   a.b.c:1;a.b.d:2;!`a`b -> `c`d
-x!y dict      `a`b!1 2 -> `a`b!1 2
-i!I div       -10!1234 567 -> 123 56
-i!I mod       10!1234 567 -> 4 7
- &I where     &3 -> 0 0 0   &1 0 1 4 2 -> 0 2 3 3 3 3 4 4
- &x deepwhere &(0 1 0;1 0 0;1 1 1) -> (0 1 2 2 2;1 0 0 1 2)
-N&N min/and   2&-1 3 -> -1 2   0 0 1 1&0 1 0 1 -> 0 0 0 1
- |x reverse   |"abc" -> "cba"   |12 -> 12
-N|N max/or    2|-1 3 -> 2 3   0 0 1 1|0 1 0 1 -> 0 1 1 1
- <X ascend    <"abacus" -> 0 2 1 3 5 4
- >X descend   >"abacus" -> 4 5 3 1 0 2
- <s open      fd:<`"/path/to/file.txt"
- >i close     >fd
-N<N less      0 2<1 -> 1 0
-N>N more      0 1>0 2 -> 0 0
- =X group     ="abracadabra" -> "abrcd"!(0 3 5 7 10;1 8;2 9;,4;,6)
- =i unitmat   =3 -> (1 0 0;0 1 0;0 0 1)
-N=N equal     0 1 2=0 1 3 -> 1 1 0
- ~x not       ~(0 2;``a;"a \0";::;{}) -> (1 0;1 0;0 0 1;1;0)
-x~y match     2 3~2 3 -> 1   "4"~4 -> 0   0~0.0 -> 0
- ,x enlist    ,0 -> ,0   ,0 1 -> ,0 1   ,`a!1 -> +(,`a)!,,1
-x,y concat    0,1 2 -> 0 1 2  "a",1 -> ("a";1)
-d,d merge     (`a`b!0 1),`b`c!2 3 -> `a`b`c!0 2 3
- ^x null      ^(" a";0 1 0N;``a;0.0 0n) -> (1 0;0 0 1;1 0;0 1)
-a^y fill      1^0 0N 2 3 0N -> 0 1 2 3 1   "b"^" " -> "b"
-X^y without   "abracadabra"^"bc" -> "araadara"
- #x length    #"abc" -> 3   #4 -> 1   #`a`b`c!0 1 0 -> 3
-i#y take      5#"abc" -> "abcab"   -5#`a`b`c -> `b`c`a`b`c
-X#d take keys `c`d`f#`a`b`c`d!1 2 3 4 -> `c`d`f!3 4 0N
-I#y reshape   2 3#` -> (```;```)
-f#y replicate (3>#:')#(0;2 1 3;5 4) -> (0;5 4)   {2}#"ab" -> "aabb"
- _n floor     _12.34 -12.34 -> 12 -13
- _c lowercase _"Ab" -> "ab"
-i_Y drop      2_"abcde" -> "cde"   -2_`a`b`c -> ,`a
-X_d drop keys `a`c_`a`b`c!0 1 2 -> (,`b)!,1
-I_Y cut       2 4 4_"abcde" -> ("cd";"";,"e")
-f_Y weed out  (3>#:')_(0;2 1 3;5 4) -> ,2 1 3
-X_i delete    "abcde"_2 -> "abde"
- $x string    $(12;"ab";`cd;+) -> ("12";(,"a";,"b");"cd";,"+")
-i$C pad       5$"abc" -> "abc  "   -3$"a" -> "  a"
-s$y cast      `c$97 -> "a"   `i$-1.2 -> -1   `$"a" -> `a
-s$y int       `I$"-12" -> -12
- ?X distinct  ?"abacus" -> "abcus"
- ?i uniform   ?2 -> 0.6438163747387873 0.8852656305774402 /random
-X?y find      "abcde"?"bfe" -> 1 0N 4
-i?x roll      3?1000 -> 11 398 293   1?0 -> ,-8164324247243690787
-i?x deal      -3?1000 -> 11 398 293 /guaranteed distinct
- @x type      @1 -> `i   @"ab" -> `C   @() -> `A   @(@) -> `v
-x@y apply(1)  {x+1}@2 -> 3   "abc"@1 -> "b"   (`a`b!0 1)@`b -> 1
- .S get       a:1;.`a -> 1   b.c:2;.`b`c -> 2
- .C eval      ."1+2" -> 3
- .d values    .`a`b!0 1 -> 0 1
-x.y apply(n)  {x*y+1}. 2 3 -> 8   (`a`b`c;`d`e`f). 1 0 -> `d
-
-@[x;y;f]   amend  @["ABC";1;_:] -> "AbC"   @[2 3;1;{-x}] -> 2 -3
-@[x;y;F;z] amend  @["abc";1;:;"x"] -> "axc"   @[2 3;0;+;4] -> 6 3
-.[x;y;f]   drill  .[("AB";"CD");1 0;_:] -> ("AB";"cD")
-.[x;y;F;z] drill  .[("ab";"cd");1 0;:;"x"] -> ("ab";"xd")
-.[f;y;f]   try    .[+;1 2;"E:",] -> 3   .[+;1,`;"E:",] -> "E:'type\n"
-?[x;y;z]   splice ?["abcd";1 3;"xyz"] -> "axyzd"
---------------------------------------------------------------------------------
-\`
-Special symbols:
-   `j?C parse json   `j?"{\"a\":1,\"b\":[true,\"c\"]}" -> `a`b!(1.0;(1;,"c"))
-   `k@x pretty-print `k("ab";2 3) -> "(\"ab\";2 3)"
-   `p@C parse k
- `hex@C hexadecimal  `hex"ab" -> "6162"
- `pri@i primes       `pri 20  ->  2 3 5 7 11 13 17 19
-   `x@x fork-exec    `x(("/bin/wc";"-l");"a\nbc\nd\n") -> "3\n"
-   `t[] current time (microseconds)
-`argv[] list of cmd line args (also in global variable x)
- `env[] dict of env variables
-`prng[] `prng@I get/set pseudo-random number generator internal state
-                     s:`prng[];r:9?0;`prng s;r~9?0 -> 1
-        `prng@0 use current time to set state
- `err@C throw error
- `sin@N trigonometry `sin 12.34 -> -0.22444212919135995
- `exp@N exponential  `exp 1 -> 2.7182818284590455
-  `ln@N logarithm    `ln 2 -> 0.6931471805599453
-`exit@i exit
---------------------------------------------------------------------------------
-\'
-Adverbs:   ' / \ ': /: \:
-   f' each1     #'("abc";3 4 5 6) -> 3 4
- x F' each2     2 3#'"ab" -> ("aa";"bbb")
-   X' binsearch 1 3 5 7 9'8 9 0 -> 3 4 -1
-   F/ fold      +/1 2 3 -> 6
-   F\ scan      +\1 2 3 -> 1 3 6
- x F/ seeded /  10+/1 2 3 -> 16
- x F\ seeded \  10+\1 2 3 -> 11 13 16
- i f/ n-do      5(2*)/1 -> 32
- i f\ n-dos     5(2*)\1 -> 1 2 4 8 16 32
- f f/ while     (1<){:[2!x;1+3*x;-2!x]}/3 -> 1
- f f\ whiles    (1<){:[2!x;1+3*x;-2!x]}\3 -> 3 10 5 16 8 4 2 1
-   f/ converge  {1+1.0%x}/1 -> 1.618033988749895
-   f\ converges (-2!)\100 -> 100 50 25 12 6 3 1 0
-   C/ join      "ra"/("ab";"cadab";"") -> "abracadabra"
-   C\ split     "ra"\"abracadabra" -> ("ab";"cadab";"")
-   I/ decode    24 60 60/1 2 3 -> 3723   2/1 1 0 1 -> 13
-   I\ encode    24 60 60\3723 -> 1 2 3   2\13 -> 1 1 0 1
-  i': window    3':"abcdef" -> ("abc";"bcd";"cde";"def")
-i f': stencil   3{x,"."}':"abcde" -> ("abc.";"bcd.";"cde.")
-  F': eachprior -':12 13 11 17 14 -> 12 1 -2 6 -3
-x F': seeded ': 10-':12 13 11 17 14 -> 2 1 -2 6 -3
-x F/: eachright 1 2*/:3 4 -> (3 6;4 8)
-x F\: eachleft  1 2*\:3 4 -> (3 4;6 8)
---------------------------------------------------------------------------------
-\h
-: SET      RETURN    :[c;t;f]     COND
-+ add      flip
-- subtract negate    '  each|slide|bin
-* multiply first     /  fold|join |dec|comment
-% divide   sqrt      \  scan|split|enc|trace
-! mod|dict enum|key  ': eachprior
-& min|and  where     /: eachright
-| max|or   reverse   \: eachleft
-< less     ascend
-> more     descend   /
-= equal    group     multiline comment
-~ match    not       \
-, concat   enlist
-^ without  null      0: lines i/o
-# reshape  length    1: bytes i/o
-_ drop|cut floor
-$ cast     string
-? find|rnd uniq      ?[a;i;b]     splice
-@ apply(1) type      @[x;i;[f;]y] amend
-. apply(n) eval      .[x;i;[f;]y] drill
-grammar:  E:E;e|e e:nve|te| t:n|v v:tA|V n:t[E]|(E)|{E}|N
-limits:   8args 16locals 256globals 256bytecode 2048stack
-\

+ 27 - 0
st.k

@@ -0,0 +1,27 @@
+/ evalST
+/ pass the data generated
+/ by the compiled function
+/ to evalST to get an
+/ action that can be called
+
+// condition vec, actions vec, transition table, table args
+evalST: {[c;a;t;args] eidx:*&c[args]; ts: t[0;eidx]; (a[ts[0]];ts[1])};
+
+/ Actions
+A1: {[] "fan low"};
+A2: {[] "fan med"};
+A3: {[] "fan hig"};
+A4: {[] "heat on"};
+A5: {[] "acpw on"};
+A6: {[] "allp of"};
+
+c: {[args] T:args[0]; isOff:args[1]; (isOff;T<18;T<22;T<26;T<30;T>30)};
+a: (A1;A2;A3;A4;A5;A6);
+t: (((0N;1);(4;5);(1;2);(2;3);(3;4);(5;6));((6;1);(4;5);(0N;2);(2;3);(3;4);(5;6));((6;1);(4;5);(1;2);(0N;3);(3;4);(5;6));((6;1);(4;5);(1;2);(2;3);(0N;4);(5;6));((6;1);(0N;5);(1;2);(2;3);(3;4);(5;6));((6;1);(4;5);(1;2);(2;3);(3;4);(0N;6)));
+s: ("Off";"FanLow";"FanMedium";"FanHigh";"Heating";"Cooling");
+at: (`i;`i;`i); / T, isOff, current state - see c
+
+state: 0;
+(action;state): evalST[c;a;t;(20;0;state)];
+:action
+:s[state]

+ 25 - 0
tempST.csv

@@ -0,0 +1,25 @@
+tempST,State Table,,,,,,,
+States/Events,,E1,E2,E3,E4,E5,E6,
+Off,S1,0N 1,4 5,1 2,2 3,3 4,5 6,
+FanLow,S2,6 1,4 5,0N 2,2 3,3 4,5 6,
+FanMedium,S3,6 1,4 5,1 2,0N 3,3 4,5 6,
+FanHigh,S4,6 1,4 5,1 2,2 3,0N 4,5 6,
+Heating,S5,6 1,0N 5,1 2,2 3,3 4,5 6,
+Cooling,S6,6 1,4 5,1 2,2 3,3 4,0N 6,
+Events,,,,,,,,
+isOff,E1,,,,,,,
+T < 18,E2,,,,,,,
+T < 22,E3,,,,,,,
+T < 26,E4,,,,,,,
+T < 30,E5,,,,,,,
+T > 30,E6,,,,,,,
+Actions,,,,,,,,
+setFan[`l],A1,,,,,,,set fan to low
+setFan[`m],A2,,,,,,,// to medium
+setFan[`h],A3,,,,,,,// to high
+heaterPower[1],A4,,,,,,,
+ACPower[1],A5,,,,,,,
+allPower[0],A6,,,,,,,
+next,A7,,,,,,,
+exit,A8,,,,,,,
+error,A9,,,,,,,

+ 20 - 0
test.k

@@ -0,0 +1,20 @@
+/ example compiled tempST
+/ compiled table into data
+/ calling evalST and passing 
+/ the data generated by tempST
+/ will be passed to evalST
+/ to get executable action
+
+/ Actions
+A1: {[] "fan low"};
+A2: {[] "fan med"};
+A3: {[] "fan hig"};
+A4: {[] "heat on"};
+A5: {[] "acpw on"};
+A6: {[] "allp of"};
+
+// condition vector, action vector, transition table, args types
+c: {[T;isOff] (isOff;T<18;T<22;T<26;T<30;T>30)};
+a: A1 A2 A3 A4 A5 A6;
+t: (((0N;1);(4;5);(1;2);(2;3);(3;4);(5;6));((6;1);(4;5);(0N;2);(2;3);(3;4);(5;6));((6;1);(4;5);(1;2);(0N;3);(3;4);(5;6));((6;1);(4;5);(1;2);(2;3);(0N;4);(5;6));((6;1);(0N;5);(1;2);(2;3);(3;4);(5;6));((6;1);(4;5);(1;2);(2;3);(3;4);(0N;6)));
+at: (`i;`i;`i);

+ 20 - 0
testST.k

@@ -0,0 +1,20 @@
+/ example compiled tempST
+/ compiled table into data
+/ calling evalST and passing 
+/ the data generated by tempST
+/ will be passed to evalST
+/ to get executable action
+
+/ Actions
+A1: {[] "fan low"};
+A2: {[] "fan med"};
+A3: {[] "fan hig"};
+A4: {[] "heat on"};
+A5: {[] "acpw on"};
+A6: {[] "allp of"};
+
+// condition vector, action vector, transition table, args types
+c: {[T;isOff] (isOff;T<18;T<22;T<26;T<30;T>30)};
+a: A1 A2 A3 A4 A5 A6;
+t: (((0N;1);(4;5);(1;2);(2;3);(3;4);(5;6));((6;1);(4;5);(0N;2);(2;3);(3;4);(5;6));((6;1);(4;5);(1;2);(0N;3);(3;4);(5;6));((6;1);(4;5);(1;2);(2;3);(0N;4);(5;6));((6;1);(0N;5);(1;2);(2;3);(3;4);(5;6));((6;1);(4;5);(1;2);(2;3);(3;4);(0N;6)));
+at: (`i;`i);

+ 0 - 55
transpiler.py

@@ -1,55 +0,0 @@
-import csv
-
-# read state table csv
-def parse_st_csv(file_path):
-    with open(file_path, newline='') as csvfile:
-        reader = csv.reader(csvfile)
-        data = [row for row in reader]
-
-    state_table = []
-    events = []
-    actions = []
-
-    section = None
-    for row in data:
-        if row[0] == 'States/Events':
-            section = 'state_table'
-            continue
-        elif row[0] == 'Events':
-            section = 'events'
-            continue
-        elif row[0] == 'Actions':
-            section = 'actions'
-            continue
-
-        if section == 'state_table':
-            state_table.append(row)
-        elif section == 'events':
-            events.append(row)
-        elif section == 'actions':
-            actions.append(row)
-
-    return state_table, events, actions
-
-# state table transpiler
-def transpile_st(state_table, events, actions):
-    # actions 0-n (starting from 0)
-    actions = [a[0] for a in actions]
-
-    # conditions for events
-    conditions = [e[0] for e in events]
-
-    # events on conditions
-    events = [e[2:] for e in events]
-
-    # state names
-    states = [s[0] for s in state_table]
-
-    # columns of state table - event_states[0] is E1
-    # this is used because action/nextstate is choosed based on event
-    event_states = [[erows[i] for erows in state_table] for i in range(2, len(state_table[2]))]
-
-    print(event_states)
-
-state_table, events, actions = parse_st_csv('TTExample.csv')
-transpile_st(state_table, events, actions)