Skip to content

Commit 6f2e1ba

Browse files
committed
fix: add FromPythonCall to examples
1 parent 90b2a5d commit 6f2e1ba

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

example/beer/interp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
@dialect.register
11-
class BeerInterpreter(MethodTable):
11+
class BeerMethods(MethodTable):
1212

1313
@impl(NewBeer)
1414
def new_beer(self, interp: Interpreter, frame: Frame, stmt: NewBeer):

example/beer/script.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from stmts import Pour, Puke, Drink, NewBeer
22
from dialect import dialect
33

4-
from interp import BeerInterpreter as BeerInterpreter
4+
from interp import BeerMethods as BeerMethods
55
from rewrite import RandomWalkBranch
66
from kirin.ir import dialect_group
77
from kirin.prelude import basic_no_opt
@@ -24,10 +24,15 @@ def run_pass(mt):
2424
# type: ignore
2525
@beer
2626
def main(x):
27+
def some_closure(beer, amount):
28+
Pour(beer, amount + 1)
29+
Puke()
30+
2731
beer = NewBeer("budlight")
2832
Drink(beer)
29-
Pour(beer, 12)
33+
Pour(beer, 12 + x)
3034
Puke()
35+
some_closure(beer, 1 + 1)
3136
if x > 1:
3237
Drink(NewBeer("heineken"))
3338
else:

example/beer/stmts.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,22 @@
88
@statement(dialect=dialect)
99
class NewBeer(ir.Statement):
1010
name = "new_beer"
11-
traits = frozenset({ir.Pure()})
11+
traits = frozenset({ir.Pure(), ir.FromPythonCall()})
1212
brand: ir.SSAValue = info.argument(types.String)
1313
result: ir.ResultValue = info.result(types.PyClass(Beer))
1414

1515

1616
@statement(dialect=dialect)
1717
class Drink(ir.Statement):
1818
name = "drink"
19+
traits = frozenset({ir.FromPythonCall()})
1920
beverage: ir.SSAValue = info.argument(types.PyClass(Beer))
2021

2122

2223
@statement(dialect=dialect)
2324
class Pour(ir.Statement):
2425
name = "pour"
26+
traits = frozenset({ir.FromPythonCall()})
2527
beverage: ir.SSAValue = info.argument(types.PyClass(Beer))
2628
amount: ir.SSAValue = info.argument(types.Int)
2729

@@ -40,3 +42,4 @@ class RandomBranch(ir.Statement):
4042
@statement(dialect=dialect)
4143
class Puke(ir.Statement):
4244
name = "puke"
45+
traits = frozenset({ir.FromPythonCall()})

example/simple.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""A minimal language example with a single pass that does nothing.
2+
"""
3+
4+
from kirin import ir
5+
from kirin.dialects import cf, py, func
6+
7+
8+
@ir.dialect_group([func, py.base, py.constant, py.assign, py.binop, py.unary])
9+
def simple(self):
10+
def run_pass(mt):
11+
return mt
12+
13+
return run_pass
14+
15+
16+
@simple
17+
def main(x):
18+
y = x + 1
19+
return y
20+
21+
22+
main.print()
23+
24+
25+
@simple.add(cf).add(py.cmp)
26+
def main2(x):
27+
y = x + 1
28+
if y > 0: # errors
29+
return y
30+
else:
31+
return -y
32+
33+
34+
main2.print()

src/kirin/ir/nodes/block.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from kirin.ir.nodes.view import View, MutableSequenceView
1414

1515
if TYPE_CHECKING:
16-
from kirin.ir.types import TypeAttribute
1716
from kirin.ir.nodes.stmt import Statement
17+
from kirin.ir.attrs.types import TypeAttribute
1818
from kirin.ir.nodes.region import Region
1919

2020

0 commit comments

Comments
 (0)