summaryrefslogtreecommitdiff
path: root/tnslc/compile/codegen.tnsl
blob: 48545f350533c7be9e53e6dc4c6f900a3391ec42 (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

/; generate (~utils.File fin, fout)
	# Parse files into AST
	parse.Node ast = parse.generate_ast(fin)
	ast.update_children()
	parse.print_ast(~ast)

	# Create output buffer
	CompBuf buffer
	buffer.init()

	# Transform into a module tree
	Module mod
	mod.init(~ast, ~buffer)
	mod.update_children()

	# Compile code
	_gen_prims(~mod)
	mod.compile(~buffer)

	# Write assembly to output file
	fout.create()
	buffer.write_to(fout)
	fout.close()
	
	# Free all structs
	mod.end()
	buffer.end()
	ast.end()
;/

/; _gen_prims (~Module m)
	Var t

	Struct s
	s.members.init(len t)
	s.methods = NULL
	s._up = NULL

	~uint8 str

	# One byte prims
	s.size = 1
	s.name = utils.strcpy("bool\0")
	m`.structs.push(~s)
	s.name = utils.strcpy("uint8\0")
	m`.structs.push(~s)
	s.name = utils.strcpy("int8\0")
	m`.structs.push(~s)

	# Two byte prims
	s.size = 2
	s.name = utils.strcpy("uint16\0")
	m`.structs.push(~s)
	s.name = utils.strcpy("int16\0")
	m`.structs.push(~s)

	# Four byte prims
	s.size = 4
	s.name = utils.strcpy("uint32\0")
	m`.structs.push(~s)
	s.name = utils.strcpy("int32\0")
	m`.structs.push(~s)
	s.name = utils.strcpy("float32\0")
	m`.structs.push(~s)

	# Eight byte prims
	s.size = 8
	s.name = utils.strcpy("uint64\0")
	m`.structs.push(~s)
	s.name = utils.strcpy("int64\0")
	m`.structs.push(~s)
	s.name = utils.strcpy("float64\0")
	m`.structs.push(~s)
	s.name = utils.strcpy("uint\0")
	m`.structs.push(~s)
	s.name = utils.strcpy("int\0")
	m`.structs.push(~s)
	s.name = utils.strcpy("float\0")
	m`.structs.push(~s)
	s.name = utils.strcpy("void\0")
	m`.structs.push(~s)

;/