summaryrefslogtreecommitdiff
path: root/doc/types.txt
blob: 98ac6dee7e55b1536d5ea6dada566f772ae79056 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
scalar types:

* i8
* i16
* i32
* i64
* u8
* u16
* u32
* u64
* uptr
* iptr
* usize
* isize
* f32
* f64

enums, struct, union:

* enum Name { A, B, C, D }

ranges:

* T..T
  + range type
  + T must be an ordinal

* a..b
  + range literal
  + a and b must be ordinals (integer or enum) of the same type

slices and arrays:

* []T - slice
* [N]T - array of N elements
* [R]T - array of as many elements as the range constant R covers
* [E]T - array over the enum E
* in general, any expression X that can be used in [X]T can also be used in a
  foreach statement (`for v in X { ... }`)

* sized integers
  + i8, i16, i32, i64
  + u8, u16, u32, u64
  + uptr, iptr: pointer-sized
  + usize, isize: native machine word size
* sized floating point
  + f32, f64
* bool

* more modern type system than c
  + distinction between pointers and arrays
  + slice types (ptr, len)
    - strings are slices, like rust &str or c++ str_view
  + dynamic arrays (ptr, len, cap)
    - manipulation of dynamic arrays is handled by normal functions
  + type-safe generics
  + parametric polymorphism (at compile time)
  + built-in types for vector and matrix math
  + scalar types have explicit bit sizes
    - u8, i32, u64, f32, f64
  + bit set support!
  + type inference
    - let x = y
    - can do like .ENUM_NAME when expecting an enum value, even though
      otherwise it's `let x = EnumType.ENUM_NAME`
  + pascal-style postfix dereference, no need for a->b or (*a).b
    - possibly also auto-dereference when accessing fields