sonolus.py 0.1.3__py3-none-any.whl → 0.1.5__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.

Files changed (90) hide show
  1. sonolus/backend/blocks.py +756 -756
  2. sonolus/backend/excepthook.py +37 -37
  3. sonolus/backend/finalize.py +77 -69
  4. sonolus/backend/interpret.py +7 -7
  5. sonolus/backend/ir.py +29 -3
  6. sonolus/backend/mode.py +24 -24
  7. sonolus/backend/node.py +40 -40
  8. sonolus/backend/ops.py +197 -197
  9. sonolus/backend/optimize/__init__.py +0 -0
  10. sonolus/backend/optimize/allocate.py +126 -0
  11. sonolus/backend/optimize/constant_evaluation.py +374 -0
  12. sonolus/backend/optimize/copy_coalesce.py +85 -0
  13. sonolus/backend/optimize/dead_code.py +185 -0
  14. sonolus/backend/optimize/dominance.py +96 -0
  15. sonolus/backend/{flow.py → optimize/flow.py} +122 -92
  16. sonolus/backend/optimize/inlining.py +137 -0
  17. sonolus/backend/optimize/liveness.py +177 -0
  18. sonolus/backend/optimize/optimize.py +44 -0
  19. sonolus/backend/optimize/passes.py +52 -0
  20. sonolus/backend/optimize/simplify.py +191 -0
  21. sonolus/backend/optimize/ssa.py +200 -0
  22. sonolus/backend/place.py +17 -25
  23. sonolus/backend/utils.py +58 -48
  24. sonolus/backend/visitor.py +1151 -882
  25. sonolus/build/cli.py +7 -1
  26. sonolus/build/compile.py +88 -90
  27. sonolus/build/engine.py +10 -5
  28. sonolus/build/level.py +24 -23
  29. sonolus/build/node.py +43 -43
  30. sonolus/script/archetype.py +438 -139
  31. sonolus/script/array.py +27 -10
  32. sonolus/script/array_like.py +297 -0
  33. sonolus/script/bucket.py +253 -191
  34. sonolus/script/containers.py +257 -51
  35. sonolus/script/debug.py +26 -10
  36. sonolus/script/easing.py +365 -0
  37. sonolus/script/effect.py +191 -131
  38. sonolus/script/engine.py +71 -4
  39. sonolus/script/globals.py +303 -269
  40. sonolus/script/instruction.py +205 -151
  41. sonolus/script/internal/__init__.py +5 -5
  42. sonolus/script/internal/builtin_impls.py +255 -144
  43. sonolus/script/{callbacks.py → internal/callbacks.py} +127 -127
  44. sonolus/script/internal/constant.py +139 -0
  45. sonolus/script/internal/context.py +26 -9
  46. sonolus/script/internal/descriptor.py +17 -17
  47. sonolus/script/internal/dict_impl.py +65 -0
  48. sonolus/script/internal/generic.py +6 -9
  49. sonolus/script/internal/impl.py +38 -13
  50. sonolus/script/internal/introspection.py +17 -14
  51. sonolus/script/internal/math_impls.py +121 -0
  52. sonolus/script/internal/native.py +40 -38
  53. sonolus/script/internal/random.py +67 -0
  54. sonolus/script/internal/range.py +81 -0
  55. sonolus/script/internal/transient.py +51 -0
  56. sonolus/script/internal/tuple_impl.py +113 -0
  57. sonolus/script/internal/value.py +3 -3
  58. sonolus/script/interval.py +338 -112
  59. sonolus/script/iterator.py +167 -214
  60. sonolus/script/level.py +24 -0
  61. sonolus/script/num.py +80 -48
  62. sonolus/script/options.py +257 -191
  63. sonolus/script/particle.py +190 -157
  64. sonolus/script/pointer.py +30 -30
  65. sonolus/script/print.py +102 -81
  66. sonolus/script/project.py +8 -0
  67. sonolus/script/quad.py +263 -0
  68. sonolus/script/record.py +47 -16
  69. sonolus/script/runtime.py +52 -1
  70. sonolus/script/sprite.py +418 -333
  71. sonolus/script/text.py +409 -407
  72. sonolus/script/timing.py +114 -42
  73. sonolus/script/transform.py +332 -48
  74. sonolus/script/ui.py +216 -160
  75. sonolus/script/values.py +6 -13
  76. sonolus/script/vec.py +196 -78
  77. {sonolus_py-0.1.3.dist-info → sonolus_py-0.1.5.dist-info}/METADATA +1 -1
  78. sonolus_py-0.1.5.dist-info/RECORD +89 -0
  79. {sonolus_py-0.1.3.dist-info → sonolus_py-0.1.5.dist-info}/WHEEL +1 -1
  80. {sonolus_py-0.1.3.dist-info → sonolus_py-0.1.5.dist-info}/licenses/LICENSE +21 -21
  81. sonolus/backend/allocate.py +0 -51
  82. sonolus/backend/optimize.py +0 -9
  83. sonolus/backend/passes.py +0 -6
  84. sonolus/backend/simplify.py +0 -30
  85. sonolus/script/comptime.py +0 -160
  86. sonolus/script/graphics.py +0 -150
  87. sonolus/script/math.py +0 -92
  88. sonolus/script/range.py +0 -58
  89. sonolus_py-0.1.3.dist-info/RECORD +0 -75
  90. {sonolus_py-0.1.3.dist-info → sonolus_py-0.1.5.dist-info}/entry_points.txt +0 -0
@@ -1,151 +1,205 @@
1
- from dataclasses import dataclass
2
- from typing import Annotated, Any, NewType, dataclass_transform, get_origin
3
-
4
- from sonolus.backend.ops import Op
5
- from sonolus.script.internal.introspection import get_field_specifiers
6
- from sonolus.script.internal.native import native_function
7
- from sonolus.script.record import Record
8
- from sonolus.script.runtime import _TutorialInstruction
9
- from sonolus.script.text import StandardText
10
- from sonolus.script.vec import Vec2
11
-
12
-
13
- class InstructionText(Record):
14
- id: int
15
-
16
- def show(self):
17
- show_instruction(self)
18
-
19
-
20
- class InstructionIcon(Record):
21
- id: int
22
-
23
- def paint(self, position: Vec2, size: float, rotation: float, z: float, a: float):
24
- _paint(self.id, position.x, position.y, size, rotation, z, a)
25
-
26
-
27
- @dataclass
28
- class InstructionTextInfo:
29
- name: str
30
-
31
-
32
- @dataclass
33
- class InstructionIconInfo:
34
- name: str
35
-
36
-
37
- def instruction(name: str) -> Any:
38
- return InstructionTextInfo(name=name)
39
-
40
-
41
- def instruction_icon(name: str) -> Any:
42
- return InstructionIconInfo(name=name)
43
-
44
-
45
- type TutorialInstructions = NewType("TutorialInstructions", Any)
46
- type TutorialInstructionIcons = NewType("TutorialInstructionIcons", Any)
47
-
48
-
49
- @dataclass_transform()
50
- def instructions[T](cls: type[T]) -> T | TutorialInstructions:
51
- if len(cls.__bases__) != 1:
52
- raise ValueError("Instructions class must not inherit from any class (except object)")
53
- instance = cls()
54
- names = []
55
- for i, (name, annotation) in enumerate(get_field_specifiers(cls).items()):
56
- if get_origin(annotation) is not Annotated:
57
- raise TypeError(f"Invalid annotation for instruction: {annotation}")
58
- annotation_type = annotation.__args__[0]
59
- annotation_values = annotation.__metadata__
60
- if annotation_type is not InstructionText:
61
- raise TypeError(
62
- f"Invalid annotation for instruction: {annotation}, expected annotation of type InstructionText"
63
- )
64
- if len(annotation_values) != 1 or not isinstance(annotation_values[0], InstructionTextInfo):
65
- raise TypeError(f"Invalid annotation for instruction: {annotation}, expected a single annotation value")
66
- instruction_name = annotation_values[0].name
67
- names.append(instruction_name)
68
- setattr(instance, name, InstructionText(i))
69
- instance._instructions_ = names
70
- instance._is_comptime_value_ = True
71
- return instance
72
-
73
-
74
- @dataclass_transform()
75
- def instruction_icons[T](cls: type[T]) -> T | TutorialInstructionIcons:
76
- if len(cls.__bases__) != 1:
77
- raise ValueError("Instruction icons class must not inherit from any class (except object)")
78
- instance = cls()
79
- names = []
80
- for i, (name, annotation) in enumerate(get_field_specifiers(cls).items()):
81
- if get_origin(annotation) is not Annotated:
82
- raise TypeError(f"Invalid annotation for instruction icon: {annotation}")
83
- annotation_type = annotation.__args__[0]
84
- annotation_values = annotation.__metadata__
85
- if annotation_type is not InstructionIcon:
86
- raise TypeError(
87
- f"Invalid annotation for instruction icon: {annotation}, expected annotation of type InstructionIcon"
88
- )
89
- if len(annotation_values) != 1 or not isinstance(annotation_values[0], InstructionIconInfo):
90
- raise TypeError(
91
- f"Invalid annotation for instruction icon: {annotation}, expected a single annotation value"
92
- )
93
- icon_name = annotation_values[0].name
94
- names.append(icon_name)
95
- setattr(instance, name, InstructionIcon(i))
96
- instance._instruction_icons_ = names
97
- instance._is_comptime_value_ = True
98
- return instance
99
-
100
-
101
- class StandardInstruction:
102
- TAP = Annotated[InstructionText, instruction(StandardText.TAP)]
103
- TAP_HOLD = Annotated[InstructionText, instruction(StandardText.TAP_HOLD)]
104
- TAP_RELEASE = Annotated[InstructionText, instruction(StandardText.TAP_RELEASE)]
105
- TAP_FLICK = Annotated[InstructionText, instruction(StandardText.TAP_FLICK)]
106
- TAP_SLIDE = Annotated[InstructionText, instruction(StandardText.TAP_SLIDE)]
107
- HOLD = Annotated[InstructionText, instruction(StandardText.HOLD)]
108
- HOLD_SLIDE = Annotated[InstructionText, instruction(StandardText.HOLD_SLIDE)]
109
- HOLD_FOLLOW = Annotated[InstructionText, instruction(StandardText.HOLD_FOLLOW)]
110
- RELEASE = Annotated[InstructionText, instruction(StandardText.RELEASE)]
111
- FLICK = Annotated[InstructionText, instruction(StandardText.FLICK)]
112
- SLIDE = Annotated[InstructionText, instruction(StandardText.SLIDE)]
113
- SLIDE_FLICK = Annotated[InstructionText, instruction(StandardText.SLIDE_FLICK)]
114
- AVOID = Annotated[InstructionText, instruction(StandardText.AVOID)]
115
- JIGGLE = Annotated[InstructionText, instruction(StandardText.JIGGLE)]
116
-
117
-
118
- class StandardInstructionIcon:
119
- HAND = Annotated[InstructionIcon, instruction_icon("#HAND")]
120
- ARROW = Annotated[InstructionIcon, instruction_icon("#ARROW")]
121
-
122
-
123
- @instructions
124
- class EmptyInstructions:
125
- pass
126
-
127
-
128
- @instruction_icons
129
- class EmptyInstructionIcons:
130
- pass
131
-
132
-
133
- @native_function(Op.Paint)
134
- def _paint(
135
- icon_id: int,
136
- x: float,
137
- y: float,
138
- size: float,
139
- rotation: float,
140
- z: float,
141
- a: float,
142
- ):
143
- raise NotImplementedError()
144
-
145
-
146
- def show_instruction(inst: InstructionText, /):
147
- _TutorialInstruction.text_id = inst.id
148
-
149
-
150
- def clear_instruction():
151
- _TutorialInstruction.text_id = -1
1
+ from dataclasses import dataclass
2
+ from typing import Annotated, Any, NewType, dataclass_transform, get_origin
3
+
4
+ from sonolus.backend.ops import Op
5
+ from sonolus.script.internal.introspection import get_field_specifiers
6
+ from sonolus.script.internal.native import native_function
7
+ from sonolus.script.record import Record
8
+ from sonolus.script.runtime import _TutorialInstruction
9
+ from sonolus.script.text import StandardText
10
+ from sonolus.script.vec import Vec2
11
+
12
+
13
+ class Instruction(Record):
14
+ """Tutorial instruction text.
15
+
16
+ Usage:
17
+ ```python
18
+ Instruction(id: int)
19
+ ```
20
+ """
21
+
22
+ id: int
23
+
24
+ def show(self):
25
+ """Show this instruction text."""
26
+ show_instruction(self)
27
+
28
+
29
+ class InstructionIcon(Record):
30
+ """Tutorial instruction icon.
31
+
32
+ Usage:
33
+ ```python
34
+ InstructionIcon(id: int)
35
+ ```
36
+ """
37
+
38
+ id: int
39
+
40
+ def paint(self, position: Vec2, size: float, rotation: float, z: float, a: float):
41
+ """Paint this instruction icon.
42
+
43
+ Args:
44
+ position: The position of the icon.
45
+ size: The size of the icon.
46
+ rotation: The rotation of the icon.
47
+ z: The z-index of the icon.
48
+ a: The alpha of the icon.
49
+ """
50
+ _paint(self.id, position.x, position.y, size, rotation, z, a)
51
+
52
+
53
+ @dataclass
54
+ class _InstructionTextInfo:
55
+ name: str
56
+
57
+
58
+ @dataclass
59
+ class _InstructionIconInfo:
60
+ name: str
61
+
62
+
63
+ def instruction(name: str) -> Any:
64
+ """Define an instruction with the given name."""
65
+ return _InstructionTextInfo(name=name)
66
+
67
+
68
+ def instruction_icon(name: str) -> Any:
69
+ """Define an instruction icon with the given name."""
70
+ return _InstructionIconInfo(name=name)
71
+
72
+
73
+ type TutorialInstructions = NewType("TutorialInstructions", Any)
74
+ type TutorialInstructionIcons = NewType("TutorialInstructionIcons", Any)
75
+
76
+
77
+ @dataclass_transform()
78
+ def instructions[T](cls: type[T]) -> T | TutorialInstructions:
79
+ """Decorator to define tutorial instructions.
80
+
81
+ Usage:
82
+ ```python
83
+ @instructions
84
+ class Instructions:
85
+ tap: StandardInstruction.TAP
86
+ other_instruction: InstructionText = instruction("Other Instruction")
87
+ ```
88
+ """
89
+ if len(cls.__bases__) != 1:
90
+ raise ValueError("Instructions class must not inherit from any class (except object)")
91
+ instance = cls()
92
+ names = []
93
+ for i, (name, annotation) in enumerate(get_field_specifiers(cls).items()):
94
+ if get_origin(annotation) is not Annotated:
95
+ raise TypeError(f"Invalid annotation for instruction: {annotation}")
96
+ annotation_type = annotation.__args__[0]
97
+ annotation_values = annotation.__metadata__
98
+ if annotation_type is not Instruction:
99
+ raise TypeError(
100
+ f"Invalid annotation for instruction: {annotation}, expected annotation of type InstructionText"
101
+ )
102
+ if len(annotation_values) != 1 or not isinstance(annotation_values[0], _InstructionTextInfo):
103
+ raise TypeError(f"Invalid annotation for instruction: {annotation}, expected a single annotation value")
104
+ instruction_name = annotation_values[0].name
105
+ names.append(instruction_name)
106
+ setattr(instance, name, Instruction(i))
107
+ instance._instructions_ = names
108
+ instance._is_comptime_value_ = True
109
+ return instance
110
+
111
+
112
+ @dataclass_transform()
113
+ def instruction_icons[T](cls: type[T]) -> T | TutorialInstructionIcons:
114
+ """Decorator to define tutorial instruction icons.
115
+
116
+ Usage:
117
+ ```python
118
+ @instruction_icons
119
+ class InstructionIcons:
120
+ hand: StandardInstructionIcon.HAND
121
+ other_icon: InstructionIcon = instruction_icon("Other Icon")
122
+ ```
123
+ """
124
+ if len(cls.__bases__) != 1:
125
+ raise ValueError("Instruction icons class must not inherit from any class (except object)")
126
+ instance = cls()
127
+ names = []
128
+ for i, (name, annotation) in enumerate(get_field_specifiers(cls).items()):
129
+ if get_origin(annotation) is not Annotated:
130
+ raise TypeError(f"Invalid annotation for instruction icon: {annotation}")
131
+ annotation_type = annotation.__args__[0]
132
+ annotation_values = annotation.__metadata__
133
+ if annotation_type is not InstructionIcon:
134
+ raise TypeError(
135
+ f"Invalid annotation for instruction icon: {annotation}, expected annotation of type InstructionIcon"
136
+ )
137
+ if len(annotation_values) != 1 or not isinstance(annotation_values[0], _InstructionIconInfo):
138
+ raise TypeError(
139
+ f"Invalid annotation for instruction icon: {annotation}, expected a single annotation value"
140
+ )
141
+ icon_name = annotation_values[0].name
142
+ names.append(icon_name)
143
+ setattr(instance, name, InstructionIcon(i))
144
+ instance._instruction_icons_ = names
145
+ instance._is_comptime_value_ = True
146
+ return instance
147
+
148
+
149
+ class StandardInstruction:
150
+ """Standard instructions."""
151
+
152
+ TAP = Annotated[Instruction, instruction(StandardText.TAP)]
153
+ TAP_HOLD = Annotated[Instruction, instruction(StandardText.TAP_HOLD)]
154
+ TAP_RELEASE = Annotated[Instruction, instruction(StandardText.TAP_RELEASE)]
155
+ TAP_FLICK = Annotated[Instruction, instruction(StandardText.TAP_FLICK)]
156
+ TAP_SLIDE = Annotated[Instruction, instruction(StandardText.TAP_SLIDE)]
157
+ HOLD = Annotated[Instruction, instruction(StandardText.HOLD)]
158
+ HOLD_SLIDE = Annotated[Instruction, instruction(StandardText.HOLD_SLIDE)]
159
+ HOLD_FOLLOW = Annotated[Instruction, instruction(StandardText.HOLD_FOLLOW)]
160
+ RELEASE = Annotated[Instruction, instruction(StandardText.RELEASE)]
161
+ FLICK = Annotated[Instruction, instruction(StandardText.FLICK)]
162
+ SLIDE = Annotated[Instruction, instruction(StandardText.SLIDE)]
163
+ SLIDE_FLICK = Annotated[Instruction, instruction(StandardText.SLIDE_FLICK)]
164
+ AVOID = Annotated[Instruction, instruction(StandardText.AVOID)]
165
+ JIGGLE = Annotated[Instruction, instruction(StandardText.JIGGLE)]
166
+
167
+
168
+ class StandardInstructionIcon:
169
+ """Standard instruction icons."""
170
+
171
+ HAND = Annotated[InstructionIcon, instruction_icon("#HAND")]
172
+ ARROW = Annotated[InstructionIcon, instruction_icon("#ARROW")]
173
+
174
+
175
+ @instructions
176
+ class EmptyInstructions:
177
+ pass
178
+
179
+
180
+ @instruction_icons
181
+ class EmptyInstructionIcons:
182
+ pass
183
+
184
+
185
+ @native_function(Op.Paint)
186
+ def _paint(
187
+ icon_id: int,
188
+ x: float,
189
+ y: float,
190
+ size: float,
191
+ rotation: float,
192
+ z: float,
193
+ a: float,
194
+ ) -> None:
195
+ raise NotImplementedError()
196
+
197
+
198
+ def show_instruction(inst: Instruction, /):
199
+ """Show the given instruction text."""
200
+ _TutorialInstruction.text_id = inst.id
201
+
202
+
203
+ def clear_instruction():
204
+ """Clear the current instruction text."""
205
+ _TutorialInstruction.text_id = -1
@@ -1,5 +1,5 @@
1
- """Internal scripting details.
2
-
3
- These are internal details of scripting which typically should not be used directly
4
- in engine code.
5
- """
1
+ """Internal scripting details.
2
+
3
+ These are internal details of scripting which typically should not be used directly
4
+ in engine code.
5
+ """