Built-in Types¶
Integer¶
- class Int(minimum-value, maximum-value)¶
- Parameters
minimum-value – (optional) the minimum legal value (inclusive), default is
0maximum-value – the maximum legal value (inclusive)
An integer that can only hold a range of values between its minimum and maximum (inclusive), enforced by the compiler. Obviously “minimum-value” should be equal or smaller than “maximum-value”.
For example:
Int{10:20}can only hold numbers between10and20.If only one parameter is given it is treated as the maximum and the minimum is automatically
0.For example:
Int{100}can only hold numbers between0and100.If the minimum is negative the integer is consider “signed”, else it is “unsigned”.
The actual representation of an integer in the memory is the minimal possible from 8,16,32,64 bits based on the limits. This mean that only ranges that fit in
uint64_torint64_tare supported:-9223372036854775808to9223372036854775807for signed integer, and0to18446744073709551615for unsigned.The default value of an uninitialized integer is
0if it is within its legal range, otherwise the integer must be manually initialized.- Aliases for common ranges:
Uint8forInt{0:255}Sint8forInt{-127:127}Uint16forInt{0:65535}Sint16forInt{-32767:32767}Uint32forInt{0:4294967295}Sint32forInt{-2147483647:2147483647}Uint64forInt{0:18446744073709551615}Sint64forInt{-9223372036854775807:9223372036854775807}
- Supported integer literals:
decimal:
70695binary:
0b100101octal:
0175hexadecimal:
0xa30eb9f6negative integer:
-before any positive integer literal:-23
A complete guide to integer range management is in Integer Ranges and Overflow Prevention.
- str(user String text)¶
write into
textthe integer converted to string in decimal- Raises
if
textis too short to store the number
Boolean¶
- class Bool¶
A boolean value that can only be a
trueor afalseconstant.
Constants:
- Bool true
- Bool false
Character¶
- class Char¶
A single Unicode code-point, which is the same as
Int{1114111}.Character literal are surrounded with
'characters:'a'. Special characters can be written with\escape character as in C:\' \" \? \a \b \f \n \r \t \v \\.
Real Number¶
planned - not supported yet in TL5
- class Real¶
Floating point real number, same as
floatin C.Real number literal is a decimal number with
.character in the middle, with optional exponential suffix:2.4,-0.3,4.0,2.34e2,-5.678e-12.
Function¶
Array¶
- class Array(length, subtype)¶
Sequence of any typed item with static length.
- Parameters
length – array static length and the actual allocation size
subtype – the type of each item in the array
For example:
Array{12:Uint32},Array{6:String{16}}.Array references should be declared without the
lengthparameter: justArray{Uint32}orArray{String}for example.Accessing a single item can be done using
array[index].Note
If the index can be out of range it is checked at run-time and an error may raise. In such case the
!warning sign must be used if error is to be propagated:array[index]!.It is possible to extract a sub-array from an array by slicing:
array[start-index:sub-array-length]. This will not copy the array but return an array reference that points to the original array.- length()->(var Uint32 length)¶
return (static) length of the array
Buffer¶
String¶
- class String¶
Holds a legal UTF-8 string with dynamic length. The compiler ensures that the last character is a null-terminator (
'\0').String literals are strings surrounded by
"characters:"I am a string literal". Escape characters can be used.String literals may contain line breaks, with additional indentation of exactly 8 spaces. It is treated as
\n, or ignored if\is used before it:; the same as "line\nbrake" s := "line break" ; the same as "linebrake" s := "line\ break"
String is currently not implicitly converted to
Array{Byte}when needed.- length()->(var Uint32 length)¶
returns current (dynamic) string length, not counting the null-terminator
- new(user Buffer value)¶
initialize this string with a copy of
value- Raises
if not enough memory
- clear()¶
make this string empty
- equal(user Buffer other)->(var Bool is-equal)¶
return whether this string is exactly equal to
other
- get(copy Uint32 index)->(var Char value)¶
return character at place
index- Raises
if
indexis out of range
- set(copy Uint32 index, copy Char value)¶
set character at place
indextovalue- Raises
if
indexis out of range
- append(copy Char character)¶
append
characterto this string end- Raises
if has no room for another character
- concat(user Buffer other)¶
concatenate
otherto this string end- Raises
if has no room for
other
- concat-int(copy Sint64 number)
covert
numberto string and concatenate it to this string end- Raises
if has no room for
numberstring
- find(user Buffer pattern)->(copy Uint32 index)¶
return index of first occurrence of
patternin this string, return this stringlengthifpatternnot found
- has(copy Char character)->(var Bool has)¶
return whether this string contains
character
Files¶
- class File¶
Basic type for managing files, is extended by these types:
FileReadTextFileReadBinaryFileWriteTextFileWriteBinaryFileReadWriteTextFileReadWriteBinary
- FileReadText(user String file-name)¶
open
file-namefor read only in textual mode- Raises
if file opening failed
- FileReadBinary(user String file-name)¶
open
file-namefor read only in binary mode- Raises
if file opening failed
- FileWriteText(user String file-name, copy Bool append)¶
open
file-namefor write only in textual modefile is created if it does not exist
if
appendis true all writes will be appended to the file end- Raises
if file opening failed
- FileWriteBinary(user String file-name, copy Bool append)¶
open
file-namefor write only in binary modefile is created if it does not exist
if
appendis true all writes will be appended to the file end- Raises
if file opening failed
- FileReadWriteText(user String file-name, copy Bool append, copy Bool create)¶
open
file-namefor read and write in textual modeif
appendis true:file is created if it does not exist
all writes will be appended to the file end
createis ignoredelse, if
createis true file is cleared of data if exists, or created if it does not exist- Raises
if file opening failed
- FileReadWriteBinary(user String file-name, copy Bool append, copy Bool exist)¶
open
file-namefor read and write in binary modeif
appendis true:file is created if it does not exist
all writes will be appended to the file end
createis ignoredelse, if
createis true file is cleared of data if exists, or created if it does not exist- Raises
if file opening failed
- close()¶
close this file, does nothing if this file is already closed
- Raises
if closing failed
- tell()->(var Sint64 offset)¶
return current position of the file
- Raises
if getting offset failed
- seek-set(var Sint64 offset)
set file position to
offsetrelative to file start- Raises
if setting offset failed
- seek-cur(var Sint64 offset)
set file position to
offsetrelative to the current position- Raises
if setting offset failed
- seek-end(var Sint64 offset)
set file position to
offsetrelative to file end- Raises
if setting offset failed
- flush()¶
flush any buffered written data to the file
- Raises
if flush failed
- get()->(var Char value, var Bool is-eof)¶
only available in
FileReadTextandFileReadWriteTextread one character from this file into
valueor setis-eoftotrueif end-of-file reached- Raises
if read failed
- get()->(var Byte value, var Bool is-eof)
only available in
FileReadBinaryandFileReadWriteBinaryread one byte from this file into
valueor setis-eoftotrueif end-of-file reached- Raises
if read failed
- getline()->(user String line, var Bool is-eof)¶
only available in
FileReadTextandFileReadWriteTextread one line from this file into
lineor setis-eoftotrueif end-of-file reachednew-line character is not added to
lineend- Raises
if read failed or
lineis too short to store the line
- read(user Array{Byte} data)->(var Uint32 bytes-read)¶
only available in
FileReadBinaryandFileReadWriteBinaryread bytes from file to
dataup to the its length, set inbytes-readthe number of actual read bytes- Raises
if read failed
- put(copy Char value)¶
only available in
FileWriteTextandFileReadWriteTextwrite
valuecharacter to this file- Raises
if writing failed
- put(copy Byte value)
only available in
FileWriteBinaryandFileReadWriteBinarywrite
valuebyte to this file- Raises
if writing failed
- write(user Array{Char} data)->(var Uint32 written)¶
only available in
FileWriteTextandFileReadWriteTexttry write all
datacharacters to this file, set inwrittenthe number of actual written characters- Raises
if writing failed
- write(user Array{Byte} data)->(var Uint32 written)
only available in
FileWriteBinaryandFileReadWriteBinarytry write all
databytes to this file, set inwrittenthe number of actual written bytes- Raises
if writing failed
sys Module¶
- Array{String} sys.argv
holds program arguments
- FileReadText sys.stdin
can be used to read from the standard input stream
- FileWriteText sys.stdout
can be used to write to the standard output stream
- FileWriteText sys.stderr
can be used to write to the standard error stream
- sys.print(user String text)¶
print
textto the standard output stream, same as callingsys.stdout.write- Raises
if writing failed
- sys.println(user String text)¶
print
textappended with new-line character to the standard output stream- Raises
if writing failed
- sys.getchar()->(var Char character, var Bool is-eof)¶
read one character from the standard input stream into
valueor setis-eoftotrueif end-of-file reached, same as callingsys.stdin.get- Raises
if read failed
- sys.getline(user String line)->(var Bool is-eof)¶
read one line from the standard input stream into
lineor setis-eoftotrueif end-of-file reached, same as callingsys.stdin.getlinenew-line character is not added to
lineend- Raises
if read failed or
lineis too short to store the line
- sys.exit(copy Sint32 status)¶
terminates execution of the program immediately with
statusas the exit status valuecalls C
exitfunction- Raises
if exiting failed
- sys.system(user String command)->(var Sint32 status)¶
execute
commandby the host command processor and return the return status of the commandcalls C
systemfunction- Raises
if command fails to execute
- sys.getenv(user String name, user String value)->(var Bool exists)¶
set into
valuethe value of the environment variablename, or setexiststofalseif it does not exist