Repository navigation
1. Basic Types
While Gator is built around support for geometry types, we also require standard types to have Gator be used as a more standard language. This article documents the standard Gator types, parameterization, and declaring custom types. Additionally, if we add existential types per #81, the syntax and details of that implementation will be included here. This article does not detail geometry types or their implementation, for details on that, see this page (TODO: add link to correct page).
The following table outlines the primitives and example literals provided by Gator:
| Primitive | Example Literal |
|---|---|
bool |
true |
int |
15 |
float |
3. |
string |
"hello" |
Custom types in Gator can either extend existing primitives or be declared as external without a backing type. For example, the following are all valid type declarations and uses:
type scalar is float;
declare type long is int;
declare sampler2D;
scalar s = 1.3;
long l = 5;
uniform sampler2D uTexture;
The only difference between using the declare keyword and not is whether or not Gator erases the type when translating. In this example, scalar will be erased, while long will be written to the underlying language target. Additionally, using the declare keyword means that you are not required to include a supertype, since Gator assumes the given type is built in to the target language.
Types introduced as type t1 is t2 have the property that t1 is a subtype of t2. Additionally, a literal of a given primitive is a subtype of all subtypes of that primitive. This means, for example, that the following behavior holds:
type scalar is float;
scalar s = 1.; // Valid since literal float < scalar
float f = s; // Valid since scalar < float
scalar s2 = f; //Error! float is not a subtype of scalar
Gator also supports arrays of values; all elements must be subtypes of the array type and have a fixed dimension. For example, we might have the following declarations:
int[3] x = [1, 2, 3];
type vec2 is float[2];
vec2 v = [1.2, 1.3];
Types can be parameterized freely on other types. Originally included to support geometry types, this feature currently primarily sees use with parameterizing GLSL's sampler2D type. Parameterization requirements in Gator are given using the with keyword as follows:
// Require that users parameterize the type T when using sampler2D
with float[4] T
declare type sampler2D;
type color is float[4];
// Both uses are valid
sampler2D<float[4]> x;
sampler2D<color> y;
Using this parameterization information will be introduced in an upcoming article on functions (TODO: insert link here)