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

Commit

Permalink
[REFACTOR]: Rename ObjectAnchor to Anchor
Browse files Browse the repository at this point in the history
  • Loading branch information
amadolid committed Jul 12, 2024
1 parent 7dc9c71 commit bad20f1
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 43 deletions.
4 changes: 2 additions & 2 deletions jaclang/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from jaclang.compiler.passes.main.pyast_load_pass import PyastBuildPass
from jaclang.compiler.passes.main.schedules import py_code_gen_typed
from jaclang.compiler.passes.tool.schedules import format_pass
from jaclang.core.constructs import NodeAnchor, ObjectAnchor
from jaclang.core.constructs import Anchor, NodeAnchor
from jaclang.plugin.builtin import dotgen
from jaclang.plugin.feature import JacCmd as Cmd
from jaclang.plugin.feature import JacFeature as Jac
Expand Down Expand Up @@ -141,7 +141,7 @@ def get_object(id: str, session: str = "") -> dict[str, object]:
if id == "root":
super_root = jctx.super_root
response = super_root.serialize()
elif (anchor := ObjectAnchor.ref(id)) and anchor.sync():
elif (anchor := Anchor.ref(id)) and anchor.sync():
response = anchor.serialize()

jctx.close()
Expand Down
36 changes: 18 additions & 18 deletions jaclang/core/architype.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def deserialize(cls, data: dict[str, Any]) -> Permission:


@dataclass(eq=False)
class ObjectAnchor:
class Anchor:
"""Object Anchor."""

type: ObjectType = ObjectType.generic
Expand All @@ -160,10 +160,10 @@ def ref_id(self) -> str:
return f"{self.type.value}:{self.name}:{self.id}"

@staticmethod
def ref(ref_id: str) -> Optional[ObjectAnchor]:
def ref(ref_id: str) -> Optional[Anchor]:
"""Return ObjectAnchor instance if ."""
if matched := GENERIC_ID_REGEX.search(ref_id):
cls: type = ObjectAnchor
cls: type = Anchor
match ObjectType(matched.group(1)):
case ObjectType.node:
cls = NodeAnchor
Expand Down Expand Up @@ -209,19 +209,19 @@ def allocate(self) -> None:
self.root = jctx.root.id
jctx.datasource.set(self, True)

def has_read_access(self, to: ObjectAnchor) -> bool:
def has_read_access(self, to: Anchor) -> bool:
"""Read Access Validation."""
return self.access_level(to) > -1

def has_connect_access(self, to: ObjectAnchor) -> bool:
def has_connect_access(self, to: Anchor) -> bool:
"""Write Access Validation."""
return self.access_level(to) > 0

def has_write_access(self, to: ObjectAnchor) -> bool:
def has_write_access(self, to: Anchor) -> bool:
"""Write Access Validation."""
return self.access_level(to) > 1

def access_level(self, to: ObjectAnchor) -> int:
def access_level(self, to: Anchor) -> int:
"""Access validation."""
from .context import ExecutionContext

Expand Down Expand Up @@ -301,7 +301,7 @@ def __hash__(self) -> int:

def __eq__(self, other: object) -> bool:
"""Override equal implementation."""
if isinstance(other, ObjectAnchor):
if isinstance(other, Anchor):
return (
self.type == other.type
and self.name == other.name
Expand All @@ -316,7 +316,7 @@ def __eq__(self, other: object) -> bool:


@dataclass(eq=False)
class NodeAnchor(ObjectAnchor):
class NodeAnchor(Anchor):
"""Node Anchor."""

type: ObjectType = ObjectType.node
Expand Down Expand Up @@ -480,7 +480,7 @@ def serialize(self) -> dict[str, object]:


@dataclass(eq=False)
class EdgeAnchor(ObjectAnchor):
class EdgeAnchor(Anchor):
"""Edge Anchor."""

type: ObjectType = ObjectType.edge
Expand Down Expand Up @@ -585,14 +585,14 @@ def serialize(self) -> dict[str, object]:


@dataclass(eq=False)
class WalkerAnchor(ObjectAnchor):
class WalkerAnchor(Anchor):
"""Walker Anchor."""

type: ObjectType = ObjectType.walker
architype: Optional[WalkerArchitype] = None
path: list[ObjectAnchor] = field(default_factory=list)
next: list[ObjectAnchor] = field(default_factory=list)
ignores: list[ObjectAnchor] = field(default_factory=list)
path: list[Anchor] = field(default_factory=list)
next: list[Anchor] = field(default_factory=list)
ignores: list[Anchor] = field(default_factory=list)
disengaged: bool = False
persistent: bool = False # Disabled initially but can be adjusted

Expand Down Expand Up @@ -667,7 +667,7 @@ def disengage_now(self) -> None:
"""Disengage walker from traversal."""
self.disengaged = True

def spawn_call(self, nd: ObjectAnchor) -> WalkerArchitype:
def spawn_call(self, nd: Anchor) -> WalkerArchitype:
"""Invoke data spatial call."""
if walker := self.sync():
self.path = []
Expand Down Expand Up @@ -718,16 +718,16 @@ class Architype:
_jac_exit_funcs_: list[DSFunc]
_jac_classes_: dict[str, type[Architype]]

def __init__(self, __jac__: Optional[ObjectAnchor] = None) -> None:
def __init__(self, __jac__: Optional[Anchor] = None) -> None:
"""Create default architype."""
self.__jac__ = __jac__ or ObjectAnchor(architype=self)
self.__jac__ = __jac__ or Anchor(architype=self)
self.__jac__.allocate()

def __eq__(self, other: object) -> bool:
"""Override equal implementation."""
if isinstance(other, Architype):
return super().__eq__(other)
elif isinstance(other, ObjectAnchor):
elif isinstance(other, Anchor):
return self.__jac__ == other

return False
Expand Down
4 changes: 2 additions & 2 deletions jaclang/core/constructs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@


from .architype import (
Anchor,
Architype,
DSFunc,
EdgeAnchor,
EdgeArchitype,
GenericEdge,
NodeAnchor,
NodeArchitype,
ObjectAnchor,
Root,
WalkerAnchor,
WalkerArchitype,
Expand All @@ -21,7 +21,7 @@
from .test import JacTestCheck, JacTestResult, JacTextTestRunner

__all__ = [
"ObjectAnchor",
"Anchor",
"NodeAnchor",
"EdgeAnchor",
"WalkerAnchor",
Expand Down
30 changes: 14 additions & 16 deletions jaclang/core/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from uuid import UUID

from .architype import (
Anchor,
Architype,
EdgeAnchor,
EdgeArchitype,
MANUAL_SAVE,
NodeAnchor,
NodeArchitype,
ObjectAnchor,
ObjectType,
Permission,
WalkerAnchor,
Expand All @@ -27,7 +27,7 @@
class Memory:
"""Generic Memory Handler."""

__mem__: dict[str, ObjectAnchor] = field(default_factory=dict)
__mem__: dict[str, Anchor] = field(default_factory=dict)
__gc__: set[str] = field(default_factory=set)

def close(self) -> None:
Expand All @@ -40,8 +40,8 @@ def __del__(self) -> None:
self.close()

def find(
self, ids: IDS, filter: Optional[Callable[[ObjectAnchor], ObjectAnchor]] = None
) -> Generator[ObjectAnchor, None, None]:
self, ids: IDS, filter: Optional[Callable[[Anchor], Anchor]] = None
) -> Generator[Anchor, None, None]:
"""Find anchors from memory by ids with filter."""
if not isinstance(ids, list):
ids = [ids]
Expand All @@ -55,12 +55,12 @@ def find(
def find_one(
self,
ids: IDS,
filter: Optional[Callable[[ObjectAnchor], ObjectAnchor]] = None,
) -> Optional[ObjectAnchor]:
filter: Optional[Callable[[Anchor], Anchor]] = None,
) -> Optional[Anchor]:
"""Find one anchor from memory by ids with filter."""
return next(self.find(ids, filter), None)

def set(self, data: Union[ObjectAnchor, list[ObjectAnchor]]) -> None:
def set(self, data: Union[Anchor, list[Anchor]]) -> None:
"""Save anchor/s to memory."""
if isinstance(data, list):
for d in data:
Expand All @@ -69,7 +69,7 @@ def set(self, data: Union[ObjectAnchor, list[ObjectAnchor]]) -> None:
elif str(data.id) not in self.__gc__:
self.__mem__[str(data.id)] = data

def remove(self, data: Union[ObjectAnchor, list[ObjectAnchor]]) -> None:
def remove(self, data: Union[Anchor, list[Anchor]]) -> None:
"""Remove anchor/s from memory."""
if isinstance(data, list):
for d in data:
Expand Down Expand Up @@ -106,8 +106,8 @@ def close(self) -> None:
super().close()

def find(
self, ids: IDS, filter: Optional[Callable[[ObjectAnchor], ObjectAnchor]] = None
) -> Generator[ObjectAnchor, None, None]:
self, ids: IDS, filter: Optional[Callable[[Anchor], Anchor]] = None
) -> Generator[Anchor, None, None]:
"""Find anchors from datasource by ids with filter."""
if not isinstance(ids, list):
ids = [ids]
Expand All @@ -128,9 +128,7 @@ def find(
else:
yield from super().find(ids, filter)

def set(
self, data: Union[ObjectAnchor, list[ObjectAnchor]], mem_only: bool = False
) -> None:
def set(self, data: Union[Anchor, list[Anchor]], mem_only: bool = False) -> None:
"""Save anchor/s to datasource."""
super().set(data)

Expand All @@ -146,7 +144,7 @@ def set(
if d.current_access_level > 1:
self.__shelf__[_id]["architype"] = json["architype"]

def remove(self, data: Union[ObjectAnchor, list[ObjectAnchor]]) -> None:
def remove(self, data: Union[Anchor, list[Anchor]]) -> None:
"""Remove anchor/s from datasource."""
super().remove(data)
if isinstance(self.__shelf__, Shelf) and MANUAL_SAVE:
Expand All @@ -156,7 +154,7 @@ def remove(self, data: Union[ObjectAnchor, list[ObjectAnchor]]) -> None:
else:
self.__shelf__.pop(str(data.id), None)

def get(self, anchor: dict[str, Any]) -> ObjectAnchor:
def get(self, anchor: dict[str, Any]) -> Anchor:
"""Get Anchor Instance."""
name = cast(str, anchor.get("name"))
architype = anchor.pop("architype")
Expand Down Expand Up @@ -191,6 +189,6 @@ def get(self, anchor: dict[str, Any]) -> ObjectAnchor:
wanch.architype = WalkerArchitype.get(name)(__jac__=wanch, **architype)
return wanch
case _:
oanch = ObjectAnchor(access=access, **anchor)
oanch = Anchor(access=access, **anchor)
oanch.architype = Architype(__jac__=oanch)
return oanch
6 changes: 3 additions & 3 deletions jaclang/plugin/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from jaclang.compiler.constant import EdgeDir, T, colors
from jaclang.compiler.semtable import SemInfo, SemRegistry, SemScope
from jaclang.core.constructs import (
Anchor,
Architype,
DSFunc,
EdgeAnchor,
Expand All @@ -24,7 +25,6 @@
JacTestCheck,
NodeAnchor,
NodeArchitype,
ObjectAnchor,
Root,
WalkerAnchor,
WalkerArchitype,
Expand All @@ -43,7 +43,7 @@
"GenericEdge",
"JacTestCheck",
"NodeAnchor",
"ObjectAnchor",
"Anchor",
"WalkerAnchor",
"NodeArchitype",
"EdgeArchitype",
Expand Down Expand Up @@ -112,7 +112,7 @@ def make_architype(
def new_init(
self: Architype,
*args: object,
__jac__: Optional[ObjectAnchor] = None,
__jac__: Optional[Anchor] = None,
**kwargs: object,
) -> None:
arch_base.__init__(self, __jac__)
Expand Down
4 changes: 2 additions & 2 deletions stubs/jaclang/plugin/default.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import types
from jaclang.compiler.constant import EdgeDir
from jaclang.core.constructs import (
Anchor as Anchor,
Architype as Architype,
DSFunc as DSFunc,
EdgeAnchor as EdgeAnchor,
Expand All @@ -9,7 +10,6 @@ from jaclang.core.constructs import (
JacTestCheck as JacTestCheck,
NodeAnchor as NodeAnchor,
NodeArchitype as NodeArchitype,
ObjectAnchor as ObjectAnchor,
Root as Root,
WalkerAnchor as WalkerAnchor,
WalkerArchitype as WalkerArchitype,
Expand All @@ -25,7 +25,7 @@ __all__ = [
"GenericEdge",
"JacTestCheck",
"NodeAnchor",
"ObjectAnchor",
"Anchor",
"WalkerAnchor",
"NodeArchitype",
"EdgeArchitype",
Expand Down

0 comments on commit bad20f1

Please sign in to comment.