Skip to content

Commit 28f286f

Browse files
committed
更新到2023-12-09版本
1 parent 1e6ca69 commit 28f286f

16 files changed

+3390
-3467
lines changed

Changelog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2023-12-09:
2+
3+
- added Object.hasOwn, {String|Array|TypedArray}.prototype.at,
4+
{Array|TypedArray}.prototype.findLast{Index}
5+
- BigInt support is enabled even if CONFIG_BIGNUM disabled
6+
- updated to Unicode 15.0.0
7+
- misc bug fixes
8+
19
2021-03-27:
210

311
- faster Array.prototype.push and Array.prototype.unshift

Makefile

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ prefix=/usr/local
4747
#CONFIG_PROFILE=y
4848
# use address sanitizer
4949
#CONFIG_ASAN=y
50-
# include the code for BigInt/BigFloat/BigDecimal and math mode
50+
# include the code for BigFloat/BigDecimal, math mode and faster large integers
5151
CONFIG_BIGNUM=y
5252

5353
OBJDIR=.obj
@@ -166,11 +166,10 @@ endif
166166

167167
all: $(OBJDIR) $(OBJDIR)/quickjs.check.o $(OBJDIR)/qjs.check.o $(PROGS)
168168

169-
QJS_LIB_OBJS=$(OBJDIR)/quickjs.o $(OBJDIR)/libregexp.o $(OBJDIR)/libunicode.o $(OBJDIR)/cutils.o $(OBJDIR)/quickjs-libc.o
169+
QJS_LIB_OBJS=$(OBJDIR)/quickjs.o $(OBJDIR)/libregexp.o $(OBJDIR)/libunicode.o $(OBJDIR)/cutils.o $(OBJDIR)/quickjs-libc.o $(OBJDIR)/libbf.o
170170

171171
QJS_OBJS=$(OBJDIR)/qjs.o $(OBJDIR)/repl.o $(QJS_LIB_OBJS)
172172
ifdef CONFIG_BIGNUM
173-
QJS_LIB_OBJS+=$(OBJDIR)/libbf.o
174173
QJS_OBJS+=$(OBJDIR)/qjscalc.o
175174
endif
176175

@@ -317,10 +316,7 @@ endif
317316
HELLO_SRCS=examples/hello.js
318317
HELLO_OPTS=-fno-string-normalize -fno-map -fno-promise -fno-typedarray \
319318
-fno-typedarray -fno-regexp -fno-json -fno-eval -fno-proxy \
320-
-fno-date -fno-module-loader
321-
ifdef CONFIG_BIGNUM
322-
HELLO_OPTS+=-fno-bigint
323-
endif
319+
-fno-date -fno-module-loader -fno-bigint
324320

325321
hello.c: $(QJSC) $(HELLO_SRCS)
326322
$(QJSC) -e $(HELLO_OPTS) -o $@ $(HELLO_SRCS)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2021-03-27
1+
2023-12-09

libbf.c

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@
3737

3838
/* enable it to check the multiplication result */
3939
//#define USE_MUL_CHECK
40+
#ifdef CONFIG_BIGNUM
4041
/* enable it to use FFT/NTT multiplication */
4142
#define USE_FFT_MUL
4243
/* enable decimal floating point support */
4344
#define USE_BF_DEC
45+
#endif
4446

4547
//#define inline __attribute__((always_inline))
4648

@@ -164,6 +166,21 @@ static inline slimb_t sat_add(slimb_t a, slimb_t b)
164166
return r;
165167
}
166168

169+
static inline __maybe_unused limb_t shrd(limb_t low, limb_t high, long shift)
170+
{
171+
if (shift != 0)
172+
low = (low >> shift) | (high << (LIMB_BITS - shift));
173+
return low;
174+
}
175+
176+
static inline __maybe_unused limb_t shld(limb_t a1, limb_t a0, long shift)
177+
{
178+
if (shift != 0)
179+
return (a1 << shift) | (a0 >> (LIMB_BITS - shift));
180+
else
181+
return a1;
182+
}
183+
167184
#define malloc(s) malloc_is_forbidden(s)
168185
#define free(p) free_is_forbidden(p)
169186
#define realloc(p, s) realloc_is_forbidden(p, s)
@@ -236,7 +253,7 @@ int bf_set_ui(bf_t *r, uint64_t a)
236253
a1 = a >> 32;
237254
shift = clz(a1);
238255
r->tab[0] = a0 << shift;
239-
r->tab[1] = (a1 << shift) | (a0 >> (LIMB_BITS - shift));
256+
r->tab[1] = shld(a1, a0, shift);
240257
r->expn = 2 * LIMB_BITS - shift;
241258
}
242259
#endif
@@ -1585,7 +1602,9 @@ int bf_mul(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
15851602
r = &tmp;
15861603
}
15871604
if (bf_resize(r, a_len + b_len)) {
1605+
#ifdef USE_FFT_MUL
15881606
fail:
1607+
#endif
15891608
bf_set_nan(r);
15901609
ret = BF_ST_MEM_ERROR;
15911610
goto done;
@@ -2282,11 +2301,14 @@ static int bf_pow_ui_ui(bf_t *r, limb_t a1, limb_t b,
22822301
bf_t a;
22832302
int ret;
22842303

2304+
#ifdef USE_BF_DEC
22852305
if (a1 == 10 && b <= LIMB_DIGITS) {
22862306
/* use precomputed powers. We do not round at this point
22872307
because we expect the caller to do it */
22882308
ret = bf_set_ui(r, mp_pow_dec[b]);
2289-
} else {
2309+
} else
2310+
#endif
2311+
{
22902312
bf_init(r->ctx, &a);
22912313
ret = bf_set_ui(&a, a1);
22922314
ret |= bf_pow_ui(r, &a, b, prec, flags);
@@ -5392,21 +5414,6 @@ int bf_acos(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
53925414

53935415
#endif /* LIMB_BITS != 64 */
53945416

5395-
static inline __maybe_unused limb_t shrd(limb_t low, limb_t high, long shift)
5396-
{
5397-
if (shift != 0)
5398-
low = (low >> shift) | (high << (LIMB_BITS - shift));
5399-
return low;
5400-
}
5401-
5402-
static inline __maybe_unused limb_t shld(limb_t a1, limb_t a0, long shift)
5403-
{
5404-
if (shift != 0)
5405-
return (a1 << shift) | (a0 >> (LIMB_BITS - shift));
5406-
else
5407-
return a1;
5408-
}
5409-
54105417
#if LIMB_DIGITS == 19
54115418

54125419
/* WARNING: hardcoded for b = 1e19. It is assumed that:

libregexp.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,11 +1071,10 @@ static int re_is_simple_quantifier(const uint8_t *bc_buf, int bc_buf_len)
10711071
}
10721072

10731073
/* '*pp' is the first char after '<' */
1074-
static int re_parse_group_name(char *buf, int buf_size,
1075-
const uint8_t **pp, BOOL is_utf16)
1074+
static int re_parse_group_name(char *buf, int buf_size, const uint8_t **pp)
10761075
{
1077-
const uint8_t *p;
1078-
uint32_t c;
1076+
const uint8_t *p, *p1;
1077+
uint32_t c, d;
10791078
char *q;
10801079

10811080
p = *pp;
@@ -1086,11 +1085,18 @@ static int re_parse_group_name(char *buf, int buf_size,
10861085
p++;
10871086
if (*p != 'u')
10881087
return -1;
1089-
c = lre_parse_escape(&p, is_utf16 * 2);
1088+
c = lre_parse_escape(&p, 2); // accept surrogate pairs
10901089
} else if (c == '>') {
10911090
break;
10921091
} else if (c >= 128) {
10931092
c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p);
1093+
if (c >= 0xD800 && c <= 0xDBFF) {
1094+
d = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p1);
1095+
if (d >= 0xDC00 && d <= 0xDFFF) {
1096+
c = 0x10000 + 0x400 * (c - 0xD800) + (d - 0xDC00);
1097+
p = p1;
1098+
}
1099+
}
10941100
} else {
10951101
p++;
10961102
}
@@ -1140,8 +1146,7 @@ static int re_parse_captures(REParseState *s, int *phas_named_captures,
11401146
/* potential named capture */
11411147
if (capture_name) {
11421148
p += 3;
1143-
if (re_parse_group_name(name, sizeof(name), &p,
1144-
s->is_utf16) == 0) {
1149+
if (re_parse_group_name(name, sizeof(name), &p) == 0) {
11451150
if (!strcmp(name, capture_name))
11461151
return capture_index;
11471152
}
@@ -1314,7 +1319,7 @@ static int re_parse_term(REParseState *s, BOOL is_backward_dir)
13141319
} else if (p[2] == '<') {
13151320
p += 3;
13161321
if (re_parse_group_name(s->u.tmp_buf, sizeof(s->u.tmp_buf),
1317-
&p, s->is_utf16)) {
1322+
&p)) {
13181323
return re_parse_error(s, "invalid group name");
13191324
}
13201325
if (find_group_name(s, s->u.tmp_buf) > 0) {
@@ -1378,7 +1383,7 @@ static int re_parse_term(REParseState *s, BOOL is_backward_dir)
13781383
}
13791384
p1 += 3;
13801385
if (re_parse_group_name(s->u.tmp_buf, sizeof(s->u.tmp_buf),
1381-
&p1, s->is_utf16)) {
1386+
&p1)) {
13821387
if (s->is_utf16 || re_has_named_captures(s))
13831388
return re_parse_error(s, "invalid group name");
13841389
else

0 commit comments

Comments
 (0)