mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 23:12:19 +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(",");
|
if (typeof features === "string") features = features.split(",");
|
||||||
for (let i = 0, k = features.length; i < k; ++i) {
|
for (let i = 0, k = features.length; i < k; ++i) {
|
||||||
let name = features[i].trim();
|
let name = features[i].trim();
|
||||||
let flag = assemblyscript["FEATURE_" + name.toUpperCase()];
|
let flag = assemblyscript["FEATURE_" + name.replace(/\-/g, "_").toUpperCase()];
|
||||||
if (!flag) return callback(Error("Feature '" + name + "' is invalid."));
|
if (!flag) return callback(Error("Feature '" + name + "' is unknown."));
|
||||||
assemblyscript.enableFeature(compilerOptions, flag);
|
assemblyscript.enableFeature(compilerOptions, flag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,13 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"feature": {
|
"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"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"measure": {
|
"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. */
|
/** No additional features. */
|
||||||
NONE = 0,
|
NONE = 0,
|
||||||
/** Sign extension operations. */
|
/** 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. */
|
/** Indicates the desired kind of a conversion. */
|
||||||
@ -551,7 +553,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
if (global.is(CommonFlags.AMBIENT)) {
|
if (global.is(CommonFlags.AMBIENT)) {
|
||||||
|
|
||||||
// constant global
|
// constant global
|
||||||
if (isConstant) {
|
if (isConstant || this.options.hasFeature(Feature.MUTABLE_GLOBAL)) {
|
||||||
global.set(CommonFlags.MODULE_IMPORT);
|
global.set(CommonFlags.MODULE_IMPORT);
|
||||||
module.addGlobalImport(
|
module.addGlobalImport(
|
||||||
global.internalName,
|
global.internalName,
|
||||||
@ -768,7 +770,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
|
|
||||||
// export values if the enum is exported
|
// export values if the enum is exported
|
||||||
if (element.is(CommonFlags.MODULE_EXPORT)) {
|
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));
|
module.addGlobalExport(member.internalName, mangleExportName(member));
|
||||||
} else if (valueDeclaration) {
|
} else if (valueDeclaration) {
|
||||||
this.warning(
|
this.warning(
|
||||||
@ -6811,7 +6813,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
switch (type.kind) {
|
switch (type.kind) {
|
||||||
case TypeKind.I8: {
|
case TypeKind.I8: {
|
||||||
if (flow.canOverflow(expr, type)) {
|
if (flow.canOverflow(expr, type)) {
|
||||||
expr = this.options.hasFeature(Feature.SIGNEXT)
|
expr = this.options.hasFeature(Feature.SIGN_EXTENSION)
|
||||||
? module.createUnary(UnaryOp.ExtendI8ToI32, expr)
|
? module.createUnary(UnaryOp.ExtendI8ToI32, expr)
|
||||||
: module.createBinary(BinaryOp.ShrI32,
|
: module.createBinary(BinaryOp.ShrI32,
|
||||||
module.createBinary(BinaryOp.ShlI32,
|
module.createBinary(BinaryOp.ShlI32,
|
||||||
@ -6825,7 +6827,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
case TypeKind.I16: {
|
case TypeKind.I16: {
|
||||||
if (flow.canOverflow(expr, type)) {
|
if (flow.canOverflow(expr, type)) {
|
||||||
expr = this.options.hasFeature(Feature.SIGNEXT)
|
expr = this.options.hasFeature(Feature.SIGN_EXTENSION)
|
||||||
? module.createUnary(UnaryOp.ExtendI16ToI32, expr)
|
? module.createUnary(UnaryOp.ExtendI16ToI32, expr)
|
||||||
: module.createBinary(BinaryOp.ShrI32,
|
: module.createBinary(BinaryOp.ShrI32,
|
||||||
module.createBinary(BinaryOp.ShlI32,
|
module.createBinary(BinaryOp.ShlI32,
|
||||||
|
@ -131,7 +131,9 @@ export function setGlobalAlias(options: Options, name: string, alias: string): v
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Sign extension operations. */
|
/** 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. */
|
/** Enables a specific feature. */
|
||||||
export function enableFeature(options: Options, feature: Feature): void {
|
export function enableFeature(options: Options, feature: Feature): void {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user