jaclang 0.7.5__py3-none-any.whl → 0.7.6__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 (55) hide show
  1. jaclang/compiler/absyntree.py +167 -26
  2. jaclang/compiler/constant.py +98 -2
  3. jaclang/compiler/jac.lark +2 -0
  4. jaclang/compiler/parser.py +4 -0
  5. jaclang/compiler/passes/main/access_modifier_pass.py +5 -3
  6. jaclang/compiler/passes/main/def_impl_match_pass.py +3 -1
  7. jaclang/compiler/passes/main/def_use_pass.py +27 -39
  8. jaclang/compiler/passes/main/fuse_typeinfo_pass.py +34 -12
  9. jaclang/compiler/passes/main/sub_node_tab_pass.py +0 -5
  10. jaclang/compiler/passes/main/sym_tab_build_pass.py +31 -181
  11. jaclang/compiler/passes/tool/tests/fixtures/genai/essay_review.jac +1 -1
  12. jaclang/compiler/passes/tool/tests/fixtures/genai/expert_answer.jac +1 -1
  13. jaclang/compiler/passes/tool/tests/fixtures/genai/joke_gen.jac +1 -1
  14. jaclang/compiler/passes/tool/tests/fixtures/genai/odd_word_out.jac +1 -1
  15. jaclang/compiler/passes/tool/tests/fixtures/genai/personality_finder.jac +1 -1
  16. jaclang/compiler/passes/tool/tests/fixtures/genai/text_to_type.jac +1 -1
  17. jaclang/compiler/passes/tool/tests/fixtures/genai/translator.jac +1 -1
  18. jaclang/compiler/passes/tool/tests/fixtures/genai/wikipedia.jac +1 -1
  19. jaclang/compiler/symtable.py +118 -65
  20. jaclang/core/aott.py +7 -3
  21. jaclang/core/importer.py +1 -1
  22. jaclang/langserve/engine.py +100 -36
  23. jaclang/langserve/server.py +34 -61
  24. jaclang/langserve/tests/fixtures/base_module_structure.jac +28 -0
  25. jaclang/langserve/tests/fixtures/circle_pure.test.jac +15 -0
  26. jaclang/langserve/tests/fixtures/import_include_statements.jac +6 -0
  27. jaclang/langserve/tests/fixtures/py_import.py +26 -0
  28. jaclang/langserve/tests/test_server.py +90 -6
  29. jaclang/langserve/utils.py +114 -4
  30. jaclang/plugin/default.py +2 -2
  31. jaclang/plugin/feature.py +1 -1
  32. jaclang/plugin/spec.py +1 -1
  33. jaclang/tests/fixtures/aott_raise.jac +1 -1
  34. jaclang/tests/fixtures/edgetypeissue.jac +10 -0
  35. jaclang/tests/fixtures/hello.jac +1 -1
  36. jaclang/tests/fixtures/with_llm_function.jac +1 -1
  37. jaclang/tests/fixtures/with_llm_lower.jac +1 -1
  38. jaclang/tests/fixtures/with_llm_method.jac +1 -1
  39. jaclang/tests/fixtures/with_llm_type.jac +1 -1
  40. jaclang/tests/fixtures/with_llm_vision.jac +1 -1
  41. jaclang/tests/test_language.py +106 -96
  42. {jaclang-0.7.5.dist-info → jaclang-0.7.6.dist-info}/METADATA +1 -1
  43. {jaclang-0.7.5.dist-info → jaclang-0.7.6.dist-info}/RECORD +45 -50
  44. jaclang/core/llms/__init__.py +0 -20
  45. jaclang/core/llms/anthropic.py +0 -90
  46. jaclang/core/llms/base.py +0 -206
  47. jaclang/core/llms/groq.py +0 -70
  48. jaclang/core/llms/huggingface.py +0 -76
  49. jaclang/core/llms/ollama.py +0 -81
  50. jaclang/core/llms/openai.py +0 -65
  51. jaclang/core/llms/togetherai.py +0 -63
  52. jaclang/core/llms/utils.py +0 -9
  53. jaclang/tests/fixtures/edgetypetest.jac +0 -16
  54. {jaclang-0.7.5.dist-info → jaclang-0.7.6.dist-info}/WHEEL +0 -0
  55. {jaclang-0.7.5.dist-info → jaclang-0.7.6.dist-info}/entry_points.txt +0 -0
@@ -10,28 +10,15 @@ import ast as ast3
10
10
 
11
11
  import jaclang.compiler.absyntree as ast
12
12
  from jaclang.compiler.constant import Tokens as Tok
13
- from jaclang.compiler.passes.main.sym_tab_build_pass import SymTabPass
13
+ from jaclang.compiler.passes import Pass
14
14
 
15
15
 
16
- class DefUsePass(SymTabPass):
16
+ class DefUsePass(Pass):
17
17
  """Jac Ast build pass."""
18
18
 
19
19
  def after_pass(self) -> None:
20
20
  """After pass."""
21
21
 
22
- def inherit_baseclasses_sym(self, node: ast.Architype | ast.Enum) -> None:
23
- """Inherit base classes symbol tables."""
24
- if node.base_classes:
25
- for cls in node.base_classes.items:
26
- if (
27
- isinstance(cls, ast.AstSymbolNode)
28
- and (found := self.use_lookup(cls))
29
- and found
30
- and found.decl.sym_tab
31
- and node.sym_tab
32
- ):
33
- node.sym_tab.inherit.append(found.decl.sym_tab)
34
-
35
22
  def enter_architype(self, node: ast.Architype) -> None:
36
23
  """Sub objects.
37
24
 
@@ -44,7 +31,7 @@ class DefUsePass(SymTabPass):
44
31
  semstr: Optional[String] = None,
45
32
  decorators: Optional[SubNodeList[Expr]] = None,
46
33
  """
47
- self.inherit_baseclasses_sym(node)
34
+ node.sym_tab.inherit_baseclasses_sym(node)
48
35
 
49
36
  def inform_from_walker(node: ast.AstNode) -> None:
50
37
  for i in (
@@ -72,7 +59,7 @@ class DefUsePass(SymTabPass):
72
59
  semstr: Optional[String] = None,
73
60
  decorators: Optional[SubNodeList[Expr]] = None,
74
61
  """
75
- self.inherit_baseclasses_sym(node)
62
+ node.sym_tab.inherit_baseclasses_sym(node)
76
63
 
77
64
  def enter_arch_ref(self, node: ast.ArchRef) -> None:
78
65
  """Sub objects.
@@ -80,14 +67,14 @@ class DefUsePass(SymTabPass):
80
67
  name_ref: NameType,
81
68
  arch: Token,
82
69
  """
83
- self.use_lookup(node)
70
+ node.sym_tab.use_lookup(node)
84
71
 
85
72
  def enter_arch_ref_chain(self, node: ast.ArchRefChain) -> None:
86
73
  """Sub objects.
87
74
 
88
75
  archs: list[ArchRef],
89
76
  """
90
- self.chain_use_lookup(node.archs)
77
+ node.sym_tab.chain_use_lookup(node.archs)
91
78
 
92
79
  def enter_param_var(self, node: ast.ParamVar) -> None:
93
80
  """Sub objects.
@@ -97,7 +84,7 @@ class DefUsePass(SymTabPass):
97
84
  type_tag: SubTag[ExprType],
98
85
  value: Optional[ExprType],
99
86
  """
100
- self.def_insert(node)
87
+ node.sym_tab.def_insert(node)
101
88
 
102
89
  def enter_has_var(self, node: ast.HasVar) -> None:
103
90
  """Sub objects.
@@ -109,7 +96,7 @@ class DefUsePass(SymTabPass):
109
96
  if isinstance(node.parent, ast.SubNodeList) and isinstance(
110
97
  node.parent.parent, ast.ArchHas
111
98
  ):
112
- self.def_insert(
99
+ node.sym_tab.def_insert(
113
100
  node,
114
101
  single_decl="has var",
115
102
  access_spec=node.parent.parent,
@@ -128,9 +115,9 @@ class DefUsePass(SymTabPass):
128
115
  """
129
116
  for i in node.target.items:
130
117
  if isinstance(i, ast.AtomTrailer):
131
- self.chain_def_insert(self.unwind_atom_trailer(i))
118
+ i.sym_tab.chain_def_insert(i.as_attr_list)
132
119
  elif isinstance(i, ast.AstSymbolNode):
133
- self.def_insert(i)
120
+ i.sym_tab.def_insert(i)
134
121
  else:
135
122
  self.error("Assignment target not valid")
136
123
 
@@ -143,9 +130,9 @@ class DefUsePass(SymTabPass):
143
130
  conditional: Optional[ExprType],
144
131
  """
145
132
  if isinstance(node.target, ast.AtomTrailer):
146
- self.chain_def_insert(self.unwind_atom_trailer(node.target))
133
+ node.target.sym_tab.chain_def_insert(node.target.as_attr_list)
147
134
  elif isinstance(node.target, ast.AstSymbolNode):
148
- self.def_insert(node.target)
135
+ node.target.sym_tab.def_insert(node.target)
149
136
  else:
150
137
  self.error("Named target not valid")
151
138
 
@@ -156,8 +143,8 @@ class DefUsePass(SymTabPass):
156
143
  right: AtomType,
157
144
  is_scope_contained: bool,
158
145
  """
159
- chain = self.unwind_atom_trailer(node)
160
- self.chain_use_lookup(chain)
146
+ chain = node.as_attr_list
147
+ node.sym_tab.chain_use_lookup(chain)
161
148
 
162
149
  def enter_func_call(self, node: ast.FuncCall) -> None:
163
150
  """Sub objects.
@@ -179,7 +166,7 @@ class DefUsePass(SymTabPass):
179
166
 
180
167
  var: Token,
181
168
  """
182
- self.use_lookup(node)
169
+ node.sym_tab.use_lookup(node)
183
170
 
184
171
  def enter_edge_op_ref(self, node: ast.EdgeOpRef) -> None:
185
172
  """Sub objects.
@@ -232,7 +219,7 @@ class DefUsePass(SymTabPass):
232
219
  pos_start: int,
233
220
  pos_end: int,
234
221
  """
235
- self.use_lookup(node)
222
+ node.sym_tab.use_lookup(node)
236
223
 
237
224
  def enter_int(self, node: ast.Int) -> None:
238
225
  """Sub objects.
@@ -245,7 +232,7 @@ class DefUsePass(SymTabPass):
245
232
  pos_start: int,
246
233
  pos_end: int,
247
234
  """
248
- self.use_lookup(node)
235
+ node.sym_tab.use_lookup(node)
249
236
 
250
237
  def enter_string(self, node: ast.String) -> None:
251
238
  """Sub objects.
@@ -258,7 +245,7 @@ class DefUsePass(SymTabPass):
258
245
  pos_start: int,
259
246
  pos_end: int,
260
247
  """
261
- self.use_lookup(node)
248
+ node.sym_tab.use_lookup(node)
262
249
 
263
250
  def enter_bool(self, node: ast.Bool) -> None:
264
251
  """Sub objects.
@@ -271,7 +258,7 @@ class DefUsePass(SymTabPass):
271
258
  pos_start: int,
272
259
  pos_end: int,
273
260
  """
274
- self.use_lookup(node)
261
+ node.sym_tab.use_lookup(node)
275
262
 
276
263
  def enter_builtin_type(self, node: ast.BuiltinType) -> None:
277
264
  """Sub objects.
@@ -285,7 +272,7 @@ class DefUsePass(SymTabPass):
285
272
  pos_end: int,
286
273
  typ: type,
287
274
  """
288
- self.use_lookup(node)
275
+ node.sym_tab.use_lookup(node)
289
276
 
290
277
  def enter_name(self, node: ast.Name) -> None:
291
278
  """Sub objects.
@@ -297,7 +284,8 @@ class DefUsePass(SymTabPass):
297
284
  pos_start: int,
298
285
  pos_end: int,
299
286
  """
300
- self.use_lookup(node)
287
+ if not isinstance(node.parent, ast.AtomTrailer):
288
+ node.sym_tab.use_lookup(node)
301
289
 
302
290
  def enter_in_for_stmt(self, node: ast.InForStmt) -> None:
303
291
  """Sub objects.
@@ -309,9 +297,9 @@ class DefUsePass(SymTabPass):
309
297
  else_body: Optional[ElseStmt],
310
298
  """
311
299
  if isinstance(node.target, ast.AtomTrailer):
312
- self.chain_def_insert(self.unwind_atom_trailer(node.target))
300
+ node.target.sym_tab.chain_def_insert(node.target.as_attr_list)
313
301
  elif isinstance(node.target, ast.AstSymbolNode):
314
- self.def_insert(node.target)
302
+ node.target.sym_tab.def_insert(node.target)
315
303
  else:
316
304
  self.error("For loop assignment target not valid")
317
305
 
@@ -327,7 +315,7 @@ class DefUsePass(SymTabPass):
327
315
  )
328
316
  for i in items:
329
317
  if isinstance(i, ast.AtomTrailer):
330
- self.unwind_atom_trailer(i)[-1].name_spec.py_ctx_func = ast3.Del
318
+ i.as_attr_list[-1].name_spec.py_ctx_func = ast3.Del
331
319
  elif isinstance(i, ast.AstSymbolNode):
332
320
  i.name_spec.py_ctx_func = ast3.Del
333
321
  else:
@@ -341,8 +329,8 @@ class DefUsePass(SymTabPass):
341
329
  """
342
330
  if node.alias:
343
331
  if isinstance(node.alias, ast.AtomTrailer):
344
- self.chain_def_insert(self.unwind_atom_trailer(node.alias))
332
+ node.alias.sym_tab.chain_def_insert(node.alias.as_attr_list)
345
333
  elif isinstance(node.alias, ast.AstSymbolNode):
346
- self.def_insert(node.alias)
334
+ node.alias.sym_tab.def_insert(node.alias)
347
335
  else:
348
336
  self.error("For expr as target not valid")
@@ -11,6 +11,7 @@ from typing import Callable, TypeVar
11
11
 
12
12
  import jaclang.compiler.absyntree as ast
13
13
  from jaclang.compiler.passes import Pass
14
+ from jaclang.compiler.symtable import SymbolTable
14
15
  from jaclang.settings import settings
15
16
  from jaclang.utils.helpers import pascal_to_snake
16
17
  from jaclang.vendor.mypy.nodes import Node as VNode # bit of a hack
@@ -183,18 +184,6 @@ class FuseTypeInfoPass(Pass):
183
184
  """Pass handler for name nodes."""
184
185
  self.__collect_type_from_symbol(node)
185
186
 
186
- # Assign correct symbols to sym_link in case of
187
- # AtomTrailer Object
188
- if isinstance(node.parent, ast.AtomTrailer):
189
- target_node = node.parent.target
190
- if isinstance(target_node, ast.AstSymbolNode):
191
- parent_symbol_table = target_node.type_sym_tab
192
- if isinstance(parent_symbol_table, ast.SymbolTable):
193
- owner = parent_symbol_table.owner
194
- if isinstance(owner, ast.AstSymbolNode):
195
- target_node.name_spec.sym = owner.sym
196
- node.sym = parent_symbol_table.lookup(node.sym_name)
197
-
198
187
  @__handle_node
199
188
  def enter_module_path(self, node: ast.ModulePath) -> None:
200
189
  """Pass handler for ModulePath nodes."""
@@ -442,3 +431,36 @@ class FuseTypeInfoPass(Pass):
442
431
  ) -> None:
443
432
  """Get type info from mypy type TupleType."""
444
433
  node.name_spec.sym_type = "builtins.tuple"
434
+
435
+ def exit_assignment(self, node: ast.Assignment) -> None:
436
+ """Add new symbols in the symbol table in case of self."""
437
+ # This will fix adding new items to the class through self
438
+ # self.x = 5 # will add x to self datatype symbol table
439
+ for target in node.target.items:
440
+ if (
441
+ isinstance(target, ast.AtomTrailer)
442
+ and isinstance(target.target, ast.SpecialVarRef)
443
+ and target.target.sym_name == "self"
444
+ ):
445
+ self_obj = target.target
446
+ right_obj = target.right
447
+ if self_obj.type_sym_tab and isinstance(right_obj, ast.AstSymbolNode):
448
+ self_obj.type_sym_tab.def_insert(right_obj)
449
+
450
+ def exit_name(self, node: ast.Name) -> None:
451
+ """Add new symbols in the symbol table in case of atom trailer."""
452
+ if isinstance(node.parent, ast.AtomTrailer):
453
+ target_node = node.parent.target
454
+ if isinstance(target_node, ast.AstSymbolNode):
455
+ parent_symbol_table = target_node.type_sym_tab
456
+ if isinstance(parent_symbol_table, SymbolTable):
457
+ node.sym = parent_symbol_table.lookup(node.sym_name)
458
+
459
+ # def exit_in_for_stmt(self, node: ast.InForStmt):
460
+ # print(node.loc.mod_path, node.loc)
461
+ # print(node.target, node.target.loc)
462
+ # # node.sym_tab.def_insert()
463
+ # # exit()
464
+
465
+ # def after_pass(self) -> None:
466
+ # exit()
@@ -6,7 +6,6 @@ pass and is not required for any other pass to work.
6
6
  """
7
7
 
8
8
  from copy import copy
9
- from typing import Optional
10
9
 
11
10
  import jaclang.compiler.absyntree as ast
12
11
  from jaclang.compiler.passes import Pass
@@ -15,10 +14,6 @@ from jaclang.compiler.passes import Pass
15
14
  class SubNodeTabPass(Pass):
16
15
  """AST Enrichment Pass for basic high level semantics."""
17
16
 
18
- def before_pass(self) -> None:
19
- """Initialize pass."""
20
- self.cur_module: Optional[ast.Module] = None
21
-
22
17
  def enter_node(self, node: ast.AstNode) -> None:
23
18
  """Table builder."""
24
19
  super().enter_node(node)
@@ -4,172 +4,19 @@ This pass builds the symbol table tree for the Jaseci Ast. It also adds symbols
4
4
  for globals, imports, architypes, and abilities declarations and definitions.
5
5
  """
6
6
 
7
- import ast as ast3
8
7
  import builtins
9
- from typing import Optional, Sequence
10
8
 
11
9
  import jaclang.compiler.absyntree as ast
12
10
  from jaclang.compiler.constant import Tokens as Tok
13
11
  from jaclang.compiler.passes import Pass
14
- from jaclang.compiler.symtable import Symbol, SymbolAccess, SymbolTable
15
-
16
-
17
- class SymTabPass(Pass):
18
- """Jac Ast build pass."""
19
-
20
- def inherit_sym_tab(self, scope: SymbolTable, sym_tab: SymbolTable) -> None:
21
- """Inherit symbol table."""
22
- for i in sym_tab.tab.values():
23
- self.def_insert(i.decl, access_spec=i.access, table_override=scope)
24
-
25
- def def_insert(
26
- self,
27
- node: ast.AstSymbolNode,
28
- access_spec: Optional[ast.AstAccessNode] | SymbolAccess = None,
29
- single_decl: Optional[str] = None,
30
- table_override: Optional[SymbolTable] = None,
31
- ) -> Optional[Symbol]:
32
- """Insert into symbol table."""
33
- table = table_override if table_override else node.sym_tab
34
- if node.sym and table == node.sym.parent_tab:
35
- return node.sym
36
- if table:
37
- table.insert(
38
- node=node, single=single_decl is not None, access_spec=access_spec
39
- )
40
- self.update_py_ctx_for_def(node)
41
- return node.sym
42
-
43
- def update_py_ctx_for_def(self, node: ast.AstSymbolNode) -> None:
44
- """Update python context for definition."""
45
- node.name_spec.py_ctx_func = ast3.Store
46
- if isinstance(node.name_spec, ast.AstSymbolNode):
47
- node.name_spec.py_ctx_func = ast3.Store
48
- if isinstance(node, (ast.TupleVal, ast.ListVal)) and node.values:
49
- # Handling of UnaryExpr case for item is only necessary for
50
- # the generation of Starred nodes in the AST for examples
51
- # like `(a, *b) = (1, 2, 3, 4)`.
52
- def fix(item: ast.TupleVal | ast.ListVal | ast.UnaryExpr) -> None:
53
- if isinstance(item, ast.UnaryExpr):
54
- if isinstance(item.operand, ast.AstSymbolNode):
55
- item.operand.name_spec.py_ctx_func = ast3.Store
56
- elif isinstance(item, (ast.TupleVal, ast.ListVal)):
57
- for i in item.values.items if item.values else []:
58
- if isinstance(i, ast.AstSymbolNode):
59
- i.name_spec.py_ctx_func = ast3.Store
60
- elif isinstance(i, ast.AtomTrailer):
61
- self.chain_def_insert(self.unwind_atom_trailer(i))
62
- if isinstance(i, (ast.TupleVal, ast.ListVal, ast.UnaryExpr)):
63
- fix(i)
64
-
65
- fix(node)
66
-
67
- def use_lookup(
68
- self,
69
- node: ast.AstSymbolNode,
70
- sym_table: Optional[SymbolTable] = None,
71
- ) -> Optional[Symbol]:
72
- """Link to symbol."""
73
- if node.sym:
74
- return node.sym
75
- if not sym_table:
76
- sym_table = node.sym_tab
77
- if sym_table:
78
- lookup = sym_table.lookup(name=node.sym_name, deep=True)
79
- lookup.add_use(node.name_spec) if lookup else None
80
- return node.sym
81
-
82
- def chain_def_insert(self, node_list: Sequence[ast.AstSymbolNode]) -> None:
83
- """Link chain of containing names to symbol."""
84
- if not node_list:
85
- return
86
- cur_sym_tab = node_list[0].sym_tab
87
- node_list[-1].name_spec.py_ctx_func = ast3.Store
88
- if isinstance(node_list[-1].name_spec, ast.AstSymbolNode):
89
- node_list[-1].name_spec.py_ctx_func = ast3.Store
90
-
91
- node_list = node_list[:-1] # Just performs lookup mappings of pre assign chain
92
- for i in node_list:
93
- if cur_sym_tab is None:
94
- break
95
- cur_sym_tab = (
96
- lookup.decl.sym_tab
97
- if (
98
- lookup := self.use_lookup(
99
- i,
100
- sym_table=cur_sym_tab,
101
- )
102
- )
103
- else None
104
- )
12
+ from jaclang.compiler.symtable import SymbolTable
105
13
 
106
- def chain_use_lookup(self, node_list: Sequence[ast.AstSymbolNode]) -> None:
107
- """Link chain of containing names to symbol."""
108
- if not node_list:
109
- return
110
- cur_sym_tab = node_list[0].sym_tab
111
- for i in node_list:
112
- if cur_sym_tab is None:
113
- break
114
- cur_sym_tab = (
115
- lookup.decl.sym_tab
116
- if (
117
- lookup := self.use_lookup(
118
- i,
119
- sym_table=cur_sym_tab,
120
- )
121
- )
122
- else None
123
- )
124
14
 
125
- def unwind_atom_trailer(self, node: ast.AtomTrailer) -> list[ast.AstSymbolNode]:
126
- """Sub objects.
127
-
128
- target: ExprType,
129
- right: AtomType,
130
- is_scope_contained: bool,
131
- """
132
- left = node.right if isinstance(node.right, ast.AtomTrailer) else node.target
133
- right = node.target if isinstance(node.right, ast.AtomTrailer) else node.right
134
- trag_list: list[ast.AstSymbolNode] = (
135
- [right] if isinstance(right, ast.AstSymbolNode) else []
136
- )
137
- if not trag_list:
138
- self.ice("Something went very wrong with atom trailer not valid")
139
- while isinstance(left, ast.AtomTrailer) and left.is_attr:
140
- if isinstance(left.right, ast.AstSymbolNode):
141
- trag_list.insert(0, left.right)
142
- else:
143
- raise self.ice("Something went very wrong with atom trailer not valid")
144
- left = left.target
145
- if isinstance(left, ast.AstSymbolNode):
146
- trag_list.insert(0, left)
147
- return trag_list
148
-
149
- def already_declared_err(
150
- self,
151
- name: str,
152
- typ: str,
153
- original: ast.AstNode,
154
- other_nodes: Optional[list[ast.AstNode]] = None,
155
- ) -> None:
156
- """Already declared error."""
157
- err_msg = (
158
- f"Name used for {typ} '{name}' already declared at "
159
- f"{original.loc.mod_path}, line {original.loc.first_line}"
160
- )
161
- if other_nodes:
162
- for i in other_nodes:
163
- err_msg += f", also see {i.loc.mod_path}, line {i.loc.first_line}"
164
- self.warning(err_msg)
165
-
166
-
167
- class SymTabBuildPass(SymTabPass):
15
+ class SymTabBuildPass(Pass):
168
16
  """Jac Symbol table build pass."""
169
17
 
170
18
  def before_pass(self) -> None:
171
19
  """Before pass."""
172
- super().before_pass()
173
20
  self.cur_sym_tab: list[SymbolTable] = []
174
21
 
175
22
  def push_scope(self, name: str, key_node: ast.AstNode, fresh: bool = False) -> None:
@@ -177,19 +24,20 @@ class SymTabBuildPass(SymTabPass):
177
24
  if fresh:
178
25
  self.cur_sym_tab.append(SymbolTable(name, key_node))
179
26
  else:
180
- self.cur_sym_tab.append(self.cur_scope().push_scope(name, key_node))
27
+ self.cur_sym_tab.append(self.cur_scope.push_scope(name, key_node))
181
28
 
182
29
  def pop_scope(self) -> SymbolTable:
183
30
  """Pop scope."""
184
31
  return self.cur_sym_tab.pop()
185
32
 
33
+ @property
186
34
  def cur_scope(self) -> SymbolTable:
187
35
  """Return current scope."""
188
36
  return self.cur_sym_tab[-1]
189
37
 
190
38
  def sync_node_to_scope(self, node: ast.AstNode) -> None:
191
39
  """Sync node to scope."""
192
- node.sym_tab = self.cur_scope()
40
+ node.sym_tab = self.cur_scope
193
41
 
194
42
  def enter_module(self, node: ast.Module) -> None:
195
43
  """Sub objects.
@@ -215,7 +63,7 @@ class SymTabBuildPass(SymTabPass):
215
63
  pos_end=0,
216
64
  )
217
65
  self.sync_node_to_scope(builtin)
218
- self.def_insert(builtin)
66
+ builtin.sym_tab.def_insert(builtin)
219
67
  # self.def_insert(ast.Name.gen_stub_from_node(node.name, "root"))
220
68
 
221
69
  def exit_module(self, node: ast.Module) -> None:
@@ -250,7 +98,7 @@ class SymTabBuildPass(SymTabPass):
250
98
  for i in self.get_all_sub_nodes(node, ast.Assignment):
251
99
  for j in i.target.items:
252
100
  if isinstance(j, ast.AstSymbolNode):
253
- self.def_insert(j, access_spec=node, single_decl="global var")
101
+ j.sym_tab.def_insert(j, access_spec=node, single_decl="global var")
254
102
  else:
255
103
  self.ice("Expected name type for globabl vars")
256
104
 
@@ -276,7 +124,14 @@ class SymTabBuildPass(SymTabPass):
276
124
  description: Token,
277
125
  body: CodeBlock,
278
126
  """
127
+ self.push_scope(node.sym_name, node)
279
128
  self.sync_node_to_scope(node)
129
+ import unittest
130
+
131
+ for i in [j for j in dir(unittest.TestCase()) if j.startswith("assert")]:
132
+ node.sym_tab.def_insert(
133
+ ast.Name.gen_stub_from_node(node, i, set_name_of=node)
134
+ )
280
135
 
281
136
  def exit_test(self, node: ast.Test) -> None:
282
137
  """Sub objects.
@@ -286,9 +141,6 @@ class SymTabBuildPass(SymTabPass):
286
141
  description: Token,
287
142
  body: CodeBlock,
288
143
  """
289
- self.def_insert(node, single_decl="test")
290
- self.push_scope(node.name.value, node)
291
- self.sync_node_to_scope(node)
292
144
  self.pop_scope()
293
145
 
294
146
  def enter_module_code(self, node: ast.ModuleCode) -> None:
@@ -340,22 +192,16 @@ class SymTabBuildPass(SymTabPass):
340
192
  """
341
193
  if not node.is_absorb:
342
194
  for i in node.items.items:
343
- self.def_insert(i, single_decl="import item")
195
+ i.sym_tab.def_insert(i, single_decl="import item")
344
196
  elif node.is_absorb and node.hint.tag.value == "jac":
345
197
  source = node.items.items[0]
346
- if (
347
- not isinstance(source, ast.ModulePath)
348
- or not source.sub_module
349
- or not source.sub_module.sym_tab
350
- ):
198
+ if not isinstance(source, ast.ModulePath) or not source.sub_module:
351
199
  self.error(
352
200
  f"Module {node.from_loc.path_str if node.from_loc else 'from location'}"
353
201
  f" not found to include *, or ICE occurred!"
354
202
  )
355
203
  else:
356
- self.inherit_sym_tab(
357
- scope=self.cur_scope(), sym_tab=source.sub_module.sym_tab
358
- )
204
+ node.sym_tab.inherit_sym_tab(source.sub_module.sym_tab)
359
205
 
360
206
  def enter_module_path(self, node: ast.ModulePath) -> None:
361
207
  """Sub objects.
@@ -374,9 +220,9 @@ class SymTabBuildPass(SymTabPass):
374
220
  sub_module: Optional[Module] = None,
375
221
  """
376
222
  if node.alias:
377
- self.def_insert(node.alias, single_decl="import")
223
+ node.alias.sym_tab.def_insert(node.alias, single_decl="import")
378
224
  elif node.path and isinstance(node.path[0], ast.Name):
379
- self.def_insert(node.path[0])
225
+ node.path[0].sym_tab.def_insert(node.path[0])
380
226
  else:
381
227
  pass # Need to support pythonic import symbols with dots in it
382
228
 
@@ -401,7 +247,7 @@ class SymTabBuildPass(SymTabPass):
401
247
  body: Optional[ArchBlock],
402
248
  """
403
249
  self.sync_node_to_scope(node)
404
- self.def_insert(node, access_spec=node, single_decl="architype")
250
+ node.sym_tab.def_insert(node, access_spec=node, single_decl="architype")
405
251
  self.push_scope(node.name.value, node)
406
252
  self.sync_node_to_scope(node)
407
253
 
@@ -427,7 +273,7 @@ class SymTabBuildPass(SymTabPass):
427
273
  body: ArchBlock,
428
274
  """
429
275
  self.sync_node_to_scope(node)
430
- self.def_insert(node, single_decl="arch def")
276
+ node.sym_tab.def_insert(node, single_decl="arch def")
431
277
  self.push_scope(node.sym_name, node)
432
278
  self.sync_node_to_scope(node)
433
279
 
@@ -455,12 +301,16 @@ class SymTabBuildPass(SymTabPass):
455
301
  body: Optional[CodeBlock],
456
302
  """
457
303
  self.sync_node_to_scope(node)
458
- self.def_insert(node, access_spec=node, single_decl="ability")
304
+ node.sym_tab.def_insert(node, access_spec=node, single_decl="ability")
459
305
  self.push_scope(node.sym_name, node)
460
306
  self.sync_node_to_scope(node)
461
307
  if node.is_method:
462
- self.def_insert(ast.Name.gen_stub_from_node(node, "self"))
463
- self.def_insert(ast.Name.gen_stub_from_node(node, "super"))
308
+ node.sym_tab.def_insert(ast.Name.gen_stub_from_node(node, "self"))
309
+ node.sym_tab.def_insert(
310
+ ast.Name.gen_stub_from_node(
311
+ node, "super", set_name_of=node.owner_method
312
+ )
313
+ )
464
314
 
465
315
  def exit_ability(self, node: ast.Ability) -> None:
466
316
  """Sub objects.
@@ -486,7 +336,7 @@ class SymTabBuildPass(SymTabPass):
486
336
  body: CodeBlock,
487
337
  """
488
338
  self.sync_node_to_scope(node)
489
- self.def_insert(node, single_decl="ability def")
339
+ node.sym_tab.def_insert(node, single_decl="ability def")
490
340
  self.push_scope(node.sym_name, node)
491
341
  self.sync_node_to_scope(node)
492
342
 
@@ -546,7 +396,7 @@ class SymTabBuildPass(SymTabPass):
546
396
  body: Optional['EnumBlock'],
547
397
  """
548
398
  self.sync_node_to_scope(node)
549
- self.def_insert(node, access_spec=node, single_decl="enum")
399
+ node.sym_tab.def_insert(node, access_spec=node, single_decl="enum")
550
400
  self.push_scope(node.sym_name, node)
551
401
  self.sync_node_to_scope(node)
552
402
 
@@ -570,7 +420,7 @@ class SymTabBuildPass(SymTabPass):
570
420
  body: EnumBlock,
571
421
  """
572
422
  self.sync_node_to_scope(node)
573
- self.def_insert(node, single_decl="enum def")
423
+ node.sym_tab.def_insert(node, single_decl="enum def")
574
424
  self.push_scope(node.sym_name, node)
575
425
  self.sync_node_to_scope(node)
576
426
 
@@ -1,4 +1,4 @@
1
- import:py from jaclang.core.llms, Anthropic;
1
+ import:py from mtllm.llms, Anthropic;
2
2
 
3
3
  glob llm = Anthropic(model_name="claude-3-sonnet-20240229");
4
4
 
@@ -1,4 +1,4 @@
1
- import:py from jaclang.core.llms, Anthropic;
1
+ import:py from mtllm.llms, Anthropic;
2
2
 
3
3
  glob llm = Anthropic(model_name="claude-3-sonnet-20240229");
4
4
 
@@ -1,4 +1,4 @@
1
- import:py from jaclang.core.llms, Anthropic;
1
+ import:py from mtllm.llms, Anthropic;
2
2
 
3
3
  glob llm = Anthropic(model_name="claude-3-sonnet-20240229");
4
4
 
@@ -1,4 +1,4 @@
1
- import:py from jaclang.core.llms, Anthropic;
1
+ import:py from mtllm.llms, Anthropic;
2
2
 
3
3
  glob llm = Anthropic(model_name="claude-3-sonnet-20240229");
4
4
 
@@ -1,4 +1,4 @@
1
- import:py from jaclang.core.llms, Anthropic;
1
+ import:py from mtllm.llms, Anthropic;
2
2
 
3
3
  glob llm = Anthropic(model_name="claude-3-sonnet-20240229");
4
4
 
@@ -1,4 +1,4 @@
1
- import:py from jaclang.core.llms, Anthropic;
1
+ import:py from mtllm.llms, Anthropic;
2
2
 
3
3
  glob llm = Anthropic(model_name="claude-3-sonnet-20240229");
4
4
 
@@ -1,4 +1,4 @@
1
- import:py from jaclang.core.llms, Anthropic;
1
+ import:py from mtllm.llms, Anthropic;
2
2
 
3
3
  glob llm = Anthropic(model_name="claude-3-sonnet-20240229");
4
4