Skip to content

Commit

Permalink
jac2py codegen refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
ThakeeNathees committed Dec 17, 2024
1 parent 0a4a3c9 commit ee8dfc9
Show file tree
Hide file tree
Showing 10 changed files with 777 additions and 494 deletions.
11 changes: 10 additions & 1 deletion jac/examples/reference/architypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ def print_base_classes(cls: type) -> type:
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:
class Animal(Base):
pass


Expand Down
11 changes: 10 additions & 1 deletion jac/examples/reference/data_spatial_walker_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
from jaclang.plugin.feature import JacFeature as _Jac


# 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:
class Visitor(Base):
def self_destruct(self, _jac_here_) -> None:
print("get's here")
_Jac.disengage(self)
Expand Down
13 changes: 11 additions & 2 deletions jac/examples/reference/disengage_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
from jaclang.plugin.feature import JacFeature as _Jac


# 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:
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)
Expand All @@ -14,7 +23,7 @@ def travel(self, _jac_here_: _Jac.get_root_type()) -> None:


@_Jac.make_node(on_entry=[_Jac.DSFunc("speak", Visitor)], on_exit=[])
class item:
class item(Base):
def speak(self, _jac_here_: Visitor) -> None:
print("Hey There!!!")
_Jac.disengage(_jac_here_)
Expand Down
11 changes: 10 additions & 1 deletion jac/examples/reference/match_class_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
from dataclasses import dataclass as dataclass


# 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=[])
@dataclass(eq=False)
class Point:
class Point(Base):
x: float
y: float

Expand Down
13 changes: 11 additions & 2 deletions jac/examples/reference/special_comprehensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@
import random


# 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=[])
@dataclass(eq=False)
class TestObj:
class TestObj(Base):
x: int = Jac.has_instance_default(gen_func=lambda: random.randint(0, 15))
y: int = Jac.has_instance_default(gen_func=lambda: random.randint(0, 15))
z: int = Jac.has_instance_default(gen_func=lambda: random.randint(0, 15))
Expand All @@ -23,7 +32,7 @@ class TestObj:

@Jac.make_obj(on_entry=[], on_exit=[])
@dataclass(eq=False)
class MyObj:
class MyObj(Base):
apple: int = Jac.has_instance_default(gen_func=lambda: 0)
banana: int = Jac.has_instance_default(gen_func=lambda: 0)

Expand Down
13 changes: 11 additions & 2 deletions jac/examples/reference/visit_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
from jaclang.plugin.feature import JacFeature as _Jac


# 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:
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)
Expand All @@ -14,7 +23,7 @@ def travel(self, _jac_here_: _Jac.get_root_type()) -> None:


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

Expand Down
Loading

0 comments on commit ee8dfc9

Please sign in to comment.