Skip to content

Commit

Permalink
Unify reference types (#2689)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Apr 22, 2023
1 parent 5e3be1e commit b248254
Show file tree
Hide file tree
Showing 23 changed files with 367 additions and 315 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -74,7 +74,7 @@ jobs:
- uses: dcodeIO/setup-node-nvm@master
with:
node-mirror: https://nodejs.org/download/v8-canary/
node-version: 19.0.0-v8-canary202209029fc5a9347b
node-version: 21.0.0-v8-canary20230419061e93e884
- name: Install dependencies
run: npm ci --no-audit
- name: Build
Expand Down
4 changes: 2 additions & 2 deletions cli/index.js
Expand Up @@ -372,7 +372,7 @@ export async function main(argv, options) {
let name = features[i].trim();
let flag = assemblyscript[`FEATURE_${toUpperSnakeCase(name)}`];
if (!flag) return prepareResult(Error(`Feature '${name}' is unknown.`));
assemblyscript.disableFeature(compilerOptions, flag);
assemblyscript.setFeature(compilerOptions, flag, false);
}
}

Expand All @@ -383,7 +383,7 @@ export async function main(argv, options) {
let name = features[i].trim();
let flag = assemblyscript[`FEATURE_${toUpperSnakeCase(name)}`];
if (!flag) return prepareResult(Error(`Feature '${name}' is unknown.`));
assemblyscript.enableFeature(compilerOptions, flag);
assemblyscript.setFeature(compilerOptions, flag, true);
}
}

Expand Down
36 changes: 18 additions & 18 deletions src/builtins.ts
Expand Up @@ -3523,7 +3523,7 @@ function builtin_i31_new(ctx: BuiltinFunctionContext): ExpressionRef {
) return module.unreachable();
let operands = ctx.operands;
let arg0 = compiler.compileExpression(operands[0], Type.i32, Constraints.ConvImplicit);
compiler.currentType = Type.i31ref;
compiler.currentType = Type.i31;
return module.i31_new(arg0);
}
builtinFunctions.set(BuiltinNames.i31_new, builtin_i31_new);
Expand All @@ -3536,7 +3536,7 @@ function builtin_i31_get(ctx: BuiltinFunctionContext): ExpressionRef {
checkArgsRequired(ctx, 1)
) return module.unreachable();
let operands = ctx.operands;
let arg0 = compiler.compileExpression(operands[0], Type.i31ref, Constraints.ConvImplicit);
let arg0 = compiler.compileExpression(operands[0], Type.i31.asNullable(), Constraints.ConvImplicit);
if (ctx.contextualType.is(TypeFlags.Unsigned)) {
compiler.currentType = Type.u32;
return module.i31_get(arg0, false);
Expand Down Expand Up @@ -3653,14 +3653,14 @@ function builtin_assert(ctx: BuiltinFunctionContext): 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.Anyref:
case TypeKind.Eqref:
case TypeKind.Structref:
case TypeKind.Arrayref:
case TypeKind.I31ref:
case TypeKind.Stringref:
case TypeKind.Func:
case TypeKind.Extern:
case TypeKind.Any:
case TypeKind.Eq:
case TypeKind.Struct:
case TypeKind.Array:
case TypeKind.I31:
case TypeKind.String:
case TypeKind.StringviewWTF8:
case TypeKind.StringviewWTF16:
case TypeKind.StringviewIter: return module.if(module.ref_is_null(arg0), abort);
Expand Down Expand Up @@ -3734,14 +3734,14 @@ function builtin_assert(ctx: BuiltinFunctionContext): ExpressionRef {
);
return ret;
}
case TypeKind.Funcref:
case TypeKind.Externref:
case TypeKind.Anyref:
case TypeKind.Eqref:
case TypeKind.Structref:
case TypeKind.Arrayref:
case TypeKind.I31ref:
case TypeKind.Stringref:
case TypeKind.Func:
case TypeKind.Extern:
case TypeKind.Any:
case TypeKind.Eq:
case TypeKind.Struct:
case TypeKind.Array:
case TypeKind.I31:
case TypeKind.String:
case TypeKind.StringviewWTF8:
case TypeKind.StringviewWTF16:
case TypeKind.StringviewIter: {
Expand Down
41 changes: 22 additions & 19 deletions src/common.ts
Expand Up @@ -81,7 +81,9 @@ export const enum CommonFlags {
// Other

/** Is quoted. */
Quoted = 1 << 30
Quoted = 1 << 30,
/** Is internally nullable. */
InternallyNullable = 1 << 31
}

/** Path delimiter inserted between file system levels. */
Expand Down Expand Up @@ -126,17 +128,17 @@ 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 anyref = "anyref";
export const eqref = "eqref";
export const structref = "structref";
export const arrayref = "arrayref";
export const i31ref = "i31ref";
export const stringref = "stringref";
export const stringview_wtf8 = "stringview_wtf8";
export const stringview_wtf16 = "stringview_wtf16";
export const stringview_iter = "stringview_iter";
export const ref_func = "ref_func";
export const ref_extern = "ref_extern";
export const ref_any = "ref_any";
export const ref_eq = "ref_eq";
export const ref_struct = "ref_struct";
export const ref_array = "ref_array";
export const ref_i31 = "ref_i31";
export const ref_string = "ref_string";
export const ref_stringview_wtf8 = "ref_stringview_wtf8";
export const ref_stringview_wtf16 = "ref_stringview_wtf16";
export const ref_stringview_iter = "ref_stringview_iter";
export const i8x16 = "i8x16";
export const u8x16 = "u8x16";
export const i16x8 = "i16x8";
Expand Down Expand Up @@ -207,13 +209,14 @@ 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 Anyref = "Anyref";
export const Eqref = "Eqref";
export const Structref = "Structref";
export const Arrayref = "Arrayref";
export const I31ref = "I31ref";
export const RefFunc = "RefFunc";
export const RefExtern = "RefExtern";
export const RefAny = "RefAny";
export const RefEq = "RefEq";
export const RefStruct = "RefStruct";
export const RefArray = "RefArray";
export const RefI31 = "RefI31";
export const RefString = "RefString";
export const String = "String";
export const RegExp = "RegExp";
export const Object = "Object";
Expand Down

0 comments on commit b248254

Please sign in to comment.