Library utils

This is exported from the core library, which means you don't need to import it.

Contains various utility functions.

Classes

Simplistic profiler based on bytecode invocation counts.

Globals

Deprecated. Use system.BITS-PER-BYTE instead.

Deprecated. Use system.BITS-PER-WORD instead.

Deprecated. Use system.BYTES-PER-WORD instead.

The number of bytes per kilobyte.

Deprecated: Use system.LINE-TERMINATOR instead.

The number of bytes per megabyte.

Deprecated: Use system.PLATFORM-FREERTOS instead.

Deprecated: Use system.PLATFORM-LINUX instead.

Deprecated: Use system.PLATFORM-MACOS instead.

Deprecated: Use system.PLATFORM-WINDOWS instead.

Deprecated: Use system.STATS-INDEX-ALLOCATED-MEMORY instead.

Deprecated: Use system.STATS-INDEX-BYTES-ALLOCATED-IN-OBJECT-HEAP instead.

Deprecated: Use system.STATS-INDEX-FULL-COMPACTING-GC-COUNT instead.

Deprecated: Use system.STATS-INDEX-FULL-GC-COUNT instead.

Deprecated: Use system.STATS-INDEX-GC-COUNT instead.

Deprecated: Use system.STATS-INDEX-GROUP-ID instead.

Deprecated: Use system.STATS-INDEX-PROCESS-ID instead.

Deprecated: Use system.STATS-INDEX-PROCESS-MESSAGE-COUNT instead.

Deprecated: Use system.STATS-INDEX-RESERVED-MEMORY instead.

Deprecated: Use system.STATS-INDEX-SYSTEM-FREE-MEMORY instead.

Deprecated: Use system.STATS-INDEX-SYSTEM-LARGEST-FREE instead.

Functions

Returns information about who build this application snapshot.
Deprecated. Use system.app-sdk-info instead.

Returns the Toit SDK version that generated this application snapshot.
Deprecated. Use system.app-sdk-version instead.

Returns the number of initial zeros in binary representation of the argument.
The argument is treated as an unsigned 64 bit number. Thus it returns 0 if given a negative input.
Deprecated. Use int.count-leading-zeros instead.

Creates an off-heap byte array with the given size.
Off-heap byte arrays are preferred when transferring data between applications.

critical-do --respect-deadline/bool=true [block] -> none
Enters and calls the given critical block.
Within block, the current task won't be interrupted by cancellation exceptions. Instead such exceptions will be delayed until the block is left. The critical block can be interrupted by a timeout (see with-timeout) if respect-deadline is true.

exit status/int -> none
Exits the VM with the given status.
Argument $status
0 signals a successful exit. All other statuses are error codes.

Deprecated: Use system.gc-count instead.

hex-char-to-value char/int [--on-error] -> int
Deprecated. Use hex-char-to-value char [--if-error] instead.

hex-char-to-value char/int [--if-error] -> int
Converts a hex digit character char in the ranges '0'-'9', 'a'-'f', or 'A'-'F'.
Returns the value between 0 and 15.
Calls the block if-error on invalid input and returns its return value if any.

Converts a hex digit character in the ranges '0'-'9', 'a'-'f', or 'A'-'F'.
Returns the value between 0 and 15.
The input must be a valid hex digit character.

hex-digit char/int [error-block] -> int
Deprecated. Use hex-char-to-value instead.

hex-digit char/int -> int
Deprecated. Use hex-char-to-value instead.

identical x/any y/any -> bool
Whether x and y are identical objects.
Every object is identical to itself.
For numbers, two objects are furthermore identical if they have the same numeric value. Contrary to == two numbers must be of the same type, and have the same bit-pattern. As such, -0.0 == 0.0, but not identical -0.0 0.0.
Two strings are identical if they contain the same characters. For example, we have identical "tw" + "in" "twin".
For floats, two NaN's (not-a-number) are identical when they have the same bits. For example, we have identical float.NAN float.NAN, but not identical float.NAN (float.from-bits float.NAN.bits + 1). This is unlike == where NaN's are never equal, so float.NAN == float.NAN is always false.

Returns the max of a and b.
Returns a if a and b are equal.
Returns float.NAN if either is float.NAN.
Returns the greater element, according to Comparable.compare-to, otherwise.

Returns the min of a and b.
Returns a if a and b are equal.
Returns float.NAN if either is float.NAN.
Returns the smaller element, according to Comparable.compare-to, otherwise.

Deprecated: Use system.platform instead.

process-stats --gc/bool=false list/List=(List system.STATS-LIST-SIZE_) -> List
Deprecated: Use system.process-stats instead.

process-stats --gc/bool=false group/any id/any list/List=(List system.STATS-LIST-SIZE_) -> List
Deprecated: Use system.process-stats instead.

random -> any
Returns a random number in the range [0..0xFFF_FFFF] (inclusive).
The returned number is the result of a PRNG (pseudo random number generator). The seed of the PRNG can be changed by calling set-random-seed.

random n/int -> any
Returns a random number in the range [0..n[ (n exclusive).
The returned number is the result of a PRNG (pseudo random number generator). The seed of the PRNG can be changed by calling set-random-seed.

random start/int end/int -> any
Returns a pseudo-random number from start to end - 1.

round-down value/int divisor/int -> int
Rounds a non-negative value down to the previous multiple of the divisor.
Examples

round-down 27 10  // => 20
round-down 7 2    // => 6
round-down -13 10 // => OUT_OF_RANGE error

round-up value/int divisor/int -> int
Rounds a non-negative value up to the next multiple of the divisor.
Examples

round-up 17 10  // => 20
round-up 7 2    // => 8
round-up -13 10 // => OUT_OF_RANGE error

set-random-seed seed/Data -> none
Seeds the random number generator with the seed.
Currently only the first 16 bytes of the seed are used.

Converts a number between 0 and 15 to a lower case hex digit.

Converts a number between 0 and 15 to an upper case hex digit.

Returns information about who built this virtual machine.
Deprecated. Use system.vm-sdk-info instead.

Returns the Toit SDK model that this virtual machine has been built from.
Deprecated. Use system.vm-sdk-model instead.

Returns the Toit SDK version that this virtual machine has been built from.
Deprecated. Use system.vm-sdk-version instead.

with-timeout timeout/Duration [block] -> any
Calls the given block but throws an exception if the timeout is exceeded.
If timeout is null, calls the block without a timeout.

with-timeout --ms/int [block] -> any
Calls the given block but throws an exception if a timeout of ms milliseconds is exceeded.

with-timeout --us/int [block] -> any
Calls the given block but throws an exception if a timeout of us microseconds is exceeded.