Skip to content
Snippets Groups Projects
Commit b4f36868 authored by Frederik Hennig's avatar Frederik Hennig
Browse files

Decoupled generator and composers

parent 3edfb527
No related branches found
No related tags found
No related merge requests found
...@@ -4,10 +4,12 @@ import sympy as sp ...@@ -4,10 +4,12 @@ import sympy as sp
from pystencils import fields, kernel from pystencils import fields, kernel
from pystencilssfg import SourceFileGenerator from pystencilssfg import SourceFileGenerator, SfgComposer
with SourceFileGenerator() as sfg: with SourceFileGenerator() as ctx:
sfg = SfgComposer(ctx)
src, dst = fields("src, dst(1) : double[2D]") src, dst = fields("src, dst(1) : double[2D]")
@kernel @kernel
......
...@@ -4,10 +4,11 @@ import sympy as sp ...@@ -4,10 +4,11 @@ import sympy as sp
from pystencils import fields, kernel, Field from pystencils import fields, kernel, Field
from pystencilssfg import SourceFileGenerator from pystencilssfg import SourceFileGenerator, SfgComposer
with SourceFileGenerator() as ctx:
sfg = SfgComposer(ctx)
with SourceFileGenerator() as sfg:
src: Field = fields("src: double[2D]") src: Field = fields("src: double[2D]")
h = sp.Symbol('h') h = sp.Symbol('h')
......
...@@ -4,14 +4,16 @@ import sympy as sp ...@@ -4,14 +4,16 @@ import sympy as sp
from pystencils import fields, kernel from pystencils import fields, kernel
from pystencilssfg import SourceFileGenerator, SfgConfiguration from pystencilssfg import SourceFileGenerator, SfgConfiguration, SfgComposer
from pystencilssfg.source_concepts.cpp import mdspan_ref from pystencilssfg.source_concepts.cpp import mdspan_ref
sfg_config = SfgConfiguration( sfg_config = SfgConfiguration(
outer_namespace="make_demo" outer_namespace="make_demo"
) )
with SourceFileGenerator(sfg_config) as sfg: with SourceFileGenerator(sfg_config) as ctx:
sfg = SfgComposer(ctx)
sfg.prelude("""Generated by the pystencils Source File Generator. sfg.prelude("""Generated by the pystencils Source File Generator.
Author: Frederik Hennig <frederik.hennig@fau.de>""") Author: Frederik Hennig <frederik.hennig@fau.de>""")
......
from pystencilssfg import SourceFileGenerator from pystencilssfg import SourceFileGenerator, SfgComposer
from lbmpy.advanced_streaming import Timestep from lbmpy.advanced_streaming import Timestep
from lbmpy import LBMConfig, create_lb_ast from lbmpy import LBMConfig, create_lb_ast
with SourceFileGenerator() as sfg: with SourceFileGenerator() as ctx:
sfg = SfgComposer(ctx)
lb_config = LBMConfig(streaming_pattern='esotwist') lb_config = LBMConfig(streaming_pattern='esotwist')
......
# type: ignore # type: ignore
from pystencilssfg import SourceFileGenerator, SfgConfiguration from pystencilssfg import SourceFileGenerator, SfgConfiguration, SfgComposer
from pystencilssfg.configuration import SfgCodeStyle from pystencilssfg.configuration import SfgCodeStyle
from pystencilssfg.source_concepts import SrcObject from pystencilssfg.source_concepts import SrcObject
from pystencilssfg.source_components import SfgClass, SfgMemberVariable, SfgConstructor, SfgMethod, SfgVisibility from pystencilssfg.source_components import SfgClass, SfgMemberVariable, SfgConstructor, SfgMethod, SfgVisibility
...@@ -17,7 +17,8 @@ sfg_config = SfgConfiguration( ...@@ -17,7 +17,8 @@ sfg_config = SfgConfiguration(
f, g = fields("f, g(1): double[2D]") f, g = fields("f, g(1): double[2D]")
with SourceFileGenerator(sfg_config) as sfg: with SourceFileGenerator(sfg_config) as ctx:
sfg = SfgComposer(ctx)
@kernel @kernel
def assignments(): def assignments():
......
...@@ -7,7 +7,6 @@ from os import path ...@@ -7,7 +7,6 @@ from os import path
from .configuration import SfgConfiguration, config_from_commandline, merge_configurations from .configuration import SfgConfiguration, config_from_commandline, merge_configurations
from .context import SfgContext from .context import SfgContext
from .composer import SfgComposer
class SourceFileGenerator: class SourceFileGenerator:
...@@ -35,9 +34,9 @@ class SourceFileGenerator: ...@@ -35,9 +34,9 @@ class SourceFileGenerator:
if path.exists(file): if path.exists(file):
os.remove(file) os.remove(file)
def __enter__(self): def __enter__(self) -> SfgContext:
self.clean_files() self.clean_files()
return SfgComposer(self._context) return self._context
def __exit__(self, exc_type, exc_value, traceback): def __exit__(self, exc_type, exc_value, traceback):
if exc_type is None: if exc_type is None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment