Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asc version global variables #1765

Merged
merged 11 commits into from
Mar 30, 2021
3 changes: 2 additions & 1 deletion NOTICE
Expand Up @@ -36,6 +36,7 @@ under the licensing terms detailed in LICENSE:
* Peter Salomonsen <petersalomonsen@runbox.com>
* ookangzheng <git-ed@runbox.no>
* yjhmelody <yjh465402634@gmail.com>
* bnbarak <bn.barak@gmail.com>

Portions of this software are derived from third-party works licensed under
the following terms:
Expand All @@ -61,6 +62,6 @@ the following terms:
The 3-Clause BSD License (https://opensource.org/licenses/BSD-3-Clause)

* Arm Optimized Routines: https://github.com/ARM-software/optimized-routines

Copyright (c) Arm Limited
The MIT License (https://opensource.org/licenses/MIT)
10 changes: 10 additions & 0 deletions cli/asc.js
Expand Up @@ -245,6 +245,15 @@ exports.main = function main(argv, options, callback) {
options = {};
}

// Bundle semantic version
let bundleMinorVersion = 0, bundleMajorVersion = 0, bundlePatchVersion = 0;
const versionParts = (exports.version || "").split(".");
if(versionParts.length === 3) {
MaxGraey marked this conversation as resolved.
Show resolved Hide resolved
bundleMajorVersion = parseInt(versionParts[0]);
bundleMinorVersion = parseInt(versionParts[1]);
bundlePatchVersion = parseInt(versionParts[2]);
bnbarak marked this conversation as resolved.
Show resolved Hide resolved
}

const stdout = options.stdout || process.stdout;
const stderr = options.stderr || process.stderr;
const readFile = options.readFile || readFileNode;
Expand Down Expand Up @@ -422,6 +431,7 @@ exports.main = function main(argv, options, callback) {
assemblyscript.setPedantic(compilerOptions, opts.pedantic);
assemblyscript.setLowMemoryLimit(compilerOptions, opts.lowMemoryLimit >>> 0);
assemblyscript.setExportRuntime(compilerOptions, opts.exportRuntime);
assemblyscript.setBundleVersion(compilerOptions, bundleMajorVersion, bundleMinorVersion, bundlePatchVersion);
if (!opts.stackSize && opts.runtime == "incremental") {
opts.stackSize = assemblyscript.DEFAULT_STACK_SIZE;
}
Expand Down
3 changes: 3 additions & 0 deletions src/common.ts
Expand Up @@ -178,6 +178,9 @@ export namespace CommonNames {
export const ASC_FEATURE_MULTI_VALUE = "ASC_FEATURE_MULTI_VALUE";
export const ASC_FEATURE_GC = "ASC_FEATURE_GC";
export const ASC_FEATURE_MEMORY64 = "ASC_FEATURE_MEMORY64";
export const ASC_VERSION_MAJOR = "ASC_VERSION_MAJOR";
export const ASC_VERSION_MINOR = "ASC_VERSION_MINOR";
export const ASC_VERSION_PATCH = "ASC_VERSION_PATCH";
// classes
export const I8 = "I8";
export const I16 = "I16";
Expand Down
10 changes: 8 additions & 2 deletions src/compiler.ts
Expand Up @@ -251,6 +251,12 @@ export class Options {
exportRuntime: bool = false;
/** Stack size in bytes, if using a stack. */
stackSize: i32 = 0;
/** Semantic major bundle version from root package.json */
bundleMajorVersion: i32 = 0;
/** Semantic minor bundle version from root package.json */
bundleMinorVersion: i32 = 0;
/** Semantic patch bundle version from root package.json */
bundlePatchVersion: i32 = 0;

/** Hinted optimize level. Not applied by the compiler itself. */
optimizeLevelHint: i32 = 0;
Expand Down Expand Up @@ -1509,7 +1515,7 @@ export class Compiler extends DiagnosticEmitter {
if (!this.compileFunctionBody(instance, stmts)) {
stmts.push(module.unreachable());
}

this.currentFlow = previousFlow;

// create the function
Expand Down Expand Up @@ -7533,7 +7539,7 @@ export class Compiler extends DiagnosticEmitter {
expr = module.local_tee(local.index, expr, ftype.isManaged);
}
}

return expr;
}

Expand Down
12 changes: 12 additions & 0 deletions src/index.ts
Expand Up @@ -142,6 +142,18 @@ export function setStackSize(options: Options, stackSize: i32): void {
options.stackSize = stackSize;
}

/** Sets the bundle semantic version. */
export function setBundleVersion(
options: Options,
bundleMajorVersion: i32,
bundleMinorVersion: i32,
bundlePatchVersion: i32,
): void {
options.bundleMajorVersion = bundleMajorVersion;
options.bundleMinorVersion = bundleMinorVersion;
options.bundlePatchVersion = bundlePatchVersion;
}

/** Sign extension operations. */
export const FEATURE_SIGN_EXTENSION = Feature.SIGN_EXTENSION;
/** Mutable global imports and exports. */
Expand Down
10 changes: 8 additions & 2 deletions src/program.ts
Expand Up @@ -1013,6 +1013,12 @@ export class Program extends DiagnosticEmitter {
i64_new(options.lowMemoryLimit, 0));
this.registerConstantInteger(CommonNames.ASC_EXPORT_RUNTIME, Type.bool,
i64_new(options.exportRuntime ? 1 : 0, 0));
this.registerConstantInteger(CommonNames.ASC_VERSION_MAJOR, Type.i32,
i64_new(options.bundleMajorVersion));
this.registerConstantInteger(CommonNames.ASC_VERSION_MINOR, Type.i32,
i64_new(options.bundleMinorVersion));
this.registerConstantInteger(CommonNames.ASC_VERSION_PATCH, Type.i32,
i64_new(options.bundlePatchVersion));

// register feature hints
this.registerConstantInteger(CommonNames.ASC_FEATURE_SIGN_EXTENSION, Type.bool,
Expand Down Expand Up @@ -3084,8 +3090,8 @@ export class File extends Element {

/** Creates an imported namespace from this file. */
asAliasNamespace(
name: string,
parent: Element,
name: string,
parent: Element,
localIdentifier: IdentifierExpression
): Namespace {
var declaration = this.program.makeNativeNamespaceDeclaration(name);
Expand Down
4 changes: 4 additions & 0 deletions tests/compiler/asc-constants.ts
Expand Up @@ -16,3 +16,7 @@ ASC_FEATURE_REFERENCE_TYPES;
ASC_FEATURE_MULTI_VALUE;
ASC_FEATURE_GC;
ASC_FEATURE_MEMORY64;

ASC_VERSION_MAJOR;
ASC_VERSION_MINOR;
ASC_VERSION_PATCH;
9 changes: 9 additions & 0 deletions tests/compiler/asc-constants.untouched.wat
Expand Up @@ -19,6 +19,9 @@
(global $~lib/ASC_FEATURE_MULTI_VALUE i32 (i32.const 0))
(global $~lib/ASC_FEATURE_GC i32 (i32.const 0))
(global $~lib/ASC_FEATURE_MEMORY64 i32 (i32.const 0))
(global $~lib/ASC_VERSION_MAJOR i32 (i32.const 0))
(global $~lib/ASC_VERSION_MINOR i32 (i32.const 0))
(global $~lib/ASC_VERSION_PATCH i32 (i32.const 0))
(global $~lib/memory/__data_end i32 (i32.const 8))
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 16392))
(global $~lib/memory/__heap_base i32 (i32.const 16392))
Expand Down Expand Up @@ -59,6 +62,12 @@
drop
i32.const 0
drop
i32.const 0
drop
i32.const 0
drop
i32.const 0
drop
)
(func $~start
call $start:asc-constants
Expand Down