quickjs 0.9.0 → 0.11.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b35606f03fd2d506d2f460873000dcfd75595a2639b4d921ed6f8d76e4fff118
4
- data.tar.gz: 3c42d67e4e6d57936a34e5ee93669722e5187f7f8b389fa789798fd3ec37abe8
3
+ metadata.gz: e79081c82cb9b414f3c77b44883c6e025558aea6c3000f204b7da4df411642e4
4
+ data.tar.gz: 8d0be576f2b301e793e767f8f3a9c7529856e6694d2655beaf14efeb85aab043
5
5
  SHA512:
6
- metadata.gz: ff5cc1f531fe2c7c5ecc098a024fd6fe4ca62088565e2d6fe46be77e0aeea7db97eba84c1bfb2e032628e60805346f1f6ffafa885287a5c67e553e790668b7c2
7
- data.tar.gz: 1a4c6ae31c835475f4146531e7d19e08d5542331e37541832010a920b6510c27cc6512ef119c70a310d11786b535f2f71891f538e9a80a275afadf52c462bd9e
6
+ metadata.gz: 12404c2ffe3dbc5021eefbf6b8b42bdb9a74d2aa649b55eeb57ad92dbb9330c2d95834401af7a8a8471bc85db0adeebd3d877c5d46b421bc0320b356671253b3
7
+ data.tar.gz: 387ef0a683d6169e113a3488208c8a75d7409e574eddecc416c059cf9d0d0282b1c3a0c267c54b5b74a2065bb843da5a90070db9c33b34ddc86b9919e7161990
@@ -176,6 +176,8 @@ int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,
176
176
  va_start(ap, fmt);
177
177
  len = vsnprintf(buf, sizeof(buf), fmt, ap);
178
178
  va_end(ap);
179
+ if (len < 0)
180
+ return -1;
179
181
  if (len < sizeof(buf)) {
180
182
  /* fast case */
181
183
  return dbuf_put(s, (uint8_t *)buf, len);
@@ -364,4 +364,60 @@ static inline double uint64_as_float64(uint64_t u64)
364
364
  return u.d;
365
365
  }
366
366
 
367
+ static inline double fromfp16(uint16_t v)
368
+ {
369
+ double d;
370
+ uint32_t v1;
371
+ v1 = v & 0x7fff;
372
+ if (unlikely(v1 >= 0x7c00))
373
+ v1 += 0x1f8000; /* NaN or infinity */
374
+ d = uint64_as_float64(((uint64_t)(v >> 15) << 63) | ((uint64_t)v1 << (52 - 10)));
375
+ return d * 0x1p1008;
376
+ }
377
+
378
+ static inline uint16_t tofp16(double d)
379
+ {
380
+ uint64_t a, addend;
381
+ uint32_t v, sgn;
382
+ int shift;
383
+
384
+ a = float64_as_uint64(d);
385
+ sgn = a >> 63;
386
+ a = a & 0x7fffffffffffffff;
387
+ if (unlikely(a > 0x7ff0000000000000)) {
388
+ /* nan */
389
+ v = 0x7c01;
390
+ } else if (a < 0x3f10000000000000) { /* 0x1p-14 */
391
+ /* subnormal f16 number or zero */
392
+ if (a <= 0x3e60000000000000) { /* 0x1p-25 */
393
+ v = 0x0000; /* zero */
394
+ } else {
395
+ shift = 1051 - (a >> 52);
396
+ a = ((uint64_t)1 << 52) | (a & (((uint64_t)1 << 52) - 1));
397
+ addend = ((a >> shift) & 1) + (((uint64_t)1 << (shift - 1)) - 1);
398
+ v = (a + addend) >> shift;
399
+ }
400
+ } else {
401
+ /* normal number or infinity */
402
+ a -= 0x3f00000000000000; /* adjust the exponent */
403
+ /* round */
404
+ addend = ((a >> (52 - 10)) & 1) + (((uint64_t)1 << (52 - 11)) - 1);
405
+ v = (a + addend) >> (52 - 10);
406
+ /* overflow ? */
407
+ if (unlikely(v > 0x7c00))
408
+ v = 0x7c00;
409
+ }
410
+ return v | (sgn << 15);
411
+ }
412
+
413
+ static inline int isfp16nan(uint16_t v)
414
+ {
415
+ return (v & 0x7FFF) > 0x7C00;
416
+ }
417
+
418
+ static inline int isfp16zero(uint16_t v)
419
+ {
420
+ return (v & 0x7FFF) == 0;
421
+ }
422
+
367
423
  #endif /* CUTILS_H */
@@ -1147,6 +1147,9 @@ int js_dtoa(char *buf, double d, int radix, int n_digits, int flags,
1147
1147
  P = n_digits + 1;
1148
1148
  else
1149
1149
  P = n_digits;
1150
+ /* "-0" is displayed as "0" if JS_DTOA_MINUS_ZERO is not present */
1151
+ if (sgn && (flags & JS_DTOA_MINUS_ZERO))
1152
+ *q++ = '-';
1150
1153
  goto output;
1151
1154
  }
1152
1155
  /* denormal number: convert to a normal number */
@@ -1156,6 +1159,8 @@ int js_dtoa(char *buf, double d, int radix, int n_digits, int flags,
1156
1159
  } else {
1157
1160
  m |= (uint64_t)1 << 52;
1158
1161
  }
1162
+ if (sgn)
1163
+ *q++ = '-';
1159
1164
  /* remove the bias */
1160
1165
  e -= 1022;
1161
1166
  /* d = 2^(e-53)*m */
@@ -1167,8 +1172,6 @@ int js_dtoa(char *buf, double d, int radix, int n_digits, int flags,
1167
1172
  (flags & JS_DTOA_EXP_MASK) != JS_DTOA_EXP_ENABLED) {
1168
1173
  m >>= 53 - e;
1169
1174
  /* 'm' is never zero */
1170
- if (sgn)
1171
- *q++ = '-';
1172
1175
  q += u64toa_radix(q, m, radix);
1173
1176
  goto done;
1174
1177
  }
@@ -1244,10 +1247,6 @@ int js_dtoa(char *buf, double d, int radix, int n_digits, int flags,
1244
1247
  /* frac is rounded using RNDNA */
1245
1248
  mul_pow_round(tmp1, m, e - 53, radix1, radix_shift, n_digits, JS_RNDNA);
1246
1249
 
1247
- /* "-0" is displayed as "0" */
1248
- if (sgn && !(tmp1->tab[0] == 0 && tmp1->len == 1)) {
1249
- *q++ = '-';
1250
- }
1251
1250
  /* we add one extra digit on the left and remove it if needed
1252
1251
  to avoid testing if the result is < radix^P */
1253
1252
  len = output_digits(q, tmp1, radix, max_int(E + 1, 1) + n_digits,
@@ -1277,11 +1276,6 @@ int js_dtoa(char *buf, double d, int radix, int n_digits, int flags,
1277
1276
  }
1278
1277
  }
1279
1278
  output:
1280
- /* "-0" is displayed as "0" if JS_DTOA_MINUS_ZERO is not present */
1281
- if (sgn && ((flags & JS_DTOA_MINUS_ZERO) ||
1282
- !(tmp1->tab[0] == 0 && tmp1->len == 1))) {
1283
- *q++ = '-';
1284
- }
1285
1279
  if (fmt == JS_DTOA_FORMAT_FIXED)
1286
1280
  E_max = n_digits;
1287
1281
  else
@@ -26,11 +26,15 @@
26
26
 
27
27
  DEF(invalid, 1) /* never used */
28
28
  DEF(char, 3)
29
+ DEF(char_i, 3)
29
30
  DEF(char32, 5)
31
+ DEF(char32_i, 5)
30
32
  DEF(dot, 1)
31
33
  DEF(any, 1) /* same as dot but match any character including line terminator */
32
34
  DEF(line_start, 1)
35
+ DEF(line_start_m, 1)
33
36
  DEF(line_end, 1)
37
+ DEF(line_end_m, 1)
34
38
  DEF(goto, 5)
35
39
  DEF(split_goto_first, 5)
36
40
  DEF(split_next_first, 5)
@@ -42,11 +46,17 @@ DEF(loop, 5) /* decrement the top the stack and goto if != 0 */
42
46
  DEF(push_i32, 5) /* push integer on the stack */
43
47
  DEF(drop, 1)
44
48
  DEF(word_boundary, 1)
49
+ DEF(word_boundary_i, 1)
45
50
  DEF(not_word_boundary, 1)
51
+ DEF(not_word_boundary_i, 1)
46
52
  DEF(back_reference, 2)
47
- DEF(backward_back_reference, 2) /* must come after back_reference */
53
+ DEF(back_reference_i, 2) /* must come after */
54
+ DEF(backward_back_reference, 2) /* must come after */
55
+ DEF(backward_back_reference_i, 2) /* must come after */
48
56
  DEF(range, 3) /* variable length */
57
+ DEF(range_i, 3) /* variable length */
49
58
  DEF(range32, 3) /* variable length */
59
+ DEF(range32_i, 3) /* variable length */
50
60
  DEF(lookahead, 5)
51
61
  DEF(negative_lookahead, 5)
52
62
  DEF(push_char_pos, 1) /* push the character position on the stack */