@thi.ng/pointfree 3.1.53 → 3.1.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/api.js +0 -1
- package/array.js +150 -358
- package/binary.js +16 -43
- package/cond.js +38 -74
- package/context.js +7 -11
- package/dataflow.js +55 -169
- package/env.js +24 -63
- package/index.js +9 -2
- package/io.js +8 -11
- package/logic.js +30 -85
- package/loop.js +32 -81
- package/math.js +50 -145
- package/ops.js +42 -71
- package/package.json +11 -9
- package/run.js +18 -37
- package/safe.js +14 -11
- package/stack.js +163 -339
- package/string.js +22 -35
- package/word.js +40 -107
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/api.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/array.js
CHANGED
|
@@ -6,372 +6,164 @@ import { defOp1, defOp2, defOp2v } from "./ops.js";
|
|
|
6
6
|
import { $, $n } from "./safe.js";
|
|
7
7
|
import { invrot, swap } from "./stack.js";
|
|
8
8
|
import { $stackFn, defWord } from "./word.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* Compare:
|
|
19
|
-
*
|
|
20
|
-
* ```
|
|
21
|
-
* // using array literal within word definition
|
|
22
|
-
* foo = pf.word([ [], 1, pf.pushl ])
|
|
23
|
-
* pf.runU(foo)
|
|
24
|
-
* // [ 1 ]
|
|
25
|
-
* pf.runU(foo)
|
|
26
|
-
* // [ 1, 1 ] // wrong!
|
|
27
|
-
*
|
|
28
|
-
* // using `list` instead
|
|
29
|
-
* bar = pf.word([ pf.list, 1, pf.pushl ])
|
|
30
|
-
* pf.runU(bar)
|
|
31
|
-
* // [ 1 ]
|
|
32
|
-
* pf.runU(bar)
|
|
33
|
-
* // [ 1 ] // correct!
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* ( -- [] )
|
|
37
|
-
*
|
|
38
|
-
* @param ctx -
|
|
39
|
-
*/
|
|
40
|
-
export const list = (ctx) => (ctx[0].push([]), ctx);
|
|
41
|
-
/**
|
|
42
|
-
* Pushes new empty JS object on d-stack.
|
|
43
|
-
* Same reasoning as for {@link list}.
|
|
44
|
-
*
|
|
45
|
-
* ( -- {} )
|
|
46
|
-
*
|
|
47
|
-
* @param ctx -
|
|
48
|
-
*/
|
|
49
|
-
export const obj = (ctx) => (ctx[0].push({}), ctx);
|
|
50
|
-
/**
|
|
51
|
-
* Pushes `val` on the LHS of array.
|
|
52
|
-
*
|
|
53
|
-
* ( val arr -- arr )
|
|
54
|
-
*
|
|
55
|
-
* @param ctx -
|
|
56
|
-
*/
|
|
57
|
-
export const pushl = (ctx) => {
|
|
58
|
-
$(ctx[0], 2);
|
|
59
|
-
const stack = ctx[0];
|
|
60
|
-
const a = stack.pop();
|
|
61
|
-
a.unshift(stack.pop());
|
|
62
|
-
stack.push(a);
|
|
63
|
-
return ctx;
|
|
9
|
+
const list = (ctx) => (ctx[0].push([]), ctx);
|
|
10
|
+
const obj = (ctx) => (ctx[0].push({}), ctx);
|
|
11
|
+
const pushl = (ctx) => {
|
|
12
|
+
$(ctx[0], 2);
|
|
13
|
+
const stack = ctx[0];
|
|
14
|
+
const a = stack.pop();
|
|
15
|
+
a.unshift(stack.pop());
|
|
16
|
+
stack.push(a);
|
|
17
|
+
return ctx;
|
|
64
18
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
export const pushr = (ctx) => {
|
|
73
|
-
const stack = ctx[0];
|
|
74
|
-
const n = stack.length - 2;
|
|
75
|
-
$n(n, 0);
|
|
76
|
-
stack[n].push(stack[n + 1]);
|
|
77
|
-
stack.length--;
|
|
78
|
-
return ctx;
|
|
19
|
+
const pushr = (ctx) => {
|
|
20
|
+
const stack = ctx[0];
|
|
21
|
+
const n = stack.length - 2;
|
|
22
|
+
$n(n, 0);
|
|
23
|
+
stack[n].push(stack[n + 1]);
|
|
24
|
+
stack.length--;
|
|
25
|
+
return ctx;
|
|
79
26
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
export const popr = (ctx) => {
|
|
89
|
-
const stack = ctx[0];
|
|
90
|
-
const n = stack.length - 1;
|
|
91
|
-
$n(n, 0);
|
|
92
|
-
const a = stack[n];
|
|
93
|
-
!a.length && illegalState("can't pop empty array");
|
|
94
|
-
stack.push(a.pop());
|
|
95
|
-
return ctx;
|
|
27
|
+
const popr = (ctx) => {
|
|
28
|
+
const stack = ctx[0];
|
|
29
|
+
const n = stack.length - 1;
|
|
30
|
+
$n(n, 0);
|
|
31
|
+
const a = stack[n];
|
|
32
|
+
!a.length && illegalState("can't pop empty array");
|
|
33
|
+
stack.push(a.pop());
|
|
34
|
+
return ctx;
|
|
96
35
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const stack = ctx[0];
|
|
114
|
-
const n = stack.length - 2;
|
|
115
|
-
$n(n, 0);
|
|
116
|
-
const a = stack[n];
|
|
117
|
-
const b = stack[n + 1];
|
|
118
|
-
stack[n + 1] = a.splice(b, a.length - b);
|
|
119
|
-
return ctx;
|
|
36
|
+
const pull = defWord([popr, swap]);
|
|
37
|
+
const pull2 = defWord([pull, pull]);
|
|
38
|
+
const pull3 = defWord([pull2, pull]);
|
|
39
|
+
const pull4 = defWord([pull2, pull2]);
|
|
40
|
+
const vadd = defOp2v((b, a) => a + b);
|
|
41
|
+
const vsub = defOp2v((b, a) => a - b);
|
|
42
|
+
const vmul = defOp2v((b, a) => a * b);
|
|
43
|
+
const vdiv = defOp2v((b, a) => a / b);
|
|
44
|
+
const split = (ctx) => {
|
|
45
|
+
const stack = ctx[0];
|
|
46
|
+
const n = stack.length - 2;
|
|
47
|
+
$n(n, 0);
|
|
48
|
+
const a = stack[n];
|
|
49
|
+
const b = stack[n + 1];
|
|
50
|
+
stack[n + 1] = a.splice(b, a.length - b);
|
|
51
|
+
return ctx;
|
|
120
52
|
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
*/
|
|
128
|
-
export const cat = (ctx) => {
|
|
129
|
-
const stack = ctx[0];
|
|
130
|
-
const n = stack.length - 2;
|
|
131
|
-
$n(n, 0);
|
|
132
|
-
stack[n] = stack[n].concat(stack.pop());
|
|
133
|
-
return ctx;
|
|
53
|
+
const cat = (ctx) => {
|
|
54
|
+
const stack = ctx[0];
|
|
55
|
+
const n = stack.length - 2;
|
|
56
|
+
$n(n, 0);
|
|
57
|
+
stack[n] = stack[n].concat(stack.pop());
|
|
58
|
+
return ctx;
|
|
134
59
|
};
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
*/
|
|
142
|
-
export const catr = (ctx) => {
|
|
143
|
-
const stack = ctx[0];
|
|
144
|
-
const n = stack.length - 2;
|
|
145
|
-
$n(n, 0);
|
|
146
|
-
stack[n] = stack.pop().concat(stack[n]);
|
|
147
|
-
return ctx;
|
|
60
|
+
const catr = (ctx) => {
|
|
61
|
+
const stack = ctx[0];
|
|
62
|
+
const n = stack.length - 2;
|
|
63
|
+
$n(n, 0);
|
|
64
|
+
stack[n] = stack.pop().concat(stack[n]);
|
|
65
|
+
return ctx;
|
|
148
66
|
};
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
* // each item times 10
|
|
161
|
-
* run([[1, 2, 3, 4], [10, mul], mapl])
|
|
162
|
-
* // [ [ 10, 20, 30, 40 ], [], {} ]
|
|
163
|
-
* ```
|
|
164
|
-
*
|
|
165
|
-
* Use for filtering:
|
|
166
|
-
*
|
|
167
|
-
* ```
|
|
168
|
-
* // drop even numbers, duplicate odd ones
|
|
169
|
-
* run([[1, 2, 3, 4], [dup, even, cond(drop, dup)], mapl])
|
|
170
|
-
* // [ [ 1, 1, 3, 3 ], [], {} ]
|
|
171
|
-
* ```
|
|
172
|
-
*
|
|
173
|
-
* Reduction:
|
|
174
|
-
*
|
|
175
|
-
* ```
|
|
176
|
-
* // the `0` is the initial reduction result
|
|
177
|
-
* runU([0, [1, 2, 3, 4], [add], mapl])
|
|
178
|
-
* // 10
|
|
179
|
-
* ```
|
|
180
|
-
*
|
|
181
|
-
* **Important**: {@link mapl} does not produce a result array. However,
|
|
182
|
-
* there're several options to collect results as array, e.g.
|
|
183
|
-
*
|
|
184
|
-
* Use {@link mapll} to transform:
|
|
185
|
-
*
|
|
186
|
-
* @example
|
|
187
|
-
* ```ts
|
|
188
|
-
* runU([[1, 2, 3, 4], [10, mul], mapll])
|
|
189
|
-
* // [ 10, 20, 30, 40]
|
|
190
|
-
* ```
|
|
191
|
-
*
|
|
192
|
-
* Collecting results as array is a form of reduction, so we can use
|
|
193
|
-
* {@link list} to produce an initial new array and {@link pushr} to push each new
|
|
194
|
-
* interim value into the result:
|
|
195
|
-
*
|
|
196
|
-
* @example
|
|
197
|
-
* ```ts
|
|
198
|
-
* runU([list, [1, 2, 3, 4], [10, mul, pushr], mapl])
|
|
199
|
-
* // [ 10, 20, 30, 40 ]
|
|
200
|
-
* ```
|
|
201
|
-
*
|
|
202
|
-
* If the array size is known & not changed by transformation:
|
|
203
|
-
*
|
|
204
|
-
* @example
|
|
205
|
-
* ```ts
|
|
206
|
-
* runU([[1, 2, 3, 4], [10, mul], mapl, 4, collect])
|
|
207
|
-
* // [ 10, 20, 30, 40 ]
|
|
208
|
-
* ```
|
|
209
|
-
*
|
|
210
|
-
* @param ctx -
|
|
211
|
-
*/
|
|
212
|
-
export const mapl = (ctx) => {
|
|
213
|
-
$(ctx[0], 2);
|
|
214
|
-
const stack = ctx[0];
|
|
215
|
-
const w = $stackFn(stack.pop());
|
|
216
|
-
const list = stack.pop();
|
|
217
|
-
const n = list.length;
|
|
218
|
-
for (let i = 0; i < n; i++) {
|
|
219
|
-
ctx[0].push(list[i]);
|
|
220
|
-
ctx = w(ctx);
|
|
221
|
-
}
|
|
222
|
-
return ctx;
|
|
67
|
+
const mapl = (ctx) => {
|
|
68
|
+
$(ctx[0], 2);
|
|
69
|
+
const stack = ctx[0];
|
|
70
|
+
const w = $stackFn(stack.pop());
|
|
71
|
+
const list2 = stack.pop();
|
|
72
|
+
const n = list2.length;
|
|
73
|
+
for (let i = 0; i < n; i++) {
|
|
74
|
+
ctx[0].push(list2[i]);
|
|
75
|
+
ctx = w(ctx);
|
|
76
|
+
}
|
|
77
|
+
return ctx;
|
|
223
78
|
};
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
* // [ [ [ 1, 1, 3, 3 ] ], [], {} ]
|
|
241
|
-
* ```
|
|
242
|
-
*
|
|
243
|
-
* @param ctx -
|
|
244
|
-
*/
|
|
245
|
-
export const mapll = (ctx) => {
|
|
246
|
-
$(ctx[0], 2);
|
|
247
|
-
let stack = ctx[0];
|
|
248
|
-
const w = $stackFn(stack.pop());
|
|
249
|
-
const list = stack.pop();
|
|
250
|
-
const n = list.length;
|
|
251
|
-
let r = 0;
|
|
252
|
-
for (let i = 0; i < n; i++) {
|
|
253
|
-
let m = stack.length;
|
|
254
|
-
stack.push(list[i]);
|
|
255
|
-
ctx = w(ctx);
|
|
256
|
-
stack = ctx[0];
|
|
257
|
-
r += stack.length - m;
|
|
258
|
-
}
|
|
259
|
-
stack.push(stack.splice(stack.length - r, r));
|
|
260
|
-
return ctx;
|
|
79
|
+
const mapll = (ctx) => {
|
|
80
|
+
$(ctx[0], 2);
|
|
81
|
+
let stack = ctx[0];
|
|
82
|
+
const w = $stackFn(stack.pop());
|
|
83
|
+
const list2 = stack.pop();
|
|
84
|
+
const n = list2.length;
|
|
85
|
+
let r = 0;
|
|
86
|
+
for (let i = 0; i < n; i++) {
|
|
87
|
+
let m = stack.length;
|
|
88
|
+
stack.push(list2[i]);
|
|
89
|
+
ctx = w(ctx);
|
|
90
|
+
stack = ctx[0];
|
|
91
|
+
r += stack.length - m;
|
|
92
|
+
}
|
|
93
|
+
stack.push(stack.splice(stack.length - r, r));
|
|
94
|
+
return ctx;
|
|
261
95
|
};
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
* Pops TOS (a number) and then forms a tuple of the top `n` remaining
|
|
271
|
-
* values and pushes it as new TOS. The original collected stack values
|
|
272
|
-
* are removed from d-stack.
|
|
273
|
-
*
|
|
274
|
-
* ( ... n --- ... [...] )
|
|
275
|
-
*
|
|
276
|
-
* @param ctx -
|
|
277
|
-
*/
|
|
278
|
-
export const collect = (ctx) => {
|
|
279
|
-
const stack = ctx[0];
|
|
280
|
-
let n = stack.length - 1, m;
|
|
281
|
-
$n(n, 0);
|
|
282
|
-
$n((n -= m = stack.pop()), 0);
|
|
283
|
-
stack.push(stack.splice(n, m));
|
|
284
|
-
return ctx;
|
|
96
|
+
const foldl = defWord([invrot, mapl]);
|
|
97
|
+
const collect = (ctx) => {
|
|
98
|
+
const stack = ctx[0];
|
|
99
|
+
let n = stack.length - 1, m;
|
|
100
|
+
$n(n, 0);
|
|
101
|
+
$n(n -= m = stack.pop(), 0);
|
|
102
|
+
stack.push(stack.splice(n, m));
|
|
103
|
+
return ctx;
|
|
285
104
|
};
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
export const defJoin = (sep = "") => defOp1((x) => x.join(sep));
|
|
306
|
-
export const join = defOp2((sep, buf) => buf.join(sep));
|
|
307
|
-
/**
|
|
308
|
-
* Pushes length of TOS on d-stack.
|
|
309
|
-
*
|
|
310
|
-
* ( x -- x.length )
|
|
311
|
-
*
|
|
312
|
-
* @param ctx -
|
|
313
|
-
*/
|
|
314
|
-
export const length = defOp1((x) => x.length);
|
|
315
|
-
/**
|
|
316
|
-
* Replaces TOS with its shallow copy. MUST be an array or plain object.
|
|
317
|
-
*
|
|
318
|
-
* ( x -- copy )
|
|
319
|
-
*/
|
|
320
|
-
export const copy = defOp1((x) => isArray(x)
|
|
321
|
-
? x.slice()
|
|
322
|
-
: isPlainObject(x)
|
|
323
|
-
? { ...x }
|
|
324
|
-
: illegalArgs(`can't copy type ${typeof x}`));
|
|
325
|
-
/**
|
|
326
|
-
* Reads key/index from object/array.
|
|
327
|
-
*
|
|
328
|
-
* ( obj k -- obj[k] )
|
|
329
|
-
*
|
|
330
|
-
* @param ctx -
|
|
331
|
-
*/
|
|
332
|
-
export const at = defOp2((b, a) => a[b]);
|
|
333
|
-
/**
|
|
334
|
-
* Writes `val` at key/index in object/array.
|
|
335
|
-
*
|
|
336
|
-
* ( val obj k -- obj )
|
|
337
|
-
*
|
|
338
|
-
* @param ctx -
|
|
339
|
-
*/
|
|
340
|
-
export const setat = (ctx) => {
|
|
341
|
-
const stack = ctx[0];
|
|
342
|
-
const n = stack.length - 3;
|
|
343
|
-
$n(n, 0);
|
|
344
|
-
stack[n + 1][stack[n + 2]] = stack[n];
|
|
345
|
-
stack[n] = stack[n + 1];
|
|
346
|
-
stack.length -= 2;
|
|
347
|
-
return ctx;
|
|
105
|
+
const defTuple = (n) => defWord([n, collect]);
|
|
106
|
+
const vec2 = defTuple(2);
|
|
107
|
+
const vec3 = defTuple(3);
|
|
108
|
+
const vec4 = defTuple(4);
|
|
109
|
+
const defJoin = (sep = "") => defOp1((x) => x.join(sep));
|
|
110
|
+
const join = defOp2((sep, buf) => buf.join(sep));
|
|
111
|
+
const length = defOp1((x) => x.length);
|
|
112
|
+
const copy = defOp1(
|
|
113
|
+
(x) => isArray(x) ? x.slice() : isPlainObject(x) ? { ...x } : illegalArgs(`can't copy type ${typeof x}`)
|
|
114
|
+
);
|
|
115
|
+
const at = defOp2((b, a) => a[b]);
|
|
116
|
+
const setat = (ctx) => {
|
|
117
|
+
const stack = ctx[0];
|
|
118
|
+
const n = stack.length - 3;
|
|
119
|
+
$n(n, 0);
|
|
120
|
+
stack[n + 1][stack[n + 2]] = stack[n];
|
|
121
|
+
stack[n] = stack[n + 1];
|
|
122
|
+
stack.length -= 2;
|
|
123
|
+
return ctx;
|
|
348
124
|
};
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
125
|
+
const bindkeys = (ctx) => {
|
|
126
|
+
const stack = ctx[0];
|
|
127
|
+
$(stack, 2);
|
|
128
|
+
const obj2 = stack.pop();
|
|
129
|
+
const keys = stack.pop();
|
|
130
|
+
$(stack, keys.length);
|
|
131
|
+
for (let i = keys.length - 1; i >= 0; i--) {
|
|
132
|
+
obj2[keys[i]] = stack.pop();
|
|
133
|
+
}
|
|
134
|
+
stack.push(obj2);
|
|
135
|
+
return ctx;
|
|
136
|
+
};
|
|
137
|
+
export {
|
|
138
|
+
at,
|
|
139
|
+
bindkeys,
|
|
140
|
+
cat,
|
|
141
|
+
catr,
|
|
142
|
+
collect,
|
|
143
|
+
copy,
|
|
144
|
+
defJoin,
|
|
145
|
+
defTuple,
|
|
146
|
+
foldl,
|
|
147
|
+
join,
|
|
148
|
+
length,
|
|
149
|
+
list,
|
|
150
|
+
mapl,
|
|
151
|
+
mapll,
|
|
152
|
+
obj,
|
|
153
|
+
popr,
|
|
154
|
+
pull,
|
|
155
|
+
pull2,
|
|
156
|
+
pull3,
|
|
157
|
+
pull4,
|
|
158
|
+
pushl,
|
|
159
|
+
pushr,
|
|
160
|
+
setat,
|
|
161
|
+
split,
|
|
162
|
+
vadd,
|
|
163
|
+
vdiv,
|
|
164
|
+
vec2,
|
|
165
|
+
vec3,
|
|
166
|
+
vec4,
|
|
167
|
+
vmul,
|
|
168
|
+
vsub
|
|
377
169
|
};
|
package/binary.js
CHANGED
|
@@ -1,44 +1,17 @@
|
|
|
1
1
|
import { defOp1, defOp2 } from "./ops.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* @param ctx -
|
|
19
|
-
*/
|
|
20
|
-
export const bitxor = defOp2((b, a) => a ^ b);
|
|
21
|
-
/**
|
|
22
|
-
* ( x -- ~x )
|
|
23
|
-
*
|
|
24
|
-
* @param ctx -
|
|
25
|
-
*/
|
|
26
|
-
export const bitnot = defOp1((x) => ~x);
|
|
27
|
-
/**
|
|
28
|
-
* ( x y -- x<<y )
|
|
29
|
-
*
|
|
30
|
-
* @param ctx -
|
|
31
|
-
*/
|
|
32
|
-
export const lsl = defOp2((b, a) => a << b);
|
|
33
|
-
/**
|
|
34
|
-
* ( x y -- x>>y )
|
|
35
|
-
*
|
|
36
|
-
* @param ctx -
|
|
37
|
-
*/
|
|
38
|
-
export const lsr = defOp2((b, a) => a >> b);
|
|
39
|
-
/**
|
|
40
|
-
* ( x y -- x>>>y )
|
|
41
|
-
*
|
|
42
|
-
* @param ctx -
|
|
43
|
-
*/
|
|
44
|
-
export const lsru = defOp2((b, a) => a >>> b);
|
|
2
|
+
const bitand = defOp2((b, a) => a & b);
|
|
3
|
+
const bitor = defOp2((b, a) => a | b);
|
|
4
|
+
const bitxor = defOp2((b, a) => a ^ b);
|
|
5
|
+
const bitnot = defOp1((x) => ~x);
|
|
6
|
+
const lsl = defOp2((b, a) => a << b);
|
|
7
|
+
const lsr = defOp2((b, a) => a >> b);
|
|
8
|
+
const lsru = defOp2((b, a) => a >>> b);
|
|
9
|
+
export {
|
|
10
|
+
bitand,
|
|
11
|
+
bitnot,
|
|
12
|
+
bitor,
|
|
13
|
+
bitxor,
|
|
14
|
+
lsl,
|
|
15
|
+
lsr,
|
|
16
|
+
lsru
|
|
17
|
+
};
|