Skip to content

Commit

Permalink
POC TypeScript languageprovider
Browse files Browse the repository at this point in the history
  • Loading branch information
nx10 committed Feb 11, 2025
1 parent d9254e0 commit 8cf0430
Show file tree
Hide file tree
Showing 4 changed files with 699 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/styx/backend/generic/gen/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def _compile_func_execute(
)

func.body.extend([
"# validate constraint checks (or after middlewares?)",
# lang.expr_line_comment("todo: validate constraint checks (or after middlewares?)"),
*lang.call_build_cargs(lookup, struct, "params", "execution", "cargs"),
*lang.call_build_outputs(lookup, struct, "params", "execution", "ret"),
])
Expand Down
7 changes: 6 additions & 1 deletion src/styx/backend/generic/languageprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from styx.backend.generic.gen.lookup import LookupParam
else:
LookupParam = None
from styx.backend.generic.linebuffer import LineBuffer, indent
from styx.backend.generic.linebuffer import LineBuffer
from styx.backend.generic.model import GenericArg, GenericFunc, GenericModule, GenericStructure

if typing.TYPE_CHECKING:
Expand Down Expand Up @@ -295,6 +295,11 @@ def expr_null(self) -> ExprType:
"""Null value."""
...

@abstractmethod
def expr_line_comment(self, comment_: LineBuffer) -> LineBuffer:
"""Line comment."""
...


class LanguageHighLevelProvider(Protocol):
@abstractmethod
Expand Down
8 changes: 6 additions & 2 deletions src/styx/backend/python/languageprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from styx.backend.generic.model import GenericArg, GenericFunc, GenericModule, GenericStructure
from styx.backend.generic.scope import Scope
from styx.backend.generic.string_case import pascal_case, screaming_snake_case, snake_case
from styx.backend.generic.utils import enbrace, enquote, ensure_endswith, escape_backslash, linebreak_paragraph
from styx.backend.generic.utils import enbrace, enquote, ensure_endswith, escape_backslash, linebreak_paragraph, \
struct_has_outputs
from styx.ir import core as ir


Expand Down Expand Up @@ -259,6 +260,9 @@ def param_is_set_by_user(self, param: ir.Param, symbol: str, enbrace_statement:


class PythonLanguageExprProvider(LanguageExprProvider):
def expr_line_comment(self, comment_: LineBuffer) -> LineBuffer:
return comment(comment_, "#")

def expr_bool(self, obj: bool) -> ExprType:
"""Convert a bool to a language literal."""
return "True" if obj else "False"
Expand Down Expand Up @@ -593,7 +597,7 @@ def dyn_declare(self, lookup: LookupParam, root_struct: ir.Param[ir.Param.Struct
# Build outputs function lookup
items = [
(self.expr_str(s.base.name), lookup.expr_func_build_outputs[s.base.id_])
for s in root_struct.iter_structs_recursively(False)
for s in root_struct.iter_structs_recursively(False) if struct_has_outputs(s)
]
func_get_build_outputs = GenericFunc(
name="dyn_outputs",
Expand Down
Loading

0 comments on commit 8cf0430

Please sign in to comment.