01The language
Kinds and values
The kinds of value in Zaka - integers, decimal numbers, characters, true/false values, addresses and lists - with ranges, sizes and default values.
Each value in a Zaka program has a kind. The kind tells how much room the value takes, which values are possible and which operations are allowed. The compiler works out the kind of each expression before the program runs, and a variable keeps the kind it was declared with for its whole life. A kind is written in Burmese; compiler messages use a short English name for it, listed below.
Values and kinds in the Learn book introduces the scalar kinds with gentle examples. This page states the full rules.
Integer kinds
An integer kind is built from three parts in a fixed order:
(လက္ခဏာရှိ | လက္ခဏာမဲ့) (N ဘစ်) ကိန်းပြည့်
sign, optional size, optional the kind word
- The sign is
လက္ခဏာရှိ(signed) orလက္ခဏာမဲ့(unsigned). Without a sign word the integer is signed. Signed integers use two's complement. - The size is 8, 16, 32, 64 or 128 bits, written with Burmese or Western digits. Another count is ZK0216. Without a size the integer has the platform size.
- A sign word can stand before
ကိန်းပြည့်and no other kind (ZK0217).
| Kind | Short name | Smallest | Largest |
|---|---|---|---|
၈ ဘစ် ကိန်းပြည့် | i8 | -128 | 127 |
လက္ခဏာမဲ့ ၈ ဘစ် ကိန်းပြည့် | u8 | 0 | 255 |
၁၆ ဘစ် ကိန်းပြည့် | i16 | -32,768 | 32,767 |
လက္ခဏာမဲ့ ၁၆ ဘစ် ကိန်းပြည့် | u16 | 0 | 65,535 |
၃၂ ဘစ် ကိန်းပြည့် | i32 | -2,147,483,648 | 2,147,483,647 |
လက္ခဏာမဲ့ ၃၂ ဘစ် ကိန်းပြည့် | u32 | 0 | 4,294,967,295 |
၆၄ ဘစ် ကိန်းပြည့် | i64 | -2^63 | 2^63 - 1 |
လက္ခဏာမဲ့ ၆၄ ဘစ် ကိန်းပြည့် | u64 | 0 | 2^64 - 1 |
၁၂၈ ဘစ် ကိန်းပြည့် | i128 | -2^127 | 2^127 - 1 |
လက္ခဏာမဲ့ ၁၂၈ ဘစ် ကိန်းပြည့် | u128 | 0 | 2^128 - 1 |
ကိန်းပြည့်, လက္ခဏာရှိ ကိန်းပြည့် | isize | as the platform size | |
လက္ခဏာမဲ့ ကိန်းပြည့် | usize | as the platform size |
The platform size
isize and usize take their width from the platform: 64 bits unless set otherwise.
zakac run --platform-bits N (and semantic-check) picks 8, 16, 32, 64 or 128 instead. Plain
ကိန်းပြည့် is the right choice when no size matters, and it is the kind that an
integer literal gets when its place asks for nothing else.
isize and i64 are two kinds even when the platform has 64 bits, and so are usize
and u64. Neither goes into the other without a conversion:
Expected error
error[ZK0404]: cannot combine i64 and isize without a conversion
zakac run --platform-bits 32 program.zaka
Decimal number kinds
A decimal number kind is ဒဿမကိန်း with an optional size: 16, 32, 64 or 128 bits.
Without a size it has 64 bits. These are the IEEE 754 formats of base 2. There is no
unsigned decimal kind.
| Kind | Short name | Sign / exponent / fraction bits | Correct digits | Largest finite |
|---|---|---|---|---|
၁၆ ဘစ် ဒဿမကိန်း | f16 | 1 / 5 / 10 | about 3 | 65,504 |
၃၂ ဘစ် ဒဿမကိန်း | f32 | 1 / 8 / 23 | about 7 | about 3.4 × 10^38 |
ဒဿမကိန်း, ၆၄ ဘစ် ဒဿမကိန်း | f64 | 1 / 11 / 52 | about 15 | about 1.8 × 10^308 |
၁၂၈ ဘစ် ဒဿမကိန်း | f128 | 1 / 15 / 112 | about 33 | about 1.2 × 10^4932 |
A decimal number can also be inf, -inf or NaN. These come from arithmetic, such as
a division with a zero divisor, and do not stop the program. A literal that is too big for its float
kind becomes inf, with no error. A decimal number prints with a decimal point, and with
an exponent when its size is far from 1.
Expected output
inf
-inf
NaN
မမှန်
၁e၃၀
inf
Characters
စာလုံး holds one Unicode scalar value: 32 bits, written 'က'. Characters can be
compared with ==, != and the ordering operators, and convert to integers and
back. Arithmetic does not take them.
True/false values
မှန်မှားတန်ဖိုး (or the loanword ဘူလီယန်) holds မှန် or မမှန်. It takes one octet,
which holds 1 or 0. A condition must be of this kind (ZK0402): an integer is not true or
false. It prints as မှန် or မမှန်.
Addresses and lists
Two more families of kind are built from the scalar kinds. Their rules have pages of their own.
| Burmese | Short name | Page |
|---|---|---|
ကိန်းပြည့် လိပ်စာ | *isize | Pointers |
ကိန်းပြည့် လိပ်စာ ၏ လိပ်စာ | **isize | Pointers |
ငှားထားသော ကိန်းပြည့် လိပ်စာ | &*isize | Ownership and borrowing |
ကိန်းပြည့် လိပ်စာအကြမ်း | ~isize | Ownership and borrowing |
လိပ်စာ | ptr | Pointers |
ဗလာ (the null address) | null | Pointers |
အကွက် ၃ ခုရှိသော ကိန်းပြည့် စာရင်း | [3]isize | Lists |
အကွက် ၂ ခုရှိသော အကွက် ၃ ခုရှိသော ကိန်းပြည့် စာရင်း စာရင်း | [2][3]isize | Lists |
A short name reads left to right as the kind is built: * for each level of owner
address, & in front for a borrow, ~ for a raw level, [n] for each list level.
An address takes the platform size.
The size of a kind
<kind> ၏ အရွယ်အစား ("the size of the kind") is the number of octets one value takes:
Expected output
၁
၂
၄
၁
၈
၈
၁၂
Default values
A variable declared with no value starts at the default of its kind. A constant has no default: it must be given a value (ZK0308).
| Kind | Default |
|---|---|
| integers | ၀ |
| decimal numbers | ၀.၀ |
စာလုံး | the null character, '\0' |
မှန်မှားတန်ဖိုး | မမှန် |
| an address | ဗလာ |
| a list | each cell at the default of its kind |
Expected output
၀
၀.၀
မမှန်
၀
ဗလာ
[မမှန်၊ မမှန်၊ မမှန်]
The edges of a kind
A value keeps inside the range of its kind. A literal that falls outside it is an error at compile time, and arithmetic that goes past an edge while the program runs wraps around (Expressions gives the rules).
Expected output
-၁၂၈
၂၅၅
Expected error
error[ZK0406]: the literal 256 does not fit u8
Expected error
error[ZK0216]: ၇ is not a valid bit count here; use 8, 16, 32, 64, 128
Kinds do not mix on their own
A true/false value is not a number, a character is not an integer and a decimal number is not an integer. A value goes where a different kind is wanted just through a conversion, or through the widening that conversions describes.