diff --git a/asm.js b/asm.js index 604b750..1b4f60a 100644 --- a/asm.js +++ b/asm.js @@ -886,8 +886,9 @@ const Section = Object.freeze({ }); const Kind = Object.freeze({ - FUNC: 0x00, - MEM: 0x02, + FUNC: 0x00, + MEM: 0x02, + GLOBAL: 0x03, }); export class Assembler { @@ -942,8 +943,28 @@ export class Assembler { } action_export(action) { - const index = Object.keys(this.funcs).indexOf(action.name); - this.exports[action.name] = { kind: Kind.FUNC, index }; + const func_index = Object.keys(this.funcs).indexOf(action.name); + if (func_index != -1) { + this.exports[action.name] = { + kind: Kind.FUNC, + index: func_index, + }; + return; + } + + const global_index = Object.keys(this.globals).indexOf(action.name); + if (global_index != -1) { + this.exports[action.name] = { + kind: Kind.GLOBAL, + index: global_index, + }; + return; + } + + console.error( + `ERROR: Unable to resolve export ${action.name} ` + + "(only functions and globals currently supported)" + ); } action_func(action) {