diff --git a/lib/loader/README.md b/lib/loader/README.md index 25efbf88..141256dd 100644 --- a/lib/loader/README.md +++ b/lib/loader/README.md @@ -101,7 +101,7 @@ Besides demangling classes exported from your entry file to a handy object struc ``` * **__start**(): `void`
- Explicit start function if the `--explicit-start` option is used. Must be called before any other exports if present. + Explicit start function if the `--explicitStart` option is used. Must be called before any other exports if present. * **__allocString**(str: `string`): `number`
Allocates a new string in the module's memory and returns a reference (pointer) to it. diff --git a/src/compiler.ts b/src/compiler.ts index 7c9e5e52..cedc477c 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -2660,11 +2660,7 @@ export class Compiler extends DiagnosticEmitter { // === Expressions ============================================================================== - /** - * Compiles the value of an inlined constant element. - * @param retainType If true, the annotated type of the constant is retained. Otherwise, the value - * is precomputed according to context. - */ + /** Compiles the value of an inlined constant element. */ compileInlineConstant( element: VariableLikeElement, contextualType: Type, @@ -6717,27 +6713,35 @@ export class Compiler extends DiagnosticEmitter { for (let i = numArguments; i < maxArguments; ++i) { let initializer = parameterNodes[i].initializer; if (initializer) { - let resolved: Element | null; - if ( - nodeIsConstantValue(initializer.kind) || - ( - (resolved = this.resolver.resolveExpression(initializer, instance.flow, parameterTypes[i])) && - ( - resolved.kind == ElementKind.GLOBAL - // resolved.kind == ElementKind.FUNCTION_TARGET - ) - ) - ) { // inline into the call - let previousFlow = this.currentFlow; - this.currentFlow = instance.flow; + if (nodeIsConstantValue(initializer.kind)) { operands.push(this.compileExpression( parameterNodes[i].initializer, parameterTypes[i], ContextualFlags.IMPLICIT )); - this.currentFlow = previousFlow; continue; } + let resolved = this.resolver.resolveExpression(initializer, instance.flow, parameterTypes[i]); + if (resolved) { + if (resolved.kind == ElementKind.GLOBAL) { + let global = resolved; + if (this.compileGlobal(global)) { + if (global.is(CommonFlags.INLINED)) { + operands.push( + this.compileInlineConstant(global, parameterTypes[i], ContextualFlags.IMPLICIT) + ); + } else { + operands.push( + this.convertExpression( + module.global_get(global.internalName, global.type.toNativeType()), + global.type, parameterTypes[i], false, false, initializer + ) + ); + } + continue; + } + } + } } operands.push(parameterTypes[i].toNativeZero(module)); allOptionalsAreConstant = false;