summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2022-09-14 14:05:03 -0400
committerKyle Gunger <kgunger12@gmail.com>2022-09-14 14:05:03 -0400
commit4e2e269fab3f5facedc6ec0131f132bd66c0aac4 (patch)
treedab2c175c4c81c3665703c800d07bb1d775821e0
parent37d1e9fa02b27d1a6c56b4c95d31e6d2b9eab9ee (diff)
Focus on ASM generation instead of raw binary
-rw-r--r--tnslc/compile/arch/arch.tnsl20
-rw-r--r--tnslc/compile/arch/common.tnsl22
-rw-r--r--tnslc/compile/arch/isa_arm.tnsl15
-rw-r--r--tnslc/compile/arch/isa_risc_v.tnsl15
-rw-r--r--tnslc/compile/arch/isa_x86.tnsl29
-rw-r--r--tnslc/compile/comp.tnsl3
-rw-r--r--tnslc/compile/compile.tnsl6
-rw-r--r--tnslc/compile/format/elf.tnsl151
-rw-r--r--tnslc/compile/format/format.tnsl20
-rw-r--r--tnslc/compile/format/pe.tnsl0
-rw-r--r--tnslc/compile/isa_x86.tnsl48
-rw-r--r--tnslc/dummy.tnsl42
-rwxr-xr-xtnslc/run.sh2
-rw-r--r--tnslc/tnslc.tnsl1
-rw-r--r--tnslc/util.tnsl68
15 files changed, 151 insertions, 291 deletions
diff --git a/tnslc/compile/arch/arch.tnsl b/tnslc/compile/arch/arch.tnsl
deleted file mode 100644
index 5e81673..0000000
--- a/tnslc/compile/arch/arch.tnsl
+++ /dev/null
@@ -1,20 +0,0 @@
-/##
- Copyright 2021 Kyle Gunger
-
- This file is licensed under the CDDL 1.0 (the License)
- and may only be used in accordance with the License.
- You should have received a copy of the License with this
- software/source code. If you did not, a copy can be found
- at the following URL:
-
- https://opensource.org/licenses/CDDL-1.0
-
- THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO
- WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE
- EXPRESS OR IMPLIED
-#/
-
-/; module arch
- :import "compile/arch/common.tnsl"
- :import "compile/arch/isa_x86.tnsl"
-;/ \ No newline at end of file
diff --git a/tnslc/compile/arch/common.tnsl b/tnslc/compile/arch/common.tnsl
deleted file mode 100644
index 1ff1c89..0000000
--- a/tnslc/compile/arch/common.tnsl
+++ /dev/null
@@ -1,22 +0,0 @@
-/##
- Copyright 2021 Kyle Gunger
-
- This file is licensed under the CDDL 1.0 (the License)
- and may only be used in accordance with the License.
- You should have received a copy of the License with this
- software/source code. If you did not, a copy can be found
- at the following URL:
-
- https://opensource.org/licenses/CDDL-1.0
-
- THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO
- WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE
- EXPRESS OR IMPLIED
-#/
-
-# Instructions are always stored in big-endian format internally.
-# The settings for the isa/compiler dictate weather the instruction
-# data will be reversed when the sections are being written.
-; struct instruction {
- {}uint8 data
-} \ No newline at end of file
diff --git a/tnslc/compile/arch/isa_arm.tnsl b/tnslc/compile/arch/isa_arm.tnsl
deleted file mode 100644
index 0dc3468..0000000
--- a/tnslc/compile/arch/isa_arm.tnsl
+++ /dev/null
@@ -1,15 +0,0 @@
-/##
- Copyright 2021 Kyle Gunger
-
- This file is licensed under the CDDL 1.0 (the License)
- and may only be used in accordance with the License.
- You should have received a copy of the License with this
- software/source code. If you did not, a copy can be found
- at the following URL:
-
- https://opensource.org/licenses/CDDL-1.0
-
- THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO
- WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE
- EXPRESS OR IMPLIED
-#/
diff --git a/tnslc/compile/arch/isa_risc_v.tnsl b/tnslc/compile/arch/isa_risc_v.tnsl
deleted file mode 100644
index 0dc3468..0000000
--- a/tnslc/compile/arch/isa_risc_v.tnsl
+++ /dev/null
@@ -1,15 +0,0 @@
-/##
- Copyright 2021 Kyle Gunger
-
- This file is licensed under the CDDL 1.0 (the License)
- and may only be used in accordance with the License.
- You should have received a copy of the License with this
- software/source code. If you did not, a copy can be found
- at the following URL:
-
- https://opensource.org/licenses/CDDL-1.0
-
- THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO
- WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE
- EXPRESS OR IMPLIED
-#/
diff --git a/tnslc/compile/arch/isa_x86.tnsl b/tnslc/compile/arch/isa_x86.tnsl
deleted file mode 100644
index 03646ce..0000000
--- a/tnslc/compile/arch/isa_x86.tnsl
+++ /dev/null
@@ -1,29 +0,0 @@
-/##
- Copyright 2021 Kyle Gunger
-
- This file is licensed under the CDDL 1.0 (the License)
- and may only be used in accordance with the License.
- You should have received a copy of the License with this
- software/source code. If you did not, a copy can be found
- at the following URL:
-
- https://opensource.org/licenses/CDDL-1.0
-
- THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO
- WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE
- EXPRESS OR IMPLIED
-#/
-
-
-
-/; gen_symtab (Node program) [Symtab]
-
-;/
-
-/; symtab_to_section (Symtab sym) [{}charp]
-
-;/
-
-/; block_to_asm ({}charp block_name, Node block) [{}charp]
-
-;/
diff --git a/tnslc/compile/comp.tnsl b/tnslc/compile/comp.tnsl
deleted file mode 100644
index 18ca4b5..0000000
--- a/tnslc/compile/comp.tnsl
+++ /dev/null
@@ -1,3 +0,0 @@
-/; do_compile ({}charp file, ast.Node data, Settings settings)
-
-;/ \ No newline at end of file
diff --git a/tnslc/compile/compile.tnsl b/tnslc/compile/compile.tnsl
index df94752..d1f72b4 100644
--- a/tnslc/compile/compile.tnsl
+++ b/tnslc/compile/compile.tnsl
@@ -16,13 +16,15 @@
/; module compile
# :include "compile/arch/arch.tnsl"
- :include "compile/arch/isa_x86.tnsl"
+ :include "compile/isa_x86.tnsl"
# :include "compile/comp.tnsl"
;/
-/; do_compile ({}charp file, ast.Node data, Settings settings)
+/; do_compile ({}charp file, ~{}Token data)
+ /;
+ ;/
;/
;struct Symtab {
diff --git a/tnslc/compile/format/elf.tnsl b/tnslc/compile/format/elf.tnsl
deleted file mode 100644
index 8490180..0000000
--- a/tnslc/compile/format/elf.tnsl
+++ /dev/null
@@ -1,151 +0,0 @@
-/##
- Copyright 2021 Kyle Gunger
-
- This file is licensed under the CDDL 1.0 (the License)
- and may only be used in accordance with the License.
- You should have received a copy of the License with this
- software/source code. If you did not, a copy can be found
- at the following URL:
-
- https://opensource.org/licenses/CDDL-1.0
-
- THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO
- WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE
- EXPRESS OR IMPLIED
-#/
-
-# Constants and values used in ELF files
-
-# File signature
-;const {4}uint8 SIGNATURE_ELF = {0x7F, 'E', 'L', 'F'}
-
-# ELF version always 1
-;const uint8 VERSION_ELF = 1
-
-# OS identifiers (from wikipedia)
-;enum ABI_ELF [uint8] {
- SystemV = 0x0,
- HP_UX = 0x1,
- NetBSD = 0x2,
- Linux = 0x3,
- GNUHurd = 0x4,
- Solaris = 0x6,
- AIX = 0x7,
- IRIX = 0x8,
- FreeBSD = 0x9,
- Tru64 = 0xA,
- OpenBSD = 0xC,
- OpenVMS = 0xD
-}
-
-# ELF file types (from wikipedia)
-;enum TYPE_ELF [uint16] {
- ET_NONE = 0x0,
- ET_REL = 0x1,
- ET_EXEC = 0x2,
- ET_DYN = 0x3,
- ET_CORE = 0x4,
- ET_LOOS = 0xFE00,
- ET_HIOS = 0xFEFF,
- ET_LOPROC = 0xFF00,
- ET_HIPROC = 0xFFFF
-}
-
-# ISA (from wikipedia)
-;enum ARCH_ELF [uint16] {
- NONE = 0x0,
- SPARC = 0x2,
- x86_32 = 0x3,
- MIPS = 0x8,
- PowerPC = 0x14,
- PowerPC64 = 0x15,
- ARM = 0x28,
- SPARC9 = 0x2B,
- IA_64 = 0x32,
- x86_64 = 0x3E,
- ARM64 = 0xB7,
- RISC_V = 0xF3
-}
-
-# Some zeros to fill out the pad in the header
-;const {7}uint8 PAD_ZEROS_ELF = {0, 0, 0, 0, 0, 0, 0}
-
-
-
-# Internal file structures
-
-# Identity inside header
-;raw struct IdentityELF {
- {4}uint8
- signature,
-
- uint8
- class,
- data,
- version,
- abi,
-
- # Usually zero
- abiVersion,
-
- {7}uint8
- # Filled with zeros, use PAD_ZEROS_ELF to fill out
- pad
-}
-
-# Main header (32 bit)
-;raw struct HeaderELF32 {
- IdentityELF
- identity,
-
- uint16
- fileType,
- arch,
-
- {4}uint8
- version,
- entry,
- programHeader,
- sectionHeader,
-
- {4}uint8
- flags,
-
- uint16
- headerSize,
- programHeaderSize,
- programHeaderEntries,
- sectionHeaderSize,
- sectionHeaderEntries,
- shNameIndex
-}
-
-# Main header (64 bit)
-;raw struct HeaderELF64 {
- IdentityELF
- identity,
-
- uint16
- fileType,
- arch,
-
- {4}uint8
- version,
-
- {8}uint8
- entry,
- programHeader,
- sectionHeader,
-
- {4}uint8
- flags,
-
- uint16
- headerSize,
- programHeaderSize,
- programHeaderEntries,
- sectionHeaderSize,
- sectionHeaderEntries,
- shNameIndex
-}
-
diff --git a/tnslc/compile/format/format.tnsl b/tnslc/compile/format/format.tnsl
deleted file mode 100644
index 14831b5..0000000
--- a/tnslc/compile/format/format.tnsl
+++ /dev/null
@@ -1,20 +0,0 @@
-/##
- Copyright 2021 Kyle Gunger
-
- This file is licensed under the CDDL 1.0 (the License)
- and may only be used in accordance with the License.
- You should have received a copy of the License with this
- software/source code. If you did not, a copy can be found
- at the following URL:
-
- https://opensource.org/licenses/CDDL-1.0
-
- THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO
- WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE
- EXPRESS OR IMPLIED
-#/
-
-/; module format
- # :include "compile/format/out.tnsl"
- :include "compile/format/elf.tnsl"
-;/ \ No newline at end of file
diff --git a/tnslc/compile/format/pe.tnsl b/tnslc/compile/format/pe.tnsl
deleted file mode 100644
index e69de29..0000000
--- a/tnslc/compile/format/pe.tnsl
+++ /dev/null
diff --git a/tnslc/compile/isa_x86.tnsl b/tnslc/compile/isa_x86.tnsl
new file mode 100644
index 0000000..1df9902
--- /dev/null
+++ b/tnslc/compile/isa_x86.tnsl
@@ -0,0 +1,48 @@
+/##
+ Copyright 2021 Kyle Gunger
+
+ This file is licensed under the CDDL 1.0 (the License)
+ and may only be used in accordance with the License.
+ You should have received a copy of the License with this
+ software/source code. If you did not, a copy can be found
+ at the following URL:
+
+ https://opensource.org/licenses/CDDL-1.0
+
+ THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO
+ WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE
+ 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/dummy.tnsl b/tnslc/dummy.tnsl
index 12b082e..8fdb165 100644
--- a/tnslc/dummy.tnsl
+++ b/tnslc/dummy.tnsl
@@ -1,12 +1,30 @@
-;int a = 0x11
-;bool aaaa = false
-
-/; main
- /; if (a !== 11)
- ;tnsl.io.println(a)
- ;/
-
- /; loop (!aaaa) [a !== 17]
- ;tnsl.io.println("Looping!")
- ;/
-;/
+; struct Token {
+ int
+ token_type,
+ line,
+ col,
+
+ ~{}charp
+ data
+}
+
+;struct Node {
+ Token
+ # associated token to the node
+ tok,
+
+ ~{}Node
+ # sub-nodes
+ sub
+}
+
+;{}charp cnull = "a"
+
+/; main [int]
+ ;{}Node s = {}
+ ;Node n = {{1, 2, 3, ~cnull}, ~s}
+ ;s.append(n)
+ ;tnsl.io.println(~s)
+ ;tnsl.io.println(n.sub)
+ ;return 0
+;/ \ No newline at end of file
diff --git a/tnslc/run.sh b/tnslc/run.sh
index e02b7fd..c1b19e5 100755
--- a/tnslc/run.sh
+++ b/tnslc/run.sh
@@ -1,3 +1,3 @@
#!/bin/bash
-../tint -quiet -in tnslc.tnsl -flags "$1"
+../tint -in tnslc.tnsl -flags "$1"
diff --git a/tnslc/tnslc.tnsl b/tnslc/tnslc.tnsl
index 7ea58df..10a7bbd 100644
--- a/tnslc/tnslc.tnsl
+++ b/tnslc/tnslc.tnsl
@@ -18,7 +18,6 @@
/; export module tnslc
:include "parse/parse.tnsl"
- :include "ast/ast.tnsl"
:include "compile/compile.tnsl"
;/
diff --git a/tnslc/util.tnsl b/tnslc/util.tnsl
index f1644e7..a26b93e 100644
--- a/tnslc/util.tnsl
+++ b/tnslc/util.tnsl
@@ -32,6 +32,20 @@
;return true
;/
+/; add_strings (~{}charp a, b) [{}charp]
+ ;{}charp out = ""
+
+ /; loop (int i = 0; i < len a`) [i++]
+ ;out.append(a`{i})
+ ;/
+
+ /; loop (int i = 0; i < len b`) [i++]
+ ;out.append(b`{i})
+ ;/
+
+ ;return out
+;/
+
/; is_whitespace (charp c) [bool]
;return c == '\t' || c == '\n' || c == ' '
;/
@@ -44,3 +58,57 @@
;bool low = c !< 'A' && c !> 'Z', high = c !< 'a' && c >! 'z'
;return low || high
;/
+
+/; digit_to_char(int i) [charp]
+ ;charp out = '0'
+ ;out = out + (i % 10)
+ ;return out
+;/
+
+/; string_from_int(int i) [{}charp]
+ ;{}charp c = ""
+
+ /; if (i < 0)
+ ;c = "-"
+ ;i = -i
+ ;/
+
+ ;c.append(digit_to_char(i))
+
+ /; loop (i !== 0) [i = i / 10]
+ ;c.append(digit_to_char(i))
+ ;/
+
+ ;return c
+;/
+
+/; get_escape_code (charp c) [charp]
+ /; if (c == '\'')
+ ;return '\''
+ ;; else if (c == 'n')
+ ;return '\n'
+ ;; else if (c == 't')
+ ;return '\t'
+ ;; else if (c == '\r')
+ ;return '\r'
+ ;; else if (c == '\b')
+ ;return '\b'
+ ;/
+
+ ;return 0
+;/
+
+/; unquote_char ({}charp c) [charp]
+ /; if (c{1} == '\\')
+ /; if (c{2} == 'u')
+ ;return 0
+ ;/
+ ;return get_escape_code(c{2})
+ ;/
+
+ ;return c{1}
+;/
+
+/; unquote_string ({}charp str) [{}charp]
+
+;/