Add support for pointers to the language.
Pointers can be either uniform or varying, and behave correspondingly. e.g.: "uniform float * varying" is a varying pointer to uniform float data in memory, and "float * uniform" is a uniform pointer to varying data in memory. Like other types, pointers are varying by default. Pointer-based expressions, & and *, sizeof, ->, pointer arithmetic, and the array/pointer duality all bahave as in C. Array arguments to functions are converted to pointers, also like C. There is a built-in NULL for a null pointer value; conversion from compile-time constant 0 values to NULL still needs to be implemented. Other changes: - Syntax for references has been updated to be C++ style; a useful warning is now issued if the "reference" keyword is used. - It is now illegal to pass a varying lvalue as a reference parameter to a function; references are essentially uniform pointers. This case had previously been handled via special case call by value return code. That path has been removed, now that varying pointers are available to handle this use case (and much more). - Some stdlib routines have been updated to take pointers as arguments where appropriate (e.g. prefetch and the atomics). A number of others still need attention. - All of the examples have been updated - Many new tests TODO: documentation
This commit is contained in:
6
tests_errors/array-increment.ispc
Normal file
6
tests_errors/array-increment.ispc
Normal file
@@ -0,0 +1,6 @@
|
||||
// Can only pre/post increment numeric and pointer types
|
||||
|
||||
void foo() {
|
||||
float a[5] = { 1,2,3,4,5};
|
||||
++a;
|
||||
}
|
||||
6
tests_errors/array-pointer-assign.ispc
Normal file
6
tests_errors/array-pointer-assign.ispc
Normal file
@@ -0,0 +1,6 @@
|
||||
// ffofoof
|
||||
|
||||
void foo(float *x) {
|
||||
float a[5] = { 1,2,3,4,5};
|
||||
a = x;
|
||||
}
|
||||
10
tests_errors/assign-struct-with-const-member.ispc
Normal file
10
tests_errors/assign-struct-with-const-member.ispc
Normal file
@@ -0,0 +1,10 @@
|
||||
// ffofoof
|
||||
|
||||
struct Foo {
|
||||
const int a;
|
||||
};
|
||||
|
||||
void foo(Foo f) {
|
||||
Foo a;
|
||||
a = f;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Can't pre-increment
|
||||
// Can't assign to type "const int32" on left-hand
|
||||
|
||||
int func() {
|
||||
const int x = 2;
|
||||
|
||||
7
tests_errors/const-global.ispc
Normal file
7
tests_errors/const-global.ispc
Normal file
@@ -0,0 +1,7 @@
|
||||
// Can't assign to type "const int32" on left-hand side
|
||||
|
||||
const int x = 0;
|
||||
|
||||
void foo() {
|
||||
++x;
|
||||
}
|
||||
5
tests_errors/deref-1.ispc
Normal file
5
tests_errors/deref-1.ispc
Normal file
@@ -0,0 +1,5 @@
|
||||
// operator "." can't be used with expression of "int32" type
|
||||
|
||||
int func(int *a) {
|
||||
a.x = 0;
|
||||
}
|
||||
7
tests_errors/deref-2.ispc
Normal file
7
tests_errors/deref-2.ispc
Normal file
@@ -0,0 +1,7 @@
|
||||
// operator "." can't be applied to pointer type
|
||||
|
||||
struct Foo { int x; };
|
||||
|
||||
int func(Foo *a) {
|
||||
a.x = 0;
|
||||
}
|
||||
7
tests_errors/deref-3.ispc
Normal file
7
tests_errors/deref-3.ispc
Normal file
@@ -0,0 +1,7 @@
|
||||
// Dereference operator "->" can't be applied to non-pointer type "uniform struct Foo"
|
||||
|
||||
struct Foo { int x; };
|
||||
|
||||
int func(Foo a) {
|
||||
a->x = 0;
|
||||
}
|
||||
5
tests_errors/deref.ispc
Normal file
5
tests_errors/deref.ispc
Normal file
@@ -0,0 +1,5 @@
|
||||
// Member operator "->" can't be used with expression of "int32" type
|
||||
|
||||
int func(int *a) {
|
||||
a->x = 0;
|
||||
}
|
||||
7
tests_errors/func-param-mismatch-2.ispc
Normal file
7
tests_errors/func-param-mismatch-2.ispc
Normal file
@@ -0,0 +1,7 @@
|
||||
// Unable to find matching overload for call to function
|
||||
|
||||
void foo(int x);
|
||||
|
||||
void bar(int x) {
|
||||
foo();
|
||||
}
|
||||
7
tests_errors/func-param-mismatch-3.ispc
Normal file
7
tests_errors/func-param-mismatch-3.ispc
Normal file
@@ -0,0 +1,7 @@
|
||||
// Unable to find matching overload for call to function
|
||||
|
||||
void foo(int x);
|
||||
|
||||
void bar(int x) {
|
||||
foo(x, x);
|
||||
}
|
||||
7
tests_errors/func-param-mismatch.ispc
Normal file
7
tests_errors/func-param-mismatch.ispc
Normal file
@@ -0,0 +1,7 @@
|
||||
// Unable to find matching overload for call to function
|
||||
|
||||
void foo();
|
||||
|
||||
void bar(int x) {
|
||||
foo(x);
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
// Initializer list for array "int32[2][4]" must have 2 elements (has 3).
|
||||
// Initializer list for array "int32[4]" must have 4 elements (has 3)
|
||||
|
||||
int a[2][4] = { { 1, 2, 3 }, { 1, 2, 3, 4 }, 1 };
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Inconsistent expression list lengths found in initializer list
|
||||
// Inconsistent initializer expression list lengths make it impossible to size unsized array dimensions
|
||||
|
||||
void foo() {
|
||||
int a[2][] = { { 1, 2, 3 }, { 1, 2, 3, 4 } };
|
||||
|
||||
4
tests_errors/initexpr-5.ispc
Normal file
4
tests_errors/initexpr-5.ispc
Normal file
@@ -0,0 +1,4 @@
|
||||
// Inconsistent initializer expression list lengths make it impossible
|
||||
|
||||
int a[2][] = { { 1, 2, 3 }, { 1, 2, 3, 4 } };
|
||||
|
||||
5
tests_errors/ptr-1.ispc
Normal file
5
tests_errors/ptr-1.ispc
Normal file
@@ -0,0 +1,5 @@
|
||||
// Can't convert between incompatible pointer types
|
||||
|
||||
int *foo(void *p) {
|
||||
return p;
|
||||
}
|
||||
5
tests_errors/ptr-2.ispc
Normal file
5
tests_errors/ptr-2.ispc
Normal file
@@ -0,0 +1,5 @@
|
||||
// Illegal to pre/post increment
|
||||
|
||||
void *foo(void *p) {
|
||||
++p;
|
||||
}
|
||||
6
tests_errors/ptr-3.ispc
Normal file
6
tests_errors/ptr-3.ispc
Normal file
@@ -0,0 +1,6 @@
|
||||
// Illegal to perform pointer arithmetic
|
||||
|
||||
void *foo(void *p) {
|
||||
p = p-2;
|
||||
return p;
|
||||
}
|
||||
6
tests_errors/ptr-4.ispc
Normal file
6
tests_errors/ptr-4.ispc
Normal file
@@ -0,0 +1,6 @@
|
||||
// Illegal to perform pointer arithmetic
|
||||
|
||||
void *foo(void *p) {
|
||||
p += 1;
|
||||
return p;
|
||||
}
|
||||
5
tests_errors/ptr-const-1.ispc
Normal file
5
tests_errors/ptr-const-1.ispc
Normal file
@@ -0,0 +1,5 @@
|
||||
// Can't assign to type "const int32 * const"
|
||||
|
||||
void foo(const int * const p) {
|
||||
++p;
|
||||
}
|
||||
5
tests_errors/ptr-const.ispc
Normal file
5
tests_errors/ptr-const.ispc
Normal file
@@ -0,0 +1,5 @@
|
||||
// Can't assign to type "const int32" on left-hand side
|
||||
|
||||
void foo(const int * p) {
|
||||
*p = 0;
|
||||
}
|
||||
12
tests_errors/ptr-incompat-types.ispc
Normal file
12
tests_errors/ptr-incompat-types.ispc
Normal file
@@ -0,0 +1,12 @@
|
||||
// Conversion between incompatible pointer types
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
export void f_f(uniform float RET[], uniform float aFOO[]) {
|
||||
uniform int8 * varying pa = (uniform int8 *)aFOO;
|
||||
RET[programIndex] = aFOO - pa;
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = 40;
|
||||
}
|
||||
6
tests_errors/ref-1.ispc
Normal file
6
tests_errors/ref-1.ispc
Normal file
@@ -0,0 +1,6 @@
|
||||
// Syntax error--token "&" unexpected
|
||||
|
||||
int foo(int & & bar) {
|
||||
bar = 0;
|
||||
return bar;
|
||||
}
|
||||
6
tests_errors/ref-2.ispc
Normal file
6
tests_errors/ref-2.ispc
Normal file
@@ -0,0 +1,6 @@
|
||||
// Must provide initializer for reference-type variable
|
||||
|
||||
void func(int a) {
|
||||
int &b;
|
||||
b = 0;
|
||||
}
|
||||
5
tests_errors/ref-3.ispc
Normal file
5
tests_errors/ref-3.ispc
Normal file
@@ -0,0 +1,5 @@
|
||||
// Syntax error--token "*" unexpected
|
||||
|
||||
void foo(int & * x) {
|
||||
*x = NULL;
|
||||
}
|
||||
7
tests_errors/ref-const-array.ispc
Normal file
7
tests_errors/ref-const-array.ispc
Normal file
@@ -0,0 +1,7 @@
|
||||
// Can't assign to type "const int32" on left-hand side of expression
|
||||
|
||||
const int x[20];
|
||||
|
||||
void foo() {
|
||||
++x[5];
|
||||
}
|
||||
9
tests_errors/ref-const-struct-1.ispc
Normal file
9
tests_errors/ref-const-struct-1.ispc
Normal file
@@ -0,0 +1,9 @@
|
||||
// Can't assign to type "const int32" on left-hand side of expression
|
||||
|
||||
struct Foo {
|
||||
int x;
|
||||
};
|
||||
|
||||
void f(const Foo &f) {
|
||||
f.x += 2;
|
||||
}
|
||||
9
tests_errors/ref-const-struct.ispc
Normal file
9
tests_errors/ref-const-struct.ispc
Normal file
@@ -0,0 +1,9 @@
|
||||
// Can't assign to type "const int32" on left-hand side of expression
|
||||
|
||||
struct Foo {
|
||||
int x;
|
||||
};
|
||||
|
||||
void f(const Foo &f) {
|
||||
++f.x;
|
||||
}
|
||||
5
tests_errors/ref-const.ispc
Normal file
5
tests_errors/ref-const.ispc
Normal file
@@ -0,0 +1,5 @@
|
||||
// Can't assign to type "const uniform int32" on left-hand side of expression
|
||||
|
||||
void foo(const uniform int &x) {
|
||||
x = 0;
|
||||
}
|
||||
9
tests_errors/ref-varying.ispc
Normal file
9
tests_errors/ref-varying.ispc
Normal file
@@ -0,0 +1,9 @@
|
||||
// fff
|
||||
|
||||
void foo(float &x) {
|
||||
++x;
|
||||
}
|
||||
|
||||
void bar(uniform float a[], int i) {
|
||||
foo(a[i]);
|
||||
}
|
||||
13
tests_errors/struct-unsized-array.ispc
Normal file
13
tests_errors/struct-unsized-array.ispc
Normal file
@@ -0,0 +1,13 @@
|
||||
// Unsized arrays aren't allowed in struct definitions
|
||||
|
||||
struct Foo {
|
||||
float a[];
|
||||
float b[10];
|
||||
};
|
||||
|
||||
Foo f;
|
||||
|
||||
void Func() {
|
||||
Foo f;
|
||||
}
|
||||
|
||||
5
tests_errors/struct-with-repeated-member-name.ispc
Normal file
5
tests_errors/struct-with-repeated-member-name.ispc
Normal file
@@ -0,0 +1,5 @@
|
||||
// ffofoof
|
||||
|
||||
struct Foo {
|
||||
int a, a;
|
||||
};
|
||||
7
tests_errors/varying-lvalue-to-ref.ispc
Normal file
7
tests_errors/varying-lvalue-to-ref.ispc
Normal file
@@ -0,0 +1,7 @@
|
||||
// ffofoof
|
||||
|
||||
void inc(float &x) { ++x; }
|
||||
|
||||
void foo(uniform float a[], int index) {
|
||||
inc(a[index]);
|
||||
}
|
||||
Reference in New Issue
Block a user