include Update

This commit is contained in:
mmichlol
2026-02-07 11:57:44 +01:00
parent e250b2f5fb
commit 9bbf8435c6
4 changed files with 26 additions and 30 deletions

View File

@@ -4,14 +4,22 @@
#include <vector>
#include <cstdlib>
#include <filesystem>
#include <windows.h>
#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";

View File

@@ -17,7 +17,7 @@ std::string loadFileContent(const std::string& path) {
return std::string((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
}
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";
}
}

View File

@@ -2,10 +2,7 @@
#define PREPROCESSOR_H
#include <string>
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

View File

@@ -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 <main.pcc>` or your own files `#include "myfile.pcc`.
- **include files**: you can include base files from compiler `#include <main.pcc>` 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.