%include "sys.inc" %include "alloc.inc" %include "linked_list.inc" ;; TODO: Monad bind functions need to return a monad %include "monad.inc" %include "lstring.inc" %include "zstring.inc" %include "dtos.inc" %include "file.inc" %include "debug.inc" section .data make_lstring test_lstring, "LString Test: Ok",10 m_make test_lstring, test_lstring_len, 1 make_zstring test_zstring, "ZString Test: Ok",10 m_make test_zstring, test_zstring, 1 make_zstring test_two_zstring, "Clone Test: Ok",10 m_make test_empty ; m_(label) is the created monad make_zstring test_dots, "DTOS Test: " make_zstring test_mdots, "Monad-Bound DTOS Test: " m_make test_mdots make_zstring file_too_long_err_s, "File too long!",10 _TEST: dq "kO" make_fbuffer "input.txt", test_file, FBUF_DEFAULT_SIZE m_make test_file, test_file_filedata, 1 global _main global _start section .text _start: _main: m_call print_lstring, rel m_test_lstring m_call print_zstring, rel m_test_zstring m_Nothing rel m_test_zstring m_call print_zstring m_Just rel m_test_zstring, test_two_zstring, 1 m_call print_zstring m_return rel m_test_empty, test_two_zstring m_call print_zstring, rel m_test_empty lea rax, [rel test_dots] call print_zstring dtomz_h "kO" ; Little endian m_call print_zstring lea rax, [rel test_mdots] call print_zstring mov rax, [rel _TEST] m_return rel m_test_mdots m_bind data_to_zstring_mh m_call print_zstring lea rax, [rel test_mdots] call print_zstring mov rax, "kO" m_return rel m_test_mdots m_bind data_to_zstring_mh m_call print_zstring alloc FBUF_ALLOC_SIZE mov rbx, rax m_call ffopen, rel m_test_file mov [rel test_file_filedata + fd_buffer], rbx mov qword [rel test_file_filedata + fd_size], FBUF_ALLOC_SIZE flen test_file push rax m_return rel m_test_mdots m_bind data_to_zstring_md m_call print_zstring pop rax cmp rax, FBUF_ALLOC_SIZE ja .error.exit fbegin test_file lea rax, [rel test_file_filedata] call ffread fclose test_file mov rax, [rel test_file_filedata + fd_buffer] mov rcx, 0 add rax, 54 mov [rax], rcx mov rax, [rel test_file_filedata + fd_buffer] call print_zstring free rbx, FBUF_ALLOC_SIZE lln_alloc push rax mov rbx, rax mov r12, 0xDEADBEEF ll_push rbx, r12 push rax mov rax, [rax + ll_value] REGD rax pop rax lln_free pop rax lln_free exit_prog .error.exit: fclose test_file lea rax, [rel file_too_long_err_s] call print_zstring exit_prog 1