jaclang 0.8.1__py3-none-any.whl → 0.8.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 jaclang might be problematic. Click here for more details.
- jaclang/__init__.py +6 -0
- jaclang/cli/cli.py +21 -50
- jaclang/compiler/codeinfo.py +0 -1
- jaclang/compiler/jac.lark +12 -10
- jaclang/compiler/larkparse/jac_parser.py +2 -2
- jaclang/compiler/parser.py +18 -10
- jaclang/compiler/passes/main/__init__.py +0 -14
- jaclang/compiler/passes/main/annex_pass.py +2 -8
- jaclang/compiler/passes/main/cfg_build_pass.py +38 -12
- jaclang/compiler/passes/main/import_pass.py +3 -11
- jaclang/compiler/passes/main/pyast_gen_pass.py +243 -592
- jaclang/compiler/passes/main/sym_tab_link_pass.py +2 -5
- jaclang/compiler/passes/main/tests/test_cfg_build_pass.py +2 -8
- jaclang/compiler/passes/main/tests/test_decl_impl_match_pass.py +7 -8
- jaclang/compiler/passes/main/tests/test_import_pass.py +5 -18
- jaclang/compiler/passes/main/tests/test_pyast_gen_pass.py +2 -6
- jaclang/compiler/passes/main/tests/test_sub_node_pass.py +1 -3
- jaclang/compiler/passes/main/tests/test_sym_tab_link_pass.py +20 -17
- jaclang/compiler/passes/tool/doc_ir_gen_pass.py +237 -105
- jaclang/compiler/passes/tool/jac_formatter_pass.py +2 -0
- jaclang/compiler/passes/tool/tests/fixtures/archetype_frmt.jac +14 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/triple_quoted_string.jac +5 -4
- jaclang/compiler/passes/tool/tests/fixtures/import_fmt.jac +6 -0
- jaclang/compiler/passes/tool/tests/fixtures/simple_walk_fmt.jac +3 -3
- jaclang/compiler/passes/tool/tests/fixtures/tagbreak.jac +9 -0
- jaclang/compiler/passes/tool/tests/test_jac_format_pass.py +18 -3
- jaclang/compiler/passes/tool/tests/test_unparse_validate.py +2 -2
- jaclang/compiler/program.py +21 -60
- jaclang/compiler/tests/fixtures/pkg_import_lib_py/__init__.py +2 -8
- jaclang/compiler/tests/fixtures/pkg_import_lib_py/sub/__init__.py +1 -5
- jaclang/compiler/tests/test_importer.py +10 -13
- jaclang/compiler/unitree.py +32 -16
- jaclang/langserve/__init__.jac +1 -1
- jaclang/langserve/engine.jac +113 -108
- jaclang/langserve/server.jac +17 -2
- jaclang/langserve/tests/server_test/test_lang_serve.py +138 -46
- jaclang/langserve/tests/server_test/utils.py +35 -9
- jaclang/langserve/tests/test_sem_tokens.py +1 -1
- jaclang/langserve/tests/test_server.py +3 -7
- jaclang/runtimelib/archetype.py +127 -5
- jaclang/runtimelib/importer.py +51 -94
- jaclang/runtimelib/machine.py +391 -268
- jaclang/runtimelib/meta_importer.py +86 -0
- jaclang/runtimelib/tests/fixtures/graph_purger.jac +24 -26
- jaclang/runtimelib/tests/fixtures/other_root_access.jac +25 -16
- jaclang/runtimelib/tests/test_jaseci.py +3 -1
- jaclang/tests/fixtures/arch_rel_import_creation.jac +23 -23
- jaclang/tests/fixtures/async_ability.jac +43 -10
- jaclang/tests/fixtures/async_function.jac +18 -0
- jaclang/tests/fixtures/async_walker.jac +17 -12
- jaclang/tests/fixtures/create_dynamic_archetype.jac +25 -28
- jaclang/tests/fixtures/deep/deeper/deep_outer_import.jac +7 -4
- jaclang/tests/fixtures/deep/deeper/snd_lev.jac +2 -2
- jaclang/tests/fixtures/deep/deeper/snd_lev_dup.jac +6 -0
- jaclang/tests/fixtures/deep/one_lev.jac +2 -2
- jaclang/tests/fixtures/deep/one_lev_dup.jac +4 -3
- jaclang/tests/fixtures/dynamic_archetype.jac +19 -12
- jaclang/tests/fixtures/foo.jac +14 -22
- jaclang/tests/fixtures/jac_from_py.py +1 -1
- jaclang/tests/fixtures/jp_importer.jac +6 -6
- jaclang/tests/fixtures/jp_importer_auto.jac +5 -3
- jaclang/tests/fixtures/unicode_strings.jac +24 -0
- jaclang/tests/fixtures/walker_update.jac +5 -7
- jaclang/tests/test_language.py +138 -140
- jaclang/tests/test_reference.py +9 -4
- jaclang/tests/test_typecheck.py +13 -26
- jaclang/utils/lang_tools.py +7 -5
- jaclang/utils/module_resolver.py +23 -0
- {jaclang-0.8.1.dist-info → jaclang-0.8.2.dist-info}/METADATA +1 -1
- {jaclang-0.8.1.dist-info → jaclang-0.8.2.dist-info}/RECORD +72 -70
- jaclang/compiler/passes/main/tests/fixtures/main_err.jac +0 -6
- jaclang/compiler/passes/main/tests/fixtures/second_err.jac +0 -4
- jaclang/compiler/passes/tool/tests/fixtures/corelib.jac +0 -644
- jaclang/compiler/passes/tool/tests/test_doc_ir_gen_pass.py +0 -29
- jaclang/tests/fixtures/deep/deeper/__init__.jac +0 -1
- {jaclang-0.8.1.dist-info → jaclang-0.8.2.dist-info}/WHEEL +0 -0
- {jaclang-0.8.1.dist-info → jaclang-0.8.2.dist-info}/entry_points.txt +0 -0
jaclang/__init__.py
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
"""The Jac Programming Language."""
|
|
2
2
|
|
|
3
|
+
import sys
|
|
4
|
+
|
|
3
5
|
from jaclang.runtimelib.machine import (
|
|
4
6
|
JacMachine,
|
|
5
7
|
JacMachineImpl,
|
|
6
8
|
JacMachineInterface,
|
|
7
9
|
plugin_manager,
|
|
8
10
|
)
|
|
11
|
+
from jaclang.runtimelib.meta_importer import JacMetaImporter
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
plugin_manager.register(JacMachineImpl)
|
|
12
15
|
plugin_manager.load_setuptools_entrypoints("jac")
|
|
13
16
|
|
|
17
|
+
if not any(isinstance(f, JacMetaImporter) for f in sys.meta_path):
|
|
18
|
+
sys.meta_path.insert(0, JacMetaImporter())
|
|
19
|
+
|
|
14
20
|
__all__ = ["JacMachineInterface", "JacMachine"]
|
jaclang/cli/cli.py
CHANGED
|
@@ -12,20 +12,20 @@ from typing import Optional
|
|
|
12
12
|
|
|
13
13
|
import jaclang.compiler.unitree as uni
|
|
14
14
|
from jaclang.cli.cmdreg import CommandShell, cmd_registry
|
|
15
|
-
from jaclang.compiler.passes.main import
|
|
15
|
+
from jaclang.compiler.passes.main import PyastBuildPass
|
|
16
16
|
from jaclang.compiler.program import JacProgram
|
|
17
17
|
from jaclang.runtimelib.builtin import printgraph
|
|
18
18
|
from jaclang.runtimelib.constructs import WalkerArchetype
|
|
19
19
|
from jaclang.runtimelib.machine import (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
ExecutionContext,
|
|
21
|
+
JacMachine as Jac,
|
|
22
|
+
JacMachineInterface as JacInterface,
|
|
23
23
|
)
|
|
24
24
|
from jaclang.utils.helpers import debugger as db
|
|
25
25
|
from jaclang.utils.lang_tools import AstTool
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
JacInterface.create_cmd()
|
|
29
29
|
Jac.setup()
|
|
30
30
|
|
|
31
31
|
|
|
@@ -86,7 +86,7 @@ def format(path: str, outfile: str = "", to_screen: bool = False) -> None:
|
|
|
86
86
|
|
|
87
87
|
def proc_file_sess(
|
|
88
88
|
filename: str, session: str, root: Optional[str] = None
|
|
89
|
-
) -> tuple[str, str,
|
|
89
|
+
) -> tuple[str, str, ExecutionContext]:
|
|
90
90
|
"""Create JacMachine and return the base path, module name, and machine state."""
|
|
91
91
|
if session == "":
|
|
92
92
|
session = (
|
|
@@ -99,7 +99,8 @@ def proc_file_sess(
|
|
|
99
99
|
base, mod = os.path.split(filename)
|
|
100
100
|
base = base if base else "./"
|
|
101
101
|
mod = mod[:-4]
|
|
102
|
-
mach =
|
|
102
|
+
mach = ExecutionContext(session=session, root=root)
|
|
103
|
+
Jac.set_context(mach)
|
|
103
104
|
return base, mod, mach
|
|
104
105
|
|
|
105
106
|
|
|
@@ -129,11 +130,11 @@ def run(
|
|
|
129
130
|
# if no session specified, check if it was defined when starting the command shell
|
|
130
131
|
# otherwise default to jaclang.session
|
|
131
132
|
base, mod, mach = proc_file_sess(filename, session)
|
|
133
|
+
Jac.set_base_path(base)
|
|
132
134
|
|
|
133
135
|
if filename.endswith(".jac"):
|
|
134
136
|
try:
|
|
135
137
|
Jac.jac_import(
|
|
136
|
-
mach=mach,
|
|
137
138
|
target=mod,
|
|
138
139
|
base_path=base,
|
|
139
140
|
override_name="__main__" if main else None,
|
|
@@ -143,9 +144,8 @@ def run(
|
|
|
143
144
|
elif filename.endswith(".jir"):
|
|
144
145
|
try:
|
|
145
146
|
with open(filename, "rb") as f:
|
|
146
|
-
Jac.attach_program(
|
|
147
|
+
Jac.attach_program(pickle.load(f))
|
|
147
148
|
Jac.jac_import(
|
|
148
|
-
mach=mach,
|
|
149
149
|
target=mod,
|
|
150
150
|
base_path=base,
|
|
151
151
|
override_name="__main__" if main else None,
|
|
@@ -179,19 +179,14 @@ def get_object(filename: str, id: str, session: str = "", main: bool = True) ->
|
|
|
179
179
|
|
|
180
180
|
if filename.endswith(".jac"):
|
|
181
181
|
Jac.jac_import(
|
|
182
|
-
mach=mach,
|
|
183
182
|
target=mod,
|
|
184
183
|
base_path=base,
|
|
185
184
|
override_name="__main__" if main else None,
|
|
186
185
|
)
|
|
187
186
|
elif filename.endswith(".jir"):
|
|
188
187
|
with open(filename, "rb") as f:
|
|
189
|
-
Jac.attach_program(
|
|
190
|
-
mach,
|
|
191
|
-
pickle.load(f),
|
|
192
|
-
)
|
|
188
|
+
Jac.attach_program(pickle.load(f))
|
|
193
189
|
Jac.jac_import(
|
|
194
|
-
mach=mach,
|
|
195
190
|
target=mod,
|
|
196
191
|
base_path=base,
|
|
197
192
|
override_name="__main__" if main else None,
|
|
@@ -201,12 +196,11 @@ def get_object(filename: str, id: str, session: str = "", main: bool = True) ->
|
|
|
201
196
|
raise ValueError("Not a valid file!\nOnly supports `.jac` and `.jir`")
|
|
202
197
|
|
|
203
198
|
data = {}
|
|
204
|
-
obj =
|
|
199
|
+
obj = Jac.get_object(id)
|
|
205
200
|
if obj:
|
|
206
201
|
data = obj.__jac__.__getstate__()
|
|
207
202
|
else:
|
|
208
203
|
print(f"Object with id {id} not found.", file=sys.stderr)
|
|
209
|
-
|
|
210
204
|
mach.close()
|
|
211
205
|
return data
|
|
212
206
|
|
|
@@ -227,10 +221,7 @@ def build(filename: str) -> None:
|
|
|
227
221
|
jac build myprogram.jac --no-typecheck
|
|
228
222
|
"""
|
|
229
223
|
if filename.endswith(".jac"):
|
|
230
|
-
(out := JacProgram()).compile(
|
|
231
|
-
file_path=filename,
|
|
232
|
-
mode=CMode.COMPILE,
|
|
233
|
-
)
|
|
224
|
+
(out := JacProgram()).compile(file_path=filename)
|
|
234
225
|
errs = len(out.errors_had)
|
|
235
226
|
warnings = len(out.warnings_had)
|
|
236
227
|
print(f"Errors: {errs}, Warnings: {warnings}")
|
|
@@ -256,10 +247,7 @@ def check(filename: str, print_errs: bool = True) -> None:
|
|
|
256
247
|
jac check myprogram.jac --no-print_errs
|
|
257
248
|
"""
|
|
258
249
|
if filename.endswith(".jac"):
|
|
259
|
-
(prog := JacProgram()).compile(
|
|
260
|
-
file_path=filename,
|
|
261
|
-
mode=CMode.TYPECHECK,
|
|
262
|
-
)
|
|
250
|
+
(prog := JacProgram()).compile(file_path=filename)
|
|
263
251
|
|
|
264
252
|
errs = len(prog.errors_had)
|
|
265
253
|
warnings = len(prog.warnings_had)
|
|
@@ -284,13 +272,9 @@ def lsp() -> None:
|
|
|
284
272
|
Examples:
|
|
285
273
|
jac lsp
|
|
286
274
|
"""
|
|
287
|
-
from jaclang import
|
|
275
|
+
from jaclang.langserve.server import run_lang_server
|
|
288
276
|
|
|
289
|
-
|
|
290
|
-
"...jaclang.langserve.server", __file__, items={"run_lang_server": None}
|
|
291
|
-
)
|
|
292
|
-
run_lang_server = run_lang_server_tuple[0]
|
|
293
|
-
run_lang_server() # type: ignore
|
|
277
|
+
run_lang_server()
|
|
294
278
|
|
|
295
279
|
|
|
296
280
|
@cmd_registry.register
|
|
@@ -326,19 +310,14 @@ def enter(
|
|
|
326
310
|
|
|
327
311
|
if filename.endswith(".jac"):
|
|
328
312
|
ret_module = Jac.jac_import(
|
|
329
|
-
mach=mach,
|
|
330
313
|
target=mod,
|
|
331
314
|
base_path=base,
|
|
332
315
|
override_name="__main__" if main else None,
|
|
333
316
|
)
|
|
334
317
|
elif filename.endswith(".jir"):
|
|
335
318
|
with open(filename, "rb") as f:
|
|
336
|
-
Jac.attach_program(
|
|
337
|
-
mach,
|
|
338
|
-
pickle.load(f),
|
|
339
|
-
)
|
|
319
|
+
Jac.attach_program(pickle.load(f))
|
|
340
320
|
ret_module = Jac.jac_import(
|
|
341
|
-
mach=mach,
|
|
342
321
|
target=mod,
|
|
343
322
|
base_path=base,
|
|
344
323
|
override_name="__main__" if main else None,
|
|
@@ -355,11 +334,10 @@ def enter(
|
|
|
355
334
|
archetype = getattr(loaded_mod, entrypoint)(*args)
|
|
356
335
|
|
|
357
336
|
mach.set_entry_node(node)
|
|
358
|
-
if isinstance(archetype, WalkerArchetype) and
|
|
359
|
-
mach
|
|
337
|
+
if isinstance(archetype, WalkerArchetype) and Jac.check_read_access(
|
|
338
|
+
mach.entry_node
|
|
360
339
|
):
|
|
361
340
|
Jac.spawn(mach.entry_node.archetype, archetype)
|
|
362
|
-
|
|
363
341
|
mach.close()
|
|
364
342
|
|
|
365
343
|
|
|
@@ -397,10 +375,7 @@ def test(
|
|
|
397
375
|
jac test --xit # Stop on first failure
|
|
398
376
|
jac test --verbose # Show detailed output
|
|
399
377
|
"""
|
|
400
|
-
mach = JacMachine()
|
|
401
|
-
|
|
402
378
|
failcount = Jac.run_test(
|
|
403
|
-
mach=mach,
|
|
404
379
|
filepath=filepath,
|
|
405
380
|
func_name=("test_" + test_name) if test_name else None,
|
|
406
381
|
filter=filter,
|
|
@@ -410,8 +385,6 @@ def test(
|
|
|
410
385
|
verbose=verbose,
|
|
411
386
|
)
|
|
412
387
|
|
|
413
|
-
mach.close()
|
|
414
|
-
|
|
415
388
|
if failcount:
|
|
416
389
|
raise SystemExit(f"Tests failed: {failcount}")
|
|
417
390
|
|
|
@@ -528,10 +501,8 @@ def dot(
|
|
|
528
501
|
base, mod, jac_machine = proc_file_sess(filename, session)
|
|
529
502
|
|
|
530
503
|
if filename.endswith(".jac"):
|
|
531
|
-
Jac.jac_import(
|
|
532
|
-
|
|
533
|
-
)
|
|
534
|
-
module = jac_machine.loaded_modules.get("__main__")
|
|
504
|
+
Jac.jac_import(target=mod, base_path=base, override_name="__main__")
|
|
505
|
+
module = Jac.loaded_modules.get("__main__")
|
|
535
506
|
globals().update(vars(module))
|
|
536
507
|
try:
|
|
537
508
|
node = globals().get(initial, eval(initial)) if initial else None
|
jaclang/compiler/codeinfo.py
CHANGED
jaclang/compiler/jac.lark
CHANGED
|
@@ -62,7 +62,7 @@ ability: decorators? KW_ASYNC? (ability_decl | function_decl)
|
|
|
62
62
|
function_decl: KW_OVERRIDE? KW_STATIC? KW_DEF access_tag? named_ref func_decl? (block_tail | KW_ABSTRACT? SEMI)
|
|
63
63
|
ability_decl: KW_OVERRIDE? KW_STATIC? KW_CAN access_tag? named_ref event_clause (block_tail | KW_ABSTRACT? SEMI)
|
|
64
64
|
block_tail: code_block | KW_BY atomic_call SEMI
|
|
65
|
-
event_clause: KW_WITH expression? (KW_EXIT | KW_ENTRY)
|
|
65
|
+
event_clause: KW_WITH expression? (KW_EXIT | KW_ENTRY)
|
|
66
66
|
|
|
67
67
|
func_decl: (LPAREN func_decl_params? RPAREN) (RETURN_HINT expression)?
|
|
68
68
|
| (RETURN_HINT expression)
|
|
@@ -190,7 +190,7 @@ global_ref: GLOBAL_OP name_list
|
|
|
190
190
|
nonlocal_ref: NONLOCAL_OP name_list
|
|
191
191
|
name_list: (named_ref COMMA)* named_ref
|
|
192
192
|
|
|
193
|
-
// [Heading]:
|
|
193
|
+
// [Heading]: Object spatial typed context blocks.
|
|
194
194
|
typed_ctx_block: RETURN_HINT expression code_block
|
|
195
195
|
|
|
196
196
|
// [Heading]: Return statements.
|
|
@@ -217,7 +217,7 @@ report_stmt: KW_REPORT expression
|
|
|
217
217
|
// [Heading]: Control statements.
|
|
218
218
|
ctrl_stmt: KW_SKIP | KW_BREAK | KW_CONTINUE
|
|
219
219
|
|
|
220
|
-
// [Heading]:
|
|
220
|
+
// [Heading]: Object spatial Walker statements.
|
|
221
221
|
spatial_stmt: visit_stmt | ignore_stmt | disenage_stmt
|
|
222
222
|
|
|
223
223
|
// [Heading]: Visit statements.
|
|
@@ -304,10 +304,10 @@ connect: (connect (connect_op | disconnect_op))? atomic_pipe
|
|
|
304
304
|
atomic_pipe: (atomic_pipe A_PIPE_FWD)? atomic_pipe_back
|
|
305
305
|
|
|
306
306
|
// [Heading]: Atomic pipe back expressions.
|
|
307
|
-
atomic_pipe_back: (atomic_pipe_back A_PIPE_BKWD)?
|
|
307
|
+
atomic_pipe_back: (atomic_pipe_back A_PIPE_BKWD)? os_spawn
|
|
308
308
|
|
|
309
|
-
// [Heading]:
|
|
310
|
-
|
|
309
|
+
// [Heading]: Object spatial spawn expressions.
|
|
310
|
+
os_spawn: (os_spawn KW_SPAWN)? unpack
|
|
311
311
|
|
|
312
312
|
// [Heading]: Unpack expressions.
|
|
313
313
|
unpack: STAR_MUL? ref
|
|
@@ -315,7 +315,7 @@ unpack: STAR_MUL? ref
|
|
|
315
315
|
// [Heading]: References (unused).
|
|
316
316
|
ref: BW_AND? pipe_call
|
|
317
317
|
|
|
318
|
-
// [Heading]:
|
|
318
|
+
// [Heading]: Object spatial calls.
|
|
319
319
|
pipe_call: (PIPE_FWD | A_PIPE_FWD | KW_SPAWN | KW_AWAIT)? atomic_chain
|
|
320
320
|
|
|
321
321
|
// [Heading]: Subscripted and dotted expressions.
|
|
@@ -330,7 +330,9 @@ index_slice: LSQUARE
|
|
|
330
330
|
| list_val
|
|
331
331
|
|
|
332
332
|
// [Heading]: Function calls.
|
|
333
|
-
atomic_call: atomic_chain LPAREN param_list?
|
|
333
|
+
atomic_call: atomic_chain LPAREN param_list? by_call? RPAREN by_call?
|
|
334
|
+
|
|
335
|
+
by_call: KW_BY expression
|
|
334
336
|
|
|
335
337
|
param_list: expr_list COMMA kw_expr_list COMMA?
|
|
336
338
|
| kw_expr_list COMMA?
|
|
@@ -398,7 +400,7 @@ tuple_list: expression COMMA expr_list COMMA kw_expr_list COMMA?
|
|
|
398
400
|
kw_expr_list: (kw_expr_list COMMA)? kw_expr
|
|
399
401
|
kw_expr: named_ref EQ expression | STAR_POW expression
|
|
400
402
|
|
|
401
|
-
// [Heading]:
|
|
403
|
+
// [Heading]: Object-Spatial References.
|
|
402
404
|
edge_ref_chain: LSQUARE (KW_NODE| KW_EDGE)? expression? (edge_op_ref (filter_compr | expression)?)+ RSQUARE
|
|
403
405
|
edge_op_ref: edge_any | edge_from | edge_to
|
|
404
406
|
edge_to: ARROW_R | ARROW_R_P1 typed_filter_compare_list ARROW_R_P2
|
|
@@ -589,7 +591,7 @@ KWESC_NAME: /<>[a-zA-Z_][a-zA-Z0-9_]*/
|
|
|
589
591
|
NAME: /[a-zA-Z_][a-zA-Z0-9_]*/
|
|
590
592
|
|
|
591
593
|
|
|
592
|
-
//
|
|
594
|
+
// Object-Spatial Operators -------------------------------------------------- //
|
|
593
595
|
|
|
594
596
|
ARROW_BI: "<-->"
|
|
595
597
|
ARROW_L: "<--"
|