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 between 10 and 20.

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 between 0 and 100.

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 or int64_t are supported: -9223372036854775808 to 9223372036854775807 for signed integer, and 0 to 18446744073709551615 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 for Int{0:255}

  • Sint8 for Int{-127:127}

  • Uint16 for Int{0:65535}

  • Sint16 for Int{-32767:32767}

  • Uint32 for Int{0:4294967295}

  • Sint32 for Int{-2147483647:2147483647}

  • Uint64 for Int{0:18446744073709551615}

  • Sint64 for Int{-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

Infinitely Long Integer

planned - not supported yet in TL5

class Long

A signed integer that can be infinitely long (practically limited by the system memory). Automatically allocates heap memory to store the number. Is dramatically less efficient that a normal integer.

Boolean

class Bool

A boolean value that can only be a true or a false 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 \\.

Byte

class Byte

A single memory byte value.

Byte is treated as Int{255}.

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

class Func(arguments)

Holds (pointer to) a function.

Parameters

arguments – the function input and output arguments

For example: Func{()}, Func{(copy Uint32 in)}, Func{()->(var Uint32 out)} , Func{(copy Uint32 in)->(var Uint32 out)}.

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: just Array{Uint32} or Array{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

class Buffer(length)

Alias for an Array with Byte items.

Parameters

length – length of the buffer and the actual allocation size

For example: Buffer{5}, Buffer{256}.

Buffer literals are hexadecimal strings surrounded by ` characters: `4a0069ff3487beef2649`.

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 to value

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 string length if pattern 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 mode

file 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 mode

file 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 mode

if append is true:

file is created if it does not exist

all writes will be appended to the file end

create is ignored

else, 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 mode

if append is true:

file is created if it does not exist

all writes will be appended to the file end

create is ignored

else, 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 and FileReadWriteText

read one character from this file into value or set is-eof to true if end-of-file reached

Raises

if read failed

get()->(var Byte value, var Bool is-eof)

only available in FileReadBinary and FileReadWriteBinary

read one byte from this file into value or set is-eof to true if end-of-file reached

Raises

if read failed

getline()->(user String line, var Bool is-eof)

only available in FileReadText and FileReadWriteText

read one line from this file into line or set is-eof to true if end-of-file reached

new-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 and FileReadWriteBinary

read bytes from file to data up to the its length, set in bytes-read the number of actual read bytes

Raises

if read failed

put(copy Char value)

only available in FileWriteText and FileReadWriteText

write value character to this file

Raises

if writing failed

put(copy Byte value)

only available in FileWriteBinary and FileReadWriteBinary

write value byte to this file

Raises

if writing failed

write(user Array{Char} data)->(var Uint32 written)

only available in FileWriteText and FileReadWriteText

try write all data characters to this file, set in written the number of actual written characters

Raises

if writing failed

write(user Array{Byte} data)->(var Uint32 written)

only available in FileWriteBinary and FileReadWriteBinary

try write all data bytes to this file, set in written 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 calling sys.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 set is-eof to true if end-of-file reached, same as calling sys.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 set is-eof to true if end-of-file reached, same as calling sys.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 value

calls 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 command

calls 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 variable name, or set exists to false if it does not exist