Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Assignment AND Operator Support #163

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -266,6 +266,7 @@ def map_operator(self, op):
"ASSIGN_MUL": "*=",
"ASSIGN_DIV": "/=",
"ASSIGN_MOD": "%=",
"ASSIGN_AND": "&=",
"ASSIGN_XOR": "^=",
"LESS_EQUAL": "<=",
"GREATER_EQUAL": ">=",
Expand Down
2 changes: 2 additions & 0 deletions crosstl/src/translator/codegen/metal_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ def map_operator(self, op):
"ASSIGN_MUL": "*=",
"ASSIGN_DIV": "/=",
"ASSIGN_MOD": "%=",
"ASSIGN_AND": "&=",
"GREATER_THAN": ">",
"ASSIGN_XOR": "^=",
"LESS_EQUAL": "<=",
"GREATER_EQUAL": ">=",
Expand Down
2 changes: 2 additions & 0 deletions crosstl/src/translator/codegen/opengl_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ def map_operator(self, op):
"ASSIGN_MUL": "*=",
"ASSIGN_DIV": "/=",
"ASSIGN_MOD": "%=",
"ASSIGN_AND": "&=",
"GREATER_THAN": ">",
"ASSIGN_XOR": "^=",
"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 @@ -410,6 +410,40 @@ def test_assignment_xor_operator():
pytest.fail("XOR operator codegen not implemented.")


def test_assignment_and_operator():
code = """
shader ANDShader {
vertex {
input vec3 position;
output vec2 vUV;
void main() {
vUV = position.xy * 10.0;
vUV.x &= 3.0; // AND 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; // AND 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("AND operator parsing not implemented.")


def test_assignment_shift_operators():
code = """
shader main {
Expand Down
Loading