Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ under the licensing terms detailed in LICENSE:
* Peter Salomonsen <[email protected]>
* ookangzheng <[email protected]>
* yjhmelody <[email protected]>
* bnbarak <[email protected]>

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)
1 change: 1 addition & 0 deletions cli/asc.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,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);
if (!opts.stackSize && opts.runtime == "incremental") {
opts.stackSize = assemblyscript.DEFAULT_STACK_SIZE;
}
Expand Down
3 changes: 3 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
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
6 changes: 4 additions & 2 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ 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";

/** Hinted optimize level. Not applied by the compiler itself. */
optimizeLevelHint: i32 = 0;
Expand Down Expand Up @@ -1509,7 +1511,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 +7535,7 @@ export class Compiler extends DiagnosticEmitter {
expr = module.local_tee(local.index, expr, ftype.isManaged);
}
}

return expr;
}

Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ 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;
}

/** Sign extension operations. */
export const FEATURE_SIGN_EXTENSION = Feature.SIGN_EXTENSION;
/** Mutable global imports and exports. */
Expand Down
19 changes: 17 additions & 2 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,15 @@ 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 @@ -1013,6 +1022,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(bundleMajorVersion));
this.registerConstantInteger(CommonNames.ASC_VERSION_MINOR, Type.i32,
i64_new(bundleMinorVersion));
this.registerConstantInteger(CommonNames.ASC_VERSION_PATCH, Type.i32,
i64_new(bundlePatchVersion));

// register feature hints
this.registerConstantInteger(CommonNames.ASC_FEATURE_SIGN_EXTENSION, Type.bool,
Expand Down Expand Up @@ -3084,8 +3099,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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