spork-runtime 0.1.0__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.
- spork/runtime/__init__.py +400 -0
- spork/runtime/core.py +1621 -0
- spork/runtime/json.py +344 -0
- spork/runtime/ns.py +607 -0
- spork/runtime/testing.py +50 -0
- spork/runtime/types.py +357 -0
- spork/runtime/utils.py +601 -0
- spork/std/__init__.py +10 -0
- spork/std/json.py +85 -0
- spork/std/map.py +219 -0
- spork/std/prelude.py +519 -0
- spork/std/string.py +182 -0
- spork_runtime-0.1.0.dist-info/METADATA +85 -0
- spork_runtime-0.1.0.dist-info/RECORD +17 -0
- spork_runtime-0.1.0.dist-info/WHEEL +5 -0
- spork_runtime-0.1.0.dist-info/licenses/LICENSE +21 -0
- spork_runtime-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
"""
|
|
2
|
+
spork.runtime - The Spork Runtime Library
|
|
3
|
+
|
|
4
|
+
This package contains everything needed to run compiled Spork programs.
|
|
5
|
+
It is designed to be lightweight and independent of the compiler.
|
|
6
|
+
|
|
7
|
+
Submodules:
|
|
8
|
+
- types: Core type definitions (Symbol, Keyword, VectorLiteral, etc.)
|
|
9
|
+
- persistent data structures: provided by the spork-pds dependency
|
|
10
|
+
- core: Standard library functions (first, rest, map, filter, etc.)
|
|
11
|
+
- utils: Runtime utilities (spork_try, setup_runtime_env, etc.)
|
|
12
|
+
- testing: Module-local descriptors for declared tests
|
|
13
|
+
- ns: Namespace management (loading, registering, finding namespaces)
|
|
14
|
+
|
|
15
|
+
The runtime is what gets installed into user project environments.
|
|
16
|
+
The compiler (spork.compiler) depends on runtime.types for AST nodes,
|
|
17
|
+
but the runtime has no dependencies on the compiler.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from typing import Any, TypeVar, Union
|
|
21
|
+
|
|
22
|
+
# Re-export core functions
|
|
23
|
+
from spork.runtime.core import (
|
|
24
|
+
_PROTOCOL_IMPLS,
|
|
25
|
+
_PROTOCOLS,
|
|
26
|
+
LazySeq,
|
|
27
|
+
add,
|
|
28
|
+
assoc,
|
|
29
|
+
assoc_bang,
|
|
30
|
+
bit_and,
|
|
31
|
+
bit_and_not,
|
|
32
|
+
bit_not,
|
|
33
|
+
bit_or,
|
|
34
|
+
bit_shift_left,
|
|
35
|
+
bit_shift_right,
|
|
36
|
+
bit_xor,
|
|
37
|
+
concat,
|
|
38
|
+
conj,
|
|
39
|
+
conj_bang,
|
|
40
|
+
contains_q,
|
|
41
|
+
count,
|
|
42
|
+
cycle,
|
|
43
|
+
dec,
|
|
44
|
+
dedupe,
|
|
45
|
+
disj,
|
|
46
|
+
disj_bang,
|
|
47
|
+
dissoc,
|
|
48
|
+
dissoc_bang,
|
|
49
|
+
distinct,
|
|
50
|
+
div,
|
|
51
|
+
doall,
|
|
52
|
+
dorun,
|
|
53
|
+
drop,
|
|
54
|
+
drop_while,
|
|
55
|
+
empty,
|
|
56
|
+
even_q,
|
|
57
|
+
every,
|
|
58
|
+
first,
|
|
59
|
+
flatten,
|
|
60
|
+
frequencies,
|
|
61
|
+
get,
|
|
62
|
+
get_protocol_abc,
|
|
63
|
+
group_by,
|
|
64
|
+
inc,
|
|
65
|
+
interleave,
|
|
66
|
+
interpose,
|
|
67
|
+
into,
|
|
68
|
+
iterate,
|
|
69
|
+
keep,
|
|
70
|
+
keep_indexed,
|
|
71
|
+
lazy_seq,
|
|
72
|
+
map_indexed,
|
|
73
|
+
mapcat,
|
|
74
|
+
mod,
|
|
75
|
+
mul,
|
|
76
|
+
neg_q,
|
|
77
|
+
not_any,
|
|
78
|
+
not_every,
|
|
79
|
+
nth,
|
|
80
|
+
odd_q,
|
|
81
|
+
partition,
|
|
82
|
+
partition_all,
|
|
83
|
+
persistent_bang,
|
|
84
|
+
pop_bang,
|
|
85
|
+
pos_q,
|
|
86
|
+
protocol_dispatch,
|
|
87
|
+
protocol_register_virtual_subclass,
|
|
88
|
+
quot,
|
|
89
|
+
realized_q,
|
|
90
|
+
reduce,
|
|
91
|
+
reductions,
|
|
92
|
+
register_protocol_impl,
|
|
93
|
+
rest,
|
|
94
|
+
reverse,
|
|
95
|
+
runtime_register_protocol,
|
|
96
|
+
satisfies_protocol,
|
|
97
|
+
seq,
|
|
98
|
+
some,
|
|
99
|
+
sort,
|
|
100
|
+
sort_by,
|
|
101
|
+
split_at,
|
|
102
|
+
split_with,
|
|
103
|
+
spork_abs,
|
|
104
|
+
spork_filter,
|
|
105
|
+
spork_map,
|
|
106
|
+
spork_max,
|
|
107
|
+
spork_min,
|
|
108
|
+
spork_range,
|
|
109
|
+
spork_repeat,
|
|
110
|
+
sub,
|
|
111
|
+
take,
|
|
112
|
+
take_while,
|
|
113
|
+
transient,
|
|
114
|
+
zero_q,
|
|
115
|
+
zipmap,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# Re-export JSON utilities
|
|
119
|
+
from spork.runtime.json import (
|
|
120
|
+
SporkJSONEncoder,
|
|
121
|
+
)
|
|
122
|
+
from spork.runtime.json import (
|
|
123
|
+
dump as json_dump,
|
|
124
|
+
)
|
|
125
|
+
from spork.runtime.json import (
|
|
126
|
+
dumps as json_dumps,
|
|
127
|
+
)
|
|
128
|
+
from spork.runtime.json import (
|
|
129
|
+
load as json_load,
|
|
130
|
+
)
|
|
131
|
+
from spork.runtime.json import (
|
|
132
|
+
load_spork as json_load_spork,
|
|
133
|
+
)
|
|
134
|
+
from spork.runtime.json import (
|
|
135
|
+
loads as json_loads,
|
|
136
|
+
)
|
|
137
|
+
from spork.runtime.json import (
|
|
138
|
+
loads_spork as json_loads_spork,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
# Re-export PDS (persistent data structures)
|
|
142
|
+
from spork.pds import (
|
|
143
|
+
EMPTY_DOUBLE_VECTOR,
|
|
144
|
+
EMPTY_LONG_VECTOR,
|
|
145
|
+
EMPTY_MAP,
|
|
146
|
+
EMPTY_SET,
|
|
147
|
+
EMPTY_SORTED_VECTOR,
|
|
148
|
+
EMPTY_VECTOR,
|
|
149
|
+
Cons,
|
|
150
|
+
DoubleVector,
|
|
151
|
+
IntVector,
|
|
152
|
+
Map,
|
|
153
|
+
Set,
|
|
154
|
+
SortedVector,
|
|
155
|
+
TransientDoubleVector,
|
|
156
|
+
TransientIntVector,
|
|
157
|
+
TransientMap,
|
|
158
|
+
TransientSet,
|
|
159
|
+
TransientSortedVector,
|
|
160
|
+
TransientVector,
|
|
161
|
+
Vector,
|
|
162
|
+
cons,
|
|
163
|
+
hash_map,
|
|
164
|
+
hash_set,
|
|
165
|
+
sorted_vec,
|
|
166
|
+
vec,
|
|
167
|
+
vec_f64,
|
|
168
|
+
vec_i64,
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
# Re-export types
|
|
172
|
+
from spork.runtime.testing import SporkTest, register_spork_test
|
|
173
|
+
from spork.runtime.types import (
|
|
174
|
+
_MISSING,
|
|
175
|
+
Decorated,
|
|
176
|
+
Keyword,
|
|
177
|
+
KwargsLiteral,
|
|
178
|
+
MapLiteral,
|
|
179
|
+
MatchError,
|
|
180
|
+
SetLiteral,
|
|
181
|
+
Symbol,
|
|
182
|
+
VectorLiteral,
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
# Re-export utils
|
|
186
|
+
from spork.runtime.utils import (
|
|
187
|
+
__spork_ns_env__,
|
|
188
|
+
__spork_ns_get__,
|
|
189
|
+
__spork_refer_all__,
|
|
190
|
+
__spork_require__,
|
|
191
|
+
setup_runtime_env,
|
|
192
|
+
spork_kwargs_dict,
|
|
193
|
+
spork_kwargs_map,
|
|
194
|
+
spork_raise,
|
|
195
|
+
spork_setattr,
|
|
196
|
+
spork_try,
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
# Type variables for generic types
|
|
200
|
+
T = TypeVar("T")
|
|
201
|
+
K = TypeVar("K")
|
|
202
|
+
V = TypeVar("V")
|
|
203
|
+
T_co = TypeVar("T_co", covariant=True)
|
|
204
|
+
V_co = TypeVar("V_co", covariant=True)
|
|
205
|
+
|
|
206
|
+
# Type aliases for common patterns
|
|
207
|
+
List = Vector
|
|
208
|
+
Vec = Vector
|
|
209
|
+
Dict = Map
|
|
210
|
+
ConsCell = Cons
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def is_typed_collection(obj: Any) -> bool:
|
|
214
|
+
"""Check if an object is one of Spork's typed persistent collections."""
|
|
215
|
+
return isinstance(obj, (Vector, Map, Cons))
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def get_collection_type(obj: Any) -> Union[type, None]:
|
|
219
|
+
"""Get the collection type of a Spork persistent data structure."""
|
|
220
|
+
if isinstance(obj, Vector):
|
|
221
|
+
return Vector
|
|
222
|
+
elif isinstance(obj, Map):
|
|
223
|
+
return Map
|
|
224
|
+
elif isinstance(obj, Cons):
|
|
225
|
+
return Cons
|
|
226
|
+
return None
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
__all__ = [
|
|
230
|
+
# Types
|
|
231
|
+
"Symbol",
|
|
232
|
+
"Keyword",
|
|
233
|
+
"VectorLiteral",
|
|
234
|
+
"MapLiteral",
|
|
235
|
+
"SetLiteral",
|
|
236
|
+
"KwargsLiteral",
|
|
237
|
+
"Decorated",
|
|
238
|
+
"MatchError",
|
|
239
|
+
"SporkTest",
|
|
240
|
+
"register_spork_test",
|
|
241
|
+
"_MISSING",
|
|
242
|
+
# Persistent data structures
|
|
243
|
+
"Vector",
|
|
244
|
+
"Map",
|
|
245
|
+
"Set",
|
|
246
|
+
"Cons",
|
|
247
|
+
"DoubleVector",
|
|
248
|
+
"IntVector",
|
|
249
|
+
"TransientVector",
|
|
250
|
+
"TransientDoubleVector",
|
|
251
|
+
"TransientIntVector",
|
|
252
|
+
"TransientMap",
|
|
253
|
+
"TransientSet",
|
|
254
|
+
"EMPTY_VECTOR",
|
|
255
|
+
"EMPTY_DOUBLE_VECTOR",
|
|
256
|
+
"EMPTY_LONG_VECTOR",
|
|
257
|
+
"EMPTY_MAP",
|
|
258
|
+
"EMPTY_SET",
|
|
259
|
+
"EMPTY_SORTED_VECTOR",
|
|
260
|
+
"vec",
|
|
261
|
+
"vec_f64",
|
|
262
|
+
"vec_i64",
|
|
263
|
+
"hash_map",
|
|
264
|
+
"hash_set",
|
|
265
|
+
"sorted_vec",
|
|
266
|
+
"cons",
|
|
267
|
+
"SortedVector",
|
|
268
|
+
"TransientSortedVector",
|
|
269
|
+
# JSON
|
|
270
|
+
"SporkJSONEncoder",
|
|
271
|
+
"json_dump",
|
|
272
|
+
"json_dumps",
|
|
273
|
+
"json_load",
|
|
274
|
+
"json_loads",
|
|
275
|
+
"json_load_spork",
|
|
276
|
+
"json_loads_spork",
|
|
277
|
+
# Protocol system
|
|
278
|
+
"_PROTOCOLS",
|
|
279
|
+
"_PROTOCOL_IMPLS",
|
|
280
|
+
"runtime_register_protocol",
|
|
281
|
+
"get_protocol_abc",
|
|
282
|
+
"register_protocol_impl",
|
|
283
|
+
"protocol_register_virtual_subclass",
|
|
284
|
+
"protocol_dispatch",
|
|
285
|
+
"satisfies_protocol",
|
|
286
|
+
# Sequence operations
|
|
287
|
+
"first",
|
|
288
|
+
"rest",
|
|
289
|
+
"seq",
|
|
290
|
+
"nth",
|
|
291
|
+
"conj",
|
|
292
|
+
"assoc",
|
|
293
|
+
"dissoc",
|
|
294
|
+
"disj",
|
|
295
|
+
"get",
|
|
296
|
+
"count",
|
|
297
|
+
"contains_q",
|
|
298
|
+
"empty",
|
|
299
|
+
"into",
|
|
300
|
+
# Transients
|
|
301
|
+
"transient",
|
|
302
|
+
"persistent_bang",
|
|
303
|
+
"conj_bang",
|
|
304
|
+
"assoc_bang",
|
|
305
|
+
"dissoc_bang",
|
|
306
|
+
"disj_bang",
|
|
307
|
+
"pop_bang",
|
|
308
|
+
# Lazy sequences
|
|
309
|
+
"spork_map",
|
|
310
|
+
"spork_filter",
|
|
311
|
+
"take",
|
|
312
|
+
"take_while",
|
|
313
|
+
"drop",
|
|
314
|
+
"drop_while",
|
|
315
|
+
"concat",
|
|
316
|
+
"spork_repeat",
|
|
317
|
+
"cycle",
|
|
318
|
+
"iterate",
|
|
319
|
+
"spork_range",
|
|
320
|
+
"interleave",
|
|
321
|
+
"interpose",
|
|
322
|
+
"partition",
|
|
323
|
+
"partition_all",
|
|
324
|
+
"keep",
|
|
325
|
+
"keep_indexed",
|
|
326
|
+
"map_indexed",
|
|
327
|
+
"dedupe",
|
|
328
|
+
"distinct",
|
|
329
|
+
"flatten",
|
|
330
|
+
"mapcat",
|
|
331
|
+
# Predicates and reducers
|
|
332
|
+
"some",
|
|
333
|
+
"every",
|
|
334
|
+
"not_every",
|
|
335
|
+
"not_any",
|
|
336
|
+
"reduce",
|
|
337
|
+
"reductions",
|
|
338
|
+
# Collection utilities
|
|
339
|
+
"zipmap",
|
|
340
|
+
"group_by",
|
|
341
|
+
"frequencies",
|
|
342
|
+
"reverse",
|
|
343
|
+
"sort",
|
|
344
|
+
"sort_by",
|
|
345
|
+
"split_at",
|
|
346
|
+
"split_with",
|
|
347
|
+
"doall",
|
|
348
|
+
"dorun",
|
|
349
|
+
"realized_q",
|
|
350
|
+
# Math
|
|
351
|
+
"inc",
|
|
352
|
+
"dec",
|
|
353
|
+
"even_q",
|
|
354
|
+
"odd_q",
|
|
355
|
+
"pos_q",
|
|
356
|
+
"neg_q",
|
|
357
|
+
"zero_q",
|
|
358
|
+
"add",
|
|
359
|
+
"sub",
|
|
360
|
+
"mul",
|
|
361
|
+
"div",
|
|
362
|
+
"mod",
|
|
363
|
+
"quot",
|
|
364
|
+
"spork_max",
|
|
365
|
+
"spork_min",
|
|
366
|
+
"spork_abs",
|
|
367
|
+
# Bitwise
|
|
368
|
+
"bit_or",
|
|
369
|
+
"bit_and",
|
|
370
|
+
"bit_and_not",
|
|
371
|
+
"bit_xor",
|
|
372
|
+
"bit_not",
|
|
373
|
+
"bit_shift_left",
|
|
374
|
+
"bit_shift_right",
|
|
375
|
+
# Utils
|
|
376
|
+
"spork_try",
|
|
377
|
+
"spork_raise",
|
|
378
|
+
"spork_setattr",
|
|
379
|
+
"spork_kwargs_dict",
|
|
380
|
+
"spork_kwargs_map",
|
|
381
|
+
"setup_runtime_env",
|
|
382
|
+
"__spork_require__",
|
|
383
|
+
"__spork_ns_env__",
|
|
384
|
+
"__spork_ns_get__",
|
|
385
|
+
"__spork_refer_all__",
|
|
386
|
+
# Type variables
|
|
387
|
+
"T",
|
|
388
|
+
"T_co",
|
|
389
|
+
"K",
|
|
390
|
+
"V",
|
|
391
|
+
"V_co",
|
|
392
|
+
# Type aliases
|
|
393
|
+
"List",
|
|
394
|
+
"Vec",
|
|
395
|
+
"Dict",
|
|
396
|
+
"ConsCell",
|
|
397
|
+
# Utilities
|
|
398
|
+
"is_typed_collection",
|
|
399
|
+
"get_collection_type",
|
|
400
|
+
]
|