summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2022-09-28 15:55:56 -0400
committerKyle Gunger <kgunger12@gmail.com>2022-09-28 15:55:56 -0400
commita58e2685b815a5a0d2d5f07bc3ae53016ba6f52b (patch)
treeb80ae09d5e66c32633b29917ab5412000187c513
parentdedd1d1e4bcc2607a626776507ef1136ef44af8d (diff)
Add stub code
-rw-r--r--tnslc/compile/compile.tnsl125
-rw-r--r--tnslc/dummy.tnsl6
2 files changed, 107 insertions, 24 deletions
diff --git a/tnslc/compile/compile.tnsl b/tnslc/compile/compile.tnsl
index 7df7acb..0aade7b 100644
--- a/tnslc/compile/compile.tnsl
+++ b/tnslc/compile/compile.tnsl
@@ -22,22 +22,121 @@
;{}{}charp COMMON_ASM = {
- "\tret"
+ "\tret",
+ "push %",
+ "pop %"
}
+;struct VType {
+ uint _size,
+ {}charp name
+}
+
+;struct VTrack {
+ {}{}charp
+ sym_names,
+
+ {}VType
+ sym_types
+}
+
+# Null type
+;VType NT = {0, "null"}
+
+/; find_var ({}charp name, ~VTrack tab) [{}charp]
+ /; loop (int i = 0; i < 8) [i++]
+ /; if (string_equate(tab`.sym_names{i}, name))
+ ;{}charp out = "r"
+ ;{}charp n = string_from_int(i + 8)
+ ;add_strings(~out, ~n)
+ /; if (tab`.sym_sizes{i}._size == 4)
+ ;out.append('d')
+ ;; else if (tab`.sym_sizes{i}._size == 2)
+ ;out.append('w')
+ ;; else if (tab`.sym_sizes{i}._size == 1)
+ ;out.append('b')
+ ;/
+ ;return out
+ ;/
+ ;/
+
+ ;tnsl.io.print("Failed to find vairable ")
+ ;tnsl.io.println(name)
+;/
+
+/; token_is(~int cur, ~{}Token data, {}charp str) [bool]
+ ;return string_equate(data`{cur`}.data`, str)
+;/
+
+/; setup_vtrack (~int cur, ~{}Token data, ~VTrack tab)
+ ;cur`++
+
+ /; loop (cur` < len data`) [cur`++]
+ /; if (token_is(cur, data, ")"))
+ ;break
+ ;;
+ ;/
+ ;/
+;/
+
+/; header_guard (~VTrack tab, ~{}charp csec)
+
+;/
+
+/; ret_guard (~VTrack tab, {}charp to_ret, ~{}charp csec)
+ ;tail_guard(csec)
+
+;/
+
+/; tail_guard (~{}charp csec)
+;/
+
+/; compile_statement (~int cur, ~{}Token data, ~{}charp hsec, csec, dsec)
+ ;cur`++
+ /; if (cur` < len data`)
+ /; if (token_is(cur, data, "asm"))
+ ;cur`++
+ ;{}charp raw_asm = unquote_string(data`{cur`}.data`)
+ ;raw_asm.append('\n')
+ ;csec`.append('\t')
+ ;add_strings(csec, ~raw_asm)
+ ;/
+ ;/
+;/
+
/; compile_block (~int cur, ~{}Token data, ~{}charp hsec, csec, dsec)
+ ;VTrack tab = {
+ {"", "", "", "", "", "", "", ""},
+ {NT, NT, NT, NT, NT, NT, NT, NT}
+ }
+
;{}charp name = {}
+ ;bool r = false
/; 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 if (token_is(cur, data, "("))
+ ;setup_vtrack(cur, data, ~tab)
+ ;; else if (token_is(cur, data, "["))
+ /; loop (cur`++; cur` < len data`) [cur`++]
+ /; if (token_is(cur, data, "]"))
+ ;break
+ ;/
+ ;/
+ ;; else if (token_is(cur, data, "raw"))
+ ;r = true
;; else
;break
;/
;/
+ /; if (!r)
+ ;header_guard(tab, csec)
+ ;/
+
/; loop (cur` < len data`) [cur`++]
/; if (string_equate(data`{cur`}.data`, ";/"))
;add_strings(csec, ~(tnslc.COMMON_ASM{0}))
@@ -61,20 +160,11 @@
;/
;/
- ;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"))
- ;cur`++
- ;{}charp raw_asm = unquote_string(data`{cur`}.data`)
- ;raw_asm.append('\n')
- ;csec`.append('\t')
- ;add_strings(csec, ~raw_asm)
- ;/
+ /; if (!r)
+ ;tail_guard(csec)
;/
+
+ ;csec`.append('\n')
;/
/; do_compile ({}charp file, ~{}Token data)
@@ -116,10 +206,3 @@
;out.close()
;/
-;struct Symtab {
- {}{}charp
- sym_names,
-
- {}uint
- sym_sizes
-}
diff --git a/tnslc/dummy.tnsl b/tnslc/dummy.tnsl
index 2a624a2..003e428 100644
--- a/tnslc/dummy.tnsl
+++ b/tnslc/dummy.tnsl
@@ -1,4 +1,4 @@
-/; _alloc
+/; raw _alloc
;asm "mov %rax, %rdi"
;asm "push %r8"
;asm "push %r9"
@@ -10,7 +10,7 @@
;asm "pop %r8"
;/
-/; _delete
+/; raw _delete
;asm "mov %rax, %rdi"
;asm "push %r9"
;asm "push %r10"
@@ -20,7 +20,7 @@
;asm "pop %r9"
;/
-/; main
+/; main [int]
;asm "mov $10, %rax"
;asm "call _alloc"
;asm "call _delete"