Skip to content

Commit b75403a

Browse files
author
tianya
committed
更新到2020-11-08版本
1 parent afd4c54 commit b75403a

20 files changed

+1882
-1272
lines changed

Changelog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2020-11-08:
2+
3+
- improved function parameter initializers
4+
- added std.setenv(), std.unsetenv() and std.getenviron()
5+
- added JS_EvalThis()
6+
- misc bug fixes
7+
18
2020-09-06:
29

310
- added logical assignment operators

Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ CONFIG_BIGNUM=y
5353
OBJDIR=.obj
5454

5555
ifdef CONFIG_WIN32
56-
CROSS_PREFIX=i686-w64-mingw32-
56+
ifdef CONFIG_M32
57+
CROSS_PREFIX=i686-w64-mingw32-
58+
else
59+
CROSS_PREFIX=x86_64-w64-mingw32-
60+
endif
5761
EXE=.exe
5862
else
5963
CROSS_PREFIX=
@@ -281,15 +285,12 @@ $(OBJDIR)/%.check.o: %.c | $(OBJDIR)
281285
regexp_test: libregexp.c libunicode.c cutils.c
282286
$(CC) $(LDFLAGS) $(CFLAGS) -DTEST -o $@ libregexp.c libunicode.c cutils.c $(LIBS)
283287

284-
jscompress: jscompress.c
285-
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ jscompress.c
286-
287288
unicode_gen: $(OBJDIR)/unicode_gen.host.o $(OBJDIR)/cutils.host.o libunicode.c unicode_gen_def.h
288289
$(HOST_CC) $(LDFLAGS) $(CFLAGS) -o $@ $(OBJDIR)/unicode_gen.host.o $(OBJDIR)/cutils.host.o
289290

290291
clean:
291292
rm -f repl.c qjscalc.c out.c
292-
rm -f *.a *.o *.d *~ jscompress unicode_gen regexp_test $(PROGS)
293+
rm -f *.a *.o *.d *~ unicode_gen regexp_test $(PROGS)
293294
rm -f hello.c test_fib.c
294295
rm -f examples/*.so tests/*.so
295296
rm -rf $(OBJDIR)/ *.dSYM/ qjs-debug

TODO

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,48 @@
1-
Misc:
2-
- use realpath in module name normalizer and put it in quickjs-libc
3-
- use custom printf to avoid C library compatibility issues
4-
- rename CONFIG_ALL_UNICODE, CONFIG_BIGNUM, CONFIG_ATOMICS, CONFIG_CHECK_JSVALUE ?
1+
Bugs:
2+
- modules: better error handling with cyclic module references
3+
4+
Misc ideas:
5+
- use custom printf to avoid compatibility issues with floating point numbers
6+
- consistent naming for preprocessor defines
57
- unify coding style and naming conventions
68
- use names from the ECMA spec in library implementation
7-
- modules: if no ".", use a well known module loading path ?
8-
- use JSHoistedDef only for global variables (JSHoistedDef.var_name != JS_ATOM_NULL)
9-
- add index in JSVarDef and is_arg flag to merge args and vars in JSFunctionDef
10-
- replace most JSVarDef flags with var_type enumeration
119
- use byte code emitters with typed arguments (for clarity)
1210
- use 2 bytecode DynBufs in JSFunctionDef, one for reading, one for writing
1311
and use the same wrappers in all phases
1412
- use more generic method for line numbers in resolve_variables and resolve_labels
1513
- use custom timezone support to avoid C library compatibility issues
1614

1715
Memory:
16+
- use memory pools for objects, etc?
1817
- test border cases for max number of atoms, object properties, string length
1918
- add emergency malloc mode for out of memory exceptions.
2019
- test all DynBuf memory errors
2120
- test all js_realloc memory errors
22-
- bignum: handle memory errors
23-
- use memory pools for objects, etc?
2421
- improve JS_ComputeMemoryUsage() with more info
2522

26-
Optimizations:
23+
Built-in standard library:
24+
- BSD sockets
25+
- modules: use realpath in module name normalizer and put it in quickjs-libc
26+
- modules: if no ".", use a well known module loading path ?
27+
- get rid of __loadScript, use more common name
28+
29+
REPL:
30+
- debugger
31+
- readline: support MS Windows terminal
32+
- readline: handle dynamic terminal resizing
33+
- readline: handle double width unicode characters
34+
- multiline editing
35+
- runtime object and function inspectors
36+
- interactive object browser
37+
- use more generic approach to display evaluation results
38+
- improve directive handling: dispatch, colorize, completion...
39+
- save history
40+
- close all predefined methods in repl.js and jscalc.js
41+
42+
Optimization ideas:
2743
- 64-bit atoms in 64-bit mode ?
28-
- use auto-init properties for more global objects
44+
- 64-bit small bigint in 64-bit mode ?
2945
- reuse stack slots for disjoint scopes, if strip
30-
- optimize `for of` iterator for built-in array objects
3146
- add heuristic to avoid some cycles in closures
3247
- small String (0-2 charcodes) with immediate storage
3348
- perform static string concatenation at compile time
@@ -36,43 +51,20 @@ Optimizations:
3651
- optimize `s += a + b`, `s += a.b` and similar simple expressions
3752
- ensure string canonical representation and optimise comparisons and hashes?
3853
- remove JSObject.first_weak_ref, use bit+context based hashed array for weak references
39-
- optimize function storage with length and name accessors?
4054
- property access optimization on the global object, functions,
4155
prototypes and special non extensible objects.
4256
- create object literals with the correct length by backpatching length argument
4357
- remove redundant set_loc_uninitialized/check_uninitialized opcodes
4458
- peephole optim: push_atom_value, to_propkey -> push_atom_value
4559
- peephole optim: put_loc x, get_loc_check x -> set_loc x
46-
- comparative performance benchmark
47-
- use variable name when throwing uninitialized exception if available
4860
- convert slow array to fast array when all properties != length are numeric
4961
- optimize destructuring assignments for global and local variables
5062
- implement some form of tail-call-optimization
5163
- optimize OP_apply
5264
- optimize f(...b)
5365

54-
Extensions:
55-
- support more features in [features] section
56-
- add built-in preprocessor in compiler, get rid of jscompress
57-
handle #if, #ifdef, #line, limited support for #define
58-
- get rid of __loadScript, use more common name
59-
- BSD sockets
60-
61-
REPL:
62-
- debugger
63-
- readline: support MS Windows terminal
64-
- readline: handle dynamic terminal resizing
65-
- readline: handle double width unicode characters
66-
- multiline editing
67-
- runtime object and function inspectors
68-
- interactive object browser
69-
- use more generic approach to display evaluation results
70-
- improve directive handling: dispatch, colorize, completion...
71-
- save history
72-
- close all predefined methods in repl.js and jscalc.js
73-
7466
Test262o: 0/11262 errors, 463 excluded
7567
Test262o commit: 7da91bceb9ce7613f87db47ddd1292a2dda58b42 (es5-tests branch)
7668

77-
Test262: 30/71748 errors, 868 excluded, 474 skipped
78-
Test262 commit: 24c67328062383079ada85f4d253eb0526fd209b
69+
Result: 51/75119 errors, 899 excluded, 570 skipped
70+
Test262 commit: 1c33fdb0ca60fb9d7392403be769ed0d26209132

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2020-09-06
1+
2020-11-08

doc/quickjs.html

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/quickjs.pdf

168 Bytes
Binary file not shown.

doc/quickjs.texi

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,16 @@ useful in case of specific memory constraints or for testing.
452452
Return the value of the environment variable @code{name} or
453453
@code{undefined} if it is not defined.
454454

455+
@item setenv(name, value)
456+
Set the value of the environment variable @code{name} to the string
457+
@code{value}.
458+
459+
@item unsetenv(name)
460+
Delete the environment variable @code{name}.
461+
462+
@item getenviron()
463+
Return an object containing the environment variables as key-value pairs.
464+
455465
@item urlGet(url, options = undefined)
456466

457467
Download @code{url} using the @file{curl} command line
@@ -532,7 +542,7 @@ position @code{position} (wrapper to the libc @code{fread}).
532542

533543
@item write(buffer, position, length)
534544
Write @code{length} bytes to the file from the ArrayBuffer @code{buffer} at byte
535-
position @code{position} (wrapper to the libc @code{fread}).
545+
position @code{position} (wrapper to the libc @code{fwrite}).
536546

537547
@item getline()
538548
Return the next line from the file, assuming UTF-8 encoding, excluding

libbf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <stddef.h>
2828
#include <stdint.h>
2929

30-
#if defined(__x86_64__)
30+
#if INTPTR_MAX >= INT64_MAX
3131
#define LIMB_LOG2_BITS 6
3232
#else
3333
#define LIMB_LOG2_BITS 5

libregexp.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ typedef struct {
7575
int capture_count;
7676
int total_capture_count; /* -1 = not computed yet */
7777
int has_named_captures; /* -1 = don't know, 0 = no, 1 = yes */
78-
void *mem_opaque;
78+
void *opaque;
7979
DynBuf group_names;
8080
union {
8181
char error_msg[TMP_BUF_SIZE];
@@ -230,7 +230,7 @@ static int cr_init_char_range(REParseState *s, CharRange *cr, uint32_t c)
230230
invert = c & 1;
231231
c_pt = char_range_table[c >> 1];
232232
len = *c_pt++;
233-
cr_init(cr, s->mem_opaque, lre_realloc);
233+
cr_init(cr, s->opaque, lre_realloc);
234234
for(i = 0; i < len * 2; i++) {
235235
if (cr_add_point(cr, c_pt[i]))
236236
goto fail;
@@ -625,7 +625,7 @@ static int parse_unicode_property(REParseState *s, CharRange *cr,
625625
p++;
626626
q = name;
627627
while (is_unicode_char(*p)) {
628-
if ((q - name) > sizeof(name) - 1)
628+
if ((q - name) >= sizeof(name) - 1)
629629
goto unknown_property_name;
630630
*q++ = *p++;
631631
}
@@ -634,7 +634,7 @@ static int parse_unicode_property(REParseState *s, CharRange *cr,
634634
if (*p == '=') {
635635
p++;
636636
while (is_unicode_char(*p)) {
637-
if ((q - value) > sizeof(value) - 1)
637+
if ((q - value) >= sizeof(value) - 1)
638638
return re_parse_error(s, "unknown unicode property value");
639639
*q++ = *p++;
640640
}
@@ -651,7 +651,7 @@ static int parse_unicode_property(REParseState *s, CharRange *cr,
651651
} else if (!strcmp(name, "Script_Extensions") || !strcmp(name, "scx")) {
652652
script_ext = TRUE;
653653
do_script:
654-
cr_init(cr, s->mem_opaque, lre_realloc);
654+
cr_init(cr, s->opaque, lre_realloc);
655655
ret = unicode_script(cr, value, script_ext);
656656
if (ret) {
657657
cr_free(cr);
@@ -661,7 +661,7 @@ static int parse_unicode_property(REParseState *s, CharRange *cr,
661661
goto out_of_memory;
662662
}
663663
} else if (!strcmp(name, "General_Category") || !strcmp(name, "gc")) {
664-
cr_init(cr, s->mem_opaque, lre_realloc);
664+
cr_init(cr, s->opaque, lre_realloc);
665665
ret = unicode_general_category(cr, value);
666666
if (ret) {
667667
cr_free(cr);
@@ -671,7 +671,7 @@ static int parse_unicode_property(REParseState *s, CharRange *cr,
671671
goto out_of_memory;
672672
}
673673
} else if (value[0] == '\0') {
674-
cr_init(cr, s->mem_opaque, lre_realloc);
674+
cr_init(cr, s->opaque, lre_realloc);
675675
ret = unicode_general_category(cr, name);
676676
if (ret == -1) {
677677
cr_free(cr);
@@ -864,7 +864,7 @@ static int re_parse_char_class(REParseState *s, const uint8_t **pp)
864864
CharRange cr1_s, *cr1 = &cr1_s;
865865
BOOL invert;
866866

867-
cr_init(cr, s->mem_opaque, lre_realloc);
867+
cr_init(cr, s->opaque, lre_realloc);
868868
p = *pp;
869869
p++; /* skip '[' */
870870
invert = FALSE;
@@ -1147,9 +1147,13 @@ static int re_parse_captures(REParseState *s, int *phas_named_captures,
11471147
}
11481148
}
11491149
capture_index++;
1150+
if (capture_index >= CAPTURE_COUNT_MAX)
1151+
goto done;
11501152
}
11511153
} else {
11521154
capture_index++;
1155+
if (capture_index >= CAPTURE_COUNT_MAX)
1156+
goto done;
11531157
}
11541158
break;
11551159
case '\\':
@@ -1163,6 +1167,7 @@ static int re_parse_captures(REParseState *s, int *phas_named_captures,
11631167
break;
11641168
}
11651169
}
1170+
done:
11661171
if (capture_name)
11671172
return -1;
11681173
else
@@ -1734,6 +1739,9 @@ static int re_parse_disjunction(REParseState *s, BOOL is_backward_dir)
17341739
{
17351740
int start, len, pos;
17361741

1742+
if (lre_check_stack_overflow(s->opaque, 0))
1743+
return re_parse_error(s, "stack overflow");
1744+
17371745
start = s->byte_code.size;
17381746
if (re_parse_alternative(s, is_backward_dir))
17391747
return -1;
@@ -1819,7 +1827,7 @@ uint8_t *lre_compile(int *plen, char *error_msg, int error_msg_size,
18191827
BOOL is_sticky;
18201828

18211829
memset(s, 0, sizeof(*s));
1822-
s->mem_opaque = opaque;
1830+
s->opaque = opaque;
18231831
s->buf_ptr = (const uint8_t *)buf;
18241832
s->buf_end = s->buf_ptr + buf_len;
18251833
s->buf_start = s->buf_ptr;

qjscalc.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,6 +2625,17 @@ function atanh(a)
26252625
return 0.5 * log((1 + x) / (1 - x));
26262626
}
26272627

2628+
function sigmoid(x)
2629+
{
2630+
x = Float(x);
2631+
return 1 / (1 + exp(-x));
2632+
}
2633+
2634+
function lerp(a, b, t)
2635+
{
2636+
return a + (b - a) * t;
2637+
}
2638+
26282639
var idn = Matrix.idn;
26292640
var diag = Matrix.diag;
26302641
var trans = Matrix.trans;

0 commit comments

Comments
 (0)