From 33ca4acbc7b27286039e634c9ba4c336436f90ee Mon Sep 17 00:00:00 2001 From: Marc Auberer Date: Mon, 3 Oct 2022 18:01:04 +0200 Subject: [PATCH 1/2] Fix mistakes and extend docs --- docs/docs/language/arrays.md | 16 +++++----- docs/docs/language/builtins.md | 35 ++++++++++++++++++++- docs/docs/language/casts.md | 6 ++-- docs/docs/language/declaration-modifiers.md | 2 +- docs/docs/language/functions.md | 8 ++--- docs/docs/language/procedures.md | 2 +- 6 files changed, 51 insertions(+), 18 deletions(-) diff --git a/docs/docs/language/arrays.md b/docs/docs/language/arrays.md index 9338cbcfa..d4bed8070 100644 --- a/docs/docs/language/arrays.md +++ b/docs/docs/language/arrays.md @@ -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.
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; diff --git a/docs/docs/language/builtins.md b/docs/docs/language/builtins.md index d06f651fd..bf8bd2acb 100644 --- a/docs/docs/language/builtins.md +++ b/docs/docs/language/builtins.md @@ -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). @@ -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); ``` \ No newline at end of file diff --git a/docs/docs/language/casts.md b/docs/docs/language/casts.md index 797eb6296..888f23492 100644 --- a/docs/docs/language/casts.md +++ b/docs/docs/language/casts.md @@ -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 main() { int i = 1234567; short s = 65s; - testFunc((char) s, (long) i); + testProc((char) s, (long) i); } ``` \ No newline at end of file diff --git a/docs/docs/language/declaration-modifiers.md b/docs/docs/language/declaration-modifiers.md index f03a7774b..be6f218c4 100644 --- a/docs/docs/language/declaration-modifiers.md +++ b/docs/docs/language/declaration-modifiers.md @@ -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 diff --git a/docs/docs/language/functions.md b/docs/docs/language/functions.md index c2d08bad7..89fa80620 100644 --- a/docs/docs/language/functions.md +++ b/docs/docs/language/functions.md @@ -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 @@ -25,10 +25,10 @@ f 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 diff --git a/docs/docs/language/procedures.md b/docs/docs/language/procedures.md index 8257f36a1..16912ea9b 100644 --- a/docs/docs/language/procedures.md +++ b/docs/docs/language/procedures.md @@ -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 From 6fd6663693ef94c15cc8b9e9a73bbb0ce3ab3314 Mon Sep 17 00:00:00 2001 From: Marc Auberer Date: Mon, 3 Oct 2022 18:58:22 +0200 Subject: [PATCH 2/2] Fix mistake in workflow --- .github/workflows/ci-cpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-cpp.yml b/.github/workflows/ci-cpp.yml index f01e2d4f0..64026a2ff 100644 --- a/.github/workflows/ci-cpp.yml +++ b/.github/workflows/ci-cpp.yml @@ -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