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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//! The codegen↔runtime helper symbol contract.
//!
//! The Rust backend (`smelt-codegen-rust`) emits generated programs that call a
//! fixed set of runtime helper functions. Those helpers are themselves emitted
//! into every generated crate as a prelude (see `lib.rs` in the codegen crate).
//! Both halves — the *definition* of a helper in the prelude and every *call
//! site* the expression emitter writes — must agree on the exact symbol name.
//! When they drift apart the mismatch is invisible until the generated crate
//! reaches `rustc`, far from the codegen change that caused it.
//!
//! This module is the single, enumerable source of truth for those names. Each
//! constant is the literal Rust identifier of one runtime helper. Codegen
//! references these constants instead of inlining string literals, so renaming
//! a helper is a one-line edit here that updates the prelude definition and all
//! call sites at once.
//!
//! Scope: this table covers only the *fixed* runtime helper set — symbols whose
//! names are baked into the runtime prelude and shared with the emitter. It
//! intentionally does **not** cover per-program or generated identifiers (e.g.
//! `smelt_object`, `smelt_args`, locals like `smelt_callback`), which are
//! synthesized per emission and are not part of the cross-crate contract.
/// Timer and microtask-queue runtime helpers.
///
/// These back the JavaScript timer surface (`setTimeout`/`clearTimeout`),
/// `await`-based sleeping, and the cooperative promise-task pump that the async
/// lowering drives. They are emitted into the prelude and called from the
/// async-op and statement emitters.
/// JSON / dynamic-`unknown` boundary helpers.
///
/// These bridge `serde_json` values and the runtime's tagged `SmeltUnknown`
/// dynamic value, used at JSON parse boundaries.
/// String runtime helpers.
///
/// These back JavaScript global string functions that need more than a direct
/// Rust std method call.
/// Host-object construction helpers.
///
/// These build the marker records that model JavaScript host builtins (see
/// `host_object.rs` for the marker registry itself).
/// Host-global override-slot runtime helpers.
///
/// These back the bounded whole-global reassignment of modeled host
/// constructors (`globalThis.File = ...`, `globalThis.Blob = undefined`,
/// save/restore). The generated crate emits one `thread_local!` slot per host
/// name the crate actually writes (`SMELT_HOST_OVERRIDE_<NAME>`), initialized to
/// the fixed `SmeltHostOverride::Native` state, plus the fixed enum and the
/// three helpers named here. See the `HostGlobalRead`/`HostGlobalWrite`/
/// `HostGlobalPresent` MIR rvalues.
///
/// Per-test-thread semantics: each `#[test]` runs on its own thread and gets a
/// fresh `Native` slot, matching the specs' save/restore discipline (they
/// snapshot the native handle, override the slot, then restore it within one
/// test).