1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
%include "sys.inc"
%include "alloc.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_b, 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
;; m_call ffopen, rel m_test_file
;; 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_DEFAULT_SIZE
;; ja .error.exit
;; fbegin test_file
;; fread test_file
;; fclose test_file
;; m_call print_filedata, rel m_test_file
alloc FBUF_ALLOC_SIZE
mov rbx, rax
m_call ffopen, rel m_test_file
mov [rel test_file_filedata + buffer], rbx
mov qword [rel test_file_filedata + 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 + buffer]
call print_zstring
free rbx, FBUF_ALLOC_SIZE
exit_prog
.error.exit:
fclose test_file
lea rax, [rel file_too_long_err_s]
call print_zstring
exit_prog 1
|