-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50e18c4
commit 9c4c432
Showing
5 changed files
with
74 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
{ | ||
"cSpell.words": [ | ||
"benda", | ||
"bjit", | ||
"Clippy", | ||
"dataclass", | ||
"dataclasses", | ||
"nixpkgs", | ||
"Numba" | ||
] | ||
|
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import ast, inspect | ||
|
||
import benda | ||
from benda import u24 | ||
|
||
def test_1(): | ||
return 4 | ||
|
||
def test_2(): | ||
x = u24(3) | ||
y = x - u24(2) | ||
return y | ||
|
||
def get_ast(): | ||
my_ast = ast.dump(ast.parse(inspect.getsource(test_2))) | ||
return my_ast | ||
|
||
if __name__ == "__main__": | ||
print(get_ast()) | ||
print(test_2()) |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from dataclasses import dataclass | ||
# from benda import bjit, u24 | ||
|
||
u24 = int | ||
|
||
|
||
@dataclass | ||
class Leaf: | ||
value: u24 | ||
|
||
|
||
@dataclass | ||
class Node: | ||
left: 'Tree' | ||
right: 'Tree' | ||
|
||
|
||
Tree = Node | Leaf | ||
|
||
|
||
# @bjit | ||
def sum_tree(tree: Tree) -> u24: | ||
match tree: | ||
case Leaf(value): | ||
return value | ||
case Node(left, right): | ||
return sum_tree(left) + sum_tree(right) | ||
|
||
|
||
def gen_tree(depth: int, n: int) -> Tree: | ||
if depth == 0: | ||
return Leaf(value=n) | ||
else: | ||
return Node(left=gen_tree(depth-1, n-1), right=gen_tree(depth-1, n+1)) | ||
|
||
|
||
if __name__ == "__main__": | ||
tree = gen_tree(4, 10) | ||
print(tree) | ||
print(sum_tree(tree)) |
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