Add a way to ensure that lazy globals are resolved, fixes #355

This only affects static fields that currently must have a type annotation, while it wouldn't work if there wasn't an annotated type, like on normal globals, which aren't compiled lazily, though. Must be revisted if requirements on type annotations on fields ever become relaxed.
This commit is contained in:
dcodeIO
2018-12-01 13:31:37 +01:00
parent a661ff7d89
commit 0e33806cf6
4 changed files with 39 additions and 21 deletions

View File

@ -16,7 +16,8 @@ import {
import {
Options,
Feature
Feature,
Compiler
} from "./compiler";
import {
@ -730,19 +731,19 @@ export class Program extends DiagnosticEmitter {
/** Sets a constant integer value. */
setConstantInteger(globalName: string, type: Type, value: I64): void {
assert(type.is(TypeFlags.INTEGER));
this.elementsLookup.set(globalName,
new Global(this, globalName, globalName, type, null, DecoratorFlags.NONE)
.withConstantIntegerValue(value)
);
var global = new Global(this, globalName, globalName, type, null, DecoratorFlags.NONE)
.withConstantIntegerValue(value);
global.set(CommonFlags.RESOLVED);
this.elementsLookup.set(globalName, global);
}
/** Sets a constant float value. */
setConstantFloat(globalName: string, type: Type, value: f64): void {
assert(type.is(TypeFlags.FLOAT));
this.elementsLookup.set(globalName,
new Global(this, globalName, globalName, type, null, DecoratorFlags.NONE)
.withConstantFloatValue(value)
);
var global = new Global(this, globalName, globalName, type, null, DecoratorFlags.NONE)
.withConstantFloatValue(value);
global.set(CommonFlags.RESOLVED);
this.elementsLookup.set(globalName, global);
}
/** Tries to locate an import by traversing exports and queued exports. */