Skip to content

Commit

Permalink
Extend std & fix bugs (#194)
Browse files Browse the repository at this point in the history
* Re-enable in-place struct test

* Fix bug

* Upgrade to LLVM 15.0.0-rc3

* Fix format of lexer/parser error messages

* Add Sudoku test case

* Code and test improvements

* Add graph coloring test

* Start implementing the std implementation of HttpServer

* Make ctors and dtors public
  • Loading branch information
marcauberer authored Aug 28, 2022
1 parent 417668f commit d4b0554
Show file tree
Hide file tree
Showing 33 changed files with 704 additions and 320 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-rc2
key: llvm-15.0.0-rc3

- 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-rc2 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-15.0.0-rc3 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
6 changes: 2 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ jobs:
analyze-cpp:
name: Analyze C++ Code
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -43,13 +41,13 @@ jobs:
uses: actions/cache@v3
with:
path: /home/runner/work/spice/llvm
key: 15.0.0-rc2
key: 15.0.0-rc3

- name: Setup LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
cd ..
git clone --depth 1 --branch llvmorg-15.0.0-rc2 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-15.0.0-rc3 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
13 changes: 7 additions & 6 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-rc2-linux-x64
key: llvm-15.0.0-rc3-linux-x64

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

- name: Setup LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
git clone --depth 1 --branch llvmorg-15.0.0-rc2 https://github.com/llvm/llvm-project.git llvm
git clone --depth 1 --branch llvmorg-15.0.0-rc3 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 @@ -351,8 +351,9 @@ jobs:
asset_name: spice_${{ matrix.config.label }}_setup.msi
tag: ${{ github.ref }}

- uses: vedantmgoyal2009/winget-releaser@latest
- name: Deploy to WinGet
uses: vedantmgoyal2009/winget-releaser@latest
with:
identifier: ChilliBits.Spice
release-tag: ${{ github.ref }}
token: ${{ secrets.CR_PAT }}
token: ${{ secrets.CR_PAT }}
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-rc2 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-15.0.0-rc3 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-rc2 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-15.0.0-rc3 https://github.com/llvm/llvm-project llvm
colored_echo "done."

# Build LLVM
Expand Down
10 changes: 6 additions & 4 deletions media/test-project/os-test.spice
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
import "std/data/pair" as pair;

f<int> main() {
vec.Vector<pair.Pair<int, string>> pairVector = vec.Vector<pair.Pair<int, string>>();
vec::Vector<pair::Pair<int, string>> pairVector = vec.Vector<pair::Pair<int, string>>();
pairVector.pushBack(pair.Pair<int, string>(0, "Hello"));
pairVector.pushBack(pair.Pair<int, string>(1, "World"));

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

import "std/net/http" as http;

f<int> main() {
int[10] testArray = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
printf("Test: %d\n", testArray[10]);
http::HttpServer server = http::HttpServer();
server.serve("/test", "Hello World!");
}
20 changes: 10 additions & 10 deletions src/analyzer/AnalyzerVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ std::any AnalyzerVisitor::visitForeachLoop(ForeachLoopNode *node) {
std::string varName = node->idxVarDecl()->varName;
SymbolTableEntry *entry = currentScope->lookup(varName);
assert(entry != nullptr);
entry->updateState(INITIALIZED, err.get(), node->idxVarDecl()->codeLoc);
entry->updateState(INITIALIZED, node->idxVarDecl()->codeLoc);
}

// Check if index type is int
Expand Down Expand Up @@ -870,7 +870,7 @@ std::any AnalyzerVisitor::visitForeachLoop(ForeachLoopNode *node) {
"Foreach loop item type does not match array type. Expected " + arrayType.getName(false) + ", provided " +
itemType.getName(false));
}
itemVarSymbol->updateState(INITIALIZED, err.get(), node->itemDecl()->codeLoc);
itemVarSymbol->updateState(INITIALIZED, node->itemDecl()->codeLoc);

// Visit statement list in new scope
nestedLoopCounter++;
Expand Down Expand Up @@ -1052,7 +1052,7 @@ std::any AnalyzerVisitor::visitReturnStmt(ReturnStmtNode *node) {
}

// Set the return variable to initialized
returnVariable->updateState(INITIALIZED, err.get(), node->codeLoc);
returnVariable->updateState(INITIALIZED, node->codeLoc);
} else {
returnType = returnVariable->getType();
}
Expand Down Expand Up @@ -1270,7 +1270,7 @@ std::any AnalyzerVisitor::visitAssignExpr(AssignExprNode *node) {

// Update state in symbol table
if (!currentEntry->getType().isOneOf({TY_FUNCTION, TY_PROCEDURE}))
currentEntry->updateState(INITIALIZED, err.get(), node->lhs()->codeLoc);
currentEntry->updateState(INITIALIZED, node->lhs()->codeLoc);

// In case the lhs variable is captured, notify the capture about the write access
Capture *lhsCapture = currentScope->lookupCapture(variableName);
Expand Down Expand Up @@ -1528,7 +1528,7 @@ std::any AnalyzerVisitor::visitPrefixUnaryExpr(PrefixUnaryExprNode *node) {

// Update state in symbol table
if (currentEntry != nullptr)
currentEntry->updateState(INITIALIZED, err.get(), node->codeLoc);
currentEntry->updateState(INITIALIZED, node->codeLoc);

// In case the lhs is captured, notify the capture about the write access
if (Capture *lhsCapture = currentScope->lookupCapture(currentVarName); lhsCapture)
Expand All @@ -1539,7 +1539,7 @@ std::any AnalyzerVisitor::visitPrefixUnaryExpr(PrefixUnaryExprNode *node) {

// Update state in symbol table
if (currentEntry != nullptr)
currentEntry->updateState(INITIALIZED, err.get(), node->codeLoc);
currentEntry->updateState(INITIALIZED, node->codeLoc);

// In case the lhs is captured, notify the capture about the write access
if (Capture *lhsCapture = currentScope->lookupCapture(currentVarName); lhsCapture)
Expand Down Expand Up @@ -1653,7 +1653,7 @@ std::any AnalyzerVisitor::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) {

// Update state in symbol table
if (currentEntry != nullptr)
currentEntry->updateState(INITIALIZED, err.get(), node->codeLoc);
currentEntry->updateState(INITIALIZED, node->codeLoc);

// In case the lhs is captured, notify the capture about the write access
if (Capture *lhsCapture = currentScope->lookupCapture(currentVarName); lhsCapture)
Expand All @@ -1665,7 +1665,7 @@ std::any AnalyzerVisitor::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) {

// Update state in symbol table
if (currentEntry != nullptr)
currentEntry->updateState(INITIALIZED, err.get(), node->codeLoc);
currentEntry->updateState(INITIALIZED, node->codeLoc);

// In case the lhs is captured, notify the capture about the write access
if (Capture *lhsCapture = currentScope->lookupCapture(currentVarName); lhsCapture)
Expand Down Expand Up @@ -1959,8 +1959,8 @@ std::any AnalyzerVisitor::visitFunctionCall(FunctionCallNode *node) {

// If the return type is an external struct, initialize it
if (!scopePathBackup.isEmpty() && returnType.is(TY_STRUCT) && scopePathBackup.getCurrentScope()->isImported(currentScope)) {
SymbolType symbolType = initExtStruct(scopePathBackup.getCurrentScope(), scopePathBackup.getScopePrefix(true),
returnType.getSubType(), thisType.getTemplateTypes(), node->codeLoc);
SymbolType symbolType = initExtStruct(currentScope, scopePathBackup.getScopePrefix(true), returnType.getSubType(),
returnType.getTemplateTypes(), node->codeLoc);
return node->setEvaluatedSymbolType(symbolType);
}

Expand Down
2 changes: 1 addition & 1 deletion src/dependency/SourceFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ SourceFile::SourceFile(CliOptions &options, SourceFile *parent, std::string name
antlrCtx.parser->removeParseListeners();

// Create AST
ast = std::make_shared<EntryNode>(nullptr, CodeLoc(filePath, 1, 1));
ast = std::make_shared<EntryNode>(nullptr, CodeLoc(1, 1, filePath));

// Create symbol table
symbolTable = std::make_shared<SymbolTable>(nullptr, SCOPE_GLOBAL, parent == nullptr, true);
Expand Down
3 changes: 1 addition & 2 deletions src/exception/AntlrThrowingErrorListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@

void AntlrThrowingErrorListener::syntaxError(antlr4::Recognizer *recognizer, antlr4::Token *offendingSymbol, size_t line,
size_t charPositionInLine, const std::string &msg, std::exception_ptr e) {
CodeLoc codeLoc = CodeLoc("", line, charPositionInLine);
throw LexerParserError(codeLoc, mode == LEXER ? TOKENIZING_FAILED : PARSING_FAILED, msg);
throw LexerParserError(CodeLoc(line, charPositionInLine), mode == LEXER ? TOKENIZING_FAILED : PARSING_FAILED, msg);
}
Loading

0 comments on commit d4b0554

Please sign in to comment.