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

Translator Support for Assignment OR Token #162

Merged
Merged
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 @@ -359,6 +359,7 @@ def map_operator(self, op):
"GREATER_THAN": ">",
"ASSIGN_ADD": "+=",
"ASSIGN_SUB": "-=",
"ASSIGN_OR": "|=",
"ASSIGN_MUL": "*=",
"ASSIGN_DIV": "/=",
"ASSIGN_MOD": "%=",
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 @@ -418,6 +418,7 @@ def map_operator(self, op):
"LESS_THAN": "<",
"ASSIGN_ADD": "+=",
"ASSIGN_SUB": "-=",
"ASSIGN_OR": "|=",
"ASSIGN_MUL": "*=",
"ASSIGN_DIV": "/=",
"ASSIGN_MOD": "%=",
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 @@ -275,6 +275,7 @@ def map_operator(self, op):
"LESS_THAN": "<",
"ASSIGN_ADD": "+=",
"ASSIGN_SUB": "-=",
"ASSIGN_OR": "|=",
"ASSIGN_MUL": "*=",
"ASSIGN_DIV": "/=",
"ASSIGN_MOD": "%=",
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 @@ -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 {
Expand Down