rapydscript-ns 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/.agignore +1 -0
- package/.gitattributes +4 -0
- package/.github/workflows/ci.yml +38 -0
- package/.github/workflows/web-repl-page-deploy.yml +42 -0
- package/=template.pyj +5 -0
- package/CHANGELOG.md +456 -0
- package/CONTRIBUTORS +13 -0
- package/HACKING.md +103 -0
- package/LICENSE +24 -0
- package/README.md +2512 -0
- package/TODO.md +327 -0
- package/add-toc-to-readme +2 -0
- package/bin/export +75 -0
- package/bin/rapydscript +70 -0
- package/bin/web-repl-export +102 -0
- package/build +3 -0
- package/package.json +46 -0
- package/publish.py +37 -0
- package/release/baselib-plain-pretty.js +4370 -0
- package/release/baselib-plain-ugly.js +3 -0
- package/release/compiler.js +18394 -0
- package/release/signatures.json +31 -0
- package/session.vim +4 -0
- package/setup.cfg +2 -0
- package/src/ast.pyj +1356 -0
- package/src/baselib-builtins.pyj +279 -0
- package/src/baselib-containers.pyj +723 -0
- package/src/baselib-errors.pyj +37 -0
- package/src/baselib-internal.pyj +421 -0
- package/src/baselib-itertools.pyj +97 -0
- package/src/baselib-str.pyj +798 -0
- package/src/compiler.pyj +36 -0
- package/src/errors.pyj +30 -0
- package/src/lib/aes.pyj +646 -0
- package/src/lib/collections.pyj +695 -0
- package/src/lib/elementmaker.pyj +83 -0
- package/src/lib/encodings.pyj +126 -0
- package/src/lib/functools.pyj +148 -0
- package/src/lib/gettext.pyj +569 -0
- package/src/lib/itertools.pyj +580 -0
- package/src/lib/math.pyj +193 -0
- package/src/lib/numpy.pyj +2101 -0
- package/src/lib/operator.pyj +11 -0
- package/src/lib/pythonize.pyj +20 -0
- package/src/lib/random.pyj +118 -0
- package/src/lib/re.pyj +470 -0
- package/src/lib/traceback.pyj +63 -0
- package/src/lib/uuid.pyj +77 -0
- package/src/monaco-language-service/analyzer.js +526 -0
- package/src/monaco-language-service/builtins.js +543 -0
- package/src/monaco-language-service/completions.js +498 -0
- package/src/monaco-language-service/diagnostics.js +643 -0
- package/src/monaco-language-service/dts.js +550 -0
- package/src/monaco-language-service/hover.js +121 -0
- package/src/monaco-language-service/index.js +386 -0
- package/src/monaco-language-service/scope.js +162 -0
- package/src/monaco-language-service/signature.js +144 -0
- package/src/output/__init__.pyj +0 -0
- package/src/output/classes.pyj +296 -0
- package/src/output/codegen.pyj +492 -0
- package/src/output/comments.pyj +45 -0
- package/src/output/exceptions.pyj +105 -0
- package/src/output/functions.pyj +491 -0
- package/src/output/literals.pyj +109 -0
- package/src/output/loops.pyj +444 -0
- package/src/output/modules.pyj +329 -0
- package/src/output/operators.pyj +429 -0
- package/src/output/statements.pyj +463 -0
- package/src/output/stream.pyj +309 -0
- package/src/output/treeshake.pyj +182 -0
- package/src/output/utils.pyj +72 -0
- package/src/parse.pyj +3106 -0
- package/src/string_interpolation.pyj +72 -0
- package/src/tokenizer.pyj +702 -0
- package/src/unicode_aliases.pyj +576 -0
- package/src/utils.pyj +192 -0
- package/test/_import_one.pyj +37 -0
- package/test/_import_two/__init__.pyj +11 -0
- package/test/_import_two/level2/__init__.pyj +0 -0
- package/test/_import_two/level2/deep.pyj +4 -0
- package/test/_import_two/other.pyj +6 -0
- package/test/_import_two/sub.pyj +13 -0
- package/test/aes_vectors.pyj +421 -0
- package/test/annotations.pyj +80 -0
- package/test/baselib.pyj +319 -0
- package/test/classes.pyj +452 -0
- package/test/collections.pyj +152 -0
- package/test/decorators.pyj +77 -0
- package/test/dict_spread.pyj +76 -0
- package/test/docstrings.pyj +39 -0
- package/test/elementmaker_test.pyj +45 -0
- package/test/ellipsis.pyj +49 -0
- package/test/functions.pyj +151 -0
- package/test/generators.pyj +41 -0
- package/test/generic.pyj +370 -0
- package/test/imports.pyj +72 -0
- package/test/internationalization.pyj +73 -0
- package/test/lint.pyj +164 -0
- package/test/loops.pyj +85 -0
- package/test/numpy.pyj +734 -0
- package/test/omit_function_metadata.pyj +20 -0
- package/test/regexp.pyj +55 -0
- package/test/repl.pyj +121 -0
- package/test/scoped_flags.pyj +76 -0
- package/test/starargs.pyj +506 -0
- package/test/starred_assign.pyj +104 -0
- package/test/str.pyj +198 -0
- package/test/subscript_tuple.pyj +53 -0
- package/test/unit/fixtures/fibonacci_expected.js +46 -0
- package/test/unit/index.js +2989 -0
- package/test/unit/language-service-builtins.js +815 -0
- package/test/unit/language-service-completions.js +1067 -0
- package/test/unit/language-service-dts.js +543 -0
- package/test/unit/language-service-hover.js +455 -0
- package/test/unit/language-service-scope.js +833 -0
- package/test/unit/language-service-signature.js +458 -0
- package/test/unit/language-service.js +705 -0
- package/test/unit/run-language-service.js +41 -0
- package/test/unit/web-repl.js +484 -0
- package/tools/build-language-service.js +190 -0
- package/tools/cli.js +547 -0
- package/tools/compile.js +219 -0
- package/tools/compiler.js +108 -0
- package/tools/completer.js +131 -0
- package/tools/embedded_compiler.js +251 -0
- package/tools/export.js +316 -0
- package/tools/gettext.js +185 -0
- package/tools/ini.js +65 -0
- package/tools/lint.js +705 -0
- package/tools/msgfmt.js +187 -0
- package/tools/repl.js +223 -0
- package/tools/self.js +162 -0
- package/tools/test.js +118 -0
- package/tools/utils.js +128 -0
- package/tools/web_repl.js +95 -0
- package/try +41 -0
- package/web-repl/env.js +74 -0
- package/web-repl/index.html +163 -0
- package/web-repl/language-service.js +4084 -0
- package/web-repl/main.js +254 -0
- package/web-repl/prism.css +139 -0
- package/web-repl/prism.js +113 -0
- package/web-repl/rapydscript.js +435 -0
- package/web-repl/sha1.js +25 -0
|
@@ -0,0 +1,723 @@
|
|
|
1
|
+
# vim:fileencoding=utf-8
|
|
2
|
+
# License: BSD
|
|
3
|
+
# Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
|
4
|
+
|
|
5
|
+
# globals:ρσ_iterator_symbol, ρσ_kwargs_symbol, ρσ_arraylike, ρσ_repr
|
|
6
|
+
|
|
7
|
+
def ρσ_equals(a, b):
|
|
8
|
+
if a is b:
|
|
9
|
+
return True
|
|
10
|
+
if a and jstype(a.__eq__) is 'function':
|
|
11
|
+
return a.__eq__(b)
|
|
12
|
+
if b and jstype(b.__eq__) is 'function':
|
|
13
|
+
return b.__eq__(a)
|
|
14
|
+
if ρσ_arraylike(a) and ρσ_arraylike(b):
|
|
15
|
+
if a.length != b.length:
|
|
16
|
+
return False
|
|
17
|
+
for v'var i=0; i < a.length; i++':
|
|
18
|
+
if not (a[i] == b[i]):
|
|
19
|
+
return False
|
|
20
|
+
return True
|
|
21
|
+
if jstype(a) is 'object' and jstype(b) is 'object' and a is not None and b is not None and (
|
|
22
|
+
(a.constructor is Object and b.constructor is Object) or (Object.getPrototypeOf(a) is None and Object.getPrototypeOf(b) is None)
|
|
23
|
+
):
|
|
24
|
+
# Do a dict like comparison as this is most likely either a JS has
|
|
25
|
+
# (Object.create(null) or a JS object used as a hash (v"{}"))
|
|
26
|
+
akeys, bkeys = Object.keys(a), Object.keys(b)
|
|
27
|
+
if akeys.length is not bkeys.length:
|
|
28
|
+
return False
|
|
29
|
+
for v'var j=0; j < akeys.length; j++':
|
|
30
|
+
key = akeys[j]
|
|
31
|
+
if not (a[key] == b[key]):
|
|
32
|
+
return False
|
|
33
|
+
return True
|
|
34
|
+
return False
|
|
35
|
+
|
|
36
|
+
def ρσ_not_equals(a, b):
|
|
37
|
+
if a is b:
|
|
38
|
+
return False
|
|
39
|
+
if a and jstype(a.__ne__) is 'function':
|
|
40
|
+
return a.__ne__(b)
|
|
41
|
+
if b and jstype(b.__ne__) is 'function':
|
|
42
|
+
return b.__ne__(a)
|
|
43
|
+
return not ρσ_equals(a, b)
|
|
44
|
+
|
|
45
|
+
v'var equals = ρσ_equals'
|
|
46
|
+
|
|
47
|
+
# list {{{
|
|
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
|
+
def ρσ_list_iterator(value):
|
|
156
|
+
self = this
|
|
157
|
+
return {
|
|
158
|
+
'_i':-1,
|
|
159
|
+
'_list':self,
|
|
160
|
+
'next':def():
|
|
161
|
+
this._i += 1
|
|
162
|
+
if this._i >= this._list.length:
|
|
163
|
+
return {'done':True}
|
|
164
|
+
return {'done':False, 'value':this._list[this._i]}
|
|
165
|
+
,
|
|
166
|
+
}
|
|
167
|
+
|
|
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
|
+
def ρσ_list_constructor(iterable):
|
|
213
|
+
if iterable is undefined:
|
|
214
|
+
ans = v'[]'
|
|
215
|
+
elif ρσ_arraylike(iterable):
|
|
216
|
+
ans = new Array(iterable.length)
|
|
217
|
+
for v'var i = 0; i < iterable.length; i++':
|
|
218
|
+
ans[i] = iterable[i] # noqa:undef
|
|
219
|
+
elif jstype(iterable[ρσ_iterator_symbol]) is 'function':
|
|
220
|
+
iterator = iterable.keys() if jstype(Map) is 'function' and v'iterable instanceof Map' else iterable[ρσ_iterator_symbol]()
|
|
221
|
+
ans = []
|
|
222
|
+
result = iterator.next()
|
|
223
|
+
while not result.done:
|
|
224
|
+
ans.push(result.value)
|
|
225
|
+
result = iterator.next()
|
|
226
|
+
elif jstype(iterable) is 'number':
|
|
227
|
+
# non-pythonic optimization to allocate all needed memory in a single operation
|
|
228
|
+
ans = new Array(iterable)
|
|
229
|
+
else:
|
|
230
|
+
ans = Object.keys(iterable)
|
|
231
|
+
return ρσ_list_decorate(ans)
|
|
232
|
+
ρσ_list_constructor.__name__ = 'list'
|
|
233
|
+
|
|
234
|
+
v'var list = ρσ_list_constructor, list_wrap = ρσ_list_decorate'
|
|
235
|
+
|
|
236
|
+
def sorted(iterable, key=None, reverse=False):
|
|
237
|
+
ans = ρσ_list_constructor(iterable)
|
|
238
|
+
ans.pysort(key, reverse)
|
|
239
|
+
return ans
|
|
240
|
+
# }}}
|
|
241
|
+
|
|
242
|
+
# set {{{
|
|
243
|
+
v'var ρσ_global_object_id = 0, ρσ_set_implementation'
|
|
244
|
+
|
|
245
|
+
def ρσ_set_keyfor(x):
|
|
246
|
+
t = jstype(x)
|
|
247
|
+
if t is 'string' or t is 'number' or t is 'boolean':
|
|
248
|
+
return '_' + t[0] + x
|
|
249
|
+
if v'x === null': # also matches undefined
|
|
250
|
+
return "__!@#$0"
|
|
251
|
+
ans = x.ρσ_hash_key_prop
|
|
252
|
+
if ans is undefined:
|
|
253
|
+
v'ans = "_!@#$" + (++ρσ_global_object_id)'
|
|
254
|
+
Object.defineProperty(x, 'ρσ_hash_key_prop', { 'value': ans })
|
|
255
|
+
return ans
|
|
256
|
+
|
|
257
|
+
def ρσ_set_polyfill():
|
|
258
|
+
this._store = {}
|
|
259
|
+
this.size = 0
|
|
260
|
+
|
|
261
|
+
ρσ_set_polyfill.prototype.add = def(x):
|
|
262
|
+
key = ρσ_set_keyfor(x)
|
|
263
|
+
if not Object.prototype.hasOwnProperty.call(this._store, key):
|
|
264
|
+
this.size += 1
|
|
265
|
+
this._store[key] = x
|
|
266
|
+
return this
|
|
267
|
+
|
|
268
|
+
ρσ_set_polyfill.prototype.clear = def(x):
|
|
269
|
+
this._store = {}
|
|
270
|
+
this.size = 0
|
|
271
|
+
|
|
272
|
+
ρσ_set_polyfill.prototype.delete = def(x):
|
|
273
|
+
key = ρσ_set_keyfor(x)
|
|
274
|
+
if Object.prototype.hasOwnProperty.call(this._store, key):
|
|
275
|
+
this.size -= 1
|
|
276
|
+
v'delete this._store[key]'
|
|
277
|
+
return True
|
|
278
|
+
return False
|
|
279
|
+
|
|
280
|
+
ρσ_set_polyfill.prototype.has = def(x):
|
|
281
|
+
return Object.prototype.hasOwnProperty.call(this._store, ρσ_set_keyfor(x))
|
|
282
|
+
|
|
283
|
+
ρσ_set_polyfill.prototype.values = def(x):
|
|
284
|
+
ans = v"{'_keys': Object.keys(this._store), '_i':-1, '_s':this._store}"
|
|
285
|
+
ans[ρσ_iterator_symbol] = def():
|
|
286
|
+
return this
|
|
287
|
+
ans['next'] = def():
|
|
288
|
+
this._i += 1
|
|
289
|
+
if this._i >= this._keys.length:
|
|
290
|
+
return v"{'done': true}"
|
|
291
|
+
return v"{'done':false, 'value':this._s[this._keys[this._i]]}"
|
|
292
|
+
return ans
|
|
293
|
+
|
|
294
|
+
if jstype(Set) is not 'function' or jstype(Set.prototype.delete) is not 'function':
|
|
295
|
+
v'ρσ_set_implementation = ρσ_set_polyfill'
|
|
296
|
+
else:
|
|
297
|
+
v'ρσ_set_implementation = Set'
|
|
298
|
+
|
|
299
|
+
def ρσ_set(iterable):
|
|
300
|
+
if v'this instanceof ρσ_set':
|
|
301
|
+
this.jsset = new ρσ_set_implementation() # noqa:undef
|
|
302
|
+
ans = this
|
|
303
|
+
if iterable is undefined:
|
|
304
|
+
return ans
|
|
305
|
+
s = ans.jsset
|
|
306
|
+
if ρσ_arraylike(iterable):
|
|
307
|
+
for v'var i = 0; i < iterable.length; i++':
|
|
308
|
+
s.add(iterable[i])
|
|
309
|
+
elif jstype(iterable[ρσ_iterator_symbol]) is 'function':
|
|
310
|
+
iterator = iterable.keys() if jstype(Map) is 'function' and v'iterable instanceof Map' else iterable[ρσ_iterator_symbol]()
|
|
311
|
+
result = iterator.next()
|
|
312
|
+
while not result.done:
|
|
313
|
+
s.add(result.value)
|
|
314
|
+
result = iterator.next()
|
|
315
|
+
else:
|
|
316
|
+
keys = Object.keys(iterable)
|
|
317
|
+
for v'var j=0; j < keys.length; j++':
|
|
318
|
+
s.add(keys[j])
|
|
319
|
+
return ans
|
|
320
|
+
else:
|
|
321
|
+
return new ρσ_set(iterable)
|
|
322
|
+
ρσ_set.prototype.__name__ = 'set'
|
|
323
|
+
|
|
324
|
+
# These are for JavaScript users' convenience
|
|
325
|
+
Object.defineProperties(ρσ_set.prototype, {
|
|
326
|
+
'length': { 'get': def(): return this.jsset.size; },
|
|
327
|
+
'size': { 'get': def(): return this.jsset.size; },
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
ρσ_set.prototype.__len__ = def(): return this.jsset.size
|
|
331
|
+
ρσ_set.prototype.has = ρσ_set.prototype.__contains__ = def(x): return this.jsset.has(x)
|
|
332
|
+
ρσ_set.prototype.add = def(x): this.jsset.add(x)
|
|
333
|
+
ρσ_set.prototype.clear = def(): this.jsset.clear()
|
|
334
|
+
ρσ_set.prototype.copy = def(): return ρσ_set(this)
|
|
335
|
+
ρσ_set.prototype.discard = def(x): this.jsset.delete(x)
|
|
336
|
+
ρσ_set.prototype[ρσ_iterator_symbol] = def(): return this.jsset.values()
|
|
337
|
+
|
|
338
|
+
ρσ_set.prototype.difference = def():
|
|
339
|
+
ans = new ρσ_set()
|
|
340
|
+
s = ans.jsset
|
|
341
|
+
iterator = this.jsset.values()
|
|
342
|
+
r = iterator.next()
|
|
343
|
+
while not r.done:
|
|
344
|
+
x = r.value
|
|
345
|
+
has = False
|
|
346
|
+
for v'var i = 0; i < arguments.length; i++':
|
|
347
|
+
if arguments[i].has(x): # noqa:undef
|
|
348
|
+
has = True
|
|
349
|
+
break
|
|
350
|
+
if not has:
|
|
351
|
+
s.add(x)
|
|
352
|
+
r = iterator.next()
|
|
353
|
+
return ans
|
|
354
|
+
|
|
355
|
+
ρσ_set.prototype.difference_update = def():
|
|
356
|
+
s = this.jsset
|
|
357
|
+
remove = v'[]'
|
|
358
|
+
iterator = s.values()
|
|
359
|
+
r = iterator.next()
|
|
360
|
+
while not r.done:
|
|
361
|
+
x = r.value
|
|
362
|
+
for v'var i = 0; i < arguments.length; i++':
|
|
363
|
+
if arguments[i].has(x): # noqa:undef
|
|
364
|
+
remove.push(x)
|
|
365
|
+
break
|
|
366
|
+
r = iterator.next()
|
|
367
|
+
for v'var j = 0; j < remove.length; j++':
|
|
368
|
+
s.delete(remove[j]) # noqa:undef
|
|
369
|
+
|
|
370
|
+
ρσ_set.prototype.intersection = def():
|
|
371
|
+
ans = new ρσ_set()
|
|
372
|
+
s = ans.jsset
|
|
373
|
+
iterator = this.jsset.values()
|
|
374
|
+
r = iterator.next()
|
|
375
|
+
while not r.done:
|
|
376
|
+
x = r.value
|
|
377
|
+
has = True
|
|
378
|
+
for v'var i = 0; i < arguments.length; i++':
|
|
379
|
+
if not arguments[i].has(x): # noqa:undef
|
|
380
|
+
has = False
|
|
381
|
+
break
|
|
382
|
+
if has:
|
|
383
|
+
s.add(x)
|
|
384
|
+
r = iterator.next()
|
|
385
|
+
return ans
|
|
386
|
+
|
|
387
|
+
ρσ_set.prototype.intersection_update = def():
|
|
388
|
+
s = this.jsset
|
|
389
|
+
remove = v'[]'
|
|
390
|
+
iterator = s.values()
|
|
391
|
+
r = iterator.next()
|
|
392
|
+
while not r.done:
|
|
393
|
+
x = r.value
|
|
394
|
+
for v'var i = 0; i < arguments.length; i++':
|
|
395
|
+
if not arguments[i].has(x): # noqa:undef
|
|
396
|
+
remove.push(x)
|
|
397
|
+
break
|
|
398
|
+
r = iterator.next()
|
|
399
|
+
for v'var j = 0; j < remove.length; j++':
|
|
400
|
+
s.delete(remove[j]) # noqa:undef
|
|
401
|
+
|
|
402
|
+
ρσ_set.prototype.isdisjoint = def(other):
|
|
403
|
+
iterator = this.jsset.values()
|
|
404
|
+
r = iterator.next()
|
|
405
|
+
while not r.done:
|
|
406
|
+
x = r.value
|
|
407
|
+
if other.has(x):
|
|
408
|
+
return False
|
|
409
|
+
r = iterator.next()
|
|
410
|
+
return True
|
|
411
|
+
|
|
412
|
+
ρσ_set.prototype.issubset = def(other):
|
|
413
|
+
iterator = this.jsset.values()
|
|
414
|
+
r = iterator.next()
|
|
415
|
+
while not r.done:
|
|
416
|
+
x = r.value
|
|
417
|
+
if not other.has(x):
|
|
418
|
+
return False
|
|
419
|
+
r = iterator.next()
|
|
420
|
+
return True
|
|
421
|
+
|
|
422
|
+
ρσ_set.prototype.issuperset = def(other):
|
|
423
|
+
s = this.jsset
|
|
424
|
+
iterator = other.jsset.values()
|
|
425
|
+
r = iterator.next()
|
|
426
|
+
while not r.done:
|
|
427
|
+
x = r.value
|
|
428
|
+
if not s.has(x):
|
|
429
|
+
return False
|
|
430
|
+
r = iterator.next()
|
|
431
|
+
return True
|
|
432
|
+
|
|
433
|
+
ρσ_set.prototype.pop = def():
|
|
434
|
+
iterator = this.jsset.values()
|
|
435
|
+
r = iterator.next()
|
|
436
|
+
if r.done:
|
|
437
|
+
raise KeyError('pop from an empty set')
|
|
438
|
+
this.jsset.delete(r.value)
|
|
439
|
+
return r.value
|
|
440
|
+
|
|
441
|
+
ρσ_set.prototype.remove = def(x):
|
|
442
|
+
if not this.jsset.delete(x):
|
|
443
|
+
raise KeyError(x.toString())
|
|
444
|
+
|
|
445
|
+
ρσ_set.prototype.symmetric_difference = def(other):
|
|
446
|
+
return this.union(other).difference(this.intersection(other))
|
|
447
|
+
|
|
448
|
+
ρσ_set.prototype.symmetric_difference_update = def(other):
|
|
449
|
+
common = this.intersection(other)
|
|
450
|
+
this.update(other)
|
|
451
|
+
this.difference_update(common)
|
|
452
|
+
|
|
453
|
+
ρσ_set.prototype.union = def():
|
|
454
|
+
ans = ρσ_set(this)
|
|
455
|
+
ans.update.apply(ans, arguments)
|
|
456
|
+
return ans
|
|
457
|
+
|
|
458
|
+
ρσ_set.prototype.update = def():
|
|
459
|
+
s = this.jsset
|
|
460
|
+
for v'var i=0; i < arguments.length; i++':
|
|
461
|
+
iterator = arguments[i][ρσ_iterator_symbol]() # noqa:undef
|
|
462
|
+
r = iterator.next()
|
|
463
|
+
while not r.done:
|
|
464
|
+
s.add(r.value)
|
|
465
|
+
r = iterator.next()
|
|
466
|
+
|
|
467
|
+
ρσ_set.prototype.toString = ρσ_set.prototype.__repr__ = ρσ_set.prototype.__str__ = ρσ_set.prototype.inspect = def():
|
|
468
|
+
return '{' + list(this).join(', ') + '}'
|
|
469
|
+
|
|
470
|
+
ρσ_set.prototype.__eq__ = def(other):
|
|
471
|
+
if not v'other instanceof this.constructor':
|
|
472
|
+
return False
|
|
473
|
+
if other.size is not this.size:
|
|
474
|
+
return False
|
|
475
|
+
if other.size is 0:
|
|
476
|
+
return True
|
|
477
|
+
iterator = other[ρσ_iterator_symbol]()
|
|
478
|
+
r = iterator.next()
|
|
479
|
+
while not r.done:
|
|
480
|
+
if not this.has(r.value):
|
|
481
|
+
return False
|
|
482
|
+
r = iterator.next()
|
|
483
|
+
return True
|
|
484
|
+
|
|
485
|
+
def ρσ_set_wrap(x):
|
|
486
|
+
ans = new ρσ_set()
|
|
487
|
+
ans.jsset = x
|
|
488
|
+
return ans
|
|
489
|
+
|
|
490
|
+
v'var set = ρσ_set, set_wrap = ρσ_set_wrap'
|
|
491
|
+
# }}}
|
|
492
|
+
|
|
493
|
+
# dict {{{
|
|
494
|
+
v'var ρσ_dict_implementation'
|
|
495
|
+
|
|
496
|
+
def ρσ_dict_polyfill():
|
|
497
|
+
this._store = {}
|
|
498
|
+
this.size = 0
|
|
499
|
+
|
|
500
|
+
ρσ_dict_polyfill.prototype.set = def(x, value):
|
|
501
|
+
key = ρσ_set_keyfor(x)
|
|
502
|
+
if not Object.prototype.hasOwnProperty.call(this._store, key):
|
|
503
|
+
this.size += 1
|
|
504
|
+
this._store[key] = v'[x, value]'
|
|
505
|
+
return this
|
|
506
|
+
|
|
507
|
+
ρσ_dict_polyfill.prototype.clear = def(x):
|
|
508
|
+
this._store = {}
|
|
509
|
+
this.size = 0
|
|
510
|
+
|
|
511
|
+
ρσ_dict_polyfill.prototype.delete = def(x):
|
|
512
|
+
key = ρσ_set_keyfor(x)
|
|
513
|
+
if Object.prototype.hasOwnProperty.call(this._store, key):
|
|
514
|
+
this.size -= 1
|
|
515
|
+
v'delete this._store[key]'
|
|
516
|
+
return True
|
|
517
|
+
return False
|
|
518
|
+
|
|
519
|
+
ρσ_dict_polyfill.prototype.has = def(x):
|
|
520
|
+
return Object.prototype.hasOwnProperty.call(this._store, ρσ_set_keyfor(x))
|
|
521
|
+
|
|
522
|
+
ρσ_dict_polyfill.prototype.get = def(x):
|
|
523
|
+
try:
|
|
524
|
+
return this._store[ρσ_set_keyfor(x)][1]
|
|
525
|
+
except TypeError: # Key is not present
|
|
526
|
+
return undefined
|
|
527
|
+
|
|
528
|
+
ρσ_dict_polyfill.prototype.values = def(x):
|
|
529
|
+
ans = v"{'_keys': Object.keys(this._store), '_i':-1, '_s':this._store}"
|
|
530
|
+
ans[ρσ_iterator_symbol] = def():
|
|
531
|
+
return this
|
|
532
|
+
ans['next'] = def():
|
|
533
|
+
this._i += 1
|
|
534
|
+
if this._i >= this._keys.length:
|
|
535
|
+
return v"{'done': true}"
|
|
536
|
+
return v"{'done':false, 'value':this._s[this._keys[this._i]][1]}"
|
|
537
|
+
return ans
|
|
538
|
+
|
|
539
|
+
ρσ_dict_polyfill.prototype.keys = def(x):
|
|
540
|
+
ans = v"{'_keys': Object.keys(this._store), '_i':-1, '_s':this._store}"
|
|
541
|
+
ans[ρσ_iterator_symbol] = def():
|
|
542
|
+
return this
|
|
543
|
+
ans['next'] = def():
|
|
544
|
+
this._i += 1
|
|
545
|
+
if this._i >= this._keys.length:
|
|
546
|
+
return v"{'done': true}"
|
|
547
|
+
return v"{'done':false, 'value':this._s[this._keys[this._i]][0]}"
|
|
548
|
+
return ans
|
|
549
|
+
|
|
550
|
+
ρσ_dict_polyfill.prototype.entries = def(x):
|
|
551
|
+
ans = v"{'_keys': Object.keys(this._store), '_i':-1, '_s':this._store}"
|
|
552
|
+
ans[ρσ_iterator_symbol] = def():
|
|
553
|
+
return this
|
|
554
|
+
ans['next'] = def():
|
|
555
|
+
this._i += 1
|
|
556
|
+
if this._i >= this._keys.length:
|
|
557
|
+
return v"{'done': true}"
|
|
558
|
+
return v"{'done':false, 'value':this._s[this._keys[this._i]]}"
|
|
559
|
+
return ans
|
|
560
|
+
|
|
561
|
+
if jstype(Map) is not 'function' or jstype(Map.prototype.delete) is not 'function':
|
|
562
|
+
v'ρσ_dict_implementation = ρσ_dict_polyfill'
|
|
563
|
+
else:
|
|
564
|
+
v'ρσ_dict_implementation = Map'
|
|
565
|
+
|
|
566
|
+
def ρσ_dict(iterable, **kw):
|
|
567
|
+
if v'this instanceof ρσ_dict':
|
|
568
|
+
this.jsmap = new ρσ_dict_implementation() # noqa:undef
|
|
569
|
+
if iterable is not undefined:
|
|
570
|
+
this.update(iterable)
|
|
571
|
+
this.update(kw)
|
|
572
|
+
return this
|
|
573
|
+
else:
|
|
574
|
+
return new ρσ_dict(iterable, **kw)
|
|
575
|
+
ρσ_dict.prototype.__name__ = 'dict'
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
# These are for JavaScript users' convenience
|
|
579
|
+
Object.defineProperties(ρσ_dict.prototype, {
|
|
580
|
+
'length': { 'get': def(): return this.jsmap.size; },
|
|
581
|
+
'size': { 'get': def(): return this.jsmap.size; },
|
|
582
|
+
})
|
|
583
|
+
|
|
584
|
+
ρσ_dict.prototype.__len__ = def(): return this.jsmap.size
|
|
585
|
+
ρσ_dict.prototype.has = ρσ_dict.prototype.__contains__ = def(x): return this.jsmap.has(x)
|
|
586
|
+
ρσ_dict.prototype.set = ρσ_dict.prototype.__setitem__ = def(key, value): this.jsmap.set(key, value)
|
|
587
|
+
ρσ_dict.prototype.__delitem__ = def (key): this.jsmap.delete(key)
|
|
588
|
+
ρσ_dict.prototype.clear = def(): this.jsmap.clear()
|
|
589
|
+
ρσ_dict.prototype.copy = def(): return ρσ_dict(this)
|
|
590
|
+
ρσ_dict.prototype.keys = def(): return this.jsmap.keys()
|
|
591
|
+
ρσ_dict.prototype.values = def(): return this.jsmap.values()
|
|
592
|
+
ρσ_dict.prototype.items = ρσ_dict.prototype.entries = def(): return this.jsmap.entries()
|
|
593
|
+
ρσ_dict.prototype[ρσ_iterator_symbol] = def(): return this.jsmap.keys()
|
|
594
|
+
|
|
595
|
+
ρσ_dict.prototype.__getitem__ = def (key):
|
|
596
|
+
ans = this.jsmap.get(key)
|
|
597
|
+
if ans is undefined and not this.jsmap.has(key):
|
|
598
|
+
raise KeyError(key + '')
|
|
599
|
+
return ans
|
|
600
|
+
|
|
601
|
+
ρσ_dict.prototype.get = def (key, defval):
|
|
602
|
+
ans = this.jsmap.get(key)
|
|
603
|
+
if ans is undefined and not this.jsmap.has(key):
|
|
604
|
+
return None if defval is undefined else defval
|
|
605
|
+
return ans
|
|
606
|
+
|
|
607
|
+
ρσ_dict.prototype.set_default = ρσ_dict.prototype.setdefault = def (key, defval):
|
|
608
|
+
j = this.jsmap
|
|
609
|
+
if not j.has(key):
|
|
610
|
+
j.set(key, defval)
|
|
611
|
+
return defval
|
|
612
|
+
return j.get(key)
|
|
613
|
+
|
|
614
|
+
ρσ_dict.fromkeys = ρσ_dict.prototype.fromkeys = def (iterable, value=None):
|
|
615
|
+
ans = ρσ_dict()
|
|
616
|
+
iterator = iter(iterable)
|
|
617
|
+
r = iterator.next()
|
|
618
|
+
while not r.done:
|
|
619
|
+
ans.set(r.value, value)
|
|
620
|
+
r = iterator.next()
|
|
621
|
+
return ans
|
|
622
|
+
|
|
623
|
+
ρσ_dict.prototype.pop = def (key, defval):
|
|
624
|
+
ans = this.jsmap.get(key)
|
|
625
|
+
if ans is undefined and not this.jsmap.has(key):
|
|
626
|
+
if defval is undefined:
|
|
627
|
+
raise KeyError(key)
|
|
628
|
+
return defval
|
|
629
|
+
this.jsmap.delete(key)
|
|
630
|
+
return ans
|
|
631
|
+
|
|
632
|
+
ρσ_dict.prototype.popitem = def ():
|
|
633
|
+
last = None
|
|
634
|
+
e = this.jsmap.entries()
|
|
635
|
+
while True:
|
|
636
|
+
r = e.next()
|
|
637
|
+
if r.done:
|
|
638
|
+
if last is None:
|
|
639
|
+
raise KeyError('dict is empty')
|
|
640
|
+
this.jsmap.delete(last.value[0])
|
|
641
|
+
return last.value
|
|
642
|
+
last = r
|
|
643
|
+
|
|
644
|
+
ρσ_dict.prototype.update = def ():
|
|
645
|
+
if arguments.length is 0:
|
|
646
|
+
return
|
|
647
|
+
m = this.jsmap
|
|
648
|
+
iterable = arguments[0]
|
|
649
|
+
if Array.isArray(iterable):
|
|
650
|
+
for v'var i = 0; i < iterable.length; i++':
|
|
651
|
+
m.set(iterable[i][0], iterable[i][1])
|
|
652
|
+
elif v'iterable instanceof ρσ_dict':
|
|
653
|
+
iterator = iterable.items()
|
|
654
|
+
result = iterator.next()
|
|
655
|
+
while not result.done:
|
|
656
|
+
m.set(result.value[0], result.value[1])
|
|
657
|
+
result = iterator.next()
|
|
658
|
+
elif jstype(Map) is 'function' and v'iterable instanceof Map':
|
|
659
|
+
iterator = iterable.entries()
|
|
660
|
+
result = iterator.next()
|
|
661
|
+
while not result.done:
|
|
662
|
+
m.set(result.value[0], result.value[1])
|
|
663
|
+
result = iterator.next()
|
|
664
|
+
elif jstype(iterable.items) is 'function' and not Array.isArray(iterable):
|
|
665
|
+
pairs = iterable.items()
|
|
666
|
+
for v'var k2 = 0; k2 < pairs.length; k2++':
|
|
667
|
+
m.set(pairs[k2][0], pairs[k2][1])
|
|
668
|
+
elif jstype(iterable[ρσ_iterator_symbol]) is 'function':
|
|
669
|
+
iterator = iterable[ρσ_iterator_symbol]()
|
|
670
|
+
result = iterator.next()
|
|
671
|
+
while not result.done:
|
|
672
|
+
m.set(result.value[0], result.value[1])
|
|
673
|
+
result = iterator.next()
|
|
674
|
+
else:
|
|
675
|
+
keys = Object.keys(iterable)
|
|
676
|
+
for v'var j=0; j < keys.length; j++':
|
|
677
|
+
if keys[j] is not ρσ_iterator_symbol:
|
|
678
|
+
m.set(keys[j], iterable[keys[j]])
|
|
679
|
+
if arguments.length > 1:
|
|
680
|
+
ρσ_dict.prototype.update.call(this, arguments[1])
|
|
681
|
+
|
|
682
|
+
ρσ_dict.prototype.toString = ρσ_dict.prototype.inspect = ρσ_dict.prototype.__str__ = ρσ_dict.prototype.__repr__ = def():
|
|
683
|
+
entries = v'[]'
|
|
684
|
+
iterator = this.jsmap.entries()
|
|
685
|
+
r = iterator.next()
|
|
686
|
+
while not r.done:
|
|
687
|
+
entries.push(ρσ_repr(r.value[0]) + ': ' + ρσ_repr(r.value[1]))
|
|
688
|
+
r = iterator.next()
|
|
689
|
+
return '{' + entries.join(', ') + '}'
|
|
690
|
+
|
|
691
|
+
ρσ_dict.prototype.__eq__ = def(other):
|
|
692
|
+
if not v'(other instanceof this.constructor)':
|
|
693
|
+
return False
|
|
694
|
+
if other.size is not this.size:
|
|
695
|
+
return False
|
|
696
|
+
if other.size is 0:
|
|
697
|
+
return True
|
|
698
|
+
iterator = other.items()
|
|
699
|
+
r = iterator.next()
|
|
700
|
+
while not r.done:
|
|
701
|
+
x = this.jsmap.get(r.value[0])
|
|
702
|
+
if (x is undefined and not this.jsmap.has(r.value[0])) or x is not r.value[1]:
|
|
703
|
+
return False
|
|
704
|
+
r = iterator.next()
|
|
705
|
+
return True
|
|
706
|
+
|
|
707
|
+
ρσ_dict.prototype.as_object = def(other):
|
|
708
|
+
ans = {}
|
|
709
|
+
iterator = this.jsmap.entries()
|
|
710
|
+
r = iterator.next()
|
|
711
|
+
while not r.done:
|
|
712
|
+
ans[r.value[0]] = r.value[1]
|
|
713
|
+
r = iterator.next()
|
|
714
|
+
return ans
|
|
715
|
+
|
|
716
|
+
def ρσ_dict_wrap(x):
|
|
717
|
+
ans = new ρσ_dict()
|
|
718
|
+
ans.jsmap = x
|
|
719
|
+
return ans
|
|
720
|
+
|
|
721
|
+
v'var dict = ρσ_dict, dict_wrap = ρσ_dict_wrap'
|
|
722
|
+
|
|
723
|
+
# }}}
|