2018-05-13 10:10:44 +00:00
|
|
|
// Copyright 2018 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
module test {
|
2018-05-16 09:45:07 +00:00
|
|
|
macro ElementsKindTestHelper1(kind: constexpr ElementsKind): bool {
|
|
|
|
if constexpr ((kind == UINT8_ELEMENTS) || (kind == UINT16_ELEMENTS)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-05-13 10:10:44 +00:00
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
macro ElementsKindTestHelper2(kind: constexpr ElementsKind): bool {
|
|
|
|
return ((kind == UINT8_ELEMENTS) || (kind == UINT16_ELEMENTS));
|
2018-05-13 10:10:44 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
macro ElementsKindTestHelper3(kind: constexpr ElementsKind): constexpr bool {
|
|
|
|
return ((kind == UINT8_ELEMENTS) || (kind == UINT16_ELEMENTS));
|
|
|
|
}
|
2018-05-13 10:10:44 +00:00
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
macro LabelTestHelper1(): never
|
|
|
|
labels Label1 {
|
|
|
|
goto Label1;
|
|
|
|
}
|
2018-05-13 10:10:44 +00:00
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
macro LabelTestHelper2(): never
|
|
|
|
labels Label2(Smi) {
|
|
|
|
goto Label2(42);
|
|
|
|
}
|
2018-05-13 14:24:08 +00:00
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
macro LabelTestHelper3(): never
|
|
|
|
labels Label3(String, Smi) {
|
|
|
|
goto Label3('foo', 7);
|
|
|
|
}
|
2018-05-13 14:24:08 +00:00
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
macro TestConstexpr1() {
|
|
|
|
assert(convert<bool>(IsFastElementsKind(PACKED_SMI_ELEMENTS)));
|
|
|
|
}
|
2018-05-13 14:24:08 +00:00
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
macro TestConstexprIf() {
|
|
|
|
assert(ElementsKindTestHelper1(UINT8_ELEMENTS));
|
|
|
|
assert(ElementsKindTestHelper1(UINT16_ELEMENTS));
|
|
|
|
assert(!ElementsKindTestHelper1(UINT32_ELEMENTS));
|
|
|
|
}
|
2018-05-13 10:10:44 +00:00
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
macro TestConstexprReturn() {
|
|
|
|
assert(convert<bool>(ElementsKindTestHelper3(UINT8_ELEMENTS)));
|
|
|
|
assert(convert<bool>(ElementsKindTestHelper3(UINT16_ELEMENTS)));
|
|
|
|
assert(!convert<bool>(ElementsKindTestHelper3(UINT32_ELEMENTS)));
|
|
|
|
assert(convert<bool>(!ElementsKindTestHelper3(UINT32_ELEMENTS)));
|
|
|
|
}
|
2018-05-13 10:10:44 +00:00
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
macro TestGotoLabel(): Boolean {
|
|
|
|
try {
|
|
|
|
LabelTestHelper1() otherwise Label1;
|
|
|
|
}
|
|
|
|
label Label1 {
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
}
|
2018-05-13 10:10:44 +00:00
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
macro TestGotoLabelWithOneParameter(): Boolean {
|
|
|
|
try {
|
|
|
|
LabelTestHelper2() otherwise Label2;
|
|
|
|
}
|
|
|
|
label Label2(smi: Smi) {
|
|
|
|
assert(smi == 42);
|
|
|
|
return True;
|
|
|
|
}
|
2018-05-13 14:24:08 +00:00
|
|
|
}
|
2018-05-16 09:45:07 +00:00
|
|
|
|
|
|
|
macro TestGotoLabelWithTwoParameters(): Boolean {
|
|
|
|
try {
|
|
|
|
LabelTestHelper3() otherwise Label3;
|
|
|
|
}
|
|
|
|
label Label3(str: String, smi: Smi) {
|
|
|
|
assert(str == 'foo');
|
|
|
|
assert(smi == 7);
|
|
|
|
return True;
|
|
|
|
}
|
2018-05-13 14:24:08 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
builtin GenericBuiltinTest<T: type>(c: Context, param: T): Object {
|
|
|
|
return Null;
|
2018-05-13 14:24:08 +00:00
|
|
|
}
|
2018-05-16 09:45:07 +00:00
|
|
|
|
|
|
|
GenericBuiltinTest<Object>(c: Context, param: Object): Object {
|
|
|
|
return param;
|
2018-05-13 14:24:08 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
macro TestBuiltinSpecialization(c: Context) {
|
|
|
|
assert(GenericBuiltinTest<Smi>(c, 0) == Null);
|
|
|
|
assert(GenericBuiltinTest<Smi>(c, 1) == Null);
|
|
|
|
assert(GenericBuiltinTest<Object>(c, Undefined) == Undefined);
|
|
|
|
assert(GenericBuiltinTest<Object>(c, Undefined) == Undefined);
|
2018-05-13 14:24:08 +00:00
|
|
|
}
|
2018-05-16 09:45:07 +00:00
|
|
|
|
|
|
|
macro LabelTestHelper4(flag: constexpr bool): never labels Label4, Label5 {
|
|
|
|
if constexpr (flag) goto Label4;
|
|
|
|
else
|
|
|
|
goto Label5;
|
2018-05-13 14:24:08 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
macro CallLabelTestHelper4(flag: constexpr bool): bool {
|
|
|
|
try {
|
|
|
|
LabelTestHelper4(flag) otherwise Label4, Label5;
|
|
|
|
}
|
|
|
|
label Label4 {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
label Label5 {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-05-14 10:53:04 +00:00
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
macro TestPartiallyUnusedLabel(): Boolean {
|
|
|
|
let r1: bool = CallLabelTestHelper4(true);
|
|
|
|
let r2: bool = CallLabelTestHelper4(false);
|
|
|
|
|
|
|
|
if (r1 && !r2)
|
|
|
|
return True;
|
|
|
|
else
|
|
|
|
return False;
|
2018-05-14 10:53:04 +00:00
|
|
|
}
|
2018-05-16 09:45:07 +00:00
|
|
|
|
|
|
|
macro GenericMacroTest<T: type>(param: T): Object {
|
|
|
|
return Undefined;
|
2018-05-14 10:53:04 +00:00
|
|
|
}
|
2018-05-16 09:45:07 +00:00
|
|
|
|
|
|
|
GenericMacroTest<Object>(param2: Object): Object {
|
|
|
|
return param2;
|
2018-05-14 10:53:04 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
macro GenericMacroTestWithLabels<T: type>(param: T): Object labels X {
|
|
|
|
return Undefined;
|
|
|
|
}
|
2018-05-14 10:53:04 +00:00
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
GenericMacroTestWithLabels<Object>(param2: Object): Object labels Y {
|
|
|
|
return param2;
|
|
|
|
}
|
2018-05-14 10:53:04 +00:00
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
macro TestMacroSpecialization() {
|
|
|
|
try {
|
|
|
|
if (True == False) goto Fail; // Silence warnings in release build
|
|
|
|
assert(GenericMacroTest<Smi>(0) == Undefined);
|
|
|
|
assert(GenericMacroTest<Smi>(1) == Undefined);
|
|
|
|
assert(GenericMacroTest<Object>(Null) == Null);
|
|
|
|
assert(GenericMacroTest<Object>(False) == False);
|
|
|
|
assert(GenericMacroTest<Object>(True) == True);
|
|
|
|
assert(GenericMacroTestWithLabels<Smi>(0) otherwise Fail == Undefined);
|
|
|
|
assert(GenericMacroTestWithLabels<Smi>(0) otherwise Fail == Undefined);
|
|
|
|
assert(GenericMacroTestWithLabels<Object>(Null) otherwise Fail == Null);
|
|
|
|
assert(GenericMacroTestWithLabels<Object>(False) otherwise Fail == False);
|
|
|
|
}
|
|
|
|
label Fail {
|
|
|
|
unreachable;
|
|
|
|
}
|
|
|
|
}
|
2018-05-16 14:00:35 +00:00
|
|
|
|
|
|
|
builtin TestHelperPlus1(context : Context, x : Smi) : Smi {
|
|
|
|
return x + 1;
|
|
|
|
}
|
|
|
|
builtin TestHelperPlus2(context : Context, x : Smi) : Smi {
|
|
|
|
return x + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
macro TestFunctionPointers(context : Context) : Boolean {
|
|
|
|
let fptr : builtin(Context, Smi) => Smi = TestHelperPlus1;
|
|
|
|
assert(fptr(context, 42) == 43);
|
|
|
|
fptr = TestHelperPlus2;
|
|
|
|
assert(fptr(context, 42) == 44);
|
|
|
|
return True;
|
|
|
|
}
|
2018-05-18 08:33:36 +00:00
|
|
|
|
|
|
|
macro TestVariableRedeclaration(context : Context) : Boolean {
|
|
|
|
let var1 : Number = 42 == 0 ? 0 : 1;
|
|
|
|
let var2 : Number = 42 == 0 ? 1 : 0;
|
|
|
|
return True;
|
|
|
|
}
|
2018-05-22 12:48:29 +00:00
|
|
|
|
|
|
|
macro TestFunctionPointerToGeneric(c: Context) {
|
|
|
|
let fptr1: builtin(Context, Smi) => Object = GenericBuiltinTest<Smi>;
|
|
|
|
let fptr2: builtin(Context, Object) => Object = GenericBuiltinTest<Object>;
|
|
|
|
|
|
|
|
assert(fptr1(c, 0) == Null);
|
|
|
|
assert(fptr1(c, 1) == Null);
|
|
|
|
assert(fptr2(c, Undefined) == Undefined);
|
|
|
|
assert(fptr2(c, Undefined) == Undefined);
|
|
|
|
}
|
2018-05-22 21:11:39 +00:00
|
|
|
|
|
|
|
type SmiToSmi = builtin(Smi) => Smi;
|
|
|
|
macro TestTypeAlias(x : SmiToSmi) : Code {
|
|
|
|
return x;
|
|
|
|
}
|
2018-05-13 10:10:44 +00:00
|
|
|
}
|