စံကား

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).
KindShort nameSmallestLargest
၈ ဘစ် ကိန်းပြည့်i8-128127
လက္ခဏာမဲ့ ၈ ဘစ် ကိန်းပြည့်u80255
၁၆ ဘစ် ကိန်းပြည့်i16-32,76832,767
လက္ခဏာမဲ့ ၁၆ ဘစ် ကိန်းပြည့်u16065,535
၃၂ ဘစ် ကိန်းပြည့်i32-2,147,483,6482,147,483,647
လက္ခဏာမဲ့ ၃၂ ဘစ် ကိန်းပြည့်u3204,294,967,295
၆၄ ဘစ် ကိန်းပြည့်i64-2^632^63 - 1
လက္ခဏာမဲ့ ၆၄ ဘစ် ကိန်းပြည့်u6402^64 - 1
၁၂၈ ဘစ် ကိန်းပြည့်i128-2^1272^127 - 1
လက္ခဏာမဲ့ ၁၂၈ ဘစ် ကိန်းပြည့်u12802^128 - 1
ကိန်းပြည့်, လက္ခဏာရှိ ကိန်းပြည့်isizeas the platform size
လက္ခဏာမဲ့ ကိန်းပြည့်usizeas 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:

စံကားZK0404

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.

KindShort nameSign / exponent / fraction bitsCorrect digitsLargest finite
၁၆ ဘစ် ဒဿမကိန်းf161 / 5 / 10about 365,504
၃၂ ဘစ် ဒဿမကိန်းf321 / 8 / 23about 7about 3.4 × 10^38
ဒဿမကိန်း, ၆၄ ဘစ် ဒဿမကိန်းf641 / 11 / 52about 15about 1.8 × 10^308
၁၂၈ ဘစ် ဒဿမကိန်းf1281 / 15 / 112about 33about 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.

BurmeseShort namePage
ကိန်းပြည့် လိပ်စာ*isizePointers
ကိန်းပြည့် လိပ်စာ ၏ လိပ်စာ**isizePointers
ငှားထားသော ကိန်းပြည့် လိပ်စာ&*isizeOwnership and borrowing
ကိန်းပြည့် လိပ်စာအကြမ်း~isizeOwnership and borrowing
လိပ်စာptrPointers
ဗလာ (the null address)nullPointers
အကွက် ၃ ခုရှိသော ကိန်းပြည့် စာရင်း[3]isizeLists
အကွက် ၂ ခုရှိသော အကွက် ၃ ခုရှိသော ကိန်းပြည့် စာရင်း စာရင်း[2][3]isizeLists

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).

KindDefault
integers၀
decimal numbers၀.၀
စာလုံးthe null character, '\0'
မှန်မှားတန်ဖိုးမမှန်
an addressဗလာ
a listeach 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

-၁၂၈
၂၅၅
စံကားZK0406

Expected error

error[ZK0406]: the literal 256 does not fit u8
စံကားZK0216

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.