Updated Programming language specification (Gemstone) (markdown)
parent
be6056bc2e
commit
85bb2cc375
|
@ -156,6 +156,21 @@ array[0] = 7
|
||||||
g = abc[array[2]]
|
g = abc[array[2]]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Custom type definitions
|
||||||
|
|
||||||
|
Custom types can be defined in the following way:
|
||||||
|
|
||||||
|
```
|
||||||
|
type <composite-type>: <name>
|
||||||
|
```
|
||||||
|
|
||||||
|
Example type definitions:
|
||||||
|
|
||||||
|
```scala
|
||||||
|
type long float: f64
|
||||||
|
type short short int: byte
|
||||||
|
```
|
||||||
|
|
||||||
## Storage qualifier
|
## Storage qualifier
|
||||||
Variables may have storage qualifier. These keywords describe how a variable is to be stored upon its creation. Available options are:
|
Variables may have storage qualifier. These keywords describe how a variable is to be stored upon its creation. Available options are:
|
||||||
- `local`: store variable on function-local stack
|
- `local`: store variable on function-local stack
|
||||||
|
@ -241,7 +256,7 @@ Output parameter without default parameter have to be initialised inside the fun
|
||||||
|
|
||||||
#### Function declaration example
|
#### Function declaration example
|
||||||
```glsl
|
```glsl
|
||||||
foo(in double float: a, in double float: b)(out double float: c)
|
fun foo(in double float: a, in double float: b)(out double float: c)
|
||||||
{
|
{
|
||||||
c = a + b
|
c = a + b
|
||||||
}
|
}
|
||||||
|
@ -249,17 +264,17 @@ foo(in double float: a, in double float: b)(out double float: c)
|
||||||
|
|
||||||
#### Function call example
|
#### Function call example
|
||||||
```glsl
|
```glsl
|
||||||
foo(in double float: a, in double float: b)(out double float: c)
|
fun foo(in double float: a, in double float: b)(out double float: c)
|
||||||
{
|
{
|
||||||
c = a + b
|
c = a + b
|
||||||
}
|
}
|
||||||
|
|
||||||
abc(in ref int: output)
|
fun abc(in ref int: output)
|
||||||
{
|
{
|
||||||
output = 99
|
output = 99
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
fun main()
|
||||||
{
|
{
|
||||||
local double float: a = 7
|
local double float: a = 7
|
||||||
local double float: b = 9
|
local double float: b = 9
|
||||||
|
@ -279,11 +294,9 @@ Unlike other languages (Java, C, ...) gemstone has no special handling for funct
|
||||||
Functions must be defined in global scope and cannot be nested. Functions can be declared but its body must be defined eventually. In the following example we declare a function without its body. The declared function can be used freely. However, if no implementation is provided at some point during compilation an error is to be thrown as no executable code is found.
|
Functions must be defined in global scope and cannot be nested. Functions can be declared but its body must be defined eventually. In the following example we declare a function without its body. The declared function can be used freely. However, if no implementation is provided at some point during compilation an error is to be thrown as no executable code is found.
|
||||||
|
|
||||||
```glsl
|
```glsl
|
||||||
divide(in int: a, in int b, out int c)
|
fun divide(in int: a, in int b, out int c)
|
||||||
|
|
||||||
|
fun divide(in int: a, in int b, out int c)
|
||||||
|
|
||||||
divide(in int: a, in int b, out int c)
|
|
||||||
{
|
{
|
||||||
c = a / b
|
c = a / b
|
||||||
}
|
}
|
||||||
|
@ -329,7 +342,6 @@ Algebra operations are normal mathematical operations. The operations return the
|
||||||
|
|
||||||
addition
|
addition
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
a + b: addition
|
a + b: addition
|
||||||
a - b: subtraction
|
a - b: subtraction
|
||||||
|
@ -346,12 +358,9 @@ a && b
|
||||||
|
|
||||||
//xor
|
//xor
|
||||||
a ^^ b
|
a ^^ b
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
boolean algebra for bits
|
boolean algebra for bits
|
||||||
|
|
||||||
c = a | b: a or b
|
c = a | b: a or b
|
||||||
|
@ -362,8 +371,202 @@ boolean algebra for bits
|
||||||
only for ints
|
only for ints
|
||||||
a and b has to be the same datatype
|
a and b has to be the same datatype
|
||||||
expression return the statements as the datatype of a
|
expression return the statements as the datatype of a
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### TODO
|
### TODO
|
||||||
herausfinden, wie syntaktisch ein Strukt und Interfaces aufgebaut sein soll
|
herausfinden, wie syntaktisch ein Strukt und Interfaces aufgebaut sein soll
|
||||||
|
## Container types
|
||||||
|
|
||||||
|
A Container is a complex type and uses the keyword box to initialize it. a box can contain other types as well as other boxes. Types in the box are bound to the box and cant be set with storage qualifyer. boxes are not composite types so you can't declare it with a scale or a sign.
|
||||||
|
|
||||||
|
Boxes are directly initialized with all content set with the default values. You can use or modify the content by the name of the content after the instance of the box seperated by dot.
|
||||||
|
|
||||||
|
A Box can have functions that require an object of the box to use them on. To get the content of the current instance the keyword self has to be used
|
||||||
|
|
||||||
|
When an instance of a box is intitialized you can directly use a function on that instance in the same line with an explicite syntax.
|
||||||
|
```
|
||||||
|
type box: rectangle{
|
||||||
|
float: a
|
||||||
|
float: b = 43
|
||||||
|
|
||||||
|
fun area(out float: area) {
|
||||||
|
area = self.a * self.b
|
||||||
|
}
|
||||||
|
|
||||||
|
fun new(in float: a, in float: b) {
|
||||||
|
self.a = a
|
||||||
|
self.b = b
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fill(in float: a, out float b) {
|
||||||
|
self.a = a
|
||||||
|
b = a
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rectangle: square
|
||||||
|
square.new(2, 3)
|
||||||
|
|
||||||
|
|
||||||
|
float: b
|
||||||
|
rectangle: square2.fill(2, b)
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Generics
|
||||||
|
A generic defines a type alias. Generic types have an unknown size at declaration time. Respective type options can be limited by Schemes. Generics must be unique at any time. They cannot be overwritten by other generics or type defintions.
|
||||||
|
|
||||||
|
```scala
|
||||||
|
type gen: T = Add, Sub, Mul, Div
|
||||||
|
|
||||||
|
fun foo(in T: some)
|
||||||
|
```
|
||||||
|
|
||||||
|
Generics can be inlined into function parameter lists. Generics defined within parameter lists are only valid within the scop of the function they are declared in.
|
||||||
|
|
||||||
|
```scala
|
||||||
|
fun foo(type gen: T, type gen: U)(in T: t, out U: u)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Composition and polymorphism
|
||||||
|
|
||||||
|
Schemes define certain functionality that is to be implemented by a given type.
|
||||||
|
They define functions a type has to implement in order to be a member of the schemes accountants.
|
||||||
|
```glsl
|
||||||
|
scheme Area {
|
||||||
|
fun area(out float: area)
|
||||||
|
}
|
||||||
|
|
||||||
|
type box: Rect = Area {
|
||||||
|
float: a
|
||||||
|
float: b
|
||||||
|
|
||||||
|
fun area(out float: area) {
|
||||||
|
area = self.a * self.b
|
||||||
|
}
|
||||||
|
|
||||||
|
fun new(in float: a, in float: b) {
|
||||||
|
self.a = a
|
||||||
|
self.b = b
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scheme cube = area{
|
||||||
|
fun cube( out float: cube)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Schemes can inherit the functionalities of other schemes:
|
||||||
|
|
||||||
|
```
|
||||||
|
type unsigned short short int: ascii
|
||||||
|
|
||||||
|
scheme Stringify {
|
||||||
|
fun stringify(out ref ascii)
|
||||||
|
}
|
||||||
|
|
||||||
|
scheme Serialize = Stringify {
|
||||||
|
type gen: T
|
||||||
|
|
||||||
|
fun serialize(in ref ascii)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The number of type that can be inferred for a generic can be limited with schemes. A generic that is marked with a specific scheme will only accept type that implement that scheme.
|
||||||
|
|
||||||
|
```
|
||||||
|
scheme Add {
|
||||||
|
type gen: T
|
||||||
|
|
||||||
|
fun add(in T, in T, out T)
|
||||||
|
}
|
||||||
|
|
||||||
|
scheme Sub {
|
||||||
|
type gen: T
|
||||||
|
|
||||||
|
fun sub(in T, in T, out T)
|
||||||
|
}
|
||||||
|
|
||||||
|
scheme Algebra = Add, Sub {
|
||||||
|
}
|
||||||
|
|
||||||
|
fun do_math(type gen: T = Algebra)(in T, in T)
|
||||||
|
```
|
||||||
|
|
||||||
|
# Standard library
|
||||||
|
|
||||||
|
## Packages
|
||||||
|
|
||||||
|
### Intrinsics `intr`
|
||||||
|
Containes platform specific intrisic functions and data types.
|
||||||
|
Some intrinsic function may be optimized by the compiler to resolve to a set of native instructs and make usage of hardware acceleration.
|
||||||
|
|
||||||
|
Example functions include operations for bit shifts and rotations.
|
||||||
|
Optionally supported definitions for vector extensions such SSE or AVX may be available through language extensions such as: `GEM_EXT_AVX2`, `GEM_EXT_SSE4`.
|
||||||
|
|
||||||
|
### Memory management `mem`
|
||||||
|
|
||||||
|
Ability to allocate and deallocate memory.
|
||||||
|
|
||||||
|
```
|
||||||
|
fun alloc(in unsigned long int: len, out ref gen: ptr)
|
||||||
|
|
||||||
|
fun realloc(in unsigned long int: len, in out ref gen: ptr)
|
||||||
|
|
||||||
|
fun free(in ref gen: ptr)
|
||||||
|
|
||||||
|
fun copy(type gen: T)(in ref T: src, in ref T: dst)
|
||||||
|
|
||||||
|
fun fill(type gen: T)(in ref T: src, in T: elem)
|
||||||
|
|
||||||
|
fun append(type gen: T)(in ref T: src, in T: elem)
|
||||||
|
|
||||||
|
fun swap(type gen: T)(in ref T: a, in ref T: b)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Common data structures `data`
|
||||||
|
|
||||||
|
Contains boxes which implement common data types used in various other languages such as:
|
||||||
|
|
||||||
|
- Stack
|
||||||
|
- Queue
|
||||||
|
- Array
|
||||||
|
- LinkedList
|
||||||
|
- ArrayList
|
||||||
|
- Hashmap
|
||||||
|
- BTree
|
||||||
|
|
||||||
|
### UTF-8 Strings `str`
|
||||||
|
|
||||||
|
Growable UTF-8 encoded string data structure and string processing functions.
|
||||||
|
|
||||||
|
### Files `fs`
|
||||||
|
|
||||||
|
Create, read and write to files.
|
||||||
|
|
||||||
|
### Input and Output `io`
|
||||||
|
|
||||||
|
Access to standard input, output and error streams.
|
||||||
|
|
||||||
|
### Formatting `fmt`
|
||||||
|
|
||||||
|
Functions for formatting various arguments into strings and writing them into streams.
|
||||||
|
|
||||||
|
### Multithreading `thread`
|
||||||
|
|
||||||
|
Access to native operating system threads
|
||||||
|
|
||||||
|
### Atomic data structures and synchronisation mechanisims `atom`
|
||||||
|
|
||||||
|
Includes:
|
||||||
|
- Semaphore
|
||||||
|
- Mutex
|
||||||
|
- Channel
|
||||||
|
|
||||||
|
### Native operating system `os`
|
||||||
|
|
||||||
|
Access to information about operating system or platform specific functionality
|
||||||
|
|
Loading…
Reference in New Issue