From ce7160360af3b9187e1d38e333c01710629f950b Mon Sep 17 00:00:00 2001 From: dcode Date: Fri, 11 Jun 2021 12:51:11 +0200 Subject: [PATCH 1/4] Include env/RT in generated definitions --- src/definitions.ts | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/definitions.ts b/src/definitions.ts index 7bb599b272..6d587dcd87 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -438,23 +438,19 @@ export class TSDBuilder extends ExportsWalker { } visitFunction(name: string, element: Function): void { - if (element.isAny(CommonFlags.PRIVATE | CommonFlags.SET)) return; + if (element.isAny(CommonFlags.PRIVATE)) return; var sb = this.sb; var signature = element.signature; indent(sb, this.indentLevel); - if (element.is(CommonFlags.PROTECTED)) sb.push("protected "); - if (element.is(CommonFlags.STATIC)) sb.push("static "); - if (element.is(CommonFlags.GET)) { - sb.push("get "); - sb.push(name); // 'get:funcName' internally - sb.push("(): "); - sb.push(this.typeToString(signature.returnType)); - sb.push(";\n"); - return; + if (!element.isAny(CommonFlags.STATIC | CommonFlags.INSTANCE)) { + sb.push("export function "); } else { - if (!element.isAny(CommonFlags.STATIC | CommonFlags.INSTANCE)) sb.push("export function "); - sb.push(name); + if (element.is(CommonFlags.PROTECTED)) sb.push("protected "); + if (element.is(CommonFlags.STATIC)) sb.push("static "); + if (element.is(CommonFlags.GET)) sb.push("get "); + else if (element.is(CommonFlags.SET)) sb.push("set "); } + sb.push(name); sb.push("("); var parameters = signature.parameterTypes; var numParameters = parameters.length; @@ -604,12 +600,12 @@ export class TSDBuilder extends ExportsWalker { build(): string { var sb = this.sb; - var isWasm64 = this.program.options.isWasm64; + var options = this.program.options; sb.push("type i8 = number;\n"); sb.push("type i16 = number;\n"); sb.push("type i32 = number;\n"); sb.push("type i64 = bigint;\n"); - if (isWasm64) { + if (options.isWasm64) { sb.push("type isize = bigint;\n"); } else { sb.push("type isize = number;\n"); @@ -618,7 +614,7 @@ export class TSDBuilder extends ExportsWalker { sb.push("type u16 = number;\n"); sb.push("type u32 = number;\n"); sb.push("type u64 = bigint;\n"); - if (isWasm64) { + if (options.isWasm64) { sb.push("type usize = bigint;\n"); } else { sb.push("type usize = number;\n"); @@ -627,6 +623,23 @@ export class TSDBuilder extends ExportsWalker { sb.push("type f64 = number;\n"); sb.push("type bool = boolean | number;\n"); this.walk(); + if (options.exportMemory) { + sb.push("export const memory: WebAssembly.Memory;\n"); + } + if (options.exportTable) { + sb.push("export const table: WebAssembly.Table;\n"); + } + if (options.explicitStart) { + sb.push("export function _start(): void;\n"); + } + if (options.exportRuntime) { + sb.push("export function __new(size: usize, id: u32): usize;\n"); + sb.push("export function __pin(ptr: usize): usize;\n"); + sb.push("export function __unpin(ptr: usize): usize;\n"); + sb.push("export function __collect(): usize;\n"); + sb.push("export const __rtti_base: usize;\n"); + } + sb.push("export const __setArgumentsLength: ((n: i32) => usize) | undefined;\n"); return this.sb.join(""); } } From b6ed41b7da9e66b29949d7e04fbc0d5e15952bd3 Mon Sep 17 00:00:00 2001 From: Daniel Wirtz Date: Sat, 12 Jun 2021 00:08:10 +0200 Subject: [PATCH 2/4] Update src/definitions.ts Co-authored-by: Max Graey --- src/definitions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/definitions.ts b/src/definitions.ts index 6d587dcd87..47feee83ae 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -639,7 +639,7 @@ export class TSDBuilder extends ExportsWalker { sb.push("export function __collect(): usize;\n"); sb.push("export const __rtti_base: usize;\n"); } - sb.push("export const __setArgumentsLength: ((n: i32) => usize) | undefined;\n"); + sb.push("export const __setArgumentsLength: ((n: i32) => void) | undefined;\n"); return this.sb.join(""); } } From 501153535725bb8ef60032eed550b3d298d3f97b Mon Sep 17 00:00:00 2001 From: Daniel Wirtz Date: Sat, 12 Jun 2021 00:08:18 +0200 Subject: [PATCH 3/4] Update src/definitions.ts Co-authored-by: Max Graey --- src/definitions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/definitions.ts b/src/definitions.ts index 47feee83ae..aca4544d6a 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -636,7 +636,7 @@ export class TSDBuilder extends ExportsWalker { sb.push("export function __new(size: usize, id: u32): usize;\n"); sb.push("export function __pin(ptr: usize): usize;\n"); sb.push("export function __unpin(ptr: usize): usize;\n"); - sb.push("export function __collect(): usize;\n"); + sb.push("export function __collect(): void;\n"); sb.push("export const __rtti_base: usize;\n"); } sb.push("export const __setArgumentsLength: ((n: i32) => void) | undefined;\n"); From ff90bf7f5060e7c611829972d7a777693236e2b8 Mon Sep 17 00:00:00 2001 From: dcode Date: Sat, 12 Jun 2021 00:09:47 +0200 Subject: [PATCH 4/4] __unpin as well --- src/definitions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/definitions.ts b/src/definitions.ts index aca4544d6a..cdf6749d06 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -635,7 +635,7 @@ export class TSDBuilder extends ExportsWalker { if (options.exportRuntime) { sb.push("export function __new(size: usize, id: u32): usize;\n"); sb.push("export function __pin(ptr: usize): usize;\n"); - sb.push("export function __unpin(ptr: usize): usize;\n"); + sb.push("export function __unpin(ptr: usize): void;\n"); sb.push("export function __collect(): void;\n"); sb.push("export const __rtti_base: usize;\n"); }