Export function table by default and add an option to import it

This commit is contained in:
dcodeIO 2018-03-23 15:12:03 +01:00
parent 2738eee9cd
commit ec5bb7ad51
12 changed files with 27 additions and 4 deletions

View File

@ -360,6 +360,7 @@ exports.main = function main(argv, options, callback) {
assemblyscript.setNoAssert(compilerOptions, !!args.noAssert);
assemblyscript.setNoMemory(compilerOptions, !!args.noMemory);
assemblyscript.setImportMemory(compilerOptions, !!args.importMemory);
assemblyscript.setImportTable(compilerOptions, !!args.importTable);
assemblyscript.setMemoryBase(compilerOptions, args.memoryBase >>> 0);
assemblyscript.setSourceMap(compilerOptions, args.sourceMap != null);

View File

@ -107,6 +107,10 @@
"desc": "Sets the start offset of compiler-generated static memory.",
"type": "number"
},
"importTable": {
"desc": "Imports the function table instance provided by the embedder.",
"type": "boolean"
},
"noLib": {
"desc": "Does not include the shipped standard library.",
"type": "boolean"

2
dist/asc.js vendored

File diff suppressed because one or more lines are too long

2
dist/asc.js.map vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -147,6 +147,8 @@ export class Options {
noMemory: bool = false;
/** If true, imports the memory provided by the embedder. */
importMemory: bool = false;
/** If true, imports the function table provided by the embedder. */
importTable: bool = false;
/** Static memory start offset. */
memoryBase: u32 = 0;
/** If true, generates information necessary for source maps. */
@ -327,6 +329,13 @@ export class Compiler extends DiagnosticEmitter {
entries[i] = functionTable[i].ref;
}
module.setFunctionTable(entries);
module.addTableExport("0", "table");
}
// import table if requested
if (options.importTable) {
module.addTableImport("0", "env", "table");
if (!functionTableSize) module.addTableExport("0", "table");
}
return module;

View File

@ -110,6 +110,11 @@ export function setImportMemory(options: Options, importMemory: bool): void {
options.importMemory = importMemory;
}
/** Sets the `importTable` option. */
export function setImportTable(options: Options, importTable: bool): void {
options.importTable = importTable;
}
/** Sets the `sourceMap` option. */
export function setSourceMap(options: Options, sourceMap: bool): void {
options.sourceMap = sourceMap;

View File

@ -13,6 +13,7 @@
(memory $0 1)
(data (i32.const 4) "\16\00\00\00f\00u\00n\00c\00t\00i\00o\00n\00-\00e\00x\00p\00r\00e\00s\00s\00i\00o\00n\00.\00t\00s")
(export "memory" (memory $0))
(export "table" (table $0))
(start $start)
(func $start~anonymous|0 (; 1 ;) (type $ii) (param $0 i32) (result i32)
(get_local $0)

View File

@ -14,6 +14,7 @@
(memory $0 1)
(data (i32.const 4) "\16\00\00\00f\00u\00n\00c\00t\00i\00o\00n\00-\00e\00x\00p\00r\00e\00s\00s\00i\00o\00n\00.\00t\00s\00")
(export "memory" (memory $0))
(export "table" (table $0))
(start $start)
(func $start~anonymous|0 (; 1 ;) (type $ii) (param $0 i32) (result i32)
(return

View File

@ -15,6 +15,7 @@
(memory $0 1)
(data (i32.const 4) "\11\00\00\00f\00u\00n\00c\00t\00i\00o\00n\00-\00t\00y\00p\00e\00s\00.\00t\00s")
(export "memory" (memory $0))
(export "table" (table $0))
(start $start)
(func $function-types/makeAdder<i32>~anonymous|0 (; 1 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.add

View File

@ -16,6 +16,7 @@
(memory $0 1)
(data (i32.const 4) "\11\00\00\00f\00u\00n\00c\00t\00i\00o\00n\00-\00t\00y\00p\00e\00s\00.\00t\00s\00")
(export "memory" (memory $0))
(export "table" (table $0))
(start $start)
(func $function-types/makeAdder<i32>~anonymous|0 (; 1 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(return