1var noun = require('./noun.js'),
2 BigInteger = require('jsbn').BigInteger,
6// a is native, returns native
8 var bits = b.number.bitLength(),
10 part = (full << a) !== bits;
12 return part ? full + 1 : full;
16 return a.number.compareTo(b.number) > 0;
20 return a.number.compareTo(b.number) < 0;
24 return a.number.compareTo(b.number) >= 0;
28 return a.number.compareTo(b.number) <= 0;
32 return new noun.Atom.Atom(a.number.add(b.number));
40 return new noun.Atom.Atom(BigInteger.ONE.shiftLeft(a.number.intValue()));
44 var r = a.number.subtract(b.number);
46 throw new Error("subtract underflow");
49 return new noun.Atom.Atom(r);
53function lsh(a, b, c) {
54 var bits = b.number.shiftLeft(a.number.intValue()).intValue();
55 return new noun.Atom.Atom(c.number.shiftLeft(bits));
58function rsh(a, b, c) {
59 var bits = b.number.shiftLeft(a.number.intValue()).intValue();
60 return new noun.Atom.Atom(c.number.shiftRight(bits));
63// to/from little-endian 32-bit word array, as used in vere
64// TODO: efficiency is horrible here, but can be improved using internals
65function bytesToWords(bytes) {
66 var len = bytes.length,
72 for ( i = 0; i < trim; ++i ) {
78 var words = new Array(size);
79 for ( i = 0, b = 0; i < size; ++i ) {
80 w = (bytes[b++] << 0) & 0x000000FF;
81 w ^= (bytes[b++] << 8) & 0x0000FF00;
82 w ^= (bytes[b++] << 16) & 0x00FF0000;
83 w ^= (bytes[b++] << 24) & 0xFF000000;
89function wordsToBytes(words) {
92 for ( i = 0, b = 0; i < words.length; ++i ) {
94 buf[b++] = 0xff & (w & 0x000000FF);
95 buf[b++] = 0xff & ((w & 0x0000FF00) >>> 8);
96 buf[b++] = 0xff & ((w & 0x00FF0000) >>> 16);
97 buf[b++] = 0xff & ((w & 0xFF000000) >>> 24);
99 // or here. one of the 'get rid of extra zeros' functions.
100 while ( buf[--b] === 0 ) {
106function bytesToAtom(bytes) {
108 for ( var i = bytes.length - 1; i >= 0; --i ) {
109 byt = bytes[i] & 0xff;
110 parts.push(byt < 16 ? ("0" + byt.toString(16)) : byt.toString(16));
112 return new noun.Atom.Atom(new BigInteger(parts.join(''), 16));
115function atomToBytes(atom) {
119function atomToWords(atom) {
120 return bytesToWords(atomToBytes(atom));
123function wordsToAtom(words) {
124 return bytesToAtom(wordsToBytes(words));
127var malt = wordsToAtom;
130function slaq(bloq, len) {
131 return new Array(((len << bloq) + 31) >>> 5);
134// src is atom, all others native
135function chop(met, fum, wid, tou, dst, src) {
136 var buf = atomToWords(src),
138 i, j, mek, baf, bat, hut, san,
139 wuf, wut, waf, raf, wat, rat, hop;
143 mek = ((1 << san) - 1);
147 for ( i = 0; i < wid; ++i ) {
152 hop = ((waf >= len) ? 0 : buf[waf]);
153 hop = ((hop >>> raf) & mek);
154 dst[wat] ^= hop << rat;
163 for ( i = 0; i < wid; ++i ) {
164 wuf = (fum + i) << hut;
165 wut = (tou + i) << hut;
167 for ( j = 0; j < san; ++j ) {
168 dst[wut + j] ^= ((wuf + j) >= len)
176function cut(a, b, c, d) {
177 var ai = a.number.intValue(),
178 bi = b.number.intValue(),
179 ci = c.number.intValue();
181 var len = met(ai, d);
182 if ( zero.equals(c) || bi >= len ) {
185 if ( bi + ci > len ) {
188 if ( 0 === bi && ci === len ) {
192 var sal = slaq(ai, ci);
193 chop(ai, bi, ci, 0, sal, d);
198var maxCat = noun.Atom.fromInt(0xffffffff);
199var catBits = noun.Atom.fromInt(32);
201function end(a, b, c) {
202 if ( gth(a, catBits) ) {
203 throw new Error("Fail");
205 else if ( gth(b, maxCat) ) {
209 var ai = a.number.intValue(),
210 bi = b.number.intValue(),
216 else if ( bi >= len ) {
220 var sal = slaq(ai, bi);
221 chop(ai, 0, bi, 0, sal, c);
228 return new noun.Atom.Atom(a.number.xor(b.number));
231function cat(a, b, c) {
232 if ( gth(a, catBits) ) {
233 throw new Error("Fail");
236 var ai = a.number.intValue(),
245 var sal = slaq(ai, all);
246 chop(ai, 0, lew, 0, sal, b);
247 chop(ai, 0, ler, lew, sal, c);
254 if ( gth(a, catBits) ) {
255 throw new Error("Fail");
258 var ai = a.number.intValue(),
261 pos, i_cab, pi_cab, qi_cab;
265 if ( zero.equals(cab) ) {
269 throw new Error("Fail");
273 throw new Error("Fail");
277 if ( gth(pi_cab, maxCat) ) {
278 throw new Error("Fail");
281 throw new Error("Fail");
283 if ( (tot + pi_cab) < tot ) {
284 throw new Error("Fail");
292 var sal = slaq(ai, tot);
294 // chop the list atoms in
297 while ( !zero.equals(cab) ) {
299 pi_cab = i_cab.head.number.intValue();
302 chop(ai, 0, pi_cab, pos, sal, qi_cab);
327 bytesToWords: bytesToWords,
328 wordsToBytes: wordsToBytes,
329 bytesToAtom: bytesToAtom,
330 atomToBytes: atomToBytes,
331 atomToWords: atomToWords,
332 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