summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2022-09-20 00:03:32 -0400
committerKyle Gunger <kgunger12@gmail.com>2022-09-20 00:03:32 -0400
commitbe9813b1062c1f9b2c0d13a76d56c41ba984c1db (patch)
treefbfa5b93495c14c646009c92c3b403e639ad9161
parent5582d6427e2bc09b9975615f87cace64ce2d29ca (diff)
Generate a dummy file
-rw-r--r--tnslc/compile/compile.tnsl59
-rw-r--r--tnslc/compile/isa_x86.tnsl32
-rw-r--r--tnslc/tnslc.tnsl6
-rw-r--r--tnslc/util.tnsl12
4 files changed, 64 insertions, 45 deletions
diff --git a/tnslc/compile/compile.tnsl b/tnslc/compile/compile.tnsl
index d1f72b4..d7e9416 100644
--- a/tnslc/compile/compile.tnsl
+++ b/tnslc/compile/compile.tnsl
@@ -21,10 +21,67 @@
;/
+/; compile_block (~int cur, ~{}Token data, ~{}charp hsec, csec, dsec)
+ ;hsec`.append('b')
+
+ ;cur`++
+
+ /; loop (cur` < len data`) [cur`++]
+ /; if (string_equate(data`{cur`}.data`, ";/") || string_equate(data`{cur`}.data`, ";;"))
+ ;break
+ ;; else if (string_equate(data`{cur`}.data`, "/;"))
+ ;bool ch = true
+ /; loop (ch)
+ ;compile_block(cur, data, hsec, csec, dsec)
+ ;ch = string_equate(data`{cur`}.data`, ";;")
+ ;/
+ ;; else if (string_equate(data`{cur`}.data`, ";"))
+ ;compile_statement(cur, data, hsec, csec, dsec)
+ ;/
+ ;/
+;/
+
+/; compile_statement (~int cur, ~{}Token data, ~{}charp hsec, csec, dsec)
+ ;csec`.append('c')
+ ;dsec`.append('d')
+;/
+
/; do_compile ({}charp file, ~{}Token data)
- /;
+ ;{}charp hsec = ".global _start\n"
+ ;{}charp csec = ".text\n"
+ ;{}charp dsec = ".data\n"
+
+ ;int j = len data`
+
+ /; loop (int i = 0; i < j) [i++]
+ /; if (string_equate(data`{i}.data`, "/;"))
+ ;compile_block(~i, data, ~hsec, ~csec, ~dsec)
+ ;; else if (string_equate(data`{i}.data`, ";"))
+ ;compile_statement(~i, data, ~hsec, ~csec, ~dsec)
+ ;; else
+ ;break
+ ;/
+ ;/
+
+ ;tnsl.io.File out = tnsl.io.writeFile(file)
+
+ /; loop (int i = 0; i < len hsec) [i++]
+ ;out.write(hsec{i})
+ ;/
+
+ ;out.write('\n')
+ /; loop (int i = 0; i < len csec) [i++]
+ ;out.write(csec{i})
;/
+
+ ;out.write('\n')
+
+ /; loop (int i = 0; i < len dsec) [i++]
+ ;out.write(dsec{i})
+ ;/
+
+ ;out.write('\n')
;/
;struct Symtab {
diff --git a/tnslc/compile/isa_x86.tnsl b/tnslc/compile/isa_x86.tnsl
index 1df9902..bc5d43f 100644
--- a/tnslc/compile/isa_x86.tnsl
+++ b/tnslc/compile/isa_x86.tnsl
@@ -14,35 +14,3 @@
EXPRESS OR IMPLIED
#/
-/; gen_x86 (~Node program, {}charp out)
- ;tnsl.io.File o = tnsl.io.writeFile(out)
-
- ;{}uint8 current = gen_head(program)
- /; loop (int i = 0; i < len current) [i++]
- ;o.write(current{i})
- ;/
-
- ;{}uint8 current = gen_data(program)
- /; loop (int i = 0; i < len current) [i++]
- ;o.write(current{i})
- ;/
-
- ;{}uint8 current = gen_text(program)
- /; loop (int i = 0; i < len current) [i++]
- ;o.write(current{i})
- ;/
-
- ;o.close()
-;/
-
-/; gen_data (~Node program) [{}charp]
-
-;/
-
-/; gen_text (~Node program) [{}charp]
-
-;/
-
-/; gen_head (~Node program) [{}charp]
-
-;/
diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl
index ec6fa04..2a19f20 100644
--- a/tnslc/tnslc.tnsl
+++ b/tnslc/tnslc.tnsl
@@ -24,8 +24,8 @@
/; main ({}{}charp args) [int]
- /; if (len args < 1)
- ;tnsl.io.println(string_from_int(97265))
+ /; if (len args < 2)
+ ;tnsl.io.println("Usage: tnslc [file in] [file out]")
;return 1
;/
@@ -39,5 +39,7 @@
# ;tnslc.Node tree_node = tnslc.ast.make_tree(psrc, args{0})
+ ;tnslc.do_compile(args{1}, psrc)
+
;return 0
;/
diff --git a/tnslc/util.tnsl b/tnslc/util.tnsl
index 4e2849b..5d84dec 100644
--- a/tnslc/util.tnsl
+++ b/tnslc/util.tnsl
@@ -32,18 +32,10 @@
;return true
;/
-/; add_strings (~{}charp a, b) [{}charp]
- ;{}charp out = ""
-
- /; loop (int i = 0; i < len a`) [i++]
- ;out.append(a`{i})
- ;/
-
+/; add_strings (~{}charp a, b)
/; loop (int i = 0; i < len b`) [i++]
- ;out.append(b`{i})
+ ;a`.append(b`{i})
;/
-
- ;return out
;/
/; reverse_string({}charp str) [{}charp]