koatl 0.1.34__tar.gz → 0.1.36__tar.gz
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.
- {koatl-0.1.34 → koatl-0.1.36}/Cargo.lock +1 -1
- {koatl-0.1.34 → koatl-0.1.36}/PKG-INFO +1 -1
- {koatl-0.1.34 → koatl-0.1.36}/koatl/Cargo.toml +1 -1
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/prelude/functional/algebra.tl +4 -4
- {koatl-0.1.34 → koatl-0.1.36/koatl}/python/koatl/prelude/iterable.tl +16 -6
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/runtime/classes.py +5 -4
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/prelude/virtual.tl +1 -1
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/src/resolve_scopes.rs +46 -14
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/src/transform.rs +2 -1
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/prelude/functional/algebra.tl +4 -4
- {koatl-0.1.34/koatl → koatl-0.1.36}/python/koatl/prelude/iterable.tl +16 -6
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/runtime/classes.py +5 -4
- {koatl-0.1.34 → koatl-0.1.36}/Cargo.toml +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/README.md +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/.github/workflows/CI.yml +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/.gitignore +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/LICENSE +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/README.md +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/__init__.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/__main__.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/cli.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/notebook/__init__.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/notebook/magic.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/prelude/__init__.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/prelude/functional/__init__.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/prelude/functional/async.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/prelude/functional/env.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/prelude/functional/list.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/prelude/functional/memo.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/prelude/functional/result.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/prelude/io.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/prelude/regex.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/runtime/__init__.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/runtime/helpers.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/runtime/meta_finder.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/runtime/record.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/python/koatl/runtime/virtual.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/requirements.txt +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/src/emit_py.rs +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/src/lib.rs +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/coal.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/containers.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/data.txt +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/decorators.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/destructure-for-and-fn.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/destructure.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/escape_ident.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/fstr.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/functions.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/generator.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/if_expr.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/imports.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/loops.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/match.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/nary-list.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/placeholder.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/precedence.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/record.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/scopes.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/semantic_whitespace.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/short_circuit.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/base/with.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/prelude/async.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/prelude/aug_assign.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/prelude/env.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/prelude/iterables.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/prelude/list.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/prelude/memo.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/prelude/result.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/prelude/slice.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/prelude/try.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/util/__init__.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/util/module0.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/util/module1.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/e2e/util/module2.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/parse/arith.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/parse/assign.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/parse/block-comments.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/parse/deco.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/parse/func.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/parse/matches.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/test_e2e.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl/tests/test_parse.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/Cargo.toml +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/parser/Cargo.toml +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/parser/src/ast.rs +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/parser/src/lexer.rs +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/parser/src/lib.rs +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/parser/src/parser.rs +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/parser/src/util.rs +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/src/inference.rs +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/src/lib.rs +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/src/main.rs +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/src/parse_timer.rs +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/src/parser.rs +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/src/py/ast.rs +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/src/py/emit.rs +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/src/py/mod.rs +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/src/py/util.rs +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/src/types.rs +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/koatl-core/src/util.rs +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/pyproject.toml +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/__init__.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/__main__.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/cli.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/notebook/__init__.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/notebook/magic.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/prelude/__init__.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/prelude/functional/__init__.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/prelude/functional/async.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/prelude/functional/env.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/prelude/functional/list.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/prelude/functional/memo.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/prelude/functional/result.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/prelude/io.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/prelude/regex.tl +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/runtime/__init__.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/runtime/helpers.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/runtime/meta_finder.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/runtime/record.py +0 -0
- {koatl-0.1.34 → koatl-0.1.36}/python/koatl/runtime/virtual.py +0 -0
|
@@ -8,9 +8,9 @@ export Monad = class(Trait):
|
|
|
8
8
|
"""
|
|
9
9
|
__slots__ = ()
|
|
10
10
|
|
|
11
|
-
bind =
|
|
11
|
+
bind = Trait.abstract& (self, f) => None
|
|
12
12
|
|
|
13
|
-
pure = staticmethod&
|
|
13
|
+
pure = staticmethod& Trait.abstract& value => None
|
|
14
14
|
|
|
15
15
|
# Automatically generated implementations.
|
|
16
16
|
map = (self, f) => self.bind(x => self.pure(f(x)))
|
|
@@ -33,7 +33,7 @@ export MonadOnce = class(Monad, Trait):
|
|
|
33
33
|
__slots__ = ()
|
|
34
34
|
|
|
35
35
|
# The default implementation required for `@` syntax that should be overridden by subclasses.
|
|
36
|
-
bind_once =
|
|
36
|
+
bind_once = Trait.abstract& (self, f) => None
|
|
37
37
|
|
|
38
38
|
# An optional, optimized implementation of `bind` that skips deep recursion.
|
|
39
39
|
# TODO: can this be automatically generated from bind_once?
|
|
@@ -69,4 +69,4 @@ export Traversable = class(Trait):
|
|
|
69
69
|
"""
|
|
70
70
|
__slots__ = ()
|
|
71
71
|
|
|
72
|
-
traverse =
|
|
72
|
+
traverse = Trait.abstract& (self, f) => None
|
|
@@ -3,7 +3,7 @@ import builtins
|
|
|
3
3
|
import .functional.(Traversable, Ok, Err, Memo, Async, AsyncMemo, Result)
|
|
4
4
|
|
|
5
5
|
export Iterable = Extension.trait& class(Traversable, Trait):
|
|
6
|
-
iter =
|
|
6
|
+
iter = Trait.abstract& self => None
|
|
7
7
|
|
|
8
8
|
skip = (self, n) =>
|
|
9
9
|
let it = self.iter
|
|
@@ -11,6 +11,16 @@ export Iterable = Extension.trait& class(Traversable, Trait):
|
|
|
11
11
|
next(it, None)
|
|
12
12
|
it
|
|
13
13
|
|
|
14
|
+
skip_while = (self, f) =>
|
|
15
|
+
let it = self.iter
|
|
16
|
+
while True:
|
|
17
|
+
try:
|
|
18
|
+
let value = next(it)
|
|
19
|
+
if not f(value):
|
|
20
|
+
return Iterable.chain([value], it)
|
|
21
|
+
except StopIteration():
|
|
22
|
+
return it
|
|
23
|
+
|
|
14
24
|
take = (self, n) =>
|
|
15
25
|
let impl = () =>
|
|
16
26
|
let it = self.iter
|
|
@@ -70,7 +80,7 @@ export Iterable = Extension.trait& class(Traversable, Trait):
|
|
|
70
80
|
|
|
71
81
|
reverse = self => reversed(list(self.iter))
|
|
72
82
|
|
|
73
|
-
|
|
83
|
+
sorted = (self, key=None, reverse=False) =>
|
|
74
84
|
sorted(self.iter, key=key, reverse=reverse)
|
|
75
85
|
|
|
76
86
|
copy = self => itertools.tee(self.iter)
|
|
@@ -99,19 +109,19 @@ export Iterable = Extension.trait& class(Traversable, Trait):
|
|
|
99
109
|
acc[i] = value
|
|
100
110
|
acc
|
|
101
111
|
|
|
102
|
-
group_by = (self, f) =>
|
|
112
|
+
group_by = (self, f=None) =>
|
|
103
113
|
let acc = dict()
|
|
104
114
|
for i in self:
|
|
105
|
-
let key = f(i)
|
|
115
|
+
let key = f === None then i else f(i)
|
|
106
116
|
if not acc.__contains__(key):
|
|
107
117
|
acc[key] = []
|
|
108
118
|
acc[key].append(i)
|
|
109
119
|
acc
|
|
110
120
|
|
|
111
|
-
count_by = (self, f) =>
|
|
121
|
+
count_by = (self, f=None) =>
|
|
112
122
|
let acc = dict()
|
|
113
123
|
for i in self:
|
|
114
|
-
let key = f(i)
|
|
124
|
+
let key = f === None then i else f(i)
|
|
115
125
|
if not acc.__contains__(key):
|
|
116
126
|
acc[key] = 0
|
|
117
127
|
acc[key] += 1
|
|
@@ -40,6 +40,7 @@ class MappingMeta(type):
|
|
|
40
40
|
return [(k, v) for k, v in inspect.getmembers(self) if not k.startswith("_")]
|
|
41
41
|
|
|
42
42
|
|
|
43
|
+
# A utility base class to inherit from to enable __getitem__ method lookup on types and thus destructuring.
|
|
43
44
|
class Class(metaclass=MappingMeta):
|
|
44
45
|
pass
|
|
45
46
|
|
|
@@ -104,9 +105,9 @@ class Trait(metaclass=TraitMeta):
|
|
|
104
105
|
fn._property = True
|
|
105
106
|
return property(fn)
|
|
106
107
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
@staticmethod
|
|
109
|
+
def abstract(value):
|
|
110
|
+
return abc.abstractmethod(value)
|
|
110
111
|
|
|
111
112
|
|
|
112
|
-
__all__ = ["Class", "Trait"
|
|
113
|
+
__all__ = ["Class", "Trait"]
|
|
@@ -15,7 +15,7 @@ assert_eq(x.a, 1)
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
SomeTrait = Extension.trait& class(Trait):
|
|
18
|
-
required_method =
|
|
18
|
+
required_method = Trait.abstract& self => ()
|
|
19
19
|
|
|
20
20
|
derived_method = self => self.required_method()
|
|
21
21
|
derived_property = Trait.property& self => self.required_method()
|
|
@@ -142,6 +142,10 @@ impl<'src> ResolveState<'src> {
|
|
|
142
142
|
fn_ctx.captures.insert(found.decl.clone().into());
|
|
143
143
|
|
|
144
144
|
for fn_ctx in self.fn_stack.iter_mut().rev().skip(1) {
|
|
145
|
+
if fn_ctx.decls.contains(&found.decl) {
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
|
|
145
149
|
fn_ctx.indirect_captures.insert(found.decl.clone().into());
|
|
146
150
|
}
|
|
147
151
|
|
|
@@ -152,9 +156,12 @@ impl<'src> ResolveState<'src> {
|
|
|
152
156
|
|
|
153
157
|
if lhs {
|
|
154
158
|
if scope.is_class || scope.is_global {
|
|
155
|
-
let decl =
|
|
156
|
-
self.
|
|
157
|
-
|
|
159
|
+
let decl = self.declarations.insert_declaration(
|
|
160
|
+
&mut self.fn_stack,
|
|
161
|
+
ident.clone(),
|
|
162
|
+
scope_key,
|
|
163
|
+
DeclType::Let,
|
|
164
|
+
);
|
|
158
165
|
|
|
159
166
|
scope.locals.push(decl.clone());
|
|
160
167
|
|
|
@@ -163,9 +170,12 @@ impl<'src> ResolveState<'src> {
|
|
|
163
170
|
}
|
|
164
171
|
|
|
165
172
|
if !lhs {
|
|
166
|
-
let decl =
|
|
167
|
-
self.
|
|
168
|
-
|
|
173
|
+
let decl = self.declarations.insert_declaration(
|
|
174
|
+
&mut self.fn_stack,
|
|
175
|
+
ident.clone(),
|
|
176
|
+
self.root_scope,
|
|
177
|
+
DeclType::Let,
|
|
178
|
+
);
|
|
169
179
|
|
|
170
180
|
self.scopes[self.root_scope].locals.push(decl.clone());
|
|
171
181
|
|
|
@@ -212,6 +222,7 @@ impl<'src> ResolveState<'src> {
|
|
|
212
222
|
let temp_scope_key = self.scopes.insert(dummy_scope);
|
|
213
223
|
|
|
214
224
|
let ph_decl = self.declarations.insert_declaration(
|
|
225
|
+
&mut self.fn_stack,
|
|
215
226
|
Ident("x".into()).spanned(span),
|
|
216
227
|
temp_scope_key,
|
|
217
228
|
DeclType::Let,
|
|
@@ -332,9 +343,9 @@ impl<'src> ResolveState<'src> {
|
|
|
332
343
|
|
|
333
344
|
let key = *self.scope_stack.last().unwrap();
|
|
334
345
|
|
|
335
|
-
let decl =
|
|
336
|
-
.declarations
|
|
337
|
-
|
|
346
|
+
let decl =
|
|
347
|
+
self.declarations
|
|
348
|
+
.insert_declaration(&mut self.fn_stack, name.clone(), key, modifier);
|
|
338
349
|
|
|
339
350
|
if lifted {
|
|
340
351
|
self.scopes[key].lifted_decls.push(decl.clone());
|
|
@@ -415,6 +426,8 @@ pub struct FnInfo {
|
|
|
415
426
|
pub is_memo: bool,
|
|
416
427
|
pub is_mapped_rhs: bool,
|
|
417
428
|
|
|
429
|
+
pub decls: Vec<DeclarationKey>,
|
|
430
|
+
|
|
418
431
|
pub arg_names: Vec<DeclarationKey>,
|
|
419
432
|
|
|
420
433
|
/**
|
|
@@ -439,6 +452,7 @@ impl FnInfo {
|
|
|
439
452
|
is_memo: false,
|
|
440
453
|
is_mapped_rhs: false,
|
|
441
454
|
arg_names: Vec::new(),
|
|
455
|
+
decls: Vec::new(),
|
|
442
456
|
captures: HashSet::new(),
|
|
443
457
|
indirect_captures: HashSet::new(),
|
|
444
458
|
}
|
|
@@ -461,6 +475,7 @@ pub struct Declaration<'src> {
|
|
|
461
475
|
trait DeclSlotMapExt<'src> {
|
|
462
476
|
fn insert_declaration(
|
|
463
477
|
&mut self,
|
|
478
|
+
fn_stack: &mut Vec<FnInfo>,
|
|
464
479
|
name: SIdent<'src>,
|
|
465
480
|
scope: ScopeKey,
|
|
466
481
|
modifier: DeclType,
|
|
@@ -470,6 +485,7 @@ trait DeclSlotMapExt<'src> {
|
|
|
470
485
|
impl<'src> DeclSlotMapExt<'src> for SlotMap<DeclarationKey, Declaration<'src>> {
|
|
471
486
|
fn insert_declaration(
|
|
472
487
|
&mut self,
|
|
488
|
+
fn_stack: &mut Vec<FnInfo>,
|
|
473
489
|
name: SIdent<'src>,
|
|
474
490
|
scope: ScopeKey,
|
|
475
491
|
modifier: DeclType,
|
|
@@ -486,7 +502,15 @@ impl<'src> DeclSlotMapExt<'src> for SlotMap<DeclarationKey, Declaration<'src>> {
|
|
|
486
502
|
is_import: false,
|
|
487
503
|
};
|
|
488
504
|
|
|
489
|
-
self.insert(decl)
|
|
505
|
+
let key = self.insert(decl);
|
|
506
|
+
|
|
507
|
+
if let Some(fnctx) = fn_stack.last_mut() {
|
|
508
|
+
if matches!(modifier, DeclType::Let | DeclType::Const) {
|
|
509
|
+
fnctx.decls.push(key);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
key
|
|
490
514
|
}
|
|
491
515
|
}
|
|
492
516
|
|
|
@@ -614,9 +638,12 @@ fn error_ident_and_decl<'src>(
|
|
|
614
638
|
let ident = Ident("_".into()).spanned(span);
|
|
615
639
|
let expr = Expr::Ident(ident.clone()).spanned(span).indirect();
|
|
616
640
|
|
|
617
|
-
let decl = state
|
|
618
|
-
.
|
|
619
|
-
|
|
641
|
+
let decl = state.declarations.insert_declaration(
|
|
642
|
+
&mut state.fn_stack,
|
|
643
|
+
ident.clone(),
|
|
644
|
+
state.err_scope,
|
|
645
|
+
DeclType::Let,
|
|
646
|
+
);
|
|
620
647
|
|
|
621
648
|
state.resolutions.insert(expr.as_ref().into(), decl);
|
|
622
649
|
|
|
@@ -861,6 +888,7 @@ fn pattern_scoped<'src>(
|
|
|
861
888
|
.iter()
|
|
862
889
|
.map(|x| {
|
|
863
890
|
state.declarations.insert_declaration(
|
|
891
|
+
&mut state.fn_stack,
|
|
864
892
|
x.clone().spanned(pattern.span),
|
|
865
893
|
scope_key,
|
|
866
894
|
DeclType::Let,
|
|
@@ -1187,6 +1215,7 @@ impl<'src> SExprExt<'src> for Indirect<SExpr<'src>> {
|
|
|
1187
1215
|
let cap = capture.spanned(pattern.span);
|
|
1188
1216
|
|
|
1189
1217
|
let decl = state.declarations.insert_declaration(
|
|
1218
|
+
&mut state.fn_stack,
|
|
1190
1219
|
cap,
|
|
1191
1220
|
scope,
|
|
1192
1221
|
DeclType::Let,
|
|
@@ -1210,6 +1239,7 @@ impl<'src> SExprExt<'src> for Indirect<SExpr<'src>> {
|
|
|
1210
1239
|
}
|
|
1211
1240
|
ArgDefItem::ArgSpread(arg) => {
|
|
1212
1241
|
let decl = state.declarations.insert_declaration(
|
|
1242
|
+
&mut state.fn_stack,
|
|
1213
1243
|
arg.clone(),
|
|
1214
1244
|
scope,
|
|
1215
1245
|
DeclType::Let,
|
|
@@ -1221,6 +1251,7 @@ impl<'src> SExprExt<'src> for Indirect<SExpr<'src>> {
|
|
|
1221
1251
|
}
|
|
1222
1252
|
ArgDefItem::KwargSpread(arg) => {
|
|
1223
1253
|
let decl = state.declarations.insert_declaration(
|
|
1254
|
+
&mut state.fn_stack,
|
|
1224
1255
|
arg.clone(),
|
|
1225
1256
|
scope,
|
|
1226
1257
|
DeclType::Let,
|
|
@@ -1432,7 +1463,7 @@ impl<'src> SExprExt<'src> for Indirect<SExpr<'src>> {
|
|
|
1432
1463
|
MappingItem::Item(key.traverse(state), value.traverse(state))
|
|
1433
1464
|
}
|
|
1434
1465
|
MappingItem::Spread(i) => MappingItem::Spread(i.traverse(state)),
|
|
1435
|
-
MappingItem::Ident(i) => MappingItem::Ident(i),
|
|
1466
|
+
MappingItem::Ident(i) => MappingItem::Ident(i.traverse(state)),
|
|
1436
1467
|
})
|
|
1437
1468
|
.collect::<Vec<_>>(),
|
|
1438
1469
|
),
|
|
@@ -1640,6 +1671,7 @@ impl<'src> SStmtExt<'src> for Indirect<SStmt<'src>> {
|
|
|
1640
1671
|
ImportList::Leaves(imports) => {
|
|
1641
1672
|
for (ident, as_name) in imports {
|
|
1642
1673
|
let decl = state.declarations.insert_declaration(
|
|
1674
|
+
&mut state.fn_stack,
|
|
1643
1675
|
as_name.clone().unwrap_or(ident.clone()),
|
|
1644
1676
|
scope_key,
|
|
1645
1677
|
if import_stmt.reexport {
|
|
@@ -2019,9 +2019,10 @@ impl<'src, 'ast> SExprExt<'src, 'ast> for SExpr<'src> {
|
|
|
2019
2019
|
for capture in deps_set {
|
|
2020
2020
|
let decl = &ctx.declarations[*capture];
|
|
2021
2021
|
let decl_scope = &ctx.scopes[decl.scope];
|
|
2022
|
+
let py_name = ctx.decl_py_ident(*capture)?;
|
|
2022
2023
|
|
|
2023
2024
|
if !decl_scope.is_global {
|
|
2024
|
-
nonglobal_deps.push(
|
|
2025
|
+
nonglobal_deps.push(py_name.clone());
|
|
2025
2026
|
}
|
|
2026
2027
|
}
|
|
2027
2028
|
|
|
@@ -8,9 +8,9 @@ export Monad = class(Trait):
|
|
|
8
8
|
"""
|
|
9
9
|
__slots__ = ()
|
|
10
10
|
|
|
11
|
-
bind =
|
|
11
|
+
bind = Trait.abstract& (self, f) => None
|
|
12
12
|
|
|
13
|
-
pure = staticmethod&
|
|
13
|
+
pure = staticmethod& Trait.abstract& value => None
|
|
14
14
|
|
|
15
15
|
# Automatically generated implementations.
|
|
16
16
|
map = (self, f) => self.bind(x => self.pure(f(x)))
|
|
@@ -33,7 +33,7 @@ export MonadOnce = class(Monad, Trait):
|
|
|
33
33
|
__slots__ = ()
|
|
34
34
|
|
|
35
35
|
# The default implementation required for `@` syntax that should be overridden by subclasses.
|
|
36
|
-
bind_once =
|
|
36
|
+
bind_once = Trait.abstract& (self, f) => None
|
|
37
37
|
|
|
38
38
|
# An optional, optimized implementation of `bind` that skips deep recursion.
|
|
39
39
|
# TODO: can this be automatically generated from bind_once?
|
|
@@ -69,4 +69,4 @@ export Traversable = class(Trait):
|
|
|
69
69
|
"""
|
|
70
70
|
__slots__ = ()
|
|
71
71
|
|
|
72
|
-
traverse =
|
|
72
|
+
traverse = Trait.abstract& (self, f) => None
|
|
@@ -3,7 +3,7 @@ import builtins
|
|
|
3
3
|
import .functional.(Traversable, Ok, Err, Memo, Async, AsyncMemo, Result)
|
|
4
4
|
|
|
5
5
|
export Iterable = Extension.trait& class(Traversable, Trait):
|
|
6
|
-
iter =
|
|
6
|
+
iter = Trait.abstract& self => None
|
|
7
7
|
|
|
8
8
|
skip = (self, n) =>
|
|
9
9
|
let it = self.iter
|
|
@@ -11,6 +11,16 @@ export Iterable = Extension.trait& class(Traversable, Trait):
|
|
|
11
11
|
next(it, None)
|
|
12
12
|
it
|
|
13
13
|
|
|
14
|
+
skip_while = (self, f) =>
|
|
15
|
+
let it = self.iter
|
|
16
|
+
while True:
|
|
17
|
+
try:
|
|
18
|
+
let value = next(it)
|
|
19
|
+
if not f(value):
|
|
20
|
+
return Iterable.chain([value], it)
|
|
21
|
+
except StopIteration():
|
|
22
|
+
return it
|
|
23
|
+
|
|
14
24
|
take = (self, n) =>
|
|
15
25
|
let impl = () =>
|
|
16
26
|
let it = self.iter
|
|
@@ -70,7 +80,7 @@ export Iterable = Extension.trait& class(Traversable, Trait):
|
|
|
70
80
|
|
|
71
81
|
reverse = self => reversed(list(self.iter))
|
|
72
82
|
|
|
73
|
-
|
|
83
|
+
sorted = (self, key=None, reverse=False) =>
|
|
74
84
|
sorted(self.iter, key=key, reverse=reverse)
|
|
75
85
|
|
|
76
86
|
copy = self => itertools.tee(self.iter)
|
|
@@ -99,19 +109,19 @@ export Iterable = Extension.trait& class(Traversable, Trait):
|
|
|
99
109
|
acc[i] = value
|
|
100
110
|
acc
|
|
101
111
|
|
|
102
|
-
group_by = (self, f) =>
|
|
112
|
+
group_by = (self, f=None) =>
|
|
103
113
|
let acc = dict()
|
|
104
114
|
for i in self:
|
|
105
|
-
let key = f(i)
|
|
115
|
+
let key = f === None then i else f(i)
|
|
106
116
|
if not acc.__contains__(key):
|
|
107
117
|
acc[key] = []
|
|
108
118
|
acc[key].append(i)
|
|
109
119
|
acc
|
|
110
120
|
|
|
111
|
-
count_by = (self, f) =>
|
|
121
|
+
count_by = (self, f=None) =>
|
|
112
122
|
let acc = dict()
|
|
113
123
|
for i in self:
|
|
114
|
-
let key = f(i)
|
|
124
|
+
let key = f === None then i else f(i)
|
|
115
125
|
if not acc.__contains__(key):
|
|
116
126
|
acc[key] = 0
|
|
117
127
|
acc[key] += 1
|
|
@@ -40,6 +40,7 @@ class MappingMeta(type):
|
|
|
40
40
|
return [(k, v) for k, v in inspect.getmembers(self) if not k.startswith("_")]
|
|
41
41
|
|
|
42
42
|
|
|
43
|
+
# A utility base class to inherit from to enable __getitem__ method lookup on types and thus destructuring.
|
|
43
44
|
class Class(metaclass=MappingMeta):
|
|
44
45
|
pass
|
|
45
46
|
|
|
@@ -104,9 +105,9 @@ class Trait(metaclass=TraitMeta):
|
|
|
104
105
|
fn._property = True
|
|
105
106
|
return property(fn)
|
|
106
107
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
@staticmethod
|
|
109
|
+
def abstract(value):
|
|
110
|
+
return abc.abstractmethod(value)
|
|
110
111
|
|
|
111
112
|
|
|
112
|
-
__all__ = ["Class", "Trait"
|
|
113
|
+
__all__ = ["Class", "Trait"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|