Skip to content
Closed
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
26 changes: 14 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name: build-cpp

on:
push:
pull_request:

push:
branches: [compile]
pull_request:
branches: [compile]
jobs:
build:
compile:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
Expand All @@ -15,20 +16,21 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install compiler (Linux)
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update && sudo apt-get install -y g++
# - name: Install compiler (Linux)
# if: matrix.os == 'ubuntu-latest'
#run: sudo apt-get update && sudo apt-get install -y g++

- name: Compile
run: |
if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then
g++ cppsp_compiler.cpp -Os -s -std=c++17 -o cppsp_compiler_linux
if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then
g++ cppsp_compiler.cpp -Os -s -std=c++17 -o cppsp_compiler_linux -static
else
clang++ cppsp_compiler.cpp -Os -s -std=c++17 -o cppsp_compiler_mac
fi
clang++ cppsp_compiler.cpp -Os -std=c++17 -o cppsp_compiler_mac
fi


- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-binary
name: ${{ matrix.os }}-binary
path: cppsp_compiler_*
24 changes: 17 additions & 7 deletions cppsp_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
#include <cstdlib>
#include <unordered_map>
#include <functional>

bool isWindows=false;bool isMac=false;bool isLinux =false;
#if defined(_WIN32) || defined(_WIN64)
#define isWindows 1
#elif defined(__APPLE__) && defined(__MACH__)
#define isMac 1
#elif defined(__linux__)
#define isLinux 1
#endif
//檢查dll依賴:objdump -p cppsp_compiler.exe | findstr ".dll"

namespace fs = std::filesystem;
Expand Down Expand Up @@ -200,16 +207,18 @@ std::string parseIni(const std::string& path, const std::string& flag) {
std::ifstream infile(path);
if (!infile) return "";

std::string line;
std::getline(infile, line);
std::string line;
std::string result;
while(std::getline(infile, line)){
std::stringstream ss(line);
std::string token;
std::string result;
while (std::getline(ss, token, ',')) {
if (!token.empty()) {
result += flag + "\"" + token + "\" ";
result += flag+ "\"" + token + "\" ";
}
}

}
return result;
}
// 判斷字串是否為布林值
Expand Down Expand Up @@ -248,6 +257,7 @@ int main(int argc, char* argv[]) {
double iorf = std::stod(cur);
if (iorf == (int)iorf) out += "{ int _t = " + cur + "; printf(\"%d\", _t); }\n";
else out += "{ double _t = " + cur + "; printf(\"%g\", _t); }\n"; }
else if(cur[0]== 'L') out +=(Ifiostream)? "std::wcout<<"+cur+";\n" :"wprintf("+cur+");\n";
else if(Ifiostream==true) out +="std::cout<<"+cur+";\n";
else { out += "printf(" + cur + ");\n";}
}
Expand Down Expand Up @@ -367,8 +377,8 @@ if (!comment && importline.find("import ") != std::string::npos) {
outfile << "\nreturn 0;\n}\n";
if(enableoverwrite) outfile << "*/";
outfile.close();

fs::path exePath = cpsPath.parent_path() / (cpsPath.stem().string() );// .exe後綴 : + ".exe");
std::string local=(isMac || isLinux)? "./":"";
fs::path exePath = cpsPath.parent_path() / (local+cpsPath.stem().string() );// .exe後綴 : + ".exe");

// 讀 include.ini 和 lib.ini
std::string includeFlags = parseIni("include.ini", "-I");
Expand Down
Binary file modified cppsp_compiler.exe
Binary file not shown.