Built-in Types¶
Integer¶
- class Int(minimum-value, maximum-value)¶
- Parameters
minimum-value – (optional) the minimum legal value (inclusive), default is
0
maximum-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 between10
and20
.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 between0
and100
.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_t
orint64_t
are supported:-9223372036854775808
to9223372036854775807
for signed integer, and0
to18446744073709551615
for unsigned.The default value of an uninitialized integer is
0
if it is within its legal range, otherwise the integer must be manually initialized.- Aliases for common ranges:
Uint8
forInt{0:255}
Sint8
forInt{-127:127}
Uint16
forInt{0:65535}
Sint16
forInt{-32767:32767}
Uint32
forInt{0:4294967295}
Sint32
forInt{-2147483647:2147483647}
Uint64
forInt{0:18446744073709551615}
Sint64
forInt{-9223372036854775807:9223372036854775807}
- Supported integer literals:
decimal:
70695
binary:
0b100101
octal:
0175
hexadecimal:
0xa30eb9f6
negative 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
text
the integer converted to string in decimal- Raises
if
text
is too short to store the number
Boolean¶
- class Bool¶
A boolean value that can only be a
true
or afalse
constant.
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
float
in 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
length
parameter: 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
index
is out of range
- set(copy Uint32 index, copy Char value)¶
set character at place
index
tovalue
- Raises
if
index
is out of range
- append(copy Char character)¶
append
character
to this string end- Raises
if has no room for another character
- concat(user Buffer other)¶
concatenate
other
to this string end- Raises
if has no room for
other
- concat-int(copy Sint64 number)
covert
number
to string and concatenate it to this string end- Raises
if has no room for
number
string
- find(user Buffer pattern)->(copy Uint32 index)¶
return index of first occurrence of
pattern
in this string, return this stringlength
ifpattern
not 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:
FileReadText
FileReadBinary
FileWriteText
FileWriteBinary
FileReadWriteText
FileReadWriteBinary
- FileReadText(user String file-name)¶
open
file-name
for read only in textual mode- Raises
if file opening failed
- FileReadBinary(user String file-name)¶
open
file-name
for read only in binary mode- Raises
if file opening failed
- FileWriteText(user String file-name, copy Bool append)¶
open
file-name
for write only in textual modefile is created if it does not exist
if
append
is 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-name
for write only in binary modefile is created if it does not exist
if
append
is 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-name
for read and write in textual modeif
append
is true:file is created if it does not exist
all writes will be appended to the file end
create
is ignoredelse, if
create
is 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-name
for read and write in binary modeif
append
is true:file is created if it does not exist
all writes will be appended to the file end
create
is ignoredelse, if
create
is 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
offset
relative to file start- Raises
if setting offset failed
- seek-cur(var Sint64 offset)
set file position to
offset
relative to the current position- Raises
if setting offset failed
- seek-end(var Sint64 offset)
set file position to
offset
relative 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
FileReadText
andFileReadWriteText
read one character from this file into
value
or setis-eof
totrue
if end-of-file reached- Raises
if read failed
- get()->(var Byte value, var Bool is-eof)
only available in
FileReadBinary
andFileReadWriteBinary
read one byte from this file into
value
or setis-eof
totrue
if end-of-file reached- Raises
if read failed
- getline()->(user String line, var Bool is-eof)¶
only available in
FileReadText
andFileReadWriteText
read one line from this file into
line
or setis-eof
totrue
if end-of-file reachednew-line character is not added to
line
end- Raises
if read failed or
line
is too short to store the line
- read(user Array{Byte} data)->(var Uint32 bytes-read)¶
only available in
FileReadBinary
andFileReadWriteBinary
read bytes from file to
data
up to the its length, set inbytes-read
the number of actual read bytes- Raises
if read failed
- put(copy Char value)¶
only available in
FileWriteText
andFileReadWriteText
write
value
character to this file- Raises
if writing failed
- put(copy Byte value)
only available in
FileWriteBinary
andFileReadWriteBinary
write
value
byte to this file- Raises
if writing failed
- write(user Array{Char} data)->(var Uint32 written)¶
only available in
FileWriteText
andFileReadWriteText
try write all
data
characters to this file, set inwritten
the number of actual written characters- Raises
if writing failed
- write(user Array{Byte} data)->(var Uint32 written)
only available in
FileWriteBinary
andFileReadWriteBinary
try write all
data
bytes to this file, set inwritten
the 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
text
to the standard output stream, same as callingsys.stdout.write
- Raises
if writing failed
- sys.println(user String text)¶
print
text
appended 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
value
or setis-eof
totrue
if 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
line
or setis-eof
totrue
if end-of-file reached, same as callingsys.stdin.getline
new-line character is not added to
line
end- Raises
if read failed or
line
is too short to store the line
- sys.exit(copy Sint32 status)¶
terminates execution of the program immediately with
status
as the exit status valuecalls C
exit
function- Raises
if exiting failed
- sys.system(user String command)->(var Sint32 status)¶
execute
command
by the host command processor and return the return status of the commandcalls C
system
function- Raises
if command fails to execute
- sys.getenv(user String name, user String value)->(var Bool exists)¶
set into
value
the value of the environment variablename
, or setexists
tofalse
if it does not exist