jaclang 0.8.6__py3-none-any.whl → 0.8.8__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 (103) hide show
  1. jaclang/cli/cli.md +3 -3
  2. jaclang/cli/cli.py +37 -37
  3. jaclang/cli/cmdreg.py +45 -140
  4. jaclang/compiler/constant.py +0 -1
  5. jaclang/compiler/jac.lark +3 -6
  6. jaclang/compiler/larkparse/jac_parser.py +2 -2
  7. jaclang/compiler/parser.py +213 -34
  8. jaclang/compiler/passes/main/__init__.py +2 -4
  9. jaclang/compiler/passes/main/def_use_pass.py +0 -4
  10. jaclang/compiler/passes/main/predynamo_pass.py +221 -0
  11. jaclang/compiler/passes/main/pyast_gen_pass.py +83 -55
  12. jaclang/compiler/passes/main/pyast_load_pass.py +66 -40
  13. jaclang/compiler/passes/main/sym_tab_build_pass.py +1 -1
  14. jaclang/compiler/passes/main/tests/fixtures/checker/import_sym.jac +2 -0
  15. jaclang/compiler/passes/main/tests/fixtures/checker/import_sym_test.jac +6 -0
  16. jaclang/compiler/passes/main/tests/fixtures/checker/imported_sym.jac +5 -0
  17. jaclang/compiler/passes/main/tests/fixtures/checker_arg_param_match.jac +37 -0
  18. jaclang/compiler/passes/main/tests/fixtures/checker_arity.jac +18 -0
  19. jaclang/compiler/passes/main/tests/fixtures/checker_binary_op.jac +21 -0
  20. jaclang/compiler/passes/main/tests/fixtures/checker_call_expr_class.jac +12 -0
  21. jaclang/compiler/passes/main/tests/fixtures/checker_cat_is_animal.jac +18 -0
  22. jaclang/compiler/passes/main/tests/fixtures/checker_cyclic_symbol.jac +4 -0
  23. jaclang/compiler/passes/main/tests/fixtures/checker_expr_call.jac +9 -0
  24. jaclang/compiler/passes/main/tests/fixtures/checker_float.jac +7 -0
  25. jaclang/compiler/passes/main/tests/fixtures/checker_import_missing_module.jac +13 -0
  26. jaclang/compiler/passes/main/tests/fixtures/checker_magic_call.jac +17 -0
  27. jaclang/compiler/passes/main/tests/fixtures/checker_mod_path.jac +8 -0
  28. jaclang/compiler/passes/main/tests/fixtures/checker_param_types.jac +11 -0
  29. jaclang/compiler/passes/main/tests/fixtures/checker_self_type.jac +9 -0
  30. jaclang/compiler/passes/main/tests/fixtures/checker_sym_inherit.jac +42 -0
  31. jaclang/compiler/passes/main/tests/fixtures/predynamo_fix3.jac +43 -0
  32. jaclang/compiler/passes/main/tests/fixtures/predynamo_where_assign.jac +13 -0
  33. jaclang/compiler/passes/main/tests/fixtures/predynamo_where_return.jac +11 -0
  34. jaclang/compiler/passes/main/tests/test_checker_pass.py +265 -0
  35. jaclang/compiler/passes/main/tests/test_predynamo_pass.py +57 -0
  36. jaclang/compiler/passes/main/type_checker_pass.py +36 -61
  37. jaclang/compiler/passes/tool/doc_ir_gen_pass.py +204 -44
  38. jaclang/compiler/passes/tool/jac_formatter_pass.py +119 -69
  39. jaclang/compiler/passes/tool/tests/fixtures/corelib_fmt.jac +3 -3
  40. jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/triple_quoted_string.jac +4 -5
  41. jaclang/compiler/passes/tool/tests/fixtures/tagbreak.jac +171 -11
  42. jaclang/compiler/passes/transform.py +12 -8
  43. jaclang/compiler/program.py +14 -6
  44. jaclang/compiler/tests/fixtures/jac_import_py_files.py +4 -0
  45. jaclang/compiler/tests/fixtures/jac_module.jac +3 -0
  46. jaclang/compiler/tests/fixtures/multiple_syntax_errors.jac +10 -0
  47. jaclang/compiler/tests/fixtures/python_module.py +1 -0
  48. jaclang/compiler/tests/test_importer.py +39 -0
  49. jaclang/compiler/tests/test_parser.py +49 -0
  50. jaclang/compiler/type_system/operations.py +104 -0
  51. jaclang/compiler/type_system/type_evaluator.py +470 -47
  52. jaclang/compiler/type_system/type_utils.py +246 -0
  53. jaclang/compiler/type_system/types.py +58 -2
  54. jaclang/compiler/unitree.py +79 -94
  55. jaclang/langserve/engine.jac +253 -230
  56. jaclang/langserve/server.jac +46 -15
  57. jaclang/langserve/tests/fixtures/circle.jac +3 -3
  58. jaclang/langserve/tests/fixtures/circle_err.jac +3 -3
  59. jaclang/langserve/tests/fixtures/circle_pure.test.jac +3 -3
  60. jaclang/langserve/tests/fixtures/completion_test_err.jac +10 -0
  61. jaclang/langserve/tests/server_test/circle_template.jac +80 -0
  62. jaclang/langserve/tests/server_test/glob_template.jac +4 -0
  63. jaclang/langserve/tests/server_test/test_lang_serve.py +154 -312
  64. jaclang/langserve/tests/server_test/utils.py +153 -116
  65. jaclang/langserve/tests/test_dev_server.py +1 -1
  66. jaclang/langserve/tests/test_server.py +30 -86
  67. jaclang/langserve/utils.jac +56 -63
  68. jaclang/runtimelib/machine.py +7 -0
  69. jaclang/runtimelib/meta_importer.py +27 -1
  70. jaclang/runtimelib/tests/fixtures/custom_access_validation.jac +1 -1
  71. jaclang/runtimelib/tests/fixtures/savable_object.jac +2 -2
  72. jaclang/settings.py +18 -14
  73. jaclang/tests/fixtures/abc_check.jac +3 -3
  74. jaclang/tests/fixtures/arch_rel_import_creation.jac +12 -12
  75. jaclang/tests/fixtures/chandra_bugs2.jac +3 -3
  76. jaclang/tests/fixtures/create_dynamic_archetype.jac +13 -13
  77. jaclang/tests/fixtures/jac_run_py_bugs.py +18 -0
  78. jaclang/tests/fixtures/jac_run_py_import.py +13 -0
  79. jaclang/tests/fixtures/lambda_arg_annotation.jac +15 -0
  80. jaclang/tests/fixtures/lambda_self.jac +18 -0
  81. jaclang/tests/fixtures/maxfail_run_test.jac +4 -4
  82. jaclang/tests/fixtures/params/param_syntax_err.jac +9 -0
  83. jaclang/tests/fixtures/params/test_complex_params.jac +42 -0
  84. jaclang/tests/fixtures/params/test_failing_kwonly.jac +207 -0
  85. jaclang/tests/fixtures/params/test_failing_posonly.jac +116 -0
  86. jaclang/tests/fixtures/params/test_failing_varargs.jac +300 -0
  87. jaclang/tests/fixtures/params/test_kwonly_params.jac +29 -0
  88. jaclang/tests/fixtures/py2jac_params.py +8 -0
  89. jaclang/tests/fixtures/run_test.jac +4 -4
  90. jaclang/tests/test_cli.py +103 -18
  91. jaclang/tests/test_language.py +74 -16
  92. jaclang/utils/helpers.py +47 -2
  93. jaclang/utils/module_resolver.py +11 -1
  94. jaclang/utils/test.py +8 -0
  95. jaclang/utils/treeprinter.py +0 -18
  96. {jaclang-0.8.6.dist-info → jaclang-0.8.8.dist-info}/METADATA +3 -3
  97. {jaclang-0.8.6.dist-info → jaclang-0.8.8.dist-info}/RECORD +99 -62
  98. {jaclang-0.8.6.dist-info → jaclang-0.8.8.dist-info}/WHEEL +1 -1
  99. jaclang/compiler/passes/main/inheritance_pass.py +0 -131
  100. jaclang/langserve/dev_engine.jac +0 -645
  101. jaclang/langserve/dev_server.jac +0 -201
  102. jaclang/langserve/tests/server_test/code_test.py +0 -0
  103. {jaclang-0.8.6.dist-info → jaclang-0.8.8.dist-info}/entry_points.txt +0 -0
@@ -1,5 +1,7 @@
1
1
  """Jaclang Language Server."""
2
2
 
3
+ import asyncio;
4
+
3
5
  import from typing { Optional }
4
6
 
5
7
  import from jaclang.compiler.constant {
@@ -17,11 +19,16 @@ with entry {
17
19
  server = JacLangServer();
18
20
  }
19
21
 
22
+ def debug(ls: JacLangServer, msg: str) -> None {
23
+ ls.log_py(f"[DEBUG] " + ("-" * 80));
24
+ ls.log_py(f"[DEBUG]' {msg} ");
25
+ ls.log_py(f"[DEBUG] " + ("-" * 80));
26
+ }
20
27
 
21
28
  """Check syntax on change."""
22
29
  @server.feature(lspt.TEXT_DOCUMENT_DID_OPEN)
23
30
  async def did_open(ls: JacLangServer, params: lspt.DidOpenTextDocumentParams) -> None {
24
- await ls.launch_deep_check(params.text_document.uri);
31
+ await ls.launch_deep_check(params.text_document.uri, delay=0.001);
25
32
  ls.lsp.send_request(lspt.WORKSPACE_SEMANTIC_TOKENS_REFRESH);
26
33
  }
27
34
 
@@ -30,38 +37,54 @@ async def did_open(ls: JacLangServer, params: lspt.DidOpenTextDocumentParams) ->
30
37
  @server.feature(lspt.TEXT_DOCUMENT_DID_SAVE)
31
38
  async def did_save(ls: JacLangServer, params: lspt.DidOpenTextDocumentParams) -> None {
32
39
  file_path = params.text_document.uri;
33
- quick_check_passed = await ls.launch_quick_check(file_path);
40
+ quick_check_passed = await ls.launch_quick_check(file_path, delay=0.1);
34
41
  if not quick_check_passed {
35
42
  return;
36
43
  }
37
- await ls.launch_deep_check(file_path);
44
+ await ls.launch_deep_check(file_path, delay=0.2);
38
45
  ls.lsp.send_request(lspt.WORKSPACE_SEMANTIC_TOKENS_REFRESH);
39
46
  }
40
47
 
48
+ glob still_compiling = False;
41
49
 
42
- """Check syntax on change."""
43
- @server.feature(lspt.TEXT_DOCUMENT_DID_CHANGE)
50
+ """Check syntax on change with debouncing."""
51
+ @ server.feature(lspt.TEXT_DOCUMENT_DID_CHANGE)
44
52
  async def did_change(
45
53
  ls: JacLangServer,
46
54
  params: lspt.DidChangeTextDocumentParams
47
55
  ) -> None {
48
- file_path = params.text_document.uri;
49
- quick_check_passed = await ls.launch_quick_check(file_path);
56
+ global still_compiling;
57
+ still_compiling = True;
50
58
 
51
- if quick_check_passed {
59
+ file_path = params.text_document.uri;
60
+ try {
52
61
  document = ls.workspace.get_text_document(file_path);
53
62
  lines = document.source.splitlines();
54
- sem_manager = ls.sem_managers[file_path.removeprefix('file://')];
55
- sem_manager.update_sem_tokens(
56
- params,sem_manager.sem_tokens,lines
63
+ fs_path = document.path;
64
+ if (fs_path in ls.sem_managers) {
65
+ sem_manager = ls.sem_managers[fs_path];
66
+ sem_manager.update_sem_tokens(params, sem_manager.sem_tokens, lines);
67
+ ls.lsp.send_request(lspt.WORKSPACE_SEMANTIC_TOKENS_REFRESH);
68
+ }
69
+ } except Exception as e {
70
+ ls.log_py(f" 'Failed to update semantic tokens: ' {e} ");
71
+ }
72
+
73
+ debug(ls, "Compilation started...");
74
+ ls.log_py(f" 'Launching debounced quick check for ' {file_path} ");
75
+ quick_check_passed = await ls.launch_quick_check(file_path, delay=0.5);
76
+ if quick_check_passed {
77
+ ls.log_py(
78
+ f" 'Quick check passed, launching debounced deep check for ' {file_path} "
57
79
  );
58
- ls.lsp.send_request(lspt.WORKSPACE_SEMANTIC_TOKENS_REFRESH);
59
- await ls.launch_deep_check(file_path);
80
+ await ls.launch_deep_check(file_path, delay=1.0);
81
+
60
82
  ls.lsp.send_request(lspt.WORKSPACE_SEMANTIC_TOKENS_REFRESH);
61
83
  }
84
+ still_compiling = False;
85
+ debug(ls, "Compilation finished...");
62
86
  }
63
87
 
64
-
65
88
  """Format the given document."""
66
89
  @server.feature(lspt.TEXT_DOCUMENT_FORMATTING)
67
90
  def formatting(
@@ -117,7 +140,15 @@ def did_delete_files(ls: JacLangServer, params: lspt.DeleteFilesParams) -> None
117
140
  lspt.TEXT_DOCUMENT_COMPLETION,
118
141
  lspt.CompletionOptions(trigger_characters=['.', ':', 'a-zA-Z0-9'])
119
142
  )
120
- def completion(ls: JacLangServer, params: lspt.CompletionParams) -> lspt.CompletionList {
143
+ async def completion(ls: JacLangServer, params: lspt.CompletionParams) -> lspt.CompletionList {
144
+
145
+ debug(ls, "Waiting for compilation to finish...");
146
+ global still_compiling;
147
+ while still_compiling {
148
+ await asyncio.sleep(0.1);
149
+ }
150
+ debug(ls, "Compilation finished, providing completions...");
151
+
121
152
  return ls.get_completion(
122
153
  params.text_document.uri,
123
154
  params.position,
@@ -63,15 +63,15 @@ with entry:__main__ {
63
63
  glob expected_area = 78.53981633974483;
64
64
 
65
65
  test calc_area {
66
- check almostEqual(calculate_area(RAD), expected_area);
66
+ assert almostEqual(calculate_area(RAD), expected_area);
67
67
  }
68
68
 
69
69
  test circle_area {
70
70
  c = Circle(RAD);
71
- check almostEqual(c.area(), expected_area);
71
+ assert almostEqual(c.area(), expected_area);
72
72
  }
73
73
 
74
74
  test circle_type {
75
75
  c = Circle(RAD);
76
- check c.shape_type == ShapeType.CIRCLE;
76
+ assert c.shape_type == ShapeType.CIRCLE;
77
77
  }
@@ -59,15 +59,15 @@ print(f"Area of a {c.shape_type.value} with radius {RAD} using class: {c.area()}
59
59
  glob expected_area = 78.53981633974483;
60
60
 
61
61
  test calc_area {
62
- check almostEqual(calculate_area(RAD), expected_area);
62
+ assert almostEqual(calculate_area(RAD), expected_area);
63
63
  }
64
64
 
65
65
  test circle_area {
66
66
  c = Circle(RAD);
67
- check almostEqual(c.area(), expected_area);
67
+ assert almostEqual(c.area(), expected_area);
68
68
  }
69
69
 
70
70
  test circle_type {
71
71
  c = Circle(RAD);
72
- check c.shape_type == ShapeType.CIRCLE;
72
+ assert c.shape_type == ShapeType.CIRCLE;
73
73
  }
@@ -1,15 +1,15 @@
1
1
  glob expected_area = 78.53981633974483;
2
2
 
3
3
  test a1 {
4
- check almostEqual(calculate_area(RAD), expected_area);
4
+ assert almostEqual(calculate_area(RAD), expected_area);
5
5
  }
6
6
 
7
7
  test a2 {
8
8
  c = Circle(RAD);
9
- check almostEqual(c.area(), expected_area);
9
+ assert almostEqual(c.area(), expected_area);
10
10
  }
11
11
 
12
12
  test a3 {
13
13
  c = Circle(RAD);
14
- check c.shape_type == ShapeType.CIRCLE;
14
+ assert c.shape_type == ShapeType.CIRCLE;
15
15
  }
@@ -0,0 +1,10 @@
1
+
2
+ class Foo {
3
+ has bar: int;
4
+ has baz: int;
5
+ }
6
+
7
+ with entry {
8
+ foo = Foo();
9
+ foo.
10
+ }
@@ -0,0 +1,80 @@
1
+ """
2
+ This module demonstrates a simple circle class and a function to calculate
3
+ the area of a circle in all of Jac's glory.
4
+ """
5
+
6
+ import math;
7
+
8
+ # Module-level global variable
9
+ glob RAD = 5;
10
+
11
+ """Function to calculate the area of a circle."""
12
+ def calculate_area(radius: float) -> float {
13
+ return math.pi * radius * radius;
14
+ }
15
+
16
+ #* (This is a multiline comment in Jac)
17
+ Above we have the demonstration of a function to calculate the area of a circle.
18
+ Below we have the demonstration of a class to calculate the area of a circle.
19
+ *#
20
+
21
+ """Enum for shape types"""
22
+ enum ShapeType {
23
+ CIRCLE = "Circle",
24
+ UNKNOWN = "Unknown"
25
+ }
26
+
27
+ """Base class for a shape."""
28
+ obj Shape {
29
+ has shape_type: ShapeType;
30
+
31
+ """Abstract method to calculate the area of a shape."""
32
+ def area -> float abs;
33
+ }
34
+
35
+ """Circle class inherits from Shape."""
36
+ obj Circle(Shape) {
37
+ def init(radius: float) {
38
+ super.init(ShapeType.CIRCLE);
39
+ self.radius = radius;
40
+ }
41
+
42
+ """Overridden method to calculate the area of the circle."""
43
+ override def area -> float {
44
+ return math.pi * self.radius * self.radius;
45
+ }
46
+ }
47
+
48
+ with entry {
49
+ c = Circle(RAD);
50
+ }
51
+
52
+ # Global also works here
53
+
54
+ with entry:__main__ {
55
+ # To run the program functionality
56
+ print(
57
+ f"Area of a circle with radius {RAD} using function: {calculate_area(RAD)}"
58
+ );
59
+ print(
60
+ f"Area of a {c.shape_type.value} with radius {RAD} using class: {c.area()}"
61
+ );
62
+ }
63
+
64
+ # Unit Tests!
65
+ glob expected_area = 78.53981633974483;
66
+ #{{INJECT_CODE}}
67
+
68
+ test calc_area {
69
+ assert almostEqual(calculate_area(RAD), expected_area);
70
+ }
71
+
72
+ test circle_area {
73
+ c = Circle(RAD);
74
+ assert almostEqual(c.area(), expected_area);
75
+ }
76
+
77
+ test circle_type {
78
+ c = Circle(RAD);
79
+ assert c.shape_type == ShapeType.CIRCLE;
80
+ }
@@ -0,0 +1,4 @@
1
+ glob expected_area0 = 78.53981633974483;
2
+ glob expected_area1 = 78.53981633974483;
3
+ #{{INJECT_CODE}}
4
+ glob expected_area2 = 78.53981633974483;