2025-10-23 15:23:12 +00:00
|
|
|
from copapy import _binwrite, variable
|
2025-10-19 21:24:14 +00:00
|
|
|
from copapy.backend import Write, compile_to_instruction_list
|
2025-10-26 12:21:35 +00:00
|
|
|
import copapy as cp
|
2025-10-12 20:22:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_compile() -> None:
|
|
|
|
|
|
2025-10-26 12:21:35 +00:00
|
|
|
c1 = variable(9.0)
|
2025-10-12 20:22:30 +00:00
|
|
|
|
|
|
|
|
#ret = [c1 / 4, c1 / -4, c1 // 4, c1 // -4, (c1 * -1) // 4]
|
2025-10-26 12:21:35 +00:00
|
|
|
#ret = [c1 // 3.3 + 5]
|
|
|
|
|
ret = [cp.sqrt(c1)]
|
2025-10-12 20:22:30 +00:00
|
|
|
|
|
|
|
|
out = [Write(r) for r in ret]
|
|
|
|
|
|
2025-10-26 12:21:35 +00:00
|
|
|
il, _ = compile_to_instruction_list(out, cp.generic_sdb)
|
2025-10-12 20:22:30 +00:00
|
|
|
|
|
|
|
|
# run program command
|
2025-10-19 21:24:14 +00:00
|
|
|
il.write_com(_binwrite.Command.RUN_PROG)
|
2025-10-12 20:22:30 +00:00
|
|
|
|
2025-10-19 21:24:14 +00:00
|
|
|
il.write_com(_binwrite.Command.READ_DATA)
|
2025-10-12 20:22:30 +00:00
|
|
|
il.write_int(0)
|
|
|
|
|
il.write_int(36)
|
|
|
|
|
|
2025-10-19 21:24:14 +00:00
|
|
|
il.write_com(_binwrite.Command.END_COM)
|
2025-10-12 20:22:30 +00:00
|
|
|
|
|
|
|
|
print('* Data to runner:')
|
|
|
|
|
il.print()
|
|
|
|
|
|
|
|
|
|
il.to_file('bin/test.copapy')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
test_compile()
|