From 9bbf8435c61315d09df03168c394019ba1bac71f Mon Sep 17 00:00:00 2001 From: mmichlol Date: Sat, 7 Feb 2026 11:57:44 +0100 Subject: [PATCH] include Update --- PCCcompiler/main.cpp | 24 +++++++++++++++--------- PCCcompiler/preprocessor.cpp | 22 ++++++---------------- PCCcompiler/preprocessor.h | 5 +---- README.md | 5 ++++- 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/PCCcompiler/main.cpp b/PCCcompiler/main.cpp index fdb949f..7e84a52 100644 --- a/PCCcompiler/main.cpp +++ b/PCCcompiler/main.cpp @@ -4,14 +4,22 @@ #include #include #include +#include #include "compiler_types.h" #include "parser.h" #include "codegen.h" #include "preprocessor.h" +std::string getExecutablePath() { + char buffer[MAX_PATH]; + GetModuleFileNameA(NULL, buffer, MAX_PATH); + std::string::size_type pos = std::string(buffer).find_last_of("\\/"); + return std::string(buffer).substr(0, pos); +} + int main(int argc, char* argv[]) { std::string inputFile, outputName; - std::string Version = "v0.0.3-beta"; // ZaktualizowaÅ‚em wersjÄ™ :) + std::string Version = "v0.0.5-beta"; bool showHelp = false, showVersion = false, showCredits = false; // --- PARSOWANIE ARGUMENTÓW --- @@ -77,17 +85,15 @@ int main(int argc, char* argv[]) { // --- PREPROCESSOR START --- std::cout << "[INFO] Preprocessing...\n"; + // 1. Åšcieżka projektu (tam gdzie plik wejÅ›ciowy) std::filesystem::path p(inputFile); - std::string basePath = p.parent_path().string(); + std::string projectDir = p.parent_path().string(); - // Uruchamiamy preprocesor - podmieni #include na kod - src = preprocessSource(src, basePath); + // 2. Åšcieżka kompilatora (tam gdzie PCC.exe i folder std) + std::string compilerDir = getExecutablePath(); - // Opcjonalnie: pokaż kod po złączeniu (do debugowania) - // std::cout << "--- FINAL CODE ---\n" << src << "\n------------------\n"; - // --- PREPROCESSOR END --- - - // --- LOGIKA KOMPILATORA (DALEJ BEZ ZMIAN) --- + // Uruchamiamy z obiema Å›cieżkami + src = preprocessSource(src, projectDir, compilerDir); CompilerState state; std::cout << "[INFO] Parsing code...\n"; diff --git a/PCCcompiler/preprocessor.cpp b/PCCcompiler/preprocessor.cpp index c4fa84c..e3b4d34 100644 --- a/PCCcompiler/preprocessor.cpp +++ b/PCCcompiler/preprocessor.cpp @@ -17,7 +17,7 @@ std::string loadFileContent(const std::string& path) { return std::string((std::istreambuf_iterator(in)), std::istreambuf_iterator()); } -std::string preprocessSource(const std::string& src, const std::string& basePath) { +std::string preprocessSource(const std::string& src, const std::string& projectDir, const std::string& compilerDir) { std::istringstream iss(src); std::string line; std::stringstream output; @@ -53,26 +53,17 @@ std::string preprocessSource(const std::string& src, const std::string& basePath if (!includePath.empty()) { std::string fullPath; if (isStdLib) { - // Biblioteka standardowa: szukamy w folderze "std" obok exe/projektu - // U¿ywamy current_path() + "std" - fullPath = "std/" + includePath; + fullPath = compilerDir + "/std/" + includePath; std::cout << "[PREPROCESSOR] Including STD lib: " << fullPath << "\n"; } else { - // Plik lokalny: szukamy w tym samym folderze co plik Ÿród³owy - // Jeœli basePath jest pusty, szukamy lokalnie - if (basePath.empty()) fullPath = includePath; - else fullPath = basePath + "/" + includePath; + // Plik lokalny: Szukamy w folderze projektu + if (projectDir.empty()) fullPath = includePath; + else fullPath = projectDir + "/" + includePath; std::cout << "[PREPROCESSOR] Including local file: " << fullPath << "\n"; } - - // Wczytujemy plik i REKURENCYJNIE go przetwarzamy - // (bo plik do³¹czany mo¿e mieæ swoje include!) std::string content = loadFileContent(fullPath); - - // Dla uproszczenia rekurencji w include'ach lokalnych, przekazujemy ten sam basePath - // W idealnym œwiecie powinniœmy braæ folder nowego pliku. - std::string processedContent = preprocessSource(content, basePath); + std::string processedContent = preprocessSource(content, projectDir, compilerDir); output << "\n// --- BEGIN INCLUDE: " << includePath << " ---\n"; output << processedContent; @@ -80,7 +71,6 @@ std::string preprocessSource(const std::string& src, const std::string& basePath } } else { - // Zwyk³a linia kodu - przepisujemy bez zmian output << line << "\n"; } } diff --git a/PCCcompiler/preprocessor.h b/PCCcompiler/preprocessor.h index 51cabe6..10d129a 100644 --- a/PCCcompiler/preprocessor.h +++ b/PCCcompiler/preprocessor.h @@ -2,10 +2,7 @@ #define PREPROCESSOR_H #include +std::string preprocessSource(const std::string& src, const std::string& projectDir, const std::string& compilerDir); -// G³ówna funkcja preprocesora. -// src: kod Ÿród³owy g³ównego pliku -// basePath: œcie¿ka do folderu, w którym jest g³ówny plik (¿eby wiedzieæ sk¹d braæ lokalne include) -std::string preprocessSource(const std::string& src, const std::string& basePath); #endif diff --git a/README.md b/README.md index 91b053d..7052b9f 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,15 @@ ![Status](https://img.shields.io/badge/status-BETA-orange.svg) ![Platform](https://img.shields.io/badge/platform-Windows%20x64-lightgrey.svg) +## Docs +https://nodrop.xyz/docs/docs.html + **PCC Compiler** is a custom programming language compiler built from scratch in C++. It translates PCC code into x64 Assembly (NASM), which is then linked into a standalone Windows executable. ## 🚀 Features - **Custom Syntax**: C-like syntax easy for beginners. - **Variables**: Support for `int`, `bool` and `string`. -- **include files**: you can include base files from compiler `#include ` or your own files `#include "myfile.pcc`. +- **include files**: you can include base files from compiler `#include ` or your own files `#include "myfile.pcc"`. - **Control Flow**: `if` statements support. - **Functions**: Define and call `void` functions. - **Native Compilation**: Compiles directly to x64 machine code.