Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jaclib #1477

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

jaclib #1477

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions jac/examples/reference/architypes.jac
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ can print_base_classes(cls: type) -> type {
return cls;
}

class Animal {}
obj Animal {}

obj Domesticated {}

@print_base_classes
node Pet :Animal, Domesticated: {}
obj Pet :Animal, Domesticated: {}

walker Person :Animal: {}
obj Person :Animal: {}

walker Feeder :Person: {}
obj Feeder :Person: {}

@print_base_classes
walker Zoologist :Feeder: {}
obj Zoologist :Feeder: {}
80 changes: 66 additions & 14 deletions jac/examples/reference/architypes.py
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
4 changes: 3 additions & 1 deletion jac/examples/reference/builtin_types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from jaclang import List

a = 9.2
b = 44
c = [2, 4, 6, 10]
c = List([2, 4, 6, 10]) # (thakee):
d = {"name": "john", "age": 28}
e = ("jaseci", 5, 4, 14)
f = True
Expand Down
10 changes: 5 additions & 5 deletions jac/examples/reference/check_statements.py
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)
19 changes: 14 additions & 5 deletions jac/examples/reference/data_spatial_walker_statements.py
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())
33 changes: 21 additions & 12 deletions jac/examples/reference/disengage_statements.py
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())
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
31 changes: 20 additions & 11 deletions jac/examples/reference/visit_statements.py
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())
Loading
Loading