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
11 changes: 10 additions & 1 deletion 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,7 +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, exports.version);
assemblyscript.setBundleVersion(compilerOptions, bundleMajorVersion, bundleMinorVersion, bundlePatchVersion);
if (!opts.stackSize && opts.runtime == "incremental") {
opts.stackSize = assemblyscript.DEFAULT_STACK_SIZE;
}
Expand Down
8 changes: 6 additions & 2 deletions src/compiler.ts
Expand Up @@ -251,8 +251,12 @@ export class Options {
exportRuntime: bool = false;
/** Stack size in bytes, if using a stack. */
stackSize: i32 = 0;
/* Bundle version from the root package.json */
bundleVersion: string = "0.0.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
13 changes: 10 additions & 3 deletions src/index.ts
Expand Up @@ -142,9 +142,16 @@ export function setStackSize(options: Options, stackSize: i32): void {
options.stackSize = stackSize;
}

/** Sets the bundle version. */
export function setBundleVersion(options: Options, bundleVersion: string): void {
options.bundleVersion = bundleVersion;
/** 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. */
Expand Down
15 changes: 3 additions & 12 deletions src/program.ts
Expand Up @@ -943,15 +943,6 @@ export class Program extends DiagnosticEmitter {

var options = this.options;

// Semantic version from root package.json
let bundleMinorVersion = 0, bundleMajorVersion = 0, bundlePatchVersion = 0;
const versionParts = (options.bundleVersion || "").split(".");
if(versionParts.length === 3) {
bundleMajorVersion = i32(parseInt(versionParts[0]));
bundleMinorVersion = i32(parseInt(versionParts[1]));
bundlePatchVersion = i32(parseInt(versionParts[2]));
}

// register native types
this.registerNativeType(CommonNames.i8, Type.i8);
this.registerNativeType(CommonNames.i16, Type.i16);
Expand Down Expand Up @@ -1023,11 +1014,11 @@ export class Program extends DiagnosticEmitter {
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(bundleMajorVersion));
i64_new(options.bundleMajorVersion));
this.registerConstantInteger(CommonNames.ASC_VERSION_MINOR, Type.i32,
i64_new(bundleMinorVersion));
i64_new(options.bundleMinorVersion));
this.registerConstantInteger(CommonNames.ASC_VERSION_PATCH, Type.i32,
i64_new(bundlePatchVersion));
i64_new(options.bundlePatchVersion));

// register feature hints
this.registerConstantInteger(CommonNames.ASC_FEATURE_SIGN_EXTENSION, Type.bool,
Expand Down