Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting getting symbols for Jac object #1493

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,26 @@ 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:
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_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",
ast.SetVal: "builtins.set",
Expand Down Expand Up @@ -299,6 +319,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:
Expand Down
22 changes: 22 additions & 0 deletions jac/jaclang/compiler/passes/main/import_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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 = 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(
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
Expand Down
11 changes: 11 additions & 0 deletions jac/jaclang/plugin/jac_builtins.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Loading