Skip to content

Commit

Permalink
[REFACTOR]: Spawn Call wlk-ent -> wlk-ent-with -> node-ent -> node-en…
Browse files Browse the repository at this point in the history
…t-with -> node-ext-with -> node-ext -> wlk-ext-with -> wlk-ext
  • Loading branch information
amadolid committed Oct 11, 2024
1 parent e93ba97 commit 8a7a06d
Show file tree
Hide file tree
Showing 10 changed files with 410 additions and 101 deletions.
6 changes: 3 additions & 3 deletions jac-cloud/jac_cloud/core/architype.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,10 +766,10 @@ class WalkerAnchor(BaseAnchor, _WalkerAnchor): # type: ignore[misc]
"""Walker Anchor."""

architype: "WalkerArchitype"
path: list[Anchor] = field(default_factory=list)
next: list[Anchor] = field(default_factory=list)
path: list[NodeAnchor] = field(default_factory=list) # type: ignore[assignment]
next: list[NodeAnchor] = field(default_factory=list) # type: ignore[assignment]
returns: list[Any] = field(default_factory=list)
ignores: list[Anchor] = field(default_factory=list)
ignores: list[NodeAnchor] = field(default_factory=list) # type: ignore[assignment]
disengaged: bool = False

class Collection(BaseCollection["WalkerAnchor"]):
Expand Down
105 changes: 66 additions & 39 deletions jac-cloud/jac_cloud/plugin/jaseci.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from jaclang.plugin.default import JacFeatureImpl, hookimpl
from jaclang.plugin.feature import JacFeature as Jac
from jaclang.runtimelib.architype import DSFunc
from jaclang.runtimelib.utils import all_issubclass

from orjson import loads

Expand Down Expand Up @@ -718,59 +719,85 @@ def spawn_call(op1: Architype, op2: Architype) -> WalkerArchitype:
walker.path = []
walker.next = [node]
walker.returns = []
current_node = node.architype

# walker entry
for i in warch._jac_entry_funcs_:
if i.func and not i.trigger:
walker.returns.append(i.func(warch, current_node))
if walker.disengaged:
return warch

if walker.next:
current_node = walker.next[-1].architype
for i in warch._jac_entry_funcs_:
if not i.trigger:
if i.func:
walker.returns.append(i.func(warch, current_node))
else:
raise ValueError(f"No function {i.name} to call.")
while len(walker.next):
if current_node := walker.next.pop(0).architype:
# walker entry with
for i in warch._jac_entry_funcs_:
if (
i.func
and i.trigger
and all_issubclass(i.trigger, NodeArchitype)
and isinstance(current_node, i.trigger)
):
walker.returns.append(i.func(warch, current_node))
if walker.disengaged:
return warch

# node entry
for i in current_node._jac_entry_funcs_:
if not i.trigger or isinstance(walker, i.trigger):
if i.func:
walker.returns.append(i.func(current_node, warch))
else:
raise ValueError(f"No function {i.name} to call.")
if i.func and not i.trigger:
walker.returns.append(i.func(current_node, warch))
if walker.disengaged:
return warch
for i in warch._jac_entry_funcs_:
if not i.trigger or isinstance(current_node, i.trigger):
if i.func and i.trigger:
walker.returns.append(i.func(warch, current_node))
elif not i.trigger:
continue
else:
raise ValueError(f"No function {i.name} to call.")

# node entry with
for i in current_node._jac_entry_funcs_:
if (
i.func
and i.trigger
and all_issubclass(i.trigger, WalkerArchitype)
and isinstance(warch, i.trigger)
):
walker.returns.append(i.func(current_node, warch))
if walker.disengaged:
return warch
for i in warch._jac_exit_funcs_:
if not i.trigger or isinstance(current_node, i.trigger):
if i.func and i.trigger:
walker.returns.append(i.func(warch, current_node))
elif not i.trigger:
continue
else:
raise ValueError(f"No function {i.name} to call.")

# node exit with
for i in current_node._jac_exit_funcs_:
if (
i.func
and i.trigger
and all_issubclass(i.trigger, WalkerArchitype)
and isinstance(warch, i.trigger)
):
walker.returns.append(i.func(current_node, warch))
if walker.disengaged:
return warch

# node exit
for i in current_node._jac_exit_funcs_:
if not i.trigger or isinstance(walker, i.trigger):
if i.func:
walker.returns.append(i.func(current_node, warch))
else:
raise ValueError(f"No function {i.name} to call.")
if i.func and not i.trigger:
walker.returns.append(i.func(current_node, warch))
if walker.disengaged:
return warch

# walker exit with
for i in warch._jac_exit_funcs_:
if (
i.func
and i.trigger
and all_issubclass(i.trigger, NodeArchitype)
and isinstance(current_node, i.trigger)
):
walker.returns.append(i.func(warch, current_node))
if walker.disengaged:
return warch
# walker exit
for i in warch._jac_exit_funcs_:
if not i.trigger:
if i.func:
walker.returns.append(i.func(warch, current_node))
else:
raise ValueError(f"No function {i.name} to call.")
if i.func and not i.trigger:
walker.returns.append(i.func(warch, current_node))
if walker.disengaged:
return warch

walker.ignores = []
return warch

Expand Down
72 changes: 72 additions & 0 deletions jac-cloud/jac_cloud/tests/openapi_specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4540,6 +4540,78 @@
}
}
}
},
"/walker/visit_sequence": {
"post": {
"tags": [
"walker",
"walker"
],
"summary": "/visit_sequence",
"operationId": "api_root_walker_visit_sequence_post",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ContextResponse_NoneType_"
}
}
}
}
}
}
},
"/walker/visit_sequence/{node}": {
"post": {
"tags": [
"walker",
"walker"
],
"summary": "/visit_sequence/{node}",
"operationId": "api_entry_walker_visit_sequence__node__post",
"parameters": [
{
"name": "node",
"in": "path",
"required": true,
"schema": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Node"
}
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ContextResponse_NoneType_"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
}
},
"components": {
Expand Down
57 changes: 57 additions & 0 deletions jac-cloud/jac_cloud/tests/simple_graph.jac
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,63 @@ walker different_return {
can enter6 with `root entry -> list | dict {
}

class __specs__ {
has auth: bool = False;
}
}

walker Walker {
class __specs__ {
has private: bool = True;
}
}

node Node {
has val: str;

can entry1 with entry {
return f"{self.val}-2";
}

# with 'visit_sequence' (string class reference) is not yet supported
can entry3 with Walker entry {
return f"{self.val}-3";
}

# with 'visit_sequence' (string class reference) is not yet supported
can exit1 with Walker exit {
return f"{self.val}-4";
}

can exit2 with exit {
return f"{self.val}-5";
}
}
walker visit_sequence:Walker: {
can entry1 with entry {
return "walker entry";
}

can entry2 with `root entry {
here ++> Node(val = "a");
here ++> Node(val = "b");
here ++> Node(val = "c");
visit [-->];
return "walker enter to root";
}

can entry3 with Node entry {
return f"{here.val}-1";
}

can exit1 with Node exit {
return f"{here.val}-6";
}

can exit2 with exit {
return "walker exit";
}

class __specs__ {
has auth: bool = False;
}
Expand Down
Loading

0 comments on commit 8a7a06d

Please sign in to comment.