Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mistakes and extend docs #206

Merged
merged 2 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
distribution: zulu
java-version: 11

- name: Setup latest Clang and build dependencies
- name: Setup latest GCC and build dependencies
run: |
sudo apt install gcc-12 g++-12
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 110 --slave /usr/bin/g++ g++ /usr/bin/g++-12 --slave /usr/bin/gcov gcov /usr/bin/gcov-12 --slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-12 --slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-12
Expand Down
16 changes: 8 additions & 8 deletions docs/docs/language/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ string[5] myStringArray = { "First item", "Second Item", "Third item" };
The `5` in the brackets is the size of the array. The initial values can be provided in curly braces after the assign operator and must be of the same data type. <br>
As you can see, there are less values (3) than the array size is (5). The rest of the values are set to the default data type value. The default data type values are:

| Type | Default value |
| -------- | ----------------------------- |
| `int` | `0` |
| `double` | `0.0` |
| `string` | `""` |
| `bool` | `false` |
| `struct` | Default values for all fields |
| Type | Default value |
|----------|---------------------------------------------|
| `int` | `0` |
| `double` | `0.0` |
| `string` | `""` |
| `bool` | `false` |
| `struct` | Instance with default values for all fields |

To access an array item, you can use the index. The indexes are >= 0 per definition:
```spice
string item3Value = myStringArray[3];
```

More complex expessions for initial array values and item indexing are possible. Here's an example:
More complex expressions for initial array values and item indexing are possible. Here's an example:
```spice
// Initialize array
dyn condition = 1 != 2;
Expand Down
35 changes: 34 additions & 1 deletion docs/docs/language/builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Builtin Functions
---

Spice offers two builtin functions out of the box. Those can be used anywhere without having to be imported manually and can be used to establish a minimal setup for testing or the like.
Spice offers five builtin functions out of the box. Those can be used anywhere without having to be imported manually and can be used to establish a minimal setup for testing or the like.

## The `printf` builtin
Printf works the same as the `printf` function in C and is designed for printing a string to the standard text output (cout).
Expand Down Expand Up @@ -77,4 +77,37 @@ len({1, 2, 3, 4}); // 4

string[5] stringArray = {"string1", "string2", "string3"};
len(stringArray); // 5
```

## The `tid` builtin
Tid returns the thread id of the current thread.

### Signature
`int tid()`

### Usage example
```spice
int threadId = tid();
```

## The `join` builtin
Join waits for the termination of the one or more given threads.
It returns the number of joined threads as an `int`.

### Signature
`int join(byte* ...threadIds)`

### Usage example
```spice
byte* t1 = thread {
usleep(300 * 1000);
printf("Thread 1 finished\n");
};

byte* t2 = thread {
usleep(100 * 1000);
printf("Thread 2 finished\n");
};

int threadsJoined = join(t1, t2);
```
6 changes: 3 additions & 3 deletions docs/docs/language/casts.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ Casting an int to the short data type:
short shortVar = (short) 12;
```

Example for casting for a function fall:
Example for casting for a function call:
```spice
p testFunc(char c, long l) {
p testProc(char c, long l) {
printf("Char was: %c, long was: %d", c, l);
}
f<int> main() {
int i = 1234567;
short s = 65s;
testFunc((char) s, (long) i);
testProc((char) s, (long) i);
}
```
2 changes: 1 addition & 1 deletion docs/docs/language/declaration-modifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The `inline` modifier can be used for functions and procedures to mark them as i

### Applicable for

- Function
- Functions
- Procedures

### Example
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/language/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Functions
---

Spice distinguishes strictly between functions and procedures. Functions are used to return something, that was calculated from a given input. Other than procedures, functions must have a return value. The paradigma here is, that a function calculates and returns something whereas a procedure executes some action without a result.
Spice distinguishes strictly between functions and procedures. Functions are used to return something, that was calculated from a given input. Other than procedures, functions must have a return value. The paradigm here is, that a function calculates and returns something whereas a procedure executes some action without a result.

Functions in Spice can be defined like this:
```spice
Expand All @@ -25,10 +25,10 @@ f<int> demoFunction(string arg1, double arg2 = 5.89) {
}
```

Theis procedure could get called like so:
This function could get called like so:
```spice
demoFunction("input");
demoFunction("another input", 1.0);
int result1 = demoFunction("input");
int result1 = demoFunction("another input", 1.0);
```

!!! tip
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/language/procedures.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Procedures
---

Spice distinguishes strictly between functions and procedures. Procedures are concise and enclosed blocks of code which a programmer can define within his souce code holds a set of instructions to execute in the stated order. Other than functions, procedures do not have a return value. The paradigma here is, that a function calculates and returns something whereas a procedure executes some action.
Spice distinguishes strictly between functions and procedures. Procedures are concise and enclosed blocks of code which a programmer can define within his source code holds a set of instructions to execute in the stated order. Other than functions, procedures do not have a return value. The paradigm here is, that a function calculates and returns something whereas a procedure executes some action.

Procedures in Spice can be defined like this:
```spice
Expand Down