PageSourceSearch

https://none-none1.github.io/Interpret-Esolangs-Online/actionlang.js

js none-none1.github.io collected 2026-10-03 09:41:35 UTC 2,524 bytes, 49 lines download raw bytes

1// This is a public domain yet unofficial interpreter for ActionLang. Please refer to the esolang page for more information.
2// Modified by User:None1
3function actionlang(code,input){
4	tmp=code.split('\n');
5	code=[[]];
6	output='';
7	for(let i of tmp){code.push(i.split(','))}
8	h=1;l=0;stack=[];ip=0;R=q=>BigInt(Math.floor(Math.random()*q))
9	next=_=>ip>=input.length?-1n:BigInt(input.codePointAt(ip++));
10	q=function(){let c=0n,u=1n,z=next();while(z<48n||z>57n){if(z==45n)u=-u;z=next();}
11	while(z>=48n&&z<=57n){c=10n*c+z-48n;z=next();}ip--;return c*u;}
12	code=code.map(b=>b.map(c=>[c,null]));
13	while(h<code.length){switch(code[h][l][0]){
14	case'input':stack.push(code[h][l][1]=q());break;
15	case'output':output+=(''+stack.pop());code[h][l][1]=null;break;
16	case'read':
17	case'getchar':stack.push(code[h][l][1]=next());break;
18	case'write':
19	case'putchar':output+=(String.fromCodePoint(+(""+stack.pop())));code[h][l][1]=null;break;
20	case'jump':
21	case'jmp':C=stack.pop();L=stack.pop();if(C)h=L,l=-1;break;
22	case'nop':
23	case'APLWSI':break;
24	case'duplicate':
25	case'dup':stack.push(stack[stack.length-1]);code[h][l][1]=null;break;
26	case'halt':return output;
27	case'discard':stack.pop();code[h][l][1]=null;break; //I assume that discard don't store the value
28	case'discard-store':
29	case'dst':code[h][l][1]=stack.pop();break;          //so I made up a command that stores it
30	case'add':C=stack.pop();stack.push(stack.pop()+C);break;
31	case'substract':
32	case'sub':C=stack.pop();stack.push(stack.pop()-C);break;
33	case'multiply':
34	case'mul':C=stack.pop();stack.push(stack.pop()*C);break;
35	case'divide':
36	case'div':C=stack.pop();stack.push(stack.pop()/C);break;
37	case'modulus':
38	case'modulo':
39	case'mod':C=stack.pop();stack.push(stack.pop()%C);break;
40	case'up':C=null;for(let j=h-1;j;j--)if(C===null)C=code[j][l][1];if(C!==null)stack.push(C);code[h][l][1]=C;break;
41	case'down':C=null;for(let j=h+1;j<code.length;j++)if(C===null)C=code[j][l][1];if(C!==null)stack.push(C);code[h][l][1]=C;break;
42	case'left':C=null;for(let j=l-1;j;j--)if(C===null)C=code[h][j][1];if(C!==null)stack.push(C);code[h][l][1]=C;break;
43	case'right':C=null;for(let j=l+1;j<code[h].length;j--)if(C===null)C=code[h][j][1];if(C!==null)stack.push(C);code[h][l][1]=C;break;
44	case'random':
45	case'rand':stack.push(code[h][l][1]=R(1e10)*10n**90n+R(1e15)*10n**75n+R(1e15)*10n**45n+R(1e15)*10n**60n+R(1e15)*10n**30n+R(1e15)*10n**15n+R(1e15));break;
46	default:stack.push(code[h][l][1]=+code[h][l][0]||(_=>{throw"invalid number"})())
47	}if(++l>=code[h].length)l=0,h++;}
48	return output;
49}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.