GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — wasm-split-tool/examples/game.wat at main · AnranS/wasm-split-tool

Expand file tree

/

game.wat

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
203 lines (179 loc) · 6.63 KB
/

game.wat

Copy path

File metadata and controls

203 lines (179 loc) · 6.63 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
;; game.wat — a richer demo module for examples/.
;;
;; Goals:
;; - 4 distinct cold type signatures -> archive mode builds 4 dedup'd
;; trampoline WebAssembly.Instances (one per type)
;; - 9 cold functions -> `--batch-size 3` splits the body
;; archive into 3 batches (vs 1 batch at the default of 32)
;; - cold -> hot direct call (open_inventory -> rand)
;; - cold -> cold direct call (boss_battle_init -> open_inventory,
;; achievement_unlock -> save_game)
;; - shared mutable globals (frame_count, rand_state)
;; - shared linear memory + data seg (save slots at offset 1024)
;; - deterministic exports so a Node harness can assert every return value
;;
;; Table layout is chosen so `tableIdx == funcidx` for every non-export
;; function, which keeps the archive manifest easy to reason about:
;;
;; funcidx / tableIdx
;; 0 $frame_step hot (i32) -> i32
;; 1 $entity_update hot (i32,i32) -> ()
;; 2 $rand hot () -> i32
;; 3 $open_inventory cold (i32) -> i32
;; 4 $boss_battle_init cold (i32) -> i32
;; 5 $save_game cold (i32) -> ()
;; 6 $load_game cold (i32) -> i32
;; 7 $settings_apply cold (i32,i32) -> i32
;; 8 $achievement_unlock cold (i32,i32) -> i32
;; 9 $credits_show cold () -> i32
;; 10 $credits_version cold () -> i32
;; 11 $debug_dump cold (i32) -> ()
;;
;; Cold type signatures in play:
;; (i32) -> i32 -> open_inventory, boss_battle_init, load_game
;; (i32,i32) -> i32 -> settings_apply, achievement_unlock
;; () -> i32 -> credits_show, credits_version
;; (i32) -> () -> save_game, debug_dump
;; => 4 distinct types, archive mode creates exactly 4 trampoline modules.
(module
(type $i_i (func (param i32) (result i32)))
(type $ii_i (func (param i32 i32) (result i32)))
(type $v_i (func (result i32)))
(type $i_v (func (param i32)))
(type $ii_v (func (param i32 i32)))
(memory (export "memory") 1)
;; Mutable globals simulate an Emscripten/Unity runtime's __stack_pointer:
;; primary exports them, secondary imports them (archive_builder.rs).
(global $frame_count (mut i32) (i32.const 0))
(global $rand_state (mut i32) (i32.const 1))
;; Persistent save slots live at memory offset 1024..1040.
(data (i32.const 1024)
"\00\00\00\00"
"\00\00\00\00"
"\00\00\00\00"
"\00\00\00\00")
(table 12 12 funcref)
(elem (i32.const 0)
$frame_step $entity_update $rand
$open_inventory $boss_battle_init
$save_game $load_game
$settings_apply $achievement_unlock
$credits_show $credits_version
$debug_dump)
;; ── hot (stays in primary) ──────────────────────────────────────────
(func $frame_step (type $i_i)
global.get $frame_count
local.get 0
i32.add
global.set $frame_count
global.get $frame_count)
(func $entity_update (type $ii_v)
(local $addr i32)
local.get 0
i32.const 4
i32.mul
local.set $addr
local.get $addr
local.get $addr
i32.load
local.get 1
i32.add
i32.store)
;; LCG: state = state * 1103515245 + 12345 (mod 2^32), return new state.
(func $rand (type $v_i)
global.get $rand_state
i32.const 1103515245
i32.mul
i32.const 12345
i32.add
global.set $rand_state
global.get $rand_state)
;; ── cold (moves to secondary / archive) ─────────────────────────────
;; cold → hot direct call: $rand must be rewritten to call_indirect.
(func $open_inventory (type $i_i)
local.get 0
i32.const 10
i32.mul
call $rand
i32.const 255
i32.and
i32.add)
;; cold → cold direct call: $open_inventory must be rewritten in archive
;; mode (waitTableId + call_indirect); left direct in classic split mode.
(func $boss_battle_init (type $i_i)
local.get 0
i32.const 1000
i32.mul
local.get 0
call $open_inventory
i32.add)
(func $save_game (type $i_v)
i32.const 1024
local.get 0
i32.const 4
i32.mul
i32.add
global.get $frame_count
i32.store)
(func $load_game (type $i_i)
i32.const 1024
local.get 0
i32.const 4
i32.mul
i32.add
i32.load)
(func $settings_apply (type $ii_i)
local.get 0
i32.const 10
i32.mul
local.get 1
i32.add)
;; cold → cold direct call #2: $save_game.
(func $achievement_unlock (type $ii_i)
local.get 0
call $save_game
local.get 1
i32.const 1
i32.add)
(func $credits_show (type $v_i)
global.get $frame_count)
(func $credits_version (type $v_i)
i32.const 20260420)
(func $debug_dump (type $i_v)
i32.const 0
local.get 0
i32.store)
;; ── exports (thin wrappers so the harness can call everything) ──────
(func (export "frame_step") (param i32) (result i32)
local.get 0 call $frame_step)
(func (export "entity_update") (param i32 i32)
local.get 0 local.get 1 call $entity_update)
(func (export "rand") (result i32)
call $rand)
(func (export "open_inventory") (param i32) (result i32)
local.get 0 call $open_inventory)
(func (export "boss_battle_init") (param i32) (result i32)
local.get 0 call $boss_battle_init)
(func (export "save_game") (param i32)
local.get 0 call $save_game)
(func (export "load_game") (param i32) (result i32)
local.get 0 call $load_game)
(func (export "settings_apply") (param i32 i32) (result i32)
local.get 0 local.get 1 call $settings_apply)
(func (export "achievement_unlock") (param i32 i32) (result i32)
local.get 0 local.get 1 call $achievement_unlock)
(func (export "credits_show") (result i32)
call $credits_show)
(func (export "credits_version") (result i32)
call $credits_version)
(func (export "debug_dump") (param i32)
local.get 0 call $debug_dump)
;; Exposed for harness assertions on shared state.
(func (export "frame_count") (result i32) global.get $frame_count)
(func (export "read_mem") (param i32) (result i32) local.get 0 i32.load)
;; call_indirect dispatcher for type $i_i — lets the harness invoke any
;; cold function that matches the signature through the shared table.
(func (export "dispatch_i_i") (param i32 i32) (result i32)
local.get 1
local.get 0
call_indirect (type $i_i)))
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.