]> Witch of Git - ivy/blob - docs/object-layout.md
[rt] Split the runtime into multiple modules
[ivy] / docs / object-layout.md
1 # Object Layouts
2
3
4 All heap objects have a 32-bit reference count at [obj + 4].
5 Objects are returned at +1.
6
7
8 Integers:
9 A 63-bit signed integer, shifted left 1, with the lsb set.
10 For example, 1 is stored as 0b11, 2 as 0b101, etc.
11 Can also be stored as an aligned pointer to an object.
12
13 TODO: support big ints with this layout.
14
15 [u8:tag=1]
16 [u24:pad]
17 [u32:refcount]
18 [i64:value]
19
20
21 Closures:
22 A pointer to the closure entry.
23 Must be 8-byte aligned.
24
25 00:[u8:tag=0]
26 01:[u8:pad]
27 02:[u16:upvars]
28 04:[u32:refcount]
29 08:[u64:fn ptr]
30 10:[u16:params]
31 12:[u16:filled params]
32 14:[u32:pad]
33 18:[params...]
34 ??:[fields...]
35
36
37 Indirect Closures:
38 When a closure has lots of data and is frequently copied, it's beneficial to use an indirect closure that contains a pointer to the fields block so that only the params has to be copied.
39 These are unimplemented for the time being.
40
41 00:[u8:tag=2]
42 01:[u8:pad]
43 02:[u16:upvars]
44 04:[u32:refcount]
45 08:[u64:fn ptr]
46 10:[u16:params]
47 12:[u16:filled params]
48 14:[u32:pad]
49 18:[params...]
50 ??:[u64:fields ptr]
51
52
53 fields block:
54 00:[u16:pad]
55 02:[u16:field count]
56 04:[u32:refcount]
57 08:[fields...]
58
59
60 When a closure is destroyed, it iterates over all of its fields and performs a decref on them.