Bug Fix
This commit is contained in:
@@ -69,7 +69,7 @@ std::string generateAssembly(const CompilerState& state) {
|
||||
|
||||
result += " push rbp\n";
|
||||
result += " mov rbp, rsp\n";
|
||||
result += " sub rsp, 256\n";
|
||||
result += " sub rsp, 288\n";
|
||||
|
||||
std::map<std::string, int> stackMap;
|
||||
int currentStack = 8;
|
||||
@@ -134,7 +134,7 @@ std::string generateAssembly(const CompilerState& state) {
|
||||
result += " mov rax, [rdx]\n";
|
||||
|
||||
// Zapisujemy do zmiennej docelowej
|
||||
result += " mov " + dst + ", rax\n"; // Lub eax, zale¿y jak masz
|
||||
result += " mov " + dst + ", rax\n";
|
||||
}
|
||||
else if (instr.arg3 == "STRING") {
|
||||
// Przypisanie stringa: ³adujemy ADRES (LEA)
|
||||
@@ -276,7 +276,8 @@ std::string generateAssembly(const CompilerState& state) {
|
||||
std::string cond = getVarLocation(condRaw, stackMap);
|
||||
result += " mov eax, " + cond + "\n";
|
||||
result += " test eax, eax\n";
|
||||
result += " jz " + instr.arg1 + "\n";
|
||||
result += " je " + instr.arg1 + "\n";
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -316,18 +317,6 @@ std::string generateAssembly(const CompilerState& state) {
|
||||
result += " mov rax, " + valLoc + "\n"; // Zak³adamy 64-bit (lub eax dla 32)
|
||||
}
|
||||
|
||||
// 2. Obliczamy adres elementu tablicy
|
||||
// Adres = [rbp - offset_bazowy - (index * 8)]
|
||||
// U nas stackMap trzyma offset_bazowy.
|
||||
// Poniewa¿ stos roœnie w DÓ£, a my rezerwowaliœmy w DÓ£:
|
||||
// t[0] -> offset
|
||||
// t[1] -> offset + 8
|
||||
// Czekaj, rbp-8, rbp-16...
|
||||
// Im wiêkszy offset w stackMap, tym ni¿ej w pamiêci.
|
||||
// stackMap["t"] = 8. [rbp-8].
|
||||
// t[1] powinno byæ [rbp-16].
|
||||
// Czyli Wzór: [rbp - (base_offset + index*8)]
|
||||
|
||||
int baseOffset = stackMap[arrName];
|
||||
|
||||
// £adujemy indeks do RCX
|
||||
@@ -361,9 +350,10 @@ std::string generateAssembly(const CompilerState& state) {
|
||||
case OpType::PRINT: {
|
||||
// Instrukcja PRINT zwyk³a (liczba)
|
||||
std::string val = getVarLocation(instr.arg1, stackMap);
|
||||
result += " mov edx, " + val + "\n";
|
||||
result += " lea rcx, [rel fmt_int]\n";
|
||||
result += " call printf\n";
|
||||
result += " mov edx, " + val + "\\n";
|
||||
result += " lea rcx, [rel fmt_int]\\n";
|
||||
result += " xor eax, eax\\n"; // <-- DODAJ TO
|
||||
result += " call printf\\n";
|
||||
break;
|
||||
}
|
||||
case OpType::PRINT_STRING: {
|
||||
@@ -371,20 +361,21 @@ std::string generateAssembly(const CompilerState& state) {
|
||||
std::string target = instr.arg1;
|
||||
if (target.find("str_") == 0) {
|
||||
// Litera³: print("tekst")
|
||||
result += " lea rdx, [rel " + target + "]\n";
|
||||
result += " lea rdx, [rel " + target + "]\\n";
|
||||
}
|
||||
else {
|
||||
// Zmienna: print(s) -> s trzyma adres
|
||||
std::string val = getVarLocation(target, stackMap);
|
||||
result += " mov rdx, " + val + "\n";
|
||||
result += " mov rdx, " + val + "\\n";
|
||||
}
|
||||
result += " lea rcx, [rel fmt_str]\n";
|
||||
result += " call printf\n";
|
||||
result += " lea rcx, [rel fmt_str]\\n";
|
||||
result += " xor eax, eax\\n"; // <-- DODAJ TO
|
||||
result += " call printf\\n";
|
||||
break;
|
||||
}
|
||||
case OpType::CALL: {
|
||||
if (instr.arg1 == "input") {
|
||||
result += " call getchar\n";
|
||||
result += " call _getch\n";
|
||||
break;
|
||||
}
|
||||
if (instr.arg1 == "read_key") {
|
||||
|
||||
Reference in New Issue
Block a user