1import noun from './noun.js';
2import { BigInteger } from 'jsbn';
3var zero = noun.Atom.yes, one = noun.Atom.no;
5// a is native, returns native
7 var bits = b.number.bitLength(),
9 part = (full << a) !== bits;
11 return part ? full + 1 : full;
15 return a.number.compareTo(b.number) > 0;
19 return a.number.compareTo(b.number) < 0;
23 return a.number.compareTo(b.number) >= 0;
27 return a.number.compareTo(b.number) <= 0;
31 return new noun.Atom.Atom(a.number.add(b.number));
39 return new noun.Atom.Atom(BigInteger.ONE.shiftLeft(a.number.intValue()));
43 var r = a.number.subtract(b.number);
45 throw new Error("subtract underflow");
48 return new noun.Atom.Atom(r);
52function lsh(a, b, c) {
53 var bits = b.number.shiftLeft(a.number.intValue()).intValue();
54 return new noun.Atom.Atom(c.number.shiftLeft(bits));
57function rsh(a, b, c) {
58 var bits = b.number.shiftLeft(a.number.intValue()).intValue();
59 return new noun.Atom.Atom(c.number.shiftRight(bits));
62// to/from little-endian 32-bit word array, as used in vere
63// TODO: efficiency is horrible here, but can be improved using internals
64function bytesToWords(bytes) {
65 var len = bytes.length,
71 for ( i = 0; i < trim; ++i ) {
77 var words = new Array(size);
78 for ( i = 0, b = 0; i < size; ++i ) {
79 w = (bytes[b++] << 0) & 0x000000FF;
80 w ^= (bytes[b++] << 8) & 0x0000FF00;
81 w ^= (bytes[b++] << 16) & 0x00FF0000;
82 w ^= (bytes[b++] << 24) & 0xFF000000;
88function wordsToBytes(words) {
91 for ( i = 0, b = 0; i < words.length; ++i ) {
93 buf[b++] = 0xff & (w & 0x000000FF);
94 buf[b++] = 0xff & ((w & 0x0000FF00) >>> 8);
95 buf[b++] = 0xff & ((w & 0x00FF0000) >>> 16);
96 buf[b++] = 0xff & ((w & 0xFF000000) >>> 24);
98 // or here. one of the 'get rid of extra zeros' functions.
99 while ( buf[--b] === 0 ) {
105function bytesToAtom(bytes) {
107 for ( var i = bytes.length - 1; i >= 0; --i ) {
108 byt = bytes[i] & 0xff;
109 parts.push(byt < 16 ? ("0" + byt.toString(16)) : byt.toString(16));
111 return new noun.Atom.Atom(new BigInteger(parts.join(''), 16));
114function atomToBytes(atom) {
118function atomToWords(atom) {
119 return bytesToWords(atomToBytes(atom));
122function wordsToAtom(words) {
123 return bytesToAtom(wordsToBytes(words));
126var malt = wordsToAtom;
129function slaq(bloq, len) {
130 return new Array(((len << bloq) + 31) >>> 5);
133// src is atom, all others native
134function chop(met, fum, wid, tou, dst, src) {
135 var buf = atomToWords(src),
137 i, j, mek, baf, bat, hut, san,
138 wuf, wut, waf, raf, wat, rat, hop;
142 mek = ((1 << san) - 1);
146 for ( i = 0; i < wid; ++i ) {
151 hop = ((waf >= len) ? 0 : buf[waf]);
152 hop = ((hop >>> raf) & mek);
153 dst[wat] ^= hop << rat;
162 for ( i = 0; i < wid; ++i ) {
163 wuf = (fum + i) << hut;
164 wut = (tou + i) << hut;
166 for ( j = 0; j < san; ++j ) {
167 dst[wut + j] ^= ((wuf + j) >= len)
175function cut(a, b, c, d) {
176 var ai = a.number.intValue(),
177 bi = b.number.intValue(),
178 ci = c.number.intValue();
180 var len = met(ai, d);
181 if ( zero.equals(c) || bi >= len ) {
184 if ( bi + ci > len ) {
187 if ( 0 === bi && ci === len ) {
191 var sal = slaq(ai, ci);
192 chop(ai, bi, ci, 0, sal, d);
197var maxCat = noun.Atom.fromInt(0xffffffff);
198var catBits = noun.Atom.fromInt(32);
200function end(a, b, c) {
201 if ( gth(a, catBits) ) {
202 throw new Error("Fail");
204 else if ( gth(b, maxCat) ) {
208 var ai = a.number.intValue(),
209 bi = b.number.intValue(),
215 else if ( bi >= len ) {
219 var sal = slaq(ai, bi);
220 chop(ai, 0, bi, 0, sal, c);
227 return new noun.Atom.Atom(a.number.xor(b.number));
230function cat(a, b, c) {
231 if ( gth(a, catBits) ) {
232 throw new Error("Fail");
235 var ai = a.number.intValue(),
244 var sal = slaq(ai, all);
245 chop(ai, 0, lew, 0, sal, b);
246 chop(ai, 0, ler, lew, sal, c);
253 if ( gth(a, catBits) ) {
254 throw new Error("Fail");
257 var ai = a.number.intValue(),
260 pos, i_cab, pi_cab, qi_cab;
264 if ( zero.equals(cab) ) {
268 throw new Error("Fail");
272 throw new Error("Fail");
276 if ( gth(pi_cab, maxCat) ) {
277 throw new Error("Fail");
280 throw new Error("Fail");
282 if ( (tot + pi_cab) < tot ) {
283 throw new Error("Fail");
291 var sal = slaq(ai, tot);
293 // chop the list atoms in
296 while ( !zero.equals(cab) ) {
298 pi_cab = i_cab.head.number.intValue();
301 chop(ai, 0, pi_cab, pos, sal, qi_cab);
326 bytesToWords: bytesToWords,
327 wordsToBytes: wordsToBytes,
328 bytesToAtom: bytesToAtom,
329 atomToBytes: atomToBytes,
330 atomToWords: atomToWords,
331 wordsToAtom: wordsToAtom,
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list