diff --git a/Programming-language-specification-(Gemstone).md b/Programming-language-specification-(Gemstone).md index 4ae05a3..d5d52e0 100644 --- a/Programming-language-specification-(Gemstone).md +++ b/Programming-language-specification-(Gemstone).md @@ -1,3 +1,51 @@ # Programming language specification -`TODO: write language specification` \ No newline at end of file +## Primitive data types +The most fundamental types of data. They provide the base upon everything else is built. A primitive type has 2 properties: size in bytes and arithmetic model (additionally specifies representation on bit level). There are exactly two primitive data types: + +| Type name | size in bytes | arithmetic model | +| - | - | - | +| `int` | 4 | signed integer stored as two's complement with the MSB representing the sign bit | +| `float` | 4 | signed single precision floating point as specified by IEEE-754 | + +## Composite data types +Primitive data types provide the foundation upon which direct derivations can be built. The derivations of primitive types we call composite types. A composite type modifies or extends the definition of a primitive or another composite type. +Extensions or modifications can mean adding or removing a sign bit, exchanging the arithmetic model, etc. +The declaration of a composite data type is made with the following syntax: + +`typedef $name` + +### Sign +The `` is a keyword specifying whether to implement a sign bit or not. Possible values are: +- `signed`: for a single sign bit +- `unsigned`: for no sign bit + +### Scale +`` describes the scaling factor to use. This is a rational factor used alongside the byte size of the base. To calculate the final size of the composite type multiply all factors with the base types size in bytes. + +#### Possible values +| Name | Factor | +| - | - | +| short | $2^{-1}$ | +| long | $2$ | +| half | $2^{-1}$ | +| double | $2$ | + +#### Examples: +IEEE-754 double precision floating point: `long float` with size: `4 bytes * 2 = 8 bytes`
+32-Bit integer: `half long int` with size: `4 bytes * 2 * 2^(-1) = 4 bytes`
+A single byte: `half short int` with size: `4 bytes * 2^(-1) * 2^(-1) = 1 byte`
+ +#### Limitations: +The size of composite type cannot exceed 32 and be lower than 1 nor be a non integral value. +A notable exception is the primitive type `float`. Its size is constrained to 2, 4, 8, 10, 16 and 32 in order to remain compliant with the IEEE-754 standard. A platform may choose to only provide implementations for only a few of the previously named sizes. On x86 and x64 and ARM the most common composite floats are of the sizes: 4 (float) and 8 (double). + +### Base +The base of a composite type specifies on which primitive or composite type a derivation is to be built. + +## Example types +```cpp +typedef long float double_precision +typedef short short int ascii +typedef double int long_int +``` \ No newline at end of file