From 5358fe82570680f0a9b3109c7fafe877867f357a Mon Sep 17 00:00:00 2001 From: mgtm98 Date: Fri, 20 Dec 2024 16:07:19 +0200 Subject: [PATCH 1/3] Supporting getting symbols for Jac object --- .../passes/main/fuse_typeinfo_pass.py | 11 ++++++++++ .../compiler/passes/main/import_pass.py | 22 +++++++++++++++++++ jac/jaclang/plugin/jac_builtins.pyi | 11 ++++++++++ 3 files changed, 44 insertions(+) create mode 100644 jac/jaclang/plugin/jac_builtins.pyi diff --git a/jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py b/jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py index 0d0b90532..bbb389208 100644 --- a/jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py +++ b/jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py @@ -217,6 +217,15 @@ def __check_builltin_symbol(self, node: ast.NameAtom) -> None: if builtins_sym: node.name_spec._sym = builtins_sym + def __check_jac_builltin_symbol(self, node: ast.NameAtom) -> None: + if node._sym_type == "jaclang.plugin.feature.JacFeature": + jac_builtins_symtable = self.ir.sym_tab.find_scope("jac_builtins") + assert jac_builtins_symtable is not None + jac_builtins_symbol = jac_builtins_symtable.lookup("Jac") + assert jac_builtins_symbol is not None + node.name_spec.sym = jac_builtins_symbol + node.name_spec.type_sym_tab = jac_builtins_symbol.fetch_sym_tab + collection_types_map = { ast.ListVal: "builtins.list", ast.SetVal: "builtins.set", @@ -299,6 +308,8 @@ def enter_name(self, node: ast.NameAtom) -> None: self.__collect_type_from_symbol(node) if node.sym is None: self.__check_builltin_symbol(node) + if node.sym is None: + self.__check_jac_builltin_symbol(node) @__handle_node def enter_module_path(self, node: ast.ModulePath) -> None: diff --git a/jac/jaclang/compiler/passes/main/import_pass.py b/jac/jaclang/compiler/passes/main/import_pass.py index 6471440da..f8d8107ac 100644 --- a/jac/jaclang/compiler/passes/main/import_pass.py +++ b/jac/jaclang/compiler/passes/main/import_pass.py @@ -209,6 +209,7 @@ def before_pass(self) -> None: self.import_from_build_list: list[tuple[ast.Import, ast.Module]] = [] super().before_pass() self.__load_builtins() + self.__load_jac_builtins() def after_pass(self) -> None: """Build symbol tables for import from nodes.""" @@ -485,6 +486,27 @@ def __load_builtins(self) -> None: SymTabBuildPass(input_ir=mod, prior=self) mod.parent = None + def __load_jac_builtins(self) -> None: + """Pyraise jac builtins to help with builtins auto complete.""" + from jaclang.compiler.passes.main import PyastBuildPass + + assert isinstance(self.ir, ast.Module) + + file_to_raise = str("/home/mgtm98/jaseci/jac/jaclang/plugin/jac_builtins.pyi") + with open(file_to_raise, "r", encoding="utf-8") as f: + file_source = f.read() + mod = PyastBuildPass( + input_ir=ast.PythonModuleAst( + py_ast.parse(file_source), + orig_src=ast.JacSource(file_source, file_to_raise), + ), + ).ir + mod.parent = self.ir + SubNodeTabPass(input_ir=mod, prior=self) + SymTabBuildPass(input_ir=mod, prior=self) + DefUsePass(input_ir=mod, prior=self) + mod.parent = None + def annex_impl(self, node: ast.Module) -> None: """Annex impl and test modules.""" return None diff --git a/jac/jaclang/plugin/jac_builtins.pyi b/jac/jaclang/plugin/jac_builtins.pyi new file mode 100644 index 000000000..e863439e6 --- /dev/null +++ b/jac/jaclang/plugin/jac_builtins.pyi @@ -0,0 +1,11 @@ +from __future__ import annotations + +from typing import Optional + +from jaclang.runtimelib.constructs import Architype, NodeArchitype + +class Jac: + def node_dot( + root: any, + ) -> str: ... + def jid() -> str: ... From a9b46bb458ddc17b20e8a2d7cb2e243a5a788250 Mon Sep 17 00:00:00 2001 From: kugesan1105 Date: Mon, 23 Dec 2024 17:55:46 +0530 Subject: [PATCH 2/3] Fix: path Issue in import pass --- jac/jaclang/compiler/passes/main/import_pass.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jac/jaclang/compiler/passes/main/import_pass.py b/jac/jaclang/compiler/passes/main/import_pass.py index f8d8107ac..65a4daba4 100644 --- a/jac/jaclang/compiler/passes/main/import_pass.py +++ b/jac/jaclang/compiler/passes/main/import_pass.py @@ -492,7 +492,7 @@ def __load_jac_builtins(self) -> None: assert isinstance(self.ir, ast.Module) - file_to_raise = str("/home/mgtm98/jaseci/jac/jaclang/plugin/jac_builtins.pyi") + file_to_raise = os.path.join(os.path.dirname(__file__), "../../../../jaclang/plugin/jac_builtins.pyi") with open(file_to_raise, "r", encoding="utf-8") as f: file_source = f.read() mod = PyastBuildPass( From 675a887d7ab77ee016c5cdec9edd24307878be44 Mon Sep 17 00:00:00 2001 From: mgtm98 Date: Fri, 3 Jan 2025 21:47:46 +0200 Subject: [PATCH 3/3] Fixing missing symbols when calling jid & node_dot directly --- .../compiler/passes/main/fuse_typeinfo_pass.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py b/jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py index bbb389208..1e6e58801 100644 --- a/jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py +++ b/jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py @@ -218,13 +218,24 @@ def __check_builltin_symbol(self, node: ast.NameAtom) -> None: node.name_spec._sym = builtins_sym def __check_jac_builltin_symbol(self, node: ast.NameAtom) -> None: + jac_builtins_symtable = self.ir.sym_tab.find_scope("jac_builtins") + assert jac_builtins_symtable is not None + if node._sym_type == "jaclang.plugin.feature.JacFeature": - jac_builtins_symtable = self.ir.sym_tab.find_scope("jac_builtins") - assert jac_builtins_symtable is not None jac_builtins_symbol = jac_builtins_symtable.lookup("Jac") assert jac_builtins_symbol is not None node.name_spec.sym = jac_builtins_symbol node.name_spec.type_sym_tab = jac_builtins_symbol.fetch_sym_tab + return + + jac_builtins_symtab = jac_builtins_symtable.find_scope("Jac") + assert jac_builtins_symtab is not None + if node.sym_name == "jid": + node.name_spec.sym = jac_builtins_symtab.lookup("jid") + return + if node.sym_name == "node_dot": + node.name_spec.sym = jac_builtins_symtab.lookup("node_dot") + return collection_types_map = { ast.ListVal: "builtins.list",