Types
Niblick has explicit-width integer types. There are no general pointers.
bool, flashptr, half, and float are distinct types.
Type spellings
If you’re wondering why the signed vs unsigned stuff is a little inconsistent, that’s primarily because signed types were a later addition to the language, and also I figure most people probably won’t want to use signed types for the smaller types, and so it felt unwieldy to make signed the default. But for larger types, I’m used to specifying the exact size and signedness when working in other languages anyways, so if you’re like me in that regard then you’ll probably be fine.
Canonical |
Width |
RAM |
Signed |
Aliases |
|---|---|---|---|---|
|
4 |
1 nibble |
no |
|
|
4 |
1 nibble |
yes |
|
|
8 |
2 nibbles |
no |
|
|
8 |
2 nibbles |
yes |
|
|
16 |
4 nibbles |
no |
|
|
16 |
4 nibbles |
yes |
|
|
32 |
8 nibbles |
no |
|
|
32 |
8 nibbles |
yes |
|
|
64 |
16 nibbles |
no |
|
|
64 |
16 nibbles |
yes |
|
|
logical |
1 nibble |
logical |
|
|
12 |
3 nibbles |
n/a |
|
|
16 |
4 nibbles |
signed |
|
|
32 |
8 nibbles |
signed |
|
|
0 |
0 |
n/a |
char is unsigned. int is signed 16-bit and long is signed 32-bit.
intptr_t and uintptr_t are not defined.
bool
bool is a logical type with one nibble of storage.
Comparisons,
!,&&, and||producebool.Assigning an integer to
boolnormalizes it to 0 or 1.Converting
boolto an integer yields 0 or 1.trueandfalseproduce 1 and 0.Arithmetic converts
boolto a 4-bit integer, sotrue + trueis 2.print()prints aboolas0or1.
flashptr
flashptr is a 12-bit code-memory address. It is used for flash strings and
flash tables.
&CONSTon a flash array yields aflashptr.flash_next(&p)advances aflashptrby two code words.A
flashptris not a data address and cannot be dereferenced.
Floating point
half is IEEE-754 binary16. float is IEEE-754 binary32. Both are
software implementations.
Arithmetic rounds to nearest, ties to even.
Subnormal inputs and results are supported.
Signed zero, infinities, and canonical quiet NaN follow IEEE-754.
Float-to-integer conversion truncates toward zero and saturates on overflow. NaN converts to 0. Negative values converted to unsigned types become 0.
halfandfloatconvert to and from integer and 64-bit integer types.double,f64, and_Float64are not supported.
The implementation notes are in Soft float.
64-bit integers
A 64-bit value occupies sixteen nibbles. Expression results use a dedicated memory buffer. Each 64-bit variable costs sixteen nibbles of RAM, and the compiler reserves result and temporary slots while evaluating a 64-bit expression.
64-bit multiply and divide call the helpers in lib/wide.nbl. See
64-bit arithmetic.
Struct types
struct declares a RAM-only aggregate with scalar fields. Struct layout and
limits are in Structs.