Created
July 12, 2021 11:56
-
-
Save followdarko/dc5296c7905de6f7aa6a1cf40a530e57 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Functions: | |
function a(x, y, z) { | |
x[y] = z; | |
} | |
function b(x, p) { | |
for (let i in p) a(x, i, p[i]); | |
} | |
function c() { | |
let x = { foo: 'bar' }; | |
b(x, { foo: 1, bar: 2 }); | |
} | |
// Stack Machine: | |
const OP_A = 1; | |
const OP_B = 2; | |
const OP_C = 3; | |
let firstOp; | |
let lastOp; | |
function op(op, obj, param, data) { | |
const c = { op, obj, param, data: next: undefined }; | |
if (lastOp) lastOp.next = c; | |
else { firstOp = lastOp = c; run(); } | |
} | |
function run() { | |
while (firstOp) { | |
const { obj, param, data } = firstOp; | |
switch (firstOp.op) { | |
case OP_A: | |
obj[param] = data; | |
break; | |
case OP_B: | |
for (let i in param) op(OP_A, obj, i, param[i]); | |
break; | |
case OP_C: { | |
let obj = {}; | |
op(OP_B, obj, { foo: 1, bar: 2 }); | |
break; | |
} | |
} | |
firstOp = firstOp.next; | |
} | |
} | |
op(OP_C); // start! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment