-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.minml
125 lines (100 loc) · 3.88 KB
/
core.minml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
let try x y = quote!
js! "(() => {
try {
return " (unquote! x) ";
} catch (e) {
return (" (unquote! y) ")(e);
}
})()"
let call_later f = quote! js! "setTimeout(() => " (unquote! f) ")"
let inline x = quote! js! "/*@__INLINE__*/ " (unquote! x)
let if x y z = quote! js! "(" (unquote! x) " ? " (unquote! y) " : " (unquote! z) ")"
let for_each x =
| Statement [Func {Pattern (StructPattern [patt, ipatt]), body}] -> quote! js! "(() => {
let __x = " (unquote! x) ".slice(1);
for (let __z = 0; __z < __x.length; __z++) {
let __y = __x[__z];
" (unquote! Let {patt, quote! js! "__y"}) ";
" (unquote! Let {ipatt, quote! js! "__z"}) ";
" (unquote! body) ";
}
})()"
| Statement [Func {patt, body}] -> quote! js! "(() => {
for (let __z of " (unquote! x) ".slice(1)) {
" (unquote! Let {patt, quote! js! "__z"}) ";
" (unquote! body) ";
}
})()"
| x -> js! "console.log(x)"
let not x = js! "!x"
let do x = x
let flip f x y = f y x
let match x y = quote! js! "(" (unquote! y) ")(" (unquote! x) ")"
let eq =
js! "(() => {
var envHasBigInt64Array = typeof BigInt64Array !== 'undefined';
return function equal(a, b) {
if (a === b) {
return true;
}
if (a && b && typeof a == 'object' && typeof b == 'object') {
if (a.constructor !== b.constructor) {
return false;
}
var length, i, keys;
if (Array.isArray(a)) {
length = a.length;
if (length != b.length) return false;
for (i = length; i-- !== 0;)
if (!equal(a[i], b[i])) return false;
return true;
}
if ((a instanceof Map) && (b instanceof Map)) {
if (a.size !== b.size) return false;
for (i of a.entries())
if (!b.has(i[0])) return false;
for (i of a.entries())
if (!equal(i[1], b.get(i[0]))) return false;
return true;
}
if ((a instanceof Set) && (b instanceof Set)) {
if (a.size !== b.size) return false;
for (i of a.entries())
if (!b.has(i[0])) return false;
return true;
}
if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
length = a.length;
if (length != b.length) return false;
for (i = length; i-- !== 0;)
if (a[i] !== b[i]) return false;
return true;
}
if (a.constructor === RegExp) {
return a.source === b.source && a.flags === b.flags;
}
if (a.valueOf !== Object.prototype.valueOf) {
return a.valueOf() === b.valueOf();
}
if (a.toString !== Object.prototype.toString) {
return a.toString() === b.toString();
}
keys = Object.keys(a);
length = keys.length;
if (length !== Object.keys(b).length) {
return false;
}
for (i = length; i-- !== 0;) {
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) {
return false;
}
}
for (i = length; i-- !== 0;) {
var key = keys[i];
if (!equal(a[key], b[key])) return false;
}
return true;
}
return a!==a && b!==b;
};
})();"