Repository: CrossGL/crosstl
Pull request #211 (2024-11-26 09:23:46)

Chore: add Slang translator template for frontend & tests
Also adds slang test to workflow


Patch:
diff --git a/crosstl/src/translator/codegen/slang_codegen.py b/crosstl/src/translator/codegen/slang_codegen.py
new file mode 100644
index 0000000..1f46243
--- /dev/null
+++ b/crosstl/src/translator/codegen/slang_codegen.py
@@ -0,0 +1,22 @@
+from ..ast import (
+    AssignmentNode,
+    BinaryOpNode,
+    ForNode,
+    FunctionCallNode,
+    IfNode,
+    MemberAccessNode,
+    ReturnNode,
+    StructNode,
+    TernaryOpNode,
+    UnaryOpNode,
+    VariableNode,
+)
+
+
+# ToDO: Implement the SlangCodeGen class
+class SlangCodeGen:
+    def __init__(self):
+        pass
+
+    def generate(self, ast):
+        pass


Test patch:
diff --git a/.github/workflows/backend-tests.yml b/.github/workflows/backend-tests.yml
index dcc94f3..ee55ed1 100644
--- a/.github/workflows/backend-tests.yml
+++ b/.github/workflows/backend-tests.yml
@@ -13,7 +13,7 @@ jobs:
     runs-on: ${{ matrix.OS }}
     strategy:
       matrix:
-        backend: [directx, metal, opengl] # ToDO: Add mojo to the list
+        backend: [directx, metal, opengl, 'slang'] # ToDO: Add mojo to the list
         python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
         OS: [ubuntu-latest, windows-latest, macOS-latest]
       fail-fast: false
diff --git a/.github/workflows/translator-tests.yml b/.github/workflows/translator-tests.yml
index 36ccd23..e85ed62 100644
--- a/.github/workflows/translator-tests.yml
+++ b/.github/workflows/translator-tests.yml
@@ -13,7 +13,7 @@ jobs:
     runs-on: ${{ matrix.OS }}
     strategy:
       matrix:
-        component: ['directx', 'metal', 'opengl', 'general']  # ToDo: Add 'mojo' to the list
+        component: ['directx', 'metal', 'opengl', 'slang' ,'general']  # ToDo: Add 'mojo' to the list
         python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
         OS: [ubuntu-latest, windows-latest, macOS-latest]
       fail-fast: false
diff --git a/tests/test_translator/test_codegen/test_slang_codegen.py b/tests/test_translator/test_codegen/test_slang_codegen.py
new file mode 100644
index 0000000..9b315fe
--- /dev/null
+++ b/tests/test_translator/test_codegen/test_slang_codegen.py
@@ -0,0 +1,43 @@
+from crosstl.src.translator.lexer import Lexer
+import pytest
+from typing import List
+from crosstl.src.translator.parser import Parser
+from crosstl.src.translator.codegen.slang_codegen import SlangCodeGen
+
+
+def tokenize_code(code: str) -> List:
+    """Helper function to tokenize code."""
+    lexer = Lexer(code)
+    return lexer.tokens
+
+
+def parse_code(tokens: List):
+    """Helper function to parse tokens into an AST.
+
+    Args:
+        tokens (List): The list of tokens to parse
+    Returns:
+        AST: The abstract syntax tree generated from the parser
+    """
+    parser = Parser(tokens)
+    return parser.parse()
+
+
+def generate_code(ast_node):
+    """Test the code generator
+    Args:
+        ast_node: The abstract syntax tree generated from the code
+    Returns:
+        str: The generated code from the abstract syntax tree
+    """
+    codegen = SlangCodeGen()
+    return codegen.generate(ast_node)
+
+
+# ToDO: Implement the tests
+def test_struct():
+    pass
+
+
+if __name__ == "__main__":
+    pytest.main()