JS1K

#2: the original

Source description for demo by Peter van der Zee.

//function A(){x=0;while(((x|=0)||m[c]!=']')&&m[c+1])x+=(G=m[c++])=='['||G==']'&&-1}function B(){x=0;while(((x|=0)||m[c]!='[')&&m[c-1])x+=(G=m[c--])==']'||G=='['&&-1} //function A(_,I){x=0;while(((x|=0)||m[c]!=(I?'[':']'))&&m[c+(I?-1:1)])x+=(G=m[(I?c--:c++)])==(I?']':'[')||G==(I?'[':']')&&-1}function B(){A(0,1)} ',[.'; function A(I,J){//J=0:jump back, J=1:jump forward,I=(J?B:C) while(x||m[c]!=I&&c>=0&&m[c+J]) // g[Z]=m[L='substr'](0,c)+'<u style="background:#ccc;">'+b+'</u>'+m[L](c+1), // update position in while // v[4][Q] = x+" "+c+" "+I+" "+J+" "+(c>=J|m[c+J])+" ", // debug in stack output x+=(G=m[J?c--:c++])==(J?C:B)||G==I&&-1 } /* m[c+(Y?-1:1)] Y?c>=0:m[c+1] c>=Y|m[c+Y] */ //function E(){H(f,M);H(g,N);H(a,M);H(e,O);l=setInterval(D,5)}function F(){H(f,N);H(g,M);H(a,O);H(e,M);T(l)} //function E(_,I){H(f,I?N:M);H(g,I?M:N);H(a,I?O:M);H(e,I?M:O);I?T(l):l=setInterval(D,5)}function F(){E(0,1)} //function E(){H(f,Y?N:M);H(g,Y?M:N);H(a,Y?O:M);H(v[11],Y?M:O);Y?T(l):l=setInterval(D,5)}function F(){Y=E(Y=1)} z=document.body,T=clearInterval,S=String.fromCharCode; z[Z='innerHTML']='<pre><u>Reset</u> <u>Step</u> <u>Start</u> <u>Stop</u>\nStack: <input> Steps: <b></b>\nCode[<b></b>]=<b></b> Data[<b></b>]=<b></b><input><b></b><textarea></textarea><q></q><q></q></pre>'; v=z[v='children'][0][v]; a=v[10]; // input input a[Q='value']='Hi JS1K!'; f=v[12]; // source f[Q]='+><,[.[-],]'; //f[Q]='++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.[,.]'; g=v[13]; // input locator E=v[1][z='onclick']= // step function(){ !(b=m[c])?F(): // g[Z]=m, g[Z]=m[L='substr'](0,c)+'<u style=background:red>'+b+'</u>'+m[L](c+1), g[K][X]=N, // show source position when stepping R=s[d]|=x=0, b=='>'&&++d, b=='<'&&--d, b=='+'&&++s[d], b=='-'&&--s[d], //b=='-'&&(s[d]=0), b=='.'&&(j[Z]+=S(R)+(++k%80?'':'\n')), // output //b==','&&(n?((s[d]=n.charCodeAt(0)),n=n[L](1)):s[d]=0), b==','&&(s[d]=n.charCodeAt(0)|0,v[11][Z]=(n=n[L](1))||' ') // input b==(B='[')&!R&&A(C,0,++c), b==(C=']')&&R&&A(B,1,--c), ++c, v[7][Z]=b, // code (increase after last usage) v[9][Z]=S(s[v[8][Z]=d&=32767]&=255), // data v[4][Q]=s.join(), // stack v[5][Z]=++o // steps }; // reset function (also an event when editing input/source and pressing the R link) (f[$='onkeyup']=a[$]=v[l=0][z]=function(){ T(l); s=[Y=o=c=d=k=0]; n=a[Q]; m=f[Q]; F((j=v[14])[Z]='') //i=-1;while((i+=80)<m.length)m=m[L](0,i)+'\n'+m[L](i); })( // reset is immediately invoked // start and stop (E) func defs and event hooking (as the call arguments for invoking reset, note that they execute first, then the reset, which is no problem) v[3][z]=F=function(){Y=(v[2][z]=function(){ //function H(I,J){I[K].display=J}H(f,Y?N:M);H(g,Y?M:N);H(a,Y?O:M);H(v[11],Y?M:O); f[K='style'][X='display']=a[K][X]=Y?N='block':M; g[K][X]=v[11][K][X]=Y?M='none':N; Y?T(l):l=setInterval(E,1) })(Y=1)} )