summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libtnsl/README.md2
-rw-r--r--libtnsl/src/algo/algo.tnsl (renamed from libtnsl/src/alg/alg.tnsl)8
-rw-r--r--libtnsl/src/algo/math/math.tnsl (renamed from libtnsl/src/alg/math/math.tnsl)8
-rw-r--r--libtnsl/src/libtnsl.tnsl10
-rw-r--r--libtnsl/src/reflect/type.tnsl54
-rw-r--r--spec/4 - fip.md34
-rw-r--r--spec/Appendices.md10
-rw-r--r--tnslc/src/parse/token.tnsl18
-rw-r--r--tnslc/src/parse/tokenizer.tnsl17
9 files changed, 136 insertions, 25 deletions
diff --git a/libtnsl/README.md b/libtnsl/README.md
index 7fb8922..4206136 100644
--- a/libtnsl/README.md
+++ b/libtnsl/README.md
@@ -16,7 +16,7 @@ More information on these features can be found in the specification under libts
## Provided Sub-modules
libtnsl provides the tnsl base module and the following sub-modules to address each feature:
-* alg
+* algo
* Algorithms. Also contains the math sub-module for basic math operations.
* box
* Data containers (vector, map, etc.)
diff --git a/libtnsl/src/alg/alg.tnsl b/libtnsl/src/algo/algo.tnsl
index d346464..7ddd677 100644
--- a/libtnsl/src/alg/alg.tnsl
+++ b/libtnsl/src/algo/algo.tnsl
@@ -17,4 +17,10 @@
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
+#/
+
+/; export module algo
+ /: include
+ "math"
+ :/
+;/ \ No newline at end of file
diff --git a/libtnsl/src/alg/math/math.tnsl b/libtnsl/src/algo/math/math.tnsl
index d346464..5676d09 100644
--- a/libtnsl/src/alg/math/math.tnsl
+++ b/libtnsl/src/algo/math/math.tnsl
@@ -17,4 +17,10 @@
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
+#/
+
+/; export module math
+ /; include
+
+ ;/
+;/ \ No newline at end of file
diff --git a/libtnsl/src/libtnsl.tnsl b/libtnsl/src/libtnsl.tnsl
index 266c1fa..434e7a4 100644
--- a/libtnsl/src/libtnsl.tnsl
+++ b/libtnsl/src/libtnsl.tnsl
@@ -20,5 +20,11 @@
#/
/;export module tnsl
-
-;/
+ /: import
+ "algo"
+ "box"
+ "io"
+ "reflect"
+ "time"
+ :/
+;/ \ No newline at end of file
diff --git a/libtnsl/src/reflect/type.tnsl b/libtnsl/src/reflect/type.tnsl
index 2ed0016..b36dfc5 100644
--- a/libtnsl/src/reflect/type.tnsl
+++ b/libtnsl/src/reflect/type.tnsl
@@ -19,25 +19,63 @@
EXPRESS OR IMPLIED
#/
-; raw struct _type_header {
- uint
+/## tnsl.reflect._type
+ Header data which prefixes all non-raw structs.
+ Upper limits for classes and libs defined here:
+ - Max 2^32 libraries
+ - Max 2^16 classes per library
+ - Max 2^8 Generics per class
+#/
+; raw struct _type(uint8 N) {
+ uint32
_lib_index,
+ uint16
_type_index,
- ~{}_type_header
+ {N}_type
_generic_list
}
-; raw struct _method {
+/## tnsl.reflect._method
+ Metadata for methods (can be decoded from library
+ symbol tables). Limits for methods defined here:
+ - Max 2^8 inputs
+ - Max 2^8 outputs
+#/
+; raw struct _method(uint8 I, O) {
+ ~{}charp
+ name,
+
+ {I}_type
+ inputs,
+ {O}_type
+ outputs,
+
~void
address
}
-; raw struct _type {
- ~{}int
- _offsets,
+/## tnsl.reflect._member
+ Metadata about struct members
+#/
+; raw struct _member {
+ ~{}charp
+ name,
+
+ uint
+ offset,
+
+ _type
+ _member_type
+}
+/## tnsl.reflect._type_addresses
+ Metadata about where things are stored
+ in a class
+#/
+; raw struct _type_addresses {
~{}uint
+ _offsets,
_super_offsets,
~{}_type
@@ -47,7 +85,7 @@
_methods
}
-/; method _type_header
+/; method _type
/; _is (_type_header base)
;/
diff --git a/spec/4 - fip.md b/spec/4 - fip.md
index db70987..dee037c 100644
--- a/spec/4 - fip.md
+++ b/spec/4 - fip.md
@@ -6,6 +6,40 @@ To use higher level features in TNSL, an implimentation of libtnsl must be in pl
## Section 2 - libtnsl and Types
+`libtnsl` has the authority to define how types are stored in memory (to some extent) and how method resolution works on static and dynamic structs. `libtnsl` *must* provide certain methods for some language features to be available. These functions, and their uses are now listed, but a comprehensive list of language keywords can be found in Appendix B.
+
+### 2.1 - The libtnsl Type Extension
+
+`tnsl.reflect._type` *must* be defined as a raw struct which contains minimum information for type identification. This information is stored with every static or dynamic struct so that programs can reflect type information.
+
+`tnsl.reflect._member` *must* be defined as a raw struct which contains minimum information for member variable identification within a type. The information need not be stored with every member variable, but should be stored somewhere such that the `tnsl.reflect._get` method can make use of it.
+
+`tnsl.reflect._method` *must* be defined as a raw struct which contains minimum information for method identification within a type. The information need not be stored with every member function, but should be stored somewhere such that the `tnsl.reflect._call` method can make use of it.
+
+`tnsl.reflect._is` *must* be defined as a function taking two parameters of type `tnsl.reflect._type` and returning a single `bool` as output. This function is called when the `is` operator is envoked.
+
+`tnsl.reflect._get` *must* be defined as a function taking three parameters. The first parameter will be of type `tnsl.reflect._type`, the second parameter will be of type `~void`, and the third parameter will be of type `tnsl.reflect._member`. The function will return a single `~void` as output.
+
+In the parameters, the first relates to the type of the struct given, or at least how the callee views the struct. The second is a pointer to the struct itself. The third is the requested member to get. The `~void` returned must point to the requested value.
+
+`tnsl.reflect._call` *must* be defined as a function taking four parameters. The first parameter will be of type `tnsl.reflect._type`, the second parameter will be of type `~void`, the third parameter will be of type `tnsl.reflect._method`, and the fourth parameter will be of type `~void`. The function will return a single `~void` as output.
+
+In the parameters, the first relates to the type of the struct given, or at least how the callee views the struct. The second is a pointer to the struct itself. The third is the requested method to call. The fourth is a pointer to the parameters for the method. The `~void` returned must point to the return value of the method.
+
+### 2.2 - Memory allocation and de-allocation
+
+`tnsl.algo._alloc` *must* be defined as a function taking a single parameter of type `uint` as the number of bytes to allocate and returning a single `~void` as the pointer to the allocated memory. The memory must be allocated from the heap.
+
+`tnsl.algo._salloc` *should* be defined as a function taking a single parameter of type `uint` as the number of bytes to allocate and returning a single `~void` as the pointer to the allocated memory. The memory must be allocated from the stack.
+
+`tnsl.algo._dealloc` *must* be defined as a function taking a single parameter of type `~void` as the pointer to a chunk of allocated memory. The function should deallocate the memory.
+
+### 2.3 - Extra Types Extension
+
+`tnsl.box._vect` *must* be a raw struct which vector or simd instructions can be preformed on.
+
+`tnsl.box._string` *must* be a raw struct which stores a string of text. This text may be ASCII or Unicode, but reguardless must be stored as `charp` values internally.
+
## Section 3 - Cross calling C
### Credits
diff --git a/spec/Appendices.md b/spec/Appendices.md
index c3e0426..1caccc7 100644
--- a/spec/Appendices.md
+++ b/spec/Appendices.md
@@ -186,9 +186,9 @@
void - void type
- type - meta type (tnsl.reflect.type)
+ type* - meta type (tnsl.reflect._type)
- vect* - libtnsl tnsl.vector.vector type
+ vect* - (tnsl.box._vect) type
Values:
@@ -261,7 +261,7 @@
operator - define a method for when a reserved opertaor is used on a user defined struct
- super - can reference the method of an extended type or interface
+ super* - can reference the method of an extended type or interface
Modules:
@@ -273,9 +273,9 @@
Memory control:
- alloc* (and related) - allocate (or reallocate) memory from somewhere (tnsl.alg._alloc)
+ alloc* (and related) - allocate (or reallocate) memory from somewhere (tnsl.algo._alloc)
- delete* - free allocated memory (tnsl.alg._delete)
+ dealloc* - free allocated memory (tnsl.algo._dealloc)
\* keyword requires a libtnsl implimentation
diff --git a/tnslc/src/parse/token.tnsl b/tnslc/src/parse/token.tnsl
index a841f58..cbbb31f 100644
--- a/tnslc/src/parse/token.tnsl
+++ b/tnslc/src/parse/token.tnsl
@@ -30,9 +30,9 @@
/# Token struct definition #/
;raw struct Token {
uint
- type,
+ token_type,
line,
- char,
+ col,
~{}charp
data
@@ -43,6 +43,14 @@
/; operator delete
;delete this.data
;/
+
+ /; add_char (`{}charp part)
+ ;uint l = len `this.data
+ ;realloc this.data, l + len part
+ /;loop (uint i = 0; i < len part) [i++]
+ `this.data{l + i} = part{i}
+ ;/
+ ;/
;/
/#
@@ -206,7 +214,7 @@
#; is_in_string (`const {}charp cmp, charp p) [bool]
- /; for (int i = 0; i < len cmp) [i++]
+ /; loop (int i = 0; i < len cmp) [i++]
/; if (s == cmp{i})
;return true
@@ -222,11 +230,11 @@
#; is_in_string_list (`const {}{}charp cmp, `{}charp s) [bool]
- /; for (int i = 0; i < len cmp) [i++]
+ /; loop (int i = 0; i < len cmp) [i++]
/; if (len s == len cmp{i})
- /; for (int j = 0; j < len s) [j++]
+ /; loop (int j = 0; j < len s) [j++]
/; if (s{j} !== cmp{i}{j})
;goto cont_outer
diff --git a/tnslc/src/parse/tokenizer.tnsl b/tnslc/src/parse/tokenizer.tnsl
index ec34d83..4e5eeb7 100644
--- a/tnslc/src/parse/tokenizer.tnsl
+++ b/tnslc/src/parse/tokenizer.tnsl
@@ -14,12 +14,25 @@
EXPRESS OR IMPLIED
#/
+:using 'tnsl'
/##
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]
+#; numeric_literal (io.text_stream fstream) [Token, uint]
+ ;Token out = {token_type: TOKEN_TYPE.LITERAL}
+ ;uint counter = 0
-
+ ;bool l, d, run = false, false, true
+ ;~{}charp num
+
+ ;num, run = fstream.read_number()
+
+ /; loop (run) [num, run = fstream.read_number()]
+ ;out.add_data(num)
+ ;delete num
+ ;/
+
+ ;return out, counter
;/ \ No newline at end of file