# [JavaScript (Node.js)], <s> 608 597 586 </s> 551 bytes [JavaScript (Node.js)]: https://nodejs.org Takes input as `(source)(input)`, where _input_ is an array containing single characters and/or integers. <!-- language: lang-javascript --> <pre><code>s=>I=>eval([..."@CDEJKLMNQTUWYZ^_bkmqw"].reduce((s,c)=>(a=s.split(c)).join(a.pop()),"(R=X=>(H={},o=P=[],S=[],z=x=p=i=0,gUs[p]?~(j=` 	\n`.indexOf(s[p++]N?j:gK:3,hUgK<2?Mn*2+j):V=n,GUx=z--&&S.pop(y=x),FUg(x=`mbQQ$mS[z+~(b])TSCce((z-=V=b-1,V)$mkJLmyJkTTLH[x]=y$mHD)qR[M1)]=_?R[P@p),V]:_Y_&!kY_&k<0Yp$E?P.popK:pT$^QQQQQqW+yw-yw*yw/y|0w%yN:^QTTo+=Buffer(D)$o+=k$Z.codePointAtKZ`Ct`$`[n-9],x&&eval(x,n=1N<3&&F(n*3+jN(1N(0)||R(1)||owN:^$WqTT$mz=S@kGKbgK?-M0):M0N_p$M1),E^E?g:pZ$HD=I[i++]Y?R[V]:Wz>1?(LmxU=n=>T$$QqqN))Mh(Lk,k,K()J),mx)$Ep=XD[k][email protected]")) </code></pre> [Try it online!](https://tio.run/##bVR/V9pIFP17/RQxm6UzJkTQs38sdcBdobUCs2IGrcYoEAJCIAkklEBtT79WP89@EHd@gYDlwGTy5r773rt3DsP2l3bsTgdRkg3CrvfSQy8xKn5CRe9LewRs0zTV07Ny5aJaq@MGad7c3j08dvzxZK465tTrzlwPgNhwISqCNorNOBoNEuBCaA7DQQDaZhRGAEJDBVfoM8Wco6/fjBBdItsxLLYsUYoiNEA5o9@M7cgpfQdD1FJ@uw9a5iDoeum/PUDjuu7g0rDQrxaOjadmv3pyVKoHB0f6EBauUWB8bKZomc1mMhYvuEApND40@yBFrXGn0dDGlr3Uv4OOA4l1xlpeZtE16mTzxjXUxv5Fbby48Ampndupgxba@LwMJ1d2PQ8d9Fi6si9PI2hcO4XH28fMvk8X/yR3G2mV0iUrVy1ERHtosM/kRl/Ms4v5wWJ@uHjOzf9Y4MJDg5BQR//Mej1vCspQoy@@dme6VO5LKlLyd1K9a50lLa1lB9m/HCPNZLj4qRGgPD45zmQ@gODgWB9ikMcgB5@fr0CeruGckms3E0K08RJZp/7HaqdfLWXrOVio5/BjpNEBjMpDpdQvRHfaeRl9sgdUyFs6ER3mZlnMl0BtnDZRgIpE0xqTCYaw/gRqvuEbVQAvoDFOoVaJ0Oey7Ttn3N1TM5rFdRXCl2SqICVWUFGJ6VWIRm0q7KF52DcUlwVV5T64T1RbtTBR11660IF7iRcnNBcwCQxlEESzBLKUr4obBnE48sxR2AfvCIO57dhTfn@n6Iquu0EC329heiCZchoIgeChgG97FEj5c@/3eCmgWhYh9EsItujW4iumG7byI/HA/GT7iKVZWDwsQbCZ88oot1uRdfZbyHb8F2U2Yetyu@AtvjfNbQzEp6cBbImyRHAQeUqBWDUUW5ojFWPpFIGZIG9OeRRjzFg4zw5CFGcYIpXndJyR/ngaQ4kWCO9zQ3ssA5jITojsnG1kgLwGOIEIrkN0JqEIlmGRKB6Ej8AgDEQEiOkjkqwVIZflKL8eTAooZiFrf@VEsvYOQobFuFj6xHjZ3yshT0@DQRwrili73TCczTqdkecpShxHkee1276/v38fqLvySm2336Sn3LHssaH8uZlFrNVVEB8i3ZBdkl@aza/Yq0eWFN4S94mQHV9WImNORt@lDZJndVPZY30dVibwHRaUK5@kscIdIu3Bwhn1vx8/1e1W5b1jTYhmeVGhD7Ys6TfbibHYmxj45X8 "JavaScript (Node.js) – Try It Online") (all test cases without comments) [Try it online!](https://tio.run/##jVRrc6JIFP3s/IpsirW6I7KazJe10pqsOBMfEBU0Y1jSIrQGkYc8IjjZ@evZBmIeFc0uFl3Vffuec8@5F5fagxbovumFZcc1yNMcPQWo3kZ18qCtgMJx3PFFk291uj1BHMijm8ntHZ5Z9npzrHI@MSKdABCwOkR1oKGAC7yVGQIdQm7pmg7QOM/1AITsMRiiH/TOFfr5D@uiPlJUVkqXLYqRh0xUYRejQPHUxi@wRNOjwt/OlDMdg8TXc0DPSyVVbCxri27tjL0fLbrnpw3BOTktLWFtjBz2@yhG23K5WJQywgTFkP02WoAYTe3ZYMDYkrIt/QIzFcpSMy15W0ZjNCtX2TFkbKvTs5OOJcu9KyVWUcLYVzxcDxWhClWEG0Olf@FBdqzW8AQXf7PoYp1XJh7TavRTum7Nk5m7Qfqsb0rJppxsTpLNH8ljZfN7ItbuBrLsltBf0XxOfMBDhm4s5pbTqd19alJ4GXZvp81wykwVp/ynysbFYmZ@zDqoKp6fFYvfgHNyVlqKoCqCCnx8HIIqXd0NBWdu1rLM2FskXVjfu7NFt1EWKrAmVETsMVQA27prNRY175a54lFbMamRE6qIirnZ1qsN0LPjEXJQXWaYwXotQijcg57FWmwXwA5k7RgyLQ/94BVLbWbdveC8KBCOIXzSXSdwV4RbuQswB1NFOkp/4hfcj4J7XFGVdCMdYT6iaboWkkNnckH8IhfkAh4SzcCSzLdFrAWYWkMWxE/jz9HQN8kDoQEvClUlBcr4mj5JkXrajKxw7/q6v4cmdL2cSDqiUH2fgr/jyIuXC/m7E1GtYIdsVqZDdskU9CVZv9d8TQ/z9FQCljaal1LhcOO@Yr6gpSD5Ib40jPRCvs@uNF0vwaeOgc2Q2P8V26fuVcKrgK85Zeaf4BrRyj2Undb/nNme4wruRHYq5dlVvj1u861PJKXio1mY@vE5Q5a7h0EY9eR2vzf5vxy7eg9VfMnzB9ty2Nm9RCkKvfqCn01YPgwf5@/VqSyJNwNd843d/OXc9PTBNMjbUnKgtJizPSOwL/qhr7kj@93Y1ZzV1IrNkE6xu/A1eyckN@OtkLcN2S8lIxOiVWh6q2SfUe@oc7s@GpY16v138RnSFALltKrS/59/AQ "JavaScript (Node.js) – Try It Online") (an example with a commented source code as input) ### How? Because the code is packed with [RegPack][1], it is more efficient to repeat the same pieces of code over and over rather than defining too many helper functions. The sequences of spaces, tabs and linefeeds are converted to an integer in base 3 with a leading \$1\$ until they match a known value: seq. | mnemonic | base 3 | decimal ------+----------+--------+--------- SS | PSH | 100 | 9 STS | CPY | 1010 | 30 STN | SLI | 1012 | 32 SNS | DUP | 1020 | 33 SNT | SWP | 1021 | 34 SNN | DIS | 1022 | 35 ------+----------+--------+--------- TTS | PUT | 1110 | 39 TTT | GET | 1111 | 40 ------+----------+--------+--------- NSS | LBL | 1200 | 45 NST | JSR | 1201 | 46 NSN | JMP | 1202 | 47 NTS | JZE | 1210 | 48 NTT | JMI | 1211 | 49 NTN | RTN | 1212 | 50 NNN | END | 1222 | 53 ------+----------+--------+--------- TSSS | ADD | 11000 | 108 TSST | SUB | 11001 | 109 TSSN | MUL | 11002 | 110 TSTS | DIV | 11010 | 111 TSTT | MOD | 11011 | 112 ------+----------+--------+--------- TNSS | CHR | 11200 | 126 TNST | INT | 11201 | 127 TNTS | RCH | 11210 | 129 TNTT | RNU | 11211 | 130 The commands are simply stored in a lookup table and executed with `eval()`. Everything is wrapped within the function \$R\$ which is called twice: - First pass (\$X=0\$): the jumps and the stack errors are ignored so that the whole code is parsed linearly and all labels are stored - Second pass (\$X=1\$): the code is executed normally ### Unpacked and formatted <!-- language: lang-javascript --> s => I => ( R = X => ( H = {}, o = P = [], S = [], z = x = p = i = 0, g = n => s[p] ? ~(j = ` \t\n`.indexOf(s[p++])) ? j : g() : 3, h = n => g() < 2 ? h(n * 2 + j) : V = n, G = n => x = z-- && S.pop(y = x), F = n => g( x = [ /* PSH */ "z=S.push(g()?-h(0):h(0))",,,,,,,,,,,,,,,,,,,,, /* CPY */ "z=S.push(S[z+~(g()?-h(0):h(0))])",, /* SLI */ "S.splice((z-=V=g()?-h(0):h(0))-1,V)", /* DUP */ "z=S.push(G()),z=S.push(x)", /* SWP */ "G(),G(),z=S.push(y),z=S.push(x)", /* DIS */ "G()",,,, /* PUT */ "G(),G(),H[x]=y", /* GET */ "z=S.push(H[G()])",,,,, /* LBL */ "R[h(1)]=p", /* JSR */ "h(1),p=X?R[P.push(p),V]:p", /* JMP */ "h(1),p=X?R[V]:p", /* JZE */ "h(1),p=X&!G()?R[V]:p", /* JMI */ "h(1),p=X&G()<0?R[V]:p", /* RTN */ "p=X?P.pop():p",,, /* END */ "p=X?g:p",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, /* ADD */ "z>1?(G(),G(),z=S.push(x+y)):p=X?g:p", /* SUB */ "z>1?(G(),G(),z=S.push(x-y)):p=X?g:p", /* MUL */ "z>1?(G(),G(),z=S.push(x*y)):p=X?g:p", /* DIV */ "z>1?(G(),G(),z=S.push(x/y|0)):p=X?g:p", /* MOD */ "z>1?(G(),G(),z=S.push(x%y)):p=X?g:p",,,,,,,,,,,,,, /* CHR */ "o+=Buffer([G()])", /* INT */ "o+=G()",, /* RCH */ "H[G()]=I[i++].codePointAt()", /* RNU */ "H[G()]=I[i++]" ][n - 9], x && eval(x, n = 1) ) < 3 && F(n * 3 + j) )(1) )(0) || R(1) || o [1]: https://siorki.github.io/regPack.html