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

Add support for composable structs #351

Merged
merged 11 commits into from
Oct 7, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/ci-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ jobs:
uses: actions/cache@v3
with:
path: /home/runner/work/spice/llvm
key: llvm-17.0.1
key: llvm-17.0.2

- name: Setup LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
cd ..
rm -rf llvm
git clone --depth 1 --branch llvmorg-17.0.1 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-17.0.2 https://github.com/llvm/llvm-project llvm
mkdir ./llvm/build
cd ./llvm/build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS_RELEASE="-O2" -DLLVM_ENABLE_RTTI=ON -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 @@ -46,14 +46,14 @@ jobs:
uses: actions/cache@v3
with:
path: /home/runner/work/spice/llvm
key: llvm-17.0.1
key: llvm-17.0.2

- name: Setup LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
echo "/usr/lib/ccache:/usr/local/opt/ccache/libexec" >> $GITHUB_PATH
cd ..
git clone --depth 1 --branch llvmorg-17.0.1 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-17.0.2 https://github.com/llvm/llvm-project llvm
mkdir ./llvm/build
cd ./llvm/build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS_RELEASE="-O2" -DLLVM_ENABLE_RTTI=ON -GNinja ../llvm
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ jobs:
uses: actions/cache@v3
with:
path: /home/runner/work/spice/spice/llvm
key: llvm-17.0.1-linux-x64
key: llvm-17.0.2-linux-x64

- name: Setup LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
git clone --depth 1 --branch llvmorg-17.0.1 https://github.com/llvm/llvm-project.git llvm
git clone --depth 1 --branch llvmorg-17.0.2 https://github.com/llvm/llvm-project.git llvm
mkdir ./llvm/build
cd ./llvm/build
cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS_RELEASE="-O2" -DLLVM_ENABLE_RTTI=ON -Wno-dev -Wattributes ../llvm
Expand Down Expand Up @@ -107,12 +107,12 @@ jobs:
uses: actions/cache@v3
with:
path: /home/runner/work/spice/spice/llvm
key: llvm-17.0.1-linux-aarch64
key: llvm-17.0.2-linux-aarch64

- name: Clone LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
git clone --depth 1 --branch llvmorg-17.0.1 https://github.com/llvm/llvm-project.git llvm
git clone --depth 1 --branch llvmorg-17.0.2 https://github.com/llvm/llvm-project.git llvm
mkdir ./llvm/build

- name: Setup LLVM
Expand Down Expand Up @@ -185,12 +185,12 @@ jobs:
uses: actions/cache@v3
with:
path: D:/a/spice/spice/llvm
key: llvm-17.0.1-win-x64
key: llvm-17.0.2-win-x64

- name: Setup LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
git clone --depth 1 --branch llvmorg-17.0.1 https://github.com/llvm/llvm-project.git llvm
git clone --depth 1 --branch llvmorg-17.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
2 changes: 1 addition & 1 deletion .run/spice.run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="spice" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="run -O0 -d ../../media/test-project/test.spice" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Spice" TARGET_NAME="spice" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="Spice" RUN_TARGET_NAME="spice">
<configuration default="false" name="spice" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="build -O0 -d -g -ir ../../media/test-project/test.spice" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Spice" TARGET_NAME="spice" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="Spice" RUN_TARGET_NAME="spice">
<envs>
<env name="SPICE_STD_DIR" value="$PROJECT_DIR$/std" />
</envs>
Expand Down
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-17.0.1 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-17.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-17.0.1 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-17.0.2 https://github.com/llvm/llvm-project llvm
colored_echo "done."

# Build LLVM
Expand Down
1 change: 1 addition & 0 deletions docs/docs/language/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Spice offers the option to annotate single function or whole modules via attribu
### Available attributes

- `core.linker.flag: string`: Append linker flag
- `core.compiler.alwaysKeepOnNameCollision: bool`: Always keep the symbols of this source files when merging the name registries of multiple source files

## Function attributes

Expand Down
78 changes: 37 additions & 41 deletions media/test-project/test.spice
Original file line number Diff line number Diff line change
@@ -1,42 +1,38 @@
import "std/io/cli-parser";
import "std/io/cli-subcommand";

type CliOptions struct {
string greetName = ""
}

p callback(bool& value) {
printf("Callback called with value %d\n", value);
}

f<int> main(int argc, string[] argv) {
CliParser parser = CliParser("Test Program", "This is a simple test program");
parser.setVersion("v0.1.0");
parser.setFooter("Copyright (c) Marc Auberer 2021-2023");

CliOptions options;
CliSubcommand& greet = parser.addSubcommand("greet", "Greet someone");
greet.addOption("--name", options.greetName, "Name of the person to greet");

parser.parse(argc, argv);

// Greet persion if requested
if options.greetName != "" {
printf("Hello %s!\n", options.greetName);
}
}

/*import "std/data/hash-table";

f<int> main() {
String s = String("Hello ");
assert s.getRaw() == "Hello ";
assert s.getLength() == 6;
assert s.getCapacity() == 12;
s.append("World!");
assert s.getRaw() == "Hello World!";
assert s.getLength() == 12;
assert s.getCapacity() == 12;
s.append('?');
assert s.getRaw() == "Hello World!?";
assert s.getLength() == 13;
assert s.getCapacity() == 24;
s.append('!');
assert s.getRaw() == "Hello World!?!";
assert s.getLength() == 14;
assert s.getCapacity() == 24;
s.clear();
assert s.getRaw() == "";
assert s.getLength() == 0;
assert s.getCapacity() == 24;
s.reserve(100l);
assert s.getRaw() == "";
assert s.getLength() == 0;
assert s.getCapacity() == 100;
s = String("");
assert s.isEmpty();
s.append('a');
assert !s.isEmpty();
s = String("This is a test. And because this is a test, it is a test.");
assert !s.replace("foo", "demo");
assert s.replace("test", "demo");
assert s.getRaw() == "This is a demo. And because this is a test, it is a test.";
assert s.replace("test", "demonstration", 45l);
assert s.getRaw() == "This is a demo. And because this is a test, it is a demonstration.";
assert s.replace("test", "d");
assert s.getRaw() == "This is a demo. And because this is a d, it is a demonstration.";
assert s.replaceAll(" is ", " was ") == 3;
assert s.getRaw() == "This was a demo. And because this was a d, it was a demonstration.";

printf("All assertions passed!");
}
HashTable<int, int> ht;
ht.insert(1, 2);
ht.insert(2, 3);
ht.insert(3, 4);
ht.insert(4, 5);
ht.insert(5, 6);
}*/
Loading