Keyboard and Input Update
This commit is contained in:
@@ -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<std::string> 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(',');
|
||||
|
||||
Reference in New Issue
Block a user