copapy/tools/make_example.py

35 lines
723 B
Python
Raw Normal View History

from copapy import _binwrite, variable
from copapy.backend import Write, compile_to_instruction_list
import copapy as cp
2025-10-12 20:22:30 +00:00
def test_compile() -> None:
c1 = variable(9.0)
2025-10-12 20:22:30 +00:00
#ret = [c1 / 4, c1 / -4, c1 // 4, c1 // -4, (c1 * -1) // 4]
#ret = [c1 // 3.3 + 5]
ret = [cp.sqrt(c1)]
2025-10-12 20:22:30 +00:00
out = [Write(r) for r in ret]
il, _ = compile_to_instruction_list(out, cp.generic_sdb)
2025-10-12 20:22:30 +00:00
# run program command
il.write_com(_binwrite.Command.RUN_PROG)
2025-10-12 20:22:30 +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)
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()