summaryrefslogtreecommitdiff
path: root/tnslc/tnslc.tnsl
blob: d49bcc969489de390bc295890136d87a74cfa007 (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
:import "utils/utils.tnsl"
:import "parse/parse.tnsl"
:import "compile/compile.tnsl"

~uint8 DEFAULT_FOUT = "out.asm\0"

~uint8 USAGE = "
TNSLC v0.7.0 (C) 2026 CircleShift (MPL 2.0)

usage:
	tnslc [options] (file in)

options:
	-o [output file]
		Sets the file to output asm code to (default is \"out.asm\")
	
	-p
		Print the parse tree and exit without compiling
	
	-m
		Print the module tree and exit without compiling
	
\0"

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

~uint8 char_str = "%c\0"
~uint8 newline = "\n\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, fout
	int arg_counter = 1
	int mode = 0
	~uint8 first_str = argv{arg_counter}

	/; if (first_str{0} == '-')
		/; if (utils.strcmp(argv{arg_counter}, "-p\0") == true)
			mode = 1
			arg_counter++
		;; else if (utils.strcmp(argv{arg_counter}, "-m\0") == true)
			mode = 2
			arg_counter++
		;; else if (utils.strcmp(argv{arg_counter}, "-o\0") == true)
			arg_counter++
			/; if (arg_counter !< argc)
				_printf(USAGE)
				return 1
			;/
			fout.init(argv{arg_counter})
		;; else
			fout.init(DEFAULT_FOUT)
		;/
	;/

	/; if (arg_counter !< argc)
		_printf(USAGE)
		return 1
	;/
	
	fin.init(argv{arg_counter})
	
	/; if (mode == 0)
		compile.generate(~fin, ~fout)
		fout.end()
	;; else if (mode == 1)
		compile.parse_tree(~fin)
	;; else if (mode == 2)
		compile.mod_tree(~fin)
	;/

	fin.end()

	return 0
;/