2025-10-03 21:26:51 +00:00
|
|
|
from coparun_module import coparun
|
2025-10-09 20:50:57 +00:00
|
|
|
from copapy import Write, CPVariable
|
2025-10-03 21:26:51 +00:00
|
|
|
import copapy
|
|
|
|
|
from copapy import binwrite
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_compile():
|
|
|
|
|
|
2025-10-09 20:50:57 +00:00
|
|
|
c1 = CPVariable(4)
|
|
|
|
|
c2 = CPVariable(2) * 4
|
2025-10-03 21:26:51 +00:00
|
|
|
|
|
|
|
|
i1 = c2 * 2
|
|
|
|
|
r1 = i1 + 7 + (c1 + 7 * 9)
|
|
|
|
|
r2 = i1 + 9
|
|
|
|
|
out = [Write(r1), Write(r2), Write(c2)]
|
|
|
|
|
|
2025-10-04 20:57:45 +00:00
|
|
|
il, _ = copapy.compile_to_instruction_list(out, copapy.generic_sdb)
|
2025-10-03 21:26:51 +00:00
|
|
|
|
|
|
|
|
# run program command
|
2025-10-04 20:57:45 +00:00
|
|
|
il.write_com(binwrite.Command.RUN_PROG)
|
2025-10-03 21:26:51 +00:00
|
|
|
il.write_int(0)
|
|
|
|
|
|
|
|
|
|
il.write_com(binwrite.Command.READ_DATA)
|
|
|
|
|
il.write_int(0)
|
|
|
|
|
il.write_int(36)
|
|
|
|
|
|
|
|
|
|
# run program command
|
|
|
|
|
il.write_com(binwrite.Command.END_PROG)
|
|
|
|
|
|
|
|
|
|
#print('* Data to runner:')
|
|
|
|
|
#il.print()
|
|
|
|
|
|
|
|
|
|
print('+ run coparun')
|
|
|
|
|
result = coparun(il.get_data())
|
|
|
|
|
|
|
|
|
|
assert result == 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
test_compile()
|