Skip to content

Commit

Permalink
chore: complxity reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
marsninja committed Feb 24, 2024
1 parent 150fccb commit 00fb37d
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 49 deletions.
2 changes: 1 addition & 1 deletion examples/micro/another.jac
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ with entry {
}
#[-->](`?`MyObj:a<4, b<5);
print(my_list(?a < 4));
print(my_list(`?MyObj:a < 4));
print(my_list(`?MyObj:a < 4, a<3));
my_list(=a=5);
print(my_list);
}
6 changes: 0 additions & 6 deletions jaclang/core/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,12 @@ def connect_node(self, nd: NodeArchitype, edg: EdgeArchitype) -> NodeArchitype:
def get_edges(
self,
dir: EdgeDir,
filter_type: Optional[type],
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
target_obj: Optional[list[NodeArchitype]],
) -> list[EdgeArchitype]:
"""Get edges connected to this node."""
edge_list: list[EdgeArchitype] = [*self.edges]
ret_edges: list[EdgeArchitype] = []
if filter_type:
edge_list = [e for e in edge_list if isinstance(e, filter_type)]
edge_list = filter_func(edge_list) if filter_func else edge_list
for e in edge_list:
if (
Expand All @@ -75,15 +72,12 @@ def get_edges(
def edges_to_nodes(
self,
dir: EdgeDir,
filter_type: Optional[type],
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
target_obj: Optional[list[NodeArchitype]],
) -> list[NodeArchitype]:
"""Get set of nodes connected to this node."""
edge_list: list[EdgeArchitype] = [*self.edges]
node_list: list[NodeArchitype] = []
if filter_type:
edge_list = [e for e in edge_list if isinstance(e, filter_type)]
edge_list = filter_func(edge_list) if filter_func else edge_list
for e in edge_list:
if e._jac_.target and e._jac_.source:
Expand Down
19 changes: 3 additions & 16 deletions jaclang/plugin/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import types
from dataclasses import field
from functools import wraps
from typing import Any, Callable, Optional, Sequence, Type
from typing import Any, Callable, Optional, Type

from jaclang.compiler.absyntree import Module
from jaclang.compiler.constant import EdgeDir
Expand Down Expand Up @@ -262,7 +262,6 @@ def edge_ref(
node_obj: NodeArchitype | list[NodeArchitype],
target_obj: Optional[NodeArchitype | list[NodeArchitype]],
dir: EdgeDir,
filter_type: Optional[type],
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
edges_only: bool,
) -> list[NodeArchitype] | list[EdgeArchitype]:
Expand All @@ -278,16 +277,14 @@ def edge_ref(
connected_edges: list[EdgeArchitype] = []
for node in node_obj:
connected_edges += node._jac_.get_edges(
dir, filter_type, filter_func, target_obj=targ_obj_set
dir, filter_func, target_obj=targ_obj_set
)
return list(set(connected_edges))
else:
connected_nodes: list[NodeArchitype] = []
for node in node_obj:
connected_nodes.extend(
node._jac_.edges_to_nodes(
dir, filter_type, filter_func, target_obj=targ_obj_set
)
node._jac_.edges_to_nodes(dir, filter_func, target_obj=targ_obj_set)
)
return list(set(connected_nodes))

Expand Down Expand Up @@ -354,16 +351,6 @@ def disconnect(
disconnect_occurred = True
return disconnect_occurred

@staticmethod
@hookimpl
def filter_compr(
target_obj: Sequence[T] | T,
filter_type: Optional[type],
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
) -> list[T] | T | None:
"""Jac's assign comprehension feature."""
return []

@staticmethod
@hookimpl
def assign_compr(
Expand Down
15 changes: 1 addition & 14 deletions jaclang/plugin/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import types
from typing import Any, Callable, Optional, Sequence, Type, TypeAlias
from typing import Any, Callable, Optional, Type, TypeAlias

from jaclang.compiler.absyntree import Module
from jaclang.core.construct import (
Expand Down Expand Up @@ -143,7 +143,6 @@ def edge_ref(
node_obj: NodeArchitype | list[NodeArchitype],
target_obj: Optional[NodeArchitype | list[NodeArchitype]],
dir: EdgeDir,
filter_type: Optional[type],
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
edges_only: bool = False,
) -> list[NodeArchitype] | list[EdgeArchitype]:
Expand All @@ -152,7 +151,6 @@ def edge_ref(
node_obj=node_obj,
target_obj=target_obj,
dir=dir,
filter_type=filter_type,
filter_func=filter_func,
edges_only=edges_only,
)
Expand Down Expand Up @@ -189,17 +187,6 @@ def disconnect(
filter_func=filter_func,
)

@staticmethod
def filter_compr(
target_obj: Sequence[T] | T,
filter_type: Optional[type],
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
) -> list[T] | T | None:
"""Jac's assign comprehension feature."""
return pm.hook.filter_compr(
target_obj=target_obj, filter_type=filter_type, filter_func=filter_func
)

@staticmethod
def assign_compr(
target: list[T], attr_val: tuple[tuple[str], tuple[Any]]
Expand Down
13 changes: 1 addition & 12 deletions jaclang/plugin/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import types
from typing import Any, Callable, Optional, Sequence, Type, TypeVar
from typing import Any, Callable, Optional, Type, TypeVar

from jaclang.compiler.absyntree import Module
from jaclang.plugin.default import (
Expand Down Expand Up @@ -149,7 +149,6 @@ def edge_ref(
node_obj: NodeArchitype | list[NodeArchitype],
target_obj: Optional[NodeArchitype | list[NodeArchitype]],
dir: EdgeDir,
filter_type: Optional[type],
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
edges_only: bool,
) -> list[NodeArchitype] | list[EdgeArchitype]:
Expand Down Expand Up @@ -182,16 +181,6 @@ def disconnect(
"""Jac's disconnect operator feature."""
raise NotImplementedError

@staticmethod
@hookspec(firstresult=True)
def filter_compr(
target_obj: Sequence[T] | T,
filter_type: Optional[type],
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
) -> list[T] | T | None:
"""Jac's assign comprehension feature."""
raise NotImplementedError

@staticmethod
@hookspec(firstresult=True)
def assign_compr(
Expand Down

0 comments on commit 00fb37d

Please sign in to comment.