* Processes the provided path. * @param {NodePath<Global>} path path
(path)
| 209 | * @param {NodePath<Global>} path path |
| 210 | */ |
| 211 | Global(path) { |
| 212 | const { node } = path; |
| 213 | const [init] = node.init; |
| 214 | |
| 215 | if (init.id === "get_global") { |
| 216 | node.globalType.mutability = "var"; |
| 217 | |
| 218 | const initialGlobalIdx = init.args[0]; |
| 219 | |
| 220 | node.init = [ |
| 221 | createDefaultInitForGlobal(node.globalType), |
| 222 | t.instruction("end") |
| 223 | ]; |
| 224 | |
| 225 | additionalInitCode.push( |
| 226 | /** |
| 227 | * get_global in global initializer only works for imported globals. |
| 228 | * They have the same indices as the init params, so use the |
| 229 | * same index. |
| 230 | */ |
| 231 | t.instruction("get_local", [initialGlobalIdx]), |
| 232 | t.instruction("set_global", [t.indexLiteral(newGlobals.length)]) |
| 233 | ); |
| 234 | } |
| 235 | |
| 236 | newGlobals.push(node); |
| 237 | |
| 238 | path.remove(); |
| 239 | } |
| 240 | }); |
| 241 | |
| 242 | // Add global declaration instructions |
nothing calls this directly
no test coverage detected