jaclang 0.0.1__py3-none-any.whl → 0.0.3__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.

Files changed (73) hide show
  1. jaclang/__init__.py +4 -0
  2. jaclang/cli/__init__.py +7 -0
  3. jaclang/cli/cli.jac +46 -0
  4. jaclang/cli/cmds.jac +14 -0
  5. jaclang/cli/impl/__init__.py +1 -0
  6. jaclang/cli/impl/cli_impl.jac +93 -0
  7. jaclang/cli/impl/cmds_impl.jac +26 -0
  8. jaclang/core/__init__.py +12 -0
  9. jaclang/core/impl/__init__.py +1 -0
  10. jaclang/core/impl/arch_impl.jac +112 -0
  11. jaclang/core/impl/element_impl.jac +95 -0
  12. jaclang/core/impl/exec_ctx_impl.jac +17 -0
  13. jaclang/core/impl/memory_impl.jac +57 -0
  14. jaclang/core/primitives.jac +104 -0
  15. jaclang/jac/__init__.py +1 -0
  16. jaclang/jac/absyntree.py +1787 -0
  17. jaclang/jac/constant.py +46 -0
  18. jaclang/jac/importer.py +130 -0
  19. jaclang/jac/lexer.py +538 -0
  20. jaclang/jac/parser.py +1474 -0
  21. jaclang/jac/passes/__init__.py +5 -0
  22. jaclang/jac/passes/blue/__init__.py +25 -0
  23. jaclang/jac/passes/blue/ast_build_pass.py +3190 -0
  24. jaclang/jac/passes/blue/blue_pygen_pass.py +1335 -0
  25. jaclang/jac/passes/blue/decl_def_match_pass.py +278 -0
  26. jaclang/jac/passes/blue/import_pass.py +75 -0
  27. jaclang/jac/passes/blue/sub_node_tab_pass.py +30 -0
  28. jaclang/jac/passes/blue/tests/__init__.py +1 -0
  29. jaclang/jac/passes/blue/tests/test_ast_build_pass.py +61 -0
  30. jaclang/jac/passes/blue/tests/test_blue_pygen_pass.py +117 -0
  31. jaclang/jac/passes/blue/tests/test_decl_def_match_pass.py +43 -0
  32. jaclang/jac/passes/blue/tests/test_import_pass.py +18 -0
  33. jaclang/jac/passes/blue/tests/test_sub_node_pass.py +26 -0
  34. jaclang/jac/passes/blue/tests/test_type_analyze_pass.py +53 -0
  35. jaclang/jac/passes/blue/type_analyze_pass.py +731 -0
  36. jaclang/jac/passes/ir_pass.py +154 -0
  37. jaclang/jac/passes/purple/__init__.py +17 -0
  38. jaclang/jac/passes/purple/impl/__init__.py +1 -0
  39. jaclang/jac/passes/purple/impl/purple_pygen_pass_impl.jac +289 -0
  40. jaclang/jac/passes/purple/purple_pygen_pass.jac +35 -0
  41. jaclang/jac/sym_table.py +127 -0
  42. jaclang/jac/tests/__init__.py +1 -0
  43. jaclang/jac/tests/fixtures/__init__.py +1 -0
  44. jaclang/jac/tests/fixtures/activity.py +10 -0
  45. jaclang/jac/tests/fixtures/fam.jac +68 -0
  46. jaclang/jac/tests/fixtures/hello_world.jac +5 -0
  47. jaclang/jac/tests/fixtures/lexer_fam.jac +61 -0
  48. jaclang/jac/tests/fixtures/stuff.jac +6 -0
  49. jaclang/jac/tests/test_importer.py +24 -0
  50. jaclang/jac/tests/test_lexer.py +57 -0
  51. jaclang/jac/tests/test_parser.py +50 -0
  52. jaclang/jac/tests/test_utils.py +12 -0
  53. jaclang/jac/transform.py +63 -0
  54. jaclang/jac/transpiler.py +69 -0
  55. jaclang/jac/utils.py +120 -0
  56. jaclang/utils/__init__.py +1 -0
  57. jaclang/utils/fstring_parser.py +73 -0
  58. jaclang/utils/log.py +9 -0
  59. jaclang/utils/sly/__init__.py +6 -0
  60. jaclang/utils/sly/docparse.py +62 -0
  61. jaclang/utils/sly/lex.py +510 -0
  62. jaclang/utils/sly/yacc.py +2398 -0
  63. jaclang/utils/test.py +81 -0
  64. jaclang/utils/tests/__init__.py +1 -0
  65. jaclang/utils/tests/test_fstring_parser.py +55 -0
  66. jaclang-0.0.3.dist-info/METADATA +12 -0
  67. jaclang-0.0.3.dist-info/RECORD +70 -0
  68. {jaclang-0.0.1.dist-info → jaclang-0.0.3.dist-info}/WHEEL +1 -1
  69. jaclang-0.0.3.dist-info/entry_points.txt +3 -0
  70. jaclang-0.0.3.dist-info/top_level.txt +1 -0
  71. jaclang-0.0.1.dist-info/METADATA +0 -7
  72. jaclang-0.0.1.dist-info/RECORD +0 -4
  73. jaclang-0.0.1.dist-info/top_level.txt +0 -1
@@ -0,0 +1,46 @@
1
+ """Constants across the project."""
2
+ from enum import Enum, auto
3
+
4
+
5
+ class Constants(str, Enum):
6
+ """Token constants for Jac."""
7
+
8
+ INIT_FUNC = "init"
9
+ JAC_LANG_IMP = "jac"
10
+ JAC_DEBUG_SPLITTER = "JAC DEBUG INFO"
11
+ PATCH = "PATCH"
12
+
13
+ JAC_TMP = "_jac_tmp"
14
+ EXEC_CONTEXT = "_jac_exec_ctx_"
15
+ HERE = "_jac_here_"
16
+ ROOT = f"{EXEC_CONTEXT}.get_root()"
17
+ EDGES_TO_NODE = "_jac_edges_to_nodes_"
18
+ EDGE_REF = "_jac_edge_ref_"
19
+ CONNECT_NODE = "_jac_connect_node_"
20
+ DISCONNECT_NODE = "_jac_disconnect_node_"
21
+ WALKER_VISIT = "_jac_visit_"
22
+ DISENGAGE = "_jac_disengage_"
23
+ OBJECT_CLASS = "_jac_Object_"
24
+ NODE_CLASS = "_jac_Node_"
25
+ EDGE_CLASS = "_jac_Edge_"
26
+ WALKER_CLASS = "_jac_Walker_"
27
+ WITH_DIR = "_jac_apply_dir_"
28
+ EDGE_DIR = "_jac_Edge_Dir_"
29
+
30
+ def __str__(self) -> str:
31
+ """Return the string representation of the token."""
32
+ return self.value
33
+
34
+
35
+ class EdgeDir(Enum):
36
+ """Edge direction indicator."""
37
+
38
+ IN = auto()
39
+ OUT = auto()
40
+ ANY = auto()
41
+
42
+
43
+ class Values(int, Enum):
44
+ """Token constants for Jac."""
45
+
46
+ JAC_ERROR_LINE_RANGE = 3
@@ -0,0 +1,130 @@
1
+ """Special Imports for Jac Code."""
2
+ import inspect
3
+ import marshal
4
+ import sys
5
+ import traceback
6
+ import types
7
+ from os import makedirs, path
8
+ from typing import Callable, Optional
9
+
10
+ from jaclang.jac.constant import Constants as Con, Values as Val
11
+ from jaclang.jac.transpiler import transpile_jac_blue, transpile_jac_purple
12
+ from jaclang.jac.utils import add_line_numbers, clip_code_section
13
+
14
+
15
+ def import_jac_module(
16
+ transpiler_func: Callable,
17
+ target: str,
18
+ base_path: Optional[str] = None,
19
+ save_file: bool = False,
20
+ ) -> Optional[types.ModuleType]:
21
+ """Core Import Process."""
22
+ target = path.join(*(target.split("."))) + ".jac"
23
+
24
+ dir_path, file_name = path.split(target)
25
+ module_name = path.splitext(file_name)[0]
26
+ package_path = dir_path.replace(path.sep, ".")
27
+
28
+ if package_path and f"{package_path}.{module_name}" in sys.modules:
29
+ return sys.modules[f"{package_path}.{module_name}"]
30
+ elif not package_path and module_name in sys.modules:
31
+ return sys.modules[module_name]
32
+
33
+ if base_path:
34
+ caller_dir = path.dirname(base_path) if not path.isdir(base_path) else base_path
35
+ else:
36
+ frame = inspect.stack()[2]
37
+ caller_dir = path.dirname(path.abspath(frame[0].f_code.co_filename))
38
+ full_target = path.normpath(path.join(caller_dir, target))
39
+
40
+ dev_dir = path.join(caller_dir, "__jac_gen__")
41
+ makedirs(dev_dir, exist_ok=True)
42
+ py_file_path = path.join(dev_dir, module_name + ".py")
43
+ if path.exists(py_file_path) and path.getmtime(py_file_path) > path.getmtime(
44
+ full_target
45
+ ):
46
+ with open(py_file_path, "r") as f:
47
+ code_string = f.read()
48
+ else:
49
+ code_string = transpiler_func(file_path=full_target, base_dir=caller_dir)
50
+
51
+ with open(py_file_path, "w") as f:
52
+ f.write(code_string)
53
+
54
+ module = types.ModuleType(module_name)
55
+ module.__file__ = full_target
56
+ module.__name__ = module_name
57
+ module.__dict__["_jac_pycodestring_"] = code_string
58
+
59
+ if path.exists(py_file_path + "c") and path.getmtime(
60
+ py_file_path + "c"
61
+ ) > path.getmtime(full_target):
62
+ with open(py_file_path + "c", "rb") as f:
63
+ codeobj = marshal.load(f)
64
+ else:
65
+ codeobj = compile(code_string, f"_jac_py_gen ({module.__file__})", "exec")
66
+ with open(py_file_path + "c", "wb") as f:
67
+ marshal.dump(codeobj, f)
68
+
69
+ try:
70
+ exec(codeobj, module.__dict__)
71
+ except Exception as e:
72
+ traceback.print_exc()
73
+ tb = traceback.extract_tb(e.__traceback__)
74
+ handle_jac_error(code_string, e, tb)
75
+ raise e
76
+
77
+ if package_path:
78
+ parts = package_path.split(".")
79
+ for i in range(len(parts)):
80
+ package_name = ".".join(parts[: i + 1])
81
+ if package_name not in sys.modules:
82
+ sys.modules[package_name] = types.ModuleType(package_name)
83
+
84
+ setattr(sys.modules[package_path], module_name, module)
85
+ sys.modules[f"{package_path}.{module_name}"] = module
86
+ else:
87
+ sys.modules[module_name] = module
88
+
89
+ return module
90
+
91
+
92
+ def handle_jac_error(code_string: str, e: Exception, tb: traceback.StackSummary) -> str:
93
+ """Handle Jac Error."""
94
+ except_line = e.end_lineno if isinstance(e, SyntaxError) else list(tb)[-1].lineno
95
+ if not isinstance(except_line, int) or except_line == 0:
96
+ return ""
97
+ traceback.print_exc()
98
+ py_error_region = clip_code_section(
99
+ add_line_numbers(code_string), except_line, Val.JAC_ERROR_LINE_RANGE
100
+ )
101
+ try:
102
+ jac_err_line = int(code_string.splitlines()[except_line - 1].split()[-1])
103
+ mod_index = int(code_string.splitlines()[except_line].split()[-2])
104
+ mod_paths = code_string.split(Con.JAC_DEBUG_SPLITTER)[1].strip().splitlines()
105
+ with open(mod_paths[mod_index], "r") as file:
106
+ jac_code_string = file.read()
107
+ jac_error_region = clip_code_section(
108
+ add_line_numbers(jac_code_string), jac_err_line, Val.JAC_ERROR_LINE_RANGE
109
+ )
110
+ except Exception:
111
+ jac_error_region = ""
112
+ snippet = (
113
+ f"JacCode Snippet:\n{jac_error_region}\n"
114
+ f"PyCode Snippet:\n{py_error_region}\n"
115
+ )
116
+ return snippet
117
+
118
+
119
+ def jac_blue_import(
120
+ target: str, base_path: Optional[str] = None, save_file: bool = False
121
+ ) -> Optional[types.ModuleType]:
122
+ """Jac Blue Imports."""
123
+ return import_jac_module(transpile_jac_blue, target, base_path, save_file)
124
+
125
+
126
+ def jac_purple_import(
127
+ target: str, base_path: Optional[str] = None, save_file: bool = False
128
+ ) -> Optional[types.ModuleType]:
129
+ """Jac Purple Imports."""
130
+ return import_jac_module(transpile_jac_purple, target, base_path, save_file)