Add isFunction and isNullable builtins (#504)

This commit is contained in:
Daniel Wirtz
2019-02-22 01:11:05 +01:00
committed by GitHub
parent 3b5b96f496
commit f318d68383
6 changed files with 321 additions and 208 deletions

View File

@ -76,6 +76,8 @@ export namespace BuiltinSymbols {
export const isReference = "~lib/builtins/isReference";
export const isString = "~lib/builtins/isString";
export const isArray = "~lib/builtins/isArray";
export const isFunction = "~lib/builtins/isFunction";
export const isNullable = "~lib/builtins/isNullable";
export const isDefined = "~lib/builtins/isDefined";
export const isConstant = "~lib/builtins/isConstant";
export const isManaged = "~lib/builtins/isManaged";
@ -348,6 +350,18 @@ export function compileCall(
: 0
);
}
case BuiltinSymbols.isFunction: { // isFunction<T!> / isFunction<T?>(value: T) -> bool
let type = evaluateConstantType(compiler, typeArguments, operands, reportNode);
compiler.currentType = Type.bool;
if (!type) return module.createUnreachable();
return module.createI32(type.signatureReference ? 1 : 0);
}
case BuiltinSymbols.isNullable: { // isNullable<T!> / isNullable<T?>(value: T) -> bool
let type = evaluateConstantType(compiler, typeArguments, operands, reportNode);
compiler.currentType = Type.bool;
if (!type) return module.createUnreachable();
return module.createI32(type.is(TypeFlags.NULLABLE) ? 1 : 0);
}
case BuiltinSymbols.isDefined: { // isDefined(expression) -> bool
compiler.currentType = Type.bool;
if (typeArguments) {