Repository: CrossGL/crosstl

Issue:
SHIFT_RIGHT : >>

Discussion:

Patch:
diff --git a/crosstl/src/backend/DirectX/DirectxLexer.py b/crosstl/src/backend/DirectX/DirectxLexer.py
index b8a23b2..a2c6084 100644
--- a/crosstl/src/backend/DirectX/DirectxLexer.py
+++ b/crosstl/src/backend/DirectX/DirectxLexer.py
@@ -35,6 +35,7 @@ TOKENS = [
     ("COLON", r":"),
     ("QUESTION", r"\?"),
     ("SHIFT_LEFT", r"<<"),
+    ("SHIFT_RIGHT", r">>"),
     ("LESS_EQUAL", r"<="),
     ("GREATER_EQUAL", r">="),
     ("LESS_THAN", r"<"),
diff --git a/crosstl/src/backend/DirectX/DirectxParser.py b/crosstl/src/backend/DirectX/DirectxParser.py
index 201a410..c3cd409 100644
--- a/crosstl/src/backend/DirectX/DirectxParser.py
+++ b/crosstl/src/backend/DirectX/DirectxParser.py
@@ -239,6 +239,7 @@ class HLSLParser:
                     "ASSIGN_OR",
                     "ASSIGN_AND",
                     "SHIFT_LEFT",
+                    "SHIFT_RIGHT",
                     "BITWISE_OR",
                     "BITWISE_XOR",
                 ]:
@@ -259,6 +260,7 @@ class HLSLParser:
                 "ASSIGN_OR",
                 "ASSIGN_AND",
                 "SHIFT_LEFT",
+                "SHIFT_RIGHT",
                 "BITWISE_OR",
                 "BITWISE_XOR",
             ]:
@@ -282,6 +284,7 @@ class HLSLParser:
                     "ASSIGN_OR",
                     "ASSIGN_AND",
                     "SHIFT_LEFT",
+                    "SHIFT_RIGHT",
                     "BITWISE_OR",
                     "BITWISE_XOR",
                 ]:
@@ -413,6 +416,7 @@ class HLSLParser:
             "ASSIGN_OR",
             "ASSIGN_AND",
             "SHIFT_LEFT",
+            "SHIFT_RIGHT",
             "BITWISE_OR",
             "BITWISE_XOR",
         ]:
@@ -454,6 +458,7 @@ class HLSLParser:
         while self.current_token[0] in [
             "LESS_THAN",
             "SHIFT_LEFT",
+            "SHIFT_RIGHT",
             "GREATER_THAN",
             "LESS_EQUAL",
             "GREATER_EQUAL",


Test patch:
diff --git a/tests/test_backend/test_directx/test_codegen.py b/tests/test_backend/test_directx/test_codegen.py
index 59294a9..07ae81b 100644
--- a/tests/test_backend/test_directx/test_codegen.py
+++ b/tests/test_backend/test_directx/test_codegen.py
@@ -437,7 +437,19 @@ def test_assignment_ops_codegen():
             output.redValue << 1; // Shift left by 1
             output.redValue &= 0x3;
         }
+        
+        // Testing SHIFT_RIGHT (>>) operator on some condition
+        if (input.in_position.r == 0.25) {
+            uint redValue = asuint(output.out_color.r);
+            output.redValue ^= 0x1;
+            output.out_color.r = asfloat(redValue);
 
+            output.redValue |= 0x2;
+            // Applying shift left operation
+            output.redValue >> 1; // Shift left by 1
+            output.redValue &= 0x3;
+        } 
+        
         // Testing BITWISE_XOR (^) operator on some condition
         if (input.in_position.r == 0.5) {
             uint redValue = asuint(output.out_color.r);
diff --git a/tests/test_backend/test_directx/test_lexer.py b/tests/test_backend/test_directx/test_lexer.py
index 296866f..cb5ea7f 100644
--- a/tests/test_backend/test_directx/test_lexer.py
+++ b/tests/test_backend/test_directx/test_lexer.py
@@ -146,6 +146,20 @@ def test_assignment_ops_tokenization():
 
             redValue &= 0x3;
         }
+        
+        // Testing SHIFT RIGHT (>>) operator on some condition
+        if (input.in_position.r == 0.25) {
+            uint redValue = asuint(output.out_color.r);
+            output.redValue ^= 0x1;
+            output.out_color.r = asfloat(redValue);
+            output.redValue |= 0x2;
+
+            // Applying shift left operation
+            output.redValue >> 1; // Shift left by 1
+            redValue |= 0x2;
+
+            redValue &= 0x3;
+        }
 
 
         return output;
diff --git a/tests/test_backend/test_directx/test_parser.py b/tests/test_backend/test_directx/test_parser.py
index c4bbc89..809a182 100644
--- a/tests/test_backend/test_directx/test_parser.py
+++ b/tests/test_backend/test_directx/test_parser.py
@@ -201,6 +201,18 @@ def test_assignment_ops_parsing():
             output.redValue << 1; // Shift left by 1
             output.redValue &= 0x3;
         }
+        
+        // Testing SHIFT_RIGHT (>>) operator on some condition
+        if (input.in_position.r == 0.25) {
+            uint redValue = asuint(output.out_color.r);
+            output.redValue ^= 0x1;
+            output.out_color.r = asfloat(redValue);
+
+            output.redValue |= 0x2;
+            // Applying shift left operation
+            output.redValue >> 1; // Shift left by 1
+            output.redValue &= 0x3;
+        }
 
         // Testing BITWISE_XOR (^) operator on some condition
         if (input.in_position.r == 0.5) {
diff --git a/tests/test_translator/test_codegen/test_directx_codegen.py b/tests/test_translator/test_codegen/test_directx_codegen.py
index ca816a2..6779c1c 100644
--- a/tests/test_translator/test_codegen/test_directx_codegen.py
+++ b/tests/test_translator/test_codegen/test_directx_codegen.py
@@ -596,5 +596,38 @@ def test_bitwise_and_operator():
         pytest.fail("Bitwise AND codegen not implemented")
 
 
+def test_double_data_type():
+    code = """
+    shader DoubleShader {
+        vertex {
+            input double position;
+            output double vDouble;
+
+            void main() {
+                vDouble = position * 2.0;
+                gl_Position = vec4(vDouble, 1.0);
+            }
+        }
+
+        fragment {
+            input double vDouble;
+            output vec4 fragColor;
+
+            void main() {
+                fragColor = vec4(vDouble, vDouble, vDouble, 1.0);
+            }
+        }
+    }
+    """
+    try:
+        tokens = tokenize_code(code)
+        ast = parse_code(tokens)
+        generated_code = generate_code(ast)
+        print(generated_code)
+        assert "double" in generated_code
+    except SyntaxError:
+        pytest.fail("Double data type not supported.")
+
+
 if __name__ == "__main__":
     pytest.main()