mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 15:12:12 +00:00
Add support for the 'mutable-global' proposal behind a feature flag
This commit is contained in:
parent
1bf0ca6525
commit
27f0621ee9
@ -379,8 +379,8 @@ exports.main = function main(argv, options, callback) {
|
||||
if (typeof features === "string") features = features.split(",");
|
||||
for (let i = 0, k = features.length; i < k; ++i) {
|
||||
let name = features[i].trim();
|
||||
let flag = assemblyscript["FEATURE_" + name.toUpperCase()];
|
||||
if (!flag) return callback(Error("Feature '" + name + "' is invalid."));
|
||||
let flag = assemblyscript["FEATURE_" + name.replace(/\-/g, "_").toUpperCase()];
|
||||
if (!flag) return callback(Error("Feature '" + name + "' is unknown."));
|
||||
assemblyscript.enableFeature(compilerOptions, flag);
|
||||
}
|
||||
}
|
||||
|
@ -150,7 +150,13 @@
|
||||
"type": "string"
|
||||
},
|
||||
"feature": {
|
||||
"desc": "Enables additional (experimental) WebAssembly features.",
|
||||
"desc": [
|
||||
"Enables additional (experimental) WebAssembly features.",
|
||||
"",
|
||||
" sign-extension Enables sign-extension operations",
|
||||
" mutable-global Enables mutable global imports and exports",
|
||||
""
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"measure": {
|
||||
|
2
dist/asc.js
vendored
2
dist/asc.js
vendored
File diff suppressed because one or more lines are too long
2
dist/asc.js.map
vendored
2
dist/asc.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/assemblyscript.js
vendored
2
dist/assemblyscript.js
vendored
File diff suppressed because one or more lines are too long
2
dist/assemblyscript.js.map
vendored
2
dist/assemblyscript.js.map
vendored
File diff suppressed because one or more lines are too long
@ -207,7 +207,9 @@ export const enum Feature {
|
||||
/** No additional features. */
|
||||
NONE = 0,
|
||||
/** Sign extension operations. */
|
||||
SIGNEXT = 1 << 0 // see: https://github.com/WebAssembly/sign-extension-ops
|
||||
SIGN_EXTENSION = 1 << 0, // see: https://github.com/WebAssembly/sign-extension-ops
|
||||
/** Mutable global imports and exports. */
|
||||
MUTABLE_GLOBAL = 1 << 1 // see: https://github.com/WebAssembly/mutable-global
|
||||
}
|
||||
|
||||
/** Indicates the desired kind of a conversion. */
|
||||
@ -551,7 +553,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
if (global.is(CommonFlags.AMBIENT)) {
|
||||
|
||||
// constant global
|
||||
if (isConstant) {
|
||||
if (isConstant || this.options.hasFeature(Feature.MUTABLE_GLOBAL)) {
|
||||
global.set(CommonFlags.MODULE_IMPORT);
|
||||
module.addGlobalImport(
|
||||
global.internalName,
|
||||
@ -768,7 +770,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
|
||||
// export values if the enum is exported
|
||||
if (element.is(CommonFlags.MODULE_EXPORT)) {
|
||||
if (member.is(CommonFlags.INLINED)) {
|
||||
if (member.is(CommonFlags.INLINED) || this.options.hasFeature(Feature.MUTABLE_GLOBAL)) {
|
||||
module.addGlobalExport(member.internalName, mangleExportName(member));
|
||||
} else if (valueDeclaration) {
|
||||
this.warning(
|
||||
@ -6811,7 +6813,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
switch (type.kind) {
|
||||
case TypeKind.I8: {
|
||||
if (flow.canOverflow(expr, type)) {
|
||||
expr = this.options.hasFeature(Feature.SIGNEXT)
|
||||
expr = this.options.hasFeature(Feature.SIGN_EXTENSION)
|
||||
? module.createUnary(UnaryOp.ExtendI8ToI32, expr)
|
||||
: module.createBinary(BinaryOp.ShrI32,
|
||||
module.createBinary(BinaryOp.ShlI32,
|
||||
@ -6825,7 +6827,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
case TypeKind.I16: {
|
||||
if (flow.canOverflow(expr, type)) {
|
||||
expr = this.options.hasFeature(Feature.SIGNEXT)
|
||||
expr = this.options.hasFeature(Feature.SIGN_EXTENSION)
|
||||
? module.createUnary(UnaryOp.ExtendI16ToI32, expr)
|
||||
: module.createBinary(BinaryOp.ShrI32,
|
||||
module.createBinary(BinaryOp.ShlI32,
|
||||
|
@ -131,7 +131,9 @@ export function setGlobalAlias(options: Options, name: string, alias: string): v
|
||||
}
|
||||
|
||||
/** Sign extension operations. */
|
||||
export const FEATURE_SIGNEXT = Feature.SIGNEXT;
|
||||
export const FEATURE_SIGN_EXTENSION = Feature.SIGN_EXTENSION;
|
||||
/** Mutable global imports and exports. */
|
||||
export const FEATURE_MUTABLE_GLOBAL = Feature.MUTABLE_GLOBAL;
|
||||
|
||||
/** Enables a specific feature. */
|
||||
export function enableFeature(options: Options, feature: Feature): void {
|
||||
|
Loading…
x
Reference in New Issue
Block a user