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 #572 from Jaseci-Labs/pr-series/2
Browse files Browse the repository at this point in the history
(PR-SERIES-P2) [REFACTOR]: Element/ObjectAnchor to Anchor
  • Loading branch information
marsninja authored Aug 15, 2024
2 parents 46fae81 + 9c44f36 commit de00856
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 89 deletions.
52 changes: 24 additions & 28 deletions jaclang/compiler/passes/tool/tests/fixtures/corelib.jac
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ obj ExecutionContext {
"Global Execution Context, should be monkey patched by the user."
glob exec_ctx = ExecutionContext();

obj ElementAnchor {
obj Anchor :ArchitypeProtocol: {
has ob: object,
jid: UUID = :> uuid4,
timestamp: datetime = :> datetime.now,
Expand All @@ -41,8 +41,12 @@ obj ElementAnchor {
rw_access: set = :> set,
ro_access: set = :> set,
owner_id: UUID = exec_ctx.master,
mem: Memory = exec_ctx.memory;
mem: Memory = exec_ctx.memory,
ds_entry_funcs: list[DSFunc],
ds_exit_funcs: list[DSFunc];

static can on_entry(cls: type, triggers: list[type]);
static can on_exit(cls: type, triggers: list[type]);
can make_public_ro;
can make_public_rw;
can make_private;
Expand All @@ -55,23 +59,15 @@ obj ElementAnchor {
can revoke_access(caller_id: UUID);
}

obj ObjectAnchor :ElementAnchor, ArchitypeProtocol: {
has ds_entry_funcs: list[DSFunc],
ds_exit_funcs: list[DSFunc];

static can on_entry(cls: type, triggers: list[type]);
static can on_exit(cls: type, triggers: list[type]);
}

obj NodeAnchor :ObjectAnchor: {
obj NodeAnchor :Anchor: {
has edges: dict[EdgeDir, list[Edge]] = {EdgeDir.IN: [], EdgeDir.OUT: []};

can connect_node(nd: Node, edg: Edge) -> Node;
can edges_to_nodes(dir: EdgeDir) -> list[Node];
can __call__(walk: Walker);
}

obj EdgeAnchor :ObjectAnchor: {
obj EdgeAnchor :Anchor: {
has source: Node = None,
target: Node = None,
dir: EdgeDir = None;
Expand All @@ -81,7 +77,7 @@ obj EdgeAnchor :ObjectAnchor: {
can __call__(walk: Walker);
}

obj WalkerAnchor :ObjectAnchor: {
obj WalkerAnchor :Anchor: {
has path: list[Node] = [],
next: list[Node] = [],
ignores: list[Node] = [],
Expand Down Expand Up @@ -110,11 +106,11 @@ obj GenericEdge :ArchitypeProtocol: {
}

obj Master {
has __jac__: ElementAnchor | None = None;
has __jac__: Anchor | None = None;
has root_node: Root = Root(Root);

can postinit {
self.__jac__ = ElementAnchor(self);
self.__jac__ = Anchor(self);
}
}

Expand Down Expand Up @@ -204,46 +200,46 @@ obj JacPlugin {
PRIVATE
}

:obj:ElementAnchor:can:make_public_ro {
:obj:Anchor:can:make_public_ro {
self.__jinfo.access_mode = AccessMode.READ_ONLY;
}

:obj:ElementAnchor:can:make_public_rw {
:obj:Anchor:can:make_public_rw {
self.__jinfo.access_mode = AccessMode.READ_WRITE;
}

:obj:ElementAnchor:can:make_private {
:obj:Anchor:can:make_private {
self.__jinfo.access_mode = AccessMode.PRIVATE;
}

:obj:ElementAnchor:can:is_public_ro -> bool {
:obj:Anchor:can:is_public_ro -> bool {
return self.__jinfo.access_mode == AccessMode.READ_ONLY;
}

:obj:ElementAnchor:can:is_public_rw -> bool {
:obj:Anchor:can:is_public_rw -> bool {
return self.__jinfo.access_mode == AccessMode.READ_WRITE;
}

:obj:ElementAnchor:can:is_private -> bool {
:obj:Anchor:can:is_private -> bool {
return self.__jinfo.access_mode == AccessMode.PRIVATE;
}

:obj:ElementAnchor:can:is_readable
:obj:Anchor:can:is_readable
(caller_id: UUID) -> bool {
return (caller_id == self.owner_id
or |> self.is_public_read
or caller_id in self.ro_access
or caller_id in self.rw_access);
}

:obj:ElementAnchor:can:is_writable
:obj:Anchor:can:is_writable
(caller_id: UUID) -> bool {
return (caller_id == self.owner_id
or |> self.is_public_write
or caller_id in self.rw_access);
}

:obj:ElementAnchor:can:give_access
:obj:Anchor:can:give_access
(caller_id: UUID, read_write: bool=False) {
if read_write {
caller_id |> self.rw_access.add;
Expand All @@ -252,13 +248,13 @@ obj JacPlugin {
}
}

:obj:ElementAnchor:can:revoke_access
:obj:Anchor:can:revoke_access
(caller_id: UUID) {
caller_id |> self.ro_access.discard;
caller_id |> self.rw_access.discard;
}

:obj:ObjectAnchor:can:on_entry
:obj:Anchor:can:on_entry
(cls: type, triggers: list) {
can decorator(func: callable) -> callable {
cls.ds_entry_funcs.append(
Expand All @@ -272,7 +268,7 @@ obj JacPlugin {
return decorator;
}

:obj:ObjectAnchor:can:on_exit
:obj:Anchor:can:on_exit
(cls: type, triggers: list) {
can decorator(func: callable) -> callable {
cls.ds_exit_funcs.append(
Expand Down Expand Up @@ -423,7 +419,7 @@ obj JacPlugin {
(arch: AT, arch_type: str, on_entry: list[DSFunc], on_exit: list[DSFunc]) -> bool {
match arch_type {
case 'obj':
arch.__jac__ = ObjectAnchor(
arch.__jac__ = Anchor(
ob=arch,
ds_entry_funcs=on_entry,
ds_exit_funcs=on_exit
Expand Down
52 changes: 24 additions & 28 deletions jaclang/compiler/passes/tool/tests/fixtures/corelib_fmt.jac
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ obj ExecutionContext {
"Global Execution Context, should be monkey patched by the user."
glob exec_ctx = ExecutionContext();

obj ElementAnchor {
obj Anchor :ArchitypeProtocol: {
has ob: object,
jid: UUID = :> uuid4,
timestamp: datetime = :> datetime.now,
Expand All @@ -40,8 +40,12 @@ obj ElementAnchor {
rw_access: set = :> set,
ro_access: set = :> set,
owner_id: UUID = exec_ctx.master,
mem: Memory = exec_ctx.memory;
mem: Memory = exec_ctx.memory,
ds_entry_funcs: list[DSFunc],
ds_exit_funcs: list[DSFunc];

static can on_entry(cls: type, triggers: list[type]);
static can on_exit(cls: type, triggers: list[type]);
can make_public_ro;
can make_public_rw;
can make_private;
Expand All @@ -54,23 +58,15 @@ obj ElementAnchor {
can revoke_access(caller_id: UUID);
}

obj ObjectAnchor :ElementAnchor, ArchitypeProtocol: {
has ds_entry_funcs: list[DSFunc],
ds_exit_funcs: list[DSFunc];

static can on_entry(cls: type, triggers: list[type]);
static can on_exit(cls: type, triggers: list[type]);
}

obj NodeAnchor :ObjectAnchor: {
obj NodeAnchor :Anchor: {
has edges: dict[EdgeDir, list[Edge]] = {EdgeDir.IN: [], EdgeDir.OUT: []};

can connect_node(nd: Node, edg: Edge) -> Node;
can edges_to_nodes(dir: EdgeDir) -> list[Node];
can __call__(walk: Walker);
}

obj EdgeAnchor :ObjectAnchor: {
obj EdgeAnchor :Anchor: {
has source: Node = None,
target: Node = None,
dir: EdgeDir = None;
Expand All @@ -80,7 +76,7 @@ obj EdgeAnchor :ObjectAnchor: {
can __call__(walk: Walker);
}

obj WalkerAnchor :ObjectAnchor: {
obj WalkerAnchor :Anchor: {
has path: list[Node] = [],
next: list[Node] = [],
ignores: list[Node] = [],
Expand Down Expand Up @@ -109,11 +105,11 @@ obj GenericEdge :ArchitypeProtocol: {
}

obj Master {
has __jac__: ElementAnchor | None = None;
has __jac__: Anchor | None = None;
has root_node: Root = Root(Root);

can postinit {
self.__jac__ = ElementAnchor(self);
self.__jac__ = Anchor(self);
}
}

Expand Down Expand Up @@ -203,46 +199,46 @@ obj JacPlugin {
PRIVATE
}

:obj:ElementAnchor:can:make_public_ro {
:obj:Anchor:can:make_public_ro {
self.__jinfo.access_mode = AccessMode.READ_ONLY;
}

:obj:ElementAnchor:can:make_public_rw {
:obj:Anchor:can:make_public_rw {
self.__jinfo.access_mode = AccessMode.READ_WRITE;
}

:obj:ElementAnchor:can:make_private {
:obj:Anchor:can:make_private {
self.__jinfo.access_mode = AccessMode.PRIVATE;
}

:obj:ElementAnchor:can:is_public_ro -> bool {
:obj:Anchor:can:is_public_ro -> bool {
return self.__jinfo.access_mode == AccessMode.READ_ONLY;
}

:obj:ElementAnchor:can:is_public_rw -> bool {
:obj:Anchor:can:is_public_rw -> bool {
return self.__jinfo.access_mode == AccessMode.READ_WRITE;
}

:obj:ElementAnchor:can:is_private -> bool {
:obj:Anchor:can:is_private -> bool {
return self.__jinfo.access_mode == AccessMode.PRIVATE;
}

:obj:ElementAnchor:can:is_readable
:obj:Anchor:can:is_readable
(caller_id: UUID) -> bool {
return (caller_id == self.owner_id
or |> self.is_public_read
or caller_id in self.ro_access
or caller_id in self.rw_access);
}

:obj:ElementAnchor:can:is_writable
:obj:Anchor:can:is_writable
(caller_id: UUID) -> bool {
return (caller_id == self.owner_id
or |> self.is_public_write
or caller_id in self.rw_access);
}

:obj:ElementAnchor:can:give_access
:obj:Anchor:can:give_access
(caller_id: UUID, read_write: bool=False) {
if read_write {
caller_id |> self.rw_access.add;
Expand All @@ -251,13 +247,13 @@ obj JacPlugin {
}
}

:obj:ElementAnchor:can:revoke_access
:obj:Anchor:can:revoke_access
(caller_id: UUID) {
caller_id |> self.ro_access.discard;
caller_id |> self.rw_access.discard;
}

:obj:ObjectAnchor:can:on_entry
:obj:Anchor:can:on_entry
(cls: type, triggers: list) {
can decorator(func: callable) -> callable {
cls.ds_entry_funcs.append(
Expand All @@ -271,7 +267,7 @@ obj JacPlugin {
return decorator;
}

:obj:ObjectAnchor:can:on_exit
:obj:Anchor:can:on_exit
(cls: type, triggers: list) {
can decorator(func: callable) -> callable {
cls.ds_exit_funcs.append(
Expand Down Expand Up @@ -422,7 +418,7 @@ obj JacPlugin {
(arch: AT, arch_type: str, on_entry: list[DSFunc], on_exit: list[DSFunc]) -> bool {
match arch_type {
case 'obj':
arch.__jac__ = ObjectAnchor(
arch.__jac__ = Anchor(
ob=arch,
ds_entry_funcs=on_entry,
ds_exit_funcs=on_exit
Expand Down
4 changes: 2 additions & 2 deletions jaclang/plugin/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from jaclang.compiler.passes.main.pyast_gen_pass import PyastGenPass
from jaclang.compiler.semtable import SemInfo, SemRegistry, SemScope
from jaclang.runtimelib.constructs import (
Anchor,
Architype,
DSFunc,
EdgeAnchor,
Expand All @@ -28,7 +29,6 @@
Memory,
NodeAnchor,
NodeArchitype,
ObjectAnchor,
Root,
WalkerAnchor,
WalkerArchitype,
Expand All @@ -45,12 +45,12 @@
hookimpl = pluggy.HookimplMarker("jac")

__all__ = [
"Anchor",
"EdgeAnchor",
"GenericEdge",
"hookimpl",
"JacTestCheck",
"NodeAnchor",
"ObjectAnchor",
"WalkerAnchor",
"NodeArchitype",
"EdgeArchitype",
Expand Down
Loading

0 comments on commit de00856

Please sign in to comment.