jaclang 0.7.23__py3-none-any.whl → 0.7.26__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/cli/cli.py +46 -29
- jaclang/compiler/__init__.py +2 -2
- jaclang/compiler/absyntree.py +114 -66
- jaclang/compiler/codeloc.py +7 -2
- jaclang/compiler/compile.py +10 -3
- jaclang/compiler/jac.lark +4 -1
- jaclang/compiler/parser.py +63 -43
- jaclang/compiler/passes/ir_pass.py +2 -2
- jaclang/compiler/passes/main/def_impl_match_pass.py +83 -0
- jaclang/compiler/passes/main/def_use_pass.py +1 -2
- jaclang/compiler/passes/main/fuse_typeinfo_pass.py +146 -123
- jaclang/compiler/passes/main/import_pass.py +6 -2
- jaclang/compiler/passes/main/pyast_gen_pass.py +46 -20
- jaclang/compiler/passes/main/pyast_load_pass.py +56 -41
- jaclang/compiler/passes/main/pyjac_ast_link_pass.py +7 -7
- jaclang/compiler/passes/main/registry_pass.py +3 -12
- jaclang/compiler/passes/main/sym_tab_build_pass.py +1 -2
- jaclang/compiler/passes/main/tests/fixtures/defn_decl_mismatch.jac +19 -0
- jaclang/compiler/passes/main/tests/fixtures/fstrings.jac +2 -0
- jaclang/compiler/passes/main/tests/fixtures/uninitialized_hasvars.jac +26 -0
- jaclang/compiler/passes/main/tests/test_decl_def_match_pass.py +66 -0
- jaclang/compiler/passes/main/tests/test_def_use_pass.py +3 -3
- jaclang/compiler/passes/main/tests/test_registry_pass.py +2 -10
- jaclang/compiler/passes/main/tests/test_type_check_pass.py +1 -1
- jaclang/compiler/passes/tool/jac_formatter_pass.py +2 -2
- jaclang/compiler/passes/tool/tests/fixtures/corelib.jac +3 -3
- jaclang/compiler/passes/tool/tests/fixtures/corelib_fmt.jac +3 -3
- jaclang/compiler/passes/transform.py +27 -3
- jaclang/compiler/passes/utils/mypy_ast_build.py +246 -26
- jaclang/compiler/symtable.py +6 -0
- jaclang/compiler/tests/test_importer.py +2 -2
- jaclang/compiler/tests/test_parser.py +7 -1
- jaclang/langserve/engine.py +14 -12
- jaclang/langserve/server.py +7 -2
- jaclang/langserve/tests/test_server.py +1 -1
- jaclang/langserve/utils.py +17 -3
- jaclang/plugin/default.py +80 -43
- jaclang/plugin/feature.py +12 -2
- jaclang/plugin/plugin.md +471 -0
- jaclang/plugin/spec.py +14 -1
- jaclang/plugin/tests/fixtures/graph_purger.jac +101 -0
- jaclang/plugin/tests/fixtures/other_root_access.jac +9 -0
- jaclang/plugin/tests/test_jaseci.py +126 -6
- jaclang/runtimelib/architype.py +12 -1
- jaclang/runtimelib/context.py +2 -0
- jaclang/runtimelib/importer.py +7 -2
- jaclang/runtimelib/machine.py +21 -6
- jaclang/runtimelib/memory.py +5 -1
- jaclang/settings.py +3 -0
- jaclang/tests/fixtures/architype_def_bug.jac +17 -0
- jaclang/tests/fixtures/builtin_dotgen.jac +6 -6
- jaclang/tests/fixtures/decl_defn_param_name.jac +19 -0
- jaclang/tests/fixtures/enum_inside_archtype.jac +16 -11
- jaclang/tests/fixtures/expr_type.jac +54 -0
- jaclang/tests/fixtures/glob_multivar_statement.jac +15 -0
- jaclang/tests/fixtures/multi_dim_array_split.jac +19 -0
- jaclang/tests/fixtures/registry.jac +20 -8
- jaclang/tests/foo/__init__.jac +0 -0
- jaclang/tests/main.jac +2 -0
- jaclang/tests/test_cli.py +86 -4
- jaclang/tests/test_language.py +104 -27
- jaclang/utils/helpers.py +92 -14
- jaclang/utils/lang_tools.py +6 -2
- jaclang/utils/treeprinter.py +4 -2
- {jaclang-0.7.23.dist-info → jaclang-0.7.26.dist-info}/METADATA +2 -1
- {jaclang-0.7.23.dist-info → jaclang-0.7.26.dist-info}/RECORD +68 -57
- {jaclang-0.7.23.dist-info → jaclang-0.7.26.dist-info}/WHEEL +1 -1
- {jaclang-0.7.23.dist-info → jaclang-0.7.26.dist-info}/entry_points.txt +0 -0
|
@@ -269,6 +269,75 @@ class TestJaseciPlugin(TestCase):
|
|
|
269
269
|
)
|
|
270
270
|
self._del_session(session)
|
|
271
271
|
|
|
272
|
+
def test_walker_purger(self) -> None:
|
|
273
|
+
"""Test simple persistent object."""
|
|
274
|
+
session = self.fixture_abs_path("test_walker_purger.session")
|
|
275
|
+
self._output2buffer()
|
|
276
|
+
cli.enter(
|
|
277
|
+
filename=self.fixture_abs_path("graph_purger.jac"),
|
|
278
|
+
session=session,
|
|
279
|
+
entrypoint="populate",
|
|
280
|
+
args=[],
|
|
281
|
+
)
|
|
282
|
+
cli.enter(
|
|
283
|
+
filename=self.fixture_abs_path("graph_purger.jac"),
|
|
284
|
+
session=session,
|
|
285
|
+
entrypoint="traverse",
|
|
286
|
+
args=[],
|
|
287
|
+
)
|
|
288
|
+
cli.enter(
|
|
289
|
+
filename=self.fixture_abs_path("graph_purger.jac"),
|
|
290
|
+
session=session,
|
|
291
|
+
entrypoint="check",
|
|
292
|
+
args=[],
|
|
293
|
+
)
|
|
294
|
+
cli.enter(
|
|
295
|
+
filename=self.fixture_abs_path("graph_purger.jac"),
|
|
296
|
+
session=session,
|
|
297
|
+
entrypoint="purge",
|
|
298
|
+
args=[],
|
|
299
|
+
)
|
|
300
|
+
output = self.capturedOutput.getvalue().strip()
|
|
301
|
+
self.assertEqual(
|
|
302
|
+
output,
|
|
303
|
+
(
|
|
304
|
+
"Root()\n"
|
|
305
|
+
"A(id=0)\nA(id=1)\n"
|
|
306
|
+
"B(id=0)\nB(id=1)\nB(id=0)\nB(id=1)\n"
|
|
307
|
+
"C(id=0)\nC(id=1)\nC(id=0)\nC(id=1)\nC(id=0)\nC(id=1)\nC(id=0)\nC(id=1)\n"
|
|
308
|
+
"D(id=0)\nD(id=1)\nD(id=0)\nD(id=1)\nD(id=0)\nD(id=1)\nD(id=0)\nD(id=1)\n"
|
|
309
|
+
"D(id=0)\nD(id=1)\nD(id=0)\nD(id=1)\nD(id=0)\nD(id=1)\nD(id=0)\nD(id=1)\n"
|
|
310
|
+
"E(id=0)\nE(id=1)\nE(id=0)\nE(id=1)\nE(id=0)\nE(id=1)\nE(id=0)\nE(id=1)\n"
|
|
311
|
+
"E(id=0)\nE(id=1)\nE(id=0)\nE(id=1)\nE(id=0)\nE(id=1)\nE(id=0)\nE(id=1)\n"
|
|
312
|
+
"E(id=0)\nE(id=1)\nE(id=0)\nE(id=1)\nE(id=0)\nE(id=1)\nE(id=0)\nE(id=1)\n"
|
|
313
|
+
"E(id=0)\nE(id=1)\nE(id=0)\nE(id=1)\nE(id=0)\nE(id=1)\nE(id=0)\nE(id=1)\n"
|
|
314
|
+
"125\n124"
|
|
315
|
+
),
|
|
316
|
+
)
|
|
317
|
+
self._output2buffer()
|
|
318
|
+
cli.enter(
|
|
319
|
+
filename=self.fixture_abs_path("graph_purger.jac"),
|
|
320
|
+
session=session,
|
|
321
|
+
entrypoint="traverse",
|
|
322
|
+
args=[],
|
|
323
|
+
)
|
|
324
|
+
cli.enter(
|
|
325
|
+
filename=self.fixture_abs_path("graph_purger.jac"),
|
|
326
|
+
session=session,
|
|
327
|
+
entrypoint="check",
|
|
328
|
+
args=[],
|
|
329
|
+
)
|
|
330
|
+
cli.enter(
|
|
331
|
+
filename=self.fixture_abs_path("graph_purger.jac"),
|
|
332
|
+
session=session,
|
|
333
|
+
entrypoint="purge",
|
|
334
|
+
args=[],
|
|
335
|
+
)
|
|
336
|
+
output = self.capturedOutput.getvalue().strip()
|
|
337
|
+
self.assertEqual(output, "Root()\n1\n0")
|
|
338
|
+
|
|
339
|
+
self._del_session(session)
|
|
340
|
+
|
|
272
341
|
def trigger_access_validation_test(
|
|
273
342
|
self, give_access_to_full_graph: bool, via_all: bool = False
|
|
274
343
|
) -> None:
|
|
@@ -340,6 +409,55 @@ class TestJaseciPlugin(TestCase):
|
|
|
340
409
|
self.assertEqual(archs[0], "A(val=2)")
|
|
341
410
|
self.assertEqual(archs[1], "A(val=1)")
|
|
342
411
|
|
|
412
|
+
##############################################
|
|
413
|
+
# WITH READ ACCESS BUT ELEVATED #
|
|
414
|
+
##############################################
|
|
415
|
+
|
|
416
|
+
self._output2buffer()
|
|
417
|
+
|
|
418
|
+
cli.enter(
|
|
419
|
+
filename=self.fixture_abs_path("other_root_access.jac"),
|
|
420
|
+
entrypoint="update_node_forced",
|
|
421
|
+
args=[20],
|
|
422
|
+
session=session,
|
|
423
|
+
root=self.roots[0],
|
|
424
|
+
node=self.nodes[1],
|
|
425
|
+
)
|
|
426
|
+
cli.enter(
|
|
427
|
+
filename=self.fixture_abs_path("other_root_access.jac"),
|
|
428
|
+
entrypoint="update_node_forced",
|
|
429
|
+
args=[10],
|
|
430
|
+
session=session,
|
|
431
|
+
root=self.roots[1],
|
|
432
|
+
node=self.nodes[0],
|
|
433
|
+
)
|
|
434
|
+
|
|
435
|
+
cli.enter(
|
|
436
|
+
filename=self.fixture_abs_path("other_root_access.jac"),
|
|
437
|
+
entrypoint="check_node",
|
|
438
|
+
args=[],
|
|
439
|
+
session=session,
|
|
440
|
+
root=self.roots[0],
|
|
441
|
+
node=self.nodes[1],
|
|
442
|
+
)
|
|
443
|
+
cli.enter(
|
|
444
|
+
filename=self.fixture_abs_path("other_root_access.jac"),
|
|
445
|
+
entrypoint="check_node",
|
|
446
|
+
args=[],
|
|
447
|
+
session=session,
|
|
448
|
+
root=self.roots[1],
|
|
449
|
+
node=self.nodes[0],
|
|
450
|
+
)
|
|
451
|
+
archs = self.capturedOutput.getvalue().strip().split("\n")
|
|
452
|
+
self.assertTrue(len(archs) == 2)
|
|
453
|
+
|
|
454
|
+
# ---------- UPDATE SHOULD HAPPEN ---------- #
|
|
455
|
+
|
|
456
|
+
self.assertEqual(archs[0], "A(val=20)")
|
|
457
|
+
self.assertEqual(archs[1], "A(val=10)")
|
|
458
|
+
|
|
459
|
+
# ---------- DISALLOW READ ACCESS ---------- #
|
|
460
|
+
|
|
343
461
|
self._output2buffer()
|
|
344
462
|
cli.enter(
|
|
345
463
|
filename=self.fixture_abs_path("other_root_access.jac"),
|
|
@@ -400,7 +518,7 @@ class TestJaseciPlugin(TestCase):
|
|
|
400
518
|
cli.enter(
|
|
401
519
|
filename=self.fixture_abs_path("other_root_access.jac"),
|
|
402
520
|
entrypoint="update_node",
|
|
403
|
-
args=[
|
|
521
|
+
args=[200],
|
|
404
522
|
root=self.roots[0],
|
|
405
523
|
node=self.nodes[1],
|
|
406
524
|
session=session,
|
|
@@ -408,7 +526,7 @@ class TestJaseciPlugin(TestCase):
|
|
|
408
526
|
cli.enter(
|
|
409
527
|
filename=self.fixture_abs_path("other_root_access.jac"),
|
|
410
528
|
entrypoint="update_node",
|
|
411
|
-
args=[
|
|
529
|
+
args=[100],
|
|
412
530
|
session=session,
|
|
413
531
|
root=self.roots[1],
|
|
414
532
|
node=self.nodes[0],
|
|
@@ -433,10 +551,12 @@ class TestJaseciPlugin(TestCase):
|
|
|
433
551
|
archs = self.capturedOutput.getvalue().strip().split("\n")
|
|
434
552
|
self.assertTrue(len(archs) == 2)
|
|
435
553
|
|
|
436
|
-
#
|
|
554
|
+
# ---------- UPDATE SHOULD HAPPEN ---------- #
|
|
437
555
|
|
|
438
|
-
self.assertEqual(archs[0], "A(val=
|
|
439
|
-
self.assertEqual(archs[1], "A(val=
|
|
556
|
+
self.assertEqual(archs[0], "A(val=200)")
|
|
557
|
+
self.assertEqual(archs[1], "A(val=100)")
|
|
558
|
+
|
|
559
|
+
# ---------- DISALLOW WRITE ACCESS --------- #
|
|
440
560
|
|
|
441
561
|
self._output2buffer()
|
|
442
562
|
cli.enter(
|
|
@@ -474,7 +594,7 @@ class TestJaseciPlugin(TestCase):
|
|
|
474
594
|
)
|
|
475
595
|
self.assertFalse(self.capturedOutput.getvalue().strip())
|
|
476
596
|
|
|
477
|
-
#
|
|
597
|
+
# ---------- ROOTS RESET OWN NODE ---------- #
|
|
478
598
|
|
|
479
599
|
cli.enter(
|
|
480
600
|
filename=self.fixture_abs_path("other_root_access.jac"),
|
jaclang/runtimelib/architype.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import inspect
|
|
5
6
|
from dataclasses import asdict, dataclass, field, fields, is_dataclass
|
|
6
7
|
from enum import IntEnum
|
|
7
8
|
from logging import getLogger
|
|
@@ -291,9 +292,19 @@ class DSFunc:
|
|
|
291
292
|
"""Data Spatial Function."""
|
|
292
293
|
|
|
293
294
|
name: str
|
|
294
|
-
trigger: type | UnionType | tuple[type | UnionType, ...] | None
|
|
295
295
|
func: Callable[[Any, Any], Any] | None = None
|
|
296
296
|
|
|
297
297
|
def resolve(self, cls: type) -> None:
|
|
298
298
|
"""Resolve the function."""
|
|
299
299
|
self.func = getattr(cls, self.name)
|
|
300
|
+
|
|
301
|
+
def get_funcparam_annotations(
|
|
302
|
+
self, func: Callable[[Any, Any], Any] | None
|
|
303
|
+
) -> type | UnionType | tuple[type | UnionType, ...] | None:
|
|
304
|
+
"""Get function parameter annotations."""
|
|
305
|
+
if not func:
|
|
306
|
+
return None
|
|
307
|
+
annotation = (
|
|
308
|
+
inspect.signature(func, eval_str=True).parameters["_jac_here_"].annotation
|
|
309
|
+
)
|
|
310
|
+
return annotation if annotation != inspect._empty else None
|
jaclang/runtimelib/context.py
CHANGED
|
@@ -4,6 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import unittest
|
|
6
6
|
from contextvars import ContextVar
|
|
7
|
+
from dataclasses import MISSING
|
|
7
8
|
from typing import Any, Callable, Optional, cast
|
|
8
9
|
from uuid import UUID
|
|
9
10
|
|
|
@@ -26,6 +27,7 @@ class ExecutionContext:
|
|
|
26
27
|
|
|
27
28
|
mem: Memory
|
|
28
29
|
reports: list[Any]
|
|
30
|
+
custom: Any = MISSING
|
|
29
31
|
system_root: NodeAnchor
|
|
30
32
|
root: NodeAnchor
|
|
31
33
|
entry_node: NodeAnchor
|
jaclang/runtimelib/importer.py
CHANGED
|
@@ -344,14 +344,19 @@ class JacImporter(Importer):
|
|
|
344
344
|
cachable=spec.cachable,
|
|
345
345
|
reload=reload if reload else False,
|
|
346
346
|
)
|
|
347
|
+
|
|
348
|
+
# Since this is a compile time error, we can safely raise an exception here.
|
|
349
|
+
if not codeobj:
|
|
350
|
+
raise ImportError(f"No bytecode found for {spec.full_target}")
|
|
351
|
+
|
|
347
352
|
try:
|
|
348
|
-
if not codeobj:
|
|
349
|
-
raise ImportError(f"No bytecode found for {spec.full_target}")
|
|
350
353
|
with sys_path_context(spec.caller_dir):
|
|
351
354
|
exec(codeobj, module.__dict__)
|
|
352
355
|
except Exception as e:
|
|
356
|
+
logger.error(e)
|
|
353
357
|
logger.error(dump_traceback(e))
|
|
354
358
|
raise e
|
|
359
|
+
|
|
355
360
|
import_return = ImportReturn(module, unique_loaded_items, self)
|
|
356
361
|
if spec.items:
|
|
357
362
|
import_return.process_items(
|
jaclang/runtimelib/machine.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"""Jac Machine module."""
|
|
2
2
|
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
3
5
|
import inspect
|
|
4
6
|
import marshal
|
|
5
7
|
import os
|
|
@@ -12,6 +14,7 @@ from typing import Optional, Union
|
|
|
12
14
|
from jaclang.compiler.absyntree import Module
|
|
13
15
|
from jaclang.compiler.compile import compile_jac
|
|
14
16
|
from jaclang.compiler.constant import Constants as Con
|
|
17
|
+
from jaclang.compiler.semtable import SemRegistry
|
|
15
18
|
from jaclang.runtimelib.architype import (
|
|
16
19
|
Architype,
|
|
17
20
|
EdgeArchitype,
|
|
@@ -70,6 +73,14 @@ class JacMachine:
|
|
|
70
73
|
)
|
|
71
74
|
return None
|
|
72
75
|
|
|
76
|
+
def get_sem_ir(self, mod_sem_ir: SemRegistry | None) -> None:
|
|
77
|
+
"""Update semtable on the attached JacProgram."""
|
|
78
|
+
if self.jac_program and mod_sem_ir:
|
|
79
|
+
if self.jac_program.sem_ir:
|
|
80
|
+
self.jac_program.sem_ir.registry.update(mod_sem_ir.registry)
|
|
81
|
+
else:
|
|
82
|
+
self.jac_program.sem_ir = mod_sem_ir
|
|
83
|
+
|
|
73
84
|
def load_module(self, module_name: str, module: types.ModuleType) -> None:
|
|
74
85
|
"""Load a module into the machine."""
|
|
75
86
|
self.loaded_modules[module_name] = module
|
|
@@ -263,14 +274,18 @@ class JacMachine:
|
|
|
263
274
|
|
|
264
275
|
|
|
265
276
|
class JacProgram:
|
|
266
|
-
"""Class to hold the mod_bundle and
|
|
277
|
+
"""Class to hold the mod_bundle bytecode and sem_ir for Jac modules."""
|
|
267
278
|
|
|
268
279
|
def __init__(
|
|
269
|
-
self,
|
|
280
|
+
self,
|
|
281
|
+
mod_bundle: Optional[Module],
|
|
282
|
+
bytecode: Optional[dict[str, bytes]],
|
|
283
|
+
sem_ir: Optional[SemRegistry],
|
|
270
284
|
) -> None:
|
|
271
285
|
"""Initialize the JacProgram object."""
|
|
272
286
|
self.mod_bundle = mod_bundle
|
|
273
287
|
self.bytecode = bytecode or {}
|
|
288
|
+
self.sem_ir = sem_ir if sem_ir else SemRegistry()
|
|
274
289
|
|
|
275
290
|
def get_bytecode(
|
|
276
291
|
self,
|
|
@@ -292,10 +307,10 @@ class JacProgram:
|
|
|
292
307
|
|
|
293
308
|
result = compile_jac(full_target, cache_result=cachable)
|
|
294
309
|
if result.errors_had or not result.ir.gen.py_bytecode:
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
310
|
+
for alrt in result.errors_had:
|
|
311
|
+
# We're not logging here, it already gets logged as the errors were added to the errors_had list.
|
|
312
|
+
# Regardless of the logging, this needs to be sent to the end user, so we'll printing it to stderr.
|
|
313
|
+
logger.error(alrt.pretty_print())
|
|
299
314
|
return None
|
|
300
315
|
if result.ir.gen.py_bytecode is not None:
|
|
301
316
|
return marshal.loads(result.ir.gen.py_bytecode)
|
jaclang/runtimelib/memory.py
CHANGED
|
@@ -25,6 +25,10 @@ class Memory(Generic[ID, TANCH]):
|
|
|
25
25
|
self.__mem__.clear()
|
|
26
26
|
self.__gc__.clear()
|
|
27
27
|
|
|
28
|
+
def is_cached(self, id: ID) -> bool:
|
|
29
|
+
"""Check if id if already cached."""
|
|
30
|
+
return id in self.__mem__
|
|
31
|
+
|
|
28
32
|
def find(
|
|
29
33
|
self,
|
|
30
34
|
ids: ID | Iterable[ID],
|
|
@@ -96,7 +100,7 @@ class ShelfStorage(Memory[UUID, Anchor]):
|
|
|
96
100
|
and p_d.edges != d.edges
|
|
97
101
|
and Jac.check_connect_access(d)
|
|
98
102
|
):
|
|
99
|
-
if not d.edges:
|
|
103
|
+
if not d.edges and not isinstance(d.architype, Root):
|
|
100
104
|
self.__shelf__.pop(_id, None)
|
|
101
105
|
continue
|
|
102
106
|
p_d.edges = d.edges
|
jaclang/settings.py
CHANGED
|
@@ -58,6 +58,9 @@ class Settings:
|
|
|
58
58
|
"""Override settings from environment variables if available."""
|
|
59
59
|
for key in [f.name for f in fields(self)]:
|
|
60
60
|
env_value = os.getenv("JACLANG_" + key.upper())
|
|
61
|
+
env_value = (
|
|
62
|
+
env_value if env_value is not None else os.getenv("JAC_" + key.upper())
|
|
63
|
+
)
|
|
61
64
|
if env_value is not None:
|
|
62
65
|
setattr(self, key, self.convert_type(env_value))
|
|
63
66
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# fix test type 2
|
|
2
|
+
walker MyWalker {
|
|
3
|
+
can travel with `root | MyNode entry {
|
|
4
|
+
print("MyWalker");
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
node MyNode {
|
|
9
|
+
can work with MyWalker entry {
|
|
10
|
+
print("MyNode");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
with entry {
|
|
15
|
+
Node_1 = MyNode();
|
|
16
|
+
Node_1 spawn MyWalker();
|
|
17
|
+
}
|
|
@@ -27,11 +27,11 @@ with entry{
|
|
|
27
27
|
d3=dotgen(b[2],edge_limit=5,depth=5);l3=d3|>len; #generate dot for all connected with b[1] node
|
|
28
28
|
d4=dotgen(b[1],bfs=True,edge_type= ["Edge1"],node_limit=100,edge_limit=900,depth=300);l4=d4|>len; #generate dot from nodes with depth 3 connected with b[1] node
|
|
29
29
|
d5=dotgen(b[1],node_limit=10,edge_limit=90);l5:=d5|>len; #generate dot from nodes with depth 3 connected with b[1] node
|
|
30
|
-
print(d1.count('a(val')==12,d1.count('#FFFFE0')==3,'Root' in d1,d1.count('
|
|
31
|
-
print(d2.count('a(val')==19,d2.count('#F5E5FF')==2 ,'Edge1' not in d2,d2.count('
|
|
32
|
-
print(d3.count('a(val')==6,d3.count("
|
|
33
|
-
print(d4.count("a(val")==25,d4.count("
|
|
34
|
-
print(d5.count("Edge1(val=6)")==2, d5.count("
|
|
30
|
+
print(d1.count('a(val')==12,d1.count('#FFFFE0')==3,'Root' in d1,d1.count('label=""')==30);
|
|
31
|
+
print(d2.count('a(val')==19,d2.count('#F5E5FF')==2 ,'Edge1' not in d2,d2.count('label=""')==42);
|
|
32
|
+
print(d3.count('a(val')==6,d3.count('label=""')==5,d3.count('#F5E5FF')==1);
|
|
33
|
+
print(d4.count("a(val")==25,d4.count('label=""')==66,d4.count('#FFF0F')==3);
|
|
34
|
+
print(d5.count("Edge1(val=6)")==2, d5.count('label=""')==24);
|
|
35
35
|
# print(l3<l2);
|
|
36
36
|
# print(d1);
|
|
37
37
|
# print(d2);
|
|
@@ -39,4 +39,4 @@ with entry{
|
|
|
39
39
|
# print(d4);
|
|
40
40
|
# print(dotgen(node=b[2],bfs=True,depth=3.96,edge_limit=12,node_limit=12.96));
|
|
41
41
|
|
|
42
|
-
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
obj SomeClass {
|
|
3
|
+
can method1(some_long_paramenter_name: int) -> None;
|
|
4
|
+
can method2(param1:int, param2:str) -> None;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
:o:SomeClass:c:method1(short_name:int) -> None {
|
|
8
|
+
print("short_name =", short_name);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
:o:SomeClass:c:method2(p1:int, p2: str) -> None {
|
|
12
|
+
print("p1 =", p1, ", p2 =", p2);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
with entry {
|
|
16
|
+
sc = SomeClass();
|
|
17
|
+
sc.method1(42);
|
|
18
|
+
sc.method2(64, "foobar");
|
|
19
|
+
}
|
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
obj outer{
|
|
2
|
-
has o1:int=9;
|
|
1
|
+
obj outer {
|
|
2
|
+
has o1: int = 9;
|
|
3
3
|
|
|
4
|
-
obj inner{
|
|
5
|
-
has i1:int=8;
|
|
4
|
+
obj inner {
|
|
5
|
+
has i1: int = 8;
|
|
6
6
|
}
|
|
7
|
-
can foo(){
|
|
7
|
+
can foo() {
|
|
8
8
|
return 'foo';
|
|
9
9
|
}
|
|
10
|
-
enum
|
|
10
|
+
enum color {
|
|
11
11
|
red,
|
|
12
12
|
green,
|
|
13
|
-
blue
|
|
13
|
+
blue,
|
|
14
|
+
with entry {
|
|
15
|
+
print('Initializing role system..');
|
|
16
|
+
},
|
|
17
|
+
can foo -> str {
|
|
18
|
+
return 'Accessing privileged Data';
|
|
14
19
|
}
|
|
15
|
-
|
|
20
|
+
}
|
|
16
21
|
}
|
|
17
22
|
|
|
18
|
-
with entry{
|
|
19
|
-
print(outer.color.green.value);
|
|
20
|
-
}
|
|
23
|
+
with entry {
|
|
24
|
+
print(outer.color.green.value, outer.color.foo());
|
|
25
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
with entry {
|
|
2
|
+
a = 4;
|
|
3
|
+
b = 7;
|
|
4
|
+
c = a + b; # OpExpr.
|
|
5
|
+
d = a + b + c;
|
|
6
|
+
|
|
7
|
+
h = float(a); # CallExpr.
|
|
8
|
+
|
|
9
|
+
(1 < 2); # ComparisonExpr.
|
|
10
|
+
('a' + 'b').upper(); # CallExpr.
|
|
11
|
+
[1,2][0]; # IndexExpr.
|
|
12
|
+
not False; # UnaryExpr.
|
|
13
|
+
"a" if True else "b"; # ConditionalExpr.
|
|
14
|
+
[i for i in range(10)]; # ListComprehension.
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
# Remaining expressions to test:
|
|
18
|
+
# AssertTypeExpr,
|
|
19
|
+
# AssignmentExpr,
|
|
20
|
+
# AwaitExpr,
|
|
21
|
+
# BytesExpr,
|
|
22
|
+
# CastExpr,
|
|
23
|
+
# ComplexExpr,
|
|
24
|
+
# DictionaryComprehension,
|
|
25
|
+
# DictExpr,
|
|
26
|
+
# EllipsisExpr,
|
|
27
|
+
# EnumCallExpr,
|
|
28
|
+
# Expression,
|
|
29
|
+
# FloatExpr,
|
|
30
|
+
# GeneratorExpr,
|
|
31
|
+
# IntExpr,
|
|
32
|
+
# LambdaExpr,
|
|
33
|
+
# ListExpr,
|
|
34
|
+
# MemberExpr,
|
|
35
|
+
# NamedTupleExpr,
|
|
36
|
+
# NameExpr,
|
|
37
|
+
# NewTypeExpr,
|
|
38
|
+
# ParamSpecExpr,
|
|
39
|
+
# PromoteExpr,
|
|
40
|
+
# RefExpr,
|
|
41
|
+
# RevealExpr,
|
|
42
|
+
# SetComprehension,
|
|
43
|
+
# SetExpr,
|
|
44
|
+
# SliceExpr,
|
|
45
|
+
# StarExpr,
|
|
46
|
+
# StrExpr,
|
|
47
|
+
# SuperExpr,
|
|
48
|
+
# TupleExpr,
|
|
49
|
+
# TypeAliasExpr,
|
|
50
|
+
# TypedDictExpr,
|
|
51
|
+
# TypeVarExpr,
|
|
52
|
+
# TypeVarTupleExpr,
|
|
53
|
+
# YieldExpr,
|
|
54
|
+
# YieldFromExpr,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import:py numpy as np;
|
|
2
|
+
|
|
3
|
+
with entry {
|
|
4
|
+
arr = np.array(
|
|
5
|
+
[[1, 2, 3, 4, 5],
|
|
6
|
+
[6, 7, 8, 9, 10],
|
|
7
|
+
[11, 12, 13, 14, 15],
|
|
8
|
+
[16, 17, 18, 19, 20],
|
|
9
|
+
[21, 22, 23, 24, 25]]
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
print('Original Array:');
|
|
13
|
+
print(arr);
|
|
14
|
+
|
|
15
|
+
print();
|
|
16
|
+
|
|
17
|
+
print('Sliced Array:');
|
|
18
|
+
print(arr[1:3, 1::2]);
|
|
19
|
+
}
|
|
@@ -13,16 +13,16 @@ Person {
|
|
|
13
13
|
|
|
14
14
|
enum 'Personality of the Person'
|
|
15
15
|
Personality {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
INTROVERT: 'Person who is shy and reticent' = 9,
|
|
17
|
+
EXTROVERT: 'Person who is outgoing and socially confident'
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
glob personality_examples: 'Personality Information of Famous People': dict[str, Personality|None] = {
|
|
20
|
+
glob personality_examples: 'Personality Information of Famous People': dict[str, Personality | None] = {
|
|
21
21
|
'Albert Einstein': Personality.INTROVERT,
|
|
22
22
|
'Barack Obama': Personality.EXTROVERT
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
glob person_value
|
|
25
|
+
glob person_value: list[tuple[dict[str, Personality], int]] = (-90);
|
|
26
26
|
|
|
27
27
|
can 'GenAI ability'
|
|
28
28
|
genai_ability(x: 'Something': str) -> 'Something Else': str by llm();
|
|
@@ -34,13 +34,25 @@ normal_ability(x: 'Something': str) -> 'Something Else': str {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
can foo() {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
person_value = 22;
|
|
38
|
+
can bar() {
|
|
39
|
+
person_value = 33;
|
|
40
|
+
}
|
|
41
41
|
}
|
|
42
42
|
with entry {
|
|
43
43
|
einstein_age: int = 75;
|
|
44
44
|
einstein_age += 1;
|
|
45
45
|
einstein = Person('Albert Einstein', einstein_age);
|
|
46
46
|
}
|
|
47
|
+
|
|
48
|
+
import from jaclang.runtimelib.machine { JacMachine }
|
|
49
|
+
|
|
50
|
+
with entry {
|
|
51
|
+
registry = JacMachine.get().jac_program.sem_ir;
|
|
52
|
+
|
|
53
|
+
print(len(registry.registry));
|
|
54
|
+
print(len(list(registry.registry.items())[0][1]));
|
|
55
|
+
print(list(registry.registry.items())[3][0].scope);
|
|
56
|
+
(_, sem_info) = registry.lookup(name="normal_ability");
|
|
57
|
+
print(len(sem_info.get_children(registry)));
|
|
58
|
+
}
|
|
File without changes
|
jaclang/tests/main.jac
ADDED