PageRenderTime 84ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/rts/rts-common.js

http://github.com/ghcjs/ghcjs
JavaScript | 2091 lines | 1948 code | 53 blank | 90 comment | 302 complexity | 287c2bad104200e94b55f94acb377b8f MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
  1. var $hs_mkBool = function(b) {
  2. return b ? $$GHCziTypes_True:$$GHCziTypes_False;
  3. };
  4. var $hs_mulIntMayOflozh = function(a, b) {
  5. if(WORD_SIZE_IN_BITS==32) {
  6. var x = a * b;
  7. return x===(x|0)?0:1;
  8. }
  9. else {
  10. return goog.math.Long.fromBits(0,
  11. (a.isNegative()?a.negate():a).getHighBits() |
  12. (b.isNegative()?b.negate():b).getHighBits());
  13. }
  14. };
  15. var $hs_addIntCzh = function(a, b) {
  16. if(WORD_SIZE_IN_BITS==32) {
  17. var x = a + b;
  18. return [x|0, x===(x|0)?0:1];
  19. }
  20. else {
  21. var x = goog.math.Integer.fromBits([a.getLowBits(), a.getHighBits()])
  22. .add(goog.math.Integer.fromBits([b.getLowBits(), b.getHighBits()]));
  23. return [goog.math.Long.fromBits(x.getBits(0), x.getBits(1)),
  24. x.sign_===x.getBits(2)?0:1];
  25. }
  26. };
  27. var $hs_subIntCzh = function(a, b) {
  28. if(WORD_SIZE_IN_BITS==32) {
  29. var x = a - b;
  30. return [x|0, x===(x|0)?0:1];
  31. }
  32. else {
  33. var x = goog.math.Integer.fromBits([a.getLowBits(), a.getHighBits()])
  34. .subtract(goog.math.Integer.fromBits([b.getLowBits(), b.getHighBits()]));
  35. return [goog.math.Long.fromBits(x.getBits(0), x.getBits(1)),
  36. x.sign_===x.getBits(2)?0:1];
  37. }
  38. };
  39. var $hs_ordzh = function(a) {
  40. if(WORD_SIZE_IN_BITS==32) {
  41. return a.charCodeAt();
  42. }
  43. else {
  44. return goog.math.Long.fromNumber(a.charCodeAt());
  45. }
  46. };
  47. var $hs_chrzh = function(a) {
  48. if(WORD_SIZE_IN_BITS==32) {
  49. return String.fromCharCode(a);
  50. }
  51. else {
  52. return String.fromCharCode(a.toNumber());
  53. }
  54. };
  55. var $hs_popCntTab =
  56. [0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
  57. 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
  58. 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
  59. 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
  60. 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
  61. 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
  62. 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
  63. 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8];
  64. var $hs_popCnt8 = function(a) {
  65. return $hs_popCntTab[a & 0xFF];
  66. };
  67. var $hs_popCnt8zh = function(a) {
  68. if(WORD_SIZE_IN_BITS==32) {
  69. return $hs_popCnt8(a);
  70. }
  71. else {
  72. return goog.math.Long.fromNumber(
  73. $hs_popCnt8(a.getLowBits()));
  74. }
  75. };
  76. var $hs_popCnt16zh = function(a) {
  77. if(WORD_SIZE_IN_BITS==32) {
  78. return $hs_popCnt8(a) + $hs_popCnt8(a>>>8);
  79. }
  80. else {
  81. return goog.math.Long.fromNumber(
  82. $hs_popCnt8(a.getLowBits())+$hs_popCnt8(a.getLowBits()>>>8));
  83. }
  84. };
  85. var $hs_popCnt32zh = function(a) {
  86. if(WORD_SIZE_IN_BITS==32) {
  87. return $hs_popCnt8(a) + $hs_popCnt8(a>>>8) + $hs_popCnt8(a>>>16) + $hs_popCnt8(a>>>24);
  88. }
  89. else {
  90. var l = a.getLowBits();
  91. return goog.math.Long.fromNumber(
  92. $hs_popCnt8(l)+$hs_popCnt8(l>>>8) + $hs_popCnt8(l>>>16) + $hs_popCnt8(l>>>24));
  93. }
  94. };
  95. var $hs_popCnt64zh = function(a) {
  96. var l = a.getLowBits();
  97. var h = a.getHighBits();
  98. var result =
  99. $hs_popCnt8(l)+$hs_popCnt8(l>>>8) + $hs_popCnt8(l>>>16) + $hs_popCnt8(l>>>24) +
  100. $hs_popCnt8(h)+$hs_popCnt8(h>>>8) + $hs_popCnt8(h>>>16) + $hs_popCnt8(h>>>24);
  101. if(WORD_SIZE_IN_BITS==32) {
  102. return result;
  103. }
  104. else {
  105. return goog.math.Long.fromNumber(result);
  106. }
  107. };
  108. var $hs_popCntzh = WORD_SIZE_IN_BITS==32 ? $hs_popCnt32zh : $hs_popCnt64zh;
  109. var $hs_expDoublezh = function(a) {
  110. return Math.exp(a);
  111. };
  112. var $hs_logDoublezh = function(a) {
  113. return Math.log(a);
  114. };
  115. var $hs_sqrtDoublezh = function(a) {
  116. return Math.sqrt(a);
  117. };
  118. var $hs_sinDoublezh = function(a) {
  119. return Math.sin(a);
  120. };
  121. var $hs_cosDoublezh = function(a) {
  122. return Math.cos(a);
  123. };
  124. var $hs_tanDoublezh = function(a) {
  125. return Math.tan(a);
  126. };
  127. var $hs_asinDoublezh = function(a) {
  128. return Math.asin(a);
  129. };
  130. var $hs_acosDoublezh = function(a) {
  131. return Math.acos(a);
  132. };
  133. var $hs_atanDoublezh = function(a) {
  134. return Math.atan(a);
  135. };
  136. var $hs_sinhDoublezh = function(a) {
  137. return (Math.exp(a) - Math.exp(-a)) / 2;
  138. };
  139. var $hs_coshDoublezh = function(a) {
  140. return (Math.exp(a) + Math.exp(-a)) / 2;
  141. };
  142. var $hs_tanhDoublezh = function(a) {
  143. var expA = Math.exp(a);
  144. var expNegA = Math.exp(-a);
  145. return (expA - expNegA) / (expA + expNegA);
  146. };
  147. var $hs_ztztzhzh = function(a, b) {
  148. return Math.pow(a,b);
  149. };
  150. var $hs_decodeDoublezu2Intzh = function(x) {
  151. if( x < 0 ) {
  152. var result = $hs_decodeDoublezu2Intzh(-x);
  153. return [-1, result[1], result[2], result[3]];
  154. }
  155. var negExponent = 52-Math.floor(Math.log(x) * 1.4426950408889634); // 1/log(2)
  156. var mantissa = goog.math.Long.fromNumber(x * Math.pow(2, negExponent));
  157. return [1, mantissa.getHighBits(), mantissa.getLowBits(), -negExponent];
  158. };
  159. var $hs_expFloatzh = function(a) {
  160. return Math.exp(a);
  161. };
  162. var $hs_logFloatzh = function(a) {
  163. return Math.log(a);
  164. };
  165. var $hs_sqrtFloatzh = function(a) {
  166. return Math.sqrt(a);
  167. };
  168. var $hs_sinFloatzh = function(a) {
  169. return Math.sin(a);
  170. };
  171. var $hs_cosFloatzh = function(a) {
  172. return Math.cos(a);
  173. };
  174. var $hs_tanFloatzh = function(a) {
  175. return Math.tan(a);
  176. };
  177. var $hs_asinFloatzh = function(a) {
  178. return Math.asin(a);
  179. };
  180. var $hs_acosFloatzh = function(a) {
  181. return Math.acos(a);
  182. };
  183. var $hs_atanFloatzh = function(a) {
  184. return Math.atan(a);
  185. };
  186. var $hs_sinhFloatzh = function(a) {
  187. return (Math.exp(a) - Math.exp(-a)) / 2;
  188. };
  189. var $hs_coshFloatzh = function(a) {
  190. return (Math.exp(a) + Math.exp(-a)) / 2;
  191. };
  192. var $hs_tanhFloatzh = function(a) {
  193. var expA = Math.exp(a);
  194. var expNegA = Math.exp(-a);
  195. return (expA - expNegA) / (expA + expNegA);
  196. };
  197. var $hs_powerFloatzh = function(a, b) {
  198. return Math.pow(a, b);
  199. };
  200. var $hs_decodeFloatzuIntzh = function(x) {
  201. // This probably gives unexpected results.
  202. // In particular we need to check...
  203. // * NaN
  204. // * Infinity
  205. if( x < 0 ) {
  206. var result = $hs_decodeFloatzuIntzh(-x);
  207. return [-result[0], result[1]];
  208. }
  209. var negExponent = 23-Math.floor(Math.log(x) * 1.4426950408889634); // 1/log(2)
  210. return [(x * Math.pow(2, negExponent))|0, -negExponent];
  211. };
  212. var isDoubleNegativeZero = function(a) {
  213. return (a==-0.0)?1:0;
  214. };
  215. var isDoubleNaN = function(a) {
  216. return (isNaN(a))?1:0;
  217. };
  218. var isDoubleInfinite = function(a) {
  219. return (isFinite(a)||isNaN(a))?0:1;
  220. };
  221. var isFloatNegativeZero = function(a) { // fixme switch to proper 32 bit floats
  222. return (a==-0.0)?1:0;
  223. };
  224. var isFloatNaN = function(a) {
  225. return (isNaN(a))?1:0;
  226. };
  227. var isFloatInfinite = function(a) {
  228. return (isFinite(a)||isNaN(a))?0:1;
  229. };
  230. var integer_cbits_encodeDouble = function(s, bits, e) {
  231. var g = $hs_gmpToGoog(s, bits);
  232. return Math.pow(2,e)*g.toNumber();
  233. };
  234. var __int_encodeDouble = function(b, e) {
  235. return Math.pow(2,e) * b;
  236. };
  237. var rintDouble = function(a) {
  238. return Math.round(a);
  239. };
  240. var $hs_newMutVarzh = function(a, s) {
  241. return [s, {value : a}];
  242. };
  243. var $hs_readMutVarzh = function (a, s) {
  244. return [s, a.value];
  245. };
  246. var $hs_writeMutVarzh = function (a, b, s) {
  247. a.value = b;
  248. return s;
  249. };
  250. var $hs_sameMutVarzh = function (a, b) {
  251. return a === b;
  252. };
  253. var $hs_newArrayzh = function(n, a, s) {
  254. var result = [];
  255. for (var x = 0; x != n; x++)
  256. result[x] = a;
  257. return [s, result];
  258. };
  259. var $hs_sameMutableArrayzh = function (a, b) {
  260. return a === b;
  261. };
  262. var $hs_readArrayzh = function (a, n, s) {
  263. return [s, a[n]];
  264. };
  265. var $hs_writeArrayzh = function (a, n, b, s) {
  266. a[n] = b;
  267. return s;
  268. };
  269. var $hs_sizeofArrayzh = function (a, s) {
  270. return [s, a.length];
  271. };
  272. var $hs_sizeofMutableArrayzh = function (a, s) {
  273. return [s, a.length];
  274. };
  275. var $hs_indexArrayzh = function (a, n) {
  276. return [a[n]]; // Unboxed singleton
  277. };
  278. var $hs_unsafeFreezzeArrayzh = function (a, s) {
  279. return [s, a];
  280. };
  281. var $hs_unsafeThawArrayzh = function (a, s) {
  282. return [s, a];
  283. };
  284. // ByteArray support
  285. var $hs_ptrBase = 0;
  286. /**
  287. * @param {!number} n
  288. * @param {Object=} s
  289. */
  290. var $hs_newByteArrayzh = function (n, s) {
  291. var result = [new ArrayBuffer(n), 0, $hs_ptrBase];
  292. result[0].ptrs=[];
  293. $hs_ptrBase += n;
  294. return [s, result];
  295. };
  296. /**
  297. * @param {!number} n
  298. * @param {Object=} s
  299. */
  300. var $hs_newPinnedByteArrayzh = function (n, s) {
  301. var result = [new ArrayBuffer(n), 0, $hs_ptrBase];
  302. result[0].ptrs=[];
  303. $hs_ptrBase += n;
  304. return [s, result];
  305. };
  306. /**
  307. * @param {!number} n
  308. * @param {Object=} s
  309. */
  310. var $hs_newAlignedPinnedByteArrayzh = function (n, k, s) {
  311. $hs_ptrBase += $hs_ptrBase%k;
  312. var result = [new ArrayBuffer(n), 0, $hs_ptrBase];
  313. result[0].ptrs=[];
  314. $hs_ptrBase += n;
  315. return [s, result];
  316. };
  317. var $hs_byteArrayContentszh = function (a) {
  318. return a;
  319. };
  320. var $hs_sameMutableByteArrayzh = function (a, b) {
  321. return a[2] === b[2];
  322. };
  323. var $hs_unsafeFreezzeByteArrayzh = function (a, s) {
  324. return [s, a];
  325. };
  326. var $hs_sizeofByteArrayzh = function (a) {
  327. return new Uint8Array(a[0]).length;
  328. };
  329. var $hs_sizeofMutableByteArrayzh = function (a) {
  330. return new Uint8Array(a[0]).length;
  331. };
  332. var $hs_indexCharArrayzh = function (a, n) {
  333. return String.fromCharCode(new Uint8Array(a[0])[n]);
  334. };
  335. var $hs_indexWideCharArrayzh = function (a, n) {
  336. return String.fromCharCode(new Uint32Array(a[0])[n]);
  337. };
  338. // --- goog.math.Integer and (# Int#, ByteArray# #) mapping
  339. //
  340. // Unfortunately goog.math.Integer.bits_ are the bits of a signed in.
  341. // goog.math.Integer.sign_ is the value of the rest of the infinite list.
  342. //
  343. // We want (s, bits) where bits is the ByteArray of the bits of the
  344. // absolute value. And s is
  345. // | n == 0 -> 0
  346. // | n > 0 -> length bits
  347. // | n < 0 -> -(length bits)
  348. //
  349. // For performance we will store the goog.math.Integer as the ByteArray
  350. // and spin up a cached positive version to work out the correct bits.
  351. //
  352. // When constructing the goog.math.Integer in most cases ByteArray
  353. // will be the desired number.
  354. var $hs_fastNegate = function(a) {
  355. if(a.negateCache_ === undefined) {
  356. a.negateCache_ = a.negate();
  357. a.negateCache_.negateCache_ = a;
  358. }
  359. return a.negateCache_;
  360. };
  361. var $hs_absolute = function(a) {
  362. if(a.isNegative()) {
  363. return $hs_fastNegate(a);
  364. }
  365. return a;
  366. };
  367. var $hs_googToGMP = function(a) {
  368. var bits = $hs_absolute(a).bits_;
  369. var s = bits.length;
  370. while(s !== 0 && bits[s-1] === 0)
  371. s--;
  372. s = a.isNegative() ? -s : s;
  373. return [WORD_SIZE_IN_BITS==32 ? s : goog.math.Long.fromNumber(s), a];
  374. };
  375. var $hs_gmpToGoog = function(s,bits) {
  376. s = WORD_SIZE_IN_BITS==32 ? s : s.toNumber();
  377. // If s is 0 then the number we want is 0
  378. if(s===0) {
  379. return goog.math.Integer.ZERO;
  380. }
  381. // We are going to need to know long the bits array should be
  382. var len = s < 0 ? -s : s;
  383. // Try to avoid making a new integer if we can
  384. if(bits instanceof goog.math.Integer) {
  385. var current = $hs_googToGMP(bits);
  386. // Make sure we do not have too many bits
  387. if(len >= current[0]) {
  388. if((s<0) === bits.isNegative()) {
  389. // Both same sign so just return bits
  390. return bits;
  391. }
  392. else {
  393. // Only the sign is changed
  394. return $hs_fastNegate(bits);
  395. }
  396. }
  397. }
  398. // Ok lets build a new one
  399. var newBits = [];
  400. for(var n = 0; n !== len; n++) {
  401. newBits[n] = $hs_indexIntArrayzh(bits, n);
  402. }
  403. var i = new goog.math.Integer(newBits, 0);
  404. return s < 0 ? $hs_fastNegate(i) : i;
  405. };
  406. var $hs_indexIntArrayzh = function (a, n) {
  407. if(WORD_SIZE_IN_BITS==32) {
  408. if(a instanceof goog.math.Integer) {
  409. return $hs_absolute(a).getBits(n);
  410. }
  411. return new Int32Array(a[0])[n];
  412. }
  413. else {
  414. var n2 = n.toNumber()<<1;
  415. if(a instanceof goog.math.Integer) {
  416. var positive = $hs_absolute(a);
  417. return goog.math.Long.fromBits(positive.getBits(n2), positive.getBits(n2+1));
  418. }
  419. var x = new Int32Array(a[0]);
  420. return goog.math.Long.fromBits(x[n2], x[n2+1]);
  421. }
  422. };
  423. var $hs_indexWordArrayzh = function (a, n) {
  424. if(WORD_SIZE_IN_BITS==32) {
  425. // fixme there should be something better than checking this manually
  426. if(a instanceof goog.math.Integer) return $hs_absolute(a).getBits(n);
  427. else return new Uint32Array(a[0])[n];
  428. }
  429. else {
  430. var x = new Int32Array(a[0], n.toNumber()<<3);
  431. return goog.math.Long.fromBits(x[0], x[1]);
  432. }
  433. };
  434. var $hs_indexAddrArrayzh = function (a, n) {
  435. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  436. var res = a[0].ptrs[n];
  437. if(HS_DEBUG && res[2] !== new Uint32Array(a[0])[n])
  438. throw "Array Pointer Error";
  439. return res;
  440. };
  441. var $hs_indexFloatArrayzh = function (a, n) {
  442. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  443. return new Float32Array(a[0])[n];
  444. };
  445. var $hs_indexDoubleArrayzh = function (a, n) {
  446. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  447. return new Float64Array(a[0])[n];
  448. };
  449. var $hs_indexStablePtrArrayzh = function (a, n) {
  450. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  451. var res = a[0].ptrs[n];
  452. if(HS_DEBUG && res[2] !== new Uint32Array(a[0])[n])
  453. throw "Array Pointer Error";
  454. return res;
  455. };
  456. var $hs_indexInt8Arrayzh = function (a, n) {
  457. if(WORD_SIZE_IN_BITS == 32) {
  458. return new Int8Array(a[0])[n];
  459. } else {
  460. return goog.math.Long.fromNumber(new Int8Array(a[0])[n.toNumber()]);
  461. }
  462. };
  463. var $hs_indexInt16Arrayzh = function (a, n) {
  464. if(WORD_SIZE_IN_BITS == 32) {
  465. return new Int16Array(a[0])[n];
  466. } else {
  467. return goog.math.Long.fromNumber(new Int16Array(a[0])[n.toNumber()]);
  468. }
  469. };
  470. var $hs_indexInt32Arrayzh = function (a, n) {
  471. if(WORD_SIZE_IN_BITS == 32) {
  472. return new Int32Array(a[0])[n];
  473. } else {
  474. return goog.math.Long.fromNumber(new Int32Array(a[0])[n.toNumber()]);
  475. }
  476. };
  477. var $hs_indexInt64Arrayzh = function (a, n) {
  478. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  479. var x = new Int32Array(a[0], n<<3);
  480. return goog.math.Long.fromBits(x[0], x[1]);
  481. };
  482. var $hs_indexWord8Arrayzh = function (a, n) {
  483. if(WORD_SIZE_IN_BITS == 32) {
  484. return new Uint8Array(a[0])[n];
  485. } else {
  486. return goog.math.Long.fromBits(new Uint8Array(a[0])[n.toNumber()], 0);
  487. }
  488. };
  489. var $hs_indexWord16Arrayzh = function (a, n) {
  490. if(WORD_SIZE_IN_BITS == 32) {
  491. return new Uint16Array(a[0])[n];
  492. } else {
  493. return goog.math.Long.fromBits(new Uint16Array(a[0])[n.toNumber()], 0);
  494. }
  495. };
  496. var $hs_indexWord32Arrayzh = function (a, n) {
  497. if(WORD_SIZE_IN_BITS == 32) {
  498. return new Uint32Array(a[0])[n];
  499. } else {
  500. return goog.math.Long.fromBits(new Uint32Array(a[0])[n.toNumber()], 0);
  501. }
  502. };
  503. var $hs_indexWord64Arrayzh = function (a, n) {
  504. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  505. var x = new Int32Array(a[0], n<<3);
  506. return goog.math.Long.fromBits(x[0], x[1]);
  507. };
  508. var $hs_readCharArrayzh = function (a, n, s) {
  509. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  510. return [s, String.fromCharCode(new Uint8Array(a[0])[n])];
  511. };
  512. var $hs_readWideCharArrayzh = function (a, n, s) {
  513. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  514. return [s, String.fromCharCode(new Uint32Array(a[0])[n])];
  515. };
  516. var $hs_readIntArrayzh = function (a, n, s) {
  517. if(WORD_SIZE_IN_BITS==32) {
  518. return [s, new Int32Array(a[0])[n]];
  519. }
  520. else {
  521. var x = new Int32Array(a[0], n.toNumber()<<3);
  522. return [s, goog.math.Long.fromBits(x[0], x[1])];
  523. }
  524. };
  525. var $hs_readWordArrayzh = function (a, n, s) {
  526. if(WORD_SIZE_IN_BITS==32) {
  527. return [s, new Uint32Array(a[0])[n]];
  528. }
  529. else {
  530. var x = new Int32Array(a[0], n.toNumber()<<3);
  531. return [s, goog.math.Long.fromBits(x[0], x[1])];
  532. }
  533. };
  534. var $hs_readAddrArrayzh = function (a, n, s) {
  535. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  536. var res = a[0].ptrs[n];
  537. if(HS_DEBUG && res[2] !== new Uint32Array(a[0])[n])
  538. throw "Array Pointer Error";
  539. return [s, res];
  540. };
  541. var $hs_readFloatArrayzh = function (a, n, s) {
  542. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  543. return [s, new Float32Array(a[0])[n]];
  544. };
  545. var $hs_readDoubleArrayzh = function (a, n, s) {
  546. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  547. return [s, new Float64Array(a[0])[n]];
  548. };
  549. var $hs_readStablePtrArrayzh = function (a, n, s) {
  550. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  551. var res = a[0].ptrs[n];
  552. if(HS_DEBUG && res[2] !== new Uint32Array(a[0])[n])
  553. throw "Array Pointer Error";
  554. return [s, res];
  555. };
  556. var $hs_readInt8Arrayzh = function (a, n, s) {
  557. if(WORD_SIZE_IN_BITS == 32) {
  558. return [s, new Int8Array(a[0])[n]];
  559. } else {
  560. return [s, goog.math.Long.fromNumber(new Int8Array(a[0])[n.toNumber()])];
  561. }
  562. };
  563. var $hs_readInt16Arrayzh = function (a, n, s) {
  564. if(WORD_SIZE_IN_BITS == 32) {
  565. return [s, new Int16Array(a[0])[n]];
  566. } else {
  567. return [s, goog.math.Long.fromNumber(new Int16Array(a[0])[n.toNumber()])];
  568. }
  569. };
  570. var $hs_readInt32Arrayzh = function (a, n, s) {
  571. if(WORD_SIZE_IN_BITS == 32) {
  572. return [s, new Int32Array(a[0])[n]];
  573. } else {
  574. return [s, goog.math.Long.fromNumber(new Int32Array(a[0])[n.toNumber()])];
  575. }
  576. };
  577. var $hs_readInt64Arrayzh = function (a, n, s) {
  578. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  579. var x = new Int32Array(a[0], n<<3);
  580. return [s, goog.math.Long.fromBits(x[0], x[1])];
  581. };
  582. var $hs_readWord8Arrayzh = function (a, n, s) {
  583. if(WORD_SIZE_IN_BITS == 32) {
  584. return [s, new Uint8Array(a[0])[n]];
  585. } else {
  586. return [s, goog.math.Long.fromBits(new Uint8Array(a[0])[n.toNumber()], 0)];
  587. }
  588. };
  589. var $hs_readWord16Arrayzh = function (a, n, s) {
  590. if(WORD_SIZE_IN_BITS == 32) {
  591. return [s, new Uint16Array(a[0])[n]];
  592. } else {
  593. return [s, goog.math.Long.fromBits(new Uint16Array(a[0])[n.toNumber()], 0)];
  594. }
  595. };
  596. var $hs_readWord32Arrayzh = function (a, n, s) {
  597. if(WORD_SIZE_IN_BITS == 32) {
  598. return [s, new Uint32Array(a[0])[n]];
  599. } else {
  600. return [s, goog.math.Long.fromBits(new Uint32Array(a[0])[n.toNumber()], 0)];
  601. }
  602. };
  603. var $hs_readWord64Arrayzh = function (a, n, s) {
  604. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  605. var x = new Int32Array(a[0], n<<3);
  606. return [s, goog.math.Long.fromBits(x[0], x[1])];
  607. };
  608. var $hs_writeCharArrayzh = function (a, n, v, s) {
  609. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  610. new Uint8Array(a[0])[n] = v.charCodeAt();
  611. return s;
  612. };
  613. var $hs_writeWideCharArrayzh = function (a, n, v, s) {
  614. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  615. new Uint32Array(a[0])[n] = v.charCodeAt();
  616. return s;
  617. };
  618. var $hs_writeIntArrayzh = function (a, n, v, s) {
  619. if(WORD_SIZE_IN_BITS==32) {
  620. new Int32Array(a[0])[n] = v;
  621. return s;
  622. }
  623. else {
  624. var x = new Int32Array(a[0], n.toNumber()<<3);
  625. x[0] = v.getLowBits();
  626. x[1] = v.getHighBits();
  627. return s;
  628. }
  629. };
  630. var $hs_writeWordArrayzh = function (a, n, v, s) {
  631. if(WORD_SIZE_IN_BITS==32) {
  632. new Uint32Array(a[0])[n] = v;
  633. return s;
  634. }
  635. else {
  636. var x = new Int32Array(a[0], n.toNumber()<<3);
  637. x[0] = v.getLowBits();
  638. x[1] = v.getHighBits();
  639. return s;
  640. }
  641. };
  642. var $hs_writeAddrArrayzh = function (a, n, v, s) {
  643. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  644. a[0].ptrs[n] = v;
  645. new Uint32Array(a[0])[n] = v[2];
  646. return s;
  647. };
  648. var $hs_writeFloatArrayzh = function (a, n, v, s) {
  649. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  650. new Float32Array(a[0])[n] = v;
  651. return s;
  652. };
  653. var $hs_writeDoubleArrayzh = function (a, n, v, s) {
  654. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  655. new Float64Array(a[0])[n] = v;
  656. return s;
  657. };
  658. var $hs_writeStablePtrArrayzh = function (a, n, v, s) {
  659. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  660. a[0].ptrs[n] = v;
  661. new Uint32Array(a[0])[n] = v[2];
  662. return s;
  663. };
  664. var $hs_writeInt8Arrayzh = function (a, n, v, s) {
  665. if(WORD_SIZE_IN_BITS==32) {
  666. new Int8Array(a[0])[n] = v;
  667. }
  668. else {
  669. new Int8Array(a[0])[n.toNumber()] = v.getLowBits();
  670. }
  671. return s;
  672. };
  673. var $hs_writeInt16Arrayzh = function (a, n, v, s) {
  674. if(WORD_SIZE_IN_BITS==32) {
  675. new Int16Array(a[0])[n] = v;
  676. }
  677. else {
  678. new In16Array(a[0])[n.toNumber()] = v.getLowBits();
  679. }
  680. return s;
  681. };
  682. var $hs_writeInt32Arrayzh = function (a, n, v, s) {
  683. if(WORD_SIZE_IN_BITS==32) {
  684. new Int32Array(a[0])[n] = v;
  685. }
  686. else {
  687. new Int32Array(a[0])[n.toNumber()] = v.getLowBits();
  688. }
  689. return s;
  690. };
  691. var $hs_writeInt64Arrayzh = function (a, n, v, s) {
  692. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  693. var x = new Int32Array(a[0], n<<3);
  694. x[0] = v.getLowBits();
  695. x[1] = v.getHighBits();
  696. return s;
  697. };
  698. var $hs_writeWord8Arrayzh = function (a, n, v, s) {
  699. if(WORD_SIZE_IN_BITS==32) {
  700. new Uint8Array(a[0])[n] = v;
  701. }
  702. else {
  703. new Uint8Array(a[0])[n.toNumber()] = v.getLowBits();
  704. }
  705. return s;
  706. };
  707. var $hs_writeWord16Arrayzh = function (a, n, v, s) {
  708. if(WORD_SIZE_IN_BITS==32) {
  709. new Uint16Array(a[0])[n] = v;
  710. }
  711. else {
  712. new Uint16Array(a[0])[n.toNumber()] = v.getLowBits();
  713. }
  714. return s;
  715. };
  716. var $hs_writeWord32Arrayzh = function (a, n, v, s) {
  717. if(WORD_SIZE_IN_BITS==32) {
  718. new Uint32Array(a[0])[n] = v;
  719. }
  720. else {
  721. new Uint32Array(a[0])[n.toNumber()] = v.getLowBits();
  722. }
  723. return s;
  724. };
  725. var $hs_writeWord64Arrayzh = function (a, n, v, s) {
  726. n = WORD_SIZE_IN_BITS==32 ? n : n.toNumber();
  727. var x = new Int32Array(a[0], n<<3);
  728. x[0] = v.getLowBits();
  729. x[1] = v.getHighBits();
  730. return s;
  731. };
  732. var $hs_copyByteArrayzh = function (src, soff, dest, doff, count, s) {
  733. var srcarray = new Uint8Array(src[0]);
  734. var destarray = new Uint8Array(dest[0]);
  735. while(count != 0) {
  736. destarray[doff] = srcarray[soff];
  737. soff++;
  738. doff++;
  739. count--;
  740. }
  741. return s;
  742. };
  743. var $hs_copyMutableByteArrayzh = function (src, soff, dest, doff, count, s) {
  744. var srcarray = new Uint8Array(src[0]);
  745. var destarray = new Uint8Array(dest[0]);
  746. while(count != 0) {
  747. destarray[doff] = srcarray[soff];
  748. soff++;
  749. doff++;
  750. count--;
  751. }
  752. return s;
  753. };
  754. var $hs_plusAddrzh = function (a, n) {
  755. if(typeof(a) === 'string')
  756. return [a, n, n];
  757. else
  758. return [a[0],a[1]+n,a[2]+n];
  759. };
  760. var $hs_minusAddrzh = function (a, b) {
  761. return a[1]-b[1];
  762. };
  763. var $hs_remAddrzh = function (a, b) {
  764. return a[1]%b;
  765. };
  766. var $hs_gtAddrzh = function (a, b) {
  767. return $hs_mkBool(
  768. (a===null&&b===null)?false:
  769. ((a===null&&b!==null)?false:
  770. ((a!==null&&b===null)?true:(a[2]>b[2]))));
  771. };
  772. var $hs_geAddrzh = function (a, b) {
  773. return $hs_mkBool(
  774. (a===null&&b===null)?true:
  775. ((a===null&&b!==null)?false:
  776. ((a!==null&&b===null)?true:(a[2]>=b[2]))));
  777. };
  778. var $hs_eqAddrzh = function (a, b) {
  779. return $hs_mkBool(
  780. (a===null&&b===null)?true:
  781. ((a===null&&b!==null)?false:
  782. ((a!==null&&b===null)?false:(a[2]===b[2]))));
  783. };
  784. var $hs_neAddrzh = function (a, b) {
  785. return $hs_mkBool(
  786. (a===null&&b===null)?false:
  787. ((a===null&&b!==null)?true:
  788. ((a!==null&&b===null)?true:(a[2]!==b[2]))));
  789. };
  790. var $hs_ltAddrzh = function (a, b) {
  791. return $hs_mkBool(
  792. (a===null&&b===null)?false:
  793. ((a===null&&b!==null)?true:
  794. ((a!==null&&b===null)?false:(a[2]<b[2]))));
  795. };
  796. var $hs_leAddrzh = function (a, b) {
  797. return $hs_mkBool(
  798. (a===null&&b===null)?true:
  799. ((a===null&&b!==null)?true:
  800. ((a!==null&&b===null)?false:(a[2]<=b[2]))));
  801. };
  802. var $hs_indexCharOffAddrzh = function (a, n) {
  803. if(typeof(a) === 'string')
  804. return n==a.length?'\x00':a.charAt(n);
  805. else if(typeof(a[0]) === 'string')
  806. return n==a[0].length?'\x00':a[0].charAt(a[1]+n);
  807. else
  808. return String.fromCharCode(new Uint8Array(a[0],a[1]+n)[0]);
  809. };
  810. var $hs_indexWideCharOffAddrzh = function (a, n) {
  811. return String.fromCharCode(new Uint32Array(a[0],a[1]+(n<<2))[0]);
  812. };
  813. var $hs_indexIntOffAddrzh = function (a, n) {
  814. if(WORD_SIZE_IN_BITS==32) {
  815. return new Int32Array(a[0],a[1]+(n<<2))[0];
  816. }
  817. else {
  818. var x = new Int32Array(a[0], a[1] + (n<<3));
  819. return goog.math.Long.fromBits(x[0], x[1]);
  820. }
  821. };
  822. var $hs_indexWordOffAddrzh = function (a, n) {
  823. if(WORD_SIZE_IN_BITS==32) {
  824. return new Uint32Array(a[0],a[1]+(n<<2))[0];
  825. }
  826. else {
  827. var x = new Int32Array(a[0], a[1] + (n<<3));
  828. return goog.math.Long.fromBits(x[0], x[1]);
  829. }
  830. };
  831. var $hs_indexAddrOffAddrzh = function (a, n) {
  832. var res = a[0].ptrs[a[1]+(n<<2)];
  833. if(HS_DEBUG && res[2] !== new Uint32Array(a[0],a[1]+(n<<2))[0])
  834. throw "Array Pointer Error";
  835. return res;
  836. };
  837. var $hs_indexFloatOffAddrzh = function (a, n) {
  838. return new Float32Array(a[0],a[1]+(n<<2))[0];
  839. };
  840. var $hs_indexDoubleOffAddrzh = function (a, n) {
  841. return new Float64Array(a[0],a[1]+(n<<3))[0];
  842. };
  843. var $hs_indexStablePtrOffAddrzh = function (a, n) {
  844. var res = a[0].ptrs[a[1]+(n<<2)];
  845. if(HS_DEBUG && res[2] !== new Uint32Array(a[0],a[1]+(n<<2))[0])
  846. throw "Array Pointer Error";
  847. return res;
  848. };
  849. var $hs_indexInt8OffAddrzh = function (a, n) {
  850. if(WORD_SIZE_IN_BITS==32) {
  851. return new Int8Array(a[0],a[1]+n)[0];
  852. }
  853. else {
  854. return goog.math.Long.fromNumber(new Int8Array(a[0],a[1]+n)[0]);
  855. }
  856. };
  857. var $hs_indexInt16OffAddrzh = function (a, n) {
  858. if(WORD_SIZE_IN_BITS==32) {
  859. return new Int16Array(a[0],a[1]+(n<<1))[0];
  860. }
  861. else {
  862. return goog.math.Long.fromNumber(new Int16Array(a[0],a[1]+(n<<1))[0]);
  863. }
  864. };
  865. var $hs_indexInt32OffAddrzh = function (a, n) {
  866. if(WORD_SIZE_IN_BITS==32) {
  867. return new Int32Array(a[0],a[1]+(n<<2))[0];
  868. }
  869. else {
  870. return goog.math.Long.fromNumber(new Int32Array(a[0],a[1]+(n<<2))[0]);
  871. }
  872. };
  873. var $hs_indexInt64OffAddrzh = function (a, n) {
  874. var x = new Uint32Array(a[0],a[1]+(n<<3));
  875. return goog.math.Long.fromBits(x[0], x[1]);
  876. };
  877. var $hs_indexWord8OffAddrzh = function (a, n) {
  878. if(typeof(a) === 'string')
  879. var res = n==a.length?0:a.charCodeAt(n);
  880. else if(typeof(a[0]) === 'string')
  881. var res = n==a[0].length?0:a[0].charCodeAt(a[1]+n);
  882. else
  883. var res = new Uint8Array(a[0],a[1]+n)[0];
  884. return WORD_SIZE_IN_BITS==32 ? res : goog.math.Long.fromBits(res);
  885. };
  886. var $hs_indexWord16OffAddrzh = function (a, n) {
  887. if(WORD_SIZE_IN_BITS==32) {
  888. return new Uint16Array(a[0],a[1]+(n<<1))[0];
  889. }
  890. else {
  891. return goog.math.Long.fromBits(new Uint16Array(a[0],a[1]+(n<<1))[0], 0);
  892. }
  893. };
  894. var $hs_indexWord32OffAddrzh = function (a, n) {
  895. if(WORD_SIZE_IN_BITS==32) {
  896. return new Uint32Array(a[0],a[1]+(n<<2))[0];
  897. }
  898. else {
  899. return goog.math.Long.fromBits(new Uint32Array(a[0],a[1]+(n<<2))[0], 0);
  900. }
  901. };
  902. var $hs_indexWord64OffAddrzh = function (a, n) {
  903. var x = new Int32Array(a[0],a[1]+(n<<3));
  904. return goog.math.Long.fromBits(x[0], x[1]);
  905. };
  906. var $hs_readCharOffAddrzh = function (a, n, s) {
  907. return [s, String.fromCharCode(new Uint8Array(a[0],a[1]+n)[0])];
  908. };
  909. var $hs_readWideCharOffAddrzh = function (a, n, s) {
  910. return [s, String.fromCharCode(new Uint32Array(a[0],a[1]+(n<<2))[0])];
  911. };
  912. var $hs_readIntOffAddrzh = function (a, n, s) {
  913. if(WORD_SIZE_IN_BITS==32) {
  914. return [s, new Int32Array(a[0],a[1]+(n<<2))[0]];
  915. }
  916. else {
  917. var x = new Int32Array(a[0], a[1] + (n<<3));
  918. return [s, goog.math.Long.fromBits(x[0], x[1])];
  919. }
  920. };
  921. var $hs_readWordOffAddrzh = function (a, n, s) {
  922. if(WORD_SIZE_IN_BITS==32) {
  923. return [s, new Uint32Array(a[0],a[1]+(n<<2))[0]];
  924. }
  925. else {
  926. var x = new Int32Array(a[0], a[1] + (n<<3));
  927. return [s, goog.math.Long.fromBits(x[0], x[1])];
  928. }
  929. };
  930. var $hs_readAddrOffAddrzh = function (a, n, s) {
  931. var res = a[0].ptrs[a[1]+(n<<2)];
  932. if(HS_DEBUG && a[2] !== new Uint32Array(a[0],a[1]+(n<<2))[0])
  933. throw "Array Pointer Error";
  934. return [s, res];
  935. };
  936. var $hs_readFloatOffAddrzh = function (a, n, s) {
  937. return [s, new Float32Array(a[0],a[1]+(n<<2))[0]];
  938. };
  939. var $hs_readDoubleOffAddrzh = function (a, n, s) {
  940. return [s, new Float64Array(a[0],a[1]+(n<<3))[0]];
  941. };
  942. var $hs_readStablePtrOffAddrzh = function (a, n, s) {
  943. var res = a[0].ptrs[a[1]+(n<<2)];
  944. if(HS_DEBUG && a[2] !== new Uint32Array(a[0],a[1]+(n<<2))[0])
  945. throw "Array Pointer Error";
  946. return [s, res];
  947. };
  948. var $hs_readInt8OffAddrzh = function (a, n, s) {
  949. if(WORD_SIZE_IN_BITS==32) {
  950. return [s, new Int8Array(a[0],a[1]+n)[0]];
  951. }
  952. else {
  953. return [s, goog.math.Long.fromNumber(new Int32Array(a[0],a[1]+n)[0])];
  954. }
  955. };
  956. var $hs_readInt16OffAddrzh = function (a, n, s) {
  957. if(WORD_SIZE_IN_BITS==32) {
  958. return [s, new Int16Array(a[0],a[1]+(n<<1))[0]];
  959. }
  960. else {
  961. return [s, goog.math.Long.fromNumber(new Int16Array(a[0],a[1]+(n<<1))[0])];
  962. }
  963. };
  964. var $hs_readInt32OffAddrzh = function (a, n, s) {
  965. if(WORD_SIZE_IN_BITS==32) {
  966. return [s, new Int32Array(a[0],a[1]+(n<<2))[0]];
  967. }
  968. else {
  969. return [s, goog.math.Long.fromNumber(new Int32Array(a[0],a[1]+(n<<2))[0])];
  970. }
  971. };
  972. var $hs_readInt64OffAddrzh = function (a, n, s) {
  973. var x = new Uint32Array(a[0],a[1]+(n<<3));
  974. return [s, goog.math.Long.fromBits(x[0], x[1])];
  975. };
  976. var $hs_readWord8OffAddrzh = function (a, n, s) {
  977. if(typeof(a) === 'string')
  978. return [s, a.charCodeAt(n)];
  979. else
  980. return [s, new Uint8Array(a[0],a[1]+n)[0]];
  981. };
  982. var $hs_readWord16OffAddrzh = function (a, n, s) {
  983. if(WORD_SIZE_IN_BITS==32) {
  984. return [s, new Uint16Array(a[0],a[1]+(n<<1))[0]];
  985. }
  986. else {
  987. return [s, goog.math.Long.fromBits(new Uint16Array(a[0],a[1]+(n<<1))[0], 0)];
  988. }
  989. };
  990. var $hs_readWord32OffAddrzh = function (a, n, s) {
  991. if(WORD_SIZE_IN_BITS==32) {
  992. return [s, new Uint32Array(a[0],a[1]+(n<<2))[0]];
  993. }
  994. else {
  995. return [s, goog.math.Long.fromBits(new Uint32Array(a[0],a[1]+(n<<2))[0], 0)];
  996. }
  997. };
  998. var $hs_readWord64OffAddrzh = function (a, n, s) {
  999. var x = new Uint32Array(a[0],a[1]+(n<<3));
  1000. return [s, goog.math.Long.fromBits(x[0], x[1])];
  1001. };
  1002. var $hs_writeCharOffAddrzh = function (a, n, v, s) {
  1003. (new Uint8Array(a[0],a[1]+n))[0] = v.charCodeAt();
  1004. return s;
  1005. };
  1006. var $hs_writeWideCharOffAddrzh = function (a, n, v, s) {
  1007. (new Uint32Array(a[0],a[1]+(n<<2)))[0] = v.charCodeAt();
  1008. return s;
  1009. };
  1010. var $hs_writeIntOffAddrzh = function (a, n, v, s) {
  1011. if(WORD_SIZE_IN_BITS==32) {
  1012. (new Int32Array(a[0],a[1]+(n<<2)))[0] = v;
  1013. return s;
  1014. }
  1015. else {
  1016. var x = new Int32Array(a[0], a[1]+(n<<3));
  1017. x[0] = v.getLowBits();
  1018. x[1] = v.getHighBits();
  1019. return s;
  1020. }
  1021. };
  1022. var $hs_writeWordOffAddrzh = function (a, n, v, s) {
  1023. if(WORD_SIZE_IN_BITS==32) {
  1024. (new Uint32Array(a[0],a[1]+(n<<2)))[0] = v;
  1025. return s;
  1026. }
  1027. else {
  1028. var x = new Int32Array(a[0], a[1]+(n<<3));
  1029. x[0] = v.getLowBits();
  1030. x[1] = v.getHighBits();
  1031. return s;
  1032. }
  1033. };
  1034. var $hs_writeAddrOffAddrzh = function (a, n, v, s) {
  1035. a[0].ptrs[n] = v;
  1036. (new Uint32Array(a[0],a[1]+(n<<2)))[0] = a[2];
  1037. return s;
  1038. };
  1039. var $hs_writeFloatOffAddrzh = function (a, n, v, s) {
  1040. (new Float32Array(a[0],a[1]+(n<<2)))[0] = v;
  1041. return s;
  1042. };
  1043. var $hs_writeDoubleOffAddrzh = function (a, n, v, s) {
  1044. (new Float64Array(a[0],a[1]+(n<<3)))[0] = v;
  1045. return s;
  1046. };
  1047. var $hs_writeStablePtrOffAddrzh = function (a, n, v, s) {
  1048. a[0].ptrs[n] = v;
  1049. (new Uint32Array(a[0],a[1]+(n<<2)))[0] = a[2];
  1050. return s;
  1051. };
  1052. var $hs_writeInt8OffAddrzh = function (a, n, v, s) {
  1053. (new Int8Array(a[0],a[1]+n))[0] = WORD_SIZE_IN_BITS==32 ? v : v.getLowBits();
  1054. return s;
  1055. };
  1056. var $hs_writeInt16OffAddrzh = function (a, n, v, s) {
  1057. (new Int16Array(a[0],a[1]+(n<<1)))[0] = WORD_SIZE_IN_BITS==32 ? v : v.getLowBits();
  1058. return s;
  1059. };
  1060. var $hs_writeInt32OffAddrzh = function (a, n, v, s) {
  1061. (new Int32Array(a[0],a[1]+(n<<2)))[0] = WORD_SIZE_IN_BITS==32 ? v : v.getLowBits();
  1062. return s;
  1063. };
  1064. var $hs_writeInt64OffAddrzh = function (a, n, v, s) {
  1065. var x = new Int32Array(a[0], a[1]+(n<<3));
  1066. x[0] = v.getLowBits();
  1067. x[1] = v.getHighBits();
  1068. return s;
  1069. };
  1070. var $hs_writeWord8OffAddrzh = function (a, n, v, s) {
  1071. (new Uint8Array(a[0],a[1]+n))[0] = WORD_SIZE_IN_BITS==32 ? v : v.getLowBits();
  1072. return s;
  1073. };
  1074. var $hs_writeWord16OffAddrzh = function (a, n, v, s) {
  1075. (new Uint16Array(a[0],a[1]+(n<<1)))[0] = WORD_SIZE_IN_BITS==32 ? v : v.getLowBits();
  1076. return s;
  1077. };
  1078. var $hs_writeWord32OffAddrzh = function (a, n, v, s) {
  1079. (new Uint32Array(a[0],a[1]+(n<<2)))[0] = WORD_SIZE_IN_BITS==32 ? v : v.getLowBits();
  1080. return s;
  1081. };
  1082. var $hs_writeWord64OffAddrzh = function (a, n, v, s) {
  1083. var x = new Int32Array(a[0], a[1]+(n<<3));
  1084. x[0] = v.getLowBits();
  1085. x[1] = v.getHighBits();
  1086. return s;
  1087. };
  1088. var $hs_alert = function (str) {
  1089. window.alert(str);
  1090. };
  1091. var $hs_logAny = function (c, str) {
  1092. var el = document.getElementById('log');
  1093. el.innerHTML = el.innerHTML + c + ": " + str + '<br/>\n';
  1094. };
  1095. var $hs_logInfo = function (str) {
  1096. $hs_logAny("INFO", str);
  1097. };
  1098. var $hs_logError = function (str) {
  1099. $hs_logAny("ERROR", str);
  1100. };
  1101. var $hs_logDebug = function (str) {
  1102. $hs_logAny("DEBUG", str);
  1103. };
  1104. var $hs_logger = goog.debug.Logger.getLogger('hs');
  1105. var $hs_utf32 = function(s) {
  1106. var res = $hs_newByteArrayzh((s.length<<2)+4)[1];
  1107. var dest = new Uint32Array(res[0]);
  1108. for(var i=0;i!=s.length;i++)
  1109. dest[i]=s.charCodeAt(i);
  1110. dest[i]=0;
  1111. return res;
  1112. };
  1113. var $hs_fromUtf32 = function(s) {
  1114. var res = "";
  1115. var src = new Uint32Array(s[0],s[1]);
  1116. var len = src[src.length-1] === 0 ? src.length - 1 : src.length;
  1117. for(var i=0;i!=len;i++)
  1118. res=res+String.fromCharCode(src[i]);
  1119. return res;
  1120. };
  1121. var $hs_ascii = function(s) {
  1122. var res = $hs_newByteArrayzh(s.length+1)[1];
  1123. var dest = new Uint8Array(res[0]);
  1124. for(var i=0;i!=s.length;i++)
  1125. dest[i]=s.charCodeAt(i);
  1126. dest[i]=0;
  1127. return res;
  1128. };
  1129. var integer_cmm_cmpIntegerzh = function(sa, abits, sb, bbits) {
  1130. if(WORD_SIZE_IN_BITS==32) {
  1131. return $hs_gmpToGoog(sa, abits).compare($hs_gmpToGoog(sb, bbits));
  1132. }
  1133. else {
  1134. return goog.math.Long.fromNumber($hs_gmpToGoog(sa, abits).compare(
  1135. $hs_gmpToGoog(sb, bbits)));
  1136. }
  1137. };
  1138. var integer_cmm_cmpIntegerIntzh = function(sa, abits, b) {
  1139. if(WORD_SIZE_IN_BITS==32) {
  1140. return $hs_gmpToGoog(sa, abits).compare(goog.math.Integer.fromInt(b));
  1141. }
  1142. else {
  1143. return goog.math.Long.fromNumber($hs_gmpToGoog(sa, abits).compare(
  1144. goog.math.Integer.fromBits([b.getLowBits(), b.getHighBits()])));
  1145. }
  1146. };
  1147. var integer_cmm_plusIntegerzh = function(sa, abits, sb, bbits) {
  1148. return $hs_googToGMP($hs_gmpToGoog(sa, abits).add($hs_gmpToGoog(sb, bbits)));
  1149. };
  1150. var integer_cmm_minusIntegerzh = function(sa, abits, sb, bbits) {
  1151. return $hs_googToGMP($hs_gmpToGoog(sa, abits).subtract($hs_gmpToGoog(sb, bbits)));
  1152. };
  1153. var integer_cmm_timesIntegerzh = function(sa, abits, sb, bbits) {
  1154. return $hs_googToGMP($hs_gmpToGoog(sa, abits).multiply($hs_gmpToGoog(sb, bbits)));
  1155. };
  1156. var integer_cmm_quotRemIntegerzh = function(sa, abits, sb, bbits) {
  1157. var a = $hs_gmpToGoog(sa, abits);
  1158. var b = $hs_gmpToGoog(sb, bbits)
  1159. var q = a.divide(b);
  1160. var r = a.subtract(q.multiply(b));
  1161. return $hs_googToGMP(q).concat($hs_googToGMP(r));
  1162. };
  1163. var integer_cmm_quotIntegerzh = function(sa, abits, sb, bbits) {
  1164. return $hs_googToGMP($hs_gmpToGoog(sa, abits).divide($hs_gmpToGoog(sb, bbits)));
  1165. };
  1166. var integer_cmm_remIntegerzh = function(sa, abits, sb, bbits) {
  1167. return $hs_googToGMP($hs_gmpToGoog(sa, abits).modulo($hs_gmpToGoog(sb, bbits)));
  1168. };
  1169. var integer_cmm_divModIntegerzh = function(sa, abits, sb, bbits) {
  1170. var a = $hs_gmpToGoog(sa, abits);
  1171. var b = $hs_gmpToGoog(sb, bbits);
  1172. var d = a.divide(b);
  1173. var m = a.subtract(d.multiply(b));
  1174. if(a.isNegative()!==b.isNegative() && !m.isZero()) {
  1175. // Take one off d and add b onto m
  1176. d = d.add(goog.math.Integer.fromInt(-1));
  1177. m = m.add(b);
  1178. }
  1179. return $hs_googToGMP(d).concat($hs_googToGMP(m));
  1180. };
  1181. var integer_cmm_divExactIntegerzh = function(sa, abits, sb, bbits) {
  1182. return $hs_googToGMP($hs_gmpToGoog(sa, abits).divide($hs_gmpToGoog(sb, bbits)));
  1183. };
  1184. var $hs_gcd = function(a, b) {
  1185. var x = $hs_absolute(a);
  1186. var y = $hs_absolute(b);
  1187. var big, small;
  1188. if(x.lessThan(y)) {
  1189. small = x;
  1190. big = y;
  1191. }
  1192. else {
  1193. small = x;
  1194. big = y;
  1195. }
  1196. while(!small.isZero()) {
  1197. var q = big.divide(small);
  1198. var r = big.subtract(q.multiply(small));
  1199. big = small;
  1200. small = r;
  1201. }
  1202. return $hs_googToGMP(big);
  1203. };
  1204. var integer_cmm_gcdIntegerzh = function(sa, abits, sb, bbits) {
  1205. return $hs_gcd($hs_gmpToGoog(sa, abits), $hs_gmpToGoog(sb, bbits));
  1206. };
  1207. var integer_cmm_gcdIntegerIntzh = function(sa, abits, b) {
  1208. if(WORD_SIZE_IN_BITS==32) {
  1209. return $hs_gcd($hs_gmpToGoog(sa, abits), goog.math.Integer.fromInt(b));
  1210. }
  1211. else {
  1212. return $hs_gcd($hs_gmpToGoog(sa, abits),
  1213. goog.math.Integer.fromBits([b.getLowBits(), b.getHighBits()]));
  1214. }
  1215. };
  1216. var integer_cmm_gcdIntzh = function(a, b) {
  1217. if(WORD_SIZE_IN_BITS==32) {
  1218. var x = a<0 ? -a : a;
  1219. var y = b<0 ? -b : b;
  1220. var big, small;
  1221. if(x<y) {
  1222. small = x;
  1223. big = y;
  1224. }
  1225. else {
  1226. small = x;
  1227. big = y;
  1228. }
  1229. while(small!==0) {
  1230. var r = big % small;
  1231. big = small;
  1232. small = r;
  1233. }
  1234. return big;
  1235. }
  1236. else {
  1237. var x = a.isNegative() ? a.negate() : a;
  1238. var y = b.isNegative() ? b.negate() : b;
  1239. var big, small;
  1240. if(x.lessThan(y)) {
  1241. small = x;
  1242. big = y;
  1243. }
  1244. else {
  1245. small = x;
  1246. big = y;
  1247. }
  1248. while(!small.isZero()) {
  1249. var q = big.divide(small);
  1250. var r = big.subtract(q.multiply(small));
  1251. big = small;
  1252. small = r;
  1253. }
  1254. return big;
  1255. }
  1256. };
  1257. var integer_cmm_decodeDoublezh = function(x) {
  1258. if( x < 0 ) {
  1259. var result = integer_cmm_decodeDoublezh(-x);
  1260. return [result[0], -result[1], result[2]];
  1261. }
  1262. var negExponent = 52-Math.floor(Math.log(x) * 1.4426950408889634); // 1/log(2)
  1263. return [-negExponent].concat($hs_googToGMP(
  1264. goog.math.Integer.fromNumber(x * Math.pow(2, negExponent))));
  1265. };
  1266. var integer_cmm_int2Integerzh = function(i) {
  1267. if(WORD_SIZE_IN_BITS==32) {
  1268. return $hs_googToGMP(goog.math.Integer.fromInt(i));
  1269. }
  1270. else {
  1271. return $hs_googToGMP(
  1272. goog.math.Integer.fromBits([i.getLowBits(), i.getHighBits()]));
  1273. }
  1274. };
  1275. var integer_cmm_word2Integerzh = function(i) {
  1276. if(WORD_SIZE_IN_BITS==32) {
  1277. return $hs_googToGMP(goog.math.Integer.fromBits(i<0?[0,i]:[i]));
  1278. }
  1279. else {
  1280. return $hs_googToGMP(goog.math.Integer.fromBits(
  1281. i.isNegative()?[0, i.getLowBits(), i.getHighBits()]
  1282. :[ i.getLowBits(), i.getHighBits()]));
  1283. }
  1284. };
  1285. var integer_cmm_andIntegerzh = function(sa, abits, sb, bbits) {
  1286. return $hs_googToGMP($hs_gmpToGoog(sa, abits).and($hs_gmpToGoog(sb, bbits)));
  1287. };
  1288. var integer_cmm_orIntegerzh = function(sa, abits, sb, bbits) {
  1289. return $hs_googToGMP($hs_gmpToGoog(sa, abits).or($hs_gmpToGoog(sb, bbits)));
  1290. };
  1291. var integer_cmm_xorIntegerzh = function(sa, abits, sb, bbits) {
  1292. return $hs_googToGMP($hs_gmpToGoog(sa, abits).xor($hs_gmpToGoog(sb, bbits)));
  1293. };
  1294. var integer_cmm_mul2ExpIntegerzh = function(sa, abits, b) {
  1295. return $hs_googToGMP($hs_gmpToGoog(sa, abits).shiftLeft(b));
  1296. };
  1297. var integer_cmm_fdivQ2ExpIntegerzh = function(sa, abits, b) {
  1298. return $hs_googToGMP($hs_gmpToGoog(sa, abits).shiftRight(b));
  1299. };
  1300. var integer_cmm_complementIntegerzh = function(sa, abits) {
  1301. return $hs_googToGMP($hs_gmpToGoog(sa, abits).not());
  1302. };
  1303. var integer_cmm_int64ToIntegerzh = function(a) {
  1304. return $hs_googToGMP(goog.math.Integer.fromBits([a.getLowBits(), a.getHighBits()]));
  1305. };
  1306. var integer_cmm_word64ToIntegerzh = function(a) {
  1307. return $hs_googToGMP(goog.math.Integer.fromBits(
  1308. a.isNegative()?[0, a.getLowBits(), a.getHighBits()]
  1309. :[ a.getLowBits(), a.getHighBits()]));
  1310. };
  1311. var hs_integerToInt64 = function(as, abits) {
  1312. var a = $hs_gmpToGoog(as, abits);
  1313. return goog.math.Long.fromBits(a.getBits(0), a.getBits(1));
  1314. };
  1315. var hs_integerToWord64 = function(as, abits) {
  1316. var a = $hs_gmpToGoog(as, abits);
  1317. return goog.math.Long.fromBits(a.getBits(0), a.getBits(1));
  1318. };
  1319. /**
  1320. * @param {!Array.<Object>} dest
  1321. * @param {!number} doff
  1322. * @param {!Array.<Object>} src
  1323. * @param {!number} soff
  1324. * @param {!number} count
  1325. */
  1326. var _hs_text_memcpy = function (dest, doff, src, soff, count) {
  1327. var srcarray = new Uint16Array(src[0],src[1]);
  1328. var destarray = new Uint16Array(dest[0],dest[1]);
  1329. while(count != 0) {
  1330. destarray[doff] = srcarray[soff];
  1331. soff++;
  1332. doff++;
  1333. count--;
  1334. }
  1335. };
  1336. var _hs_text_memcmp = function(a, aoff, b, boff, count) {
  1337. var aarray = new Uint16Array(a[0],a[1]);
  1338. var barray = new Uint16Array(b[0],b[1]);
  1339. while(count != 0) {
  1340. if( aarray[aoff] < barray[boff] )
  1341. return -1;
  1342. if( aarray[aoff] > barray[boff] )
  1343. return 1;
  1344. aoff++;
  1345. boff++;
  1346. count--;
  1347. }
  1348. return 0;
  1349. };
  1350. /**
  1351. * @define {number} size of Word and Int. If 64 we use goog.math.Long.
  1352. */
  1353. var $hs_UTF8_ACCEPT = 0;
  1354. /**
  1355. * @define {number} size of Word and Int. If 64 we use goog.math.Long.
  1356. */
  1357. var $hs_UTF8_REJECT = 12
  1358. var $hs_utf8d =
  1359. [
  1360. /*
  1361. * The first part of the table maps bytes to character classes that
  1362. * to reduce the size of the transition table and create bitmasks.
  1363. */
  1364. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  1365. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  1366. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  1367. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  1368. 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
  1369. 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
  1370. 8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
  1371. 10,3,3,3,3,3,3,3,3,3,3,3,3,4,3,3, 11,6,6,6,5,8,8,8,8,8,8,8,8,8,8,8,
  1372. /*
  1373. * The second part is a transition table that maps a combination of
  1374. * a state of the automaton and a character class to a state.
  1375. */
  1376. 0,12,24,36,60,96,84,12,12,12,48,72, 12,12,12,12,12,12,12,12,12,12,12,12,
  1377. 12, 0,12,12,12,12,12, 0,12, 0,12,12, 12,24,12,12,12,12,12,24,12,24,12,12,
  1378. 12,12,12,12,12,12,12,24,12,12,12,12, 12,24,12,12,12,12,12,12,12,24,12,12,
  1379. 12,12,12,12,12,12,12,36,12,36,12,12, 12,36,12,12,12,12,12,36,12,36,12,12,
  1380. 12,36,12,12,12,12,12,12,12,12,12,12];
  1381. var $hs_decode = function(state, cp, b) {
  1382. var type = $hs_utf8d[b];
  1383. var codep = (state != $hs_UTF8_ACCEPT) ?
  1384. (b & 0x3f) | (cp << 6) :
  1385. (0xff >>> type) & b;
  1386. return [$hs_utf8d[256 + state + type], codep];
  1387. };
  1388. /*
  1389. * A best-effort decoder. Runs until it hits either end of input or
  1390. * the start of an invalid byte sequence.
  1391. *
  1392. * At exit, updates *destoff with the next offset to write to, and
  1393. * returns the next source offset to read from.
  1394. */
  1395. var _hs_text_decode_utf8 = function(dest, doffptr, src, srcend)
  1396. {
  1397. // Assumes src[0] is srcend[0]
  1398. var srcarray = new Uint8Array(src[0],0);
  1399. var s = src[1];
  1400. var send = srcend[1];
  1401. var destarray = new Uint16Array(dest[0],dest[1]);
  1402. // Should really check the size of size_t and CSize here somehow
  1403. var doffArray = new Uint32Array(doffptr[0], doffptr[1]);
  1404. var doff = doffArray[0];
  1405. var state = $hs_UTF8_ACCEPT;
  1406. var codepoint = 0;
  1407. while (s != srcend) {
  1408. if ($hs_decode(state, codepoint, srcarray[s++]) != $hs_UTF8_ACCEPT) {
  1409. if (state != $hs_UTF8_REJECT)
  1410. continue;
  1411. break;
  1412. }
  1413. if ((codepoint >>> 0) <= 0xffff)
  1414. destarray[doff++] = codepoint;
  1415. else {
  1416. destarray[doff++] = 0xD7C0 + (codepoint >>> 10);
  1417. destarray[doff++] = 0xDC00 + (codepoint & 0x3FF);
  1418. }
  1419. }
  1420. /* Error recovery - if we're not in a valid finishing state, back up. */
  1421. if (state != $hs_UTF8_ACCEPT)
  1422. s -= 1;
  1423. doffArray[0] = doff;
  1424. return [src[0], s, src[2] + (s - src[1])];
  1425. };
  1426. var memcpy = function(dest, src, count) {
  1427. if(typeof(src) === 'string') {
  1428. var destarray = new Uint8Array(dest[0],dest[1]);
  1429. var soff = 0;
  1430. var doff = 0;
  1431. while(count != 0) {
  1432. destarray[doff] = src[soff];
  1433. soff++;
  1434. doff++;
  1435. count--;
  1436. }
  1437. return dest;
  1438. }
  1439. else {
  1440. var destarray = new Uint8Array(dest[0],dest[1]);
  1441. var srcarray = new Uint8Array(src[0],src[1]);
  1442. var doff = 0;
  1443. var soff = 0;
  1444. while(count != 0) {
  1445. destarray[doff] = srcarray[soff];
  1446. soff++;
  1447. doff++;
  1448. count--;
  1449. }
  1450. return dest;
  1451. }
  1452. };
  1453. var memcmp = function(a, b, count) {
  1454. if(typeof(a) === 'string') {
  1455. if(typeof(b) === 'string') {
  1456. var x = a.slice(0,count).localeCompare(b.slice(0,count));
  1457. return x === 0 ? 0 : (x < 0 ? -1 : 1);
  1458. }
  1459. var barray = new Uint8Array(b[0],b[1]);
  1460. var aoff = 0;
  1461. var boff = 0;
  1462. while(count != 0) {
  1463. if( a[aoff] < barray[boff] )
  1464. return -1;
  1465. if( a[aoff] > barray[boff] )
  1466. return 1;
  1467. aoff++;
  1468. boff++;
  1469. count--;
  1470. }
  1471. return 0;
  1472. }
  1473. else {
  1474. if(typeof(b) === 'string') {
  1475. var aarray = new Uint8Array(a[0],a[1]);
  1476. var aoff = 0;
  1477. var boff = 0;
  1478. while(count != 0) {
  1479. if( aarray[aoff] < b[boff] )
  1480. return -1;
  1481. if( aarray[aoff] > b[boff] )
  1482. return 1;
  1483. aoff++;
  1484. boff++;
  1485. count--;
  1486. }
  1487. return 0;
  1488. }
  1489. var aarray = new Uint8Array(a[0],a[1]);
  1490. var barray = new Uint8Array(b[0],b[1]);
  1491. var aoff = 0;
  1492. var boff = 0;
  1493. while(count != 0) {
  1494. if( aarray[aoff] < barray[boff] )
  1495. return -1;
  1496. if( aarray[aoff] > barray[boff] )
  1497. return 1;
  1498. aoff++;
  1499. boff++;
  1500. count--;
  1501. }
  1502. return 0;
  1503. }
  1504. };
  1505. var u_iswalpha = function(a) {
  1506. return goog.string.isAlpha(String.fromCharCode(a)) ?
  1507. (WORD_SIZE_IN_BITS == 32 ? 1 : goog.math.Long.ONE)
  1508. :(WORD_SIZE_IN_BITS == 32 ? 0 : goog.math.Long.ZERO);
  1509. };
  1510. var u_iswalnum = function(a) {
  1511. return goog.string.isAlphaNumeric(String.fromCharCode(a)) ?
  1512. (WORD_SIZE_IN_BITS == 32 ? 1 : goog.math.Long.ONE)
  1513. :(WORD_SIZE_IN_BITS == 32 ? 0 : goog.math.Long.ZERO);
  1514. };
  1515. var u_iswspace = function(a) {
  1516. return goog.string.isSpace(String.fromCharCode(a)) ?
  1517. (WORD_SIZE_IN_BITS == 32 ? 1 : goog.math.Long.ONE)
  1518. :(WORD_SIZE_IN_BITS == 32 ? 0 : goog.math.Long.ZERO);
  1519. };
  1520. var u_iswlower = function(a) {
  1521. return a === u_towupper(a) ?
  1522. (WORD_SIZE_IN_BITS == 32 ? 1 : goog.math.Long.ONE)
  1523. :(WORD_SIZE_IN_BITS == 32 ? 0 : goog.math.Long.ZERO);
  1524. };
  1525. var u_iswupper = function(a) {
  1526. return a === u_towlower(a) ?
  1527. (WORD_SIZE_IN_BITS == 32 ? 1 : goog.math.Long.ONE)
  1528. :(WORD_SIZE_IN_BITS == 32 ? 0 : goog.math.Long.ZERO);
  1529. };
  1530. var u_towlower = function(a) { return String.fromCharCode(a).toLowerCase().charCodeAt(); };
  1531. var u_towupper = function(a) { return String.fromCharCode(a).toUpperCase().charCodeAt(); };
  1532. var rtsSupportsBoundThreads = function () { return 0; };
  1533. var getOrSetGHCConcSignalSignalHandlerStore = function (x) { return x; };
  1534. var stg_sig_install = function(a,b,c) { return -1; };
  1535. var localeEncoding = function() { return $hs_ascii("UTF-32LE"); };
  1536. var hs_iconv_open = function(to,from) { return 1; };
  1537. var hs_iconv_close = function(h) { return 0; };
  1538. var $hs_unsignedCompare = function(a,b) {
  1539. if (a.equals(b)) return 0;
  1540. var aneg = a.isNegative();
  1541. var bneg = b.isNegative();
  1542. if (aneg && !bneg) return 1;
  1543. if (!aneg && bneg) return -1;
  1544. return a.subtract(b).isNegative() ? -1 : 1;
  1545. };
  1546. if(WORD_SIZE_IN_BITS == 32) {
  1547. // Safer 32 bit multiplication than just a * b
  1548. var $hs_timesIntzh = function(a, b) {
  1549. return goog.math.Long(a,0).multiply(goog.math.Long(b,0)).getLowBits(); };
  1550. }
  1551. if(WORD_SIZE_IN_BITS == 64) {
  1552. // Int primatives for 64bit
  1553. var $hs_quotIntzh = function(a, b) {
  1554. return a.div(b); };
  1555. var $hs_remIntzh = function(a, b) {
  1556. return a.modulo(b); };
  1557. var $hs_int2Wordzh = function(a) {
  1558. return a; };
  1559. var $hs_int2Floatzh = function(a) {
  1560. return a.toNumber(); };
  1561. var $hs_int2Doublezh = function(a) {
  1562. return a.toNumber(); };
  1563. var $hs_uncheckedIShiftLzh = function(a, b) {
  1564. return a.shiftLeft(b.toNumber()); };
  1565. var $hs_uncheckedIShiftRAzh = function(a, b) {
  1566. return a.shiftRight(b.toNumber()); };
  1567. var $hs_uncheckedIShiftRLzh = function(a, b) {
  1568. return a.shiftRight(b.toNumber()); };
  1569. // Word primatives for 64bit
  1570. var $hs_quotWordzh = function(a, b) {
  1571. return a.div(b); }; // TODO make unsigned
  1572. var $hs_remWordzh = function(a, b) {
  1573. return a.modulo(b); }; // TODO make unsigned
  1574. var $hs_uncheckedShiftLzh = function(a, b) {
  1575. return a.shiftLeft(b.toNumber()); };
  1576. var $hs_uncheckedShiftRLzh = function(a, b) {
  1577. return a.shiftRight(b.toNumber()); };
  1578. var $hs_word2Intzh = function(a) {
  1579. return a; };
  1580. var $hs_gtWordzh = function(a, b) {
  1581. return $hs_mkBool($hs_unsignedCompare(a, b) > 0); };
  1582. var $hs_geWordzh = function(a, b) {
  1583. return $hs_mkBool($hs_unsignedCompare(a, b) >= 0); };
  1584. var $hs_eqWordzh = function(a, b) {
  1585. return $hs_mkBool(a.equals(b)); };
  1586. var $hs_neWordzh = function(a, b) {
  1587. return $hs_mkBool(a.notEquals(b)); };
  1588. var $hs_ltWordzh = function(a, b) {
  1589. return $hs_mkBool($hs_unsignedCompare(a, b) < 0); };
  1590. var $hs_leWordzh = function(a, b) {
  1591. return $hs_mkBool($hs_unsignedCompare(a, b) <= 0); };
  1592. var $hs_intToIntzh = function(i) {
  1593. return goog.math.Long.fromInt(i); };
  1594. var $hs_intzhToInt = function(i) {
  1595. return i.toInt(); };
  1596. var $hs_int64ToWordzh = function(i) {
  1597. return i; };
  1598. var $hs_wordToWordzh = function(i) {
  1599. return goog.math.Long.fromBits(i,0); };
  1600. var $hs_wordzhToWord = function(i) {
  1601. return i.getLowBits(); };
  1602. var $hs_word64ToIntzh = function(i) {
  1603. return i; };
  1604. var $hs_narrow8Intzh = function(i) {
  1605. low = i.getLowBits();
  1606. return goog.math.Long.fromNumber((low & 0x7F) - (low & 0x80)); };
  1607. var $hs_narrow16Intzh = function(i) {
  1608. low = i.getLowBits();
  1609. return goog.math.Long.fromNumber((low & 0x7FFF) - (low & 0x8000)); };
  1610. var $hs_narrow32Intzh = function(i) {
  1611. return goog.math.Long.fromNumber(i.getLowBits()|0); };
  1612. var $hs_narrow8Wordzh = function(i) {
  1613. return goog.math.Long.fromBits(i.getLowBits() & 0xFF, 0); };
  1614. var $hs_narrow16Wordzh = function(i) {
  1615. return goog.math.Long.fromBits(i.getLowBits() & 0xFFFF, 0); };
  1616. var $hs_narrow32Wordzh = function(i) {
  1617. return goog.math.Long.fromBits(i.getLowBits(), 0); };
  1618. }
  1619. var hs_gtWord64 = function(a, b) {
  1620. return $hs_unsignedCompare(a, b) > 0 ? 1 : 0; };
  1621. var hs_geWord64 = function(a, b) {
  1622. return $hs_unsignedCompare(a, b) >= 0 ? 1 : 0; };
  1623. var hs_eqWord64 = function(a, b) {
  1624. return a.equals(b) ? 1 : 0; };
  1625. var hs_neWord64 = function(a, b) {
  1626. return a.notEquals(b) ? 1 : 0; };
  1627. var hs_ltWord64 = function(a, b) {
  1628. return $hs_unsignedCompare(a, b) < 0 ? 1 : 0; };
  1629. var hs_leWord64 = function(a, b) {
  1630. return $hs_unsignedCompare(a, b) <= 0 ? 1 : 0; };
  1631. var hs_gtInt64 = function(a, b) {
  1632. return a.greaterThan(b) ? 1 : 0; };
  1633. var hs_geInt64 = function(a, b) {
  1634. return a.greaterThanOrEqual(b) ? 1 : 0; };
  1635. var hs_eqInt64 = function(a, b) {
  1636. return a.equals(b) ? 1 : 0; };
  1637. var hs_neInt64 = function(a, b) {
  1638. return a.notEquals(b) ? 1 : 0; };
  1639. var hs_ltInt64 = function(a, b) {
  1640. return a.lessThan(b) ? 1 : 0; };
  1641. var hs_leInt64 = function(a, b) {
  1642. return a.lessThanOrEqual(b) ? 1 : 0; };
  1643. var hs_remWord64 = function(a, b) {
  1644. return a.modulo(b); }; // TODO make unsigned
  1645. var hs_quotWord64 = function(a, b) {
  1646. return a.div(b); }; // TODO make unsigned
  1647. var hs_remInt64 = function(a, b) {
  1648. return a.modulo(b); };
  1649. var hs_quotInt64 = function(a, b) {
  1650. return a.div(b); };
  1651. var hs_negateInt64 = function(a) {
  1652. return a.negate(); };
  1653. var hs_plusInt64 = function(a, b) {
  1654. return a.add(b); };
  1655. var hs_minusInt64 = function(a, b) {
  1656. return a.subtract(b); };
  1657. var hs_timesInt64 = function(a, b) {
  1658. return a.multiply(b); };
  1659. var hs_and64 = function(a, b) {
  1660. return a.and(b); };
  1661. var hs_or64 = function(a, b) {
  1662. return a.or(b); };
  1663. var hs_xor64 = function(a, b) {
  1664. return a.xor(b); };
  1665. var hs_not64 = function(a) {
  1666. return a.not(); };
  1667. var hs_uncheckedShiftL64 = function(a, b) {
  1668. return a.shiftLeft(b); };
  1669. var hs_uncheckedShiftRL64 = function(a, b) {
  1670. return a.shiftRight(b); };
  1671. var hs_uncheckedIShiftL64 = function(a, b) {
  1672. return a.shiftLeft(b); };
  1673. var hs_uncheckedIShiftRA64 = function(a, b) {
  1674. return a.shiftRight(b); };
  1675. var hs_uncheckedIShiftRL64 = function(a, b) {
  1676. return a.shiftRight(b); };
  1677. var hs_intToInt64 = function(i) {
  1678. return goog.math.Long.fromInt(i); };
  1679. var hs_int64ToInt = function(i) {
  1680. return i.toInt(); };
  1681. var hs_int64ToWord64 = function(i) {
  1682. return i; };
  1683. var hs_wordToWord64 = function(i) {
  1684. return goog.math.Long.fromBits(i,0); };
  1685. var hs_word64ToWord = function(i) {
  1686. return i.getLowBits(); };
  1687. var hs_word64ToInt64 = function(i) {
  1688. return i; };
  1689. var errno = 0;
  1690. var __hscore_get_errno = function() {
  1691. HS_RTS_TRACE && $hs_logger.info('__hscore_get_errno');
  1692. return errno;
  1693. }
  1694. var __hscore_set_errno = function(e) {
  1695. HS_RTS_TRACE && $hs_logger.info('__hscore_set_errno');
  1696. errno = e;
  1697. };
  1698. var strerror = function(e) {
  1699. return $hs_utf32("Error "+e);
  1700. }
  1701. var __hscore_s_isreg = function(m) {
  1702. HS_RTS_TRACE && $hs_logger.info('__hscore_s_isreg');
  1703. return 1;
  1704. };
  1705. var __hscore_s_isdir = function(m) {
  1706. HS_RTS_TRACE && $hs_logger.info('__hscore_s_isdir');
  1707. return 0;
  1708. };
  1709. var __hscore_s_isfifo = function(m) {
  1710. HS_RTS_TRACE && $hs_logger.info('__hscore_s_isfifo');
  1711. return 0;
  1712. };
  1713. var __hscore_s_isblk = function(m) {
  1714. HS_RTS_TRACE && $hs_logger.info('__hscore_s_isblk');
  1715. return 0;
  1716. };
  1717. var __hscore_s_ischr = function(m) {
  1718. HS_RTS_TRACE && $hs_logger.info('__hscore_s_ischr');
  1719. return 0;
  1720. };
  1721. var __hscore_s_issock = function(m) {
  1722. HS_RTS_TRACE && $hs_logger.info('__hscore_s_issock');
  1723. return 0;
  1724. };
  1725. var __hscore_sigemptyset = function(set) { return 0; };
  1726. var __hscore_sigfillset = function(set) { return 0; };
  1727. var __hscore_sigaddset = function(set, s) { return 0; };
  1728. var __hscore_sigdelset = function(set, s) { return 0; };
  1729. var __hscore_sigismember = function(set, s) { return 0; };
  1730. var __hscore_memcpy_src_off = function(dest, src, soff, count) {
  1731. var doff = 0;
  1732. var srcarray = new Uint8Array(src[0]);
  1733. var destarray = new Uint8Array(dest[0]);
  1734. while(count != 0) {
  1735. destarray[doff] = srcarray[soff];
  1736. soff++;
  1737. doff++;
  1738. count--;
  1739. }
  1740. };
  1741. var __hscore_bufsiz = function() { return 1024; };
  1742. var __hscore_seek_cur = function() { return 1; };
  1743. var __hscore_seek_set = function() { return 0; };
  1744. var __hscore_seek_end = function() { return 2; };
  1745. var __hscore_o_binary = function() { return 0; };
  1746. var __hscore_o_rdonly = function() { return 0; };
  1747. var __hscore_o_wronly = function() { return 0x0001; };
  1748. var __hscore_o_rdwr = function() { return 0x0002; };
  1749. var __hscore_o_append = function() { return 0x0008; };
  1750. var __hscore_o_creat = function() { return 0x0200; };
  1751. var __hscore_o_excl = function() { return 0x0800; };
  1752. var __hscore_o_trunc = function() { return 0x0400; };
  1753. var __hscore_o_noctty = function() { return 0x20000; };
  1754. var __hscore_o_nonblock = function() { return 0x0004; };
  1755. var __hscore_ftruncate = function(fd, where) {
  1756. HS_RTS_TRACE && $hs_logger.info('__hscore_ftruncate');
  1757. return 0;
  1758. };
  1759. var __hscore_setmode = function(fd, toBin) {
  1760. HS_RTS_TRACE && $hs_logger.info('__hscore_setmode');
  1761. return 0;
  1762. };
  1763. var __hscore_sizeof_stat = function() { return 4; };
  1764. var __hscore_st_mtime = function(st) {
  1765. HS_RTS_TRACE && $hs_logger.info('__hscore_st_mtime');
  1766. return 0;
  1767. };
  1768. var __hscore_st_size = function(st) {
  1769. HS_RTS_TRACE && $hs_logger.info('__hscore_st_size');
  1770. return 0;
  1771. };
  1772. var __hscore_st_mode = function(st) {
  1773. HS_RTS_TRACE && $hs_logger.info('__hscore_st_mode');
  1774. return 0;
  1775. };
  1776. var __hscore_st_dev = function(st) {
  1777. HS_RTS_TRACE && $hs_logger.info('__hscore_st_dev');
  1778. return 0;
  1779. };
  1780. var __hscore_st_ino = function(st) {
  1781. HS_RTS_TRACE && $hs_logger.info('__hscore_st_ino');
  1782. return 0;
  1783. };
  1784. var __hscore_stat = function(f, buf) {
  1785. var p = $hs_fromUtf32(f);
  1786. HS_RTS_TRACE && $hs_logger.info('__hscore_stat '+p);
  1787. return 0;
  1788. };
  1789. var __hscore_fstat = function(fd, buf) {
  1790. HS_RTS_TRACE && $hs_logger.info('__hscore_fstat');
  1791. return 0;
  1792. };
  1793. var __hscore_lstat = function(f, buf) {
  1794. var p = $hs_fromUtf32(f);
  1795. HS_RTS_TRACE && $hs_logger.info('__hscore_lstat '+p);
  1796. return 0;
  1797. };
  1798. var __hscore_lflag = function(ts) {
  1799. HS_RTS_TRACE && $hs_logger.info('__hscore_fstat');
  1800. return ts.c_lflag;
  1801. };
  1802. var __hscore_poke_lflag = function(ts, t) {
  1803. HS_RTS_TRACE && $hs_logger.info('__hscore_poke_lflag');
  1804. ts.c_lflag = t;
  1805. };
  1806. var __hscore_ptr_c_cc = function(ts) {
  1807. HS_RTS_TRACE && $hs_logger.info('__hscore_ptr_c_cc');
  1808. return ts.c_cc;
  1809. };
  1810. var __hscore_sizeof_termios = function() { return 0; };
  1811. var __hscore_sizeof_sigset_t = function() { return 0; };
  1812. var __hscore_echo = function() { return 0; };
  1813. var __hscore_tcsanow = function() { return 0; };
  1814. var __hscore_icanon = function() { return 0; };
  1815. var __hscore_vmin = function() { return 0; };
  1816. var __hscore_vtime = function() { return 0; };
  1817. var __hscore_sigttou = function() { return 0; };
  1818. var __hscore_sig_block = function() { return 0; };
  1819. var __hscore_sig_setmask = function() { return 0; };
  1820. var __hscore_sizeof_siginfo_t = function() { return 0; };
  1821. var __hscore_f_getfl = function() { return 0; };
  1822. var __hscore_f_setfl = function() { return 0; };
  1823. var __hscore_f_setfd = function() { return 0; };
  1824. var __hscore_fd_cloexec = function() { return 0; };
  1825. var __hscore_get_saved_termios = function(fd) {
  1826. HS_RTS_TRACE && $hs_logger.info('__hscore_get_saved_termios');
  1827. return null;
  1828. };
  1829. var __hscore_set_saved_termios = function(fd, ts) {
  1830. HS_RTS_TRACE && $hs_logger.info('__hscore_set_saved_termios');
  1831. };
  1832. var __hscore_hs_fileno = function(f) {
  1833. HS_RTS_TRACE && $hs_logger.info('__hscore_hs_fileno');
  1834. return 0;
  1835. };
  1836. var $hs_fstab = [];
  1837. var $hs_getFileURL = function(f) {
  1838. for(var i=0;i!==$hs_fstab.length;i++) {
  1839. if(f.slice(0, $hs_fstab[i].mountPoint.length) === $hs_fstab[i].mountPoint)
  1840. return $hs_fstab[i].url + f.slice($hs_fstab[i].mountPoint.length);
  1841. }
  1842. return null;
  1843. };
  1844. var $hs_allFiles = [
  1845. { text:"", fptr:0 }, // stdin
  1846. { text:"", fptr:0 }, // stdout
  1847. { text:"", fptr:0 } // stderr
  1848. ];
  1849. var fdReady = function (fd) {
  1850. if (fd >= $hs_allFiles.length) return -1;
  1851. var f = $hs_allFiles[fd];
  1852. return f.text.length > f.fptr ? 1 : 0;
  1853. };
  1854. var $hs_findFile = function(f) {
  1855. for(var i=0;i!==$hs_allFiles.length;i++) {
  1856. if(f===$hs_allFiles[i].path)
  1857. return i;
  1858. }
  1859. return -1;
  1860. };
  1861. var __hscore_open = function(f,h,m) {
  1862. var p = $hs_fromUtf32(f);
  1863. HS_RTS_TRACE && $hs_logger.info('__hscore_open '+p);
  1864. var result=$hs_findFile(p);
  1865. if(result===-1) {
  1866. var url = $hs_getFileURL(p);
  1867. if(url!==null) {
  1868. try {
  1869. var transport = new XMLHttpRequest();
  1870. transport.open("GET", url, false);
  1871. transport.send(null);
  1872. if (transport.status == 200 || transport.status == 0) {
  1873. result = $hs_allFiles.length;
  1874. $hs_allFiles[result] = {text:transport.responseText, fptr:0, path:p};
  1875. }
  1876. else {
  1877. $hs_logError("Error " + transport.status + " opening file: " + p +" ( " + url + " )");
  1878. }
  1879. } catch (e) {
  1880. $hs_logError("Error opening file: " + p + " ( " + url + " ) :\n" + e);
  1881. }
  1882. }
  1883. else {
  1884. if(m & __hscore_o_creat() !== 0) {
  1885. result = $hs_allFiles.length;
  1886. $hs_allFiles[result] = {text:"", fptr:0, path:p};
  1887. }
  1888. }
  1889. }
  1890. return result;
  1891. };
  1892. var close = function(fd) {
  1893. HS_RTS_TRACE && $hs_logger.info('close');
  1894. return 0;
  1895. };
  1896. var __hscore_lseek = function(fd, off, whence) {
  1897. HS_RTS_TRACE && $hs_logger.info('__hscore_lseek');
  1898. return 0;
  1899. };
  1900. var hsFD_SETSIZE = function() { return 1024; };
  1901. var hsFD_ISSET = function(fd, fds) {
  1902. HS_RTS_TRACE && $hs_logger.info('hsFD_ISSET');
  1903. return 0;
  1904. };
  1905. var hsFD_SET = function(fd, fds) {
  1906. HS_RTS_TRACE && $hs_logger.info('hsFD_SET');
  1907. };
  1908. var sizeof_fd_set = function() {
  1909. HS_RTS_TRACE && $hs_logger.info('sizeof_fd_set');
  1910. return 0;
  1911. };
  1912. var hsFD_ZERO = function(fds) {
  1913. HS_RTS_TRACE && $hs_logger.info('hsFD_ZERO');
  1914. };
  1915. var __hscore_select = function(nfds, readfds, writefds, exceptfds, timeout) {
  1916. HS_RTS_TRACE && $hs_logger.info('hsFD_ZERO');
  1917. return 0;
  1918. };
  1919. var environ = {};
  1920. environ['TMPDIR'] = $hs_utf32("/tmp");
  1921. var __hscore_environ = function() {
  1922. HS_RTS_TRACE && $hs_logger.info('__hscore_environ');
  1923. return environ;
  1924. };
  1925. var getenv = function(e) {
  1926. var s = $hs_fromUtf32(e);
  1927. HS_RTS_TRACE && $hs_logger.info('getenv '+s);
  1928. var v = environ[s];
  1929. return v===undefined?null:v;
  1930. };
  1931. var lockFile = function(fd, dev, ino, for_writing) {
  1932. HS_RTS_TRACE && $hs_logger.info('lockFile');
  1933. return 0;
  1934. };
  1935. var unlockFile = function(fd) {
  1936. HS_RTS_TRACE && $hs_logger.info('unlockFile');
  1937. return 0;
  1938. };
  1939. var isatty = function(fd) {
  1940. HS_RTS_TRACE && $hs_logger.info('isatty');
  1941. return 0;
  1942. };
  1943. var read = function(fd, p, s) {
  1944. HS_RTS_TRACE && $hs_logger.info('read');
  1945. var f = $hs_allFiles[fd];
  1946. if (f === undefined || f === null)
  1947. return -1;
  1948. var n = f.text.length - f.fptr;
  1949. if( n <= 0 ) {
  1950. HS_RTS_TRACE && $hs_logger.info('read : end of file');
  1951. return 0;
  1952. }
  1953. var maxChars = s>>>2;
  1954. if( n > maxChars )
  1955. n = maxChars;
  1956. var end = f.fptr + n;
  1957. var dest = new Uint32Array(p[0], p[1]);
  1958. for(var i=f.fptr;i!=end;i++)
  1959. dest[i]=f.text.charCodeAt(i);
  1960. f.fptr=end;
  1961. HS_RTS_TRACE && $hs_logger.info('read : '+(n<<2));
  1962. return n<<2;
  1963. };
  1964. var write = function(fd, p, s) {
  1965. HS_RTS_TRACE && $hs_logger.info('write');
  1966. var f = $hs_allFiles[fd];
  1967. if (f === undefined || f === null)
  1968. return -1;
  1969. var len = s>>>2;
  1970. var src = new Uint32Array(p[0], p[1]);
  1971. var res = "";
  1972. for(var i=0;i!=len;i++)
  1973. res=res+String.fromCharCode(src[i]);
  1974. if(f.fptr <= f.text.length)
  1975. f.text=f.text+res;
  1976. else if(f.text.length > f.fptr + len)
  1977. f.text=f.text.slice(0,f.fptr)+res+f.text.slice(f.fptr+len);
  1978. else
  1979. f.text=f.text.slice(0,f.fptr)+res+f.text.slice(f.fptr+len);
  1980. return s;
  1981. };
  1982. var ghc_strlen = function(s) {
  1983. return s.indexOf('\x00');
  1984. };
  1985. var initLinker = function() {
  1986. HS_RTS_TRACE && $hs_logger.info('initLinker');
  1987. };
  1988. var exitLinker = function() {
  1989. HS_RTS_TRACE && $hs_logger.info('exitLinker');
  1990. };
  1991. var $hs_loaded = [];
  1992. var $hs_loadPath = "./";
  1993. var $hs_loading = false;
  1994. /**
  1995. * @param {Array.<Object>} args
  1996. * @param {function(!string)} onComplete
  1997. * @param {function(!Object)=} onException
  1998. */
  1999. var $hs_fromString = function(args, onComplete, onException) {
  2000. var loop = function(res, a) {
  2001. $hs_force(a, function(s) {
  2002. switch (s.g) {
  2003. case 1: // nil
  2004. onComplete(res);
  2005. break;
  2006. case 2: // cons
  2007. var chthunk = s.v[0];
  2008. var sthunk = s.v[1];
  2009. $hs_force([chthunk], function(ch){
  2010. loop(res+ch.v[0],[sthunk]);}, onException);
  2011. break;
  2012. default:
  2013. throw "undefined";
  2014. }
  2015. }, onException);
  2016. }
  2017. loop("", args);
  2018. };
  2019. /**
  2020. * @param {string} s
  2021. * @return {!Object}
  2022. */
  2023. var $hs_toString = function(s) {
  2024. var x = $d(1, []);
  2025. for(var i=s.length;i!=0;)
  2026. x=$d(2, [$d(1, [s.charAt(--i)]), x]);
  2027. return x;
  2028. };
  2029. /**
  2030. * @param {Array.<Object>} args
  2031. * @param {function(!string)} onComplete
  2032. * @param {function(!Object)=} onException
  2033. */
  2034. var $hs_fromText = function(args, onComplete, onException) {
  2035. $hs_force(args, function(s) {
  2036. if(HS_DEBUG && s.g !== 1) throw "Invalid Text";
  2037. var arr = s.v[0];
  2038. var off = WORD_SIZE_IN_BITS == 32 ? s.v[1] : s.v[1].toNumb