-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_compiler.py
More file actions
68 lines (52 loc) · 1.67 KB
/
Copy pathdebug_compiler.py
File metadata and controls
68 lines (52 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import sys
from lockstep_compiler import (
LockstepCompileError,
LockstepCompileResult,
LockstepDiagnostic,
ParseErrorCollector,
build_debug_visitor,
build_semantic_validator,
compile_lockstep,
load_default_parser_classes,
normalize_diagnostics,
run_cli,
validate_semantics,
)
_LockstepLexer, _LockstepParser, _LockstepVisitor = load_default_parser_classes()
LockstepLexer = _LockstepLexer
LockstepParser = _LockstepParser
LockstepVisitor = _LockstepVisitor
class _CompatibilityVisitor(LockstepVisitor):
"""Visitor shim that keeps debug_compiler test doubles lightweight."""
def visitChildren(self, node):
get_child_count = getattr(node, "getChildCount", None)
if callable(get_child_count):
return super().visitChildren(node)
return node
LockstepDebugVisitor = build_debug_visitor(_CompatibilityVisitor)
LockstepSemanticValidator = build_semantic_validator(_CompatibilityVisitor)
TEST_SOURCE = """
struct Vec3 { float x; float y; float z; };
pure Vec3 add(Vec3 a, Vec3 b) {
Vec3 r;
r.x = a.x + b.x;
return r;
}
shader ApplyGravity(in Vec3 pos, out Vec3 new_pos, accum float energy, uniform float dt) {
new_pos.x = pos.x;
new_pos.y = pos.y - (9.8 * dt);
energy = new_pos.y;
}
pipeline Physics {
stream<Vec3, 1000> raw_positions;
stream<Vec3, 1000> final_positions;
accumulator<float> total_energy;
uniform float dt = 0.016;
bind {
final_positions = ApplyGravity(raw_positions, final_positions, total_energy, dt);
uniform float sys_energy = fold sum(total_energy);
}
}
"""
if __name__ == "__main__":
sys.exit(run_cli(compiler=compile_lockstep))