From 86bb54fe27461b31e48427e84e31a2203c8f8926 Mon Sep 17 00:00:00 2001 From: anshikavashistha <93611566+anshikavashistha@users.noreply.github.com> Date: Thu, 19 Sep 2024 12:07:49 +0530 Subject: [PATCH] -s (#160) --- .../src/translator/codegen/directx_codegen.py | 1 + .../src/translator/codegen/metal_codegen.py | 1 + .../src/translator/codegen/opengl_codegen.py | 1 + .../test_codegen/test_directx_codegen.py | 34 +++++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/crosstl/src/translator/codegen/directx_codegen.py b/crosstl/src/translator/codegen/directx_codegen.py index 2936e7e..cac1786 100644 --- a/crosstl/src/translator/codegen/directx_codegen.py +++ b/crosstl/src/translator/codegen/directx_codegen.py @@ -362,6 +362,7 @@ def map_operator(self, op): "ASSIGN_MUL": "*=", "ASSIGN_DIV": "/=", "ASSIGN_MOD": "%=", + "ASSIGN_XOR": "^=", "LESS_EQUAL": "<=", "GREATER_EQUAL": ">=", "EQUAL": "==", diff --git a/crosstl/src/translator/codegen/metal_codegen.py b/crosstl/src/translator/codegen/metal_codegen.py index a4dc188..c6d120c 100644 --- a/crosstl/src/translator/codegen/metal_codegen.py +++ b/crosstl/src/translator/codegen/metal_codegen.py @@ -421,6 +421,7 @@ def map_operator(self, op): "ASSIGN_MUL": "*=", "ASSIGN_DIV": "/=", "ASSIGN_MOD": "%=", + "ASSIGN_XOR": "^=", "GREATER_THAN": ">", "LESS_EQUAL": "<=", "GREATER_EQUAL": ">=", diff --git a/crosstl/src/translator/codegen/opengl_codegen.py b/crosstl/src/translator/codegen/opengl_codegen.py index 4b734d7..e445a3c 100644 --- a/crosstl/src/translator/codegen/opengl_codegen.py +++ b/crosstl/src/translator/codegen/opengl_codegen.py @@ -278,6 +278,7 @@ def map_operator(self, op): "ASSIGN_MUL": "*=", "ASSIGN_DIV": "/=", "ASSIGN_MOD": "%=", + "ASSIGN_XOR": "^=", "GREATER_THAN": ">", "LESS_EQUAL": "<=", "GREATER_EQUAL": ">=", diff --git a/tests/test_translator/test_codegen/test_directx_codegen.py b/tests/test_translator/test_codegen/test_directx_codegen.py index ccdb305..d1e11d5 100644 --- a/tests/test_translator/test_codegen/test_directx_codegen.py +++ b/tests/test_translator/test_codegen/test_directx_codegen.py @@ -318,6 +318,40 @@ def test_assignment_modulus_operator(): pytest.fail("Struct parsing not implemented.") +def test_assignment_xor_operator(): + code = """ + shader XORShader { + vertex { + input vec3 position; + output vec2 vUV; + void main() { + vUV = position.xy * 10.0; + vUV.x ^= 3.0; // XOR assignment operator + gl_Position = vec4(position, 1.0); + } + } + fragment { + input vec2 vUV; + output vec4 fragColor; + void main() { + float noise = perlinNoise(vUV); + float height = noise * 10.0; + height ^= 2.0; // XOR assignment operator + vec3 color = vec3(height / 10.0, 1.0 - height / 10.0, 0.0); + fragColor = vec4(color, 1.0); + } + } + } + """ + try: + tokens = tokenize_code(code) + ast = parse_code(tokens) + generated_code = generate_code(ast) + print(generated_code) + except SyntaxError: + pytest.fail("XOR operator parsing not implemented.") + + def test_assignment_shift_operators(): code = """ shader PerlinNoise {