From 22e923c9b9519a309d51f6f1029bd542800dad4c Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Mon, 9 Aug 2021 07:38:09 -0400 Subject: 5, 6, much of 4 + Finish much of ch 1 + Fix spelling in copyright notices --- spec/1 - language.md | 213 ++++++++++++++++++++++++++++++++++++++++++++++++++- spec/2 - features.md | 2 +- spec/3 - abi.md | 2 +- spec/4 - fip.md | 2 +- spec/Appendices.md | 36 ++++++++- spec/README.md | 2 +- 6 files changed, 247 insertions(+), 10 deletions(-) (limited to 'spec') diff --git a/spec/1 - language.md b/spec/1 - language.md index 73ebfb4..345eb1a 100644 --- a/spec/1 - language.md +++ b/spec/1 - language.md @@ -111,7 +111,7 @@ TNSL functions may have inputs (enclosed with `()`) and/or outputs (enclosed wit TNSL functions may have their call stack modified by the `raw` and/or `inline` keywords. If the `inline` keyword is placed around the function declaration, the function will still be exported (if it is being exported), but any time it is used in the project's code, it will be optimized as if in-line. -The use of the `raw` keyword has several effects: the function will have no generated assembly preamble, the function will not be optimized, and the function will allow `asm` statements. Any function may be labeled `raw`, even `main` and anonymous functions. +The use of the `raw` keyword has several effects: the function will have no generated assembly preamble, the function will allow `raw return` statements, the function will not be optimized, and the function will allow `asm` statements. Any function may be labeled `raw`, even `main` and anonymous functions. Examples: @@ -206,37 +206,244 @@ Examples: ## Section 4 - Types -### Built-in Types +An exhaustive list of built-in types can be found in Appendix B. ### The `void` Type +The `void` type represents one of two things: an unknown data type, or a function. When the void type is paired with input and output parameters `void( )[ ]` it represents a function. When it is not paired with these things it represents an unknown data type. + +Pure `void` types can not be created. Function types are *always* references to the function, more like pointers than data holders. Otherwise, void types must be created as pure pointers. In this case, they are in a sense "un-typed" pointers which do not know the length of the object they are pointing at, only the address. + +Examples: + + # simple function + /; func_1 + ;/ + + # void example func + /; func_2 + + # create a void type and assign it func_1's value + ;void()[] func_ref = func_1 + + # call func_1 using func_ref + ;func_ref() + ;/ + +More examples of pointer voids are available in the pointers section of this document. + ### Arrays +In memory, arrays store their length as a uint, then immediately follow with the contents of the array. This way, all arrays can be checked for length with the `len` operator. + +Arrays are created by prefixing a type with `{ <# of elements> }` or simply `{}` so long as the array is immediately initialized. One can similarly access an element of an array by suffixing the variable name with `{ }`. + +When initializing or assigning a new value to an entire array, use `{}` to encase a list of values. + +The length of the array can be gotten by `len ` + +Examples: + + # create an array of five integers + ;{5}int i + + # assign values to the array + ;i{0} = 0 + ;i{1} = 2 + ;i{2} = 0 + ;i{3} = 2 + ;i{4} = 1 + + # store the length of the array + ;uint array_length = len i + + # create an initialized array with length five + ;{}int j = {1, 2, 3, 4, 5} + + # loop through the array and add them. + /; loop (int k = 0; k < array_length) [k++] + + ;i{k} += j{k} + ;/ + + ### Pointers +Pointer types are created using the `~` (pointer to) operator. This operator serves as both part of the type, and as a way to get a pointer from a type. To de-reference a pointer into it's base type, use the `` ` `` (de-reference) operator. + +Passing by reference can be done by prefixing the type with the de-reference operator. This type is only available in function parameter declaration. To call a function with this type, a pointer to the desired variable must be given. + +Examples: + + # define int + ;int i + + # pointer to i + ;~int p = ~i + + # set i using p + ;`p = 1 + + # a function taking a pass by reference + /; add_two (`int i) + i += 2 + ;/ + + # calling add_two in two different ways + ;add_two(p) + ;add_two(~i) + + # i is now 5 + +### Casting Types + +Casting between types uses the standard input and output enclosing `()` and `[]` in conjunction. Place a value in the input enclosing characters and a type to output in the output enclosing characters to cast one type to another (`( )[ ]`). + +Examples: + + # define an int and a float + ;int i = 10 + ;float f = 11.5 + + # define a void pointer and set it to reference i + ;~void v = ~i + + # define an int pointer and cast the void pointer to initialize it + ;~int p = (v)[~int] + + # cast the float to an int and set the value of i + ;`p = (f)[int] + ### Defining Types + + ### Interfaces ### Type Levels ## Section 5 - Operators +An exhaustive list of operators can be found in Appendix A + ### Operator Precedence +Operator precedence is as follows (from greatest to least): + + Pointer operators (p0): + + ~ - address of + + ` - de-reference + + + Access operator (p1): + + . - get/access + + + Increment/de-increment (p2): + + ++ - increment + + -- - de-increment + + + Multiplication/division (p3): + + * - multiply + + / - divide + + + Addition and subtraction (p4): + + + - addition + + - - subtraction + + + Modulus (p5): + + % - modulus + + + Bitwise operators (p6): + + & - and + + | - nor + + ^ - xor + + << - shift left + + >> - shift right + + !& - nand + + !| - nor + + !^ - xand + + ! - not (bitwise or boolean) + + + Boolean operators (p7): + + && - boolean and + + || - boolean or + + == - boolean eq + + > - greater than + + < - less than + + !&& - boolean nand + + !|| - boolean nor + + !== - boolean neq + + !> - boolean not greater than + + !< - boolean not less than + + >== - boolean greater than or equal to + + <== - boolean less than or equal to + ## Section 6 - `raw` and `asm` ### The `raw` Keyword +The `raw` keyword can be used in three different scenarios, and each has a different meaning. + +1. The `raw` keyword can be used in function definitions. These effects were discussed in section 2.2. + +2. The `raw` keyword may be used in conjunction with the `return` keyword, but only inside of raw functions. This causes an instant return regardless of stack or register state. It is recommended to clean up function and provide return types before using this. + +3. The `raw` keyword may be used with the `struct` keyword to create a raw struct. Raw structs can not contain user defined types or generics. Raw types encode no type information and may not be extended. Raw structs, unlike static or dynamic structs, are only as wide their members. + - Static and dynamic structs contain a small amount of information pertaining to their actual type and generics so may be larger than only their members. + - In addition, since static and dynamic structs may be extended, they may not be the initially defined type and may be larger, further complicating matters. + ### The `asm` Keyword +The `asm` keyword may be used in `raw` functions or blocks to produce raw asm code for the assembler. Any valid assembly code may be used, and certain extensions are available such as variable pointer references. + +Syntax: + + ;asm "" + ## Credits 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 recieved a copy of the License with this + 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: diff --git a/spec/2 - features.md b/spec/2 - features.md index 4687f29..5d8d952 100644 --- a/spec/2 - features.md +++ b/spec/2 - features.md @@ -6,7 +6,7 @@ This file is licensed under the CDDL 1.0 (the License) and may only be used in accordance with the License. - You should have recieved a copy of the License with this + 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: diff --git a/spec/3 - abi.md b/spec/3 - abi.md index a83600a..5ea5c15 100644 --- a/spec/3 - abi.md +++ b/spec/3 - abi.md @@ -6,7 +6,7 @@ This file is licensed under the CDDL 1.0 (the License) and may only be used in accordance with the License. - You should have recieved a copy of the License with this + 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: diff --git a/spec/4 - fip.md b/spec/4 - fip.md index fc2e86b..db70987 100644 --- a/spec/4 - fip.md +++ b/spec/4 - fip.md @@ -14,7 +14,7 @@ To use higher level features in TNSL, an implimentation of libtnsl must be in pl This file is licensed under the CDDL 1.0 (the License) and may only be used in accordance with the License. - You should have recieved a copy of the License with this + 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: diff --git a/spec/Appendices.md b/spec/Appendices.md index 87f5f15..5049ad9 100644 --- a/spec/Appendices.md +++ b/spec/Appendices.md @@ -43,7 +43,7 @@ | - bitwise or - ^ - bitwise not + ^ - bitwise xor > - greater than @@ -144,13 +144,19 @@ <== - less than or equal to + ++ - increment + + -- - de-increment + ## Appendix B - Reserved words and their uses Built-in Types: bool - boolean - char - ascii + char - ascii/extended ascii 8-bit value + + charp - unicode 8-bit character part (using either UTF-8 or UN7+1) int8 - 8-bit integer @@ -191,6 +197,10 @@ false - boolean false value + size - size (in bytes) of a variable or type + + len - size (in elements) of an array + User defined types: @@ -277,21 +287,41 @@ In TNSL there exist three different levels of complexity structs can take on. I Raw structs are the simplist structs with the fastest lookup times. Raw structs can not be extended, though they may themselves extend interfaces (but not other structs). All members of raw structs must be built-in types, other raw structs, or pointers. Raw structs are always fixed-width and all methods are linked directly, thus there is no lookup time for calling one (they are essentially as fast as calling a regular function as long as you are referencing the struct directly and not by one of it's extended interfaces). +NOTE: Raw structs do not allow generics + ### Static structs Static structs are similar to raw structs except they may be extended. This creates a small delay for calling functions on static structs as there is a lookup time to find the method the call is actually referencing (as it may be calling the function on an extension of the type). All members of static structs must be built-in types, other raw structs, or pointers. Static structs can only extend static structs. +NOTE: Static structs *can* allow generics so long as they do not store said generics and only store pointers to them. + ### Dynamic structs Variable width structs (dynamic structs) can accomodate generics and variable width members. Dynamic structs may extend static structs or other dynamic structs. By extending a dynamic struct, even if one makes no use of the dynamic members, their struct is automatically a dynamic struct. These structs offer the least control over memory, and slightly slower call times, but offer the most flexability to the programmer. + +## Appendix D - UN7+1 + +Unicode Non-standard 7+1 bit (UN7+1) encoding is a non-standard way to represent any unicode character using a series of 8-bit values. The first bit in the 8-bit sequence represents if the next 8-bit sequence is included in the character code, the other seven bits are part of the character code. + +Examples: + + ASCII characters: + 0xxxxxxx (U+00 - U+7F) + + Unicode characters: + 1xxxxxxx 0xxxxxxx (U+0080 - U+3FFF) + 1xxxxxxx 1xxxxxxx 0xxxxxxx (U+004000 - U+1FFFFF) + 1xxxxxxx 1xxxxxxx 1xxxxxxx 0xxxxxxx (U+0200000 - U+FFFFFFF) + etc. + ## Credits 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 recieved a copy of the License with this + 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: diff --git a/spec/README.md b/spec/README.md index 83a6375..1dc82aa 100644 --- a/spec/README.md +++ b/spec/README.md @@ -50,7 +50,7 @@ Right now, TNSL isn't a language. But it *could* be. And, really, I think it's This file is licensed under the CDDL 1.0 (the License) and may only be used in accordance with the License. - You should have recieved a copy of the License with this + 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: -- cgit v1.2.3