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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//! Portable save states: the game's state in a form either build can load.
//!
//! The headless WASM (`build/us_web_headless`, what Rust, Python and the nodes
//! run) and the rendering WASM (`build/us_web`, what the browser runs) are
//! linked from the same objects, but at different addresses, and their
//! mallocs hand out different blocks, so a raw memory snapshot of one does not
//! load in the other. A [`Portable`] state holds the game's variables and the
//! malloc blocks they reach, with every pointer and function pointer replaced
//! by a build-neutral one, so it loads in either build and the game goes on
//! identically. The guide is `docs/PORTABLE.md`; the design notes and
//! measurements are in `docs/portable-state.md`.
//!
//! One translation:
//!
//! ```text
//! export: memory image --heap.rs--> chunks --walk.rs--> regions + reached blocks
//! --relocate.rs (+ ghosts.rs)--> Portable --format.rs--> bytes
//! load: bytes --format.rs--> Portable --load.rs (place, patches)--> writes into the target
//! ```
//!
//! Reading order, bottom up (each file starts with what it is, what it
//! guarantees and what to read next):
//!
//! | layer | files |
//! |---|---|
//! | memory layout, generated | `tables.rs` (by `maketools/gen_portable_tables.py`), `layout.rs` |
//! | lookups and addresses | `types.rs`, `builds.rs`, `addresses.rs`, `heap.rs`, `image.rs`, `regions.rs` |
//! | which words are pointers | `rules.rs`, `excluded.rs`, `plausible.rs` |
//! | the walk | `walk.rs` |
//! | relocation | `relocate.rs`, `ghosts.rs`, `state.rs`, `diagnostics.rs`, `export.rs` |
//! | format | `format.rs` |
//! | loading | `load.rs` |
//! | checks | `compare.rs` (digest, diff) |
//! | public API | this file |
//!
//! This module only needs `std`: the same source is compiled to WASM for the
//! browser (`rust/portable-wasm`).
// Layer 1: the memory layout of both builds (generated) and its vocabulary.
// Layer 2: lookups over the tables and over a memory image.
// Layer 3: which words are pointers, and what is not state.
// Layer 4: finding the state.
// Layer 5: making it portable.
// Layer 6: the byte format, loading, and comparing states.
pub use Build;
pub use ;
pub use ;
pub use ;
pub use ;
use VARS;