summaryrefslogtreecommitdiff
path: root/tnslc/tnslc.tnsl
blob: 23d3531469b7602d4ee6c5720017113ba90b4066 (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
:import "c_wrap_linux.tnsl"

:import "utils/utils.tnsl"
:import "compile/compile.tnsl"

~uint8 DEFAULT_FOUT = "out.asm\0"

~uint8 USAGE = "
TNSLC v0.5.0 (C) 2024 CircleShift

usage:
	tnslc (file in) [file out]
	
\0"

~uint8 FOPEN_ERR = "Error opening file\n\0"

~uint8 char_str = "%c\0"
~uint8 newline = "\n\0"
~uint8 rel_pth = "../../tnslc.tnsl\0"

/; main (int argc, ~~uint8 argv) [int]
	asm "mov r10, rdi"
	asm "mov r11, rsi"

	/; if (argc < 2)
		_printf(USAGE)
		return 1
	;/

	utils.File fin
	fin.init(argv{1})
	fin.open()

	/; if (fin.at_end == true)
		_printf(FOPEN_ERR)
		fin.end()
		return 2
	;/

	/; loop (fin.at_end == false)
		_print_num(char_str, fin.read())
	;/

	utils.File rel = fin.relative(rel_pth)
	~uint8 str = rel.path.to_cstr('/')
	_printf(str)
	_printf(newline)
	_delete(str)
	rel.end()

	fin.close()
	fin.end()

	return 0
;/