Skip to content

Commit

Permalink
Fix import bug (#207)
Browse files Browse the repository at this point in the history
* Code improvements

* Upgrade LLVM to 15.0.1

* Upgrade to LLVM 15.0.2

* Code and docs improvements

* Fix bug

* Fix #203

* Update test refs
  • Loading branch information
marcauberer authored Oct 6, 2022
1 parent bbe6320 commit 9731222
Show file tree
Hide file tree
Showing 44 changed files with 438 additions and 567 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ jobs:
uses: actions/cache@v3
with:
path: /home/runner/work/spice/llvm
key: llvm-15.0.0
key: llvm-15.0.2

- name: Setup LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
cd ..
rm -rf llvm
git clone --depth 1 --branch llvmorg-15.0.0 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-15.0.2 https://github.com/llvm/llvm-project llvm
mkdir ./llvm/build
cd ./llvm/build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS_RELEASE="-O2" -GNinja ../llvm
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ jobs:
uses: actions/cache@v3
with:
path: /home/runner/work/spice/llvm
key: 15.0.0
key: 15.0.2

- name: Setup LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
cd ..
git clone --depth 1 --branch llvmorg-15.0.0 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-15.0.2 https://github.com/llvm/llvm-project llvm
mkdir ./llvm/build
cd ./llvm/build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS_RELEASE="-O2" -GNinja ../llvm
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ jobs:
uses: actions/cache@v3
with:
path: /home/runner/work/spice/spice/llvm
key: llvm-15.0.0-linux-x64
key: llvm-15.0.2-linux-x64

- name: Setup LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
git clone --depth 1 --branch llvmorg-15.0.0 https://github.com/llvm/llvm-project.git llvm
git clone --depth 1 --branch llvmorg-15.0.2 https://github.com/llvm/llvm-project.git llvm
mkdir ./llvm/build
cd ./llvm/build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS_RELEASE="-O2" -GNinja -Wno-dev -Wattributes ../llvm
Expand Down Expand Up @@ -124,12 +124,12 @@ jobs:
uses: actions/cache@v3
with:
path: D:/a/spice/spice/llvm
key: llvm-15.0.0-win-x64
key: llvm-15.0.2-win-x64

- name: Setup LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
git clone --depth 1 --branch llvmorg-15.0.0 https://github.com/llvm/llvm-project.git llvm
git clone --depth 1 --branch llvmorg-15.0.2 https://github.com/llvm/llvm-project.git llvm
setx /M PATH "%PATH%;C:\mingw64\mingw64\bin"
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
echo "Adding MinGW to path done."
Expand Down Expand Up @@ -222,7 +222,7 @@ jobs:
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
version: v1.11.3
version: v1.11.5
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ This is the home repo of the Spice programming language. Spice is a compiled lan

If you like Spice, please consider a GitHub star! ⭐

|:warning: | The compiler of the Spice language is still in alpha stages and under development. Please note that code may behave differently in the future or even break due to the volatility of the compiler. |
|----------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| :warning: | The compiler of the Spice language is still in alpha stages and under development. Please note that code may behave differently in the future or even break due to the volatility of the compiler. |
|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|

## Documentation
Please visit the documentation at [spicelang.com](https://www.spicelang.com). <br>
Expand Down Expand Up @@ -96,4 +96,4 @@ Currently, Spice only offers stable support for x86_64/windows and x86_64/linux.
## Contribute to the project
If you want to contribute to this project, please ensure you comply with the [contribution guidelines](./CONTRIBUTING.md).

© ChilliBits 2021-2022
© ChilliBits 2021-2022
2 changes: 1 addition & 1 deletion dev-setup.bat
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ echo done.

REM - Clone LLVM
echo [Step 2] Cloning LLVM (Could take a while) ...
git clone --depth 1 --branch llvmorg-15.0.0 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-15.0.2 https://github.com/llvm/llvm-project llvm
echo done.

REM - Build LLVM
Expand Down
2 changes: 1 addition & 1 deletion dev-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ colored_echo "done."

# Clone LLVM
colored_echo "[Step 2] Cloning LLVM (Could take a while) ... "
git clone --depth 1 --branch llvmorg-15.0.0 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-15.0.2 https://github.com/llvm/llvm-project llvm
colored_echo "done."

# Build LLVM
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/language/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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:
As you can see, there are fewer 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 |
|----------|---------------------------------------------|
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/language/builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Within the template string you can use the `\n` control character to achieve a l

### Placeholders
| Placeholder | Type | Output | Example |
| ----------- | --------------------------- | --------------------------------------------- | ------------ |
|-------------|-----------------------------|-----------------------------------------------|--------------|
| `%c` | `char` | Character | a |
| `%d`/`%i` | `int`, `short`, `long` | Signed decimal integer | 392 |
| `%u` | `int`, `short`, `long` | Unsigned decimal integer | 7235 |
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/language/data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ variable2 = false;
## The `dyn` data type
The `dyn` data type is a more unconventional data type. Dyn stands for dynamic and means that the `dyn` data type can hold any value of one of the eight types `double`, `int`, `short`, `long`, `byte`, `char`, `string` or `bool`. The concrete type of a `dyn` variable gets inferred at compile time so that the language stays type-safe. This also means, that as soon as you assign a value to a `dyn` variable, the type gets set fixed and is not mutable anymore.

Dyn variables can defined like this:
Dyn variables can be defined like this:

```spice
dyn variable1 = 1.24;
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/language/for-loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ for int i = 1; i <= 10; i++ {
```

!!! note "Optional parentheses"
As with the if statement, foreach loop and while loop, the parantheses around the head of the `for` loop are optional.
As with the if statement, foreach loop and while loop, the parentheses around the head of the `for` loop are optional.

!!! tip "Usage of loop alternatives"
For loops should only be used when it is foreseeable how often a block of code will run. If this is not the case, we recommend using the [while loop](../while-loops) instead.
2 changes: 1 addition & 1 deletion docs/docs/language/foreach-loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ foreach (const int item : myIntArray) {
```

!!! note "Optional parentheses"
As with the if statement, for loop and while loop, the parantheses around the head of the `foreach` loop are optional.
As with the if statement, for loop and while loop, the parentheses around the head of the `foreach` loop are optional.

### Indexed
As soon as you need to access the index of the array item as well, you can use the indexed
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/language/hello-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Hello World

In this example, we will code a simple "Hello World" program in Spice. What it does is to simply print "Hello World!" to the console when it gets started. The guide assumes, that you already have Spice installed on your development system and are ready to go.

The first thing you need is a new file to hold the Spice code for your progam. Please create a new file in an arbitrary directory and call it `hello-world.spice`. Open up the file in a text editor of your choice and paste following code in it:
The first thing you need is a new file to hold the Spice code for your program. Please create a new file in an arbitrary directory and call it `hello-world.spice`. Open up the file in a text editor of your choice and paste following code in it:

```spice
f<int> main() {
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/language/if-statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if counter <= 10 {
The block between the curly braces only gets executed when the variable `counter` is less or equal 10, otherwise it is going to be ignored.

!!! note "Optional parentheses"
As with the for, foreach and while loops, the parantheses around the head of the `if` statement are optional.
As with the for, foreach and while loops, the parentheses around the head of the `if` statement are optional.

Let's take a look at a more complex condition:
```spice
Expand All @@ -26,4 +26,4 @@ if (otherCondition ? counter : 5) != 1 {
}
```

This piece of code is a bit pointless but you can see, that you can also have more complex conditions in there.
This piece of code is a bit pointless, but you can see, that you can also have more complex conditions in there.
4 changes: 2 additions & 2 deletions docs/docs/language/main-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Main Function
---

The `main` function is the entry point of any Spice program. When the system runs your compiled executable, the `main` function is the first function, which is called by the system. Therefore it is mandatory and must have the signature `main(): int` or `main(int argc, string[] argv): int` for retrieving command line arguments. The main function has a return value of type `int`, which represents the return code / exit code / status code of the executable.
The `main` function is the entry point of any Spice program. When the system runs your compiled executable, the `main` function is the first function, which is called by the system. Therefore, it is mandatory and must have the signature `main(): int` or `main(int argc, string[] argv): int` for retrieving command line arguments. The main function has a return value of type `int`, which represents the return code / exit code / status code of the executable.

The `main` function can be declared like this:
```spice
Expand All @@ -11,7 +11,7 @@ f<int> main() {
}
```

Like any other [function](../functions), the `main` function automatically declares the variable `result` of the same type as the function return type. You then have the option to use either the return statement (e.g.: `return 1;`) or assign a value to the `result` variable. If you choose the second option, the value of this variable gets returned at the end of the function body. Unlike normal functions, the `main` function has `0` as the initial value assigned to the `result` variable for reasons of convinience and to not always have to write `return 0;` or `result = 0;` to exit the program with a positive exit code.
Like any other [function](../functions), the `main` function automatically declares the variable `result` of the same type as the function return type. You then have the option to use either the return statement (e.g.: `return 1;`) or assign a value to the `result` variable. If you choose the second option, the value of this variable gets returned at the end of the function body. Unlike normal functions, the `main` function has `0` as the initial value assigned to the `result` variable for reasons of convenience and to not always have to write `return 0;` or `result = 0;` to exit the program with a positive exit code.

!!! info "Hello World program"
Now, as you know how to start a program in Spice, you may like to write your first Spice program. Visit the guide for the [Hello World example](../hello-world) to get started!
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/language/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Spice supports the linkage of several source files to one executable. To do so,
## Importing own source files
Here is an example for importing an own source file into the main source file. You have a source file, containing some util functions, which you want to use in your main source file

**Util functios file `utils.spice`:**
**Util functions file `utils.spice`:**
```spice
// Simple recursive fibonacci algorithm
f<int> fib(int n) {
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/language/while-loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ while counter < 20 {
```

!!! note "Optional parentheses"
As with the if statement, for loop and foreach loop, the parantheses around the head of the `while` loop are optional.
As with the if statement, for loop and foreach loop, the parentheses around the head of the `while` loop are optional.

If you would want to intentionally achieve an endless loop, you would write something like this:
If you wanted to intentionally achieve an endless loop, you would write something like this:
```spice
while true {
printf("This is gonna run forever ...");
Expand Down
2 changes: 1 addition & 1 deletion media/specs/cli11-modifications.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CLI11 lib
We use the command line parser library [CLI11](https://github.com/CLIUtils/CLI11) as a standalone header file, but we modified it,
so it allows us to use short options, that are longer than one char e.g. `-O2`, which the CLI11 libraray does not allow per default.
so it allows us to use short options, that are longer than one char e.g. `-O2`, which the CLI11 library does not allow per default.

The current version that is being used is `v2.1.2`.

Expand Down
4 changes: 2 additions & 2 deletions media/specs/multithreading.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ import "std/data/queue" as queue;
type ThreadPool struct {
unsigned int threadCount // Number of threads in the thread pool
unsigned long taskCount // Counter, which gets incremented when a task comes in
queue.Queue<void*> taskQueue // Queue of tasks to execute. Whenever a thread has no work to do it pops an item from the queue and executes that.
queue::Queue<void*> taskQueue // Queue of tasks to execute. Whenever a thread has no work to do it pops an item from the queue and executes that.
}
f<int> setThreadCount(); // Add or remove threads from the thread pool
Expand All @@ -151,4 +151,4 @@ f<int> getQueueSize(); // Returns the number of items in the task queue
- Semantic analysis of threads: [here](https://github.com/spicelang/spice/blob/main/src/analyzer/AnalyzerVisitor.cpp#L730)
- Code gen for threads: [here](https://github.com/spicelang/spice/blob/main/src/generator/GeneratorVisitor.cpp#L605)
- Tests for threads: [here](https://github.com/spicelang/spice/tree/main/test/test-files/analyzer/threads) and [here](https://github.com/spicelang/spice/tree/main/test/test-files/generator/threads)
- Fully fledged functional test: [here](https://github.com/spicelang/spice/tree/main/test/test-files/generator/arbitrary/success-fibonacci-threaded)
- Fully fledged functional test: [here](https://github.com/spicelang/spice/tree/main/test/test-files/generator/arbitrary/success-fibonacci-threaded)
2 changes: 1 addition & 1 deletion media/test-project/os-test.spice
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ f<int> main() {
pairVector.pushBack(pair.Pair<int, string>(1, "World"));

pair::Pair<int, string> p1 = pairVector.get(1);
printf("Hello %s!", p1.getSecond());
printf("Hello %s!\n", p1.getSecond());
}

/*import "std/net/http" as http;
Expand Down
2 changes: 1 addition & 1 deletion setup-libs.bat
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ mkdir json
curl -SsL "https://github.com/nlohmann/json/releases/download/v3.11.2/json.hpp" --output json/json.hpp

mkdir cli11
curl -SsL "https://github.com/spicelang/CLI11/releases/download/v2.2.0-spice/CLI11.hpp" --output cli11/CLI11.hpp
curl -SsL "https://github.com/spicelang/CLI11/releases/download/v2.3.0-spice/CLI11.hpp" --output cli11/CLI11.hpp

popd
2 changes: 1 addition & 1 deletion setup-libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ mkdir json
curl -SsL "https://github.com/nlohmann/json/releases/download/v3.11.2/json.hpp" --output json/json.hpp

mkdir cli11
curl -SsL "https://github.com/spicelang/CLI11/releases/download/v2.2.0-spice/CLI11.hpp" --output cli11/CLI11.hpp
curl -SsL "https://github.com/spicelang/CLI11/releases/download/v2.3.0-spice/CLI11.hpp" --output cli11/CLI11.hpp

cd ..
Loading

0 comments on commit 9731222

Please sign in to comment.