rapydscript-ng 0.7.23 → 0.8.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.
- package/CHANGELOG.md +24 -0
- package/README.md +72 -26
- package/bin/package.json +1 -0
- package/bin/rapydscript +65 -62
- package/editor-plugins/nvim/rapydscript/README.md +184 -0
- package/editor-plugins/nvim/rapydscript/bin/rapydscript.so +0 -0
- package/editor-plugins/nvim/rapydscript/ftdetect/rapydscript.lua +10 -0
- package/editor-plugins/nvim/rapydscript/lua/rapydscript/health.lua +88 -0
- package/editor-plugins/nvim/rapydscript/lua/rapydscript/init.lua +279 -0
- package/local-agent.md +28 -0
- package/package.json +4 -5
- package/release/baselib-plain-pretty.js +448 -326
- package/release/baselib-plain-ugly.js +3 -3
- package/release/compiler.js +2528 -1672
- package/release/signatures.json +17 -17
- package/src/ast.pyj +73 -25
- package/src/baselib-builtins.pyj +2 -2
- package/src/baselib-containers.pyj +153 -151
- package/src/baselib-internal.pyj +3 -3
- package/src/baselib-str.pyj +5 -5
- package/src/lib/aes.pyj +1 -1
- package/src/lib/encodings.pyj +1 -1
- package/src/lib/pythonize.pyj +1 -1
- package/src/lib/re.pyj +2 -2
- package/src/lib/traceback.pyj +165 -28
- package/src/lib/uuid.pyj +1 -1
- package/src/output/codegen.pyj +10 -3
- package/src/output/functions.pyj +31 -40
- package/src/output/literals.pyj +11 -14
- package/src/output/loops.pyj +25 -87
- package/src/output/modules.pyj +5 -47
- package/src/output/statements.pyj +1 -1
- package/src/output/stream.pyj +58 -31
- package/src/parse.pyj +777 -427
- package/src/tokenizer.pyj +16 -4
- package/src/utils.pyj +1 -1
- package/test/_treeshake_mod.pyj +30 -0
- package/test/_treeshake_side_effect.pyj +9 -0
- package/test/ast_serialization.pyj +392 -0
- package/test/async.pyj +95 -0
- package/test/baselib.pyj +1 -2
- package/test/embedded_compiler.pyj +57 -0
- package/test/fmt.pyj +201 -0
- package/test/generic.pyj +7 -3
- package/test/imports.pyj +8 -6
- package/test/internationalization.pyj +38 -37
- package/test/lint.pyj +120 -115
- package/test/lsp.pyj +222 -0
- package/test/repl.pyj +70 -65
- package/test/sourcemaps.pyj +315 -0
- package/test/starargs.pyj +46 -39
- package/test/traceback.pyj +263 -0
- package/test/treeshaking.pyj +181 -0
- package/test/web_repl_export.pyj +88 -0
- package/tools/ast_serialize.mjs +557 -0
- package/tools/cli.mjs +510 -0
- package/tools/compile.mjs +201 -0
- package/tools/compiler.mjs +127 -0
- package/tools/{completer.js → completer.mjs} +6 -6
- package/tools/{embedded_compiler.js → embedded_compiler.mjs} +17 -13
- package/tools/export.js +109 -56
- package/tools/fmt.mjs +735 -0
- package/tools/{gettext.js → gettext.mjs} +46 -53
- package/tools/{ini.js → ini.mjs} +9 -10
- package/tools/{lint.js → lint.mjs} +107 -56
- package/tools/lsp.mjs +914 -0
- package/tools/lsp_protocol.mjs +259 -0
- package/tools/lsp_symbols.mjs +418 -0
- package/tools/{msgfmt.js → msgfmt.mjs} +18 -18
- package/tools/{repl.js → repl.mjs} +52 -41
- package/tools/{self.js → self.mjs} +56 -46
- package/tools/sourcemap.mjs +123 -0
- package/tools/test.mjs +152 -0
- package/tools/treeshake.mjs +400 -0
- package/tools/{utils.js → utils.mjs} +26 -23
- package/tools/{web_repl.js → web_repl.mjs} +15 -13
- package/tools/web_repl_export.mjs +93 -0
- package/tree-sitter/README.md +101 -0
- package/tree-sitter/grammar.js +992 -0
- package/tree-sitter/package.json +43 -0
- package/tree-sitter/queries/rapydscript/highlights.scm +232 -0
- package/tree-sitter/queries/rapydscript/indents.scm +64 -0
- package/tree-sitter/queries/rapydscript/injections.scm +14 -0
- package/tree-sitter/queries/rapydscript/locals.scm +108 -0
- package/tree-sitter/src/grammar.json +4976 -0
- package/tree-sitter/src/node-types.json +2901 -0
- package/tree-sitter/src/parser.c +196465 -0
- package/tree-sitter/src/scanner.c +294 -0
- package/tree-sitter/src/tree_sitter/alloc.h +54 -0
- package/tree-sitter/src/tree_sitter/array.h +330 -0
- package/tree-sitter/src/tree_sitter/parser.h +286 -0
- package/tree-sitter/test/corpus/chaining.txt +99 -0
- package/tree-sitter/test/corpus/classes.txt +147 -0
- package/tree-sitter/test/corpus/comprehensions.txt +155 -0
- package/tree-sitter/test/corpus/containers.txt +242 -0
- package/tree-sitter/test/corpus/control_flow.txt +361 -0
- package/tree-sitter/test/corpus/decorators.txt +64 -0
- package/tree-sitter/test/corpus/existential.txt +102 -0
- package/tree-sitter/test/corpus/functions.txt +293 -0
- package/tree-sitter/test/corpus/imports.txt +117 -0
- package/tree-sitter/test/corpus/literals.txt +135 -0
- package/tree-sitter/test/corpus/operators.txt +296 -0
- package/tree-sitter/test/corpus/statements.txt +189 -0
- package/tree-sitter/test/corpus/strings.txt +90 -0
- package/tree-sitter/test/corpus/subscripts.txt +227 -0
- package/tree-sitter/tree-sitter.json +36 -0
- package/web-repl/env.js +35 -23
- package/web-repl/main.js +8 -8
- package/bin/export +0 -75
- package/bin/web-repl-export +0 -102
- package/tools/cli.js +0 -523
- package/tools/compile.js +0 -184
- package/tools/compiler.js +0 -84
- package/tools/test.js +0 -110
package/release/signatures.json
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
{
|
|
2
|
-
"ast": "
|
|
3
|
-
"baselib-builtins": "
|
|
4
|
-
"baselib-containers": "
|
|
2
|
+
"ast": "c5334def1141b1d2413414a0cd0be2863c62f866",
|
|
3
|
+
"baselib-builtins": "ef695c18f15e3687b1bf6e230e14292f1ce541d5",
|
|
4
|
+
"baselib-containers": "0a8c43f79565f121a0cb3b54a1ddd50ed9e5de33",
|
|
5
5
|
"baselib-errors": "f2423e1e2489bdd7fb8c8725bb76436898c8008c",
|
|
6
|
-
"baselib-internal": "
|
|
6
|
+
"baselib-internal": "c6aa6170978905a12c79908be5268dd187a42662",
|
|
7
7
|
"baselib-itertools": "ab1f3257642c8d26fab1ff9d392814a459a60cdb",
|
|
8
|
-
"baselib-str": "
|
|
8
|
+
"baselib-str": "d4db45dc7f65715cf4fecedd54de337949946054",
|
|
9
9
|
"compiler": "cfbfceb0439fed3302f78d80b303dca713b25e7b",
|
|
10
10
|
"errors": "d1b33848d19b141e19cc079cf78421f29b6d2c05",
|
|
11
11
|
"output/__init__": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
|
|
12
12
|
"output/classes": "d05c1992cc91b337a4e4ff137b0aa3d626e6624b",
|
|
13
|
-
"output/codegen": "
|
|
13
|
+
"output/codegen": "75956ff394f24681b8b867769fe27e53aea5df41",
|
|
14
14
|
"output/comments": "78ec38d8b34da96c078653e2d0d4049d7003906b",
|
|
15
15
|
"output/exceptions": "c7d90155694c7108e94d0940a160ae83725421d7",
|
|
16
|
-
"output/functions": "
|
|
17
|
-
"output/literals": "
|
|
18
|
-
"output/loops": "
|
|
19
|
-
"output/modules": "
|
|
16
|
+
"output/functions": "d93f8d01a1387aaffbf2888c7a885afa5da15a31",
|
|
17
|
+
"output/literals": "ed4f371f4f0eb7f4f5fd0d13d6bd08a23d278177",
|
|
18
|
+
"output/loops": "de20a38274dfa2d813e195d5d23928896fce6838",
|
|
19
|
+
"output/modules": "d73313473fff4951a0f8061e31f3aa6fe63439cd",
|
|
20
20
|
"output/operators": "bcda6aeab9214523252481c8dba2741c01f725bb",
|
|
21
|
-
"output/statements": "
|
|
22
|
-
"output/stream": "
|
|
21
|
+
"output/statements": "be05be9514cbea692c96206fb3d13de8d3922eed",
|
|
22
|
+
"output/stream": "85ac5b38683fa5c9c4015fed005a4e5e40bbe6f9",
|
|
23
23
|
"output/utils": "595968f96f6fdcc51eb41c34d64c92bb595e3cb1",
|
|
24
|
-
"parse": "
|
|
24
|
+
"parse": "ffa7eae73a20ca1499c3641bf7cdeeea2915e1d9",
|
|
25
25
|
"string_interpolation": "bff1cc76d772d24d35707f6c794f38734ca08376",
|
|
26
|
-
"tokenizer": "
|
|
26
|
+
"tokenizer": "589147f8768c8d4ef1fc75aebfbfd592a65259d0",
|
|
27
27
|
"unicode_aliases": "79ac6eaa5e6be44a5397d62c561f854a8fe7528e",
|
|
28
|
-
"utils": "
|
|
29
|
-
"#compiler#": "
|
|
30
|
-
"#compiled_with#": "
|
|
28
|
+
"utils": "7cf5ce8d9d3ee38b8741146e13fe6ca3413d907f",
|
|
29
|
+
"#compiler#": "d66b26de4d92a7add9187f36923e9864cbde4516",
|
|
30
|
+
"#compiled_with#": "d66b26de4d92a7add9187f36923e9864cbde4516"
|
|
31
31
|
}
|
package/src/ast.pyj
CHANGED
|
@@ -373,13 +373,35 @@ class AST_Decorator(AST_Node):
|
|
|
373
373
|
self.expression.walk(visitor)
|
|
374
374
|
)
|
|
375
375
|
|
|
376
|
+
class AST_ArgsDef(AST_Node):
|
|
377
|
+
"The formal argument definition list for a function"
|
|
378
|
+
properties = {
|
|
379
|
+
'args': "[AST_SymbolFunarg*] formal positional parameters",
|
|
380
|
+
'starargs': "[AST_SymbolFunarg?] *args parameter, or None",
|
|
381
|
+
'kwargs': "[AST_SymbolFunarg?] **kwargs parameter, or None",
|
|
382
|
+
'defaults': "[Object] map of parameter name to default value expression",
|
|
383
|
+
'has_defaults': "[bool] True if any parameter has a default value",
|
|
384
|
+
'is_simple_func': "[bool] True if no starargs, no kwargs, and no defaults",
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
def _walk(self, visitor):
|
|
388
|
+
return visitor._visit(self, def():
|
|
389
|
+
for arg in self.args:
|
|
390
|
+
arg._walk(visitor)
|
|
391
|
+
if self.starargs:
|
|
392
|
+
self.starargs._walk(visitor)
|
|
393
|
+
if self.kwargs:
|
|
394
|
+
self.kwargs._walk(visitor)
|
|
395
|
+
)
|
|
396
|
+
|
|
376
397
|
class AST_Lambda(AST_Scope):
|
|
377
398
|
"Base class for functions"
|
|
378
399
|
properties = {
|
|
379
400
|
'name': "[AST_SymbolDeclaration?] the name of this function",
|
|
380
|
-
'argnames': "[
|
|
401
|
+
'argnames': "[AST_ArgsDef] the function argument definitions",
|
|
381
402
|
'decorators': "[AST_Decorator*] function decorators, if any",
|
|
382
403
|
'is_generator': "[bool*] True iff this function is a generator",
|
|
404
|
+
'is_async': "[bool*] True iff this function is an async function",
|
|
383
405
|
'is_expression': "[bool*] True iff this function is a function expression",
|
|
384
406
|
'is_anonymous': "[bool*] True iff this function is an anonymous function",
|
|
385
407
|
"return_annotation": "[AST_Node?] The return type annotation provided (if any)",
|
|
@@ -392,13 +414,7 @@ class AST_Lambda(AST_Scope):
|
|
|
392
414
|
d.walk(visitor)
|
|
393
415
|
if self.name:
|
|
394
416
|
self.name._walk(visitor)
|
|
395
|
-
|
|
396
|
-
for arg in self.argnames:
|
|
397
|
-
arg._walk(visitor)
|
|
398
|
-
if self.argnames.starargs:
|
|
399
|
-
self.argnames.starargs._walk(visitor)
|
|
400
|
-
if self.argnames.kwargs:
|
|
401
|
-
self.argnames.kwargs._walk(visitor)
|
|
417
|
+
self.argnames._walk(visitor)
|
|
402
418
|
walk_body(self, visitor)
|
|
403
419
|
)
|
|
404
420
|
|
|
@@ -468,6 +484,18 @@ class AST_Yield(AST_Return):
|
|
|
468
484
|
'is_yield_from': "[bool] True iff this is a yield from, False otherwise"
|
|
469
485
|
}
|
|
470
486
|
|
|
487
|
+
class AST_Await(AST_Node):
|
|
488
|
+
"An await expression"
|
|
489
|
+
properties = {
|
|
490
|
+
'value': "[AST_Node] the expression being awaited"
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
def _walk(self, visitor):
|
|
494
|
+
return visitor._visit(self, def():
|
|
495
|
+
if self.value:
|
|
496
|
+
self.value._walk(visitor)
|
|
497
|
+
)
|
|
498
|
+
|
|
471
499
|
class AST_Throw(AST_Exit):
|
|
472
500
|
"A `throw` statement"
|
|
473
501
|
|
|
@@ -581,10 +609,44 @@ class AST_VarDef(AST_Node):
|
|
|
581
609
|
|
|
582
610
|
# Miscellaneous {{{
|
|
583
611
|
|
|
612
|
+
class AST_CallArg(AST_Node):
|
|
613
|
+
"A single positional argument in a function call"
|
|
614
|
+
properties = {
|
|
615
|
+
'value': "[AST_Node] the argument expression",
|
|
616
|
+
'is_array': "[bool] True if this is a *arg (already an array/iterable)",
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
def _walk(self, visitor):
|
|
620
|
+
return visitor._visit(self, def():
|
|
621
|
+
self.value._walk(visitor)
|
|
622
|
+
)
|
|
623
|
+
|
|
624
|
+
class AST_CallArgs(AST_Node):
|
|
625
|
+
"The argument list for a function call"
|
|
626
|
+
properties = {
|
|
627
|
+
'args': "[AST_CallArg*] positional arguments",
|
|
628
|
+
'kwargs': "[pair*] keyword argument pairs [key_node, value_node]",
|
|
629
|
+
'kwarg_items': "[AST_SymbolRef*] **kwargs symbol references",
|
|
630
|
+
'starargs': "[bool] True if *args were used in this call",
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
def _walk(self, visitor):
|
|
634
|
+
return visitor._visit(self, def():
|
|
635
|
+
for arg in self.args:
|
|
636
|
+
arg._walk(visitor)
|
|
637
|
+
if self.kwargs:
|
|
638
|
+
for pair in self.kwargs:
|
|
639
|
+
pair[0]._walk(visitor)
|
|
640
|
+
pair[1]._walk(visitor)
|
|
641
|
+
if self.kwarg_items:
|
|
642
|
+
for arg in self.kwarg_items:
|
|
643
|
+
arg._walk(visitor)
|
|
644
|
+
)
|
|
645
|
+
|
|
584
646
|
class AST_BaseCall(AST_Node):
|
|
585
647
|
"A base class for function calls"
|
|
586
648
|
properties = {
|
|
587
|
-
'args': "[
|
|
649
|
+
'args': "[AST_CallArgs] the function call argument list"
|
|
588
650
|
}
|
|
589
651
|
|
|
590
652
|
class AST_Call(AST_BaseCall):
|
|
@@ -596,15 +658,7 @@ class AST_Call(AST_BaseCall):
|
|
|
596
658
|
def _walk(self, visitor):
|
|
597
659
|
return visitor._visit(self, def():
|
|
598
660
|
self.expression._walk(visitor)
|
|
599
|
-
|
|
600
|
-
arg._walk(visitor)
|
|
601
|
-
if self.args.kwargs:
|
|
602
|
-
for arg in self.args.kwargs:
|
|
603
|
-
arg[0]._walk(visitor)
|
|
604
|
-
arg[1]._walk(visitor)
|
|
605
|
-
if self.args.kwarg_items:
|
|
606
|
-
for arg in self.args.kwarg_items:
|
|
607
|
-
arg._walk(visitor)
|
|
661
|
+
self.args._walk(visitor)
|
|
608
662
|
)
|
|
609
663
|
|
|
610
664
|
|
|
@@ -619,13 +673,7 @@ class AST_ClassCall(AST_BaseCall):
|
|
|
619
673
|
def _walk(self, visitor):
|
|
620
674
|
return visitor._visit(self, def():
|
|
621
675
|
if (self.expression) self.expression._walk(visitor)
|
|
622
|
-
|
|
623
|
-
arg._walk(visitor)
|
|
624
|
-
for arg in self.args.kwargs:
|
|
625
|
-
arg[0]._walk(visitor)
|
|
626
|
-
arg[1]._walk(visitor)
|
|
627
|
-
for arg in self.args.kwarg_items:
|
|
628
|
-
arg._walk(visitor)
|
|
676
|
+
self.args._walk(visitor)
|
|
629
677
|
)
|
|
630
678
|
|
|
631
679
|
class AST_New(AST_Call):
|
package/src/baselib-builtins.pyj
CHANGED
|
@@ -10,8 +10,8 @@ def ρσ_bool(val):
|
|
|
10
10
|
def ρσ_print():
|
|
11
11
|
if v'typeof console' is 'object':
|
|
12
12
|
parts = v'[]'
|
|
13
|
-
for v'var i = 0; i < arguments.length; i++':
|
|
14
|
-
parts.push(ρσ_str(arguments[i])) # noqa: undef
|
|
13
|
+
for v'var i = 0; i < arguments.length; i++': # noqa
|
|
14
|
+
parts.push(ρσ_str(v'arguments[i]')) # noqa: undef
|
|
15
15
|
console.log(parts.join(' '))
|
|
16
16
|
|
|
17
17
|
def ρσ_int(val, base):
|
|
@@ -46,112 +46,6 @@ v'var equals = ρσ_equals'
|
|
|
46
46
|
|
|
47
47
|
# list {{{
|
|
48
48
|
|
|
49
|
-
def ρσ_list_extend(iterable):
|
|
50
|
-
if Array.isArray(iterable) or jstype(iterable) is 'string':
|
|
51
|
-
# Allocate all new memory in one operation
|
|
52
|
-
start = this.length
|
|
53
|
-
this.length += iterable.length
|
|
54
|
-
for v'var i = 0; i < iterable.length; i++':
|
|
55
|
-
this[start + i] = iterable[i] # noqa:undef
|
|
56
|
-
else:
|
|
57
|
-
iterator = iterable.keys() if jstype(Map) is 'function' and v'iterable instanceof Map' else iterable[ρσ_iterator_symbol]()
|
|
58
|
-
result = iterator.next()
|
|
59
|
-
while not result.done:
|
|
60
|
-
this.push(result.value)
|
|
61
|
-
result = iterator.next()
|
|
62
|
-
|
|
63
|
-
def ρσ_list_index(val, start, stop):
|
|
64
|
-
start = start or 0
|
|
65
|
-
if start < 0:
|
|
66
|
-
start = this.length + start
|
|
67
|
-
if start < 0:
|
|
68
|
-
raise ValueError(val + ' is not in list')
|
|
69
|
-
if stop is undefined:
|
|
70
|
-
stop = this.length
|
|
71
|
-
if stop < 0:
|
|
72
|
-
stop = this.length + stop
|
|
73
|
-
for v'var i = start; i < stop; i++':
|
|
74
|
-
if this[i] == val:
|
|
75
|
-
return i # noqa:undef
|
|
76
|
-
raise ValueError(val + ' is not in list')
|
|
77
|
-
|
|
78
|
-
def ρσ_list_pop(index):
|
|
79
|
-
if this.length is 0:
|
|
80
|
-
raise IndexError('list is empty')
|
|
81
|
-
if index is undefined:
|
|
82
|
-
index = -1
|
|
83
|
-
ans = this.splice(index, 1)
|
|
84
|
-
if not ans.length:
|
|
85
|
-
raise IndexError('pop index out of range')
|
|
86
|
-
return ans[0]
|
|
87
|
-
|
|
88
|
-
def ρσ_list_remove(value):
|
|
89
|
-
for v'var i = 0; i < this.length; i++':
|
|
90
|
-
if this[i] == value:
|
|
91
|
-
this.splice(i, 1)
|
|
92
|
-
return
|
|
93
|
-
raise ValueError(value + ' not in list')
|
|
94
|
-
|
|
95
|
-
def ρσ_list_to_string():
|
|
96
|
-
return '[' + this.join(', ') + ']'
|
|
97
|
-
|
|
98
|
-
def ρσ_list_insert(index, val):
|
|
99
|
-
if index < 0:
|
|
100
|
-
index += this.length
|
|
101
|
-
index = min(this.length, max(index, 0))
|
|
102
|
-
if index is 0:
|
|
103
|
-
this.unshift(val)
|
|
104
|
-
return
|
|
105
|
-
for v'var i = this.length; i > index; i--':
|
|
106
|
-
this[i] = this[i - 1] # noqa:undef
|
|
107
|
-
this[index] = val
|
|
108
|
-
|
|
109
|
-
def ρσ_list_copy():
|
|
110
|
-
return ρσ_list_constructor(this)
|
|
111
|
-
|
|
112
|
-
def ρσ_list_clear():
|
|
113
|
-
this.length = 0
|
|
114
|
-
|
|
115
|
-
def ρσ_list_as_array():
|
|
116
|
-
return Array.prototype.slice.call(this)
|
|
117
|
-
|
|
118
|
-
def ρσ_list_count(value):
|
|
119
|
-
return this.reduce(def(n, val): return n + (val is value);, 0)
|
|
120
|
-
|
|
121
|
-
def ρσ_list_sort_key(value):
|
|
122
|
-
t = jstype(value)
|
|
123
|
-
if t is 'string' or t is 'number':
|
|
124
|
-
return value
|
|
125
|
-
return value.toString()
|
|
126
|
-
|
|
127
|
-
def ρσ_list_sort_cmp(a, b, ap, bp):
|
|
128
|
-
if a < b:
|
|
129
|
-
return -1
|
|
130
|
-
if a > b:
|
|
131
|
-
return 1
|
|
132
|
-
return ap - bp
|
|
133
|
-
|
|
134
|
-
def ρσ_list_sort(key=None, reverse=False):
|
|
135
|
-
key = key or ρσ_list_sort_key
|
|
136
|
-
mult = -1 if reverse else 1
|
|
137
|
-
keymap = dict()
|
|
138
|
-
posmap = dict()
|
|
139
|
-
for v'var i=0; i < this.length; i++':
|
|
140
|
-
k = this[i] # noqa:undef
|
|
141
|
-
keymap.set(k, key(k))
|
|
142
|
-
posmap.set(k, i)
|
|
143
|
-
this.sort(def (a, b): return mult * ρσ_list_sort_cmp(keymap.get(a), keymap.get(b), posmap.get(a), posmap.get(b));)
|
|
144
|
-
|
|
145
|
-
def ρσ_list_concat(): # ensure concat() returns an object of type list
|
|
146
|
-
ans = Array.prototype.concat.apply(this, arguments)
|
|
147
|
-
ρσ_list_decorate(ans)
|
|
148
|
-
return ans
|
|
149
|
-
|
|
150
|
-
def ρσ_list_slice(): # ensure slice() returns an object of type list
|
|
151
|
-
ans = Array.prototype.slice.apply(this, arguments)
|
|
152
|
-
ρσ_list_decorate(ans)
|
|
153
|
-
return ans
|
|
154
|
-
|
|
155
49
|
def ρσ_list_iterator(value):
|
|
156
50
|
self = this
|
|
157
51
|
return {
|
|
@@ -165,50 +59,6 @@ def ρσ_list_iterator(value):
|
|
|
165
59
|
,
|
|
166
60
|
}
|
|
167
61
|
|
|
168
|
-
def ρσ_list_len():
|
|
169
|
-
return this.length
|
|
170
|
-
|
|
171
|
-
def ρσ_list_contains(val):
|
|
172
|
-
for v'var i = 0; i < this.length; i++':
|
|
173
|
-
if this[i] == val:
|
|
174
|
-
return True
|
|
175
|
-
return False
|
|
176
|
-
|
|
177
|
-
def ρσ_list_eq(other):
|
|
178
|
-
if not ρσ_arraylike(other):
|
|
179
|
-
return False
|
|
180
|
-
if this.length != other.length:
|
|
181
|
-
return False
|
|
182
|
-
for v'var i = 0; i < this.length; i++':
|
|
183
|
-
if not (this[i] == other[i]):
|
|
184
|
-
return False
|
|
185
|
-
return True
|
|
186
|
-
|
|
187
|
-
def ρσ_list_decorate(ans):
|
|
188
|
-
ans.append = Array.prototype.push
|
|
189
|
-
ans.toString = ρσ_list_to_string
|
|
190
|
-
ans.inspect = ρσ_list_to_string
|
|
191
|
-
ans.extend = ρσ_list_extend
|
|
192
|
-
ans.index = ρσ_list_index
|
|
193
|
-
ans.pypop = ρσ_list_pop
|
|
194
|
-
ans.remove = ρσ_list_remove
|
|
195
|
-
ans.insert = ρσ_list_insert
|
|
196
|
-
ans.copy = ρσ_list_copy
|
|
197
|
-
ans.clear = ρσ_list_clear
|
|
198
|
-
ans.count = ρσ_list_count
|
|
199
|
-
ans.concat = ρσ_list_concat
|
|
200
|
-
ans.pysort = ρσ_list_sort
|
|
201
|
-
ans.slice = ρσ_list_slice
|
|
202
|
-
ans.as_array = ρσ_list_as_array
|
|
203
|
-
ans.__len__ = ρσ_list_len
|
|
204
|
-
ans.__contains__ = ρσ_list_contains
|
|
205
|
-
ans.__eq__ = ρσ_list_eq
|
|
206
|
-
ans.constructor = ρσ_list_constructor
|
|
207
|
-
if jstype(ans[ρσ_iterator_symbol]) is not 'function':
|
|
208
|
-
# Happens on ES 5 runtimes
|
|
209
|
-
ans[ρσ_iterator_symbol] = ρσ_list_iterator
|
|
210
|
-
return ans
|
|
211
|
-
|
|
212
62
|
def ρσ_list_constructor(iterable):
|
|
213
63
|
if iterable is undefined:
|
|
214
64
|
ans = v'[]'
|
|
@@ -228,9 +78,161 @@ def ρσ_list_constructor(iterable):
|
|
|
228
78
|
ans = new Array(iterable)
|
|
229
79
|
else:
|
|
230
80
|
ans = Object.keys(iterable)
|
|
231
|
-
return
|
|
81
|
+
return ans
|
|
232
82
|
ρσ_list_constructor.__name__ = 'list'
|
|
233
83
|
|
|
84
|
+
if v'typeof Array.prototype.append' is not 'function':
|
|
85
|
+
Object.defineProperty(Array.prototype, 'append', {
|
|
86
|
+
'writable': False, 'configurable': False, 'enumerable': False,
|
|
87
|
+
'value': Array.prototype.push,
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(Array.prototype, 'extend', {
|
|
90
|
+
'writable': False, 'configurable': False, 'enumerable': False,
|
|
91
|
+
'value': def(iterable):
|
|
92
|
+
if Array.isArray(iterable) or jstype(iterable) is 'string':
|
|
93
|
+
# Allocate all new memory in one operation
|
|
94
|
+
start = this.length
|
|
95
|
+
this.length += iterable.length
|
|
96
|
+
for v'var i = 0; i < iterable.length; i++':
|
|
97
|
+
this[start + i] = iterable[i] # noqa:undef
|
|
98
|
+
else:
|
|
99
|
+
iterator = iterable.keys() if jstype(Map) is 'function' and v'iterable instanceof Map' else iterable[ρσ_iterator_symbol]()
|
|
100
|
+
result = iterator.next()
|
|
101
|
+
while not result.done:
|
|
102
|
+
this.push(result.value)
|
|
103
|
+
result = iterator.next()
|
|
104
|
+
});
|
|
105
|
+
Object.defineProperty(Array.prototype, 'index', {
|
|
106
|
+
'writable': False, 'configurable': False, 'enumerable': False,
|
|
107
|
+
'value': def(val, start, stop):
|
|
108
|
+
start = start or 0
|
|
109
|
+
if start < 0:
|
|
110
|
+
start = this.length + start
|
|
111
|
+
if start < 0:
|
|
112
|
+
raise ValueError(val + ' is not in list')
|
|
113
|
+
if stop is undefined:
|
|
114
|
+
stop = this.length
|
|
115
|
+
if stop < 0:
|
|
116
|
+
stop = this.length + stop
|
|
117
|
+
for v'var i = start; i < stop; i++':
|
|
118
|
+
if this[i] == val:
|
|
119
|
+
return i # noqa:undef
|
|
120
|
+
raise ValueError(val + ' is not in list')
|
|
121
|
+
});
|
|
122
|
+
Object.defineProperty(Array.prototype, 'pypop', {
|
|
123
|
+
'writable': False, 'configurable': False, 'enumerable': False,
|
|
124
|
+
'value': def(index):
|
|
125
|
+
if this.length is 0:
|
|
126
|
+
raise IndexError('list is empty')
|
|
127
|
+
if index is undefined:
|
|
128
|
+
index = -1
|
|
129
|
+
ans = this.splice(index, 1)
|
|
130
|
+
if not ans.length:
|
|
131
|
+
raise IndexError('pop index out of range')
|
|
132
|
+
return ans[0]
|
|
133
|
+
});
|
|
134
|
+
Object.defineProperty(Array.prototype, 'remove', {
|
|
135
|
+
'writable': False, 'configurable': False, 'enumerable': False,
|
|
136
|
+
'value': def(value):
|
|
137
|
+
for v'var i = 0; i < this.length; i++':
|
|
138
|
+
if this[i] == value:
|
|
139
|
+
this.splice(i, 1)
|
|
140
|
+
return
|
|
141
|
+
raise ValueError(value + ' not in list')
|
|
142
|
+
});
|
|
143
|
+
Object.defineProperty(Array.prototype, 'toString', {
|
|
144
|
+
'writable': False, 'configurable': False, 'enumerable': False,
|
|
145
|
+
'value': def(): return '[' + this.join(', ') + ']'
|
|
146
|
+
});
|
|
147
|
+
Object.defineProperty(Array.prototype, 'inspect', {
|
|
148
|
+
'writable': False, 'configurable': False, 'enumerable': False,
|
|
149
|
+
'value': def(): return '[' + this.join(', ') + ']'
|
|
150
|
+
});
|
|
151
|
+
Object.defineProperty(Array.prototype, 'insert', {
|
|
152
|
+
'writable': False, 'configurable': False, 'enumerable': False,
|
|
153
|
+
'value': def(index, val):
|
|
154
|
+
if index < 0:
|
|
155
|
+
index += this.length
|
|
156
|
+
index = min(this.length, max(index, 0))
|
|
157
|
+
if index is 0:
|
|
158
|
+
this.unshift(val)
|
|
159
|
+
return
|
|
160
|
+
for v'var i = this.length; i > index; i--':
|
|
161
|
+
this[i] = this[i - 1] # noqa:undef
|
|
162
|
+
this[index] = val
|
|
163
|
+
});
|
|
164
|
+
Object.defineProperty(Array.prototype, 'copy', {
|
|
165
|
+
'writable': False, 'configurable': False, 'enumerable': False,
|
|
166
|
+
'value': def(): return ρσ_list_constructor(this)
|
|
167
|
+
});
|
|
168
|
+
Object.defineProperty(Array.prototype, 'clear', {
|
|
169
|
+
'writable': False, 'configurable': False, 'enumerable': False,
|
|
170
|
+
'value': def(): this.length = 0
|
|
171
|
+
});
|
|
172
|
+
Object.defineProperty(Array.prototype, 'count', {
|
|
173
|
+
'writable': False, 'configurable': False, 'enumerable': False,
|
|
174
|
+
'value': def(value): return this.reduce(def(n, val): return n + (val is value);, 0)
|
|
175
|
+
});
|
|
176
|
+
Object.defineProperty(Array.prototype, 'pysort', {
|
|
177
|
+
'writable': False, 'configurable': False, 'enumerable': False,
|
|
178
|
+
'value': def(key=None, reverse=False):
|
|
179
|
+
def _sort_key(value):
|
|
180
|
+
t = jstype(value)
|
|
181
|
+
if t is 'string' or t is 'number':
|
|
182
|
+
return value
|
|
183
|
+
return value.toString()
|
|
184
|
+
def _sort_cmp(a, b, ap, bp):
|
|
185
|
+
if a < b:
|
|
186
|
+
return -1
|
|
187
|
+
if a > b:
|
|
188
|
+
return 1
|
|
189
|
+
return ap - bp
|
|
190
|
+
key = key or _sort_key
|
|
191
|
+
mult = -1 if reverse else 1
|
|
192
|
+
keymap = dict()
|
|
193
|
+
posmap = dict()
|
|
194
|
+
for v'var i=0; i < this.length; i++':
|
|
195
|
+
k = this[i] # noqa:undef
|
|
196
|
+
keymap.set(k, key(k))
|
|
197
|
+
posmap.set(k, i)
|
|
198
|
+
this.sort(def (a, b): return mult * _sort_cmp(keymap.get(a), keymap.get(b), posmap.get(a), posmap.get(b));)
|
|
199
|
+
});
|
|
200
|
+
Object.defineProperty(Array.prototype, 'as_array', {
|
|
201
|
+
'writable': False, 'configurable': False, 'enumerable': False,
|
|
202
|
+
'value': def(): return Array.from(this)
|
|
203
|
+
});
|
|
204
|
+
Object.defineProperty(Array.prototype, '__len__', {
|
|
205
|
+
'writable': False, 'configurable': False, 'enumerable': False,
|
|
206
|
+
'value': def(): return this.length
|
|
207
|
+
});
|
|
208
|
+
Object.defineProperty(Array.prototype, '__contains__', {
|
|
209
|
+
'writable': False, 'configurable': False, 'enumerable': False,
|
|
210
|
+
'value': def(val):
|
|
211
|
+
for v'var i = 0; i < this.length; i++':
|
|
212
|
+
if this[i] == val:
|
|
213
|
+
return True
|
|
214
|
+
return False
|
|
215
|
+
});
|
|
216
|
+
Object.defineProperty(Array.prototype, '__eq__', {
|
|
217
|
+
'writable': False, 'configurable': False, 'enumerable': False,
|
|
218
|
+
'value': def(other):
|
|
219
|
+
if not ρσ_arraylike(other):
|
|
220
|
+
return False
|
|
221
|
+
if this.length != other.length:
|
|
222
|
+
return False
|
|
223
|
+
for v'var i = 0; i < this.length; i++':
|
|
224
|
+
if not (this[i] == other[i]):
|
|
225
|
+
return False
|
|
226
|
+
return True
|
|
227
|
+
});
|
|
228
|
+
Object.defineProperty(Array.prototype, 'constructor', {
|
|
229
|
+
'writable': False, 'configurable': False, 'enumerable': False,
|
|
230
|
+
'value': ρσ_list_constructor,
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
def ρσ_list_decorate(ans):
|
|
234
|
+
return ans
|
|
235
|
+
|
|
234
236
|
v'var list = ρσ_list_constructor, list_wrap = ρσ_list_decorate'
|
|
235
237
|
|
|
236
238
|
def sorted(iterable, key=None, reverse=False):
|
package/src/baselib-internal.pyj
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# vim:fileencoding=utf-8
|
|
2
2
|
# License: BSD
|
|
3
3
|
|
|
4
|
-
# globals: exports, console, ρσ_iterator_symbol, ρσ_kwargs_symbol, ρσ_arraylike, ρσ
|
|
4
|
+
# globals: exports, console, ρσ_iterator_symbol, ρσ_kwargs_symbol, ρσ_arraylike, ρσ_list_constructor, ρσ_str, ρσ_int, ρσ_float
|
|
5
5
|
|
|
6
6
|
def ρσ_eslice(arr, step, start, end):
|
|
7
7
|
if jstype(arr) is 'string' or v'arr instanceof String':
|
|
@@ -82,7 +82,7 @@ def ρσ_extends(child, parent):
|
|
|
82
82
|
if v'arr instanceof Map || arr instanceof Set':
|
|
83
83
|
return arr.has(val)
|
|
84
84
|
if ρσ_arraylike(arr):
|
|
85
|
-
return
|
|
85
|
+
return Array.prototype.__contains__.call(arr, val)
|
|
86
86
|
return Object.prototype.hasOwnProperty.call(arr, val)
|
|
87
87
|
return def(val, arr):
|
|
88
88
|
if jstype(arr) is 'string':
|
|
@@ -90,7 +90,7 @@ def ρσ_extends(child, parent):
|
|
|
90
90
|
if jstype(arr.__contains__) is 'function':
|
|
91
91
|
return arr.__contains__(val)
|
|
92
92
|
if ρσ_arraylike(arr):
|
|
93
|
-
return
|
|
93
|
+
return Array.prototype.__contains__.call(arr, val)
|
|
94
94
|
return Object.prototype.hasOwnProperty.call(arr, val)
|
|
95
95
|
)()
|
|
96
96
|
|
package/src/baselib-str.pyj
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# License: BSD
|
|
3
3
|
# Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
|
4
4
|
|
|
5
|
-
# globals: ρσ_kwargs_symbol, ρσ
|
|
5
|
+
# globals: ρσ_kwargs_symbol, ρσ_iterator_symbol, HTMLElement
|
|
6
6
|
|
|
7
7
|
# Locale can’t be changed in-flight, so we just retrieve this once.
|
|
8
8
|
# Sadly older node versions (< 8) don’t support formatToParts
|
|
@@ -116,7 +116,7 @@ define_str_func('format', def ():
|
|
|
116
116
|
template = this
|
|
117
117
|
if template is undefined:
|
|
118
118
|
raise TypeError("Template is required")
|
|
119
|
-
args = Array.
|
|
119
|
+
args = Array.from(arguments)
|
|
120
120
|
kwargs = {}
|
|
121
121
|
if args[-1] and args[-1][ρσ_kwargs_symbol] is not undefined:
|
|
122
122
|
kwargs = args[-1]
|
|
@@ -646,7 +646,7 @@ define_str_func('split', def(sep, maxsplit):
|
|
|
646
646
|
extra = ans[maxsplit:].join(sep)
|
|
647
647
|
ans = ans[:maxsplit]
|
|
648
648
|
ans.push(extra)
|
|
649
|
-
return
|
|
649
|
+
return ans
|
|
650
650
|
)
|
|
651
651
|
|
|
652
652
|
define_str_func('rsplit', def(sep, maxsplit):
|
|
@@ -692,7 +692,7 @@ define_str_func('rsplit', def(sep, maxsplit):
|
|
|
692
692
|
end = idx
|
|
693
693
|
ans.push(this[:end])
|
|
694
694
|
ans.reverse()
|
|
695
|
-
return
|
|
695
|
+
return ans
|
|
696
696
|
)
|
|
697
697
|
|
|
698
698
|
define_str_func('splitlines', def(keepends):
|
|
@@ -707,7 +707,7 @@ define_str_func('splitlines', def(keepends):
|
|
|
707
707
|
ans[-1] += parts[i] # noqa:undef
|
|
708
708
|
else:
|
|
709
709
|
ans = split(this, /(?:\r?\n)|\r/)
|
|
710
|
-
return
|
|
710
|
+
return ans
|
|
711
711
|
)
|
|
712
712
|
|
|
713
713
|
define_str_func('swapcase', def():
|
package/src/lib/aes.pyj
CHANGED
|
@@ -403,7 +403,7 @@ def generate_tag(sz):
|
|
|
403
403
|
|
|
404
404
|
def typed_array_as_js(x):
|
|
405
405
|
name = x.constructor.name or 'Uint8Array'
|
|
406
|
-
return '(new ' + name + '(' + JSON.stringify(Array.
|
|
406
|
+
return '(new ' + name + '(' + JSON.stringify(Array.from(x)) + '))'
|
|
407
407
|
|
|
408
408
|
class CBC(ModeOfOperation): # {{{
|
|
409
409
|
|
package/src/lib/encodings.pyj
CHANGED
|
@@ -26,7 +26,7 @@ def base64decode(string):
|
|
|
26
26
|
if jstype(window) is not 'undefined':
|
|
27
27
|
chars = window.atob(string)
|
|
28
28
|
else:
|
|
29
|
-
chars =
|
|
29
|
+
chars = Buffer.from(string, 'base64').toString('binary') # noqa: undef
|
|
30
30
|
ans = Uint8Array(chars.length)
|
|
31
31
|
for i in range(ans.length):
|
|
32
32
|
ans[i] = chars.charCodeAt(i)
|
package/src/lib/pythonize.pyj
CHANGED
package/src/lib/re.pyj
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
|
4
4
|
# Copyright: 2013, Alexander Tsepkov
|
|
5
5
|
|
|
6
|
-
# globals: ρσ_iterator_symbol
|
|
6
|
+
# globals: ρσ_iterator_symbol
|
|
7
7
|
|
|
8
8
|
# basic implementation of Python's 're' library
|
|
9
9
|
|
|
@@ -384,7 +384,7 @@ class RegexObject:
|
|
|
384
384
|
|
|
385
385
|
def findall(self, string):
|
|
386
386
|
self._pattern.lastIndex = 0
|
|
387
|
-
return
|
|
387
|
+
return string.match(self._pattern) or v'[]'
|
|
388
388
|
|
|
389
389
|
def finditer(self, string):
|
|
390
390
|
# We have to copy pat since lastIndex is mutable
|