-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preliminary implementation for globals
- Loading branch information
1 parent
77a07b7
commit 4b38e24
Showing
6 changed files
with
84 additions
and
3 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
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
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,24 @@ | ||
import ast | ||
|
||
import dawn4py.serialization as ser | ||
import dawn4py.serialization.SIR as sir | ||
|
||
import dusk.script as script | ||
from dusk.integration import StencilObject | ||
|
||
|
||
def resolve_globals(stencil_object: StencilObject) -> None: | ||
|
||
# TODO: check preconditions & postconditions | ||
|
||
stencil_object.globals = sir.GlobalVariableMap() | ||
|
||
for node in ast.walk(stencil_object.pyast): | ||
if ( | ||
isinstance(node, ast.Name) | ||
and hasattr(node, "decl") | ||
and isinstance(node.decl, script.Global) | ||
): | ||
name = node.decl.name | ||
stencil_object.globals.map[name].double_value = 0 | ||
node.sir = ser.make_var_access_expr(name, is_external=True) |
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,39 @@ | ||
from dusk.script import * | ||
from dusk.test import stencil_test | ||
|
||
|
||
dt = Global("dt") | ||
|
||
|
||
@stencil_test() | ||
def test_simple_global1(a: Field[Edge]): | ||
with levels_downward: | ||
a = dt | ||
|
||
|
||
g = Global("some_global") | ||
|
||
|
||
@stencil_test() | ||
def test_simple_global2(a: Field[Edge], b: Field[Cell]): | ||
with levels_downward: | ||
a = sum_over(Edge > Cell, g * b) | ||
|
||
|
||
one = Global("one") | ||
two = Global("two") | ||
|
||
|
||
@stencil_test() | ||
def test_two_globals(a: Field[Edge]): | ||
with levels_downward: | ||
a = one + two | ||
|
||
|
||
aliased = dt | ||
|
||
|
||
@stencil_test() | ||
def test_aliased_global(a: Field[Cell]): | ||
with levels_upward: | ||
a = aliased / (one - two) |