sonolus.py 0.4.1__py3-none-any.whl → 0.4.2__py3-none-any.whl
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.
Potentially problematic release.
This version of sonolus.py might be problematic. Click here for more details.
- sonolus/backend/utils.py +15 -24
- sonolus/backend/visitor.py +8 -2
- sonolus/build/cli.py +3 -3
- sonolus/build/compile.py +16 -1
- sonolus/script/archetype.py +21 -12
- sonolus/script/array.py +1 -1
- sonolus/script/containers.py +1 -1
- sonolus/script/easing.py +0 -1
- sonolus/script/effect.py +4 -2
- sonolus/script/globals.py +5 -2
- sonolus/script/internal/context.py +7 -1
- sonolus/script/internal/native.py +1 -1
- sonolus/script/iterator.py +4 -2
- sonolus/script/maybe.py +15 -12
- sonolus/script/sprite.py +1 -1
- sonolus/script/stream.py +6 -5
- {sonolus_py-0.4.1.dist-info → sonolus_py-0.4.2.dist-info}/METADATA +1 -1
- {sonolus_py-0.4.1.dist-info → sonolus_py-0.4.2.dist-info}/RECORD +21 -21
- {sonolus_py-0.4.1.dist-info → sonolus_py-0.4.2.dist-info}/WHEEL +0 -0
- {sonolus_py-0.4.1.dist-info → sonolus_py-0.4.2.dist-info}/entry_points.txt +0 -0
- {sonolus_py-0.4.1.dist-info → sonolus_py-0.4.2.dist-info}/licenses/LICENSE +0 -0
sonolus/backend/utils.py
CHANGED
|
@@ -24,14 +24,29 @@ class FindFunction(ast.NodeVisitor):
|
|
|
24
24
|
def __init__(self, line):
|
|
25
25
|
self.line = line
|
|
26
26
|
self.results: list[ast.FunctionDef | ast.Lambda] = []
|
|
27
|
+
self.current_fn = None
|
|
27
28
|
|
|
28
29
|
def visit_FunctionDef(self, node: ast.FunctionDef):
|
|
29
30
|
self.results.append(node)
|
|
31
|
+
outer_fn = self.current_fn
|
|
32
|
+
self.current_fn = node
|
|
30
33
|
self.generic_visit(node)
|
|
34
|
+
self.current_fn = outer_fn
|
|
31
35
|
|
|
32
36
|
def visit_Lambda(self, node: ast.Lambda):
|
|
33
37
|
self.results.append(node)
|
|
38
|
+
outer_fn = self.current_fn
|
|
39
|
+
self.current_fn = node
|
|
34
40
|
self.generic_visit(node)
|
|
41
|
+
self.current_fn = outer_fn
|
|
42
|
+
|
|
43
|
+
# Visitors have high overhead, so we detect generators here rather than in a separate pass.
|
|
44
|
+
|
|
45
|
+
def visit_Yield(self, node):
|
|
46
|
+
self.current_fn.has_yield = True
|
|
47
|
+
|
|
48
|
+
def visit_YieldFrom(self, node):
|
|
49
|
+
self.current_fn.has_yield = True
|
|
35
50
|
|
|
36
51
|
|
|
37
52
|
@cache
|
|
@@ -65,27 +80,3 @@ def scan_writes(node: ast.AST) -> set[str]:
|
|
|
65
80
|
visitor = ScanWrites()
|
|
66
81
|
visitor.visit(node)
|
|
67
82
|
return set(visitor.writes)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
class HasDirectYield(ast.NodeVisitor):
|
|
71
|
-
def __init__(self):
|
|
72
|
-
self.started = False
|
|
73
|
-
self.has_yield = False
|
|
74
|
-
|
|
75
|
-
def visit_Yield(self, node: ast.Yield):
|
|
76
|
-
self.has_yield = True
|
|
77
|
-
|
|
78
|
-
def visit_YieldFrom(self, node: ast.YieldFrom):
|
|
79
|
-
self.has_yield = True
|
|
80
|
-
|
|
81
|
-
def visit_FunctionDef(self, node: ast.FunctionDef):
|
|
82
|
-
if self.started:
|
|
83
|
-
return
|
|
84
|
-
self.started = True
|
|
85
|
-
self.generic_visit(node)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
def has_yield(node: ast.AST) -> bool:
|
|
89
|
-
visitor = HasDirectYield()
|
|
90
|
-
visitor.visit(node)
|
|
91
|
-
return visitor.has_yield
|
sonolus/backend/visitor.py
CHANGED
|
@@ -11,7 +11,7 @@ from types import FunctionType, MethodType, MethodWrapperType
|
|
|
11
11
|
from typing import Any, Never
|
|
12
12
|
|
|
13
13
|
from sonolus.backend.excepthook import install_excepthook
|
|
14
|
-
from sonolus.backend.utils import get_function,
|
|
14
|
+
from sonolus.backend.utils import get_function, scan_writes
|
|
15
15
|
from sonolus.script.debug import assert_true
|
|
16
16
|
from sonolus.script.internal.builtin_impls import BUILTIN_IMPLS, _bool, _float, _int, _len
|
|
17
17
|
from sonolus.script.internal.constant import ConstantValue
|
|
@@ -39,6 +39,8 @@ def compile_and_call[**P, R](fn: Callable[P, R], /, *args: P.args, **kwargs: P.k
|
|
|
39
39
|
def compile_and_call_at_definition[**P, R](fn: Callable[P, R], /, *args: P.args, **kwargs: P.kwargs) -> R:
|
|
40
40
|
if not ctx():
|
|
41
41
|
return fn(*args, **kwargs)
|
|
42
|
+
if ctx().no_eval:
|
|
43
|
+
return compile_and_call(fn, *args, **kwargs)
|
|
42
44
|
source_file, node = get_function(fn)
|
|
43
45
|
location_args = {
|
|
44
46
|
"lineno": node.lineno,
|
|
@@ -279,7 +281,8 @@ class Visitor(ast.NodeVisitor):
|
|
|
279
281
|
ctx().scope.set_value("$return", validate_value(None))
|
|
280
282
|
case _:
|
|
281
283
|
raise NotImplementedError("Unsupported syntax")
|
|
282
|
-
|
|
284
|
+
# has_yield is set by the find_function visitor
|
|
285
|
+
if getattr(node, "has_yield", False) or isinstance(node, ast.GeneratorExp):
|
|
283
286
|
return_ctx = Context.meet([*self.return_ctxs, ctx()])
|
|
284
287
|
result_binding = return_ctx.scope.get_binding("$return")
|
|
285
288
|
if not isinstance(result_binding, ValueBinding):
|
|
@@ -1423,6 +1426,9 @@ class Visitor(ast.NodeVisitor):
|
|
|
1423
1426
|
self, node: ast.stmt | ast.expr, fn: Callable[P, R], /, *args: P.args, **kwargs: P.kwargs
|
|
1424
1427
|
) -> R:
|
|
1425
1428
|
"""Executes the given function at the given node for a better traceback."""
|
|
1429
|
+
if ctx().no_eval:
|
|
1430
|
+
return fn(*args, **kwargs)
|
|
1431
|
+
|
|
1426
1432
|
location_args = {
|
|
1427
1433
|
"lineno": node.lineno,
|
|
1428
1434
|
"col_offset": node.col_offset,
|
sonolus/build/cli.py
CHANGED
|
@@ -166,13 +166,13 @@ def main():
|
|
|
166
166
|
def add_common_arguments(parser):
|
|
167
167
|
optimization_group = parser.add_mutually_exclusive_group()
|
|
168
168
|
optimization_group.add_argument(
|
|
169
|
-
"-
|
|
169
|
+
"-O0", "--optimize-minimal", action="store_true", help="Use minimal optimization passes"
|
|
170
170
|
)
|
|
171
171
|
optimization_group.add_argument(
|
|
172
|
-
"-
|
|
172
|
+
"-O1", "--optimize-fast", action="store_true", help="Use fast optimization passes"
|
|
173
173
|
)
|
|
174
174
|
optimization_group.add_argument(
|
|
175
|
-
"-
|
|
175
|
+
"-O2", "--optimize-standard", action="store_true", help="Use standard optimization passes"
|
|
176
176
|
)
|
|
177
177
|
|
|
178
178
|
build_components = parser.add_argument_group("build components")
|
sonolus/build/compile.py
CHANGED
|
@@ -21,6 +21,7 @@ from sonolus.script.internal.context import (
|
|
|
21
21
|
ctx,
|
|
22
22
|
using_ctx,
|
|
23
23
|
)
|
|
24
|
+
from sonolus.script.internal.error import CompilationError
|
|
24
25
|
from sonolus.script.num import _is_num
|
|
25
26
|
|
|
26
27
|
|
|
@@ -140,7 +141,21 @@ def callback_to_cfg(
|
|
|
140
141
|
name: str,
|
|
141
142
|
archetype: type[_BaseArchetype] | None = None,
|
|
142
143
|
) -> BasicBlock:
|
|
143
|
-
|
|
144
|
+
try:
|
|
145
|
+
# Default to no_eval=True for performance unless there's an error.
|
|
146
|
+
return _callback_to_cfg(global_state, callback, name, archetype, no_eval=True)
|
|
147
|
+
except CompilationError:
|
|
148
|
+
return _callback_to_cfg(global_state, callback, name, archetype, no_eval=False)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _callback_to_cfg(
|
|
152
|
+
global_state: GlobalContextState,
|
|
153
|
+
callback: Callable,
|
|
154
|
+
name: str,
|
|
155
|
+
archetype: type[_BaseArchetype] | None,
|
|
156
|
+
no_eval: bool,
|
|
157
|
+
) -> BasicBlock:
|
|
158
|
+
callback_state = CallbackContextState(name, no_eval=no_eval)
|
|
144
159
|
context = Context(global_state, callback_state)
|
|
145
160
|
with using_ctx(context):
|
|
146
161
|
if archetype is not None:
|
sonolus/script/archetype.py
CHANGED
|
@@ -190,7 +190,8 @@ def imported(*, name: str | None = None) -> Any:
|
|
|
190
190
|
|
|
191
191
|
In watch mode, data may also be loaded from a corresponding exported field in play mode.
|
|
192
192
|
|
|
193
|
-
Imported fields may only be updated in the `preprocess`
|
|
193
|
+
Imported fields may only be updated in the [`preprocess`][sonolus.script.archetype.PlayArchetype.preprocess]
|
|
194
|
+
callback, and are read-only in other callbacks.
|
|
194
195
|
|
|
195
196
|
Usage:
|
|
196
197
|
```python
|
|
@@ -205,10 +206,12 @@ def imported(*, name: str | None = None) -> Any:
|
|
|
205
206
|
def entity_data() -> Any:
|
|
206
207
|
"""Declare a field as entity data.
|
|
207
208
|
|
|
208
|
-
Entity data is accessible from other entities, but may only be updated in the
|
|
209
|
+
Entity data is accessible from other entities, but may only be updated in the
|
|
210
|
+
[`preprocess`][sonolus.script.archetype.PlayArchetype.preprocess] callback
|
|
209
211
|
and is read-only in other callbacks.
|
|
210
212
|
|
|
211
|
-
It functions like `imported` and shares the same underlying storage,
|
|
213
|
+
It functions like [`imported`][sonolus.script.archetype.imported] and shares the same underlying storage,
|
|
214
|
+
except that it is not loaded from a level.
|
|
212
215
|
|
|
213
216
|
Usage:
|
|
214
217
|
```python
|
|
@@ -242,7 +245,8 @@ def entity_memory() -> Any:
|
|
|
242
245
|
Entity memory is private to the entity and is not accessible from other entities. It may be read or updated in any
|
|
243
246
|
callback associated with the entity.
|
|
244
247
|
|
|
245
|
-
Entity memory fields may also be set when an entity is spawned using the
|
|
248
|
+
Entity memory fields may also be set when an entity is spawned using the
|
|
249
|
+
[`spawn()`][sonolus.script.archetype.PlayArchetype.spawn] method.
|
|
246
250
|
|
|
247
251
|
Usage:
|
|
248
252
|
```python
|
|
@@ -260,7 +264,9 @@ def shared_memory() -> Any:
|
|
|
260
264
|
Shared memory is accessible from other entities.
|
|
261
265
|
|
|
262
266
|
Shared memory may be read in any callback, but may only be updated by sequential callbacks
|
|
263
|
-
(`preprocess
|
|
267
|
+
([`preprocess`][sonolus.script.archetype.PlayArchetype.preprocess],
|
|
268
|
+
[`update_sequential`][sonolus.script.archetype.PlayArchetype.update_sequential],
|
|
269
|
+
and [`touch`][sonolus.script.archetype.PlayArchetype.touch]).
|
|
264
270
|
|
|
265
271
|
Usage:
|
|
266
272
|
```python
|
|
@@ -688,7 +694,7 @@ class PlayArchetype(_BaseArchetype):
|
|
|
688
694
|
def spawn_order(self) -> float:
|
|
689
695
|
"""Return the spawn order of the entity.
|
|
690
696
|
|
|
691
|
-
Runs when the level is loaded after `preprocess
|
|
697
|
+
Runs when the level is loaded after [`preprocess`][sonolus.script.archetype.PlayArchetype.preprocess].
|
|
692
698
|
"""
|
|
693
699
|
|
|
694
700
|
def should_spawn(self) -> bool:
|
|
@@ -709,13 +715,15 @@ class PlayArchetype(_BaseArchetype):
|
|
|
709
715
|
Runs first each frame.
|
|
710
716
|
|
|
711
717
|
This is where logic affecting shared memory should be placed.
|
|
712
|
-
Other logic should be placed in
|
|
718
|
+
Other logic should typically be placed in
|
|
719
|
+
[`update_parallel`][sonolus.script.archetype.PlayArchetype.update_parallel]
|
|
720
|
+
for better performance.
|
|
713
721
|
"""
|
|
714
722
|
|
|
715
723
|
def update_parallel(self):
|
|
716
724
|
"""Perform parallel actions for this frame.
|
|
717
725
|
|
|
718
|
-
Runs after `touch` each frame.
|
|
726
|
+
Runs after [`touch`][sonolus.script.archetype.PlayArchetype.touch] each frame.
|
|
719
727
|
|
|
720
728
|
This is where most gameplay logic should be placed.
|
|
721
729
|
"""
|
|
@@ -723,7 +731,7 @@ class PlayArchetype(_BaseArchetype):
|
|
|
723
731
|
def touch(self):
|
|
724
732
|
"""Handle user input.
|
|
725
733
|
|
|
726
|
-
Runs after `update_sequential` each frame.
|
|
734
|
+
Runs after [`update_sequential`][sonolus.script.archetype.PlayArchetype.update_sequential] each frame.
|
|
727
735
|
"""
|
|
728
736
|
|
|
729
737
|
def terminate(self):
|
|
@@ -863,13 +871,14 @@ class WatchArchetype(_BaseArchetype):
|
|
|
863
871
|
Runs first each frame.
|
|
864
872
|
|
|
865
873
|
This is where logic affecting shared memory should be placed.
|
|
866
|
-
Other logic should be placed in
|
|
874
|
+
Other logic should typically be placed in
|
|
875
|
+
[`update_parallel`][sonolus.script.archetype.PlayArchetype.update_parallel] for better performance.
|
|
867
876
|
"""
|
|
868
877
|
|
|
869
878
|
def update_parallel(self):
|
|
870
879
|
"""Parallel update callback.
|
|
871
880
|
|
|
872
|
-
Runs after `touch` each frame.
|
|
881
|
+
Runs after [`touch`][sonolus.script.archetype.PlayArchetype.touch] each frame.
|
|
873
882
|
|
|
874
883
|
This is where most gameplay logic should be placed.
|
|
875
884
|
"""
|
|
@@ -1094,7 +1103,7 @@ class WatchEntityInput(Record):
|
|
|
1094
1103
|
class EntityRef[A: _BaseArchetype](Record):
|
|
1095
1104
|
"""Reference to another entity.
|
|
1096
1105
|
|
|
1097
|
-
May be used with `Any` to reference an unknown archetype.
|
|
1106
|
+
May be used with `typing.Any` to reference an unknown archetype.
|
|
1098
1107
|
|
|
1099
1108
|
Usage:
|
|
1100
1109
|
```python
|
sonolus/script/array.py
CHANGED
|
@@ -16,7 +16,7 @@ from sonolus.script.internal.value import BackingSource, DataValue, Value
|
|
|
16
16
|
from sonolus.script.num import Num
|
|
17
17
|
|
|
18
18
|
Dim = Literal
|
|
19
|
-
"""Shorthand for `Literal` intended for use in array dimensions for type checker compatibility."""
|
|
19
|
+
"""Shorthand for `typing.Literal` intended for use in array dimensions for type checker compatibility."""
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
class ArrayMeta(ABCMeta):
|
sonolus/script/containers.py
CHANGED
sonolus/script/easing.py
CHANGED
sonolus/script/effect.py
CHANGED
|
@@ -38,7 +38,8 @@ class Effect(Record):
|
|
|
38
38
|
def schedule(self, time: float, distance: float = 0) -> None:
|
|
39
39
|
"""Schedule the effect clip to play at a specific time.
|
|
40
40
|
|
|
41
|
-
This is not suitable for real-time effects such as responses to user input.
|
|
41
|
+
This is not suitable for real-time effects such as responses to user input.
|
|
42
|
+
Use [`play`][sonolus.script.effect.Effect.play] instead.
|
|
42
43
|
|
|
43
44
|
This may be called in preprocess to schedule effects upfront.
|
|
44
45
|
|
|
@@ -61,7 +62,8 @@ class Effect(Record):
|
|
|
61
62
|
def schedule_loop(self, start_time: float) -> ScheduledLoopedEffectHandle:
|
|
62
63
|
"""Schedule the effect clip to play in a loop until stopped.
|
|
63
64
|
|
|
64
|
-
This is not suitable for real-time effects such as responses to user input.
|
|
65
|
+
This is not suitable for real-time effects such as responses to user input.
|
|
66
|
+
Use [`loop`][sonolus.script.effect.Effect.loop] instead.
|
|
65
67
|
|
|
66
68
|
Returns:
|
|
67
69
|
A handle to stop the loop.
|
sonolus/script/globals.py
CHANGED
|
@@ -235,7 +235,10 @@ def _tutorial_instruction[T](cls: type[T]) -> T:
|
|
|
235
235
|
def level_memory[T](cls: type[T]) -> T:
|
|
236
236
|
"""Define level memory.
|
|
237
237
|
|
|
238
|
-
Level memory may be modified during gameplay in sequential callbacks
|
|
238
|
+
Level memory may be modified during gameplay in sequential callbacks
|
|
239
|
+
([`preprocess`][sonolus.script.archetype.PlayArchetype.preprocess],
|
|
240
|
+
[`update_sequential`][sonolus.script.archetype.PlayArchetype.update_sequential],
|
|
241
|
+
[`touch`][sonolus.script.archetype.PlayArchetype.touch]).
|
|
239
242
|
|
|
240
243
|
Usage:
|
|
241
244
|
```python
|
|
@@ -265,7 +268,7 @@ def level_memory[T](cls: type[T]) -> T:
|
|
|
265
268
|
def level_data[T](cls: type[T]) -> T:
|
|
266
269
|
"""Define level data.
|
|
267
270
|
|
|
268
|
-
Level data may only be modified during
|
|
271
|
+
Level data may only be modified during [`preprocess`][sonolus.script.archetype.PlayArchetype.preprocess].
|
|
269
272
|
|
|
270
273
|
Usage:
|
|
271
274
|
```python
|
|
@@ -61,10 +61,12 @@ class GlobalContextState:
|
|
|
61
61
|
class CallbackContextState:
|
|
62
62
|
callback: str
|
|
63
63
|
used_names: dict[str, int]
|
|
64
|
+
no_eval: bool
|
|
64
65
|
|
|
65
|
-
def __init__(self, callback: str):
|
|
66
|
+
def __init__(self, callback: str, no_eval: bool = False):
|
|
66
67
|
self.callback = callback
|
|
67
68
|
self.used_names = {}
|
|
69
|
+
self.no_eval = no_eval
|
|
68
70
|
|
|
69
71
|
|
|
70
72
|
class Context:
|
|
@@ -111,6 +113,10 @@ class Context:
|
|
|
111
113
|
def used_names(self) -> dict[str, int]:
|
|
112
114
|
return self.callback_state.used_names
|
|
113
115
|
|
|
116
|
+
@property
|
|
117
|
+
def no_eval(self) -> bool:
|
|
118
|
+
return self.callback_state.no_eval
|
|
119
|
+
|
|
114
120
|
def check_readable(self, place: BlockPlace):
|
|
115
121
|
if debug_config().unchecked_reads:
|
|
116
122
|
return
|
|
@@ -32,7 +32,7 @@ def native_function[**P, R](op: Op) -> Callable[[Callable[P, R]], Callable[P, R]
|
|
|
32
32
|
if ctx():
|
|
33
33
|
bound_args = signature.bind(*args)
|
|
34
34
|
bound_args.apply_defaults()
|
|
35
|
-
return native_call(op, *
|
|
35
|
+
return native_call(op, *bound_args.args)
|
|
36
36
|
return fn(*args) # type: ignore
|
|
37
37
|
|
|
38
38
|
return wrapper
|
sonolus/script/iterator.py
CHANGED
|
@@ -14,7 +14,8 @@ class SonolusIterator[T]:
|
|
|
14
14
|
|
|
15
15
|
This class is used to define custom iterators that can be used in Sonolus.py.
|
|
16
16
|
|
|
17
|
-
Inheritors must implement the `next` method,
|
|
17
|
+
Inheritors must implement the [`next`][sonolus.script.iterator.SonolusIterator.next] method,
|
|
18
|
+
which should return a [`Maybe[T]`][sonolus.script.maybe.Maybe].
|
|
18
19
|
|
|
19
20
|
Usage:
|
|
20
21
|
```python
|
|
@@ -28,6 +29,7 @@ class SonolusIterator[T]:
|
|
|
28
29
|
|
|
29
30
|
@meta_fn
|
|
30
31
|
def next(self) -> Maybe[T]:
|
|
32
|
+
"""Return the next item from the iterator as a [`Maybe`][sonolus.script.maybe.Maybe]."""
|
|
31
33
|
raise NotImplementedError
|
|
32
34
|
|
|
33
35
|
def __next__(self) -> T:
|
|
@@ -120,7 +122,7 @@ class _FilteringIterator[T, Fn](Record, SonolusIterator):
|
|
|
120
122
|
|
|
121
123
|
@meta_fn
|
|
122
124
|
def maybe_next[T](iterator: Iterator[T]) -> Maybe[T]:
|
|
123
|
-
"""Get the next item from an iterator as a `Maybe`
|
|
125
|
+
"""Get the next item from an iterator as a [`Maybe`][sonolus.script.maybe.Maybe]."""
|
|
124
126
|
from sonolus.backend.visitor import compile_and_call
|
|
125
127
|
|
|
126
128
|
if not isinstance(iterator, SonolusIterator):
|
sonolus/script/maybe.py
CHANGED
|
@@ -14,10 +14,11 @@ from sonolus.script.values import copy, zeros
|
|
|
14
14
|
class Maybe[T](TransientValue):
|
|
15
15
|
"""A type that either has a value or is empty.
|
|
16
16
|
|
|
17
|
-
Maybe has special behavior when returned from a function: it may be returned from
|
|
18
|
-
in a function, provided that all but one return statement returns the literal
|
|
17
|
+
`Maybe` has special behavior when returned from a function: unlike records and arrays, it may be returned from
|
|
18
|
+
multiple places in a function, provided that all but one return statement returns the literal
|
|
19
|
+
[`Nothing`][sonolus.script.maybe.Nothing].
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
Storing values of this type in a Record, Array, or Archetype is not supported.
|
|
21
22
|
|
|
22
23
|
Usage:
|
|
23
24
|
```python
|
|
@@ -73,28 +74,30 @@ class Maybe[T](TransientValue):
|
|
|
73
74
|
def map[R](self, fn: Callable[[T], R], /) -> Maybe[R]:
|
|
74
75
|
"""Map the contained value to a new value using the provided function.
|
|
75
76
|
|
|
76
|
-
If the value is not present, returns `Nothing
|
|
77
|
+
If the value is not present, returns [`Nothing`][sonolus.script.maybe.Nothing].
|
|
77
78
|
|
|
78
79
|
Args:
|
|
79
80
|
fn: A function that takes the contained value and returns a new value.
|
|
80
81
|
|
|
81
82
|
Returns:
|
|
82
|
-
A `Maybe` instance containing the result of the function if the value
|
|
83
|
+
A [`Maybe`][sonolus.script.maybe.Maybe] instance containing the result of the function if the value
|
|
84
|
+
is present, otherwise [`Nothing`][sonolus.script.maybe.Nothing].
|
|
83
85
|
"""
|
|
84
86
|
if self.is_some:
|
|
85
87
|
return Some(fn(self.get_unsafe()))
|
|
86
88
|
return Nothing
|
|
87
89
|
|
|
88
90
|
def flat_map[R](self, fn: Callable[[T], Maybe[R]], /) -> Maybe[R]:
|
|
89
|
-
"""Flat map the contained value to a new `Maybe` using the provided function.
|
|
91
|
+
"""Flat map the contained value to a new [`Maybe`][sonolus.script.maybe.Maybe] using the provided function.
|
|
90
92
|
|
|
91
|
-
If the value is not present, returns `Nothing
|
|
93
|
+
If the value is not present, returns [`Nothing`][sonolus.script.maybe.Nothing].
|
|
92
94
|
|
|
93
95
|
Args:
|
|
94
|
-
fn: A function that takes the contained value and returns a new `Maybe
|
|
96
|
+
fn: A function that takes the contained value and returns a new [`Maybe`][sonolus.script.maybe.Maybe].
|
|
95
97
|
|
|
96
98
|
Returns:
|
|
97
|
-
A `Maybe` instance containing the result of the function if the value
|
|
99
|
+
A [`Maybe`][sonolus.script.maybe.Maybe] instance containing the result of the function if the value
|
|
100
|
+
is present, otherwise [`Nothing`][sonolus.script.maybe.Nothing].
|
|
98
101
|
"""
|
|
99
102
|
if self.is_some:
|
|
100
103
|
return fn(self.get_unsafe())
|
|
@@ -216,13 +219,13 @@ class Maybe[T](TransientValue):
|
|
|
216
219
|
|
|
217
220
|
|
|
218
221
|
def Some[T](value: T) -> Maybe[T]: # noqa: N802
|
|
219
|
-
"""Create a `Maybe` instance with a value.
|
|
222
|
+
"""Create a [`Maybe`][sonolus.script.maybe.Maybe] instance with a value.
|
|
220
223
|
|
|
221
224
|
Args:
|
|
222
225
|
value: The contained value.
|
|
223
226
|
|
|
224
227
|
Returns:
|
|
225
|
-
A `Maybe` instance that contains the provided value.
|
|
228
|
+
A [`Maybe`][sonolus.script.maybe.Maybe] instance that contains the provided value.
|
|
226
229
|
"""
|
|
227
230
|
return Maybe(present=True, value=value)
|
|
228
231
|
|
|
@@ -231,7 +234,7 @@ Nothing: Maybe[Any] = Maybe(present=False, value=None) # type: ignore
|
|
|
231
234
|
|
|
232
235
|
# Note: has to come after the definition to hide the definition in the docs.
|
|
233
236
|
Nothing: Maybe[Any]
|
|
234
|
-
"""The empty `Maybe` instance."""
|
|
237
|
+
"""The empty [`Maybe`][sonolus.script.maybe.Maybe] instance."""
|
|
235
238
|
|
|
236
239
|
|
|
237
240
|
@meta_fn
|
sonolus/script/sprite.py
CHANGED
sonolus/script/stream.py
CHANGED
|
@@ -63,7 +63,8 @@ class _StreamDataField(SonolusDescriptor):
|
|
|
63
63
|
def streams[T](cls: type[T]) -> T:
|
|
64
64
|
"""Decorator to define streams and stream groups.
|
|
65
65
|
|
|
66
|
-
Streams and stream groups are declared by annotating class attributes with
|
|
66
|
+
Streams and stream groups are declared by annotating class attributes with
|
|
67
|
+
[`Stream`][sonolus.script.stream.Stream] or [`StreamGroup`][sonolus.script.stream.StreamGroup].
|
|
67
68
|
|
|
68
69
|
Other types are also supported in the form of data fields. They may be used to store additional data to export from
|
|
69
70
|
Play to Watch mode.
|
|
@@ -180,8 +181,8 @@ class _SparseStreamBacking(BackingValue):
|
|
|
180
181
|
class Stream[T](Record):
|
|
181
182
|
"""Represents a stream.
|
|
182
183
|
|
|
183
|
-
Most users should use [`@streams`][sonolus.script.stream.streams] to declare streams and stream groups rather than
|
|
184
|
-
|
|
184
|
+
Most users should use [`@streams`][sonolus.script.stream.streams] to declare streams and stream groups, rather than
|
|
185
|
+
creating instances of this class directly.
|
|
185
186
|
|
|
186
187
|
If used directly, it is important that streams do not overlap. No other streams should have an offset in
|
|
187
188
|
`range(self.offset, self.offset + max(1, sizeof(self.element_type())))`, or they will overlap and interfere
|
|
@@ -285,12 +286,12 @@ class Stream[T](Record):
|
|
|
285
286
|
return previous_key < key
|
|
286
287
|
|
|
287
288
|
def next_key_inclusive(self, key: int | float) -> int | float:
|
|
288
|
-
"""Like `next_key
|
|
289
|
+
"""Like [`next_key`][sonolus.script.stream.Stream.next_key], but returns the key itself if it is in the stream."""
|
|
289
290
|
_check_can_read_stream()
|
|
290
291
|
return key if key in self else self.next_key(key)
|
|
291
292
|
|
|
292
293
|
def previous_key_inclusive(self, key: int | float) -> int | float:
|
|
293
|
-
"""Like `previous_key
|
|
294
|
+
"""Like [`previous_key`][sonolus.script.stream.Stream.previous_key], but returns the key itself if it is in the stream."""
|
|
294
295
|
_check_can_read_stream()
|
|
295
296
|
return key if key in self else self.previous_key(key)
|
|
296
297
|
|
|
@@ -10,8 +10,8 @@ sonolus/backend/mode.py,sha256=NkcPZJm8dn83LX35uP24MtQOCnfRDFZ280dHeEEfauE,613
|
|
|
10
10
|
sonolus/backend/node.py,sha256=eEzPP14jzWJp2xrZCAaPlNtokxdoqg0bSM7xQiwx1j8,1254
|
|
11
11
|
sonolus/backend/ops.py,sha256=5weB_vIxbkwCSJuzYZyKUk7vVXsSIEDJYRlvE-2ke8A,10572
|
|
12
12
|
sonolus/backend/place.py,sha256=7qwV732hZ4WP-9GNN8FQSEKssPJZELip1wLXTWfop7Y,4717
|
|
13
|
-
sonolus/backend/utils.py,sha256=
|
|
14
|
-
sonolus/backend/visitor.py,sha256=
|
|
13
|
+
sonolus/backend/utils.py,sha256=DDgYUVHh4h_eSY65v2KcxUaLSBYGYS6oHar5gTdV7QU,2356
|
|
14
|
+
sonolus/backend/visitor.py,sha256=6QjQ9tYOCP2a8-8WPgm8EB-hzwV5pcwLap3eDDrFG8I,62364
|
|
15
15
|
sonolus/backend/optimize/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
16
|
sonolus/backend/optimize/allocate.py,sha256=CuumoMphkpQlGRNeKLHT4FBGE0XVj5pwhfNdrqiLFSs,7535
|
|
17
17
|
sonolus/backend/optimize/constant_evaluation.py,sha256=OyjlgHIT6oPKCyBtNzEpo1nWYjr-_mwYUo8FrNV4eO4,21331
|
|
@@ -26,29 +26,29 @@ sonolus/backend/optimize/passes.py,sha256=YyFKy6qCwcR_Ua2_SXpcBODfvBbm_ygVYcqloO
|
|
|
26
26
|
sonolus/backend/optimize/simplify.py,sha256=RDNVTKfC7ByRyxY5z30_ShimOAKth_pKlVFV_36pDG4,14082
|
|
27
27
|
sonolus/backend/optimize/ssa.py,sha256=raQO0furQQRPYb8iIBKfNrJlj-_5wqtI4EWNfLZ8QFo,10834
|
|
28
28
|
sonolus/build/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
|
-
sonolus/build/cli.py,sha256
|
|
29
|
+
sonolus/build/cli.py,sha256=-_lTN8zT7nQB2lySM8itAEPVutcEQI-TJ13BcPIfGb4,10113
|
|
30
30
|
sonolus/build/collection.py,sha256=kOVnpQC_KHAsyTM4nAplSh6QE16CgO-H6PP1GItWm78,12187
|
|
31
|
-
sonolus/build/compile.py,sha256=
|
|
31
|
+
sonolus/build/compile.py,sha256=B7w6Uqa4HlZPNklNhhjJoq9ncXMVXLCYabGLxtxWGV4,6521
|
|
32
32
|
sonolus/build/engine.py,sha256=zUl0KfRygqNhIM8BABNJkKG-0zXFwcYwck-5hJy59yk,13338
|
|
33
33
|
sonolus/build/level.py,sha256=yXsQtnabkJK0vuVmZ_Wr1jx37jFLgInCS7lTlXjkv9Q,706
|
|
34
34
|
sonolus/build/node.py,sha256=gnX71RYDUOK_gYMpinQi-bLWO4csqcfiG5gFmhxzSec,1330
|
|
35
35
|
sonolus/build/project.py,sha256=mv2OuzgIDG-E9G4SIRiUDL5XiPCd1i81wVl1p7itFHA,6329
|
|
36
36
|
sonolus/script/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
37
|
-
sonolus/script/archetype.py,sha256=
|
|
38
|
-
sonolus/script/array.py,sha256=
|
|
37
|
+
sonolus/script/archetype.py,sha256=HJeKJ_vj7xUYaCAmNdGYO45rhFMSLMwOLyvpKjulfVY,42418
|
|
38
|
+
sonolus/script/array.py,sha256=9uOUHZIDMyMT9q3APcXJWXWt97yG-AZoRlxwrvSY6SU,12367
|
|
39
39
|
sonolus/script/array_like.py,sha256=jFOfXkniTLrIK4ER6HO_tUyKn_TvwjyM4B3SDd9cUS8,9678
|
|
40
40
|
sonolus/script/bucket.py,sha256=5VU-Bh7qYifl6NcgZFCo7eAEgi3iGTX-PUTmXiPCJaQ,7535
|
|
41
|
-
sonolus/script/containers.py,sha256=
|
|
41
|
+
sonolus/script/containers.py,sha256=WX0qRnr6gNtn3C0q7MwMyrzvY-C0Bd1tzLGxSkUwL9U,18680
|
|
42
42
|
sonolus/script/debug.py,sha256=_Hg1cXQJ8fBXMiwhmoPb2X9CKcQ8QO26WNa59K518og,4305
|
|
43
|
-
sonolus/script/easing.py,sha256=
|
|
44
|
-
sonolus/script/effect.py,sha256=
|
|
43
|
+
sonolus/script/easing.py,sha256=txf0OPFP5v7cOFDvJKCyKLK-d2uKIOu56ntLEHfD9QI,11377
|
|
44
|
+
sonolus/script/effect.py,sha256=mhl58IgHUl7GI6kDdwK6l_KWVXYWxxpAcfOjSkdrLj4,5944
|
|
45
45
|
sonolus/script/engine.py,sha256=etI9dJsQ7V9YZICVNZg54WqpLijPxG8eTPHiV-_EiG8,10687
|
|
46
|
-
sonolus/script/globals.py,sha256=
|
|
46
|
+
sonolus/script/globals.py,sha256=USwh_TuyZh1qORPVLk6x9qe3ca9iLhf5gnqT773gVvY,10007
|
|
47
47
|
sonolus/script/instruction.py,sha256=iBjY7nCNDT3w0SBJKlix3Z-85e7eE2qKeHp6C2Nq7KA,6753
|
|
48
48
|
sonolus/script/interval.py,sha256=dj6F2wn5uP6I6_mcZn-wIREgRUQbsLzhvhzB0oEyAdU,11290
|
|
49
|
-
sonolus/script/iterator.py,sha256=
|
|
49
|
+
sonolus/script/iterator.py,sha256=_ICY_yX7FG0Zbgs3NhVnaIBdVDpAeXjxJ_CQtq30l7Y,3774
|
|
50
50
|
sonolus/script/level.py,sha256=vnotMbdr_4-MJUsTXMbvWiw2MlMjMHme3q0XRdNFXRg,6349
|
|
51
|
-
sonolus/script/maybe.py,sha256=
|
|
51
|
+
sonolus/script/maybe.py,sha256=VYvTWgEfPzoXqI3i3zXhc4dz0pWBVoHmW8FtWH0GQvM,8194
|
|
52
52
|
sonolus/script/metadata.py,sha256=ttRK27eojHf3So50KQJ-8yj3udZoN1bli5iD-knaeLw,753
|
|
53
53
|
sonolus/script/num.py,sha256=924kWWZusW7oaWuvtQzdAMzkb4ZItWSJwNj3W9XrqZU,16041
|
|
54
54
|
sonolus/script/options.py,sha256=KlOud4QOf_lW1o6avKXbkjcMCDPkhLcEwt5PW7ZCH3s,9435
|
|
@@ -59,8 +59,8 @@ sonolus/script/project.py,sha256=2XVUXcW49iiTfljvcFuYqtFzqhQIRvD7H7OwH1Mm98w,400
|
|
|
59
59
|
sonolus/script/quad.py,sha256=XoAjaUqR60zIrC_CwheZs7HwS-DRS58yUmlj9GIjX7k,11179
|
|
60
60
|
sonolus/script/record.py,sha256=-Ff60wBoF1v4-MJWzCNI9n5K3os6WphswZpdTBezeRs,12713
|
|
61
61
|
sonolus/script/runtime.py,sha256=rJZM_KbKmnwpjhDEpR0DrM6EMSEu46apIErWA_pfLJA,33321
|
|
62
|
-
sonolus/script/sprite.py,sha256=
|
|
63
|
-
sonolus/script/stream.py,sha256=
|
|
62
|
+
sonolus/script/sprite.py,sha256=pgFQvzWB-uy9MsOfV8QabXKjnNgx5vN6md9uNYztHco,16297
|
|
63
|
+
sonolus/script/stream.py,sha256=q3uJUfUP9fx0Go7qXQopl9DMh_RJkT-96p5WlAo4x0M,24693
|
|
64
64
|
sonolus/script/text.py,sha256=wxujIgKYcCfl2AD2_Im8g3vh0lDEHYwTSRZg9wsBPEU,13402
|
|
65
65
|
sonolus/script/timing.py,sha256=ZR0ypV2PIoDCMHHGOMfCeezStCsBQdzomdqaz5VKex0,2981
|
|
66
66
|
sonolus/script/transform.py,sha256=w5mr7hTuNYU0eTAdnN_wTVibaQa0mZrkl-W-kgewJxQ,21345
|
|
@@ -71,7 +71,7 @@ sonolus/script/internal/__init__.py,sha256=T6rzLoiOUaiSQtaHMZ88SNO-ijSjSSv33TKtU
|
|
|
71
71
|
sonolus/script/internal/builtin_impls.py,sha256=vzyaSTsxoZoE6a-aBBHn4aIfjGxxYzojEnOog3-HETI,12686
|
|
72
72
|
sonolus/script/internal/callbacks.py,sha256=vWzJG8uiJoEtsNnbeZPqOHogCwoLpz2D1MnHY2wVV8s,2801
|
|
73
73
|
sonolus/script/internal/constant.py,sha256=3ycbGkDJVUwcrCZ96vLjAoAARgsvaqDM8rJ_YCrLrvo,4289
|
|
74
|
-
sonolus/script/internal/context.py,sha256=
|
|
74
|
+
sonolus/script/internal/context.py,sha256=qn8xp5BB1C3IaUS8jsSUfkMUJgPzeaIV7K4FY9mHHQo,16903
|
|
75
75
|
sonolus/script/internal/descriptor.py,sha256=XRFey-EjiAm_--KsNl-8N0Mi_iyQwlPh68gDp0pKf3E,392
|
|
76
76
|
sonolus/script/internal/dict_impl.py,sha256=alu_wKGSk1kZajNf64qbe7t71shEzD4N5xNIATH8Swo,1885
|
|
77
77
|
sonolus/script/internal/error.py,sha256=ZNnsvQVQAnFKzcvsm6-sste2lo-tP5pPI8sD7XlAZWc,490
|
|
@@ -79,15 +79,15 @@ sonolus/script/internal/generic.py,sha256=F0-cCiRNGTaUJvYlpmkiOsU3Xge_XjoBpBwBhH
|
|
|
79
79
|
sonolus/script/internal/impl.py,sha256=I3IlPZZZtXVJb044cpULg5FDYUjiLtAucnsA6w_0xUk,3233
|
|
80
80
|
sonolus/script/internal/introspection.py,sha256=MfdXo3GFHNZT2-vAKuvsE54V-5TOfbg4vU9dBI6sLqo,1032
|
|
81
81
|
sonolus/script/internal/math_impls.py,sha256=nHSLgA7Tcx7jY1p07mYBCeSRmVx713bwdNayCIcaXSE,2652
|
|
82
|
-
sonolus/script/internal/native.py,sha256=
|
|
82
|
+
sonolus/script/internal/native.py,sha256=DQxmzxgLG_UsLpXhIEtBdO7eIeDFprU78UBDC4OZzw0,1597
|
|
83
83
|
sonolus/script/internal/random.py,sha256=6Ku5edRcDUh7rtqEEYCJz0BQavw69RALsVHS25z50pI,1695
|
|
84
84
|
sonolus/script/internal/range.py,sha256=YeqB1TPh7JdvW6kDuA5tpQL5psVxYQjepBZs7RNcP5Y,3426
|
|
85
85
|
sonolus/script/internal/simulation_context.py,sha256=LGxLTvxbqBIhoe1R-SfwGajNIDwIJMVsHle0kvzd500,4818
|
|
86
86
|
sonolus/script/internal/transient.py,sha256=y2AWABqF1aoaP6H4_2u4MMpNioC4OsZQCtPyNI0txqo,1634
|
|
87
87
|
sonolus/script/internal/tuple_impl.py,sha256=DPNdmmRmupU8Ah4_XKq6-PdT336l4nt15_uCJKQGkkk,3587
|
|
88
88
|
sonolus/script/internal/value.py,sha256=OngrCdmY_h6mV2Zgwqhuo4eYFad0kTk6263UAxctZcY,6963
|
|
89
|
-
sonolus_py-0.4.
|
|
90
|
-
sonolus_py-0.4.
|
|
91
|
-
sonolus_py-0.4.
|
|
92
|
-
sonolus_py-0.4.
|
|
93
|
-
sonolus_py-0.4.
|
|
89
|
+
sonolus_py-0.4.2.dist-info/METADATA,sha256=rV2d-Y0jxrhlOQfcrYRAVAKiuobluI5omhDztt5mmLo,302
|
|
90
|
+
sonolus_py-0.4.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
91
|
+
sonolus_py-0.4.2.dist-info/entry_points.txt,sha256=oTYspY_b7SA8TptEMTDxh4-Aj-ZVPnYC9f1lqH6s9G4,54
|
|
92
|
+
sonolus_py-0.4.2.dist-info/licenses/LICENSE,sha256=JEKpqVhQYfEc7zg3Mj462sKbKYmO1K7WmvX1qvg9IJk,1067
|
|
93
|
+
sonolus_py-0.4.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|