Skip to content

Commit 3fc2fff

Browse files
committed
jac2py codegen refactored
1 parent 0a4a3c9 commit 3fc2fff

File tree

11 files changed

+954
-516
lines changed

11 files changed

+954
-516
lines changed

jac/examples/reference/architypes.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@ def print_base_classes(cls: type) -> type:
66
return cls
77

88

9+
# Since the Animal class cannot be inherit from object, (cause the base class will be changed at run time)
10+
# we need a base class.
11+
#
12+
# reference: https://stackoverflow.com/a/9639512/10846399
13+
#
14+
class Base:
15+
pass
16+
17+
918
@jac.make_obj(on_entry=[], on_exit=[])
10-
class Animal:
19+
class Animal(Base):
1120
pass
1221

1322

jac/examples/reference/data_spatial_walker_statements.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22
from jaclang.plugin.feature import JacFeature as _Jac
33

44

5+
# Since the Animal class cannot be inherit from object, (cause the base class will be changed at run time)
6+
# we need a base class.
7+
#
8+
# reference: https://stackoverflow.com/a/9639512/10846399
9+
#
10+
class Base:
11+
pass
12+
13+
514
@_Jac.make_walker(on_entry=[_Jac.DSFunc("self_destruct", None)], on_exit=[])
6-
class Visitor:
15+
class Visitor(Base):
716
def self_destruct(self, _jac_here_) -> None:
817
print("get's here")
918
_Jac.disengage(self)

jac/examples/reference/disengage_statements.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22
from jaclang.plugin.feature import JacFeature as _Jac
33

44

5+
# Since the Animal class cannot be inherit from object, (cause the base class will be changed at run time)
6+
# we need a base class.
7+
#
8+
# reference: https://stackoverflow.com/a/9639512/10846399
9+
#
10+
class Base:
11+
pass
12+
13+
514
@_Jac.make_walker(on_entry=[_Jac.DSFunc("travel", _Jac.get_root_type())], on_exit=[])
6-
class Visitor:
15+
class Visitor(Base):
716
def travel(self, _jac_here_: _Jac.get_root_type()) -> None:
817
if _Jac.visit_node(
918
self, _Jac.edge_ref(_jac_here_, None, _Jac.EdgeDir.OUT, None, None)
@@ -14,7 +23,7 @@ def travel(self, _jac_here_: _Jac.get_root_type()) -> None:
1423

1524

1625
@_Jac.make_node(on_entry=[_Jac.DSFunc("speak", Visitor)], on_exit=[])
17-
class item:
26+
class item(Base):
1827
def speak(self, _jac_here_: Visitor) -> None:
1928
print("Hey There!!!")
2029
_Jac.disengage(_jac_here_)

jac/examples/reference/match_class_patterns.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@
33
from dataclasses import dataclass as dataclass
44

55

6+
# Since the Animal class cannot be inherit from object, (cause the base class will be changed at run time)
7+
# we need a base class.
8+
#
9+
# reference: https://stackoverflow.com/a/9639512/10846399
10+
#
11+
class Base:
12+
pass
13+
14+
615
@Jac.make_obj(on_entry=[], on_exit=[])
716
@dataclass(eq=False)
8-
class Point:
17+
class Point(Base):
918
x: float
1019
y: float
1120

jac/examples/reference/special_comprehensions.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@
44
import random
55

66

7+
# Since the Animal class cannot be inherit from object, (cause the base class will be changed at run time)
8+
# we need a base class.
9+
#
10+
# reference: https://stackoverflow.com/a/9639512/10846399
11+
#
12+
class Base:
13+
pass
14+
15+
716
@Jac.make_obj(on_entry=[], on_exit=[])
817
@dataclass(eq=False)
9-
class TestObj:
18+
class TestObj(Base):
1019
x: int = Jac.has_instance_default(gen_func=lambda: random.randint(0, 15))
1120
y: int = Jac.has_instance_default(gen_func=lambda: random.randint(0, 15))
1221
z: int = Jac.has_instance_default(gen_func=lambda: random.randint(0, 15))
@@ -23,7 +32,7 @@ class TestObj:
2332

2433
@Jac.make_obj(on_entry=[], on_exit=[])
2534
@dataclass(eq=False)
26-
class MyObj:
35+
class MyObj(Base):
2736
apple: int = Jac.has_instance_default(gen_func=lambda: 0)
2837
banana: int = Jac.has_instance_default(gen_func=lambda: 0)
2938

jac/examples/reference/visit_statements.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22
from jaclang.plugin.feature import JacFeature as _Jac
33

44

5+
# Since the Animal class cannot be inherit from object, (cause the base class will be changed at run time)
6+
# we need a base class.
7+
#
8+
# reference: https://stackoverflow.com/a/9639512/10846399
9+
#
10+
class Base:
11+
pass
12+
13+
514
@_Jac.make_walker(on_entry=[_Jac.DSFunc("travel", _Jac.get_root_type())], on_exit=[])
6-
class Visitor:
15+
class Visitor(Base):
716
def travel(self, _jac_here_: _Jac.get_root_type()) -> None:
817
if _Jac.visit_node(
918
self, _Jac.edge_ref(_jac_here_, None, _Jac.EdgeDir.OUT, None, None)
@@ -14,7 +23,7 @@ def travel(self, _jac_here_: _Jac.get_root_type()) -> None:
1423

1524

1625
@_Jac.make_node(on_entry=[_Jac.DSFunc("speak", Visitor)], on_exit=[])
17-
class item:
26+
class item(Base):
1827
def speak(self, _jac_here_: Visitor) -> None:
1928
print("Hey There!!!")
2029

0 commit comments

Comments
 (0)