|
Lines 78-88
function makeFloat(program, value)
a/Tools/WebGPUShadingLanguageRI/Test.js_sec1
|
| 78 |
return TypedValue.box(program.intrinsics.float, value); |
78 |
return TypedValue.box(program.intrinsics.float, value); |
| 79 |
} |
79 |
} |
| 80 |
|
80 |
|
| 81 |
function makeDouble(program, value) |
|
|
| 82 |
{ |
| 83 |
return TypedValue.box(program.intrinsics.double, value); |
| 84 |
} |
| 85 |
|
| 86 |
function makeEnum(program, enumName, value) |
81 |
function makeEnum(program, enumName, value) |
| 87 |
{ |
82 |
{ |
| 88 |
let enumType = program.types.get(enumName); |
83 |
let enumType = program.types.get(enumName); |
|
Lines 149-162
function checkFloat(program, result, expected)
a/Tools/WebGPUShadingLanguageRI/Test.js_sec2
|
| 149 |
throw new Error("Wrong result: " + result.value + " (expected " + expected + ")"); |
144 |
throw new Error("Wrong result: " + result.value + " (expected " + expected + ")"); |
| 150 |
} |
145 |
} |
| 151 |
|
146 |
|
| 152 |
function checkDouble(program, result, expected) |
|
|
| 153 |
{ |
| 154 |
if (!result.type.equals(program.intrinsics.double)) |
| 155 |
throw new Error("Wrong result type: " + result.type); |
| 156 |
if (result.value != expected) |
| 157 |
throw new Error("Wrong result: " + result.value + " (expected " + expected + ")"); |
| 158 |
} |
| 159 |
|
| 160 |
function checkLexerToken(result, expectedIndex, expectedKind, expectedText) |
147 |
function checkLexerToken(result, expectedIndex, expectedKind, expectedText) |
| 161 |
{ |
148 |
{ |
| 162 |
if (result._index != expectedIndex) |
149 |
if (result._index != expectedIndex) |
|
Lines 320-333
tests.add1 = function() {
a/Tools/WebGPUShadingLanguageRI/Test.js_sec3
|
| 320 |
checkInt(program, callFunction(program, "foo", [], [makeInt(program, 42)]), 43); |
307 |
checkInt(program, callFunction(program, "foo", [], [makeInt(program, 42)]), 43); |
| 321 |
} |
308 |
} |
| 322 |
|
309 |
|
| 323 |
tests.simpleGeneric = function() { |
|
|
| 324 |
let program = doPrep(` |
| 325 |
T id<T>(T x) { return x; } |
| 326 |
int foo(int x) { return id(x) + 1; } |
| 327 |
`); |
| 328 |
checkInt(program, callFunction(program, "foo", [], [makeInt(program, 42)]), 43); |
| 329 |
} |
| 330 |
|
| 331 |
tests.nameResolutionFailure = function() |
310 |
tests.nameResolutionFailure = function() |
| 332 |
{ |
311 |
{ |
| 333 |
checkFail( |
312 |
checkFail( |
|
Lines 526-549
tests.deviceArrayStoreIntLiteral = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec4
|
| 526 |
throw new Error("Bad value stored into buffer (expected -111): " + buffer.get(0)); |
505 |
throw new Error("Bad value stored into buffer (expected -111): " + buffer.get(0)); |
| 527 |
} |
506 |
} |
| 528 |
|
507 |
|
| 529 |
tests.simpleProtocol = function() |
|
|
| 530 |
{ |
| 531 |
let program = doPrep(` |
| 532 |
protocol MyAddable { |
| 533 |
MyAddable operator+(MyAddable, MyAddable); |
| 534 |
} |
| 535 |
T add<T:MyAddable>(T a, T b) |
| 536 |
{ |
| 537 |
return a + b; |
| 538 |
} |
| 539 |
int foo(int x) |
| 540 |
{ |
| 541 |
return add(x, 73); |
| 542 |
} |
| 543 |
`); |
| 544 |
checkInt(program, callFunction(program, "foo", [], [makeInt(program, 45)]), 45 + 73); |
| 545 |
} |
| 546 |
|
| 547 |
tests.typeMismatchReturn = function() |
508 |
tests.typeMismatchReturn = function() |
| 548 |
{ |
509 |
{ |
| 549 |
checkFail( |
510 |
checkFail( |
|
Lines 597-614
tests.badAdd = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec5
|
| 597 |
{ |
558 |
{ |
| 598 |
checkFail( |
559 |
checkFail( |
| 599 |
() => doPrep(` |
560 |
() => doPrep(` |
| 600 |
void bar<T>(T) { } |
|
|
| 601 |
void foo(int x, uint y) |
561 |
void foo(int x, uint y) |
| 602 |
{ |
562 |
{ |
| 603 |
bar(x + y); |
563 |
uint z = x + y; |
| 604 |
} |
564 |
} |
| 605 |
`), |
565 |
`), |
| 606 |
(e) => e instanceof WTypeError && e.message.indexOf("native int32 operator+<>(int32,int32)") != -1); |
566 |
(e) => e instanceof WTypeError && e.message.indexOf("native int32 operator+(int32,int32)") != -1); |
| 607 |
} |
567 |
} |
| 608 |
|
568 |
|
| 609 |
tests.lexerKeyword = function() |
569 |
tests.lexerKeyword = function() |
| 610 |
{ |
570 |
{ |
| 611 |
let result = doLex("ident for while 123 123u { } {asd asd{ 1a3 1.2 + 3.4 + 1. + .2 1.2d 0.d .3d && ||"); |
571 |
let result = doLex("ident for while 123 123u { } {asd asd{ 1a3 1.2 + 3.4 + 1. + .2 1.2f 0.f .3f && ||"); |
| 612 |
if (result.length != 25) |
572 |
if (result.length != 25) |
| 613 |
throw new Error("Lexer emitted an incorrect number of tokens (expected 23): " + result.length); |
573 |
throw new Error("Lexer emitted an incorrect number of tokens (expected 23): " + result.length); |
| 614 |
checkLexerToken(result[0], 0, "identifier", "ident"); |
574 |
checkLexerToken(result[0], 0, "identifier", "ident"); |
|
Lines 631-639
tests.lexerKeyword = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec6
|
| 631 |
checkLexerToken(result[17], 55, "floatLiteral", "1."); |
591 |
checkLexerToken(result[17], 55, "floatLiteral", "1."); |
| 632 |
checkLexerToken(result[18], 58, "punctuation", "+"); |
592 |
checkLexerToken(result[18], 58, "punctuation", "+"); |
| 633 |
checkLexerToken(result[19], 60, "floatLiteral", ".2"); |
593 |
checkLexerToken(result[19], 60, "floatLiteral", ".2"); |
| 634 |
checkLexerToken(result[20], 63, "floatLiteral", "1.2d"); |
594 |
checkLexerToken(result[20], 63, "floatLiteral", "1.2f"); |
| 635 |
checkLexerToken(result[21], 68, "floatLiteral", "0.d"); |
595 |
checkLexerToken(result[21], 68, "floatLiteral", "0.f"); |
| 636 |
checkLexerToken(result[22], 72, "floatLiteral", ".3d"); |
596 |
checkLexerToken(result[22], 72, "floatLiteral", ".3f"); |
| 637 |
checkLexerToken(result[23], 76, "punctuation", "&&"); |
597 |
checkLexerToken(result[23], 76, "punctuation", "&&"); |
| 638 |
checkLexerToken(result[24], 79, "punctuation", "||"); |
598 |
checkLexerToken(result[24], 79, "punctuation", "||"); |
| 639 |
} |
599 |
} |
|
Lines 690-746
tests.simpleStruct = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec7
|
| 690 |
throw new Error("Wrong result for y: " + y + " (x + " + x + ")"); |
650 |
throw new Error("Wrong result for y: " + y + " (x + " + x + ")"); |
| 691 |
} |
651 |
} |
| 692 |
|
652 |
|
| 693 |
tests.genericStructInstance = function() |
|
|
| 694 |
{ |
| 695 |
let program = doPrep(` |
| 696 |
struct Foo<T> { |
| 697 |
T x; |
| 698 |
T y; |
| 699 |
} |
| 700 |
Foo<int> foo(Foo<int> foo) |
| 701 |
{ |
| 702 |
Foo<int> result; |
| 703 |
result.x = foo.y; |
| 704 |
result.y = foo.x; |
| 705 |
return result; |
| 706 |
} |
| 707 |
`); |
| 708 |
let structType = TypeRef.instantiate(program.types.get("Foo"), [program.intrinsics.int32]); |
| 709 |
let buffer = new EBuffer(2); |
| 710 |
buffer.set(0, 62); |
| 711 |
buffer.set(1, 24); |
| 712 |
let result = callFunction(program, "foo", [], [new TypedValue(structType, new EPtr(buffer, 0))]); |
| 713 |
let x = result.ePtr.get(0); |
| 714 |
let y = result.ePtr.get(1); |
| 715 |
if (x != 24) |
| 716 |
throw new Error("Wrong result for x: " + x + " (y = " + y + ")"); |
| 717 |
if (y != 62) |
| 718 |
throw new Error("Wrong result for y: " + y + " (x + " + x + ")"); |
| 719 |
} |
| 720 |
|
| 721 |
tests.doubleGenericCallsDoubleGeneric = function() |
| 722 |
{ |
| 723 |
doPrep(` |
| 724 |
void foo<T, U>(T, U) { } |
| 725 |
void bar<V, W>(V x, W y) { foo(x, y); } |
| 726 |
`); |
| 727 |
} |
| 728 |
|
| 729 |
tests.doubleGenericCallsSingleGeneric = function() |
| 730 |
{ |
| 731 |
checkFail( |
| 732 |
() => doPrep(` |
| 733 |
void foo<T>(T, T) { } |
| 734 |
void bar<V, W>(V x, W y) { foo(x, y); } |
| 735 |
`), |
| 736 |
(e) => e instanceof WTypeError); |
| 737 |
} |
| 738 |
|
| 739 |
tests.loadNull = function() |
653 |
tests.loadNull = function() |
| 740 |
{ |
654 |
{ |
| 741 |
checkFail( |
655 |
checkFail( |
| 742 |
() => doPrep(` |
656 |
() => doPrep(` |
| 743 |
void sink<T>(T) { } |
657 |
void sink(thread int* x) { } |
| 744 |
void foo() { sink(*null); } |
658 |
void foo() { sink(*null); } |
| 745 |
`), |
659 |
`), |
| 746 |
(e) => e instanceof WTypeError && e.message.indexOf("Type passed to dereference is not a pointer: null") != -1); |
660 |
(e) => e instanceof WTypeError && e.message.indexOf("Type passed to dereference is not a pointer: null") != -1); |
|
Lines 814-856
tests.passNullToPtrMonomorphic = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec8
|
| 814 |
(e) => e instanceof WTrapError); |
728 |
(e) => e instanceof WTrapError); |
| 815 |
} |
729 |
} |
| 816 |
|
730 |
|
| 817 |
tests.passNullToPtrPolymorphic = function() |
|
|
| 818 |
{ |
| 819 |
checkFail( |
| 820 |
() => doPrep(` |
| 821 |
T foo<T>(thread T* ptr) |
| 822 |
{ |
| 823 |
return *ptr; |
| 824 |
} |
| 825 |
int bar() |
| 826 |
{ |
| 827 |
return foo(null); |
| 828 |
} |
| 829 |
`), |
| 830 |
(e) => e instanceof WTypeError); |
| 831 |
} |
| 832 |
|
| 833 |
tests.passNullToPolymorphic = function() |
| 834 |
{ |
| 835 |
checkFail( |
| 836 |
() => doPrep(` |
| 837 |
T foo<T>(T ptr) |
| 838 |
{ |
| 839 |
return ptr; |
| 840 |
} |
| 841 |
int bar() |
| 842 |
{ |
| 843 |
return foo(null); |
| 844 |
} |
| 845 |
`), |
| 846 |
(e) => e instanceof WTypeError); |
| 847 |
} |
| 848 |
|
| 849 |
tests.loadNullArrayRef = function() |
731 |
tests.loadNullArrayRef = function() |
| 850 |
{ |
732 |
{ |
| 851 |
checkFail( |
733 |
checkFail( |
| 852 |
() => doPrep(` |
734 |
() => doPrep(` |
| 853 |
void sink<T>(T) { } |
735 |
void sink(thread int* x) { } |
| 854 |
void foo() { sink(null[0u]); } |
736 |
void foo() { sink(null[0u]); } |
| 855 |
`), |
737 |
`), |
| 856 |
(e) => e instanceof WTypeError && e.message.indexOf("Cannot resolve access") != -1); |
738 |
(e) => e instanceof WTypeError && e.message.indexOf("Cannot resolve access") != -1); |
|
Lines 938-968
tests.passNullToPtrMonomorphicArrayRef = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec9
|
| 938 |
(e) => e instanceof WTrapError); |
820 |
(e) => e instanceof WTrapError); |
| 939 |
} |
821 |
} |
| 940 |
|
822 |
|
| 941 |
tests.passNullToPtrPolymorphicArrayRef = function() |
|
|
| 942 |
{ |
| 943 |
checkFail( |
| 944 |
() => doPrep(` |
| 945 |
T foo<T>(thread T[] ptr) |
| 946 |
{ |
| 947 |
return ptr[0u]; |
| 948 |
} |
| 949 |
int bar() |
| 950 |
{ |
| 951 |
return foo(null); |
| 952 |
} |
| 953 |
`), |
| 954 |
(e) => e instanceof WTypeError); |
| 955 |
} |
| 956 |
|
| 957 |
tests.returnIntLiteralUint = function() |
823 |
tests.returnIntLiteralUint = function() |
| 958 |
{ |
824 |
{ |
| 959 |
let program = doPrep("uint foo() { return 42; }"); |
825 |
let program = doPrep("uint foo() { return 42; }"); |
| 960 |
checkNumber(program, callFunction(program, "foo", [], []), 42); |
826 |
checkNumber(program, callFunction(program, "foo", [], []), 42); |
| 961 |
} |
827 |
} |
| 962 |
|
828 |
|
| 963 |
tests.returnIntLiteralDouble = function() |
829 |
tests.returnIntLiteralFloat = function() |
| 964 |
{ |
830 |
{ |
| 965 |
let program = doPrep("double foo() { return 42; }"); |
831 |
let program = doPrep("float foo() { return 42; }"); |
| 966 |
checkNumber(program, callFunction(program, "foo", [], []), 42); |
832 |
checkNumber(program, callFunction(program, "foo", [], []), 42); |
| 967 |
} |
833 |
} |
| 968 |
|
834 |
|
|
Lines 980-1043
tests.badIntLiteralForUint = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec10
|
| 980 |
(e) => e instanceof WSyntaxError); |
846 |
(e) => e instanceof WSyntaxError); |
| 981 |
} |
847 |
} |
| 982 |
|
848 |
|
| 983 |
tests.badIntLiteralForDouble = function() |
849 |
tests.badIntLiteralForFloat = function() |
| 984 |
{ |
850 |
{ |
| 985 |
checkFail( |
851 |
checkFail( |
| 986 |
() => doPrep("void foo() { double x = 5000000000000000000000000000000000000; }"), |
852 |
() => doPrep("void foo() { float x = 5000000000000000000000000000000000000; }"), |
| 987 |
(e) => e instanceof WSyntaxError); |
853 |
(e) => e instanceof WSyntaxError); |
| 988 |
} |
854 |
} |
| 989 |
|
855 |
|
| 990 |
tests.passNullAndNotNull = function() |
|
|
| 991 |
{ |
| 992 |
let program = doPrep(` |
| 993 |
T bar<T>(device T* p, device T*) |
| 994 |
{ |
| 995 |
return *p; |
| 996 |
} |
| 997 |
int foo(device int* p) |
| 998 |
{ |
| 999 |
return bar(p, null); |
| 1000 |
} |
| 1001 |
`); |
| 1002 |
let buffer = new EBuffer(1); |
| 1003 |
buffer.set(0, 13); |
| 1004 |
checkInt(program, callFunction(program, "foo", [], [TypedValue.box(new PtrType(externalOrigin, "device", program.intrinsics.int32), new EPtr(buffer, 0))]), 13); |
| 1005 |
} |
| 1006 |
|
| 1007 |
tests.passNullAndNotNullFullPoly = function() |
| 1008 |
{ |
| 1009 |
let program = doPrep(` |
| 1010 |
T bar<T>(T p, T) |
| 1011 |
{ |
| 1012 |
return p; |
| 1013 |
} |
| 1014 |
int foo(device int* p) |
| 1015 |
{ |
| 1016 |
return *bar(p, null); |
| 1017 |
} |
| 1018 |
`); |
| 1019 |
let buffer = new EBuffer(1); |
| 1020 |
buffer.set(0, 13); |
| 1021 |
checkInt(program, callFunction(program, "foo", [], [TypedValue.box(new PtrType(externalOrigin, "device", program.intrinsics.int32), new EPtr(buffer, 0))]), 13); |
| 1022 |
} |
| 1023 |
|
| 1024 |
tests.passNullAndNotNullFullPolyReverse = function() |
| 1025 |
{ |
| 1026 |
let program = doPrep(` |
| 1027 |
T bar<T>(T, T p) |
| 1028 |
{ |
| 1029 |
return p; |
| 1030 |
} |
| 1031 |
int foo(device int* p) |
| 1032 |
{ |
| 1033 |
return *bar(null, p); |
| 1034 |
} |
| 1035 |
`); |
| 1036 |
let buffer = new EBuffer(1); |
| 1037 |
buffer.set(0, 13); |
| 1038 |
checkInt(program, callFunction(program, "foo", [], [TypedValue.box(new PtrType(externalOrigin, "device", program.intrinsics.int32), new EPtr(buffer, 0))]), 13); |
| 1039 |
} |
| 1040 |
|
| 1041 |
tests.nullTypeVariableUnify = function() |
856 |
tests.nullTypeVariableUnify = function() |
| 1042 |
{ |
857 |
{ |
| 1043 |
let left = new NullType(externalOrigin); |
858 |
let left = new NullType(externalOrigin); |
|
Lines 1112-1233
tests.simpleRecursion = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec11
|
| 1112 |
{ |
927 |
{ |
| 1113 |
checkFail( |
928 |
checkFail( |
| 1114 |
() => doPrep(` |
929 |
() => doPrep(` |
| 1115 |
void foo<T>(T x) |
930 |
void foo(int x) |
| 1116 |
{ |
931 |
{ |
| 1117 |
foo(&x); |
932 |
foo(x); |
| 1118 |
} |
933 |
} |
| 1119 |
`), |
934 |
`), |
| 1120 |
(e) => e instanceof WTypeError); |
935 |
(e) => e instanceof WTypeError); |
| 1121 |
} |
936 |
} |
| 1122 |
|
937 |
|
| 1123 |
tests.protocolMonoSigPolyDef = function() |
|
|
| 1124 |
{ |
| 1125 |
let program = doPrep(` |
| 1126 |
struct IntAnd<T> { |
| 1127 |
int first; |
| 1128 |
T second; |
| 1129 |
} |
| 1130 |
IntAnd<T> intAnd<T>(int first, T second) |
| 1131 |
{ |
| 1132 |
IntAnd<T> result; |
| 1133 |
result.first = first; |
| 1134 |
result.second = second; |
| 1135 |
return result; |
| 1136 |
} |
| 1137 |
protocol IntAndable { |
| 1138 |
IntAnd<int> intAnd(IntAndable, int); |
| 1139 |
} |
| 1140 |
int foo<T:IntAndable>(T first, int second) |
| 1141 |
{ |
| 1142 |
IntAnd<int> result = intAnd(first, second); |
| 1143 |
return result.first + result.second; |
| 1144 |
} |
| 1145 |
`); |
| 1146 |
checkInt(program, callFunction(program, "foo", [], [makeInt(program, 54), makeInt(program, 12)]), 54 + 12); |
| 1147 |
} |
| 1148 |
|
| 1149 |
tests.protocolPolySigPolyDef = function() |
| 1150 |
{ |
| 1151 |
let program = doPrep(` |
| 1152 |
struct IntAnd<T> { |
| 1153 |
int first; |
| 1154 |
T second; |
| 1155 |
} |
| 1156 |
IntAnd<T> intAnd<T>(int first, T second) |
| 1157 |
{ |
| 1158 |
IntAnd<T> result; |
| 1159 |
result.first = first; |
| 1160 |
result.second = second; |
| 1161 |
return result; |
| 1162 |
} |
| 1163 |
protocol IntAndable { |
| 1164 |
IntAnd<T> intAnd<T>(IntAndable, T); |
| 1165 |
} |
| 1166 |
int foo<T:IntAndable>(T first, int second) |
| 1167 |
{ |
| 1168 |
IntAnd<int> result = intAnd(first, second); |
| 1169 |
return result.first + result.second; |
| 1170 |
} |
| 1171 |
`); |
| 1172 |
checkInt(program, callFunction(program, "foo", [], [makeInt(program, 54), makeInt(program, 12)]), 54 + 12); |
| 1173 |
} |
| 1174 |
|
| 1175 |
tests.protocolDoublePolySigDoublePolyDef = function() |
| 1176 |
{ |
| 1177 |
let program = doPrep(` |
| 1178 |
struct IntAnd<T, U> { |
| 1179 |
int first; |
| 1180 |
T second; |
| 1181 |
U third; |
| 1182 |
} |
| 1183 |
IntAnd<T, U> intAnd<T, U>(int first, T second, U third) |
| 1184 |
{ |
| 1185 |
IntAnd<T, U> result; |
| 1186 |
result.first = first; |
| 1187 |
result.second = second; |
| 1188 |
result.third = third; |
| 1189 |
return result; |
| 1190 |
} |
| 1191 |
protocol IntAndable { |
| 1192 |
IntAnd<T, U> intAnd<T, U>(IntAndable, T, U); |
| 1193 |
} |
| 1194 |
int foo<T:IntAndable>(T first, int second, int third) |
| 1195 |
{ |
| 1196 |
IntAnd<int, int> result = intAnd(first, second, third); |
| 1197 |
return result.first + result.second + result.third; |
| 1198 |
} |
| 1199 |
`); |
| 1200 |
checkInt(program, callFunction(program, "foo", [], [makeInt(program, 54), makeInt(program, 12), makeInt(program, 39)]), 54 + 12 + 39); |
| 1201 |
} |
| 1202 |
|
| 1203 |
tests.protocolDoublePolySigDoublePolyDefExplicit = function() |
| 1204 |
{ |
| 1205 |
let program = doPrep(` |
| 1206 |
struct IntAnd<T, U> { |
| 1207 |
int first; |
| 1208 |
T second; |
| 1209 |
U third; |
| 1210 |
} |
| 1211 |
IntAnd<T, U> intAnd<T, U>(int first, T second, U third) |
| 1212 |
{ |
| 1213 |
IntAnd<T, U> result; |
| 1214 |
result.first = first; |
| 1215 |
result.second = second; |
| 1216 |
result.third = third; |
| 1217 |
return result; |
| 1218 |
} |
| 1219 |
protocol IntAndable { |
| 1220 |
IntAnd<T, U> intAnd<T, U>(IntAndable, T, U); |
| 1221 |
} |
| 1222 |
int foo<T:IntAndable>(T first, int second, int third) |
| 1223 |
{ |
| 1224 |
IntAnd<int, int> result = intAnd<int, int>(first, second, third); |
| 1225 |
return result.first + result.second + result.third; |
| 1226 |
} |
| 1227 |
`); |
| 1228 |
checkInt(program, callFunction(program, "foo", [], [makeInt(program, 54), makeInt(program, 12), makeInt(program, 39)]), 54 + 12 + 39); |
| 1229 |
} |
| 1230 |
|
| 1231 |
tests.variableShadowing = function() |
938 |
tests.variableShadowing = function() |
| 1232 |
{ |
939 |
{ |
| 1233 |
let program = doPrep(` |
940 |
let program = doPrep(` |
|
Lines 1478-1553
tests.simpleWhile = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec12
|
| 1478 |
checkInt(program, callFunction(program, "foo", [], [makeInt(program, 1)]), 16); |
1185 |
checkInt(program, callFunction(program, "foo", [], [makeInt(program, 1)]), 16); |
| 1479 |
} |
1186 |
} |
| 1480 |
|
1187 |
|
| 1481 |
tests.protocolMonoPolySigDoublePolyDefExplicit = function() |
|
|
| 1482 |
{ |
| 1483 |
checkFail( |
| 1484 |
() => { |
| 1485 |
let program = doPrep(` |
| 1486 |
struct IntAnd<T, U> { |
| 1487 |
int first; |
| 1488 |
T second; |
| 1489 |
U third; |
| 1490 |
} |
| 1491 |
IntAnd<T, U> intAnd<T, U>(int first, T second, U third) |
| 1492 |
{ |
| 1493 |
IntAnd<T, U> result; |
| 1494 |
result.first = first; |
| 1495 |
result.second = second; |
| 1496 |
result.third = third; |
| 1497 |
return result; |
| 1498 |
} |
| 1499 |
protocol IntAndable { |
| 1500 |
IntAnd<T, int> intAnd<T>(IntAndable, T, int); |
| 1501 |
} |
| 1502 |
int foo<T:IntAndable>(T first, int second, int third) |
| 1503 |
{ |
| 1504 |
IntAnd<int, int> result = intAnd<int>(first, second, third); |
| 1505 |
return result.first + result.second + result.third; |
| 1506 |
} |
| 1507 |
`); |
| 1508 |
callFunction(program, "foo", [], [makeInt(program, 54), makeInt(program, 12), makeInt(program, 39)]); |
| 1509 |
}, |
| 1510 |
(e) => e instanceof WTypeError); |
| 1511 |
} |
| 1512 |
|
| 1513 |
tests.ambiguousOverloadSimple = function() |
| 1514 |
{ |
| 1515 |
checkFail( |
| 1516 |
() => doPrep(` |
| 1517 |
void foo<T>(int, T) { } |
| 1518 |
void foo<T>(T, int) { } |
| 1519 |
void bar(int a, int b) { foo(a, b); } |
| 1520 |
`), |
| 1521 |
(e) => e instanceof WTypeError); |
| 1522 |
} |
| 1523 |
|
| 1524 |
tests.ambiguousOverloadOverlapping = function() |
| 1525 |
{ |
| 1526 |
checkFail( |
| 1527 |
() => doPrep(` |
| 1528 |
void foo<T>(int, T) { } |
| 1529 |
void foo<T>(T, T) { } |
| 1530 |
void bar(int a, int b) { foo(a, b); } |
| 1531 |
`), |
| 1532 |
(e) => e instanceof WTypeError); |
| 1533 |
} |
| 1534 |
|
| 1535 |
tests.ambiguousOverloadTieBreak = function() |
| 1536 |
{ |
| 1537 |
doPrep(` |
| 1538 |
void foo<T>(int, T) { } |
| 1539 |
void foo<T>(T, T) { } |
| 1540 |
void foo(int, int) { } |
| 1541 |
void bar(int a, int b) { foo(a, b); } |
| 1542 |
`); |
| 1543 |
} |
| 1544 |
|
| 1545 |
tests.intOverloadResolution = function() |
1188 |
tests.intOverloadResolution = function() |
| 1546 |
{ |
1189 |
{ |
| 1547 |
let program = doPrep(` |
1190 |
let program = doPrep(` |
| 1548 |
int foo(int) { return 1; } |
1191 |
int foo(int) { return 1; } |
| 1549 |
int foo(uint) { return 2; } |
1192 |
int foo(uint) { return 2; } |
| 1550 |
int foo(double) { return 3; } |
1193 |
int foo(float) { return 3; } |
| 1551 |
int bar() { return foo(42); } |
1194 |
int bar() { return foo(42); } |
| 1552 |
`); |
1195 |
`); |
| 1553 |
checkInt(program, callFunction(program, "bar", [], []), 1); |
1196 |
checkInt(program, callFunction(program, "bar", [], []), 1); |
|
Lines 1556-1562
tests.intOverloadResolution = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec13
|
| 1556 |
tests.intOverloadResolutionReverseOrder = function() |
1199 |
tests.intOverloadResolutionReverseOrder = function() |
| 1557 |
{ |
1200 |
{ |
| 1558 |
let program = doPrep(` |
1201 |
let program = doPrep(` |
| 1559 |
int foo(double) { return 3; } |
1202 |
int foo(float) { return 3; } |
| 1560 |
int foo(uint) { return 2; } |
1203 |
int foo(uint) { return 2; } |
| 1561 |
int foo(int) { return 1; } |
1204 |
int foo(int) { return 1; } |
| 1562 |
int bar() { return foo(42); } |
1205 |
int bar() { return foo(42); } |
|
Lines 1564-1645
tests.intOverloadResolutionReverseOrder = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec14
|
| 1564 |
checkInt(program, callFunction(program, "bar", [], []), 1); |
1207 |
checkInt(program, callFunction(program, "bar", [], []), 1); |
| 1565 |
} |
1208 |
} |
| 1566 |
|
1209 |
|
| 1567 |
tests.intOverloadResolutionGeneric = function() |
|
|
| 1568 |
{ |
| 1569 |
let program = doPrep(` |
| 1570 |
int foo(int) { return 1; } |
| 1571 |
int foo<T>(T) { return 2; } |
| 1572 |
int bar() { return foo(42); } |
| 1573 |
`); |
| 1574 |
checkInt(program, callFunction(program, "bar", [], []), 1); |
| 1575 |
} |
| 1576 |
|
| 1577 |
tests.intLiteralGeneric = function() |
| 1578 |
{ |
| 1579 |
let program = doPrep(` |
| 1580 |
int foo<T>(T x) { return 3478; } |
| 1581 |
int bar() { return foo(42); } |
| 1582 |
`); |
| 1583 |
checkInt(program, callFunction(program, "bar", [], []), 3478); |
| 1584 |
} |
| 1585 |
|
| 1586 |
tests.intLiteralGenericWithProtocols = function() |
| 1587 |
{ |
| 1588 |
let program = doPrep(` |
| 1589 |
protocol MyConvertibleToInt { |
| 1590 |
operator int(MyConvertibleToInt); |
| 1591 |
} |
| 1592 |
int foo<T:MyConvertibleToInt>(T x) { return int(x); } |
| 1593 |
int bar() { return foo(42); } |
| 1594 |
`); |
| 1595 |
checkInt(program, callFunction(program, "bar", [], []), 42); |
| 1596 |
} |
| 1597 |
|
| 1598 |
tests.uintLiteralGeneric = function() |
| 1599 |
{ |
| 1600 |
let program = doPrep(` |
| 1601 |
int foo<T>(T x) { return 3478; } |
| 1602 |
int bar() { return foo(42u); } |
| 1603 |
`); |
| 1604 |
checkInt(program, callFunction(program, "bar", [], []), 3478); |
| 1605 |
} |
| 1606 |
|
| 1607 |
tests.uintLiteralGenericWithProtocols = function() |
| 1608 |
{ |
| 1609 |
let program = doPrep(` |
| 1610 |
protocol MyConvertibleToUint { |
| 1611 |
operator uint(MyConvertibleToUint); |
| 1612 |
} |
| 1613 |
uint foo<T:MyConvertibleToUint>(T x) { return uint(x); } |
| 1614 |
uint bar() { return foo(42u); } |
| 1615 |
`); |
| 1616 |
checkUint(program, callFunction(program, "bar", [], []), 42); |
| 1617 |
} |
| 1618 |
|
| 1619 |
tests.intLiteralGenericSpecific = function() |
| 1620 |
{ |
| 1621 |
let program = doPrep(` |
| 1622 |
T foo<T>(T x) { return x; } |
| 1623 |
int bar() { return foo(int(42)); } |
| 1624 |
`); |
| 1625 |
checkInt(program, callFunction(program, "bar", [], []), 42); |
| 1626 |
} |
| 1627 |
|
| 1628 |
tests.simpleConstexpr = function() |
| 1629 |
{ |
| 1630 |
let program = doPrep(` |
| 1631 |
int foo<int a>(int b) |
| 1632 |
{ |
| 1633 |
return a + b; |
| 1634 |
} |
| 1635 |
int bar(int b) |
| 1636 |
{ |
| 1637 |
return foo<42>(b); |
| 1638 |
} |
| 1639 |
`); |
| 1640 |
checkInt(program, callFunction(program, "bar", [], [makeInt(program, 58)]), 58 + 42); |
| 1641 |
} |
| 1642 |
|
| 1643 |
tests.break = function() |
1210 |
tests.break = function() |
| 1644 |
{ |
1211 |
{ |
| 1645 |
let program = doPrep(` |
1212 |
let program = doPrep(` |
|
Lines 1993-2217
tests.forLoop = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec15
|
| 1993 |
checkInt(program, callFunction(program, "foo", [], [makeInt(program, 7)]), 7); |
1560 |
checkInt(program, callFunction(program, "foo", [], [makeInt(program, 7)]), 7); |
| 1994 |
} |
1561 |
} |
| 1995 |
|
1562 |
|
| 1996 |
tests.chainConstexpr = function() |
1563 |
tests.prefixPlusPlus = function() |
| 1997 |
{ |
|
|
| 1998 |
let program = doPrep(` |
| 1999 |
int foo<int a>(int b) |
| 2000 |
{ |
| 2001 |
return a + b; |
| 2002 |
} |
| 2003 |
int bar<int a>(int b) |
| 2004 |
{ |
| 2005 |
return foo<a>(b); |
| 2006 |
} |
| 2007 |
int baz(int b) |
| 2008 |
{ |
| 2009 |
return bar<42>(b); |
| 2010 |
} |
| 2011 |
`); |
| 2012 |
checkInt(program, callFunction(program, "baz", [], [makeInt(program, 58)]), 58 + 42); |
| 2013 |
} |
| 2014 |
|
| 2015 |
tests.chainGeneric = function() |
| 2016 |
{ |
| 2017 |
let program = doPrep(` |
| 2018 |
T foo<T>(T x) |
| 2019 |
{ |
| 2020 |
return x; |
| 2021 |
} |
| 2022 |
T bar<T>(thread T* ptr) |
| 2023 |
{ |
| 2024 |
return *foo(ptr); |
| 2025 |
} |
| 2026 |
int baz(int x) |
| 2027 |
{ |
| 2028 |
return bar(&x); |
| 2029 |
} |
| 2030 |
`); |
| 2031 |
checkInt(program, callFunction(program, "baz", [], [makeInt(program, 37)]), 37); |
| 2032 |
} |
| 2033 |
|
| 2034 |
tests.chainStruct = function() |
| 2035 |
{ |
| 2036 |
let program = doPrep(` |
| 2037 |
struct Foo<T> { |
| 2038 |
T f; |
| 2039 |
} |
| 2040 |
struct Bar<T> { |
| 2041 |
Foo<thread T*> f; |
| 2042 |
} |
| 2043 |
int foo(thread Bar<int>* x) |
| 2044 |
{ |
| 2045 |
return *x->f.f; |
| 2046 |
} |
| 2047 |
int bar(int a) |
| 2048 |
{ |
| 2049 |
Bar<int> x; |
| 2050 |
x.f.f = &a; |
| 2051 |
return foo(&x); |
| 2052 |
} |
| 2053 |
`); |
| 2054 |
checkInt(program, callFunction(program, "bar", [], [makeInt(program, 4657)]), 4657); |
| 2055 |
} |
| 2056 |
|
| 2057 |
tests.chainStructNewlyValid = function() |
| 2058 |
{ |
| 2059 |
let program = doPrep(` |
| 2060 |
struct Foo<T> { |
| 2061 |
T f; |
| 2062 |
} |
| 2063 |
struct Bar<T> { |
| 2064 |
Foo<device T*> f; |
| 2065 |
} |
| 2066 |
int foo(thread Bar<int>* x) |
| 2067 |
{ |
| 2068 |
return *x->f.f; |
| 2069 |
} |
| 2070 |
int bar(device int* a) |
| 2071 |
{ |
| 2072 |
Bar<int> x; |
| 2073 |
x.f.f = a; |
| 2074 |
return foo(&x); |
| 2075 |
} |
| 2076 |
`); |
| 2077 |
let buffer = new EBuffer(1); |
| 2078 |
buffer.set(0, 78453); |
| 2079 |
checkInt(program, callFunction(program, "bar", [], [TypedValue.box(new PtrType(externalOrigin, "device", program.intrinsics.int32), new EPtr(buffer, 0))]), 78453); |
| 2080 |
} |
| 2081 |
|
| 2082 |
tests.chainStructDevice = function() |
| 2083 |
{ |
| 2084 |
let program = doPrep(` |
| 2085 |
struct Foo<T> { |
| 2086 |
T f; |
| 2087 |
} |
| 2088 |
struct Bar<T> { |
| 2089 |
Foo<device T*> f; |
| 2090 |
} |
| 2091 |
int foo(thread Bar<int>* x) |
| 2092 |
{ |
| 2093 |
return *x->f.f; |
| 2094 |
} |
| 2095 |
int bar(device int* a) |
| 2096 |
{ |
| 2097 |
Bar<int> x; |
| 2098 |
x.f.f = a; |
| 2099 |
return foo(&x); |
| 2100 |
} |
| 2101 |
`); |
| 2102 |
let buffer = new EBuffer(1); |
| 2103 |
buffer.set(0, 79201); |
| 2104 |
checkInt(program, callFunction(program, "bar", [], [TypedValue.box(new PtrType(externalOrigin, "device", program.intrinsics.int32), new EPtr(buffer, 0))]), 79201); |
| 2105 |
} |
| 2106 |
|
| 2107 |
tests.paramChainStructDevice = function() |
| 2108 |
{ |
| 2109 |
let program = doPrep(` |
| 2110 |
struct Foo<T> { |
| 2111 |
T f; |
| 2112 |
} |
| 2113 |
struct Bar<T> { |
| 2114 |
Foo<T> f; |
| 2115 |
} |
| 2116 |
int foo(thread Bar<device int*>* x) |
| 2117 |
{ |
| 2118 |
return *x->f.f; |
| 2119 |
} |
| 2120 |
int bar(device int* a) |
| 2121 |
{ |
| 2122 |
Bar<device int*> x; |
| 2123 |
x.f.f = a; |
| 2124 |
return foo(&x); |
| 2125 |
} |
| 2126 |
`); |
| 2127 |
let buffer = new EBuffer(1); |
| 2128 |
buffer.set(0, 79201); |
| 2129 |
checkInt(program, callFunction(program, "bar", [], [TypedValue.box(new PtrType(externalOrigin, "device", program.intrinsics.int32), new EPtr(buffer, 0))]), 79201); |
| 2130 |
} |
| 2131 |
|
| 2132 |
tests.simpleProtocolExtends = function() |
| 2133 |
{ |
| 2134 |
let program = doPrep(` |
| 2135 |
protocol Foo { |
| 2136 |
void foo(thread Foo*); |
| 2137 |
} |
| 2138 |
protocol Bar : Foo { |
| 2139 |
void bar(thread Bar*); |
| 2140 |
} |
| 2141 |
void fuzz<T:Foo>(thread T* p) |
| 2142 |
{ |
| 2143 |
foo(p); |
| 2144 |
} |
| 2145 |
void buzz<T:Bar>(thread T* p) |
| 2146 |
{ |
| 2147 |
fuzz(p); |
| 2148 |
bar(p); |
| 2149 |
} |
| 2150 |
void foo(thread int* p) |
| 2151 |
{ |
| 2152 |
*p = *p + 743; |
| 2153 |
} |
| 2154 |
void bar(thread int* p) |
| 2155 |
{ |
| 2156 |
*p = *p + 91; |
| 2157 |
} |
| 2158 |
int thingy(int a) |
| 2159 |
{ |
| 2160 |
buzz(&a); |
| 2161 |
return a; |
| 2162 |
} |
| 2163 |
`); |
| 2164 |
checkInt(program, callFunction(program, "thingy", [], [makeInt(program, 642)]), 642 + 743 + 91); |
| 2165 |
} |
| 2166 |
|
| 2167 |
tests.protocolExtendsTwo = function() |
| 2168 |
{ |
| 2169 |
let program = doPrep(` |
| 2170 |
protocol Foo { |
| 2171 |
void foo(thread Foo*); |
| 2172 |
} |
| 2173 |
protocol Bar { |
| 2174 |
void bar(thread Bar*); |
| 2175 |
} |
| 2176 |
protocol Baz : Foo, Bar { |
| 2177 |
void baz(thread Baz*); |
| 2178 |
} |
| 2179 |
void fuzz<T:Foo>(thread T* p) |
| 2180 |
{ |
| 2181 |
foo(p); |
| 2182 |
} |
| 2183 |
void buzz<T:Bar>(thread T* p) |
| 2184 |
{ |
| 2185 |
bar(p); |
| 2186 |
} |
| 2187 |
void xuzz<T:Baz>(thread T* p) |
| 2188 |
{ |
| 2189 |
fuzz(p); |
| 2190 |
buzz(p); |
| 2191 |
baz(p); |
| 2192 |
} |
| 2193 |
void foo(thread int* p) |
| 2194 |
{ |
| 2195 |
*p = *p + 743; |
| 2196 |
} |
| 2197 |
void bar(thread int* p) |
| 2198 |
{ |
| 2199 |
*p = *p + 91; |
| 2200 |
} |
| 2201 |
void baz(thread int* p) |
| 2202 |
{ |
| 2203 |
*p = *p + 39; |
| 2204 |
} |
| 2205 |
int thingy(int a) |
| 2206 |
{ |
| 2207 |
xuzz(&a); |
| 2208 |
return a; |
| 2209 |
} |
| 2210 |
`); |
| 2211 |
checkInt(program, callFunction(program, "thingy", [], [makeInt(program, 642)]), 642 + 743 + 91 + 39); |
| 2212 |
} |
| 2213 |
|
| 2214 |
tests.prefixPlusPlus = function() |
| 2215 |
{ |
1564 |
{ |
| 2216 |
let program = doPrep(` |
1565 |
let program = doPrep(` |
| 2217 |
int foo(int x) |
1566 |
int foo(int x) |
|
Lines 2406-2471
tests.twoIntLiterals = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec16
|
| 2406 |
checkBool(program, callFunction(program, "foo", [], []), true); |
1755 |
checkBool(program, callFunction(program, "foo", [], []), true); |
| 2407 |
} |
1756 |
} |
| 2408 |
|
1757 |
|
| 2409 |
tests.unifyDifferentLiterals = function() |
|
|
| 2410 |
{ |
| 2411 |
checkFail( |
| 2412 |
() => doPrep(` |
| 2413 |
void bar<T>(T, T) |
| 2414 |
{ |
| 2415 |
} |
| 2416 |
void foo() |
| 2417 |
{ |
| 2418 |
bar(42, 42u); |
| 2419 |
} |
| 2420 |
`), |
| 2421 |
(e) => e instanceof WTypeError); |
| 2422 |
} |
| 2423 |
|
| 2424 |
tests.unifyDifferentLiteralsBackwards = function() |
| 2425 |
{ |
| 2426 |
checkFail( |
| 2427 |
() => doPrep(` |
| 2428 |
void bar<T>(T, T) |
| 2429 |
{ |
| 2430 |
} |
| 2431 |
void foo() |
| 2432 |
{ |
| 2433 |
bar(42u, 42); |
| 2434 |
} |
| 2435 |
`), |
| 2436 |
(e) => e instanceof WTypeError); |
| 2437 |
} |
| 2438 |
|
| 2439 |
tests.unifyVeryDifferentLiterals = function() |
| 2440 |
{ |
| 2441 |
checkFail( |
| 2442 |
() => doPrep(` |
| 2443 |
void bar<T>(T, T) |
| 2444 |
{ |
| 2445 |
} |
| 2446 |
void foo() |
| 2447 |
{ |
| 2448 |
bar(42, null); |
| 2449 |
} |
| 2450 |
`), |
| 2451 |
(e) => e instanceof WTypeError); |
| 2452 |
} |
| 2453 |
|
| 2454 |
tests.unifyVeryDifferentLiteralsBackwards = function() |
| 2455 |
{ |
| 2456 |
checkFail( |
| 2457 |
() => doPrep(` |
| 2458 |
void bar<T>(T, T) |
| 2459 |
{ |
| 2460 |
} |
| 2461 |
void foo() |
| 2462 |
{ |
| 2463 |
bar(null, 42); |
| 2464 |
} |
| 2465 |
`), |
| 2466 |
(e) => e instanceof WTypeError); |
| 2467 |
} |
| 2468 |
|
| 2469 |
tests.assignUintToInt = function() |
1758 |
tests.assignUintToInt = function() |
| 2470 |
{ |
1759 |
{ |
| 2471 |
checkFail( |
1760 |
checkFail( |
|
Lines 2691-2697
tests.simpleLength = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec17
|
| 2691 |
let program = doPrep(` |
1980 |
let program = doPrep(` |
| 2692 |
uint foo() |
1981 |
uint foo() |
| 2693 |
{ |
1982 |
{ |
| 2694 |
double[754] array; |
1983 |
float[754] array; |
| 2695 |
return (@array).length; |
1984 |
return (@array).length; |
| 2696 |
} |
1985 |
} |
| 2697 |
`); |
1986 |
`); |
|
Lines 2703-2713
tests.nonArrayRefArrayLengthSucceed = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec18
|
| 2703 |
let program = doPrep(` |
1992 |
let program = doPrep(` |
| 2704 |
uint foo() |
1993 |
uint foo() |
| 2705 |
{ |
1994 |
{ |
| 2706 |
double[754] array; |
1995 |
float[754] array; |
|
|
1996 |
return array.length; |
| 1997 |
} |
| 1998 |
uint bar() |
| 1999 |
{ |
| 2000 |
int[754] array; |
| 2707 |
return array.length; |
2001 |
return array.length; |
| 2708 |
} |
2002 |
} |
| 2709 |
`); |
2003 |
`); |
| 2710 |
checkUint(program, callFunction(program, "foo", [], []), 754); |
2004 |
checkUint(program, callFunction(program, "foo", [], []), 754); |
|
|
2005 |
checkUint(program, callFunction(program, "bar", [], []), 754); |
| 2711 |
} |
2006 |
} |
| 2712 |
|
2007 |
|
| 2713 |
tests.nonArrayRefArrayLengthFail = function() |
2008 |
tests.nonArrayRefArrayLengthFail = function() |
|
Lines 2723-2792
tests.nonArrayRefArrayLengthFail = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec19
|
| 2723 |
e => e instanceof WTypeError); |
2018 |
e => e instanceof WTypeError); |
| 2724 |
} |
2019 |
} |
| 2725 |
|
2020 |
|
| 2726 |
tests.constexprIsNotLValuePtr = function() |
|
|
| 2727 |
{ |
| 2728 |
checkFail( |
| 2729 |
() => doPrep(` |
| 2730 |
thread int* foo<int x>() |
| 2731 |
{ |
| 2732 |
return &x; |
| 2733 |
} |
| 2734 |
`), |
| 2735 |
e => e instanceof WTypeError); |
| 2736 |
} |
| 2737 |
|
| 2738 |
tests.constexprIsNotLValueAssign = function() |
| 2739 |
{ |
| 2740 |
checkFail( |
| 2741 |
() => doPrep(` |
| 2742 |
void foo<int x>() |
| 2743 |
{ |
| 2744 |
x = 42; |
| 2745 |
} |
| 2746 |
`), |
| 2747 |
e => e instanceof WTypeError); |
| 2748 |
} |
| 2749 |
|
| 2750 |
tests.constexprIsNotLValueRMW = function() |
| 2751 |
{ |
| 2752 |
checkFail( |
| 2753 |
() => doPrep(` |
| 2754 |
void foo<int x>() |
| 2755 |
{ |
| 2756 |
x += 42; |
| 2757 |
} |
| 2758 |
`), |
| 2759 |
e => e instanceof WTypeError); |
| 2760 |
} |
| 2761 |
|
| 2762 |
tests.assignLength = function() |
2021 |
tests.assignLength = function() |
| 2763 |
{ |
2022 |
{ |
| 2764 |
checkFail( |
2023 |
checkFail( |
| 2765 |
() => doPrep(` |
2024 |
() => doPrep(` |
| 2766 |
void foo() |
2025 |
void foo() |
| 2767 |
{ |
2026 |
{ |
| 2768 |
double[754] array; |
2027 |
float[754] array; |
| 2769 |
(@array).length = 42; |
2028 |
(@array).length = 42; |
| 2770 |
} |
2029 |
} |
| 2771 |
`), |
2030 |
`), |
| 2772 |
(e) => e instanceof WTypeError && e.message.indexOf("Have neither ander nor setter") != -1); |
2031 |
(e) => e instanceof WTypeError); |
| 2773 |
} |
2032 |
} |
| 2774 |
|
2033 |
|
| 2775 |
tests.assignLengthHelper = function() |
2034 |
tests.assignLengthHelper = function() |
| 2776 |
{ |
2035 |
{ |
| 2777 |
checkFail( |
2036 |
checkFail( |
| 2778 |
() => doPrep(` |
2037 |
() => doPrep(` |
| 2779 |
void bar(thread double[] array) |
2038 |
void bar(thread float[] array) |
| 2780 |
{ |
2039 |
{ |
| 2781 |
array.length = 42; |
2040 |
array.length = 42; |
| 2782 |
} |
2041 |
} |
| 2783 |
void foo() |
2042 |
void foo() |
| 2784 |
{ |
2043 |
{ |
| 2785 |
double[754] array; |
2044 |
float[754] array; |
| 2786 |
bar(@array); |
2045 |
bar(@array); |
| 2787 |
} |
2046 |
} |
| 2788 |
`), |
2047 |
`), |
| 2789 |
(e) => e instanceof WTypeError && e.message.indexOf("Have neither ander nor setter") != -1); |
2048 |
(e) => e instanceof WTypeError); |
| 2790 |
} |
2049 |
} |
| 2791 |
|
2050 |
|
| 2792 |
tests.simpleGetter = function() |
2051 |
tests.simpleGetter = function() |
|
Lines 2834-3068
tests.simpleSetter = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec20
|
| 2834 |
checkInt(program, callFunction(program, "foo", [], []), 7804); |
2093 |
checkInt(program, callFunction(program, "foo", [], []), 7804); |
| 2835 |
} |
2094 |
} |
| 2836 |
|
2095 |
|
| 2837 |
tests.genericAccessors = function() |
|
|
| 2838 |
{ |
| 2839 |
let program = doPrep(` |
| 2840 |
struct Foo<T> { |
| 2841 |
T x; |
| 2842 |
T[3] y; |
| 2843 |
} |
| 2844 |
struct Bar<T> { |
| 2845 |
T x; |
| 2846 |
T y; |
| 2847 |
} |
| 2848 |
Bar<T> operator.z<T>(Foo<T> foo) |
| 2849 |
{ |
| 2850 |
Bar<T> result; |
| 2851 |
result.x = foo.x; |
| 2852 |
result.y = foo.y[1]; |
| 2853 |
return result; |
| 2854 |
} |
| 2855 |
Foo<T> operator.z=<T>(Foo<T> foo, Bar<T> bar) |
| 2856 |
{ |
| 2857 |
foo.x = bar.x; |
| 2858 |
foo.y[1] = bar.y; |
| 2859 |
return foo; |
| 2860 |
} |
| 2861 |
T operator.sum<T:Addable>(Foo<T> foo) |
| 2862 |
{ |
| 2863 |
return foo.x + foo.y[0] + foo.y[1] + foo.y[2]; |
| 2864 |
} |
| 2865 |
T operator.sum<T:Addable>(Bar<T> bar) |
| 2866 |
{ |
| 2867 |
return bar.x + bar.y; |
| 2868 |
} |
| 2869 |
operator<T> Bar<T>(T x, T y) |
| 2870 |
{ |
| 2871 |
Bar<T> result; |
| 2872 |
result.x = x; |
| 2873 |
result.y = y; |
| 2874 |
return result; |
| 2875 |
} |
| 2876 |
void setup(thread Foo<int>* foo) |
| 2877 |
{ |
| 2878 |
foo->x = 1; |
| 2879 |
foo->y[0] = 2; |
| 2880 |
foo->y[1] = 3; |
| 2881 |
foo->y[2] = 4; |
| 2882 |
} |
| 2883 |
int testSuperBasic() |
| 2884 |
{ |
| 2885 |
Foo<int> foo; |
| 2886 |
setup(&foo); |
| 2887 |
return foo.sum; |
| 2888 |
} |
| 2889 |
int testZSetterDidSetY() |
| 2890 |
{ |
| 2891 |
Foo<int> foo; |
| 2892 |
foo.z = Bar<int>(53, 932); |
| 2893 |
return foo.y[1]; |
| 2894 |
} |
| 2895 |
int testZSetter() |
| 2896 |
{ |
| 2897 |
Foo<int> foo; |
| 2898 |
foo.z = Bar<int>(53, 932); |
| 2899 |
return foo.sum; |
| 2900 |
} |
| 2901 |
int testZGetter() |
| 2902 |
{ |
| 2903 |
Foo<int> foo; |
| 2904 |
// This deliberately does not call setup() just so we test this syntax. |
| 2905 |
foo.x = 1; |
| 2906 |
foo.y[0] = 2; |
| 2907 |
foo.y[1] = 3; |
| 2908 |
foo.y[2] = 4; |
| 2909 |
return foo.z.sum; |
| 2910 |
} |
| 2911 |
int testLValueEmulation() |
| 2912 |
{ |
| 2913 |
Foo<int> foo; |
| 2914 |
setup(&foo); |
| 2915 |
foo.z.y *= 5; |
| 2916 |
return foo.sum; |
| 2917 |
} |
| 2918 |
`); |
| 2919 |
checkInt(program, callFunction(program, "testSuperBasic", [], []), 1 + 2 + 3 + 4); |
| 2920 |
checkInt(program, callFunction(program, "testZSetterDidSetY", [], []), 932); |
| 2921 |
checkInt(program, callFunction(program, "testZSetter", [], []), 53 + 932); |
| 2922 |
checkInt(program, callFunction(program, "testZGetter", [], []), 1 + 3); |
| 2923 |
checkInt(program, callFunction(program, "testLValueEmulation", [], []), 1 + 2 + 3 * 5 + 4); |
| 2924 |
} |
| 2925 |
|
| 2926 |
tests.bitSubscriptAccessor = function() |
| 2927 |
{ |
| 2928 |
let program = doPrep(` |
| 2929 |
protocol MyBitmaskable : Equatable { |
| 2930 |
MyBitmaskable operator&(MyBitmaskable, MyBitmaskable); |
| 2931 |
MyBitmaskable operator|(MyBitmaskable, MyBitmaskable); |
| 2932 |
MyBitmaskable operator~(MyBitmaskable); |
| 2933 |
MyBitmaskable operator<<(MyBitmaskable, uint); |
| 2934 |
MyBitmaskable operator>>(MyBitmaskable, uint); |
| 2935 |
operator MyBitmaskable(int); |
| 2936 |
} |
| 2937 |
T maskForBitIndex<T:MyBitmaskable>(uint index) |
| 2938 |
{ |
| 2939 |
return T(1) << index; |
| 2940 |
} |
| 2941 |
bool operator[]<T:MyBitmaskable>(T value, uint index) |
| 2942 |
{ |
| 2943 |
return bool(value & maskForBitIndex<T>(index)); |
| 2944 |
} |
| 2945 |
T operator[]=<T:MyBitmaskable>(T value, uint index, bool bit) |
| 2946 |
{ |
| 2947 |
T mask = maskForBitIndex<T>(index); |
| 2948 |
if (bit) |
| 2949 |
value |= mask; |
| 2950 |
else |
| 2951 |
value &= ~mask; |
| 2952 |
return value; |
| 2953 |
} |
| 2954 |
uint operator.length(int) |
| 2955 |
{ |
| 2956 |
return 32; |
| 2957 |
} |
| 2958 |
uint operator.length(uint) |
| 2959 |
{ |
| 2960 |
return 32; |
| 2961 |
} |
| 2962 |
int testIntSetBit3() |
| 2963 |
{ |
| 2964 |
int foo; |
| 2965 |
foo[3] = true; |
| 2966 |
return foo; |
| 2967 |
} |
| 2968 |
bool testIntSetGetBit5() |
| 2969 |
{ |
| 2970 |
int foo; |
| 2971 |
foo[5] = true; |
| 2972 |
return foo[5]; |
| 2973 |
} |
| 2974 |
bool testIntGetBit1() |
| 2975 |
{ |
| 2976 |
int foo; |
| 2977 |
return foo[1]; |
| 2978 |
} |
| 2979 |
int testUintSumBits() |
| 2980 |
{ |
| 2981 |
int foo = 42; |
| 2982 |
int result; |
| 2983 |
for (uint i = 0; i < foo.length; ++i) { |
| 2984 |
if (foo[i]) |
| 2985 |
result++; |
| 2986 |
} |
| 2987 |
return result; |
| 2988 |
} |
| 2989 |
int testUintSwapBits() |
| 2990 |
{ |
| 2991 |
int foo = 42; |
| 2992 |
for (uint i = 0; i < foo.length / 2; ++i) { |
| 2993 |
bool tmp = foo[i]; |
| 2994 |
foo[i] = foo[foo.length - i - 1]; |
| 2995 |
foo[foo.length - i - 1] = tmp; |
| 2996 |
} |
| 2997 |
return foo; |
| 2998 |
} |
| 2999 |
struct Foo { |
| 3000 |
uint f; |
| 3001 |
uint g; |
| 3002 |
} |
| 3003 |
operator Foo(uint f, uint g) |
| 3004 |
{ |
| 3005 |
Foo result; |
| 3006 |
result.f = f; |
| 3007 |
result.g = g; |
| 3008 |
return result; |
| 3009 |
} |
| 3010 |
int operator.h(Foo foo) |
| 3011 |
{ |
| 3012 |
return int((foo.f & 0xffff) | ((foo.g & 0xffff) << 16)); |
| 3013 |
} |
| 3014 |
Foo operator.h=(Foo foo, int value) |
| 3015 |
{ |
| 3016 |
foo.f &= ~0xffffu; |
| 3017 |
foo.f |= uint(value) & 0xffff; |
| 3018 |
foo.g &= ~0xffffu; |
| 3019 |
foo.g |= (uint(value) >> 16) & 0xffff; |
| 3020 |
return foo; |
| 3021 |
} |
| 3022 |
int testLValueEmulation() |
| 3023 |
{ |
| 3024 |
Foo foo; |
| 3025 |
foo.f = 42; |
| 3026 |
foo.g = 37; |
| 3027 |
for (uint i = 0; i < foo.h.length; ++i) |
| 3028 |
foo.h[i] ^= true; |
| 3029 |
return int(foo.f + foo.g); |
| 3030 |
} |
| 3031 |
struct Bar { |
| 3032 |
Foo a; |
| 3033 |
Foo b; |
| 3034 |
} |
| 3035 |
Foo operator.c(Bar bar) |
| 3036 |
{ |
| 3037 |
return Foo(uint(bar.a.h), uint(bar.b.h)); |
| 3038 |
} |
| 3039 |
Bar operator.c=(Bar bar, Foo foo) |
| 3040 |
{ |
| 3041 |
bar.a.h = int(foo.f); |
| 3042 |
bar.b.h = int(foo.g); |
| 3043 |
return bar; |
| 3044 |
} |
| 3045 |
int testCrazyLValueEmulation() |
| 3046 |
{ |
| 3047 |
Bar bar; |
| 3048 |
bar.a.f = 1; |
| 3049 |
bar.a.g = 2; |
| 3050 |
bar.b.f = 3; |
| 3051 |
bar.b.g = 4; |
| 3052 |
for (uint i = 0; i < bar.c.h.length; i += 2) |
| 3053 |
bar.c.h[i] ^= true; |
| 3054 |
return int(bar.a.f + bar.a.g + bar.b.f + bar.b.g); |
| 3055 |
} |
| 3056 |
`); |
| 3057 |
checkInt(program, callFunction(program, "testIntSetBit3", [], []), 8); |
| 3058 |
checkBool(program, callFunction(program, "testIntSetGetBit5", [], []), true); |
| 3059 |
checkBool(program, callFunction(program, "testIntGetBit1", [], []), false); |
| 3060 |
checkInt(program, callFunction(program, "testUintSumBits", [], []), 3); |
| 3061 |
checkInt(program, callFunction(program, "testUintSwapBits", [], []), 1409286144); |
| 3062 |
checkInt(program, callFunction(program, "testLValueEmulation", [], []), 130991); |
| 3063 |
checkInt(program, callFunction(program, "testCrazyLValueEmulation", [], []), 43696); |
| 3064 |
} |
| 3065 |
|
| 3066 |
tests.nestedSubscriptLValueEmulationSimple = function() |
2096 |
tests.nestedSubscriptLValueEmulationSimple = function() |
| 3067 |
{ |
2097 |
{ |
| 3068 |
let program = doPrep(` |
2098 |
let program = doPrep(` |
|
Lines 3167-3283
tests.nestedSubscriptLValueEmulationSimple = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec21
|
| 3167 |
checkInt(program, callFunction(program, "testSetValuesMutateValuesAndSum", [], []), 5565); |
2197 |
checkInt(program, callFunction(program, "testSetValuesMutateValuesAndSum", [], []), 5565); |
| 3168 |
} |
2198 |
} |
| 3169 |
|
2199 |
|
| 3170 |
tests.nestedSubscriptLValueEmulationGeneric = function() |
|
|
| 3171 |
{ |
| 3172 |
let program = doPrep(` |
| 3173 |
struct Foo<T> { |
| 3174 |
T[7] array; |
| 3175 |
} |
| 3176 |
T operator[]<T>(Foo<T> foo, uint index) |
| 3177 |
{ |
| 3178 |
return foo.array[index]; |
| 3179 |
} |
| 3180 |
Foo<T> operator[]=<T>(Foo<T> foo, uint index, T value) |
| 3181 |
{ |
| 3182 |
foo.array[index] = value; |
| 3183 |
return foo; |
| 3184 |
} |
| 3185 |
uint operator.length<T>(Foo<T> foo) |
| 3186 |
{ |
| 3187 |
return foo.array.length; |
| 3188 |
} |
| 3189 |
protocol MyAddable { |
| 3190 |
MyAddable operator+(MyAddable, MyAddable); |
| 3191 |
} |
| 3192 |
T sum<T:MyAddable>(Foo<T> foo) |
| 3193 |
{ |
| 3194 |
T result; |
| 3195 |
for (uint i = foo.length; i--;) |
| 3196 |
result += foo[i]; |
| 3197 |
return result; |
| 3198 |
} |
| 3199 |
struct Bar<T> { |
| 3200 |
Foo<T>[6] array; |
| 3201 |
} |
| 3202 |
uint operator.length<T>(Bar<T> bar) |
| 3203 |
{ |
| 3204 |
return bar.array.length; |
| 3205 |
} |
| 3206 |
Foo<T> operator[]<T>(Bar<T> bar, uint index) |
| 3207 |
{ |
| 3208 |
return bar.array[index]; |
| 3209 |
} |
| 3210 |
Bar<T> operator[]=<T>(Bar<T> bar, uint index, Foo<T> value) |
| 3211 |
{ |
| 3212 |
bar.array[index] = value; |
| 3213 |
return bar; |
| 3214 |
} |
| 3215 |
T sum<T:MyAddable>(Bar<T> bar) |
| 3216 |
{ |
| 3217 |
T result; |
| 3218 |
for (uint i = bar.length; i--;) |
| 3219 |
result += sum(bar[i]); |
| 3220 |
return result; |
| 3221 |
} |
| 3222 |
struct Baz<T> { |
| 3223 |
Bar<T>[5] array; |
| 3224 |
} |
| 3225 |
Bar<T> operator[]<T>(Baz<T> baz, uint index) |
| 3226 |
{ |
| 3227 |
return baz.array[index]; |
| 3228 |
} |
| 3229 |
Baz<T> operator[]=<T>(Baz<T> baz, uint index, Bar<T> value) |
| 3230 |
{ |
| 3231 |
baz.array[index] = value; |
| 3232 |
return baz; |
| 3233 |
} |
| 3234 |
uint operator.length<T>(Baz<T> baz) |
| 3235 |
{ |
| 3236 |
return baz.array.length; |
| 3237 |
} |
| 3238 |
T sum<T:MyAddable>(Baz<T> baz) |
| 3239 |
{ |
| 3240 |
T result; |
| 3241 |
for (uint i = baz.length; i--;) |
| 3242 |
result += sum(baz[i]); |
| 3243 |
return result; |
| 3244 |
} |
| 3245 |
protocol MyConvertibleFromUint { |
| 3246 |
operator MyConvertibleFromUint(uint); |
| 3247 |
} |
| 3248 |
protocol SetValuable : MyAddable, MyConvertibleFromUint { } |
| 3249 |
void setValues<T:SetValuable>(thread Baz<T>* baz) |
| 3250 |
{ |
| 3251 |
for (uint i = baz->length; i--;) { |
| 3252 |
for (uint j = (*baz)[i].length; j--;) { |
| 3253 |
for (uint k = (*baz)[i][j].length; k--;) |
| 3254 |
(*baz)[i][j][k] = T(i + j + k); |
| 3255 |
} |
| 3256 |
} |
| 3257 |
} |
| 3258 |
int testSetValuesAndSum() |
| 3259 |
{ |
| 3260 |
Baz<int> baz; |
| 3261 |
setValues(&baz); |
| 3262 |
return sum(baz); |
| 3263 |
} |
| 3264 |
int testSetValuesMutateValuesAndSum() |
| 3265 |
{ |
| 3266 |
Baz<int> baz; |
| 3267 |
setValues(&baz); |
| 3268 |
for (uint i = baz.length; i--;) { |
| 3269 |
for (uint j = baz[i].length; j--;) { |
| 3270 |
for (uint k = baz[i][j].length; k--;) |
| 3271 |
baz[i][j][k] *= int(k); |
| 3272 |
} |
| 3273 |
} |
| 3274 |
return sum(baz); |
| 3275 |
} |
| 3276 |
`); |
| 3277 |
checkInt(program, callFunction(program, "testSetValuesAndSum", [], []), 1575); |
| 3278 |
checkInt(program, callFunction(program, "testSetValuesMutateValuesAndSum", [], []), 5565); |
| 3279 |
} |
| 3280 |
|
| 3281 |
tests.boolBitAnd = function() |
2200 |
tests.boolBitAnd = function() |
| 3282 |
{ |
2201 |
{ |
| 3283 |
let program = doPrep(` |
2202 |
let program = doPrep(` |
|
Lines 3605-3611
tests.floatMath = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec22
|
| 3605 |
} |
2524 |
} |
| 3606 |
bool foo5() |
2525 |
bool foo5() |
| 3607 |
{ |
2526 |
{ |
| 3608 |
return 42.5d == 42.5d; |
2527 |
return 42.5f == 42.5f; |
| 3609 |
} |
2528 |
} |
| 3610 |
float bar(float x) |
2529 |
float bar(float x) |
| 3611 |
{ |
2530 |
{ |
|
Lines 3619-3628
tests.floatMath = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec23
|
| 3619 |
{ |
2538 |
{ |
| 3620 |
return bar(7.5f); |
2539 |
return bar(7.5f); |
| 3621 |
} |
2540 |
} |
| 3622 |
float foo8() |
|
|
| 3623 |
{ |
| 3624 |
return bar(7.5d); |
| 3625 |
} |
| 3626 |
float foo9() |
2541 |
float foo9() |
| 3627 |
{ |
2542 |
{ |
| 3628 |
return float(7.5); |
2543 |
return float(7.5); |
|
Lines 3631-3654
tests.floatMath = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec24
|
| 3631 |
{ |
2546 |
{ |
| 3632 |
return float(7.5f); |
2547 |
return float(7.5f); |
| 3633 |
} |
2548 |
} |
| 3634 |
float foo11() |
|
|
| 3635 |
{ |
| 3636 |
return float(7.5d); |
| 3637 |
} |
| 3638 |
float foo12() |
2549 |
float foo12() |
| 3639 |
{ |
2550 |
{ |
| 3640 |
return float(7); |
2551 |
return float(7); |
| 3641 |
} |
2552 |
} |
| 3642 |
float foo13() |
2553 |
float foo13() |
| 3643 |
{ |
2554 |
{ |
| 3644 |
double x = 7.5d; |
2555 |
float x = 7.5f; |
| 3645 |
return float(x); |
2556 |
return float(x); |
| 3646 |
} |
2557 |
} |
| 3647 |
double foo14() |
|
|
| 3648 |
{ |
| 3649 |
double x = 7.5f; |
| 3650 |
return double(x); |
| 3651 |
} |
| 3652 |
`); |
2558 |
`); |
| 3653 |
checkBool(program, callFunction(program, "foo", [], []), true); |
2559 |
checkBool(program, callFunction(program, "foo", [], []), true); |
| 3654 |
checkBool(program, callFunction(program, "foo2", [], []), true); |
2560 |
checkBool(program, callFunction(program, "foo2", [], []), true); |
|
Lines 3657-3669
tests.floatMath = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec25
|
| 3657 |
checkBool(program, callFunction(program, "foo5", [], []), true); |
2563 |
checkBool(program, callFunction(program, "foo5", [], []), true); |
| 3658 |
checkFloat(program, callFunction(program, "foo6", [], []), 7.5); |
2564 |
checkFloat(program, callFunction(program, "foo6", [], []), 7.5); |
| 3659 |
checkFloat(program, callFunction(program, "foo7", [], []), 7.5); |
2565 |
checkFloat(program, callFunction(program, "foo7", [], []), 7.5); |
| 3660 |
checkFloat(program, callFunction(program, "foo8", [], []), 7.5); |
|
|
| 3661 |
checkFloat(program, callFunction(program, "foo9", [], []), 7.5); |
2566 |
checkFloat(program, callFunction(program, "foo9", [], []), 7.5); |
| 3662 |
checkFloat(program, callFunction(program, "foo10", [], []), 7.5); |
2567 |
checkFloat(program, callFunction(program, "foo10", [], []), 7.5); |
| 3663 |
checkFloat(program, callFunction(program, "foo11", [], []), 7.5); |
|
|
| 3664 |
checkFloat(program, callFunction(program, "foo12", [], []), 7); |
2568 |
checkFloat(program, callFunction(program, "foo12", [], []), 7); |
| 3665 |
checkFloat(program, callFunction(program, "foo13", [], []), 7.5); |
2569 |
checkFloat(program, callFunction(program, "foo13", [], []), 7.5); |
| 3666 |
checkDouble(program, callFunction(program, "foo14", [], []), 7.5); |
|
|
| 3667 |
checkFail( |
2570 |
checkFail( |
| 3668 |
() => doPrep(` |
2571 |
() => doPrep(` |
| 3669 |
int bar(int x) |
2572 |
int bar(int x) |
|
Lines 3684-3690
tests.floatMath = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec26
|
| 3684 |
} |
2587 |
} |
| 3685 |
int foo() |
2588 |
int foo() |
| 3686 |
{ |
2589 |
{ |
| 3687 |
bar(4.d); |
2590 |
bar(4.f); |
| 3688 |
} |
2591 |
} |
| 3689 |
`), |
2592 |
`), |
| 3690 |
(e) => e instanceof WTypeError); |
2593 |
(e) => e instanceof WTypeError); |
|
Lines 3720-3726
tests.floatMath = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec27
|
| 3720 |
} |
2623 |
} |
| 3721 |
int foo() |
2624 |
int foo() |
| 3722 |
{ |
2625 |
{ |
| 3723 |
bar(4.d); |
2626 |
bar(4.f); |
| 3724 |
} |
2627 |
} |
| 3725 |
`), |
2628 |
`), |
| 3726 |
(e) => e instanceof WTypeError); |
2629 |
(e) => e instanceof WTypeError); |
|
Lines 3736-3798
tests.floatMath = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec28
|
| 3736 |
} |
2639 |
} |
| 3737 |
`), |
2640 |
`), |
| 3738 |
(e) => e instanceof WTypeError); |
2641 |
(e) => e instanceof WTypeError); |
| 3739 |
checkFail( |
|
|
| 3740 |
() => doPrep(` |
| 3741 |
float bar(float x) |
| 3742 |
{ |
| 3743 |
return x; |
| 3744 |
} |
| 3745 |
void foo() |
| 3746 |
{ |
| 3747 |
bar(16777217.d); |
| 3748 |
} |
| 3749 |
`), |
| 3750 |
(e) => e instanceof WTypeError); |
| 3751 |
checkFail( |
| 3752 |
() => doPrep(` |
| 3753 |
float bar(float x) |
| 3754 |
{ |
| 3755 |
return x; |
| 3756 |
} |
| 3757 |
float foo() |
| 3758 |
{ |
| 3759 |
double x = 7.; |
| 3760 |
return bar(x); |
| 3761 |
} |
| 3762 |
`), |
| 3763 |
(e) => e instanceof WTypeError); |
| 3764 |
checkFail( |
| 3765 |
() => doPrep(` |
| 3766 |
float foo() |
| 3767 |
{ |
| 3768 |
double x = 7.; |
| 3769 |
return x; |
| 3770 |
} |
| 3771 |
`), |
| 3772 |
(e) => e instanceof WTypeError); |
| 3773 |
} |
| 3774 |
|
| 3775 |
tests.genericCastInfer = function() |
| 3776 |
{ |
| 3777 |
let program = doPrep(` |
| 3778 |
struct Complex<T> { |
| 3779 |
T real; |
| 3780 |
T imag; |
| 3781 |
} |
| 3782 |
operator<T> Complex<T>(T real, T imag) |
| 3783 |
{ |
| 3784 |
Complex<T> result; |
| 3785 |
result.real = real; |
| 3786 |
result.imag = imag; |
| 3787 |
return result; |
| 3788 |
} |
| 3789 |
int foo() |
| 3790 |
{ |
| 3791 |
Complex<int> x = Complex<int>(1, 2); |
| 3792 |
return x.real + x.imag; |
| 3793 |
} |
| 3794 |
`); |
| 3795 |
checkInt(program, callFunction(program, "foo", [], []), 3); |
| 3796 |
} |
2642 |
} |
| 3797 |
|
2643 |
|
| 3798 |
tests.booleanMath = function() |
2644 |
tests.booleanMath = function() |
|
Lines 4146-4189
tests.builtinVectors = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec29
|
| 4146 |
float3 c = float3(3., 4., 6.); |
2992 |
float3 c = float3(3., 4., 6.); |
| 4147 |
return b == c; |
2993 |
return b == c; |
| 4148 |
} |
2994 |
} |
| 4149 |
double food() |
|
|
| 4150 |
{ |
| 4151 |
double2 a = double2(3., 4.); |
| 4152 |
return a[0]; |
| 4153 |
} |
| 4154 |
double food2() |
| 4155 |
{ |
| 4156 |
double2 a = double2(3., 4.); |
| 4157 |
double3 b = double3(a, 5.); |
| 4158 |
return b[1]; |
| 4159 |
} |
| 4160 |
double food3() |
| 4161 |
{ |
| 4162 |
double3 a = double3(3., 4., 5.); |
| 4163 |
double4 b = double4(6., a); |
| 4164 |
return b[1]; |
| 4165 |
} |
| 4166 |
double food4() |
| 4167 |
{ |
| 4168 |
double2 a = double2(3., 4.); |
| 4169 |
double2 b = double2(5., 6.); |
| 4170 |
double4 c = double4(a, b); |
| 4171 |
return c[2]; |
| 4172 |
} |
| 4173 |
bool food5() |
| 4174 |
{ |
| 4175 |
double4 a = double4(3., 4., 5., 6.); |
| 4176 |
double2 b = double2(4., 5.); |
| 4177 |
double4 c = double4(3., b, 6.); |
| 4178 |
return a == c; |
| 4179 |
} |
| 4180 |
bool food6() |
| 4181 |
{ |
| 4182 |
double2 a = double2(4., 5.); |
| 4183 |
double3 b = double3(3., a); |
| 4184 |
double3 c = double3(3., 4., 6.); |
| 4185 |
return b == c; |
| 4186 |
} |
| 4187 |
`); |
2995 |
`); |
| 4188 |
checkInt(program, callFunction(program, "foo", [], []), 3); |
2996 |
checkInt(program, callFunction(program, "foo", [], []), 3); |
| 4189 |
checkInt(program, callFunction(program, "foo2", [], []), 4); |
2997 |
checkInt(program, callFunction(program, "foo2", [], []), 4); |
|
Lines 4203-4251
tests.builtinVectors = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec30
|
| 4203 |
checkFloat(program, callFunction(program, "foof4", [], []), 5); |
3011 |
checkFloat(program, callFunction(program, "foof4", [], []), 5); |
| 4204 |
checkBool(program, callFunction(program, "foof5", [], []), true); |
3012 |
checkBool(program, callFunction(program, "foof5", [], []), true); |
| 4205 |
checkBool(program, callFunction(program, "foof6", [], []), false); |
3013 |
checkBool(program, callFunction(program, "foof6", [], []), false); |
| 4206 |
checkDouble(program, callFunction(program, "food", [], []), 3); |
|
|
| 4207 |
checkDouble(program, callFunction(program, "food2", [], []), 4); |
| 4208 |
checkDouble(program, callFunction(program, "food3", [], []), 3); |
| 4209 |
checkDouble(program, callFunction(program, "food4", [], []), 5); |
| 4210 |
checkBool(program, callFunction(program, "food5", [], []), true); |
| 4211 |
checkBool(program, callFunction(program, "food6", [], []), false); |
| 4212 |
} |
3014 |
} |
| 4213 |
|
3015 |
|
| 4214 |
tests.instantiateStructInStruct = function() |
3016 |
tests.builtinVectorGetters = function() |
| 4215 |
{ |
3017 |
{ |
| 4216 |
let program = doPrep(` |
3018 |
const typeNames = [ "uint", "int", "float" ]; |
| 4217 |
struct Bar<T> { |
3019 |
const sizes = [ 2, 3, 4 ]; |
| 4218 |
T x; |
3020 |
const elements = [ "x", "y", "z", "w" ]; |
| 4219 |
} |
3021 |
const initializerList = [ 1, 2, 3, 4 ]; |
| 4220 |
struct Foo { |
3022 |
|
| 4221 |
Bar<int> x; |
3023 |
let tests = []; |
| 4222 |
} |
3024 |
let src = ""; |
| 4223 |
int foo() |
3025 |
for (let typeName of typeNames) { |
| 4224 |
{ |
3026 |
for (let size of sizes) { |
| 4225 |
Foo x; |
3027 |
for (let i = 0; i < size; i++) { |
| 4226 |
x.x.x = 42; |
3028 |
const functionName = `${typeName}${size}${elements[i]}`; |
| 4227 |
x.x.x++; |
3029 |
src += `${typeName} ${functionName}() |
| 4228 |
return x.x.x; |
3030 |
{ |
|
|
3031 |
${typeName}${size} x = ${typeName}${size}(${initializerList.slice(0, size).join(", ")}); |
| 3032 |
return x.${elements[i]}; |
| 3033 |
} |
| 3034 |
`; |
| 3035 |
tests.push({ type: typeName, name: functionName, expectation: initializerList[i] }); |
| 3036 |
} |
| 4229 |
} |
3037 |
} |
| 4230 |
`); |
3038 |
} |
| 4231 |
checkInt(program, callFunction(program, "foo", [], []), 43); |
3039 |
|
|
|
3040 |
let program = doPrep(src); |
| 3041 |
const checkFuncs = { |
| 3042 |
"uint": checkUint, |
| 3043 |
"int": checkInt, |
| 3044 |
"float": checkFloat |
| 3045 |
}; |
| 3046 |
for (let test of tests) { |
| 3047 |
const checkFunc = checkFuncs[test.type]; |
| 3048 |
checkFunc(program, callFunction(program, test.name, [], []), test.expectation); |
| 3049 |
} |
| 4232 |
} |
3050 |
} |
| 4233 |
|
3051 |
|
| 4234 |
tests.instantiateStructInStructWithInt2 = function() |
3052 |
tests.builtinVectorSetters = function() |
| 4235 |
{ |
3053 |
{ |
| 4236 |
let program = doPrep(` |
3054 |
const typeNames = [ "uint", "int", "float" ]; |
| 4237 |
struct Foo { |
3055 |
const sizes = [ 2, 3, 4 ]; |
| 4238 |
int2 x; |
3056 |
const elements = [ "x", "y", "z", "w" ]; |
|
|
3057 |
const initializerList = [ 1, 2, 3, 4 ]; |
| 3058 |
|
| 3059 |
let tests = []; |
| 3060 |
let src = ""; |
| 3061 |
for (let typeName of typeNames) { |
| 3062 |
for (let size of sizes) { |
| 3063 |
for (let i = 0; i < size; i++) { |
| 3064 |
const functionName = `${typeName}${size}${elements[i]}`; |
| 3065 |
src += `${typeName} ${functionName}() |
| 3066 |
{ |
| 3067 |
${typeName}${size} x = ${typeName}${size}(${initializerList.slice(0, size).join(", ")}); |
| 3068 |
x.${elements[i]} = 34; |
| 3069 |
return x.${elements[i]}; |
| 3070 |
} |
| 3071 |
`; |
| 3072 |
tests.push({ type: typeName, name: functionName, expectation: 34 }); |
| 3073 |
} |
| 4239 |
} |
3074 |
} |
| 4240 |
int foo() |
3075 |
} |
| 4241 |
{ |
3076 |
|
| 4242 |
Foo x; |
3077 |
let program = doPrep(src); |
| 4243 |
x.x.x = 42; |
3078 |
const checkFuncs = { |
| 4244 |
x.x.x++; |
3079 |
"uint": checkUint, |
| 4245 |
return x.x.x; |
3080 |
"int": checkInt, |
|
|
3081 |
"float": checkFloat |
| 3082 |
}; |
| 3083 |
for (let test of tests) { |
| 3084 |
const checkFunc = checkFuncs[test.type]; |
| 3085 |
checkFunc(program, callFunction(program, test.name, [], []), test.expectation); |
| 3086 |
} |
| 3087 |
} |
| 3088 |
|
| 3089 |
tests.builtinVectorIndexSetters = function() |
| 3090 |
{ |
| 3091 |
const typeNames = [ "uint", "int", "float" ]; |
| 3092 |
const sizes = [ 2, 3, 4 ]; |
| 3093 |
const elements = [ "x", "y", "z", "w" ]; |
| 3094 |
const initializerList = [ 1, 2, 3, 4 ]; |
| 3095 |
|
| 3096 |
let tests = []; |
| 3097 |
let src = ""; |
| 3098 |
for (let typeName of typeNames) { |
| 3099 |
for (let size of sizes) { |
| 3100 |
for (let i = 0; i < size; i++) { |
| 3101 |
const functionName = `${typeName}${size}${elements[i]}`; |
| 3102 |
src += `${typeName} ${functionName}() |
| 3103 |
{ |
| 3104 |
${typeName}${size} x = ${typeName}${size}(${initializerList.slice(0, size).join(", ")}); |
| 3105 |
x[${i}] = 34; |
| 3106 |
return x[${i}]; |
| 3107 |
} |
| 3108 |
`; |
| 3109 |
tests.push({ type: typeName, name: functionName, expectation: 34 }); |
| 3110 |
} |
| 4246 |
} |
3111 |
} |
| 4247 |
`); |
3112 |
} |
| 4248 |
checkInt(program, callFunction(program, "foo", [], []), 43); |
3113 |
|
|
|
3114 |
let program = doPrep(src); |
| 3115 |
const checkFuncs = { |
| 3116 |
"uint": checkUint, |
| 3117 |
"int": checkInt, |
| 3118 |
"float": checkFloat |
| 3119 |
}; |
| 3120 |
for (let test of tests) { |
| 3121 |
const checkFunc = checkFuncs[test.type]; |
| 3122 |
checkFunc(program, callFunction(program, test.name, [], []), test.expectation); |
| 3123 |
} |
| 4249 |
} |
3124 |
} |
| 4250 |
|
3125 |
|
| 4251 |
tests.simpleEnum = function() |
3126 |
tests.simpleEnum = function() |
|
Lines 4490-4528
tests.enumWithSomeManualValues = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec31
|
| 4490 |
checkEnum(program, callFunction(program, "death", [], []), 1); |
3365 |
checkEnum(program, callFunction(program, "death", [], []), 1); |
| 4491 |
} |
3366 |
} |
| 4492 |
|
3367 |
|
| 4493 |
tests.enumConstexprGenericFunction = function() |
|
|
| 4494 |
{ |
| 4495 |
let program = doPrep(` |
| 4496 |
enum Axis { X, Y } |
| 4497 |
int foo<Axis axis>() { return int(axis); } |
| 4498 |
int testX() { return foo<Axis.X>(); } |
| 4499 |
int testY() { return foo<Axis.Y>(); } |
| 4500 |
`); |
| 4501 |
checkInt(program, callFunction(program, "testX", [], []), 0); |
| 4502 |
checkInt(program, callFunction(program, "testY", [], []), 1); |
| 4503 |
} |
| 4504 |
|
| 4505 |
tests.enumConstexprGenericStruct = function() |
| 4506 |
{ |
| 4507 |
let program = doPrep(` |
| 4508 |
enum Axis { X, Y } |
| 4509 |
struct Foo<Axis axis> { } |
| 4510 |
int foo<Axis axis>(Foo<axis>) { return int(axis); } |
| 4511 |
int testX() |
| 4512 |
{ |
| 4513 |
Foo<Axis.X> f; |
| 4514 |
return foo(f); |
| 4515 |
} |
| 4516 |
int testY() |
| 4517 |
{ |
| 4518 |
Foo<Axis.Y> f; |
| 4519 |
return foo(f); |
| 4520 |
} |
| 4521 |
`); |
| 4522 |
checkInt(program, callFunction(program, "testX", [], []), 0); |
| 4523 |
checkInt(program, callFunction(program, "testY", [], []), 1); |
| 4524 |
} |
| 4525 |
|
| 4526 |
tests.trap = function() |
3368 |
tests.trap = function() |
| 4527 |
{ |
3369 |
{ |
| 4528 |
let program = doPrep(` |
3370 |
let program = doPrep(` |
|
Lines 4971-4988
tests.simpleSwitch = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec32
|
| 4971 |
|
3813 |
|
| 4972 |
tests.exhaustiveUint8Switch = function() |
3814 |
tests.exhaustiveUint8Switch = function() |
| 4973 |
{ |
3815 |
{ |
| 4974 |
let text = "double foo(uint8 x) { switch (uint8(x)) {" |
3816 |
let text = "float foo(uint8 x) { switch (uint8(x)) {" |
| 4975 |
for (let i = 0; i <= 0xff; ++i) |
3817 |
for (let i = 0; i <= 0xff; ++i) |
| 4976 |
text += "case " + i + ": return " + i * 1.5 + ";"; |
3818 |
text += "case " + i + ": return " + i * 1.5 + ";"; |
| 4977 |
text += "} }"; |
3819 |
text += "} }"; |
| 4978 |
let program = doPrep(text); |
3820 |
let program = doPrep(text); |
| 4979 |
for (let i = 0; i < 0xff; ++i) |
3821 |
for (let i = 0; i < 0xff; ++i) |
| 4980 |
checkDouble(program, callFunction(program, "foo", [], [makeUint8(program, i)]), i * 1.5); |
3822 |
checkFloat(program, callFunction(program, "foo", [], [makeUint8(program, i)]), i * 1.5); |
| 4981 |
} |
3823 |
} |
| 4982 |
|
3824 |
|
| 4983 |
tests.notQuiteExhaustiveUint8Switch = function() |
3825 |
tests.notQuiteExhaustiveUint8Switch = function() |
| 4984 |
{ |
3826 |
{ |
| 4985 |
let text = "double foo(uint8 x) { switch (uint8(x)) {" |
3827 |
let text = "float foo(uint8 x) { switch (uint8(x)) {" |
| 4986 |
for (let i = 0; i <= 0xfe; ++i) |
3828 |
for (let i = 0; i <= 0xfe; ++i) |
| 4987 |
text += "case " + i + ": return " + i * 1.5 + ";"; |
3829 |
text += "case " + i + ": return " + i * 1.5 + ";"; |
| 4988 |
text += "} }"; |
3830 |
text += "} }"; |
|
Lines 4991-5004
tests.notQuiteExhaustiveUint8Switch = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec33
|
| 4991 |
|
3833 |
|
| 4992 |
tests.notQuiteExhaustiveUint8SwitchWithDefault = function() |
3834 |
tests.notQuiteExhaustiveUint8SwitchWithDefault = function() |
| 4993 |
{ |
3835 |
{ |
| 4994 |
let text = "double foo(uint8 x) { switch (uint8(x)) {" |
3836 |
let text = "float foo(uint8 x) { switch (uint8(x)) {" |
| 4995 |
for (let i = 0; i <= 0xfe; ++i) |
3837 |
for (let i = 0; i <= 0xfe; ++i) |
| 4996 |
text += "case " + i + ": return " + i * 1.5 + ";"; |
3838 |
text += "case " + i + ": return " + i * 1.5 + ";"; |
| 4997 |
text += "default: return " + 0xff * 1.5 + ";"; |
3839 |
text += "default: return " + 0xff * 1.5 + ";"; |
| 4998 |
text += "} }"; |
3840 |
text += "} }"; |
| 4999 |
let program = doPrep(text); |
3841 |
let program = doPrep(text); |
| 5000 |
for (let i = 0; i < 0xff; ++i) |
3842 |
for (let i = 0; i < 0xff; ++i) |
| 5001 |
checkDouble(program, callFunction(program, "foo", [], [makeUint8(program, i)]), i * 1.5); |
3843 |
checkFloat(program, callFunction(program, "foo", [], [makeUint8(program, i)]), i * 1.5); |
| 5002 |
} |
3844 |
} |
| 5003 |
|
3845 |
|
| 5004 |
tests.switchFallThrough = function() |
3846 |
tests.switchFallThrough = function() |
|
Lines 5327-5333
tests.setterWithMismatchedType = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec34
|
| 5327 |
{ |
4169 |
{ |
| 5328 |
checkFail( |
4170 |
checkFail( |
| 5329 |
() => doPrep(` |
4171 |
() => doPrep(` |
| 5330 |
double operator.foo(int) |
4172 |
float operator.foo(int) |
| 5331 |
{ |
4173 |
{ |
| 5332 |
return 5.43; |
4174 |
return 5.43; |
| 5333 |
} |
4175 |
} |
|
Lines 5353-5375
tests.setterWithMatchedType = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec35
|
| 5353 |
`); |
4195 |
`); |
| 5354 |
} |
4196 |
} |
| 5355 |
|
4197 |
|
| 5356 |
tests.operatorWithUninferrableTypeVariable = function() |
|
|
| 5357 |
{ |
| 5358 |
checkFail( |
| 5359 |
() => doPrep(` |
| 5360 |
struct Foo { |
| 5361 |
int x; |
| 5362 |
} |
| 5363 |
Foo operator+<T>(Foo a, Foo b) |
| 5364 |
{ |
| 5365 |
Foo result; |
| 5366 |
result.x = a.x + b.x; |
| 5367 |
return result; |
| 5368 |
} |
| 5369 |
`), |
| 5370 |
e => e instanceof WTypeError); |
| 5371 |
} |
| 5372 |
|
| 5373 |
tests.operatorWithoutUninferrableTypeVariable = function() |
4198 |
tests.operatorWithoutUninferrableTypeVariable = function() |
| 5374 |
{ |
4199 |
{ |
| 5375 |
let program = doPrep(` |
4200 |
let program = doPrep(` |
|
Lines 5394-5446
tests.operatorWithoutUninferrableTypeVariable = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec36
|
| 5394 |
checkInt(program, callFunction(program, "foo", [], []), 645 - 35); |
4219 |
checkInt(program, callFunction(program, "foo", [], []), 645 - 35); |
| 5395 |
} |
4220 |
} |
| 5396 |
|
4221 |
|
| 5397 |
tests.operatorCastWithUninferrableTypeVariable = function() |
|
|
| 5398 |
{ |
| 5399 |
checkFail( |
| 5400 |
() => doPrep(` |
| 5401 |
struct Foo { |
| 5402 |
int x; |
| 5403 |
} |
| 5404 |
operator<T> Foo(int x) |
| 5405 |
{ |
| 5406 |
Foo result; |
| 5407 |
result.x = x; |
| 5408 |
return result; |
| 5409 |
} |
| 5410 |
`), |
| 5411 |
e => e instanceof WTypeError); |
| 5412 |
} |
| 5413 |
|
| 5414 |
tests.operatorCastWithTypeVariableInferredFromReturnType = function() |
| 5415 |
{ |
| 5416 |
let program = doPrep(` |
| 5417 |
struct Foo { |
| 5418 |
int x; |
| 5419 |
} |
| 5420 |
protocol Barable { |
| 5421 |
void bar(thread Barable*, int); |
| 5422 |
} |
| 5423 |
void bar(thread double* result, int value) |
| 5424 |
{ |
| 5425 |
*result = double(value); |
| 5426 |
} |
| 5427 |
operator<T:Barable> T(Foo foo) |
| 5428 |
{ |
| 5429 |
T result; |
| 5430 |
bar(&result, foo.x); |
| 5431 |
return result; |
| 5432 |
} |
| 5433 |
int foo() |
| 5434 |
{ |
| 5435 |
Foo foo; |
| 5436 |
foo.x = 75; |
| 5437 |
double x = double(foo); |
| 5438 |
return int(x * 1.5); |
| 5439 |
} |
| 5440 |
`); |
| 5441 |
checkInt(program, callFunction(program, "foo", [], []), 112); |
| 5442 |
} |
| 5443 |
|
| 5444 |
tests.incWrongArgumentLength = function() |
4222 |
tests.incWrongArgumentLength = function() |
| 5445 |
{ |
4223 |
{ |
| 5446 |
checkFail( |
4224 |
checkFail( |
|
Lines 5473-5479
tests.incWrongTypes = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec37
|
| 5473 |
{ |
4251 |
{ |
| 5474 |
checkFail( |
4252 |
checkFail( |
| 5475 |
() => doPrep(` |
4253 |
() => doPrep(` |
| 5476 |
int operator++(double) { return 32; } |
4254 |
int operator++(float) { return 32; } |
| 5477 |
`), |
4255 |
`), |
| 5478 |
e => e instanceof WTypeError); |
4256 |
e => e instanceof WTypeError); |
| 5479 |
} |
4257 |
} |
|
Lines 5482-5488
tests.decWrongTypes = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec38
|
| 5482 |
{ |
4260 |
{ |
| 5483 |
checkFail( |
4261 |
checkFail( |
| 5484 |
() => doPrep(` |
4262 |
() => doPrep(` |
| 5485 |
int operator--(double) { return 32; } |
4263 |
int operator--(float) { return 32; } |
| 5486 |
`), |
4264 |
`), |
| 5487 |
e => e instanceof WTypeError); |
4265 |
e => e instanceof WTypeError); |
| 5488 |
} |
4266 |
} |
|
Lines 6007-6012
tests.anderWithArrayRef = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec39
|
| 6007 |
checkInt(program, callFunction(program, "foo", [], []), 13); |
4785 |
checkInt(program, callFunction(program, "foo", [], []), 13); |
| 6008 |
} |
4786 |
} |
| 6009 |
|
4787 |
|
|
|
4788 |
tests.anderWithBadIndex = function() |
| 4789 |
{ |
| 4790 |
checkFail(() => doPrep(` |
| 4791 |
int foo(thread int[] x) { return x[-1]; } |
| 4792 |
`), e => e instanceof Error); |
| 4793 |
|
| 4794 |
checkFail(() => doPrep(` |
| 4795 |
int foo(thread int[] x) { return x[1.f]; } |
| 4796 |
`), e => e instanceof Error); |
| 4797 |
|
| 4798 |
checkFail(() => doPrep(` |
| 4799 |
int foo(thread int[] x, int y) { return x[y]; } |
| 4800 |
`), e => e instanceof Error); |
| 4801 |
|
| 4802 |
checkFail(() => doPrep(` |
| 4803 |
int foo(thread int[] x, float y) { return x[y]; } |
| 4804 |
`), e => e instanceof Error); |
| 4805 |
} |
| 4806 |
|
| 6010 |
tests.pointerIndexGetter = function() |
4807 |
tests.pointerIndexGetter = function() |
| 6011 |
{ |
4808 |
{ |
| 6012 |
checkFail( |
4809 |
checkFail( |
|
Lines 6073-6079
tests.indexSetterWithMismatchedType = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec40
|
| 6073 |
{ |
4870 |
{ |
| 6074 |
checkFail( |
4871 |
checkFail( |
| 6075 |
() => doPrep(` |
4872 |
() => doPrep(` |
| 6076 |
double operator[](int, uint) |
4873 |
float operator[](int, uint) |
| 6077 |
{ |
4874 |
{ |
| 6078 |
return 5.43; |
4875 |
return 5.43; |
| 6079 |
} |
4876 |
} |
|
Lines 6264-6270
tests.indexAnderWithArrayRef = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec41
|
| 6264 |
struct Foo { |
5061 |
struct Foo { |
| 6265 |
int x; |
5062 |
int x; |
| 6266 |
} |
5063 |
} |
| 6267 |
thread int* operator&[](thread Foo[] array, double index) |
5064 |
thread int* operator&[](thread Foo[] array, float index) |
| 6268 |
{ |
5065 |
{ |
| 6269 |
return &array[uint(index + 1)].x; |
5066 |
return &array[uint(index + 1)].x; |
| 6270 |
} |
5067 |
} |
|
Lines 6272-6278
tests.indexAnderWithArrayRef = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec42
|
| 6272 |
{ |
5069 |
{ |
| 6273 |
Foo x; |
5070 |
Foo x; |
| 6274 |
x.x = 13; |
5071 |
x.x = 13; |
| 6275 |
return (@x)[double(-1)]; |
5072 |
return (@x)[float(-1)]; |
| 6276 |
} |
5073 |
} |
| 6277 |
`); |
5074 |
`); |
| 6278 |
checkInt(program, callFunction(program, "foo", [], []), 13); |
5075 |
checkInt(program, callFunction(program, "foo", [], []), 13); |
|
Lines 6314-6619
tests.constantPtrPtr = function()
a/Tools/WebGPUShadingLanguageRI/Test.js_sec43
|
| 6314 |
e => e instanceof WTypeError && e.message.indexOf("Illegal pointer to non-primitive type: int32* constant* constant") != -1); |
5111 |
e => e instanceof WTypeError && e.message.indexOf("Illegal pointer to non-primitive type: int32* constant* constant") != -1); |
| 6315 |
} |
5112 |
} |
| 6316 |
|
5113 |
|
| 6317 |
tests.pointerIndexGetterInProtocol = function() |
|
|
| 6318 |
{ |
| 6319 |
for (let addressSpace of addressSpaces) { |
| 6320 |
checkFail( |
| 6321 |
() => doPrep(` |
| 6322 |
protocol Foo { |
| 6323 |
int operator[](${addressSpace} Foo*, uint); |
| 6324 |
} |
| 6325 |
struct Bar { } |
| 6326 |
int operator[](Bar, uint) { return 42; } |
| 6327 |
`), |
| 6328 |
e => e instanceof WTypeError && e.message.indexOf("Cannot have getter for pointer type") != -1); |
| 6329 |
} |
| 6330 |
} |
| 6331 |
|
| 6332 |
tests.loneIndexSetterInProtocol = function() |
| 6333 |
{ |
| 6334 |
checkFail( |
| 6335 |
() => doPrep(` |
| 6336 |
protocol Foo { |
| 6337 |
Foo operator[]=(Foo, uint, int); |
| 6338 |
} |
| 6339 |
struct Bar { } |
| 6340 |
int operator[](Bar, uint) { return 42; } |
| 6341 |
Bar operator[]=(Bar, uint, int) { return Bar(); } |
| 6342 |
`), |
| 6343 |
e => e instanceof WTypeError && e.message.indexOf("Every setter must have a matching getter") != -1); |
| 6344 |
} |
| 6345 |
|
| 6346 |
tests.notLoneIndexSetterInProtocol = function() |
| 6347 |
{ |
| 6348 |
doPrep(` |
| 6349 |
protocol Foo { |
| 6350 |
int operator[](Foo, uint); |
| 6351 |
Foo operator[]=(Foo, uint, int); |
| 6352 |
} |
| 6353 |
struct Bar { } |
| 6354 |
int operator[](Bar, uint) { return 42; } |
| 6355 |
Bar operator[]=(Bar, uint, int) { return Bar(); } |
| 6356 |
`); |
| 6357 |
} |
| 6358 |
|
| 6359 |
tests.indexSetterWithMismatchedTypeInProtocol = function() |
| 6360 |
{ |
| 6361 |
checkFail( |
| 6362 |
() => doPrep(` |
| 6363 |
protocol Foo { |
| 6364 |
double operator[](Foo, uint); |
| 6365 |
Foo operator[]=(Foo, uint, int); |
| 6366 |
} |
| 6367 |
struct Bar { } |
| 6368 |
int operator[](Bar, uint) { return 42; } |
| 6369 |
Bar operator[]=(Bar, uint, int) { return Bar(); } |
| 6370 |
`), |
| 6371 |
e => e instanceof WTypeError && e.message.indexOf("Setter and getter must agree on value type") != -1); |
| 6372 |
} |
| 6373 |
|
| 6374 |
tests.indexOperatorWrongArgumentLengthInProtocol = function() |
| 6375 |
{ |
| 6376 |
checkFail( |
| 6377 |
() => doPrep(` |
| 6378 |
protocol Foo { |
| 6379 |
int operator[](); |
| 6380 |
} |
| 6381 |
struct Bar { } |
| 6382 |
int operator[](Bar, uint) { return 42; } |
| 6383 |
`), |
| 6384 |
e => e instanceof WTypeError && e.message.indexOf("Protocol's type variable (Foo) not mentioned in signature") != -1); |
| 6385 |
checkFail( |
| 6386 |
() => doPrep(` |
| 6387 |
protocol Foo { |
| 6388 |
int operator[](Foo); |
| 6389 |
} |
| 6390 |
struct Bar { } |
| 6391 |
int operator[](Bar, uint) { return 42; } |
| 6392 |
`), |
| 6393 |
e => e instanceof WTypeError && e.message.indexOf("Incorrect number of parameters") != -1); |
| 6394 |
checkFail( |
| 6395 |
() => doPrep(` |
| 6396 |
protocol Foo { |
| 6397 |
int operator[](Foo, int, int); |
| 6398 |
} |
| 6399 |
struct Bar { } |
| 6400 |
int operator[](Bar, uint) { return 42; } |
| 6401 |
`), |
| 6402 |
e => e instanceof WTypeError && e.message.indexOf("Incorrect number of parameters") != -1); |
| 6403 |
} |
| 6404 |
|
| 6405 |
tests.indexOperatorSetterWrongArgumentLengthInProtocol = function() |
| 6406 |
{ |
| 6407 |
checkFail( |
| 6408 |
() => doPrep(` |
| 6409 |
protocol Foo { |
| 6410 |
int operator[]=(); |
| 6411 |
} |
| 6412 |
struct Bar { } |
| 6413 |
int operator[](Bar, uint) { return 42; } |
| 6414 |
Bar operator[]=(Bar, uint, int) { return Bar(); } |
| 6415 |
`), |
| 6416 |
e => e instanceof WTypeError && e.message.indexOf("Protocol's type variable (Foo) not mentioned in signature") != -1); |
| 6417 |
checkFail( |
| 6418 |
() => doPrep(` |
| 6419 |
protocol Foo { |
| 6420 |
int operator[]=(Foo); |
| 6421 |
} |
| 6422 |
struct Bar { } |
| 6423 |
int operator[](Bar, uint) { return 42; } |
| 6424 |
Bar operator[]=(Bar, uint, int) { return Bar(); } |
| 6425 |
`), |
| 6426 |
e => e instanceof WTypeError && e.message.indexOf("Incorrect number of parameters") != -1); |
| 6427 |
checkFail( |
| 6428 |
() => doPrep(` |
| 6429 |
protocol Foo { |
| 6430 |
int operator[]=(Foo, int); |
| 6431 |
} |
| 6432 |
struct Bar { } |
| 6433 |
int operator[](Bar, uint) { return 42; } |
| 6434 |
Bar operator[]=(Bar, uint, int) { return Bar(); } |
| 6435 |
`), |
| 6436 |
e => e instanceof WTypeError && e.message.indexOf("Incorrect number of parameters") != -1); |
| 6437 |
checkFail( |
| 6438 |
() => doPrep(` |
| 6439 |
protocol Foo { |
| 6440 |
int operator[]=(Foo, int, int, int); |
| 6441 |
} |
| 6442 |
struct Bar { } |
| 6443 |
int operator[](Bar, uint) { return 42; } |
| 6444 |
Bar operator[]=(Bar, uint, int) { return Bar(); } |
| 6445 |
`), |
| 6446 |
e => e instanceof WTypeError && e.message.indexOf("Incorrect number of parameters") != -1); |
| 6447 |
} |
| 6448 |
|
| 6449 |
tests.loneIndexSetterPointerInProtocol = function() |
| 6450 |
{ |
| 6451 |
checkFail( |
| 6452 |
() => doPrep(` |
| 6453 |
protocol Foo { |
| 6454 |
thread int* operator[]=(thread Foo* ptr, uint, int); |
| 6455 |
} |
| 6456 |
struct Bar { } |
| 6457 |
int operator[](Bar, uint) { return 42; } |
| 6458 |
Bar operator[]=(Bar, uint, int) { return Bar(); } |
| 6459 |
`), |
| 6460 |
e => e instanceof WTypeError && e.message.indexOf("Cannot have setter for pointer type") != -1); |
| 6461 |
} |
| 6462 |
|
| 6463 |
tests.indexSetterWithNoGetterOverloadInProtocol = function() |
| 6464 |
{ |
| 6465 |
checkFail( |
| 6466 |
() => doPrep(` |
| 6467 |
protocol Foo { |
| 6468 |
int operator[](int, Foo); |
| 6469 |
Foo operator[]=(Foo, uint, int); |
| 6470 |
} |
| 6471 |
struct Bar { } |
| 6472 |
int operator[](Bar, uint) { return 42; } |
| 6473 |
Bar operator[]=(Bar, uint, int) { return Bar(); } |
| 6474 |
`), |
| 6475 |
e => e instanceof WTypeError && e.message.indexOf("Did not find function named operator[]= with arguments Foo,uint32") != -1); |
| 6476 |
} |
| 6477 |
|
| 6478 |
tests.indexSetterWithNoGetterOverloadFixedInProtocol = function() |
| 6479 |
{ |
| 6480 |
doPrep(` |
| 6481 |
protocol Foo { |
| 6482 |
int operator[](Foo, uint); |
| 6483 |
Foo operator[]=(Foo, uint, int); |
| 6484 |
} |
| 6485 |
struct Bar { } |
| 6486 |
int operator[](Bar, uint) { return 42; } |
| 6487 |
Bar operator[]=(Bar, uint, int) { return Bar(); } |
| 6488 |
`); |
| 6489 |
} |
| 6490 |
|
| 6491 |
tests.indexAnderWithNothingWrongInProtocol = function() |
| 6492 |
{ |
| 6493 |
let program = doPrep(` |
| 6494 |
protocol Foo { |
| 6495 |
thread int* operator&[](thread Foo* foo, uint); |
| 6496 |
} |
| 6497 |
int bar<T:Foo>(T x) |
| 6498 |
{ |
| 6499 |
return x[42]; |
| 6500 |
} |
| 6501 |
struct Bar { } |
| 6502 |
thread int* operator&[](thread Bar*, uint) |
| 6503 |
{ |
| 6504 |
int result = 1234; |
| 6505 |
return &result; |
| 6506 |
} |
| 6507 |
int foo() |
| 6508 |
{ |
| 6509 |
return bar(Bar()); |
| 6510 |
} |
| 6511 |
`); |
| 6512 |
checkInt(program, callFunction(program, "foo", [], []), 1234); |
| 6513 |
} |
| 6514 |
|
| 6515 |
tests.indexAnderWithWrongNumberOfArgumentsInProtocol = function() |
| 6516 |
{ |
| 6517 |
checkFail( |
| 6518 |
() => doPrep(` |
| 6519 |
protocol Foo { |
| 6520 |
thread int* operator&[](); |
| 6521 |
} |
| 6522 |
struct Bar { } |
| 6523 |
thread int* operator&[](thread Bar*, uint) |
| 6524 |
{ |
| 6525 |
int result = 1234; |
| 6526 |
return &result; |
| 6527 |
} |
| 6528 |
`), |
| 6529 |
e => e instanceof WTypeError && e.message.indexOf("Protocol's type variable (Foo) not mentioned in signature") != -1); |
| 6530 |
checkFail( |
| 6531 |
() => doPrep(` |
| 6532 |
protocol Foo { |
| 6533 |
thread int* operator&[](thread Foo* foo); |
| 6534 |
} |
| 6535 |
struct Bar { } |
| 6536 |
thread int* operator&[](thread Bar*, uint) |
| 6537 |
{ |
| 6538 |
int result = 1234; |
| 6539 |
return &result; |
| 6540 |
} |
| 6541 |
`), |
| 6542 |
e => e instanceof WTypeError && e.message.indexOf("Incorrect number of parameters for operator&[]") != -1); |
| 6543 |
checkFail( |
| 6544 |
() => doPrep(` |
| 6545 |
protocol Foo { |
| 6546 |
thread int* operator&[](thread Foo* foo, uint, uint); |
| 6547 |
} |
| 6548 |
struct Bar { } |
| 6549 |
thread int* operator&[](thread Bar*, uint) |
| 6550 |
{ |
| 6551 |
int result = 1234; |
| 6552 |
return &result; |
| 6553 |
} |
| 6554 |
`), |
| 6555 |
e => e instanceof WTypeError && e.message.indexOf("Incorrect number of parameters for operator&[]") != -1); |
| 6556 |
} |
| 6557 |
|
| 6558 |
tests.indexAnderDoesntReturnPointerInProtocol = function() |
| 6559 |
{ |
| 6560 |
checkFail( |
| 6561 |
() => doPrep(` |
| 6562 |
protocol Foo { |
| 6563 |
int operator&[](thread Foo* foo, uint); |
| 6564 |
} |
| 6565 |
struct Bar { } |
| 6566 |
thread int* operator&[](thread Bar*, uint) |
| 6567 |
{ |
| 6568 |
int result = 1234; |
| 6569 |
return &result; |
| 6570 |
} |
| 6571 |
`), |
| 6572 |
e => e instanceof WTypeError && e.message.indexOf("Return type of ander is not a pointer") != -1); |
| 6573 |
} |
| 6574 |
|
| 6575 |
tests.indexAnderDoesntTakeReferenceInProtocol = function() |
| 6576 |
{ |
| 6577 |
checkFail( |
| 6578 |
() => doPrep(` |
| 6579 |
protocol Foo { |
| 6580 |
thread int* operator&[](Foo foo, uint); |
| 6581 |
} |
| 6582 |
struct Bar { } |
| 6583 |
thread int* operator&[](thread Bar*, uint) |
| 6584 |
{ |
| 6585 |
int result = 1234; |
| 6586 |
return &result; |
| 6587 |
} |
| 6588 |
`), |
| 6589 |
e => e instanceof WTypeError && e.message.indexOf("Parameter to ander is not a reference") != -1); |
| 6590 |
} |
| 6591 |
|
| 6592 |
tests.indexAnderWithArrayRefInProtocol = function() |
| 6593 |
{ |
| 6594 |
let program = doPrep(` |
| 6595 |
protocol Foo { |
| 6596 |
thread int* operator&[](thread Foo[] array, double index); |
| 6597 |
} |
| 6598 |
int bar<T:Foo>(thread T[] x) |
| 6599 |
{ |
| 6600 |
return x[1.5]; |
| 6601 |
} |
| 6602 |
struct Bar { } |
| 6603 |
thread int* operator&[](thread Bar[], double) |
| 6604 |
{ |
| 6605 |
int result = 1234; |
| 6606 |
return &result; |
| 6607 |
} |
| 6608 |
int foo() |
| 6609 |
{ |
| 6610 |
Bar x; |
| 6611 |
return bar(@x); |
| 6612 |
} |
| 6613 |
`); |
| 6614 |
checkInt(program, callFunction(program, "foo", [], []), 1234); |
| 6615 |
} |
| 6616 |
|
| 6617 |
tests.andReturnedArrayRef = function() |
5114 |
tests.andReturnedArrayRef = function() |
| 6618 |
{ |
5115 |
{ |
| 6619 |
let program = doPrep(` |
5116 |
let program = doPrep(` |