Added function overloading and using numbers

This commit is contained in:
Teascade 2017-08-27 23:58:40 +00:00
parent e0730f90a9
commit 5226f9b68b
1 changed files with 24 additions and 0 deletions

View File

@ -34,6 +34,7 @@ Table of contents for the Omega spec
- [Parenthesis](#parenthesis)
- [Values](#values)
- [Special cases](#special-cases)
- [Function overloading](#function-overloading)
- [Keywords](#keywords)
- [Built-in functions](#built-in-functions)
@ -205,6 +206,13 @@ Values in Omega are strongly typed, meaning combining two different types cannot
### Conditions
For the sake of glossary, conditions can simply be `true` or `false`, but in all cases where "conditions" are said, [logical operators](#logical-operators) also apply.
### Using numbers
When using numbers directly (like `5`, `32` or `753`), if their type cannot be deducted easily (via parameter type or variable type), the number's type will default to `i32`, then `i64`, then `i16`, then `f32` and finally `f64`.
If you however use numbers with decimals like `5.0`, `32.2` or `73.1`, their type will default to `f32` and then `f64`.
If it is necessary to specify the type of the number (ie. for [function overloading](#function overloading)), you can simply add the type immediately after the number, e.g. `5i32`, `32f32`, or `12i16`.
## Special cases
There are some special (mostly arithmetic) cases where different languages might act one way or another, so here are a list of those cases and how Omega handles them:
@ -217,6 +225,21 @@ This also causes a runtime exception, as can be deducted.
**Integer under-/overflow**
Trying to assign a number larger or smaller than the byte-limit of the type allows (ie. larger than `2147483647` for `i32` or smaller than `-2147483647`), will cause a runtime exception.
## Function Overloading
[Function overloading](https://en.wikipedia.org/wiki/Function_overloading) in Omega is possible, meaning you can create functions that have the same name as other already existing functions, but the parameter count and/or parameter types must differ.
ie. you could have two functions called `test`, both of which require a parameter `param`, but the other function's `param` is a string type, and the other is `i32`, like so:
```
def test(param: string) {
// Code
}
def test(param: i32) {
// Code
}
```
When calling overloaded functions though, keep in mind that if you have e.g. `test(param: i32)` and `test(param: i64)`, when calling it by `test(5)`, the first overload will be called, since `5` defaults to `i32` (See [using numbers](#using-numbers) under [values](#values)). To call the `i64` version, you need to specify the type by calling `test(5i64)`
## Keywords
The following keywords are specified to execute an action.
@ -332,6 +355,7 @@ def erronous_returning_function(param: boolean) -> i32 {
- If the function [`return`](#return)s something, there must be a return-type definition (`-> T`) after the function signature (see 4th example).
- If return-type is definied, but some paths of the function will not [`return`](#return) anything, a compile-time error occurs (see 5th example).
#### `return`
Returns the value rightside to the keyword. Must be inside a function definition to use this.
```