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

Finish bootstrap lexer #391

Merged
merged 12 commits into from
Dec 16, 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 @@ -60,14 +60,14 @@ jobs:
uses: actions/cache@v3
with:
path: /home/runner/work/spice/llvm
key: llvm-17.0.5
key: llvm-17.0.6

- name: Setup LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
cd ..
rm -rf llvm
git clone --depth 1 --branch llvmorg-17.0.5 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-17.0.6 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.5
key: llvm-17.0.6

- 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.5 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-17.0.6 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.5-linux-x64
key: llvm-17.0.6-linux-x64

- name: Setup LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
git clone --depth 1 --branch llvmorg-17.0.5 https://github.com/llvm/llvm-project.git llvm
git clone --depth 1 --branch llvmorg-17.0.6 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.5-linux-aarch64
key: llvm-17.0.6-linux-aarch64

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

- name: Setup LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
git clone --depth 1 --branch llvmorg-17.0.5 https://github.com/llvm/llvm-project.git llvm
git clone --depth 1 --branch llvmorg-17.0.6 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 -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">
<configuration default="false" name="spice" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="run -O3 -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">
<envs>
<env name="LLVM_LIB_DIR" value="D:/LLVM/build-release/lib" />
<env name="LLVM_INCLUDE_DIR" value="D:/LLVM/llvm/include" />
Expand Down
2 changes: 1 addition & 1 deletion dev-setup.bat
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ echo done.

REM - Clone LLVM
echo [Step 2] Cloning LLVM (Could take a while) ...
git clone --depth 1 --branch llvmorg-17.0.5 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-17.0.6 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-17.0.5 https://github.com/llvm/llvm-project llvm
git clone --depth 1 --branch llvmorg-17.0.6 https://github.com/llvm/llvm-project llvm
colored_echo "done."

# Build LLVM
Expand Down
106 changes: 48 additions & 58 deletions media/test-project/test.spice
Original file line number Diff line number Diff line change
@@ -1,68 +1,58 @@
/*ext f<byte*> fopen(string, string);
ext f<int> fclose(byte*);
ext f<int> fputc(int, byte*);
ext f<int> fputs(string, byte*);
type IASTNode interface {
p accept();
f<string> getName();
}

f<int> main() {
byte* file = fopen("./test-file.txt", "w");
fputs("Hello World!", file);
fclose(file);
}*/
type ASTNode struct : IASTNode {

}

import "std/io/file";
import "std/type/result";
p ASTNode.ctor() {}

p ASTNode.accept() {

f<int> main() {
Result<File> res = openFile("test-file.txt", MODE_WRITE);
assert res.isOk();
File file = res.unwrap();
file.write("test");
file.close();
}

/*import "../../src-bootstrap/reader/reader";
f<string> ASTNode.getName() {
return "ASTNode";
}

f<int> main() {
Reader reader = Reader("./test-file.txt");
type ASTEntryNode struct : IASTNode {
compose ASTNode base
}

printf("%d", reader.isEOF());
while !reader.isEOF() {
printf("%c", reader.getChar());
reader.advance();
}
}*/
p ASTEntryNode.ctor() {}

/*import "std/io/file";
p ASTEntryNode.accept() {

}

f<string> ASTEntryNode.getName() {
return "ASTEntryNode";
}

type ASTFctDefNode struct : IASTNode {
compose ASTNode base
}

p ASTFctDefNode.ctor() {}

p ASTFctDefNode.accept() {

}

f<string> ASTFctDefNode.getName() {
return "ASTFctDefNode";
}

f<int> main() {
// Write file
Result<File> fileResult = openFile("./test-file.txt", MODE_WRITE);
assert fileResult.isOk();
File file = fileResult.unwrap();
file.write("Hello, world!\n");
file.close();

// Read file
fileResult = openFile("./test-file.txt", MODE_READ);
assert fileResult.isOk();
file = fileResult.unwrap();
String line = file.readLine();
printf("%s", line);
assert line.getRaw() == "Hello, world!\n";
file.close();

// Append file
fileResult = openFile("./test-file.txt", MODE_APPEND);
assert fileResult.isOk();
file = fileResult.unwrap();
file.write("Hello, again!\n");
file.close();

// Read file
fileResult = openFile("./test-file.txt", MODE_READ);
assert fileResult.isOk();
file = fileResult.unwrap();
assert file.readLine() == String("Hello, world!\n");
assert file.readLine() == String("Hello, again!\n");
file.close();
}*/
IASTNode node1 = ASTEntryNode();
IASTNode node2 = ASTNode();
IASTNode node3 = ASTFctDefNode();
IASTNode* node1Ptr = &node1;
IASTNode* node2Ptr = &node2;
IASTNode* node3Ptr = &node3;
printf("%s\n", node2Ptr.getName());
printf("%s\n", node3Ptr.getName());
printf("%s\n", node1Ptr.getName());
}
17 changes: 3 additions & 14 deletions media/test-project/test2.spice
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
import "std/type/result";
import "std/type/error";
import "test3" as s2;

type FilePtr alias byte*;
public type File struct {
FilePtr* filePtr
}

// Link external functions
ext f<FilePtr*> fopen(string, string);

public f<Result<File>> openFile(string path, string mode) {
FilePtr* fp = fopen(path, mode);
File file = File{fp};
return fp != nil<FilePtr*> ? ok(file) : err(file, Error("Failed to open file"));
p test() {
printf("p: %f", s2.getDouble());
}
6 changes: 4 additions & 2 deletions media/test-project/test3.spice
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
public f<int> dummy() {
return 3;
import "test" as s;

p test() {
printf("p: %f", s.getDouble());
}
2 changes: 1 addition & 1 deletion src-bootstrap/ast/ast-nodes.spice
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "std/data/Vector";
// Own imports
import "../ast/abstract-ast-visitor";
import "../reader/code-loc";
import "../symbol/symbol-type";
import "../symboltablebuilder/symbol-type";

/**
* Saves a constant value for an AST node to realize features like array-out-of-bounds checks
Expand Down
Loading