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 nested in place array initializations #185

Merged
merged 28 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1c572e2
Code improvements
marcauberer Aug 9, 2022
d2cddfc
Further improvements
marcauberer Aug 9, 2022
e7938bb
Upgrade to LLVM 15.0.0-rc2
marcauberer Aug 10, 2022
bc6e25d
Merge branch 'main' into fix/nested-in-place-array-init
marcauberer Aug 10, 2022
6005168
Fix bug
marcauberer Aug 10, 2022
13ad207
Merge branch 'main' into fix/nested-in-place-array-init
marcauberer Aug 11, 2022
505b09f
Merge branch 'main' into fix/nested-in-place-array-init
marcauberer Aug 11, 2022
407b2a1
Add CMake option for faster dev compile times
marcauberer Aug 11, 2022
9859025
Fix bug
marcauberer Aug 11, 2022
48611bf
Update test refs
marcauberer Aug 11, 2022
7b3fb0f
Fix bug
marcauberer Aug 13, 2022
931d6b5
Fix bug
marcauberer Aug 13, 2022
14963ce
Continue fixing bug
marcauberer Aug 14, 2022
fd28739
Continue fixing bug
marcauberer Aug 14, 2022
8793c05
Cleanup
marcauberer Aug 15, 2022
28a288d
Generate debug info for global variables
marcauberer Aug 16, 2022
9b66589
Add documentation for signed and unsigned modifiers
marcauberer Aug 16, 2022
c536ed0
Improve debug info
marcauberer Aug 16, 2022
012578a
Improvements
marcauberer Aug 17, 2022
ff22139
Add debug info for function parameters
marcauberer Aug 17, 2022
67ca811
Minor code improvements
marcauberer Aug 20, 2022
1455479
Fix bug
marcauberer Aug 20, 2022
1d02633
Update test refs
marcauberer Aug 21, 2022
7823350
Fix issue with error message
marcauberer Aug 21, 2022
251c4c8
Improve LLVM var naming
marcauberer Aug 21, 2022
d0cd7c7
Fix bug
marcauberer Aug 22, 2022
2f4b347
Fix bug
marcauberer Aug 22, 2022
68e5c9e
Fix bug and update test refs
marcauberer Aug 22, 2022
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
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