summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libtnsl/src/reflect/lib.tnsl26
-rw-r--r--libtnsl/src/reflect/type.tnsl39
-rw-r--r--tnslc/src/compile/compile.tnsl5
-rw-r--r--tnslc/src/compile/format/elf.tnsl0
-rw-r--r--tnslc/src/compile/format/format.tnsl0
-rw-r--r--tnslc/src/compile/format/iex.tnsl0
-rw-r--r--tnslc/src/compile/format/out.tnsl0
-rw-r--r--tnslc/src/compile/format/pe.tnsl0
-rw-r--r--tnslc/src/parse/parse.tnsl5
-rw-r--r--tnslc/src/parse/token.tnsl259
-rw-r--r--tnslc/src/parse/tokenizer.tnsl25
11 files changed, 354 insertions, 5 deletions
diff --git a/libtnsl/src/reflect/lib.tnsl b/libtnsl/src/reflect/lib.tnsl
new file mode 100644
index 0000000..0688e6f
--- /dev/null
+++ b/libtnsl/src/reflect/lib.tnsl
@@ -0,0 +1,26 @@
+/##
+ Copyright 2021 Kyle Gunger
+
+ Dual licensed under the CDDL 1.0 and BSD 3-Clause licenses.
+
+ This file may only be used in accordance with one of the two
+ licenses. You should have received a copy of each license with
+ the source code. In the event that you did not recieve a copy
+ of the licenses, they may be found at the following URLs:
+
+ CDDL 1.0:
+ https://opensource.org/licenses/CDDL-1.0
+
+ BSD 3-Clause:
+ https://opensource.org/licenses/BSD-3-Clause
+
+ THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO
+ WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE
+ EXPRESS OR IMPLIED
+#/
+
+: extern const {}_library _LIB_TABLE
+
+; raw struct _library {
+
+} \ No newline at end of file
diff --git a/libtnsl/src/reflect/type.tnsl b/libtnsl/src/reflect/type.tnsl
index d346464..2ed0016 100644
--- a/libtnsl/src/reflect/type.tnsl
+++ b/libtnsl/src/reflect/type.tnsl
@@ -17,4 +17,41 @@
THIS SOFTWARE/SOURCE CODE IS PROVIDED "AS IS" WITH NO
WARRANTY, GUARANTEE, OR CLAIM OF FITNESS FOR ANY PURPOSE
EXPRESS OR IMPLIED
-#/ \ No newline at end of file
+#/
+
+; raw struct _type_header {
+ uint
+ _lib_index,
+ _type_index,
+
+ ~{}_type_header
+ _generic_list
+}
+
+; raw struct _method {
+ ~void
+ address
+}
+
+; raw struct _type {
+ ~{}int
+ _offsets,
+
+ ~{}uint
+ _super_offsets,
+
+ ~{}_type
+ _supers,
+
+ ~{}_method
+ _methods
+}
+
+/; method _type_header
+
+ /; _is (_type_header base)
+ ;/
+
+ /; _get_method ()
+ ;/
+;/ \ No newline at end of file
diff --git a/tnslc/src/compile/compile.tnsl b/tnslc/src/compile/compile.tnsl
index b3f4c5d..0fef36c 100644
--- a/tnslc/src/compile/compile.tnsl
+++ b/tnslc/src/compile/compile.tnsl
@@ -15,5 +15,8 @@
#/
/; export module compile
- :include "arch"
+ /: include
+ "arch"
+ "format"
+ :/
;/
diff --git a/tnslc/src/compile/format/elf.tnsl b/tnslc/src/compile/format/elf.tnsl
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tnslc/src/compile/format/elf.tnsl
diff --git a/tnslc/src/compile/format/format.tnsl b/tnslc/src/compile/format/format.tnsl
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tnslc/src/compile/format/format.tnsl
diff --git a/tnslc/src/compile/format/iex.tnsl b/tnslc/src/compile/format/iex.tnsl
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tnslc/src/compile/format/iex.tnsl
diff --git a/tnslc/src/compile/format/out.tnsl b/tnslc/src/compile/format/out.tnsl
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tnslc/src/compile/format/out.tnsl
diff --git a/tnslc/src/compile/format/pe.tnsl b/tnslc/src/compile/format/pe.tnsl
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tnslc/src/compile/format/pe.tnsl
diff --git a/tnslc/src/parse/parse.tnsl b/tnslc/src/parse/parse.tnsl
index dc6b9a2..e10ab4c 100644
--- a/tnslc/src/parse/parse.tnsl
+++ b/tnslc/src/parse/parse.tnsl
@@ -15,5 +15,8 @@
#/
/; export module parse
- :import 'token.tnsl'
+ /:import
+ "token.tnsl"
+ "tokenizer.tnsl"
+ :/
;/ \ No newline at end of file
diff --git a/tnslc/src/parse/token.tnsl b/tnslc/src/parse/token.tnsl
index 92b2ca4..a841f58 100644
--- a/tnslc/src/parse/token.tnsl
+++ b/tnslc/src/parse/token.tnsl
@@ -14,13 +14,27 @@
EXPRESS OR IMPLIED
#/
-;struct Token {
+/# The various types of tokens #/
+; enum TOKEN_TYPE [uint] {
+ LINESEP = 0,
+ INLNSEP = 1,
+ DELIMIT = 2,
+ AUGMENT = 3,
+ LITERAL = 4,
+ KEYTYPE = 5,
+ PREWORD = 6,
+ KEYWORD = 7,
+ DEFWORD = 8
+}
+
+/# Token struct definition #/
+;raw struct Token {
uint
type,
line,
char,
- ~{}char
+ ~{}charp
data
}
@@ -29,4 +43,245 @@
/; operator delete
;delete this.data
;/
+;/
+
+/#
+ Reserved words and characters, as well as
+ helper funcs for checking their token types.
+#/
+
+;const {}{}charp PREWORDS = {
+ "include",
+ "define",
+ "extern",
+ "size",
+ "align",
+ "address",
+ "rootfile",
+ "if",
+ "else",
+ "abi"
+}
+
+;const {}{}charp KEYTYPES = {
+ "bool",
+ "char",
+ "charp",
+
+ "int8",
+ "int16",
+ "int32",
+ "int64",
+ "int",
+ "uint8",
+ "uint16",
+ "uint32",
+ "uint64",
+ "uint",
+
+ "float32",
+ "float64",
+ "float",
+
+ "void",
+ "type"
+}
+
+;const {}{}charp KEYWORDS = {
+ "struct",
+ "interface",
+ "enum",
+ "is",
+ "extends",
+
+ "loop",
+ "continue",
+ "break",
+
+ "match",
+ "case",
+ "default",
+
+ "label",
+ "goto",
+
+ "if",
+ "else",
+
+ "const",
+ "static",
+ "volatile",
+
+ "method",
+ "override",
+ "self",
+ "super",
+ "operator",
+
+ "raw",
+ "asm",
+ "inline",
+
+ "delete",
+
+ "module",
+ "export",
+}
+
+;const {}{}charp LITERALS = {
+ "true",
+ "false"
+}
+
+;const {}charp DELIMITS = "()[]{}"
+;const {}charp LINESEPS = ";:#"
+;const {}charp INLNSEPS = ","
+;const {}charp AUGMENTS = "~`.&|^><!+-*/%"
+
+;const {}{}charp MDELIMITS = {
+ # Code block
+ "/;",
+ ";/",
+
+ # Comment block
+ "/#",
+ "#/",
+
+ # Preproc block
+ "/:",
+ ":/",
+
+ # Redef blocks
+ ";;",
+ "::",
+ ";#",
+ ":#",
+ "#;",
+ "#:"
+}
+
+;const {}{}charp MAUGMENTS = {
+ # Boolean
+ "==",
+ "&&",
+ "||",
+
+ # Bitwise shifts
+ "<<",
+ ">>",
+
+ # PREaugmented augmentors
+ "&=",
+ "|=",
+ "^=",
+ "+=",
+ "-=",
+ "*=",
+ "/=",
+ "%=",
+ "~=",
+ "`=",
+
+ # POSTaugmented augmentors
+ "!&",
+ "!|",
+ "!^",
+ "!==",
+ "!&&",
+ "!||",
+ "!>",
+ "!<",
+ ">==",
+ "<==",
+
+ # Increment and De-increment
+ "++",
+ "--"
+}
+
+; const uint MAX_MRESERVED = 3
+
+/##
+ Checks if the character point p is in the string cmp
+
+#; is_in_string (`const {}charp cmp, charp p) [bool]
+
+ /; for (int i = 0; i < len cmp) [i++]
+
+ /; if (s == cmp{i})
+ ;return true
+ ;/
+ ;/
+
+ ;return false
+;/
+
+
+/##
+ Checks if the string s is in the list cmp
+
+#; is_in_string_list (`const {}{}charp cmp, `{}charp s) [bool]
+
+ /; for (int i = 0; i < len cmp) [i++]
+
+ /; if (len s == len cmp{i})
+
+ /; for (int j = 0; j < len s) [j++]
+
+ /; if (s{j} !== cmp{i}{j})
+ ;goto cont_outer
+ ;/
+ ;/
+
+ ;return true
+ ;/
+
+ ;label cont_outer
+ ;/
+
+ ;return false
+;/
+
+/#
+ Get the token_type value for a given string of character points
+
+#; get_token_type (`{}charp s) [int]
+
+ /; if (len s > 1)
+
+ /; if (is_in_string_list(~PREWORDS, ~s))
+ ;return TOKEN_TYPE.PREWORD
+ ;; else if (is_in_string_list(~KEYTYPES, ~s))
+ ;return TOKEN_TYPE.KEYTYPE
+ ;; else if (is_in_string_list(~KEYWORDS, ~s))
+ ;return TOKEN_TYPE.KEYWORD
+ ;; else if (is_in_string_list(~LITERALS, ~s))
+ ;return TOKEN_TYPE.LITERAL
+ ;; else if (is_in_string_list(~MDELIMITS, ~s))
+ ;return TOKEN_TYPE.DELIMIT
+ ;; else if (is_in_string_list(~MAUGMENTS, ~s))
+ ;return TOKEN_TYPE.AUGMENT
+ ;/
+
+ ;return TOKEN_TYPE.DEFWORD
+
+ ;;else if (len s == 1)
+
+ /; if (is_in_string(~DELIMITS, s{0}))
+ ;return TOKEN_TYPE.DELIMIT
+ ;; else if (is_in_string(~LINESEPS, s{0}))
+ ;return TOKEN_TYPE.LINESEP
+ ;; else if (is_in_string(~INLNSEPS, s{0}))
+ ;return TOKEN_TYPE.INLNSEP
+ ;; else if (is_in_string(~AUGMENTS, s{0}))
+ ;return TOKEN_TYPE.AUGMENT
+ ;/
+
+ ;return TOKEN_TYPE.DEFWORD
+ ;/
+
+ # What, we just produce vacant tokens now?
+ # Something has gone wrong.
+
+ ;return -1
;/ \ No newline at end of file
diff --git a/tnslc/src/parse/tokenizer.tnsl b/tnslc/src/parse/tokenizer.tnsl
new file mode 100644
index 0000000..ec34d83
--- /dev/null
+++ b/tnslc/src/parse/tokenizer.tnsl
@@ -0,0 +1,25 @@
+/#
+ 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
+#/
+
+
+/##
+ parse.numeric_literal tokenizes the next numeric literal value in a file.
+ Returns a token with the proper data as well as the number of characters read
+
+#; numeric_literal () [Token, uint]
+
+
+;/ \ No newline at end of file