Skip to content

Instantly share code, notes, and snippets.

@MinecraftPublisher
Last active March 6, 2022 04:51
Show Gist options
  • Select an option

  • Save MinecraftPublisher/5a87937a7a3d9109b08970de7b1e09b4 to your computer and use it in GitHub Desktop.

Select an option

Save MinecraftPublisher/5a87937a7a3d9109b08970de7b1e09b4 to your computer and use it in GitHub Desktop.
"J", The smallest interpreter ever, probably.

"J"

Click here to go to the original "J" tweet

Release logs

  • Minification improvements by @19wintersp
  • Added a return value of 'true'

Minified Filesize

Filesize: 520 bytes Character count: 519

Documentation

"J" works with new lines, Which means no minification is possible. The syntax on each line must be [command] [args], Which it could range anywhere from importing another script, or just running a clear command. Plus, "J" only works with the browser!

Planned features

  • Functions
  • Custom stdin/stdout/stdclear

Available commands

  • import <url>: Imports another "J" script with the same function and memory variables. Note that changing variables are not supported yet.
  • log <text>: Well, Logs to console.
  • clear: Clears the console.
  • repeat [number] <command>: Repeats a certain command a certain amount of times.
  • eval_i <url>: Fetches a javascript file and evaluates it.
  • eval <javascript>: Runs javascript directly from "J" code. (does not support line breaks)
j = ((e = "", f = {}, m = {}) =>
{
for (r of (p = "length", q = console, f.import = (async a => j(await (await fetch(a)).text(), f, m)), f.log = (a => q.log(a)), f.clear = (() => q.clear()), f.repeat = ((a, t, e, r, c = parseInt(a.split(" ")[0]), l = a.substring(("" + c)[p] + 1, a[p])) =>
{
for (q.log(a, ".", c, ".", l), y = 0; y < c; y++) j(l, f, m)
}), f.eval_i = (async a => eval(await fetch(a).then(a => a.text()))), f.eval = eval, h = e.split("\n"), h)) c = r.split(" ")[0], a = r.substring(c[p] + 1, r[p]), f[c] ? f[c](a, c, r, h) : m["-" + c] ? j(m["-" + c], f, m) : f.log("command not found: " + c + " at line " + h[r]);
return !0
});
j=((e="",f={},m={})=>{for(r of(p="length",q=console,f.import=(async a=>j(await(await fetch(a)).text(),f,m)),f.log=(a=>q.log(a)),f.clear=(()=>q.clear()),f.repeat=((a,t,e,r,c=parseInt(a.split(" ")[0]),l=a.substring((""+c)[p]+1,a[p]))=>{for(q.log(a,".",c,".",l),y=0;y<c;y++)j(l,f,m)}),f.eval_i=(async a=>eval(await fetch(a).then(a=>a.text()))),f.eval=eval,h=e.split("\n"),h))c=r.split(" ")[0],a=r.substring(c[p]+1,r[p]),f[c]?f[c](a,c,r,h):m["-"+c]?j(m["-"+c],f,m):f.log("command not found: "+c+" at line "+h[r]);return!0});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment