2025-08-29 20:58:50 +00:00
|
|
|
from copapy import Write, const
|
2025-05-25 21:23:02 +00:00
|
|
|
import copapy as rc
|
|
|
|
|
|
2025-10-01 21:09:49 +00:00
|
|
|
|
2025-05-25 21:23:02 +00:00
|
|
|
def test_ast_generation():
|
2025-10-02 21:10:05 +00:00
|
|
|
#c1 = const(1.11)
|
2025-10-01 21:09:49 +00:00
|
|
|
#c2 = const(2.22)
|
2025-05-25 21:23:02 +00:00
|
|
|
#c3 = const(3.33)
|
|
|
|
|
|
|
|
|
|
#i1 = c1 + c2
|
|
|
|
|
#i2 = c2 * i1
|
|
|
|
|
#i3 = i2 + 4
|
|
|
|
|
|
|
|
|
|
#r1 = i1 + i3
|
|
|
|
|
#r2 = i3 * i2
|
2025-10-02 21:10:05 +00:00
|
|
|
c1 = const(4)
|
2025-05-25 21:23:02 +00:00
|
|
|
i1 = c1 * 2
|
2025-10-01 21:09:49 +00:00
|
|
|
r1 = i1 + 7
|
2025-10-02 21:10:05 +00:00
|
|
|
r2 = i1 + 9
|
|
|
|
|
out = [Write(r1), Write(r2)]
|
2025-05-25 21:23:02 +00:00
|
|
|
|
|
|
|
|
print(out)
|
2025-10-01 21:09:49 +00:00
|
|
|
print('-- get_path_segments:')
|
2025-05-25 21:23:02 +00:00
|
|
|
|
2025-10-02 21:10:05 +00:00
|
|
|
path_segments = list(rc.get_path_segments(out))
|
2025-05-25 21:23:02 +00:00
|
|
|
for p in path_segments:
|
|
|
|
|
print(p)
|
2025-10-01 21:09:49 +00:00
|
|
|
print('-- get_ordered_ops:')
|
2025-05-25 21:23:02 +00:00
|
|
|
ordered_ops = list(rc.get_ordered_ops(path_segments))
|
2025-10-02 21:10:05 +00:00
|
|
|
for p in ordered_ops:
|
2025-05-25 21:23:02 +00:00
|
|
|
print(p)
|
2025-10-01 21:09:49 +00:00
|
|
|
print('-- get_consts:')
|
2025-05-25 21:23:02 +00:00
|
|
|
|
|
|
|
|
const_list = rc.get_consts(ordered_ops)
|
|
|
|
|
for p in const_list:
|
|
|
|
|
print(p)
|
2025-10-01 21:09:49 +00:00
|
|
|
print('-- add_read_ops:')
|
2025-05-25 21:23:02 +00:00
|
|
|
|
|
|
|
|
output_ops = list(rc.add_read_ops(ordered_ops))
|
|
|
|
|
for p in output_ops:
|
|
|
|
|
print(p)
|
2025-10-01 21:09:49 +00:00
|
|
|
print('-- add_write_ops:')
|
2025-05-25 21:23:02 +00:00
|
|
|
|
|
|
|
|
extended_output_ops = list(rc.add_write_ops(output_ops, const_list))
|
|
|
|
|
for p in extended_output_ops:
|
|
|
|
|
print(p)
|
|
|
|
|
print('--')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2025-10-01 21:09:49 +00:00
|
|
|
test_ast_generation()
|