From 6531fe47620c82112cec955a14237c3483a11876 Mon Sep 17 00:00:00 2001 From: anshikavashistha Date: Wed, 18 Sep 2024 06:27:29 -0700 Subject: [PATCH] -s --- .../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..d587e3c 100644 --- a/crosstl/src/translator/codegen/directx_codegen.py +++ b/crosstl/src/translator/codegen/directx_codegen.py @@ -359,6 +359,7 @@ def map_operator(self, op): "GREATER_THAN": ">", "ASSIGN_ADD": "+=", "ASSIGN_SUB": "-=", + "ASSIGN_OR": "|=", "ASSIGN_MUL": "*=", "ASSIGN_DIV": "/=", "ASSIGN_MOD": "%=", diff --git a/crosstl/src/translator/codegen/metal_codegen.py b/crosstl/src/translator/codegen/metal_codegen.py index a4dc188..d5b8c80 100644 --- a/crosstl/src/translator/codegen/metal_codegen.py +++ b/crosstl/src/translator/codegen/metal_codegen.py @@ -418,6 +418,7 @@ def map_operator(self, op): "LESS_THAN": "<", "ASSIGN_ADD": "+=", "ASSIGN_SUB": "-=", + "ASSIGN_OR": "|=", "ASSIGN_MUL": "*=", "ASSIGN_DIV": "/=", "ASSIGN_MOD": "%=", diff --git a/crosstl/src/translator/codegen/opengl_codegen.py b/crosstl/src/translator/codegen/opengl_codegen.py index 4b734d7..78045ab 100644 --- a/crosstl/src/translator/codegen/opengl_codegen.py +++ b/crosstl/src/translator/codegen/opengl_codegen.py @@ -275,6 +275,7 @@ def map_operator(self, op): "LESS_THAN": "<", "ASSIGN_ADD": "+=", "ASSIGN_SUB": "-=", + "ASSIGN_OR": "|=", "ASSIGN_MUL": "*=", "ASSIGN_DIV": "/=", "ASSIGN_MOD": "%=", diff --git a/tests/test_translator/test_codegen/test_directx_codegen.py b/tests/test_translator/test_codegen/test_directx_codegen.py index ccdb305..df655de 100644 --- a/tests/test_translator/test_codegen/test_directx_codegen.py +++ b/tests/test_translator/test_codegen/test_directx_codegen.py @@ -283,6 +283,40 @@ def test_function_call(): pytest.fail("Struct parsing not implemented.") +def test_assignment_or_operator(): + code = """ + shader ORShader { + vertex { + input vec3 position; + output vec2 vUV; + void main() { + vUV = position.xy * 10.0; + vUV.x |= 3.0; // OR 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; // OR 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("OR operator parsing not implemented.") + + def test_assignment_modulus_operator(): code = """ shader ModulusShader {