From 00fb37d09b88972078886294172f8b2de50b7ea2 Mon Sep 17 00:00:00 2001 From: marsninja Date: Fri, 23 Feb 2024 20:56:23 -0500 Subject: [PATCH] chore: complxity reduction --- examples/micro/another.jac | 2 +- jaclang/core/construct.py | 6 ------ jaclang/plugin/default.py | 19 +++---------------- jaclang/plugin/feature.py | 15 +-------------- jaclang/plugin/spec.py | 13 +------------ 5 files changed, 6 insertions(+), 49 deletions(-) diff --git a/examples/micro/another.jac b/examples/micro/another.jac index dfbeb598f..d0c81bbbc 100644 --- a/examples/micro/another.jac +++ b/examples/micro/another.jac @@ -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); } diff --git a/jaclang/core/construct.py b/jaclang/core/construct.py index fcb1d4eac..fe8d860da 100644 --- a/jaclang/core/construct.py +++ b/jaclang/core/construct.py @@ -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 ( @@ -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: diff --git a/jaclang/plugin/default.py b/jaclang/plugin/default.py index 81919a337..71af130be 100644 --- a/jaclang/plugin/default.py +++ b/jaclang/plugin/default.py @@ -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 @@ -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]: @@ -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)) @@ -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( diff --git a/jaclang/plugin/feature.py b/jaclang/plugin/feature.py index 46e41d7a0..b88e500cb 100644 --- a/jaclang/plugin/feature.py +++ b/jaclang/plugin/feature.py @@ -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 ( @@ -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]: @@ -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, ) @@ -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]] diff --git a/jaclang/plugin/spec.py b/jaclang/plugin/spec.py index 4488b24a6..180cc0834 100644 --- a/jaclang/plugin/spec.py +++ b/jaclang/plugin/spec.py @@ -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 ( @@ -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]: @@ -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(