Created
June 22, 2019 02:41
-
-
Save n4o847/02f7bb20ddff19cc6d85224cd637940b to your computer and use it in GitHub Desktop.
This file contains 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
// https://github.com/hakatashi/unicue-lang | |
// http://unicode.org/ucd/ | |
const fs = require("fs") | |
const parser = require("codepoints/parser") | |
const codepoints = parser("UCD") | |
let res = "" | |
let depth = 0 | |
function out(code) { | |
const info = codepoints[code] | |
if (info.category === "Ps") { | |
if (info.script !== "Common") throw new Error("Ps but not Common"); | |
} | |
if (info.category === "Pe") { | |
if (info.script !== "Common") throw new Error("Pe but not Common"); | |
} | |
if (info.numeric.match(/^[\d/]+$/)) { | |
if (info.script !== "Common") throw new Error("Numeric but not Common"); | |
} | |
process.stdout.write(" ".repeat(depth * 2)) | |
console.log(code.toString(16), info.category, info.script, info.numeric) | |
res += String.fromCodePoint(code) | |
} | |
function exec(main) { | |
main() | |
fs.writeFile("./unicue.txt", res, "utf8", (err, data) => { | |
if (err) { | |
console.log(err) | |
} else { | |
console.log("done") | |
} | |
}) | |
} | |
function gen(from, to) { | |
let i = from; | |
return () => { | |
out(i) | |
i++ | |
} | |
} | |
const nums = { | |
0: [0x0030, 0x2070, 0x2080, 0x2189, 0x24EA, 0x24FF], | |
1: [0x0031, 0x00B9, 0x2081, 0x2460, 0x2474, 0x2488, 0x24F5, 0x2776], | |
2: [0x0032, 0x00B2, 0x2082, 0x2461], | |
3: [0x0033, 0x00B3, 0x2083], | |
4: [0x0034], | |
5: [0x0035], | |
6: [0x0036], | |
7: [0x0037, 0x2087, 0x2466, 0x247A], | |
8: [0x0038, 0x2088, 0x2467], | |
9: [0x0039, 0x2089, 0x2468], | |
10: [0x2469, 0x247D, 0x2491, 0x24FE] | |
} | |
function push_(a) { | |
out(nums[a].shift()) | |
} | |
// function add_(a) { } | |
// function sub_(a) { } | |
// function mul_(a) { } | |
// function div_(a) { } | |
// function mod_(a) { } | |
// function fwd_(a) { } | |
const pairs = [ | |
[0x0028, 0x0029], | |
[0x005B, 0x005D], | |
[0x007B, 0x007D], | |
// [0x0F3A, 0x0F3B], | |
// [0x0F3C, 0x0F3D], | |
// [0x169B, 0x169C], | |
[0x2045, 0x2046], [0x207D, 0x207E], [0x208D, 0x208E], [0x2308, 0x2309], [0x230A, 0x230B], [0x2329, 0x232A], [0x2768, 0x2769], [0x276A, 0x276B], [0x276C, 0x276D], [0x276E, 0x276F], [0x2770, 0x2771], [0x2772, 0x2773], [0x2774, 0x2775], [0x27C5, 0x27C6], [0x27E6, 0x27E7], [0x27E8, 0x27E9], [0x27EA, 0x27EB], [0x27EC, 0x27ED], [0x27EE, 0x27EF], [0x2983, 0x2984], [0x2985, 0x2986], [0x2987, 0x2988], [0x2989, 0x298A], [0x298B, 0x298C], [0x298D, 0x2990], [0x298F, 0x298E], [0x2991, 0x2992], [0x2993, 0x2994], [0x2995, 0x2996], [0x2997, 0x2998], [0x29D8, 0x29D9], [0x29DA, 0x29DB], [0x29FC, 0x29FD], [0x2E22, 0x2E23], [0x2E24, 0x2E25], [0x2E26, 0x2E27], [0x2E28, 0x2E29], [0x3008, 0x3009], [0x300A, 0x300B], [0x300C, 0x300D], [0x300E, 0x300F], [0x3010, 0x3011], [0x3014, 0x3015], [0x3016, 0x3017], [0x3018, 0x3019], [0x301A, 0x301B], [0xFE59, 0xFE5A], [0xFE5B, 0xFE5C], [0xFE5D, 0xFE5E], [0xFF08, 0xFF09], [0xFF3B, 0xFF3D], [0xFF5B, 0xFF5D], [0xFF5F, 0xFF60], [0xFF62, 0xFF63],]; | |
const loop = (function () { | |
let i = 0; | |
return (a) => { | |
let j = i | |
out(pairs[j][0]) | |
i++ | |
depth++ | |
a() | |
depth-- | |
out(pairs[j][1]) | |
} | |
})() | |
const swap = gen(0x11600, 0x1165F) | |
const pop = gen(0x13000, 0x1342F) | |
const read = gen(0x10600, 0x1077F) | |
const write = gen(0x10000, 0x1013F) // どこまで? | |
// const neg = gen(0x1BC0, 0x1BFF) | |
const dup = gen(0x16A0, 0x16FF) | |
// const dup3 = gen(0x0E00, 0x0E7F) | |
const add = gen(0x3041, 0x309F) | |
// const sub = gen(0x30A0, 0x30FF) | |
const mul = gen(0x0C00, 0x0C7F) | |
// const div = gen(0x10A0, 0x10FF) | |
const eq = gen(0x1000, 0x109F) | |
const gt = gen(0x0C80, 0x0CFF) | |
const lt = gen(0x0900, 0x097F) | |
// const and = gen(0x0400, 0x04FF) | |
// const or = gen(0x0600, 0x06FF) | |
// const not = gen(0x0700, 0x074F) | |
// dup(); push_(6); push_(8); mul(); add(); write() | |
exec(() => { | |
push_(0) // 0 | |
push_(1) // 0 1 | |
push_(1) // workaround | |
loop(() => { | |
pop() // workaround | |
pop() // x | |
read() // x c | |
dup() // x c c | |
push_(9) // x c c 9 | |
push_(9) // x c c 9 9 | |
mul() // x c c 81 | |
push_(3) // x c c 81 3 | |
add() // x c c 84 | |
eq() // x c (c == 84) | |
loop(() => { | |
pop() // x c | |
swap() // c x | |
pop() // c | |
push_(0) // c 0 | |
swap() // 0 c | |
push_(0) // 0 c 0 | |
}) | |
pop() // x c | |
dup() // x c c | |
push_(8) // x c c 8 | |
push_(9) // x c c 8 9 | |
mul() // x c c 72 | |
push_(3) // x c c 72 3 | |
add() // x c c 75 | |
eq() // x c (c == 75) | |
loop(() => { | |
pop() // x c | |
swap() // c x | |
push_(1) // c x 1 | |
push_(10) // workaround | |
loop(() => { | |
pop() // workaround | |
pop() // c x | |
swap() // x c | |
dup() // x c c | |
write() // x c | |
swap() // c x | |
push_(1) // c x 1 | |
add() // c x' | |
dup() // c x' x' | |
push_(7) // c x' x' 7 | |
push_(7) // c x' x' 7 7 | |
mul() // c x' x' 49 | |
push_(2) // c x' x' 49 2 | |
add() // c x' x' 51 | |
gt() // c x' (x' < 51) | |
}) | |
pop() // c x' | |
swap() // x' c | |
push_(0) // x' c 0 | |
}) | |
pop() // x c | |
swap() // c x | |
push_(1) // c x 1 | |
add() // c x' | |
dup() // c x' x' | |
push_(7) // c x' x' 7 | |
push_(7) // c x' x' 7 7 | |
mul() // c x' x' 49 | |
push_(2) // c x' x' 49 2 | |
add() // c x' x' 51 | |
eq() // c x' (x' == 51) | |
loop(() => { | |
pop() // c x' | |
pop() // c | |
push_(0) // c 0 | |
swap() // 0 c | |
push_(1) // 0 c 1 | |
add() // 0 c' | |
push_(4) // ? | |
push_(8) // ? | |
mul() // ? | |
write() // ? | |
swap() // c' 0 | |
dup() // c' 0 0 | |
}) | |
pop() // c x' | |
swap() // x' c | |
dup() // x' c c | |
push_(1) // x' c c 1 | |
lt() // x' c (c > 1) | |
loop(() => { | |
pop() // x' c | |
dup() // x' c c | |
write() // x' c | |
push_(0) // x' c 0 | |
}) | |
pop() // x' c | |
push_(1) // x' c 1 | |
lt() // x' (c > 1) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment