summaryrefslogtreecommitdiff
path: root/tnslc
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2023-08-13 02:59:41 -0400
committerKyle Gunger <kgunger12@gmail.com>2023-08-13 02:59:41 -0400
commita0108fa817c7258ab97c3c2749897c44e5467d1d (patch)
tree2f2d3f6c3dd68aaa7b7787b4c2b5bb6900cd35f4 /tnslc
parent0cc237617e4e853520b0509c02408d4170572d28 (diff)
Fix issue with vector
Re-add definitions for variable, type, and module
Diffstat (limited to 'tnslc')
-rw-r--r--tnslc/compiler.tnsl140
-rw-r--r--tnslc/vector.tnsl2
2 files changed, 130 insertions, 12 deletions
diff --git a/tnslc/compiler.tnsl b/tnslc/compiler.tnsl
index b61ff05..51ed4d6 100644
--- a/tnslc/compiler.tnsl
+++ b/tnslc/compiler.tnsl
@@ -30,6 +30,18 @@ struct CompData {
self.dsec._del()
self.csec._del()
;/
+
+ /; write_file(~void fd)
+ uint8 z = 0
+
+ self.hsec.push(~z)
+ self.dsec.push(~z)
+ self.csec.push(~z)
+
+ write_to_file(fd, self.hsec.dat)
+ write_to_file(fd, self.dsec.dat)
+ write_to_file(fd, self.csec.dat)
+ ;/
;/
# Path represents the actual path of a file
@@ -158,26 +170,132 @@ struct Path {
# Compiler functions - here be dragons #
########################################
-/; compile_file (Path in) [CompData]
+enum POINTER_TYPE [uint8] {
+ POINTER = 0,
+ REFERENCE = 1,
+ ARRAY = 2
+}
+
+# 88 bytes long
+struct Type {
+ int s,
+ ~uint8 name,
+ Vector ptr_chain,
+ Vector members,
+ ~Module mod
+}
+
+/; method Type
+ /; start
+ self.ptr_chain.start(1)
+ # 136 is the size of one Variable struct
+ self.members.start(136)
+ ;/
+
+ /; _del
+ self.ptr_chain._del()
+ self.members._del()
+
+ ;/
+;/
+
+
+
+#############
+# Variables #
+#############
+
+# 136 bytes long
+struct Variable {
+ Vector name,
+
+ Type data_type,
+
+ int location,
+ loc_type
+}
+
+/; method Variable
+
+;/
+
+
+
+###########
+# Modules #
+###########
+
+struct Module {
+ int i
+}
+
+/; method Module
+ /; start
+
+ ;/
+
+ /; _del
+
+ ;/
+;/
+
+/; base_loop_1 (Path in, Vector tokens, ~Module mod)
+
+;/
+
+/; base_loop_2 (Path in, Vector tokens, ~Module mod, ~CompData out)
+
+;/
+
+{}uint8 w_cstart = "Reading file: \0"
+{}uint8 w_nl = "\n\0"
+
+/; compile_file (Path in, ~Module mod) [CompData]
+
+ ~uint8 pth = in.full_path()
+ _printf(~w_cstart{0})
+ _printf(pth)
+ _printf(~w_nl{0})
+ _delete(pth)
+
+ ~void fd = in.open_read()
+ Vector tokens = tokenize_file(fd)
+ _close_file(fd)
+
+ base_loop_1(in, tokens, mod)
+
CompData out
out.start()
-
+ base_loop_2(in, tokens, mod, ~out)
return out
;/
+
+{}uint8 w_dsec = "\nsection .data\n\n\0"
+{}uint8 w_csec = "\nsection .text\n\n\0"
+
+{}uint8 w_compiled = "Compilation complete! Writing file.\n\0"
+
/; compile (Path in, out)
- ~void fin = in.open_read()
- Vector v = tokenize_file(fin)
- _close_file(fin)
+ Module root
+ root.start()
+ CompData cd
+ cd = compile_file(in, ~root)
+
+ _printf(~w_compiled{0})
+
+ # Section headers for the asm
+ ~uint8 shed = ~w_dsec{0}
+ cd.hsec.add_str(shed)
+ shed = ~w_csec{0}
+ cd.dsec.add_str(shed)
~void fout = out.open_write()
- /; loop (int i = 0; i < v.num_el) [i++]
- ~Token t_ptr = v.get(i)
- print_token(t_ptr`, fout)
- t_ptr`._del()
- ;/
- v._del()
+ cd.write_file(fout)
_close_file(fout)
+
+ root._del()
+ cd._del()
;/ \ No newline at end of file
diff --git a/tnslc/vector.tnsl b/tnslc/vector.tnsl
index 73580e0..cab2ead 100644
--- a/tnslc/vector.tnsl
+++ b/tnslc/vector.tnsl
@@ -73,7 +73,7 @@ struct Vector {
# [UNSAFE] ONLY USE FOR STRING VECTORS
/; add_str (~uint8 dat)
- /; loop (int i = 0; dat{i} !== 0)
+ /; loop (int i = 0; dat{i} !== 0) [i++]
self.push(dat + i)
;/
;/