Aug 13, 2022Kuina-chan

1Kuin Types And Literals
Type | Description | Classification | Default Value | Example Of Literal |
---|---|---|---|---|
int | Integer Type | Value Type | 0 | 256 |
float | Floating-point Type | Value Type | 0.0 | 3.14159 |
char | Character Type | Value Type | '\0' | 'A' |
bool | Boolean Type | Value Type | false | true |
bit8 bit16 bit32 bit64 |
Bit Type | Value Type | 0b8 0b16 0b32 0b64 |
255b8 |
[] | Array | Reference Type | null | [1, 2, 3] "abc" |
list<> | List | Reference Type | null | |
stack<> | Stack | Reference Type | null | |
queue<> | Queue | Reference Type | null | |
dict<,> | Dictionary | Reference Type | null | |
func<()> | Function Type | Reference Type | null | funcName |
enum | Enumerated Type | Value Type | Element With A Value Of 0 | %elementName |
class | Class | Reference Type | null |
2Integer Type
- It is an 8-byte type that handles integers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
- The value will overflow if it exceeds the range it can handle.
Reason For The Design
Even if integer types of various sizes are provided, as in the C language, there are few cases where memory consumption needs to be trimmed down to that level, so for the sake of simplicity, Kuin focuses on one type of integer for normal use.
- A sequence of one or more numbers in "0123456789" is interpreted as a decimal integer and becomes an int literal.
- A "0x" followed by one or more of the numbers "0123456789ABCDEF" is interpreted as a hexadecimal integer. Lowercase letters are not allowed.
Reason For The Design
The reason why the hexadecimal number "ABCDEF" only allows uppercase letters is that lowercase alphabets are used for exponential notation and bit-type literals.
3Floating-point Type
- It is an 8-byte type that handles floating-point numbers with 15 to 16 significant digits, approximately
to
.
- The basic specifications follow IEEE 754.
- It can handle positive and negative infinity, and will go to positive or negative infinity if the value overflows.
- When the value needs to be rounded, it is rounded to the nearest zero.
- If you perform a mathematically undefined operation such as "0.0/0.0", the result will be "NaN".
- The result when NaN is used for the calculation is undefined.
Reason For The Design
As with int, Kuin uses only one floating point type for brevity.
- If there is only one "." between two or more numbers in "0123456789", it is interpreted as a decimal fraction and becomes a float literal.
- If this notation is followed by "e+" or "e-", and then "0123456789", it is considered to be exponential notation.
- When written as "inf", it is positive infinity.



4Character Type
- A 2-byte type that handles UTF-16 character codes from 0x0000 to 0xFFFF.
Reason For The Design
When considering surrogate pair characters, it would be more convenient to use UTF-32 with 4 bytes per character, but since the frequency of using surrogate pair characters is not high, I decided to use UTF-16, which is more compatible with Windows API and consumes less memory.
- The part enclosed by the two "'" is a literal of char.
- The literal cannot contain tab characters or line feeds without using escape sequences.
- The combination of "\" and any single character in a literal is interpreted as a special character as an escape sequence.
Symbols | Meaning |
---|---|
\\ | The "\" symbol. |
\" | The '"' symbol. |
\' | The "'" symbol. |
\0 | Character whose code is 0. |
\n | Newline character. |
\t | Tab character. |
\u???? | Character of the specified code. "????" is a 4-digit hexadecimal number in either numbers or uppercase letters. |
\{expression} | The result of an expression as a string. It can only be used within a []char literal. For example, when 3 is stored in the int variable n, the statement '"\{n+5}"' will be interpreted as '"8"'. This is equivalent to "(expression).toStr()". |
Reason For The Design
In Windows, newline codes are mainly expressed as "\r\n" (0x0d, 0x0a) in the C language escape sequence, but since "\r" is not necessary in some situations and is complicated, newlines in Kuin are always expressed as "\n" and internally converted to "\r\n" as appropriate.
5Boolean Type
- It is a 1-byte logical type that takes a value of "false" or "true".
- Only "false" and "true" are literals of type bool.
- "false" means false, "true" means true.
6Bit Type
- The bit8 type handles 8-bit integers (0x00 to 0xFF), the bit16 type handles 16-bit integers (0x0000 to 0xFFFF), the bit32 type handles 32-bit integers (0x00000000 to 0xFFFFFFFF), and the bit64 type handles 64-bit integers (0x0000000000000000 to 0xFFFFFFFFFFFFFFFF).
Reason For The Design
Since I designed the int type as an integer type that can be handled universally, I prepared these bit types separately as integer types for cases where I have to be aware of their representation in memory.
As the name implies, they can also handle bitwise operations, so we can use them differently from the int type depending on the situation.
- An int literal followed by one of "b8", "b16", "b32", or "b64" is a literal of type bit8, bit16, bit32, or bit64, respectively.
7Array
- Arrays are written as "[]type name". For example, it can be expressed as "[]int" or as an array of arrays as "[][]char".
- Strings in Kuin are handled as "[]char".
Reason For The Design
The reason why strings are made into an array of char instead of a dedicated type is that the various functions provided for arrays can also be used.
- The literal of the array should be "[value1, value2, ..., valuen]".
- The type of each value must be the same. Based on the type of the value, the type of the array literal is determined.
- Setting all values of an array literal to null is not allowed because the type of the array literal cannot be determined. If you want them all to be null, you need to explicitly cast one of them.
- In addition to these, the part enclosed in two '"' is a []char literal. The notation rules for []char literals are the same as for char literals.
8List
- A list is a data structure in which each element is connected by a pointer, and is expressed as "list<type name>". For example, it is written as "list<int>".
- While it can add, insert, and delete elements instantly compared to arrays, the process of accessing the nth element is slower.
- Lists are bi-directionally linked, so they can be traced in order from the beginning or in reverse order from the end.
9Stack
- A stack is expressed as "stack<type name>". For example, it is written as "stack<int>".
10Queue
- A queue is expressed as "queue<type name>". For example, it is written as "queue<int>".
11Dictionary
- A dictionary is expressed as "dict<type name of key, type name of value>". For example, it is written as "dict<[]char, int>".
- Because binary search is used to look up keys, dictionary searching is much faster than searching from the top in an array or list.
12Function Type
- A function type is expressed as "func<(type of argument 1, type of argument 2, ..., type of argument n): return type)>". For example, it is written as "func<(int, char): bool>".
- The value of a function type is the function itself, and can be called as a function.