-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'thakee-py-codegen-new' of https://github.com/Jaseci-Lab…
…s/jaseci into thakee-py-codegen-new
- Loading branch information
Showing
23 changed files
with
1,245 additions
and
811 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 |
---|---|---|
@@ -1,38 +1,90 @@ | ||
from jaclang.plugin.feature import JacFeature as jac | ||
from __future__ import annotations | ||
from jaclang import * | ||
|
||
|
||
def print_base_classes(cls: type) -> type: | ||
print(f"Base classes of {cls.__name__}: {[c.__name__ for c in cls.__bases__]}") | ||
print( | ||
f"Base classes of {cls.__name__}: {List([c.__name__ for c in cls.__bases__])}" | ||
) | ||
return cls | ||
|
||
|
||
@jac.make_obj(on_entry=[], on_exit=[]) | ||
class Animal: | ||
class Animal(Obj): | ||
pass | ||
|
||
|
||
@jac.make_obj(on_entry=[], on_exit=[]) | ||
class Domesticated(jac.Obj): | ||
class Domesticated(Obj): | ||
pass | ||
|
||
|
||
@print_base_classes | ||
@jac.make_node(on_entry=[], on_exit=[]) | ||
class Pet(Animal, Domesticated, jac.Node): | ||
class Pet(Animal, Domesticated, Obj): | ||
pass | ||
|
||
|
||
@jac.make_walker(on_entry=[], on_exit=[]) | ||
class Person(Animal, jac.Walker): | ||
class Person(Animal, Obj): | ||
pass | ||
|
||
|
||
@jac.make_walker(on_entry=[], on_exit=[]) | ||
class Feeder(Person, jac.Walker): | ||
class Feeder(Person, Obj): | ||
pass | ||
|
||
|
||
@print_base_classes | ||
@jac.make_walker(on_entry=[], on_exit=[]) | ||
class Zoologist(Feeder, jac.Walker): | ||
class Zoologist(Feeder, Obj): | ||
pass | ||
|
||
|
||
# | ||
# | ||
# (thakee): I guess I can remove the bellow code. | ||
# | ||
# | ||
|
||
# from jaclang.plugin.feature import JacFeature as jac | ||
|
||
|
||
# def print_base_classes(cls: type) -> type: | ||
# print(f"Base classes of {cls.__name__}: {[c.__name__ for c in cls.__bases__]}") | ||
# return cls | ||
|
||
|
||
# # Since the Animal class cannot be inherit from object, (cause the base class will be changed at run time) | ||
# # we need a base class. | ||
# # | ||
# # reference: https://stackoverflow.com/a/9639512/10846399 | ||
# # | ||
# class Base: | ||
# pass | ||
|
||
|
||
# @jac.make_obj(on_entry=[], on_exit=[]) | ||
# class Animal(Base): | ||
# pass | ||
|
||
|
||
# @jac.make_obj(on_entry=[], on_exit=[]) | ||
# class Domesticated(jac.Obj): | ||
# pass | ||
|
||
|
||
# @print_base_classes | ||
# @jac.make_node(on_entry=[], on_exit=[]) | ||
# class Pet(Animal, Domesticated, jac.Node): | ||
# pass | ||
|
||
|
||
# @jac.make_walker(on_entry=[], on_exit=[]) | ||
# class Person(Animal, jac.Walker): | ||
# pass | ||
|
||
|
||
# @jac.make_walker(on_entry=[], on_exit=[]) | ||
# class Feeder(Person, jac.Walker): | ||
# pass | ||
|
||
|
||
# @print_base_classes | ||
# @jac.make_walker(on_entry=[], on_exit=[]) | ||
# class Zoologist(Feeder, jac.Walker): | ||
# pass |
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 |
---|---|---|
@@ -1,25 +1,25 @@ | ||
from __future__ import annotations | ||
from jaclang.plugin.feature import JacFeature as _Jac | ||
from jaclang.plugin.feature import JacFeature as Jac | ||
|
||
a = 5 | ||
b = 2 | ||
|
||
|
||
@_Jac.create_test | ||
@Jac.create_test | ||
def test_test1(check) -> None: | ||
check.assertAlmostEqual(a, 6) | ||
|
||
|
||
@_Jac.create_test | ||
@Jac.create_test | ||
def test_test2(check) -> None: | ||
check.assertTrue(a != b) | ||
|
||
|
||
@_Jac.create_test | ||
@Jac.create_test | ||
def test_test3(check) -> None: | ||
check.assertIn("d", "abc") | ||
|
||
|
||
@_Jac.create_test | ||
@Jac.create_test | ||
def test_test4(check) -> None: | ||
check.assertEqual(a - b, 3) |
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 |
---|---|---|
@@ -1,14 +1,23 @@ | ||
from __future__ import annotations | ||
from jaclang.plugin.feature import JacFeature as _Jac | ||
from jaclang.plugin.feature import JacFeature as Jac | ||
|
||
|
||
@_Jac.make_walker(on_entry=[_Jac.DSFunc("self_destruct", None)], on_exit=[]) | ||
class Visitor: | ||
# Since the Animal class cannot be inherit from object, (cause the base class will be changed at run time) | ||
# we need a base class. | ||
# | ||
# reference: https://stackoverflow.com/a/9639512/10846399 | ||
# | ||
class Base: | ||
pass | ||
|
||
|
||
@Jac.make_walker(on_entry=[Jac.DSFunc("self_destruct", None)], on_exit=[]) | ||
class Visitor(Base): | ||
def self_destruct(self, _jac_here_) -> None: | ||
print("get's here") | ||
_Jac.disengage(self) | ||
Jac.disengage(self) | ||
return | ||
print("but not here") | ||
|
||
|
||
_Jac.spawn_call(_Jac.get_root(), Visitor()) | ||
Jac.spawn_call(Jac.get_root(), Visitor()) |
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 |
---|---|---|
@@ -1,28 +1,37 @@ | ||
from __future__ import annotations | ||
from jaclang.plugin.feature import JacFeature as _Jac | ||
from jaclang.plugin.feature import JacFeature as Jac | ||
|
||
|
||
@_Jac.make_walker(on_entry=[_Jac.DSFunc("travel", _Jac.get_root_type())], on_exit=[]) | ||
class Visitor: | ||
def travel(self, _jac_here_: _Jac.get_root_type()) -> None: | ||
if _Jac.visit_node( | ||
self, _Jac.edge_ref(_jac_here_, None, _Jac.EdgeDir.OUT, None, None) | ||
# Since the Animal class cannot be inherit from object, (cause the base class will be changed at run time) | ||
# we need a base class. | ||
# | ||
# reference: https://stackoverflow.com/a/9639512/10846399 | ||
# | ||
class Base: | ||
pass | ||
|
||
|
||
@Jac.make_walker(on_entry=[Jac.DSFunc("travel", Jac.get_root_type())], on_exit=[]) | ||
class Visitor(Base): | ||
def travel(self, _jac_here_: Jac.get_root_type()) -> None: | ||
if Jac.visit_node( | ||
self, Jac.edge_ref(_jac_here_, None, Jac.EdgeDir.OUT, None, None) | ||
): | ||
pass | ||
elif _Jac.visit_node(self, _Jac.get_root()): | ||
elif Jac.visit_node(self, Jac.get_root()): | ||
pass | ||
|
||
|
||
@_Jac.make_node(on_entry=[_Jac.DSFunc("speak", Visitor)], on_exit=[]) | ||
class item: | ||
@Jac.make_node(on_entry=[Jac.DSFunc("speak", Visitor)], on_exit=[]) | ||
class item(Base): | ||
def speak(self, _jac_here_: Visitor) -> None: | ||
print("Hey There!!!") | ||
_Jac.disengage(_jac_here_) | ||
Jac.disengage(_jac_here_) | ||
return | ||
|
||
|
||
i = 0 | ||
while i < 5: | ||
_Jac.connect(_Jac.get_root(), item(), _Jac.build_edge(_Jac.EdgeDir.OUT, None, None)) | ||
Jac.connect(Jac.get_root(), item(), Jac.build_edge(Jac.EdgeDir.OUT, None, None)) | ||
i += 1 | ||
_Jac.spawn_call(_Jac.get_root(), Visitor()) | ||
Jac.spawn_call(Jac.get_root(), Visitor()) |
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
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 |
---|---|---|
@@ -1,26 +1,35 @@ | ||
from __future__ import annotations | ||
from jaclang.plugin.feature import JacFeature as _Jac | ||
from jaclang.plugin.feature import JacFeature as Jac | ||
|
||
|
||
@_Jac.make_walker(on_entry=[_Jac.DSFunc("travel", _Jac.get_root_type())], on_exit=[]) | ||
class Visitor: | ||
def travel(self, _jac_here_: _Jac.get_root_type()) -> None: | ||
if _Jac.visit_node( | ||
self, _Jac.edge_ref(_jac_here_, None, _Jac.EdgeDir.OUT, None, None) | ||
# Since the Animal class cannot be inherit from object, (cause the base class will be changed at run time) | ||
# we need a base class. | ||
# | ||
# reference: https://stackoverflow.com/a/9639512/10846399 | ||
# | ||
class Base: | ||
pass | ||
|
||
|
||
@Jac.make_walker(on_entry=[Jac.DSFunc("travel", Jac.get_root_type())], on_exit=[]) | ||
class Visitor(Base): | ||
def travel(self, _jac_here_: Jac.get_root_type()) -> None: | ||
if Jac.visit_node( | ||
self, Jac.edge_ref(_jac_here_, None, Jac.EdgeDir.OUT, None, None) | ||
): | ||
pass | ||
elif _Jac.visit_node(self, _Jac.get_root()): | ||
elif Jac.visit_node(self, Jac.get_root()): | ||
pass | ||
|
||
|
||
@_Jac.make_node(on_entry=[_Jac.DSFunc("speak", Visitor)], on_exit=[]) | ||
class item: | ||
@Jac.make_node(on_entry=[Jac.DSFunc("speak", Visitor)], on_exit=[]) | ||
class item(Base): | ||
def speak(self, _jac_here_: Visitor) -> None: | ||
print("Hey There!!!") | ||
|
||
|
||
i = 0 | ||
while i < 5: | ||
_Jac.connect(_Jac.get_root(), item(), _Jac.build_edge(_Jac.EdgeDir.OUT, None, None)) | ||
Jac.connect(Jac.get_root(), item(), Jac.build_edge(Jac.EdgeDir.OUT, None, None)) | ||
i += 1 | ||
_Jac.spawn_call(_Jac.get_root(), Visitor()) | ||
Jac.spawn_call(Jac.get_root(), Visitor()) |
Oops, something went wrong.