Skip to content

Commit

Permalink
-s (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
anshikavashistha authored Sep 19, 2024
1 parent 7f6f810 commit 86bb54f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions crosstl/src/translator/codegen/directx_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ def map_operator(self, op):
"ASSIGN_MUL": "*=",
"ASSIGN_DIV": "/=",
"ASSIGN_MOD": "%=",
"ASSIGN_XOR": "^=",
"LESS_EQUAL": "<=",
"GREATER_EQUAL": ">=",
"EQUAL": "==",
Expand Down
1 change: 1 addition & 0 deletions crosstl/src/translator/codegen/metal_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ def map_operator(self, op):
"ASSIGN_MUL": "*=",
"ASSIGN_DIV": "/=",
"ASSIGN_MOD": "%=",
"ASSIGN_XOR": "^=",
"GREATER_THAN": ">",
"LESS_EQUAL": "<=",
"GREATER_EQUAL": ">=",
Expand Down
1 change: 1 addition & 0 deletions crosstl/src/translator/codegen/opengl_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ def map_operator(self, op):
"ASSIGN_MUL": "*=",
"ASSIGN_DIV": "/=",
"ASSIGN_MOD": "%=",
"ASSIGN_XOR": "^=",
"GREATER_THAN": ">",
"LESS_EQUAL": "<=",
"GREATER_EQUAL": ">=",
Expand Down
34 changes: 34 additions & 0 deletions tests/test_translator/test_codegen/test_directx_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 86bb54f

Please sign in to comment.