Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ jobs:
- uses: dcodeIO/setup-node-nvm@master
with:
node-mirror: https://nodejs.org/download/v8-canary/
node-version: "15.0.0-v8-canary202007077c53168ead"
node-version: "node"
- name: Install dependencies
run: npm ci --no-audit
- name: Clean distribution files
run: npm run clean
- name: Test experimental features
env:
ASC_FEATURES: mutable-globals,threads,reference-types,bigint-integration
ASC_FEATURES: mutable-globals,threads,reference-types,bigint-integration,anyref
run: |
npm run test:compiler rt/flags features/js-bigint-integration features/reference-types features/threads
test-runtimes:
Expand Down
3 changes: 2 additions & 1 deletion cli/asc.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@
"description": [
"Enables WebAssembly features being disabled by default.",
"",
" sign-extension Sign-extension operations",
" bulk-memory Bulk memory operations.",
" simd SIMD types and operations.",
" threads Threading and atomic operations.",
" reference-types Reference types and operations.",
" anyref Anyref type (without GC).",
""
],
"TODO_doesNothingYet": [
Expand All @@ -209,6 +209,7 @@
"Disables WebAssembly features being enabled by default.",
"",
" mutable-globals Mutable global imports and exports.",
" sign-extension Sign-extension operations",
""
],
"type": "S",
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"url": "https://github.com/AssemblyScript/assemblyscript/issues"
},
"dependencies": {
"binaryen": "96.0.0-nightly.20200911",
"binaryen": "96.0.0-nightly.20200915",
"long": "^4.0.0",
"source-map-support": "^0.5.19",
"ts-node": "^6.2.0"
Expand Down
51 changes: 24 additions & 27 deletions src/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -968,39 +968,16 @@ function builtin_nameof(ctx: BuiltinContext): ExpressionRef {
return module.unreachable();
}
var value: string;
if (resultType.isReference) {
if (resultType.isInternalReference) {
let classReference = resultType.getClass();
if (classReference) {
value = classReference.name;
} else {
let signatureReference = resultType.getSignature();
if (signatureReference) {
value = "Function";
} else {
assert(resultType.isExternalReference);
value = "Externref";
}
assert(resultType.getSignature());
value = "Function";
}
} else {
switch (resultType.kind) {
case TypeKind.BOOL: { value = "bool"; break; }
case TypeKind.I8: { value = "i8"; break; }
case TypeKind.U8: { value = "u8"; break; }
case TypeKind.I16: { value = "i16"; break; }
case TypeKind.U16: { value = "u16"; break; }
case TypeKind.I32: { value = "i32"; break; }
case TypeKind.U32: { value = "u32"; break; }
case TypeKind.F32: { value = "f32"; break; }
case TypeKind.I64: { value = "i64"; break; }
case TypeKind.U64: { value = "u64"; break; }
case TypeKind.F64: { value = "f64"; break; }
case TypeKind.ISIZE: { value = "isize"; break; }
case TypeKind.USIZE: { value = "usize"; break; }
case TypeKind.V128: { value = "v128"; break; }
case TypeKind.EXTERNREF: { value = "externref"; break; }
default: assert(false);
case TypeKind.VOID: { value = "void"; break; }
}
value = resultType.toString();
}
return compiler.ensureStaticString(value);
}
Expand Down Expand Up @@ -2775,6 +2752,11 @@ function builtin_assert(ctx: BuiltinContext): ExpressionRef {
// TODO: also check for NaN in float assertions, as in `Boolean(NaN) -> false`?
case TypeKind.F32: return module.if(module.binary(BinaryOp.EqF32, arg0, module.f32(0)), abort);
case TypeKind.F64: return module.if(module.binary(BinaryOp.EqF64, arg0, module.f64(0)), abort);
case TypeKind.FUNCREF:
case TypeKind.EXTERNREF:
case TypeKind.EXNREF:
case TypeKind.ANYREF: return module.if(module.ref_is_null(arg0), abort);

}
} else {
compiler.currentType = type.nonNullableType;
Expand Down Expand Up @@ -2852,6 +2834,21 @@ function builtin_assert(ctx: BuiltinContext): ExpressionRef {
flow.freeTempLocal(temp);
return ret;
}
case TypeKind.FUNCREF:
case TypeKind.EXTERNREF:
case TypeKind.EXNREF:
case TypeKind.ANYREF: {
let temp = flow.getTempLocal(type);
let ret = module.if(
module.ref_is_null(
module.local_tee(temp.index, arg0)
),
abort,
module.local_get(temp.index, NativeType.F64)
);
flow.freeTempLocal(temp);
return ret;
}
}
}
compiler.error(
Expand Down
7 changes: 7 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ export namespace CommonNames {
export const f32 = "f32";
export const f64 = "f64";
export const v128 = "v128";
export const funcref = "funcref";
export const externref = "externref";
export const exnref = "exnref";
export const anyref = "anyref";
export const i8x16 = "i8x16";
export const u8x16 = "u8x16";
export const i16x8 = "i16x8";
Expand Down Expand Up @@ -170,6 +173,7 @@ export namespace CommonNames {
export const ASC_FEATURE_TAIL_CALLS = "ASC_FEATURE_TAIL_CALLS";
export const ASC_FEATURE_REFERENCE_TYPES = "ASC_FEATURE_REFERENCE_TYPES";
export const ASC_FEATURE_MULTI_VALUE = "ASC_FEATURE_MULTI_VALUE";
export const ASC_FEATURE_ANYREF = "ASC_FEATURE_ANYREF";
// classes
export const I8 = "I8";
export const I16 = "I16";
Expand All @@ -185,7 +189,10 @@ export namespace CommonNames {
export const F32 = "F32";
export const F64 = "F64";
export const V128 = "V128";
export const Funcref = "Funcref";
export const Externref = "Externref";
export const Exnref = "Exnref";
export const Anyref = "Anyref";
export const String = "String";
export const Array = "Array";
export const StaticArray = "StaticArray";
Expand Down
73 changes: 38 additions & 35 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class Options {
/** Global aliases, mapping alias names as the key to internal names to be aliased as the value. */
globalAliases: Map<string,string> | null = null;
/** Features to activate by default. These are the finished proposals. */
features: Feature = Feature.MUTABLE_GLOBALS;
features: Feature = Feature.MUTABLE_GLOBALS | Feature.SIGN_EXTENSION;
/** If true, disallows unsafe features in user code. */
noUnsafe: bool = false;
/** If true, enables pedantic diagnostics. */
Expand Down Expand Up @@ -405,6 +405,7 @@ export class Compiler extends DiagnosticEmitter {
if (options.hasFeature(Feature.TAIL_CALLS)) featureFlags |= FeatureFlags.TailCall;
if (options.hasFeature(Feature.REFERENCE_TYPES)) featureFlags |= FeatureFlags.ReferenceTypes;
if (options.hasFeature(Feature.MULTI_VALUE)) featureFlags |= FeatureFlags.MultiValue;
if (options.hasFeature(Feature.ANYREF)) featureFlags |= FeatureFlags.Anyref;
module.setFeatures(featureFlags);

// set up the main start function
Expand Down Expand Up @@ -4390,12 +4391,15 @@ export class Compiler extends DiagnosticEmitter {
);
break;
}
case TypeKind.EXTERNREF: {
// TODO: ref.eq
case TypeKind.FUNCREF:
case TypeKind.EXTERNREF:
case TypeKind.EXNREF:
case TypeKind.ANYREF: {
this.error(
DiagnosticCode.Not_implemented_0,
DiagnosticCode.Operation_0_cannot_be_applied_to_type_1,
expression.range,
"ref.eq instruction"
"ref.eq",
commonType.toString()
);
expr = module.unreachable();
break;
Expand Down Expand Up @@ -4491,12 +4495,15 @@ export class Compiler extends DiagnosticEmitter {
);
break;
}
case TypeKind.EXTERNREF: {
// TODO: !ref.eq
case TypeKind.FUNCREF:
case TypeKind.EXTERNREF:
case TypeKind.EXNREF:
case TypeKind.ANYREF: {
this.error(
DiagnosticCode.Not_implemented_0,
DiagnosticCode.Operation_0_cannot_be_applied_to_type_1,
expression.range,
"ref.eq instruction"
"ref.eq",
commonType.toString()
);
expr = module.unreachable();
break;
Expand Down Expand Up @@ -8311,13 +8318,7 @@ export class Compiler extends DiagnosticEmitter {
this.currentType = signatureReference.type.asNullable();
return options.isWasm64 ? module.i64(0) : module.i32(0);
}
// TODO: return null ref for externref or funcref
this.error(
DiagnosticCode.Not_implemented_0,
expression.range,
"ref.null"
);
return module.unreachable();
return this.makeZero(contextualType, expression);
}
this.currentType = options.usizeType;
this.warning(
Expand Down Expand Up @@ -8508,7 +8509,7 @@ export class Compiler extends DiagnosticEmitter {
);
if (!functionInstance || !this.compileFunction(functionInstance)) return module.unreachable();
if (contextualType.isExternalReference) {
this.currentType = Type.externref;
this.currentType = Type.funcref;
return module.ref_func(functionInstance.internalName);
}
let offset = this.ensureRuntimeFunction(functionInstance);
Expand Down Expand Up @@ -10619,7 +10620,17 @@ export class Compiler extends DiagnosticEmitter {
checkTypeSupported(type: Type, reportNode: Node): bool {
switch (type.kind) {
case TypeKind.V128: return this.checkFeatureEnabled(Feature.SIMD, reportNode);
case TypeKind.EXTERNREF: return this.checkFeatureEnabled(Feature.REFERENCE_TYPES, reportNode);
case TypeKind.FUNCREF:
case TypeKind.EXTERNREF:
return this.checkFeatureEnabled(Feature.REFERENCE_TYPES, reportNode);
case TypeKind.EXNREF: {
return this.checkFeatureEnabled(Feature.REFERENCE_TYPES, reportNode)
&& this.checkFeatureEnabled(Feature.EXCEPTION_HANDLING, reportNode);
}
case TypeKind.ANYREF: {
return this.checkFeatureEnabled(Feature.REFERENCE_TYPES, reportNode)
&& this.checkFeatureEnabled(Feature.ANYREF, reportNode);
}
}
let classReference = type.getClass();
if (classReference) {
Expand Down Expand Up @@ -10712,14 +10723,11 @@ export class Compiler extends DiagnosticEmitter {
case TypeKind.F32: return module.f32(0);
case TypeKind.F64: return module.f64(0);
case TypeKind.V128: return module.v128(v128_zero);
case TypeKind.FUNCREF:
case TypeKind.EXTERNREF:
// TODO: return null ref for both externref as well as funcref
this.error(
DiagnosticCode.Not_implemented_0,
reportNode.range,
"ref.null"
);
return module.unreachable();
case TypeKind.EXNREF:
case TypeKind.ANYREF:
return module.ref_null(type.toNativeType());
}
}

Expand Down Expand Up @@ -10824,16 +10832,11 @@ export class Compiler extends DiagnosticEmitter {
module.i64(0xFFFFFFFE, 0xFFDFFFFF) // (0x7FF0000000000000 - 1) << 1
);
}
case TypeKind.EXTERNREF: {
// TODO: non-null object might still be considered falseish
// i.e. a ref to Boolean(false), Number(0), String("") etc.
// TODO: return module.unary(UnaryOp.EqzI32, module.ref_is_null(expr));
this.error(
DiagnosticCode.Not_implemented_0,
reportNode.range,
"ref.is_null"
);
return module.unreachable();
case TypeKind.FUNCREF:
case TypeKind.EXTERNREF:
case TypeKind.EXNREF:
case TypeKind.ANYREF:{
return module.ref_is_null(expr);
}
default: {
assert(false);
Expand Down
14 changes: 14 additions & 0 deletions src/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,10 @@ export class Flow {
case <u32>NativeType.F32: { temps = parentFunction.tempF32s; break; }
case <u32>NativeType.F64: { temps = parentFunction.tempF64s; break; }
case <u32>NativeType.V128: { temps = parentFunction.tempV128s; break; }
case <u32>NativeType.Funcref: { temps = parentFunction.tempFuncrefs; break; }
case <u32>NativeType.Externref: { temps = parentFunction.tempExternrefs; break; }
case <u32>NativeType.Exnref: { temps = parentFunction.tempExnrefs; break; }
case <u32>NativeType.Anyref: { temps = parentFunction.tempAnyrefs; break; }
default: throw new Error("concrete type expected");
}
var local: Local;
Expand Down Expand Up @@ -395,6 +397,12 @@ export class Flow {
else parentFunction.tempV128s = temps = [];
break;
}
case <u32>NativeType.Funcref: {
let tempFuncrefs = parentFunction.tempFuncrefs;
if (tempFuncrefs) temps = tempFuncrefs;
else parentFunction.tempFuncrefs = temps = [];
break;
}
case <u32>NativeType.Externref: {
let tempExternrefs = parentFunction.tempExternrefs;
if (tempExternrefs) temps = tempExternrefs;
Expand All @@ -407,6 +415,12 @@ export class Flow {
else parentFunction.tempExnrefs = temps = [];
break;
}
case <u32>NativeType.Anyref: {
let tempAnyrefs = parentFunction.tempAnyrefs;
if (tempAnyrefs) temps = tempAnyrefs;
else parentFunction.tempAnyrefs = temps = [];
break;
}
default: throw new Error("concrete type expected");
}
assert(local.index >= 0);
Expand Down
3 changes: 2 additions & 1 deletion src/glue/binaryen.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export declare function _BinaryenFeatureExceptionHandling(): BinaryenFeatureFlag
export declare function _BinaryenFeatureTailCall(): BinaryenFeatureFlags;
export declare function _BinaryenFeatureReferenceTypes(): BinaryenFeatureFlags;
export declare function _BinaryenFeatureMultivalue(): BinaryenFeatureFlags;
export declare function _BinaryenFeatureAnyref(): BinaryenFeatureFlags;
export declare function _BinaryenFeatureAll(): BinaryenFeatureFlags;

type BinaryenExpressionId = i32;
Expand Down Expand Up @@ -790,7 +791,7 @@ export declare function _BinaryenMemoryFillSetValue(expr: BinaryenExpressionRef,
export declare function _BinaryenMemoryFillGetSize(expr: BinaryenExpressionRef): BinaryenExpressionRef;
export declare function _BinaryenMemoryFillSetSize(expr: BinaryenExpressionRef, sizeExpr: BinaryenExpressionRef): void;

export declare function _BinaryenRefNull(module: BinaryenModuleRef): BinaryenExpressionRef;
export declare function _BinaryenRefNull(module: BinaryenModuleRef, type: BinaryenType): BinaryenExpressionRef;

export declare function _BinaryenRefIsNull(module: BinaryenModuleRef, valueExpr: BinaryenExpressionRef): BinaryenExpressionRef;
export declare function _BinaryenRefIsNullGetValue(expr: BinaryenExpressionRef): BinaryenExpressionRef;
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ export const FEATURE_TAIL_CALLS = Feature.TAIL_CALLS;
export const FEATURE_REFERENCE_TYPES = Feature.REFERENCE_TYPES;
/** Multi value types. */
export const FEATURE_MULTI_VALUE = Feature.MULTI_VALUE;
/** Anyref type. */
export const FEATURE_ANYREF = Feature.ANYREF;

/** Enables a specific feature. */
export function enableFeature(options: Options, feature: Feature): void {
Expand Down
Loading