From 99b9ae450e706487deb7aa9ce8d238f0921029dd Mon Sep 17 00:00:00 2001 From: mmichlol Date: Sat, 7 Feb 2026 14:02:42 +0100 Subject: [PATCH] Keyboard and Input Update --- PCCcompiler/codegen.cpp | 22 +++++++++++++++++++--- README.md | 27 --------------------------- 2 files changed, 19 insertions(+), 30 deletions(-) delete mode 100644 README.md diff --git a/PCCcompiler/codegen.cpp b/PCCcompiler/codegen.cpp index 5d65c71..0e4fa6e 100644 --- a/PCCcompiler/codegen.cpp +++ b/PCCcompiler/codegen.cpp @@ -41,6 +41,7 @@ std::string generateAssembly(const CompilerState& state) { result += "global main\n"; result += "extern printf\n"; result += "extern getchar\n"; + result += "extern _getch\n"; // ZMIANA: Dodajemy _getch (zamiast lub obok getchar) result += "section .data\n"; result += " fmt db '%d', 10, 0\n"; result += "section .data\n"; @@ -186,7 +187,10 @@ std::string generateAssembly(const CompilerState& state) { } case OpType::RETURN: { std::string val = getVarLocation(instr.arg1, stackMap); - result += " mov eax, " + val + " ; return value\n"; + if (val.empty() || val == ";"); + else { + result += " mov eax, " + val + " ; return value\n"; + } result += " leave\n"; result += " ret\n"; break; @@ -209,9 +213,21 @@ std::string generateAssembly(const CompilerState& state) { // Parsowanie argumentów std::string argsRaw = instr.arg2; std::vector callArgs; + // --- SPECJALNE FUNKCJE SYSTEMOWE --- + + // 1. input() - czeka na ENTER (stare) if (instr.arg1 == "input") { - result += " call getchar\n"; // Czeka na enter - break; // Wychodzimy, żeby nie robić standardowego call + result += " call getchar\n"; + break; + } + + // 2. read_key() - zwraca kod wciśniętego klawisza (NOWOŚĆ) + if (instr.arg1 == "read_key") { + result += " call _getch\n"; // Zwraca kod znaku w EAX + // Jeśli to klawisz specjalny (strzałki), _getch zwraca 0 lub 224, + // a potem trzeba wywołać go drugi raz. + // Na razie zróbmy prosto: zwracamy to co zwrócił pierwszy _getch. + break; } if (!argsRaw.empty()) { size_t comma = argsRaw.find(','); diff --git a/README.md b/README.md deleted file mode 100644 index 7052b9f..0000000 --- a/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# PCC Compiler (My C++ Compiler) - -![Version](https://img.shields.io/badge/version-0.0.3-blue.svg) -![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"`. -- **Control Flow**: `if` statements support. -- **Functions**: Define and call `void` functions. -- **Native Compilation**: Compiles directly to x64 machine code. - -## 🛠️ Usage -1. Download the latest release from the [Releases](../../releases) page. -2. Unzip the archive to C:/PCC/ -3. Run `start.bat` as Administrator. -4. Compile your code: `PCC.exe code.pcc`. - ---- -*Created by MichaĹ‚ Lewandowski*