Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #559 from Jaseci-Labs/semtable-raise
Browse files Browse the repository at this point in the history
[CHORE] Adding Semstrings of abilities to SemRegistry
  • Loading branch information
marsninja authored Aug 11, 2024
2 parents 3fa8974 + 8a73436 commit 0bc1f46
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
34 changes: 34 additions & 0 deletions jaclang/compiler/passes/main/registry_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,40 @@ def exit_has_var(self, node: ast.HasVar) -> None:
if len(self.modules_visited) and self.modules_visited[-1].registry:
self.modules_visited[-1].registry.add(scope, seminfo)

def exit_ability(self, node: ast.Ability) -> None:
"""Save ability information."""
scope = get_sem_scope(node.parent) # type: ignore[arg-type]
seminfo = SemInfo(
node.name_ref.sym_name,
"Ability",
node.semstr.lit_value if node.semstr else "",
)
if len(self.modules_visited) and self.modules_visited[-1].registry:
self.modules_visited[-1].registry.add(scope, seminfo)

if (
isinstance(node.signature, ast.EventSignature)
and len(self.modules_visited)
and self.modules_visited[-1].registry
):
self.modules_visited[-1].registry.add(
get_sem_scope(node), SemInfo("No Input Params", "")
)

def exit_param_var(self, node: ast.ParamVar) -> None:
"""Save param information."""
scope = get_sem_scope(node)
extracted_type = (
"".join(self.extract_type(node.type_tag.tag)) if node.type_tag else None
)
seminfo = SemInfo(
node.name.value,
extracted_type,
node.semstr.lit_value if node.semstr else "",
)
if len(self.modules_visited) and self.modules_visited[-1].registry:
self.modules_visited[-1].registry.add(scope, seminfo)

def exit_assignment(self, node: ast.Assignment) -> None:
"""Save assignment information."""
if node.aug_op:
Expand Down
5 changes: 3 additions & 2 deletions jaclang/compiler/semtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def __str__(self) -> str:
"""Return the string representation of the class."""
if self.parent:
return f"{self.parent}.{self.scope}({self.type})"
return f"{self.scope}({self.type})"
else:
return f"{self.scope}({self.type})"

def __repr__(self) -> str:
"""Return the string representation of the class."""
Expand All @@ -57,7 +58,7 @@ def get_scope_from_str(scope_str: str) -> Optional[SemScope]:

@property
def as_type_str(self) -> Optional[str]:
"""Return the type string representation of the SemsScope."""
"""Return the type string representation of the SemScope."""
if self.type not in ["class", "node", "obj"]:
return None
type_str = self.scope
Expand Down
16 changes: 12 additions & 4 deletions jaclang/runtimelib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,26 @@ def get_sem_scope(node: ast.AstNode) -> SemScope:
a = (
node.name
if isinstance(node, ast.Module)
else node.name.value if isinstance(node, (ast.Enum, ast.Architype)) else ""
else (
node.name.value
if isinstance(node, (ast.Enum, ast.Architype))
else node.name_ref.sym_name if isinstance(node, ast.Ability) else ""
)
)
if isinstance(node, ast.Module):
return SemScope(a, "Module", None)
elif isinstance(node, (ast.Enum, ast.Architype)):
elif isinstance(node, (ast.Enum, ast.Architype, ast.Ability)):
node_type = (
node.__class__.__name__
if isinstance(node, ast.Enum)
else node.arch_type.value
else ("Ability" if isinstance(node, ast.Ability) else node.arch_type.value)
)
if node.parent:
return SemScope(a, node_type, get_sem_scope(node.parent))
return SemScope(
a,
node_type,
get_sem_scope(node.parent),
)
else:
if node.parent:
return get_sem_scope(node.parent)
Expand Down
6 changes: 3 additions & 3 deletions jaclang/tests/test_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,9 @@ def test_registry(self) -> None:
) as f:
registry = pickle.load(f)

self.assertEqual(len(registry.registry), 3)
self.assertEqual(len(list(registry.registry.items())[0][1]), 10)
self.assertEqual(list(registry.registry.items())[1][0].scope, "Person")
self.assertEqual(len(registry.registry), 7)
self.assertEqual(len(list(registry.registry.items())[0][1]), 2)
self.assertEqual(list(registry.registry.items())[3][0].scope, "Person")

def test_enum_inside_arch(self) -> None:
"""Test Enum as member stmt."""
Expand Down

0 comments on commit 0bc1f46

Please sign in to comment.