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

Commit

Permalink
refactored: connect.jac, edges_ops.jac, construct.py, test passed for…
Browse files Browse the repository at this point in the history
… conn_assign
  • Loading branch information
Saru1999 committed Jan 27, 2024
1 parent 6ddcc45 commit e95561e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 46 deletions.
29 changes: 6 additions & 23 deletions examples/reference/connect_expressions.jac
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@ walker Creator {
}

node node_a{
has val:int;
can print_some with Creator entry;
has value:int;
}

walker Travelor{
can travel with `<root>|node_a entry;
}
node node_b{
has value:int;
can do with Travelor entry;
can print_one with Creator entry;
}

edge MyEdge {
has val:int =5;
Expand All @@ -25,39 +19,28 @@ edge MyEdge {
:walker:Creator:can:create{
end = <here>;
for i = 0 to i<5 by i+=1{
end ++> end := node_a(val=i+1);
end ++> end := node_a(value=i+1);
#connect three nodes of node_b from node_a(val=3)
if i == 2{
for j=0 to j<3 by j+=1 {
end +:MyEdge:val=random.randint(1,5):+> node_b(value=j+10);
end +:MyEdge:val=random.randint(1,5):+> node_a(value=j+10);
}

}
}
#connect 3 nodes of node_b from the last node_a created
for i=0 to i<3 by i+=1 {
end +:MyEdge:val=random.randint(1,5):+> node_b(value=i+5);
print(end._jac_.edges);
end +:MyEdge:val=random.randint(1,15):+> node_a(value=i+5);
}
visit-->;
}
:walker:Travelor:can:travel{
#print the node values that is connected with MyEdge edges of val less than 5
for i in -:MyEdge:val<=5 :->{
print(i.val);
print(i.value);
}
visit-->;
}


:node:node_a:can:print_some{
visit--> ;
}
:node:node_b:can:do{
visit-->;
}
:node:node_b:can:print_one{
}

with entry{
<root> spawn Creator();
<root> spawn Travelor();
Expand Down
4 changes: 3 additions & 1 deletion jaclang/compiler/passes/main/pyast_gen_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -2043,7 +2043,9 @@ def translate_edge_op_ref(self, loc: ast3.AST, node: ast.EdgeOpRef) -> ast3.AST:
node.filter_type.gen.py_ast
if node.filter_type
else self.sync(ast3.Constant(value=None)),
node.filter_cond.gen.py_ast if node.filter_cond else self.sync(ast3.Constant(value=None))
node.filter_cond.gen.py_ast
if node.filter_cond
else self.sync(ast3.Constant(value=None)),
],
keywords=[],
)
Expand Down
14 changes: 6 additions & 8 deletions jaclang/core/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ def edges_to_nodes(
filter_func = filter_func if filter_func else lambda x: x
ret_nodes: list[NodeArchitype] = []
if dir in [EdgeDir.OUT]:
for i in filter_func(
[
x
for x in self.edges[EdgeDir.OUT]
if x._jac_.target
and (not filter_type or isinstance(x, filter_type))
]
):
edge = []
for x in self.edges[EdgeDir.OUT]:
if x._jac_.target and (not filter_type or isinstance(x, filter_type)):
edge.append(x)
new_edge = filter_func(edge)
for i in new_edge:
ret_nodes.append(i._jac_.target)
elif dir in [EdgeDir.IN]:
edge = []
Expand Down
13 changes: 0 additions & 13 deletions jaclang/tests/fixtures/edge_ops.jac
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ walker Creator {

node node_a{
has val:int;
can print_some with Creator entry;
}

walker Travelor{
can travel with `<root>|node_a entry;
}
node node_b{
has value:int;
can do with Travelor entry;
can print_one with Creator entry;
}

edge MyEdge {
Expand Down Expand Up @@ -50,16 +47,6 @@ edge MyEdge {
visit-->;
}


:node:node_a:can:print_some{
visit--> ;
}
:node:node_b:can:do{
visit-->;
}
:node:node_b:can:print_one{
}

with entry{
random.seed(1);
<root> spawn Creator();
Expand Down
4 changes: 3 additions & 1 deletion jaclang/tests/test_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,6 @@ def test_conn_assign_on_edges(self) -> None:
jac_import("edge_ops", self.fixture_abs_path("./"))
sys.stdout = sys.__stdout__
stdout_value = captured_output.getvalue()
self.assertEqual(stdout_value.split("\n")[0], "[(2, 5), (1, 3), (1, 4)]")
self.assertEqual(stdout_value.split("\n")[0], "[(3, 5), (14, 1), (5, 1)]")
self.assertEqual(stdout_value.split("\n")[1], "10")
self.assertEqual(stdout_value.split("\n")[2], "12")

0 comments on commit e95561e

Please sign in to comment.