This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #569 from Jaseci-Labs/architype_context
Initial Commit for resolving architype
- Loading branch information
Showing
4 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Define a simple node type called `Item` | ||
node Item { | ||
has value: int = 0; | ||
} | ||
|
||
# Define an edge type called `Link` | ||
edge Link {} | ||
|
||
# Define the `bar` walker | ||
walker bar_walk { | ||
has count: int = 0; | ||
|
||
# Start walking from the root node or an Item node | ||
can start with `root | Item entry { | ||
here ++> Item(); | ||
if self.count < 5 { | ||
visit [-->]; | ||
} else { | ||
"Created 5 items." |> print; | ||
disengage; | ||
} | ||
} | ||
|
||
# Walk over Item nodes and update their values | ||
can walk with Item entry { | ||
here.value = self.count; | ||
f"Item value: {here.value}" |> print; | ||
self.count += 1; | ||
visit [-->] else { | ||
"Finished walking over all items." |> print; | ||
disengage; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import:py from jaclang.plugin.feature, JacFeature as Jac; | ||
import:jac from bar, bar_walk; | ||
|
||
|
||
# Test runner to initialize the walker | ||
can test_run { | ||
# Print the loaded modules | ||
modules = Jac.context().jac_machine.list_modules(); | ||
"Loaded Modules:" |> print; | ||
for mod_name in modules { | ||
f"Module: {mod_name}" |> print; | ||
} | ||
# Print walkers | ||
walkers = Jac.context().jac_machine.list_walkers(mod_name); | ||
if walkers{ | ||
f"Walkers in {mod_name}:" |> print; | ||
for walker in walkers{ | ||
f" - Walker: {walker}" |> print; | ||
} | ||
} | ||
|
||
# Print nodes | ||
nodes = Jac.context().jac_machine.list_nodes(mod_name); | ||
if nodes{ | ||
f"Nodes in {mod_name}:" |> print; | ||
for node in nodes{ | ||
f" - Node: {node}" |> print; | ||
} | ||
} | ||
# Print edges | ||
edges = Jac.context().jac_machine.list_edges(mod_name); | ||
if edges{ | ||
f"Edges in {mod_name}:" |> print; | ||
for edge in edges{ | ||
f" - Edge: {edge}" |> print; | ||
} | ||
} | ||
root spawn bar_walk(); | ||
} | ||
|
||
# Define the entry point to run the test | ||
with entry { | ||
test_run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters