mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-18 09:21:35 +00:00
Implement isDefined and isConstant builtins
This commit is contained in:
@ -51,6 +51,11 @@ import {
|
||||
FlowFlags
|
||||
} from "./program";
|
||||
|
||||
import {
|
||||
ReportMode
|
||||
} from "./resolver";
|
||||
import { CommonFlags } from "./common";
|
||||
|
||||
/** Compiles a call to a built-in function. */
|
||||
export function compileCall(
|
||||
compiler: Compiler,
|
||||
@ -128,6 +133,57 @@ export function compileCall(
|
||||
? module.createI32(1)
|
||||
: module.createI32(0);
|
||||
}
|
||||
case "isDefined": { // isDefined(expression) -> bool
|
||||
compiler.currentType = Type.bool;
|
||||
if (operands.length != 1) {
|
||||
if (typeArguments) {
|
||||
compiler.error(
|
||||
DiagnosticCode.Type_0_is_not_generic,
|
||||
reportNode.range, prototype.internalName
|
||||
);
|
||||
}
|
||||
compiler.error(
|
||||
DiagnosticCode.Expected_0_arguments_but_got_1,
|
||||
reportNode.range, "1", operands.length.toString(10)
|
||||
);
|
||||
return module.createUnreachable();
|
||||
}
|
||||
if (typeArguments) {
|
||||
compiler.error(
|
||||
DiagnosticCode.Type_0_is_not_generic,
|
||||
reportNode.range, prototype.internalName
|
||||
);
|
||||
return module.createUnreachable();
|
||||
}
|
||||
let element = compiler.resolver.resolveExpression(operands[0], compiler.currentFunction, ReportMode.SWALLOW);
|
||||
return module.createI32(element ? 1 : 0);
|
||||
}
|
||||
case "isConstant": { // isConstant(expression) -> bool
|
||||
compiler.currentType = Type.bool;
|
||||
if (operands.length != 1) {
|
||||
if (typeArguments) {
|
||||
compiler.error(
|
||||
DiagnosticCode.Type_0_is_not_generic,
|
||||
reportNode.range, prototype.internalName
|
||||
);
|
||||
}
|
||||
compiler.error(
|
||||
DiagnosticCode.Expected_0_arguments_but_got_1,
|
||||
reportNode.range, "1", operands.length.toString(10)
|
||||
);
|
||||
return module.createUnreachable();
|
||||
}
|
||||
if (typeArguments) {
|
||||
compiler.error(
|
||||
DiagnosticCode.Type_0_is_not_generic,
|
||||
reportNode.range, prototype.internalName
|
||||
);
|
||||
return module.createUnreachable();
|
||||
}
|
||||
let expr = compiler.compileExpressionRetainType(operands[0], Type.i32, WrapMode.NONE);
|
||||
compiler.currentType = Type.bool;
|
||||
return module.createI32(getExpressionId(expr) == ExpressionId.Const ? 1 : 0);
|
||||
}
|
||||
|
||||
// math
|
||||
|
||||
|
Reference in New Issue
Block a user