aboutsummaryrefslogtreecommitdiff
path: root/main.asm
blob: 2e5d293befebd5e0000b1bb0a91b609819b030ac (plain)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
%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

	dll_alloc
	push	rax
	mov	rbx,	rax
	mov	r12,	0xDEADBEEF
	dll_push	rbx,	r12
	push rax
	mov	rbx,	[rsp+8]
	mov	r12,	0xCAFEBABE
	dll_push	rbx,	r12
	push	rax

	mov	rbx,	[rsp+16]

	mov	rax,	rbx
	mov	rax,	[rax + dll_value]
	REGD	rax

	mov	rax,	rbx
	dll_seek
	mov	rax,	[rax + dll_value]
	REGD	rax

	mov	rax,	rbx
	dll_seek
	dll_seek
	mov	rax,	[rax + dll_value]
	REGD	rax

	mov	rax,	rbx
	dll_end
	mov	rax,	[rax + dll_value]
	REGD	rax

	pop	rax
	pop	rax
	pop	rax
	call _dll_free

	FLAGD	b

	exit_prog

.error.exit:
	fclose	test_file
	lea	rax,	[rel file_too_long_err_s]
	call	print_zstring
	exit_prog	1