summaryrefslogtreecommitdiff
path: root/tnslc
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2022-09-28 11:32:11 -0400
committerKyle Gunger <kgunger12@gmail.com>2022-09-28 11:32:11 -0400
commitf927b5126ef7e219bc5d4aa875523df1f6ea6d83 (patch)
treefebf5655f3969f6259c1ff2ea2526666c4207d9a /tnslc
parent6917d1584bf16ec833a21fc35b95e520de8795f3 (diff)
Some basic asm generation around blocks
Diffstat (limited to 'tnslc')
-rw-r--r--tnslc/compile/compile.tnsl33
-rw-r--r--tnslc/compile/isa_x86.tnsl3
-rw-r--r--tnslc/dummy.tnsl9
-rw-r--r--tnslc/tnslc.tnsl12
4 files changed, 47 insertions, 10 deletions
diff --git a/tnslc/compile/compile.tnsl b/tnslc/compile/compile.tnsl
index 2439c76..7df7acb 100644
--- a/tnslc/compile/compile.tnsl
+++ b/tnslc/compile/compile.tnsl
@@ -21,11 +21,26 @@
;/
+;{}{}charp COMMON_ASM = {
+ "\tret"
+}
+
/; compile_block (~int cur, ~{}Token data, ~{}charp hsec, csec, dsec)
- ;cur`++
+ ;{}charp name = {}
+ /; loop (cur`++; cur` < len data`) [cur`++]
+ /; if (data`{cur`}.token_type == TOKEN_TYPE.DEFWORD && len name == 0)
+ ;name = data`{cur`}.data`
+ ;add_strings(csec, ~name)
+ ;csec`.append(':')
+ ;csec`.append('\n')
+ ;; else
+ ;break
+ ;/
+ ;/
/; loop (cur` < len data`) [cur`++]
- /; if (string_equate(data`{cur`}.data`, ";/") || string_equate(data`{cur`}.data`, ";;"))
+ /; if (string_equate(data`{cur`}.data`, ";/"))
+ ;add_strings(csec, ~(tnslc.COMMON_ASM{0}))
;break
;; else if (string_equate(data`{cur`}.data`, "/;"))
;bool ch = true
@@ -38,22 +53,32 @@
;/
;; else if (string_equate(data`{cur`}.data`, ";"))
;compile_statement(cur, data, hsec, csec, dsec)
+ ;; else
+ ;tnsl.io.print("Failed to compile token [compile_block]: ")
+ ;data`{cur`}.print()
+ ;tnsl.io.println("")
+ ;break
;/
;/
+
+ ;csec`.append('\n')
;/
/; compile_statement (~int cur, ~{}Token data, ~{}charp hsec, csec, dsec)
;cur`++
/; if (cur` < len data`)
/; if (string_equate(data`{cur`}.data`, "asm"))
- ;{}charp raw_asm = unquote_string(data`{cur` + 1}.data`)
+ ;cur`++
+ ;{}charp raw_asm = unquote_string(data`{cur`}.data`)
+ ;raw_asm.append('\n')
+ ;csec`.append('\t')
;add_strings(csec, ~raw_asm)
;/
;/
;/
/; do_compile ({}charp file, ~{}Token data)
- ;{}charp hsec = ".global _start\n"
+ ;{}charp hsec = ".global main\n"
;{}charp csec = ".text\n"
;{}charp dsec = ".data\n"
diff --git a/tnslc/compile/isa_x86.tnsl b/tnslc/compile/isa_x86.tnsl
index bc5d43f..a5d9b0a 100644
--- a/tnslc/compile/isa_x86.tnsl
+++ b/tnslc/compile/isa_x86.tnsl
@@ -14,3 +14,6 @@
EXPRESS OR IMPLIED
#/
+/; add_asm
+
+;/ \ No newline at end of file
diff --git a/tnslc/dummy.tnsl b/tnslc/dummy.tnsl
index 233d726..f53a658 100644
--- a/tnslc/dummy.tnsl
+++ b/tnslc/dummy.tnsl
@@ -1,3 +1,8 @@
-/; asm_test
- ;asm "_start:\n"
+/; main
+ ;asm "mov $0, %eax"
+ ;asm "call doug"
+;/
+
+/; doug
+
;/ \ No newline at end of file
diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl
index 2a19f20..76a10a3 100644
--- a/tnslc/tnslc.tnsl
+++ b/tnslc/tnslc.tnsl
@@ -24,12 +24,14 @@
/; main ({}{}charp args) [int]
- /; if (len args < 2)
- ;tnsl.io.println("Usage: tnslc [file in] [file out]")
+ /; if (len args < 1)
+ ;tnsl.io.println("Usage: tnslc [file in]")
;return 1
;/
- ;tnsl.io.File src = tnsl.io.readFile(args{0})
+ ;{}charp file = args{0}
+
+ ;tnsl.io.File src = tnsl.io.readFile(file)
;~{}tnslc.Token psrc = tnslc.parse.tokenize(src)
@@ -39,7 +41,9 @@
# ;tnslc.Node tree_node = tnslc.ast.make_tree(psrc, args{0})
- ;tnslc.do_compile(args{1}, psrc)
+ ;file.append('.')
+ ;file.append('S')
+ ;tnslc.do_compile(file, psrc)
;return 0
;/