Skip to content

Commit

Permalink
Fix nested in place array initializations (#185)
Browse files Browse the repository at this point in the history
* Code improvements

* Further improvements

* Upgrade to LLVM 15.0.0-rc2

* Fix bug

* Add CMake option for faster dev compile times

* Fix bug

* Update test refs

* Fix bug

* Fix bug

* Continue fixing bug

* Continue fixing bug

* Cleanup

* Generate debug info for global variables

* Add documentation for signed and unsigned modifiers

* Improve debug info

* Improvements

* Add debug info for function parameters

* Minor code improvements

* Fix bug

* Update test refs

* Fix issue with error message

* Improve LLVM var naming

* Fix bug

* Fix bug

* Fix bug and update test refs
  • Loading branch information
marcauberer authored Aug 22, 2022
1 parent 5331d41 commit 607d03e
Show file tree
Hide file tree
Showing 121 changed files with 2,410 additions and 2,322 deletions.
6 changes: 3 additions & 3 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-rc1-invalidate
key: llvm-15.0.0-rc2

- 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-rc1 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-15.0.0-rc2 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 All @@ -67,7 +67,7 @@ jobs:
run: |
mkdir ./bin
cd ./bin
cmake -DCMAKE_BUILD_TYPE=Debug -DSPICE_IS_GH_ACTIONS=ON -DSPICE_BUILT_BY="ghactions" -DSPICE_LINK_STATIC=OFF -DSPICE_RUN_COVERAGE=ON -GNinja -Wattributes ..
cmake -DCMAKE_BUILD_TYPE=Debug -DSPICE_IS_GH_ACTIONS=ON -DSPICE_BUILT_BY="ghactions" -DSPICE_LINK_STATIC=OFF -DSPICE_DEV_COMPILE=ON -DSPICE_RUN_COVERAGE=ON -GNinja -Wattributes ..
cmake --build . --target Spice_test
- name: Run Test target
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ jobs:
uses: actions/cache@v3
with:
path: /home/runner/work/spice/llvm
key: 15.0.0-rc1
key: 15.0.0-rc2

- name: Setup LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
cd ..
git clone --depth 1 --branch llvmorg-15.0.0-rc1 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-15.0.0-rc2 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 All @@ -66,7 +66,7 @@ jobs:
run: |
mkdir ./bin
cd ./bin
cmake -DCMAKE_BUILD_TYPE=Release -DSPICE_BUILT_BY="ghactions" -DSPICE_LINK_STATIC=OFF -GNinja -Wattributes ..
cmake -DCMAKE_BUILD_TYPE=Release -DSPICE_BUILT_BY="ghactions" -DSPICE_LINK_STATIC=OFF -DSPICE_DEV_COMPILE=ON -GNinja -Wattributes ..
cmake --build . --target Spice_test
- name: Perform CodeQL Analysis
Expand Down
8 changes: 4 additions & 4 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-rc1-linux-x64
key: llvm-15.0.0-rc2-linux-x64

- name: Setup LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
git clone --depth 1 --branch llvmorg-15.0.0-rc1 https://github.com/llvm/llvm-project.git llvm
git clone --depth 1 --branch llvmorg-15.0.0-rc2 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-rc1-win-x64
key: llvm-15.0.0-rc2-win-x64

- name: Setup LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
git clone --depth 1 --branch llvmorg-15.0.0-rc1 https://github.com/llvm/llvm-project.git llvm
git clone --depth 1 --branch llvmorg-15.0.0-rc2 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.run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Spice_run" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="run -O2 -ir ../../media/test-project/os-test.spice" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Spice" TARGET_NAME="Spice_run" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="Spice" RUN_TARGET_NAME="Spice_run">
<configuration default="false" name="Spice_run" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="run -O0 -ir ../../media/test-project/os-test.spice" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Spice" TARGET_NAME="Spice_run" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="Spice" RUN_TARGET_NAME="Spice_run">
<envs>
<env name="RUN_TESTS" value="OFF" />
</envs>
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ENV SPICE_DOCKERIZED=1
ARG COMPILER_PATH=linux-amd64

RUN apk update && apk add --repository=https://dl-cdn.alpinelinux.org/alpine/edge/main --no-cache \
build-base ncurses-dev libc6-compat gcompat && rm -rf /var/cache/apk/*
build-base ncurses-dev libc6-compat gcompat zstd-dev && rm -rf /var/cache/apk/*
RUN ln -sf /usr/lib/libncursesw.so.6 /usr/lib/libtinfo.so.6

COPY std/ /usr/lib/spice/std/
Expand Down
11 changes: 11 additions & 0 deletions Options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ else()
message(STATUS "Spice: LTO for Spice is disabled.")
endif()

# MOLD_X86_64_ONLY and MOLD_ARM64_ONLY are developer-only options.
# You should not use it for creating an executable for production use.
option(SPICE_DEV_COMPILE "Developer-only option" OFF)
if(SPICE_DEV_COMPILE)
message(STATUS "Spice: Dev build for Spice is enabled.")
SET(CMAKE_CXX_FLAGS_DEBUG "-ffunction-sections -fdata-sections ${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections")
else()
message(STATUS "Spice: Dev build for Spice is disabled.")
endif()

# Link statically
option(SPICE_LINK_STATIC "Link the compiler executable statically" OFF)
if (SPICE_LINK_STATIC)
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-15.0.0-rc1 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-15.0.0-rc2 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 @@ -16,7 +16,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-rc1 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-15.0.0-rc2 https://github.com/llvm/llvm-project llvm
colored_echo "done."

# Build LLVM
Expand Down
36 changes: 36 additions & 0 deletions docs/docs/language/declaration-modifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,40 @@ const int THIS_IS_A_CONSTANT = 101;
f<int> main() {
THIS_IS_A_CONSTANT++; // Will give a compiler error
}
```

## The `signed` modifier

Marks a numeric variable to use signed numbers explicitly.

### Applicable for

- Local variables
- Global variables
- Struct fields

### Example

```spice
f<int> main() {
signed int signedInt = -0x567;
}
```

## The `unsigned` modifier

Marks a numeric variable to use unsigned numbers explicitly.

### Applicable for

- Local variables
- Global variables
- Struct fields

### Example

```spice
f<int> main() {
unsigned int unsignedInt = -0x567; // Will wrap around
}
```
13 changes: 3 additions & 10 deletions media/test-project/os-test.spice
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,8 @@ f<int> main() {
printf("Hello %s!", p1.getSecond());
}*/

type TestStruct struct {
bool test
}

p TestStruct.dtor(int test) {
printf("Dtor called");
}

f<int> main() {
TestStruct t = TestStruct();
printf("Test: %d\n", 0o0000777);
foreach dyn item : { 1, 2, 3, 4, 5 } {
printf("Item %d: %d\n", idx, item);
}
}
2 changes: 1 addition & 1 deletion setup-libs.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ git clone --depth 1 --branch 4.10.1 https://github.com/antlr/antlr4.git
git clone --depth 1 --branch release-1.12.1 https://github.com/google/googletest.git

mkdir json
curl -SsL "https://github.com/nlohmann/json/releases/download/v3.11.1/json.hpp" --output json/json.hpp
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
Expand Down
2 changes: 1 addition & 1 deletion setup-libs.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ git clone --depth 1 --branch 4.10.1 https://github.com/antlr/antlr4.git
git clone --depth 1 --branch release-1.12.1 https://github.com/google/googletest.git

mkdir json
curl -SsL "https://github.com/nlohmann/json/releases/download/v3.11.1/json.hpp" --output json/json.hpp
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
Expand Down
2 changes: 1 addition & 1 deletion src/Spice.g4
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ TYPE_CHAR: 'char';
TYPE_STRING: 'string';
TYPE_BOOL: 'bool';
TYPE_DYN: 'dyn';
CONST: 'const';
SIGNED: 'signed';
UNSIGNED: 'unsigned';
INLINE: 'inline';
Expand All @@ -101,7 +102,6 @@ ASSERT: 'assert';
FOR: 'for';
FOREACH: 'foreach';
WHILE: 'while';
CONST: 'const';
IMPORT: 'import';
BREAK: 'break';
CONTINUE: 'continue';
Expand Down
Loading

0 comments on commit 607d03e

Please sign in to comment.