diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index b7911cf..548ae74 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -23,8 +23,8 @@ on:
- '**'
jobs:
- build_on_linux:
- name: Build on Linux
+ build_and_test_on_linux:
+ name: Build and Test on Linux
runs-on: ${{ matrix.os }}
strategy:
matrix:
@@ -48,14 +48,14 @@ jobs:
run: |
sudo wget https://apt.llvm.org/llvm.sh
sudo chmod +x llvm.sh
- sudo ./llvm.sh 11
+ sudo ./llvm.sh
sudo apt-get -y install uuid-dev pkg-config doxygen graphviz
- name: Install Antlr4 and Antlr4 Runtime
if: steps.cache-antlr.outputs.cache-hit != 'true'
run: |
sudo mkdir -p thirdparty/antlr && cd thirdparty/antlr
- sudo wget https://www.antlr.org/download/antlr-4.9-complete.jar
- sudo wget -O ${{ runner.temp }}/antlr4-src.zip https://www.antlr.org/download/antlr4-cpp-runtime-4.9-source.zip
+ sudo wget https://www.antlr.org/download/antlr-4.9.2-complete.jar
+ sudo wget -O ${{ runner.temp }}/antlr4-src.zip https://www.antlr.org/download/antlr4-cpp-runtime-4.9.2-source.zip
cd ${{ runner.temp }}
sudo unzip antlr4-src.zip
sudo mkdir build && cd build
@@ -74,30 +74,18 @@ jobs:
cd cmake-build-debug
sudo cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-w" -G "Unix Makefiles" ..
sudo cmake --build . --target staticscript document -- -j $THREAD_COUNT
+ sudo ctest --extra-verbose
cd ../cmake-build-release
sudo cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-w" -G "Unix Makefiles" ..
sudo cmake --build . --target staticscript document -- -j $THREAD_COUNT
- - name: Upload Debug File
- uses: actions/upload-artifact@v2
- with:
- name: staticscript-${{ matrix.os }}-${{ matrix.compiler.cc }}-debug
- path: |
- cmake-build-debug/staticscript
- cmake-build-debug/lib/*.bc
- - name: Upload Release File
- uses: actions/upload-artifact@v2
- with:
- name: staticscript-${{ matrix.os }}-${{ matrix.compiler.cc }}-release
- path: |
- cmake-build-release/staticscript
- cmake-build-release/lib/*.bc
+ sudo ctest --extra-verbose
- build_on_macos:
- name: Build on macOS
+ build_and_test_on_macos:
+ name: Build and Test on macOS
runs-on: ${{ matrix.os }}
strategy:
matrix:
- os: [ macos-10.15, macos-11.0 ]
+ os: [ macos-10.15 ]
compiler:
- { cc: gcc, cxx: g++ }
- { cc: clang, cxx: clang++ }
@@ -116,70 +104,8 @@ jobs:
cd cmake-build-debug
sudo cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-w" -G "Unix Makefiles" ..
sudo cmake --build . --target staticscript document -- -j $THREAD_COUNT
+ sudo ctest --extra-verbose
cd ../cmake-build-release
sudo cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-w" -G "Unix Makefiles" ..
sudo cmake --build . --target staticscript document -- -j $THREAD_COUNT
- - name: Upload Debug File
- uses: actions/upload-artifact@v2
- with:
- name: staticscript-${{ matrix.os }}-${{ matrix.compiler.cc }}-debug
- path: |
- cmake-build-debug/staticscript
- cmake-build-debug/lib/*.bc
- - name: Upload Release File
- uses: actions/upload-artifact@v2
- with:
- name: staticscript-${{ matrix.os }}-${{ matrix.compiler.cc }}-release
- path: |
- cmake-build-release/staticscript
- cmake-build-release/lib/*.bc
-
- test:
- name: Test
- needs: [ build_on_linux, build_on_macos ]
- runs-on: ${{ matrix.os }}
- strategy:
- matrix:
- os: [ ubuntu-18.04, ubuntu-20.04, macos-10.15, macos-11.0 ]
- compiler:
- - { cc: gcc, cxx: g++ }
- - { cc: clang, cxx: clang++ }
- steps:
- - name: Fetch Codebase
- uses: actions/checkout@v2
- - name: Download Debug File
- uses: actions/download-artifact@v2
- with:
- name: staticscript-${{ matrix.os }}-${{ matrix.compiler.cc }}-debug
- path: executables/debug
- - name: Download Release File
- uses: actions/download-artifact@v2
- with:
- name: staticscript-${{ matrix.os }}-${{ matrix.compiler.cc }}-release
- path: executables/release
- - name: Test Exmaple Code on Debug Compiler
- working-directory: executables/debug
- run: |
- chmod +x ./staticscript
- for file in ${{ github.workspace }}/tests/*.ss
- do
- base=$(basename $file)
- sudo ./staticscript $file -L lib --emit-llvm -o $base.ll
- sudo ./staticscript $file -L lib -c -o $base.o
- sudo ./staticscript $file -L lib -o $base.exe
- sudo clang $base.o -lm -o $base.exe
- sudo ./$base.exe
- done
- - name: Test Exmaple Code on Release Compiler
- working-directory: executables/release
- run: |
- chmod +x ./staticscript
- for file in ${{ github.workspace }}/tests/*.ss
- do
- base=$(basename $file)
- sudo ./staticscript $file -L lib --emit-llvm -o $base.ll
- sudo ./staticscript $file -L lib -c -o $base.o
- sudo ./staticscript $file -L lib -o $base.exe
- sudo clang $base.o -lm -o $base.exe
- sudo ./$base.exe
- done
\ No newline at end of file
+ sudo ctest --extra-verbose
\ No newline at end of file
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index f55c7ca..deb2f67 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -25,14 +25,14 @@ jobs:
run: |
sudo wget https://apt.llvm.org/llvm.sh
sudo chmod +x llvm.sh
- sudo ./llvm.sh 11
+ sudo ./llvm.sh
sudo apt-get -y install uuid-dev pkg-config doxygen graphviz
- name: Install Antlr4 and Antlr4 Runtime
if: steps.cache-antlr.outputs.cache-hit != 'true'
run: |
sudo mkdir -p thirdparty/antlr && cd thirdparty/antlr
- sudo wget https://www.antlr.org/download/antlr-4.9-complete.jar
- sudo wget -O ${{ runner.temp }}/antlr4-src.zip https://www.antlr.org/download/antlr4-cpp-runtime-4.9-source.zip
+ sudo wget https://www.antlr.org/download/antlr-4.9.2-complete.jar
+ sudo wget -O ${{ runner.temp }}/antlr4-src.zip https://www.antlr.org/download/antlr4-cpp-runtime-4.9.2-source.zip
cd ${{ runner.temp }}
sudo unzip antlr4-src.zip
sudo mkdir build && cd build
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c420c46..a139901 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -44,4 +44,8 @@ add_executable(
add_dependencies(staticscript antlr4_static)
-target_link_libraries(staticscript PRIVATE antlr4_static ${llvm_libs})
\ No newline at end of file
+target_link_libraries(staticscript PRIVATE antlr4_static ${llvm_libs})
+
+enable_testing()
+
+add_subdirectory(tests)
\ No newline at end of file
diff --git a/README-zh_CN.md b/README-zh_CN.md
index dacadf8..e9ae58c 100644
--- a/README-zh_CN.md
+++ b/README-zh_CN.md
@@ -2,7 +2,7 @@
-StaticScript是一门类TypeScript的静态强类型编程语言
+StaticScript是一门类TypeScript的静态编译型语言


@@ -60,7 +60,7 @@ sudo /bin/bash install-macos.sh
## 使用
-首先你编写像下面这样一个合法的StaticScript代码文件
+首先编写像下面这样一个合法的StaticScript代码文件
```typescript
// test.ss
diff --git a/README.md b/README.md
index b6e6424..258f5e2 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
-StaticScript is a statically typed and strongly typed programming language, syntactically like TypeScript.
+StaticScript is a statically typed programming language, syntactically like TypeScript.


diff --git a/cmake/AddANTLR.cmake b/cmake/AddANTLR.cmake
index 296bfdd..8d6bce9 100644
--- a/cmake/AddANTLR.cmake
+++ b/cmake/AddANTLR.cmake
@@ -1,9 +1,9 @@
list(APPEND CMAKE_PREFIX_PATH /usr/local/lib/cmake/antlr4)
if (CMAKE_HOST_SYSTEM_NAME STREQUAL Linux)
- set(ANTLR4_JAR_LOCATION ${PROJECT_SOURCE_DIR}/thirdparty/antlr/antlr-4.9-complete.jar)
+ set(ANTLR4_JAR_LOCATION ${PROJECT_SOURCE_DIR}/thirdparty/antlr/antlr-4.9.2-complete.jar)
elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin)
- set(ANTLR4_JAR_LOCATION /usr/local/opt/antlr/antlr-4.9-complete.jar)
+ set(ANTLR4_JAR_LOCATION /usr/local/opt/antlr/antlr-4.9.2-complete.jar)
endif ()
find_package(antlr4-runtime REQUIRED)
diff --git a/cmake/AddLLVM.cmake b/cmake/AddLLVM.cmake
index e1ef7ee..76a6ba8 100644
--- a/cmake/AddLLVM.cmake
+++ b/cmake/AddLLVM.cmake
@@ -2,7 +2,7 @@ if (CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin)
list(APPEND CMAKE_PREFIX_PATH /usr/local/opt/llvm/lib/cmake/llvm)
endif ()
-find_package(LLVM 11 REQUIRED CONFIG)
+find_package(LLVM 12 REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
diff --git a/include/Support/LLVM.h b/include/Support/LLVM.h
index 1e899d9..1db3e20 100644
--- a/include/Support/LLVM.h
+++ b/include/Support/LLVM.h
@@ -65,39 +65,19 @@ inline void initLLVMTarget() {
inline void initLLVMPasses() {
llvm::PassRegistry ®istry = *llvm::PassRegistry::getPassRegistry();
llvm::initializeCore(registry);
- llvm::initializeCoroutines(registry);
+ llvm::initializeTransformUtils(registry);
llvm::initializeScalarOpts(registry);
llvm::initializeObjCARCOpts(registry);
llvm::initializeVectorization(registry);
- llvm::initializeIPO(registry);
- llvm::initializeAnalysis(registry);
- llvm::initializeTransformUtils(registry);
llvm::initializeInstCombine(registry);
llvm::initializeAggressiveInstCombine(registry);
+ llvm::initializeIPO(registry);
llvm::initializeInstrumentation(registry);
+ llvm::initializeAnalysis(registry);
+ llvm::initializeCoroutines(registry);
+ llvm::initializeCodeGen(registry);
+ llvm::initializeGlobalISel(registry);
llvm::initializeTarget(registry);
- llvm::initializeExpandMemCmpPassPass(registry);
- llvm::initializeScalarizeMaskedMemIntrinPass(registry);
- llvm::initializeCodeGenPreparePass(registry);
- llvm::initializeAtomicExpandPass(registry);
- llvm::initializeRewriteSymbolsLegacyPassPass(registry);
- llvm::initializeWinEHPreparePass(registry);
- llvm::initializeDwarfEHPreparePass(registry);
- llvm::initializeSafeStackLegacyPassPass(registry);
- llvm::initializeSjLjEHPreparePass(registry);
- llvm::initializePreISelIntrinsicLoweringLegacyPassPass(registry);
- llvm::initializeGlobalMergePass(registry);
- llvm::initializeIndirectBrExpandPassPass(registry);
- llvm::initializeInterleavedLoadCombinePass(registry);
- llvm::initializeInterleavedAccessPass(registry);
- llvm::initializeEntryExitInstrumenterPass(registry);
- llvm::initializePostInlineEntryExitInstrumenterPass(registry);
- llvm::initializeUnreachableBlockElimLegacyPassPass(registry);
- llvm::initializeExpandReductionsPass(registry);
- llvm::initializeWasmEHPreparePass(registry);
- llvm::initializeWriteBitcodePassPass(registry);
- llvm::initializeHardwareLoopsPass(registry);
- llvm::initializeTypePromotionPass(registry);
}
inline void initLLVMCodeGen() {
@@ -118,7 +98,7 @@ inline llvm::CodeGenOpt::Level getCodeGenOptLevel(unsigned optLevel = 2) {
}
inline String getTargetTriple() {
- return llvm::sys::getDefaultTargetTriple();
+ return llvm::sys::getProcessTriple();
}
inline llvm::TargetMachine *getTargetMachine(unsigned optLevel = 2) {
@@ -129,7 +109,7 @@ inline llvm::TargetMachine *getTargetMachine(unsigned optLevel = 2) {
return target->createTargetMachine(targetTriple,
llvm::codegen::getCPUStr(),
llvm::codegen::getFeaturesStr(),
- llvm::codegen::InitTargetOptionsFromCodeGenFlags(),
+ llvm::codegen::InitTargetOptionsFromCodeGenFlags(llvm::Triple(targetTriple)),
llvm::codegen::getExplicitRelocModel(),
llvm::codegen::getExplicitCodeModel(),
getCodeGenOptLevel(optLevel));
diff --git a/install-macos.sh b/install-macos.sh
old mode 100644
new mode 100755
diff --git a/install-ubuntu.sh b/install-ubuntu.sh
old mode 100644
new mode 100755
diff --git a/src/CodeGen/Builtin.cpp b/src/CodeGen/Builtin.cpp
index 6918604..a7b7503 100644
--- a/src/CodeGen/Builtin.cpp
+++ b/src/CodeGen/Builtin.cpp
@@ -55,7 +55,7 @@ void BuiltinError::linkModule(LLVMModule &module, LLVMContext &context) {
}
void BuiltinError::getTypeAndFunction(LLVMModule &module) {
- llvm::StructType *errStructType = module.getTypeByName("struct.ss_error");
+ llvm::StructType *errStructType = llvm::StructType::getTypeByName(module.getContext(), "struct.ss_error");
type = errStructType->getPointerTo();
exitIfErrorFunc = module.getFunction("ss_exit_if_error");
assertFunc = module.getFunction("ss_assert");
@@ -66,7 +66,7 @@ void BuiltinString::linkModule(LLVMModule &module, LLVMContext &context) {
}
void BuiltinString::getTypeAndFunction(LLVMModule &module) {
- llvm::StructType *strStructType = module.getTypeByName("struct.ss_string");
+ llvm::StructType *strStructType = llvm::StructType::getTypeByName(module.getContext(), "struct.ss_string");
type = strStructType->getPointerTo();
createFunc = module.getFunction("ss_string_create");
deleteFunc = module.getFunction("ss_string_delete");
@@ -87,7 +87,7 @@ void BuiltinArray::linkModule(LLVMModule &module, LLVMContext &context) {
}
void BuiltinArray::getTypeAndFunction(LLVMModule &module) {
- llvm::StructType *arrStructType = module.getTypeByName("struct.ss_array");
+ llvm::StructType *arrStructType = llvm::StructType::getTypeByName(module.getContext(), "struct.ss_array");
type = arrStructType->getPointerTo();
createIntegerArrayFunc = module.getFunction("ss_array_create_integer_array");
createFloatArrayFunc = module.getFunction("ss_array_create_float_array");
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 0000000..befe0a8
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1,11 @@
+file(GLOB TEST_CASES_FILE *.ss)
+
+set(LINK_LIBRARY_PATH ${PROJECT_BINARY_DIR}/lib)
+
+foreach(filepath ${TEST_CASES_FILE})
+ string(REGEX REPLACE ".+/(.+)\\..*" "\\1" filename ${filepath})
+ add_test(
+ NAME test_${filename}
+ COMMAND staticscript ${filepath} -L ${LINK_LIBRARY_PATH}
+ )
+endforeach()
\ No newline at end of file