added changes from review 21.03.2024
parent
85bb2cc375
commit
e0dfd472a7
|
@ -373,8 +373,8 @@ boolean algebra for bits
|
||||||
expression return the statements as the datatype of a
|
expression return the statements as the datatype of a
|
||||||
```
|
```
|
||||||
|
|
||||||
### TODO
|
|
||||||
herausfinden, wie syntaktisch ein Strukt und Interfaces aufgebaut sein soll
|
|
||||||
## Container types
|
## 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.
|
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.
|
||||||
|
@ -410,17 +410,143 @@ square.new(2, 3)
|
||||||
|
|
||||||
float: b
|
float: b
|
||||||
rectangle: square2.fill(2, b)
|
rectangle: square2.fill(2, b)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Modules
|
||||||
|
|
||||||
|
Code in a file is referred to as a module. Modules can be importet into one another.
|
||||||
|
Modules can be imported with the `import` keyword followed a literal specifying the relative path to the file with the module source. To use a function within a certain module you have to specify the module the name of the file seperated with a point.
|
||||||
|
|
||||||
|
File `bar.gem`
|
||||||
|
```kotlin
|
||||||
|
fun foo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
File `main.gem`:
|
||||||
|
```kotlin
|
||||||
|
import "bar.gem"
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
bar.foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Imports cascades over modules so if a Module is imported in another module the main file can refer to both with the filename as the name of the module. Every Module name has to be unique and throws an error if not.
|
||||||
|
|
||||||
|
File `foo.gem`
|
||||||
|
```kotlin
|
||||||
|
fun foo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
File `bar.gem`
|
||||||
|
```kotlin
|
||||||
|
import foo.gem
|
||||||
|
```
|
||||||
|
|
||||||
|
File `main.gem`:
|
||||||
|
```kotlin
|
||||||
|
import "bar.gem"
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
bar.foo.foo()
|
||||||
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
To hide functionalities inside modules so another file can't use them the keyword `silent` is used. In the example the function `bar` and the variable `number` can't be used in main.
|
||||||
|
|
||||||
|
File `bar.gem`
|
||||||
|
```scala
|
||||||
|
fun foo() {
|
||||||
|
|
||||||
## 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.
|
|
||||||
|
silent fun bar() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
silent int: number
|
||||||
|
```
|
||||||
|
|
||||||
|
File `main.gem`:
|
||||||
|
```kotlin
|
||||||
|
import "bar.gem"
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
bar.foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
For boxes the silent keyword can be used for the whole box and/or specific functions inside of it.
|
||||||
|
|
||||||
|
```
|
||||||
|
silent type box: foo {
|
||||||
|
|
||||||
|
int: number
|
||||||
|
|
||||||
|
silent fun bar () {}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Comments
|
||||||
|
|
||||||
|
comments or ignored characters starts with `#` and ends with a line break
|
||||||
|
|
||||||
```scala
|
```scala
|
||||||
|
|
||||||
|
#comment
|
||||||
|
|
||||||
|
int: foo #comment
|
||||||
|
|
||||||
|
#########comment
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Compiler Meta Functions
|
||||||
|
|
||||||
|
Compiler meta functions are predefined "functions". They are called like normal functions and have repective deklarations but are builtin.
|
||||||
|
They are not executed during runtime but are always evaluated by the compiler at compile time.
|
||||||
|
|
||||||
|
### Typeof
|
||||||
|
resolves the given T's type to an UTF-8 encoded string
|
||||||
|
`typeof(type gen: T)(in ref T, out ref short short int: typename)`
|
||||||
|
|
||||||
|
### Sizeof
|
||||||
|
resolves the given T's type size in bytes
|
||||||
|
`sizeof(type gen: T)(in ref T, out unsigned long int)`
|
||||||
|
|
||||||
|
### File name
|
||||||
|
returns the current name of the file the function is called in
|
||||||
|
`filename(out ref short short int, out unsigned long int)`
|
||||||
|
|
||||||
|
### Function name
|
||||||
|
returns the current name of the function it is called in
|
||||||
|
`funname(out ref short short int, out unsigned long int)`
|
||||||
|
|
||||||
|
### Line number
|
||||||
|
returns the current line number the function is called in
|
||||||
|
`lineno(out unsigned long int)`
|
||||||
|
|
||||||
|
# Language Extensions
|
||||||
|
|
||||||
|
A extension adds extra functionality to the base language.
|
||||||
|
|
||||||
|
## Generics Extension
|
||||||
|
|
||||||
|
Extension name: `GEM_EXT_GENERIC`
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
```kotlin
|
||||||
type gen: T = Add, Sub, Mul, Div
|
type gen: T = Add, Sub, Mul, Div
|
||||||
|
|
||||||
fun foo(in T: some)
|
fun foo(in T: some)
|
||||||
|
@ -428,15 +554,42 @@ 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.
|
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
|
```kotlin
|
||||||
fun foo(type gen: T, type gen: U)(in T: t, out U: u)
|
fun foo(type gen: T, type gen: U)(in T: t, out U: u)
|
||||||
|
|
||||||
|
|
||||||
|
short int: buffer
|
||||||
|
short short int: number
|
||||||
|
|
||||||
|
foo(buffer, number)
|
||||||
|
|
||||||
|
foo(short int, short short int, buffer, number)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
note, that you can set the types, but only none or all. If the variables dont have th right type the compiler throws an error.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
The types of generics can be resolved to a concrete type with the `of` syntax. This syntax adds the keyword `of` to box type deklarations using generics.
|
||||||
|
With this syntax you can specify concrete types to generics defined in declared order (top to bottom).
|
||||||
|
|
||||||
|
```scala
|
||||||
|
type Box: Boxname = Scheme1, Scheme2{
|
||||||
|
|
||||||
|
type gen: generic
|
||||||
|
generic: buffer
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxname of int: box_with_int
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Composition and polymorphism
|
## Composition and polymorphism
|
||||||
|
|
||||||
Schemes define certain functionality that is to be implemented by a given type.
|
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.
|
They define functions a type has to implement in order to be a member of the schemes accountants.
|
||||||
```glsl
|
```scala
|
||||||
scheme Area {
|
scheme Area {
|
||||||
fun area(out float: area)
|
fun area(out float: area)
|
||||||
}
|
}
|
||||||
|
@ -455,20 +608,22 @@ type box: Rect = Area {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scheme cube = area{
|
scheme cube = Area{
|
||||||
fun cube( out float: cube)
|
fun cube( out float: cube)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Schemes can inherit the functionalities of other schemes:
|
Schemes can inherit the functionalities of other schemes:
|
||||||
|
|
||||||
```
|
```scala
|
||||||
type unsigned short short int: ascii
|
type unsigned short short int: ascii
|
||||||
|
|
||||||
scheme Stringify {
|
scheme Stringify {
|
||||||
fun stringify(out ref ascii)
|
fun stringify(out ref ascii)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
scheme Serialize = Stringify {
|
scheme Serialize = Stringify {
|
||||||
type gen: T
|
type gen: T
|
||||||
|
|
||||||
|
@ -497,17 +652,47 @@ scheme Algebra = Add, Sub {
|
||||||
fun do_math(type gen: T = Algebra)(in T, in T)
|
fun do_math(type gen: T = Algebra)(in T, in T)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
schemes can be silent for modules. Every function within it is silent when implemented. If a silent scheme is inheritated then the new scheme is implicid silent.
|
||||||
|
|
||||||
|
```
|
||||||
|
silent scheme Add {
|
||||||
|
type gen: T
|
||||||
|
|
||||||
|
fun add(in T, in T, out T)
|
||||||
|
}
|
||||||
|
|
||||||
|
scheme Algebra = Add {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#SAME AS
|
||||||
|
|
||||||
|
silent scheme Algebra = Add {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
. . .
|
||||||
|
|
||||||
|
|
||||||
|
type box: foo = Algebra {
|
||||||
|
|
||||||
|
fun add (in foo )
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#SAME AS
|
||||||
|
|
||||||
|
type box: foo = Algebra {
|
||||||
|
|
||||||
|
silent fun add (in foo )
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
# Standard library
|
# 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`
|
### Memory management `mem`
|
||||||
|
|
||||||
Ability to allocate and deallocate memory.
|
Ability to allocate and deallocate memory.
|
||||||
|
@ -528,6 +713,7 @@ 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)
|
fun swap(type gen: T)(in ref T: a, in ref T: b)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Common data structures `data`
|
### Common data structures `data`
|
||||||
|
|
||||||
Contains boxes which implement common data types used in various other languages such as:
|
Contains boxes which implement common data types used in various other languages such as:
|
||||||
|
|
Loading…
Reference in New Issue