Compare commits
3 Commits
V0.0.7-bet
...
V0.0.9-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d736f2786e | ||
|
|
3916b4ff7a | ||
|
|
c37a122850 |
@@ -37,7 +37,8 @@ std::string getVarLocation(const std::string& name, const std::map<std::string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string generateAssembly(const CompilerState& state) {
|
std::string generateAssembly(const CompilerState& state) {
|
||||||
std::string result;
|
// 1. NAG£ÓWEK I DEKLARACJE EXTERN
|
||||||
|
std::string result = "default rel\n";
|
||||||
result += "global main\n";
|
result += "global main\n";
|
||||||
result += "extern printf\n";
|
result += "extern printf\n";
|
||||||
result += "extern getchar\n";
|
result += "extern getchar\n";
|
||||||
@@ -45,15 +46,22 @@ std::string generateAssembly(const CompilerState& state) {
|
|||||||
result += "extern rand\n";
|
result += "extern rand\n";
|
||||||
result += "extern srand\n";
|
result += "extern srand\n";
|
||||||
result += "extern time\n";
|
result += "extern time\n";
|
||||||
result += "section .data\n";
|
result += "extern MessageBoxA\n";
|
||||||
result += " fmt db '%d', 10, 0\n";
|
|
||||||
result += "section .data\n";
|
|
||||||
result += " fmt_int db '%d', 10, 0\n"; // Format dla liczb
|
|
||||||
result += " fmt_str db '%s', 10, 0\n"; // Format dla stringów
|
|
||||||
|
|
||||||
// --- WYPISYWANIE STRINGÓW ---
|
// 2. SEKCJA DATA (Tylko raz!)
|
||||||
for (const auto& pair : state.stringLiterals) { result += " " + pair.second + " db '" + pair.first + "', 0\n"; }
|
result += "section .data\n";
|
||||||
result += "section .text\n\n";
|
result += " fmt_int db \"%lld\", 10, 0\n"; // Format dla liczb
|
||||||
|
result += " fmt_str db \"%s\", 10, 0\n"; // Format dla stringów
|
||||||
|
|
||||||
|
// Zrzucamy stringi: ETYKIETA db "TRESC", 0
|
||||||
|
for (const auto& p : state.stringLiterals) {
|
||||||
|
// p.first -> Etykieta (np. str_0)
|
||||||
|
// p.second -> TreϾ (np. Hello World)
|
||||||
|
result += " " + p.first + " db \"" + p.second + "\", 0\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. SEKCJA TEXT (Kod programu)
|
||||||
|
result += "section .text\n";
|
||||||
|
|
||||||
for (const auto& pair : state.functions) {
|
for (const auto& pair : state.functions) {
|
||||||
const Function& func = pair.second;
|
const Function& func = pair.second;
|
||||||
@@ -66,7 +74,7 @@ std::string generateAssembly(const CompilerState& state) {
|
|||||||
std::map<std::string, int> stackMap;
|
std::map<std::string, int> stackMap;
|
||||||
int currentStack = 8;
|
int currentStack = 8;
|
||||||
|
|
||||||
// 1. ARGUMENTY
|
// ARGUMENTY FUNKCJI
|
||||||
if (func.args.size() > 0) {
|
if (func.args.size() > 0) {
|
||||||
stackMap[func.args[0]] = currentStack;
|
stackMap[func.args[0]] = currentStack;
|
||||||
result += " mov [rbp-" + std::to_string(currentStack) + "], rcx ; arg " + func.args[0] + "\n";
|
result += " mov [rbp-" + std::to_string(currentStack) + "], rcx ; arg " + func.args[0] + "\n";
|
||||||
@@ -78,18 +86,22 @@ std::string generateAssembly(const CompilerState& state) {
|
|||||||
currentStack += 8;
|
currentStack += 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. INSTRUKCJE
|
// GENEROWANIE INSTRUKCJI
|
||||||
for (const auto& instr : func.instructions) {
|
for (const auto& instr : func.instructions) {
|
||||||
|
|
||||||
// Rezerwacja miejsca dla nowych zmiennych (wynikowych)
|
// Rezerwacja miejsca na stosie
|
||||||
// Dodajemy tu OpType::SUB i OpType::MUL
|
|
||||||
bool isWriteOp = (instr.type == OpType::ASSIGN ||
|
bool isWriteOp = (instr.type == OpType::ASSIGN ||
|
||||||
instr.type == OpType::ADD ||
|
instr.type == OpType::ADD ||
|
||||||
instr.type == OpType::EQ ||
|
instr.type == OpType::EQ ||
|
||||||
instr.type == OpType::SUB ||
|
instr.type == OpType::SUB ||
|
||||||
instr.type == OpType::MUL ||
|
instr.type == OpType::MUL ||
|
||||||
instr.type == OpType::DIV ||
|
instr.type == OpType::DIV ||
|
||||||
instr.type == OpType::MOD);
|
instr.type == OpType::MOD ||
|
||||||
|
instr.type == OpType::LOGIC_AND ||
|
||||||
|
instr.type == OpType::LOGIC_OR ||
|
||||||
|
instr.type == OpType::MSGBOX ||
|
||||||
|
instr.type == OpType::ARRAY_DECLARE ||
|
||||||
|
instr.type == OpType::ARRAY_SET);
|
||||||
|
|
||||||
if (isWriteOp && stackMap.find(instr.arg1) == stackMap.end() && instr.arg1 != "RAX") {
|
if (isWriteOp && stackMap.find(instr.arg1) == stackMap.end() && instr.arg1 != "RAX") {
|
||||||
stackMap[instr.arg1] = currentStack;
|
stackMap[instr.arg1] = currentStack;
|
||||||
@@ -99,15 +111,49 @@ std::string generateAssembly(const CompilerState& state) {
|
|||||||
switch (instr.type) {
|
switch (instr.type) {
|
||||||
case OpType::ASSIGN: {
|
case OpType::ASSIGN: {
|
||||||
std::string src = instr.arg2;
|
std::string src = instr.arg2;
|
||||||
if (instr.arg3 == "STRING") {
|
// ODCZYT TABLICY: x = t[i]
|
||||||
|
if (instr.arg3.find("ARRAY_IDX:") == 0) {
|
||||||
|
std::string indexStr = instr.arg3.substr(10); // Pobierz "i"
|
||||||
|
std::string arrName = instr.arg2; // Pobierz "t"
|
||||||
|
std::string dst = getVarLocation(instr.arg1, stackMap);
|
||||||
|
|
||||||
|
int baseOffset = stackMap[arrName];
|
||||||
|
|
||||||
|
// £adujemy indeks do RCX
|
||||||
|
if (isNumber(indexStr)) result += " mov rcx, " + indexStr + "\n";
|
||||||
|
else result += " mov rcx, " + getVarLocation(indexStr, stackMap) + "\n";
|
||||||
|
|
||||||
|
result += " imul rcx, 8\n"; // index * 8
|
||||||
|
|
||||||
|
// Obliczamy adres
|
||||||
|
result += " mov rdx, rbp\n";
|
||||||
|
result += " sub rdx, " + std::to_string(baseOffset) + "\n";
|
||||||
|
result += " sub rdx, rcx\n";
|
||||||
|
|
||||||
|
// Odczytujemy wartoϾ z tablicy do RAX
|
||||||
|
result += " mov rax, [rdx]\n";
|
||||||
|
|
||||||
|
// Zapisujemy do zmiennej docelowej
|
||||||
|
result += " mov " + dst + ", rax\n"; // Lub eax, zale¿y jak masz
|
||||||
|
}
|
||||||
|
else if (instr.arg3 == "STRING") {
|
||||||
|
// Przypisanie stringa: ³adujemy ADRES (LEA)
|
||||||
result += " lea rax, [rel " + src + "]\n";
|
result += " lea rax, [rel " + src + "]\n";
|
||||||
std::string dst = getVarLocation(instr.arg1, stackMap);
|
std::string dst = getVarLocation(instr.arg1, stackMap);
|
||||||
|
// Zapisujemy adres w zmiennej lokalnej (wskaŸnik 64-bit qword)
|
||||||
result += " mov qword " + dst + ", rax\n";
|
result += " mov qword " + dst + ", rax\n";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// Zwyk³e przypisanie liczby
|
||||||
std::string srcLoc = getVarLocation(instr.arg2, stackMap);
|
std::string srcLoc = getVarLocation(instr.arg2, stackMap);
|
||||||
std::string dst = getVarLocation(instr.arg1, stackMap);
|
std::string dst = getVarLocation(instr.arg1, stackMap);
|
||||||
result += " mov eax, " + srcLoc + "\n";
|
|
||||||
|
if (isNumber(src)) {
|
||||||
|
result += " mov eax, " + src + "\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result += " mov eax, " + srcLoc + "\n";
|
||||||
|
}
|
||||||
result += " mov " + dst + ", eax\n";
|
result += " mov " + dst + ", eax\n";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -122,29 +168,55 @@ std::string generateAssembly(const CompilerState& state) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OpType::SUB: {
|
case OpType::SUB: {
|
||||||
// a = b - c
|
|
||||||
std::string op1 = getVarLocation(instr.arg2, stackMap);
|
std::string op1 = getVarLocation(instr.arg2, stackMap);
|
||||||
std::string op2 = getVarLocation(instr.arg3, stackMap);
|
std::string op2 = getVarLocation(instr.arg3, stackMap);
|
||||||
std::string dst = getVarLocation(instr.arg1, stackMap);
|
std::string dst = getVarLocation(instr.arg1, stackMap);
|
||||||
|
|
||||||
result += " mov eax, " + op1 + "\n";
|
result += " mov eax, " + op1 + "\n";
|
||||||
result += " sub eax, " + op2 + "\n"; // sub = odejmowanie
|
result += " sub eax, " + op2 + "\n";
|
||||||
result += " mov " + dst + ", eax\n";
|
result += " mov " + dst + ", eax\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OpType::MUL: {
|
case OpType::MUL: {
|
||||||
// a = b * c
|
|
||||||
std::string op1 = getVarLocation(instr.arg2, stackMap);
|
std::string op1 = getVarLocation(instr.arg2, stackMap);
|
||||||
std::string op2 = getVarLocation(instr.arg3, stackMap);
|
std::string op2 = getVarLocation(instr.arg3, stackMap);
|
||||||
std::string dst = getVarLocation(instr.arg1, stackMap);
|
std::string dst = getVarLocation(instr.arg1, stackMap);
|
||||||
|
|
||||||
result += " mov eax, " + op1 + "\n";
|
result += " mov eax, " + op1 + "\n";
|
||||||
// Mno¿enie w x86 jest specyficzne: imul eax, operand
|
|
||||||
// Wynik l¹duje w eax (i edx jeœli du¿y, ale ignorujemy nadmiar dla prostoty)
|
|
||||||
result += " imul eax, " + op2 + "\n";
|
result += " imul eax, " + op2 + "\n";
|
||||||
result += " mov " + dst + ", eax\n";
|
result += " mov " + dst + ", eax\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case OpType::DIV: {
|
||||||
|
std::string op1 = getVarLocation(instr.arg2, stackMap);
|
||||||
|
std::string op2 = getVarLocation(instr.arg3, stackMap);
|
||||||
|
std::string dst = getVarLocation(instr.arg1, stackMap);
|
||||||
|
result += " mov eax, " + op1 + "\n";
|
||||||
|
result += " cdq\n";
|
||||||
|
if (isdigit(op2[0]) || op2[0] == '-') {
|
||||||
|
result += " mov ecx, " + op2 + "\n";
|
||||||
|
result += " idiv ecx\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result += " idiv dword " + op2 + "\n";
|
||||||
|
}
|
||||||
|
result += " mov " + dst + ", eax\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case OpType::MOD: {
|
||||||
|
std::string op1 = getVarLocation(instr.arg2, stackMap);
|
||||||
|
std::string op2 = getVarLocation(instr.arg3, stackMap);
|
||||||
|
std::string dst = getVarLocation(instr.arg1, stackMap);
|
||||||
|
result += " mov eax, " + op1 + "\n";
|
||||||
|
result += " cdq\n";
|
||||||
|
if (isdigit(op2[0]) || op2[0] == '-') {
|
||||||
|
result += " mov ecx, " + op2 + "\n";
|
||||||
|
result += " idiv ecx\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result += " idiv dword " + op2 + "\n";
|
||||||
|
}
|
||||||
|
result += " mov " + dst + ", edx\n"; // Reszta
|
||||||
|
break;
|
||||||
|
}
|
||||||
case OpType::EQ: {
|
case OpType::EQ: {
|
||||||
std::string op1 = getVarLocation(instr.arg2, stackMap);
|
std::string op1 = getVarLocation(instr.arg2, stackMap);
|
||||||
std::string op2 = getVarLocation(instr.arg3, stackMap);
|
std::string op2 = getVarLocation(instr.arg3, stackMap);
|
||||||
@@ -156,80 +228,184 @@ std::string generateAssembly(const CompilerState& state) {
|
|||||||
result += " mov " + dst + ", eax\n";
|
result += " mov " + dst + ", eax\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case OpType::LOGIC_AND: {
|
||||||
|
std::string op1 = getVarLocation(instr.arg2, stackMap);
|
||||||
|
std::string op2 = getVarLocation(instr.arg3, stackMap);
|
||||||
|
std::string dst = getVarLocation(instr.arg1, stackMap);
|
||||||
|
result += " mov eax, " + op1 + "\n";
|
||||||
|
result += " cmp eax, 0\n";
|
||||||
|
result += " setne al\n";
|
||||||
|
if (isdigit(op2[0])) result += " mov ecx, " + op2 + "\n";
|
||||||
|
else result += " mov ecx, " + op2 + "\n";
|
||||||
|
result += " cmp ecx, 0\n";
|
||||||
|
result += " setne cl\n";
|
||||||
|
result += " and al, cl\n";
|
||||||
|
result += " movzx eax, al\n";
|
||||||
|
result += " mov " + dst + ", eax\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case OpType::LOGIC_OR: {
|
||||||
|
std::string op1 = getVarLocation(instr.arg2, stackMap);
|
||||||
|
std::string op2 = getVarLocation(instr.arg3, stackMap);
|
||||||
|
std::string dst = getVarLocation(instr.arg1, stackMap);
|
||||||
|
result += " mov eax, " + op1 + "\n";
|
||||||
|
result += " cmp eax, 0\n";
|
||||||
|
result += " setne al\n";
|
||||||
|
if (isdigit(op2[0])) result += " mov ecx, " + op2 + "\n";
|
||||||
|
else result += " mov ecx, " + op2 + "\n";
|
||||||
|
result += " cmp ecx, 0\n";
|
||||||
|
result += " setne cl\n";
|
||||||
|
result += " or al, cl\n";
|
||||||
|
result += " movzx eax, al\n";
|
||||||
|
result += " mov " + dst + ", eax\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
case OpType::JMP_FALSE: {
|
case OpType::JMP_FALSE: {
|
||||||
// PARSOWANIE WARUNKU: np. "suma == 30" lub "test"
|
|
||||||
std::string condRaw = instr.arg2;
|
std::string condRaw = instr.arg2;
|
||||||
size_t eqPos = condRaw.find("==");
|
size_t eqPos = condRaw.find("==");
|
||||||
|
|
||||||
if (eqPos != std::string::npos) {
|
if (eqPos != std::string::npos) {
|
||||||
// Mamy porównanie w IFie (a == b)
|
|
||||||
std::string leftStr = condRaw.substr(0, eqPos);
|
std::string leftStr = condRaw.substr(0, eqPos);
|
||||||
std::string rightStr = condRaw.substr(eqPos + 2);
|
std::string rightStr = condRaw.substr(eqPos + 2);
|
||||||
|
|
||||||
std::string op1 = getVarLocation(leftStr, stackMap);
|
std::string op1 = getVarLocation(leftStr, stackMap);
|
||||||
std::string op2 = getVarLocation(rightStr, stackMap);
|
std::string op2 = getVarLocation(rightStr, stackMap);
|
||||||
|
|
||||||
result += " mov eax, " + op1 + "\n";
|
result += " mov eax, " + op1 + "\n";
|
||||||
result += " cmp eax, " + op2 + "\n";
|
result += " cmp eax, " + op2 + "\n";
|
||||||
result += " jne " + instr.arg1 + " ; jump if NOT equal\n";
|
result += " jne " + instr.arg1 + "\n";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Zwyk³a zmienna boolowska (if test)
|
|
||||||
std::string cond = getVarLocation(condRaw, stackMap);
|
std::string cond = getVarLocation(condRaw, stackMap);
|
||||||
result += " mov eax, " + cond + "\n";
|
result += " mov eax, " + cond + "\n";
|
||||||
result += " test eax, eax\n";
|
result += " test eax, eax\n";
|
||||||
result += " jz " + instr.arg1 + " ; jump if zero\n";
|
result += " jz " + instr.arg1 + "\n";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case OpType::JMP: {
|
||||||
|
result += " jmp " + instr.arg1 + "\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case OpType::ARRAY_DECLARE: {
|
||||||
|
std::string name = instr.arg1;
|
||||||
|
int size = std::stoi(instr.arg2);
|
||||||
|
|
||||||
|
// Rezerwujemy miejsce dla ca³ej tablicy
|
||||||
|
// t[0] bêdzie pod aktualnym currentStack
|
||||||
|
stackMap[name] = currentStack;
|
||||||
|
|
||||||
|
// Przesuwamy wskaŸnik stosu o (rozmiar * 8 bajtów)
|
||||||
|
// Zak³adamy, ¿e ka¿dy element to 64-bit (dla bezpieczeñstwa i prostoty assemblera)
|
||||||
|
currentStack += (size * 8);
|
||||||
|
|
||||||
|
// W ASM nie musimy generowaæ ¿adnego kodu! (Miejsce ju¿ jest z sub rsp, 256)
|
||||||
|
// O ile tablica mieœci siê w tych 256 bajtach.
|
||||||
|
// Jeœli chcesz byæ PRO: dodaj na pocz¹tku funkcji "sub rsp, (currentStack + zapas)"
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case OpType::ARRAY_SET: {
|
||||||
|
std::string arrName = instr.arg1; // t
|
||||||
|
std::string indexStr = instr.arg2; // i
|
||||||
|
std::string valStr = instr.arg3; // val
|
||||||
|
|
||||||
|
// 1. Obliczamy wartoϾ do wpisania
|
||||||
|
if (isNumber(valStr)) {
|
||||||
|
result += " mov rax, " + valStr + "\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::string valLoc = getVarLocation(valStr, stackMap);
|
||||||
|
// Jeœli to zmienna ze stosu, to movsxd (rozszerzenie znaku) lub mov
|
||||||
|
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
|
||||||
|
if (isNumber(indexStr)) {
|
||||||
|
result += " mov rcx, " + indexStr + "\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::string idxLoc = getVarLocation(indexStr, stackMap);
|
||||||
|
result += " mov rcx, " + idxLoc + "\n"; // Pobierz indeks ze zmiennej
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obliczamy przesuniêcie bajtowe: index * 8
|
||||||
|
result += " imul rcx, 8\n";
|
||||||
|
|
||||||
|
// Poniewa¿ adres to RBP - (base + index*8) -> RBP - base - index*8
|
||||||
|
// Musimy to sprytnie zmontowaæ.
|
||||||
|
// Obliczmy finalny adres w RDX.
|
||||||
|
|
||||||
|
result += " mov rdx, rbp\n";
|
||||||
|
result += " sub rdx, " + std::to_string(baseOffset) + "\n"; // RDX = adres t[0]
|
||||||
|
result += " sub rdx, rcx\n"; // RDX = adres t[i]
|
||||||
|
|
||||||
|
// Zapisujemy wartoϾ (RAX) pod adres (RDX)
|
||||||
|
result += " mov [rdx], rax\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
case OpType::LABEL: {
|
case OpType::LABEL: {
|
||||||
result += instr.arg1 + ":\n";
|
result += instr.arg1 + ":\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OpType::RETURN: {
|
case OpType::PRINT: {
|
||||||
|
// Instrukcja PRINT zwyk³a (liczba)
|
||||||
std::string val = getVarLocation(instr.arg1, stackMap);
|
std::string val = getVarLocation(instr.arg1, stackMap);
|
||||||
if (val.empty() || val == ";");
|
result += " mov edx, " + val + "\n";
|
||||||
else {
|
result += " lea rcx, [rel fmt_int]\n";
|
||||||
result += " mov eax, " + val + " ; return value\n";
|
result += " call printf\n";
|
||||||
}
|
|
||||||
result += " leave\n";
|
|
||||||
result += " ret\n";
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OpType::PRINT: {
|
case OpType::PRINT_STRING: {
|
||||||
if (instr.arg2 == "STRING") {
|
// Instrukcja PRINT_STRING (tekst)
|
||||||
result += " lea rdx, [rel " + instr.arg1 + "]\n";
|
std::string target = instr.arg1;
|
||||||
result += " lea rcx, [rel fmt_str]\n";
|
if (target.find("str_") == 0) {
|
||||||
result += " call printf\n";
|
// Litera³: print("tekst")
|
||||||
|
result += " lea rdx, [rel " + target + "]\n";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::string val = getVarLocation(instr.arg1, stackMap);
|
// Zmienna: print(s) -> s trzyma adres
|
||||||
result += " mov edx, " + val + "\n";
|
std::string val = getVarLocation(target, stackMap);
|
||||||
result += " lea rcx, [rel fmt_int]\n";
|
result += " mov rdx, " + val + "\n";
|
||||||
result += " call printf\n";
|
|
||||||
}
|
}
|
||||||
|
result += " lea rcx, [rel fmt_str]\n";
|
||||||
|
result += " call printf\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OpType::CALL: {
|
case OpType::CALL: {
|
||||||
// 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") {
|
if (instr.arg1 == "input") {
|
||||||
result += " call getchar\n";
|
result += " call getchar\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. read_key() - zwraca kod wciœniêtego klawisza (NOWOŒÆ)
|
|
||||||
if (instr.arg1 == "read_key") {
|
if (instr.arg1 == "read_key") {
|
||||||
result += " call _getch\n"; // Zwraca kod znaku w EAX
|
result += " call _getch\n";
|
||||||
// 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;
|
break;
|
||||||
}
|
}
|
||||||
|
if (instr.arg1 == "sys_seed") {
|
||||||
|
result += " mov rcx, 0\n";
|
||||||
|
result += " call time\n";
|
||||||
|
result += " mov rcx, rax\n";
|
||||||
|
result += " call srand\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (instr.arg1 == "sys_rand") {
|
||||||
|
result += " call rand\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Standardowe wywo³anie funkcji
|
||||||
|
std::string argsRaw = instr.arg2;
|
||||||
|
std::vector<std::string> callArgs;
|
||||||
if (!argsRaw.empty()) {
|
if (!argsRaw.empty()) {
|
||||||
size_t comma = argsRaw.find(',');
|
size_t comma = argsRaw.find(',');
|
||||||
if (comma != std::string::npos) {
|
if (comma != std::string::npos) {
|
||||||
@@ -240,82 +416,65 @@ std::string generateAssembly(const CompilerState& state) {
|
|||||||
callArgs.push_back(argsRaw);
|
callArgs.push_back(argsRaw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obs³uga RDX (arg 2)
|
|
||||||
if (callArgs.size() > 1) {
|
if (callArgs.size() > 1) {
|
||||||
std::string val = getVarLocation(callArgs[1], stackMap);
|
std::string val = getVarLocation(callArgs[1], stackMap);
|
||||||
if (isNumber(val)) {
|
if (isNumber(val)) result += " mov rdx, " + val + "\n";
|
||||||
// Jeœli liczba: mov rdx, 100
|
else result += " movsxd rdx, dword " + val + "\n";
|
||||||
result += " mov rdx, " + val + "\n";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Jeœli zmienna/pamiêæ: movsxd rdx, dword [rbp-8]
|
|
||||||
result += " movsxd rdx, dword " + val + "\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obs³uga RCX (arg 1)
|
|
||||||
if (callArgs.size() > 0) {
|
if (callArgs.size() > 0) {
|
||||||
std::string val = getVarLocation(callArgs[0], stackMap);
|
std::string val = getVarLocation(callArgs[0], stackMap);
|
||||||
if (isNumber(val)) {
|
if (isNumber(val)) result += " mov rcx, " + val + "\n";
|
||||||
result += " mov rcx, " + val + "\n";
|
else result += " movsxd rcx, dword " + val + "\n";
|
||||||
}
|
|
||||||
else {
|
|
||||||
result += " movsxd rcx, dword " + val + "\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ... wewn¹trz case OpType::CALL ...
|
|
||||||
if (instr.arg1 == "sys_seed") {
|
|
||||||
result += " mov rcx, 0\n";
|
|
||||||
result += " call time\n"; // Pobierz czas
|
|
||||||
result += " mov rcx, rax\n"; // Czas jako argument dla srand
|
|
||||||
result += " call srand\n"; // Inicjuj generator
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (instr.arg1 == "sys_rand") {
|
|
||||||
result += " call rand\n"; // Wynik w EAX
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
result += " call " + instr.arg1 + "\n";
|
result += " call " + instr.arg1 + "\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OpType::DIV: {
|
case OpType::RETURN: {
|
||||||
std::string op1 = getVarLocation(instr.arg2, stackMap);
|
std::string val = getVarLocation(instr.arg1, stackMap);
|
||||||
std::string op2 = getVarLocation(instr.arg3, stackMap);
|
if (!val.empty() && val != ";") {
|
||||||
std::string dst = getVarLocation(instr.arg1, stackMap);
|
result += " mov eax, " + val + "\n";
|
||||||
|
|
||||||
result += " mov eax, " + op1 + "\n";
|
|
||||||
result += " cdq\n"; // Rozszerza EAX na EDX:EAX (konieczne przed dzieleniem)
|
|
||||||
|
|
||||||
// IDIV nie przyjmuje sta³ej (np. 10), musi byæ rejestr
|
|
||||||
if (isdigit(op2[0]) || op2[0] == '-') {
|
|
||||||
result += " mov ecx, " + op2 + "\n";
|
|
||||||
result += " idiv ecx\n";
|
|
||||||
}
|
}
|
||||||
else {
|
result += " leave\n";
|
||||||
result += " idiv dword " + op2 + "\n";
|
result += " ret\n";
|
||||||
}
|
|
||||||
result += " mov " + dst + ", eax\n"; // Wynik dzielenia
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OpType::MOD: {
|
case OpType::MSGBOX: {
|
||||||
std::string op1 = getVarLocation(instr.arg2, stackMap);
|
// Konwencja Windows x64:
|
||||||
std::string op2 = getVarLocation(instr.arg3, stackMap);
|
// RCX = HWND (0 = brak okna nadrzêdnego)
|
||||||
std::string dst = getVarLocation(instr.arg1, stackMap);
|
// RDX = TreϾ (Text)
|
||||||
|
// R8 = Tytu³ (Caption)
|
||||||
|
// R9 = Typ (0 = przycisk OK)
|
||||||
|
|
||||||
result += " mov eax, " + op1 + "\n";
|
std::string title = instr.arg1;
|
||||||
result += " cdq\n"; // Rozszerza EAX
|
std::string text = instr.arg2;
|
||||||
|
|
||||||
if (isdigit(op2[0]) || op2[0] == '-') {
|
// --- 1. Ustawiamy RDX (TreϾ) ---
|
||||||
result += " mov ecx, " + op2 + "\n";
|
if (text.find("str_") == 0) {
|
||||||
result += " idiv ecx\n";
|
// Jeœli to litera³ (np. str_5), ³adujemy jego adres (LEA)
|
||||||
|
result += " lea rdx, [rel " + text + "]\n";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result += " idiv dword " + op2 + "\n";
|
// Jeœli to zmienna, pobieramy jej wartoœæ ze stosu (która jest adresem)
|
||||||
|
std::string loc = getVarLocation(text, stackMap);
|
||||||
|
result += " mov rdx, " + loc + "\n";
|
||||||
}
|
}
|
||||||
result += " mov " + dst + ", edx\n"; // EDX to reszta z dzielenia!
|
|
||||||
|
// --- 2. Ustawiamy R8 (Tytu³) ---
|
||||||
|
if (title.find("str_") == 0) {
|
||||||
|
result += " lea r8, [rel " + title + "]\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::string loc = getVarLocation(title, stackMap);
|
||||||
|
result += " mov r8, " + loc + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- 3. Pozosta³e argumenty (Sta³e) ---
|
||||||
|
result += " mov rcx, 0\n"; // HWND = NULL
|
||||||
|
result += " mov r9, 0\n"; // MB_OK
|
||||||
|
|
||||||
|
// --- 4. Wywo³anie ---
|
||||||
|
// Stos (shadow space) jest ju¿ przygotowany na pocz¹tku funkcji (sub rsp, 256)
|
||||||
|
result += " call MessageBoxA\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,25 +6,32 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
// Typy operacji, które nasz kompilator rozumie
|
// Typy operacji
|
||||||
enum class OpType {
|
enum class OpType {
|
||||||
ASSIGN, // a = 5
|
ASSIGN, // a = 5
|
||||||
ADD, // a = b + c
|
ADD, // a = b + c
|
||||||
SUB, // a = b - c
|
SUB, // a = b - c
|
||||||
MUL, // a = b * c
|
MUL, // a = b * c
|
||||||
|
DIV, // a = b / c
|
||||||
|
MOD, // a = b % c
|
||||||
EQ, // a == b
|
EQ, // a == b
|
||||||
PRINT, // print(a)
|
PRINT, // print(int)
|
||||||
|
PRINT_STRING, // print(string) - NOWE
|
||||||
JMP_FALSE, // if (false) skocz...
|
JMP_FALSE, // if (false) skocz...
|
||||||
|
ARRAY_DECLARE, // int t[10];
|
||||||
|
ARRAY_SET, // t[0] = 5;
|
||||||
|
ARRAY_GET, // x = t[0]; - to obs³u¿ymy w ASSIGN, ale warto mieæ typ
|
||||||
JMP, // else / pêtla
|
JMP, // else / pêtla
|
||||||
|
LOGIC_AND, // &&
|
||||||
|
LOGIC_OR, // ||
|
||||||
LABEL, // miejsce skoku
|
LABEL, // miejsce skoku
|
||||||
CALL, // wywo³anie funkcji
|
CALL, // wywo³anie funkcji
|
||||||
RETURN, // return x
|
RETURN, // return x
|
||||||
DIV, // dzielenie
|
MSGBOX, // msg box
|
||||||
MOD, // Reszta z dzelenia (%)
|
|
||||||
NOP // pusta instrukcja
|
NOP // pusta instrukcja
|
||||||
};
|
};
|
||||||
|
|
||||||
// Pojedynczy rozkaz kompilatora (Intermediate Representation)
|
// Pojedynczy rozkaz
|
||||||
struct Instruction {
|
struct Instruction {
|
||||||
OpType type;
|
OpType type;
|
||||||
std::string arg1;
|
std::string arg1;
|
||||||
@@ -35,27 +42,36 @@ struct Instruction {
|
|||||||
// Definicja funkcji
|
// Definicja funkcji
|
||||||
struct Function {
|
struct Function {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string returnType; // "int", "void", "bool"
|
std::string returnType;
|
||||||
std::vector<std::string> args; // Nazwy argumentów (np. "a", "b")
|
std::vector<std::string> args;
|
||||||
std::vector<Instruction> instructions; // Lista rozkazów w funkcji
|
std::vector<Instruction> instructions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// G£ÓWNY STAN KOMPILATORA
|
||||||
struct CompilerState {
|
struct CompilerState {
|
||||||
// Mapa wszystkich funkcji (klucz to nazwa)
|
// Mapa funkcji
|
||||||
std::map<std::string, Function> functions;
|
std::map<std::string, Function> functions;
|
||||||
|
|
||||||
// Zmienne globalne (tylko nazwa -> wartoœæ pocz¹tkowa)
|
// Zmienne globalne
|
||||||
std::map<std::string, int> globals;
|
std::map<std::string, int> globals;
|
||||||
|
|
||||||
// Stan parsera
|
// Zarz¹dzanie stosem
|
||||||
Function* currentFunction = nullptr; // WskaŸnik na aktualnie parsuj¹c¹ siê funkcjê
|
std::map<std::string, int> stackMap;
|
||||||
int labelCounter = 0; // Do generowania unikalnych nazw etykiet (L1, L2...)
|
int stackOffset = 0;
|
||||||
std::stack<std::string> loopStack; // Do break/continue (przysz³oœciowo)
|
|
||||||
|
|
||||||
|
// Stan parsera
|
||||||
|
Function* currentFunction = nullptr;
|
||||||
|
int labelCounter = 0;
|
||||||
|
|
||||||
|
// Stosy bloków
|
||||||
|
std::stack<std::string> loopStack;
|
||||||
std::stack<std::string> blockStack;
|
std::stack<std::string> blockStack;
|
||||||
|
|
||||||
std::map<std::string, std::string> stringLiterals;
|
std::vector<std::pair<std::string, std::string>> stringLiterals;
|
||||||
int stringCounter = 0; // Licznik do generowania nazw str_1, str_2...
|
|
||||||
|
// Licznik do generowania nazw str_0, str_1...
|
||||||
|
int stringCounter = 0;
|
||||||
|
std::map<std::string, std::string> varTypes;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ std::string getExecutablePath() {
|
|||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
std::string inputFile, outputName;
|
std::string inputFile, outputName;
|
||||||
std::string Version = "v0.0.5-beta";
|
std::string Version = "v0.0.7-beta";
|
||||||
bool showHelp = false, showVersion = false, showCredits = false;
|
bool showHelp = false, showVersion = false, showCredits = false;
|
||||||
|
|
||||||
// --- PARSOWANIE ARGUMENTÓW ---
|
// --- PARSOWANIE ARGUMENTÓW ---
|
||||||
|
|||||||
@@ -26,6 +26,18 @@ std::vector<std::string> parseArgs(const std::string& line) {
|
|||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Funkcja wyciągająca "tekst" i rejestrująca go w state
|
||||||
|
// Rejestruje tekst i zwraca jego etykietę (np. str_5)
|
||||||
|
std::string registerStringLiteral(CompilerState& state, std::string content) {
|
||||||
|
// Używamy stringCounter z CompilerState
|
||||||
|
std::string label = "str_" + std::to_string(state.stringCounter++);
|
||||||
|
|
||||||
|
// Dodajemy do WEKTORA (push_back działa tylko na wektorze/liście)
|
||||||
|
state.stringLiterals.push_back({ label, content });
|
||||||
|
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
void processSource(const std::string& src, CompilerState& state) {
|
void processSource(const std::string& src, CompilerState& state) {
|
||||||
std::istringstream iss(src);
|
std::istringstream iss(src);
|
||||||
std::string line;
|
std::string line;
|
||||||
@@ -34,8 +46,9 @@ void processSource(const std::string& src, CompilerState& state) {
|
|||||||
line = trim(line);
|
line = trim(line);
|
||||||
if (line.empty() || line.substr(0, 2) == "//" || line[0] == '#') continue;
|
if (line.empty() || line.substr(0, 2) == "//" || line[0] == '#') continue;
|
||||||
|
|
||||||
// --- 1. DEFINICJA FUNKCJI ---
|
// =========================================================
|
||||||
// Warunki: zaczyna się od typu, ma '(', ma '{' i NIE ma '=' (żeby nie mylić ze zmienną)
|
// 1. DEFINICJA FUNKCJI (np. void main() { )
|
||||||
|
// =========================================================
|
||||||
bool startsWithType = (line.rfind("int ", 0) == 0 || line.rfind("void ", 0) == 0 || line.rfind("bool ", 0) == 0);
|
bool startsWithType = (line.rfind("int ", 0) == 0 || line.rfind("void ", 0) == 0 || line.rfind("bool ", 0) == 0);
|
||||||
if (startsWithType && line.find("(") != std::string::npos && line.find("{") != std::string::npos && line.find("=") == std::string::npos) {
|
if (startsWithType && line.find("(") != std::string::npos && line.find("{") != std::string::npos && line.find("=") == std::string::npos) {
|
||||||
|
|
||||||
@@ -55,25 +68,49 @@ void processSource(const std::string& src, CompilerState& state) {
|
|||||||
std::cout << "[PARSER] New Function: " << funcName << "\n";
|
std::cout << "[PARSER] New Function: " << funcName << "\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// --- 2. ZAMYKANIE BLOKU '}' ---
|
|
||||||
|
// =========================================================
|
||||||
|
// 2. ZAMYKANIE BLOKU '}' (Koniec funkcji, IF-a lub WHILE)
|
||||||
|
// =========================================================
|
||||||
if (line == "}") {
|
if (line == "}") {
|
||||||
// Najpierw sprawdzamy, czy zamykamy IF-a (czy jest coś na stosie bloków)
|
|
||||||
if (!state.blockStack.empty()) {
|
if (!state.blockStack.empty()) {
|
||||||
std::string label = state.blockStack.top();
|
std::string blockInfo = state.blockStack.top();
|
||||||
state.blockStack.pop();
|
state.blockStack.pop();
|
||||||
if (state.currentFunction) {
|
|
||||||
state.currentFunction->instructions.push_back({ OpType::LABEL, label, "", "" });
|
// Sprawdzamy czy to pętla WHILE (znacznik "WHILE|...")
|
||||||
|
bool isWhile = (blockInfo.length() > 6 && blockInfo.substr(0, 6) == "WHILE|");
|
||||||
|
|
||||||
|
if (isWhile) {
|
||||||
|
size_t firstPipe = blockInfo.find('|');
|
||||||
|
size_t secondPipe = blockInfo.rfind('|');
|
||||||
|
std::string labelStart = blockInfo.substr(firstPipe + 1, secondPipe - firstPipe - 1);
|
||||||
|
std::string labelEnd = blockInfo.substr(secondPipe + 1);
|
||||||
|
|
||||||
|
if (state.currentFunction) {
|
||||||
|
state.currentFunction->instructions.push_back({ OpType::JMP, labelStart, "", "" });
|
||||||
|
state.currentFunction->instructions.push_back({ OpType::LABEL, labelEnd, "", "" });
|
||||||
|
}
|
||||||
|
std::cout << " [PARSER] } End WHILE loop\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// To zwykły IF
|
||||||
|
if (state.currentFunction) {
|
||||||
|
state.currentFunction->instructions.push_back({ OpType::LABEL, blockInfo, "", "" });
|
||||||
|
}
|
||||||
|
std::cout << " [PARSER] } End IF block -> " << blockInfo << "\n";
|
||||||
}
|
}
|
||||||
std::cout << " [PARSER] } End IF block -> " << label << "\n";
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Jeśli stos pusty, to koniec funkcji
|
// Koniec funkcji
|
||||||
state.currentFunction = nullptr;
|
state.currentFunction = nullptr;
|
||||||
std::cout << " [PARSER] } End Function\n";
|
std::cout << " [PARSER] } End Function\n";
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// --- JESTEŚMY W ŚRODKU FUNKCJI ---
|
|
||||||
|
// =========================================================
|
||||||
|
// JESTEŚMY W ŚRODKU FUNKCJI
|
||||||
|
// =========================================================
|
||||||
if (state.currentFunction) {
|
if (state.currentFunction) {
|
||||||
Function& f = *state.currentFunction;
|
Function& f = *state.currentFunction;
|
||||||
|
|
||||||
@@ -82,157 +119,296 @@ void processSource(const std::string& src, CompilerState& state) {
|
|||||||
std::string val = trim(line.substr(6));
|
std::string val = trim(line.substr(6));
|
||||||
if (!val.empty() && val.back() == ';') val.pop_back();
|
if (!val.empty() && val.back() == ';') val.pop_back();
|
||||||
f.instructions.push_back({ OpType::RETURN, val, "", "" });
|
f.instructions.push_back({ OpType::RETURN, val, "", "" });
|
||||||
std::cout << " [PARSER] Return: " << val << "\n";
|
continue;
|
||||||
}
|
}
|
||||||
// B. PRINT
|
|
||||||
else if (line.substr(0, 5) == "print") {
|
|
||||||
size_t start = line.find('(') + 1;
|
|
||||||
size_t end = line.find(')');
|
|
||||||
if (start != std::string::npos && end != std::string::npos) {
|
|
||||||
std::string arg = trim(line.substr(start, end - start));
|
|
||||||
|
|
||||||
// Czy to bezpośredni napis? np. print("Hello")
|
// B. DEKLARACJA STRINGA: string s = "hello";
|
||||||
if (arg.size() >= 2 && arg.front() == '"' && arg.back() == '"') {
|
else if (line.substr(0, 6) == "string") {
|
||||||
std::string content = arg.substr(1, arg.size() - 2);
|
size_t eqPos = line.find("=");
|
||||||
|
if (eqPos != std::string::npos) {
|
||||||
|
std::string name = trim(line.substr(7, eqPos - 7));
|
||||||
|
size_t quoteStart = line.find("\"", eqPos);
|
||||||
|
size_t quoteEnd = line.rfind("\"");
|
||||||
|
|
||||||
// Rejestrujemy
|
if (quoteStart != std::string::npos && quoteEnd > quoteStart) {
|
||||||
std::string label;
|
std::string content = line.substr(quoteStart + 1, quoteEnd - quoteStart - 1);
|
||||||
if (state.stringLiterals.count(content)) {
|
std::string label = registerStringLiteral(state, content);
|
||||||
label = state.stringLiterals[content];
|
state.varTypes[name] = "string";
|
||||||
}
|
f.instructions.push_back({ OpType::ASSIGN, name, label, "" });
|
||||||
else {
|
|
||||||
label = "str_" + std::to_string(state.stringCounter++);
|
|
||||||
state.stringLiterals[content] = label;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dajemy znać generatorowi, że to typ STRING
|
|
||||||
f.instructions.push_back({ OpType::PRINT, label, "STRING", "" });
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Zwykła zmienna (int lub string - generator musi zgadnąć lub my musimy wiedzieć)
|
|
||||||
// Na razie załóżmy, że jeśli zmienna ma w nazwie "msg" lub "txt", to string
|
|
||||||
// (To hack, w przyszłości dodamy tabelę typów zmiennych)
|
|
||||||
f.instructions.push_back({ OpType::PRINT, arg, "VAR", "" });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// C. IF STATEMENT
|
// C. DEKLARACJA TABLICY: int t[10];
|
||||||
|
else if (line.substr(0, 3) == "int" && line.find("[") != std::string::npos && line.find("=") == std::string::npos) {
|
||||||
|
size_t openBracket = line.find("[");
|
||||||
|
size_t closeBracket = line.find("]");
|
||||||
|
|
||||||
|
if (openBracket != std::string::npos && closeBracket > openBracket) {
|
||||||
|
std::string name = trim(line.substr(3, openBracket - 3));
|
||||||
|
std::string sizeStr = trim(line.substr(openBracket + 1, closeBracket - openBracket - 1));
|
||||||
|
|
||||||
|
state.varTypes[name] = "array";
|
||||||
|
f.instructions.push_back({ OpType::ARRAY_DECLARE, name, sizeStr, "" });
|
||||||
|
std::cout << " [PARSER] Array Decl: " << name << "[" << sizeStr << "]\n";
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// D. DRUKOWANIE (PRINT)
|
||||||
|
else if (line.substr(0, 5) == "print") {
|
||||||
|
size_t open = line.find("(");
|
||||||
|
size_t close = line.rfind(")");
|
||||||
|
if (open != std::string::npos && close > open) {
|
||||||
|
std::string content = trim(line.substr(open + 1, close - open - 1));
|
||||||
|
|
||||||
|
// Czy to element tablicy? print(t[0])
|
||||||
|
if (content.find("[") != std::string::npos && content.back() == ']') {
|
||||||
|
size_t opIdx = content.find("[");
|
||||||
|
std::string arrName = content.substr(0, opIdx);
|
||||||
|
std::string arrIdx = content.substr(opIdx + 1, content.length() - opIdx - 2);
|
||||||
|
|
||||||
|
// Hack: Używamy tymczasowej zmiennej do wydruku
|
||||||
|
std::string tmp = "_p_tmp_" + std::to_string(state.labelCounter++);
|
||||||
|
f.instructions.push_back({ OpType::ASSIGN, tmp, arrName, "ARRAY_IDX:" + arrIdx });
|
||||||
|
f.instructions.push_back({ OpType::PRINT, tmp, "", "" });
|
||||||
|
}
|
||||||
|
// Literał tekstowy
|
||||||
|
else if (content.front() == '"' && content.back() == '"') {
|
||||||
|
std::string text = content.substr(1, content.length() - 2);
|
||||||
|
std::string label = registerStringLiteral(state, text);
|
||||||
|
f.instructions.push_back({ OpType::PRINT_STRING, label, "", "" });
|
||||||
|
}
|
||||||
|
// Zmienna string
|
||||||
|
else if (state.varTypes.count(content) && state.varTypes[content] == "string") {
|
||||||
|
f.instructions.push_back({ OpType::PRINT_STRING, content, "", "" });
|
||||||
|
}
|
||||||
|
// Liczba
|
||||||
|
else {
|
||||||
|
f.instructions.push_back({ OpType::PRINT, content, "", "" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// E. IF STATEMENT
|
||||||
else if (line.substr(0, 2) == "if") {
|
else if (line.substr(0, 2) == "if") {
|
||||||
size_t openParen = line.find("(");
|
size_t openParen = line.find("(");
|
||||||
size_t closeParen = line.find(")");
|
size_t closeParen = line.rfind(")");
|
||||||
|
|
||||||
if (openParen != std::string::npos && closeParen > openParen) {
|
if (openParen != std::string::npos && closeParen > openParen) {
|
||||||
std::string condition = trim(line.substr(openParen + 1, closeParen - openParen - 1));
|
std::string conditionRaw = trim(line.substr(openParen + 1, closeParen - openParen - 1));
|
||||||
|
std::string finalConditionVar = conditionRaw;
|
||||||
|
|
||||||
|
// Logika && i || (uproszczona)
|
||||||
|
size_t andPos = conditionRaw.find("&&");
|
||||||
|
size_t orPos = conditionRaw.find("||");
|
||||||
|
|
||||||
|
if (andPos != std::string::npos) {
|
||||||
|
std::string partA = trim(conditionRaw.substr(0, andPos));
|
||||||
|
std::string partB = trim(conditionRaw.substr(andPos + 2));
|
||||||
|
std::string tempA = "_tmp_and_a_" + std::to_string(state.labelCounter);
|
||||||
|
std::string tempB = "_tmp_and_b_" + std::to_string(state.labelCounter);
|
||||||
|
std::string tempRes = "_tmp_and_res_" + std::to_string(state.labelCounter);
|
||||||
|
|
||||||
|
// A
|
||||||
|
if (partA.find("==") != std::string::npos) {
|
||||||
|
size_t eq = partA.find("==");
|
||||||
|
f.instructions.push_back({ OpType::EQ, tempA, trim(partA.substr(0, eq)), trim(partA.substr(eq + 2)) });
|
||||||
|
}
|
||||||
|
else f.instructions.push_back({ OpType::ASSIGN, tempA, partA, "" });
|
||||||
|
|
||||||
|
// B
|
||||||
|
if (partB.find("==") != std::string::npos) {
|
||||||
|
size_t eq = partB.find("==");
|
||||||
|
f.instructions.push_back({ OpType::EQ, tempB, trim(partB.substr(0, eq)), trim(partB.substr(eq + 2)) });
|
||||||
|
}
|
||||||
|
else f.instructions.push_back({ OpType::ASSIGN, tempB, partB, "" });
|
||||||
|
|
||||||
|
f.instructions.push_back({ OpType::LOGIC_AND, tempRes, tempA, tempB });
|
||||||
|
finalConditionVar = tempRes;
|
||||||
|
}
|
||||||
|
else if (orPos != std::string::npos) {
|
||||||
|
// ... (Tutaj można dodać logikę OR analogicznie jak wyżej, skracam dla czytelności)
|
||||||
|
}
|
||||||
|
else if (conditionRaw.find("==") != std::string::npos) {
|
||||||
|
size_t eq = conditionRaw.find("==");
|
||||||
|
std::string tempRes = "_tmp_eq_" + std::to_string(state.labelCounter);
|
||||||
|
f.instructions.push_back({ OpType::EQ, tempRes, trim(conditionRaw.substr(0, eq)), trim(conditionRaw.substr(eq + 2)) });
|
||||||
|
finalConditionVar = tempRes;
|
||||||
|
}
|
||||||
|
|
||||||
std::string labelName = "L_" + std::to_string(state.labelCounter++);
|
std::string labelName = "L_" + std::to_string(state.labelCounter++);
|
||||||
|
f.instructions.push_back({ OpType::JMP_FALSE, labelName, finalConditionVar, "" });
|
||||||
// Skok warunkowy
|
|
||||||
f.instructions.push_back({ OpType::JMP_FALSE, labelName, condition, "" });
|
|
||||||
state.blockStack.push(labelName);
|
state.blockStack.push(labelName);
|
||||||
|
|
||||||
std::cout << " [PARSER] IF (" << condition << ") -> Jump to " << labelName << "\n";
|
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
// D. PRZYPISANIE ZMIENNEJ (LUB DEKLARACJA)
|
|
||||||
// np. "int a = 5;" LUB "a = b + c;"
|
// F. WHILE LOOP
|
||||||
|
else if (line.substr(0, 5) == "while") {
|
||||||
|
size_t openParen = line.find("(");
|
||||||
|
size_t closeParen = line.rfind(")");
|
||||||
|
if (openParen != std::string::npos && closeParen > openParen) {
|
||||||
|
std::string conditionRaw = trim(line.substr(openParen + 1, closeParen - openParen - 1));
|
||||||
|
|
||||||
|
// 1. Generujemy etykiety
|
||||||
|
std::string labelStart = "L_" + std::to_string(state.labelCounter++);
|
||||||
|
std::string labelEnd = "L_" + std::to_string(state.labelCounter++);
|
||||||
|
|
||||||
|
// 2. Wstawiamy etykietę START (tu będziemy wracać)
|
||||||
|
f.instructions.push_back({ OpType::LABEL, labelStart, "", "" });
|
||||||
|
|
||||||
|
// 3. OBLICZANIE WARUNKU (Tu był błąd - brakowało tego!)
|
||||||
|
// Jeśli warunek to np. "j - 3", musimy to policzyć do zmiennej tymczasowej
|
||||||
|
std::string finalCondVar = conditionRaw;
|
||||||
|
|
||||||
|
// Prosta obsługa odejmowania w warunku (np. while (i - 10))
|
||||||
|
if (conditionRaw.find("-") != std::string::npos) {
|
||||||
|
size_t opPos = conditionRaw.find("-");
|
||||||
|
std::string a = trim(conditionRaw.substr(0, opPos));
|
||||||
|
std::string b = trim(conditionRaw.substr(opPos + 1));
|
||||||
|
std::string tmp = "_while_tmp_" + std::to_string(state.labelCounter);
|
||||||
|
|
||||||
|
f.instructions.push_back({ OpType::SUB, tmp, a, b });
|
||||||
|
finalCondVar = tmp;
|
||||||
|
}
|
||||||
|
// Prosta obsługa "==" (np. while (i == 10))
|
||||||
|
else if (conditionRaw.find("==") != std::string::npos) {
|
||||||
|
size_t opPos = conditionRaw.find("==");
|
||||||
|
std::string a = trim(conditionRaw.substr(0, opPos));
|
||||||
|
std::string b = trim(conditionRaw.substr(opPos + 2));
|
||||||
|
std::string tmp = "_while_tmp_" + std::to_string(state.labelCounter);
|
||||||
|
|
||||||
|
f.instructions.push_back({ OpType::EQ, tmp, a, b });
|
||||||
|
finalCondVar = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Skaczemy do END jeśli warunek (obliczona zmienna) jest fałszywy
|
||||||
|
f.instructions.push_back({ OpType::JMP_FALSE, labelEnd, finalCondVar, "" });
|
||||||
|
|
||||||
|
// 5. Wrzucamy info na stos
|
||||||
|
state.blockStack.push("WHILE|" + labelStart + "|" + labelEnd);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// G. MSGBOX
|
||||||
|
else if (line.substr(0, 6) == "msgbox") {
|
||||||
|
// ... (Twoja logika msgbox, jest OK) ...
|
||||||
|
size_t open = line.find("(");
|
||||||
|
size_t close = line.rfind(")");
|
||||||
|
if (open != std::string::npos && close > open) {
|
||||||
|
std::string args = line.substr(open + 1, close - open - 1);
|
||||||
|
size_t comma = args.find(",");
|
||||||
|
if (comma != std::string::npos) {
|
||||||
|
std::string arg1 = trim(args.substr(0, comma));
|
||||||
|
std::string arg2 = trim(args.substr(comma + 1));
|
||||||
|
|
||||||
|
std::string l1 = (arg1.front() == '"') ? registerStringLiteral(state, arg1.substr(1, arg1.size() - 2)) : arg1;
|
||||||
|
std::string l2 = (arg2.front() == '"') ? registerStringLiteral(state, arg2.substr(1, arg2.size() - 2)) : arg2;
|
||||||
|
|
||||||
|
f.instructions.push_back({ OpType::MSGBOX, l1, l2, "" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================================================
|
||||||
|
// H. PRZYPISANIE / OPERACJE (Linie z "=")
|
||||||
|
// =========================================================
|
||||||
else if (line.find("=") != std::string::npos) {
|
else if (line.find("=") != std::string::npos) {
|
||||||
size_t eqPos = line.find('=');
|
size_t eqPos = line.find('=');
|
||||||
std::string leftSide = trim(line.substr(0, eqPos));
|
std::string leftSide = trim(line.substr(0, eqPos));
|
||||||
std::string rightSide = trim(line.substr(eqPos + 1));
|
std::string rightSide = trim(line.substr(eqPos + 1));
|
||||||
|
|
||||||
bool isStringDecl = false; // Flaga, czy to string
|
|
||||||
if (!rightSide.empty() && rightSide.back() == ';') rightSide.pop_back();
|
if (!rightSide.empty() && rightSide.back() == ';') rightSide.pop_back();
|
||||||
|
|
||||||
// Obsługa nazwy zmiennej (usuwanie "int ", "bool ")
|
// 1. CZY TO ZAPIS DO TABLICY? t[0] = 5
|
||||||
|
if (leftSide.find("[") != std::string::npos) {
|
||||||
|
size_t open = leftSide.find("[");
|
||||||
|
size_t close = leftSide.find("]");
|
||||||
|
std::string arrName = trim(leftSide.substr(0, open));
|
||||||
|
std::string index = trim(leftSide.substr(open + 1, close - open - 1));
|
||||||
|
|
||||||
|
f.instructions.push_back({ OpType::ARRAY_SET, arrName, index, rightSide });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pobieramy nazwę zmiennej (usuwamy "int ", "bool ")
|
||||||
std::string varName = leftSide;
|
std::string varName = leftSide;
|
||||||
if (leftSide.rfind("int ", 0) == 0) varName = trim(leftSide.substr(4));
|
if (leftSide.rfind("int ", 0) == 0) varName = trim(leftSide.substr(4));
|
||||||
else if (leftSide.rfind("bool ", 0) == 0) varName = trim(leftSide.substr(5));
|
else if (leftSide.rfind("bool ", 0) == 0) varName = trim(leftSide.substr(5));
|
||||||
else if (leftSide.rfind("string ", 0) == 0) { // NOWOŚĆ
|
else if (leftSide.rfind("string ", 0) == 0) varName = trim(leftSide.substr(7));
|
||||||
varName = trim(leftSide.substr(7));
|
|
||||||
isStringDecl = true;
|
// 2. CZY TO ODCZYT Z TABLICY? x = t[0]
|
||||||
|
if (rightSide.find("[") != std::string::npos && rightSide.back() == ']') {
|
||||||
|
size_t open = rightSide.find("[");
|
||||||
|
size_t close = rightSide.find("]");
|
||||||
|
std::string arrName = trim(rightSide.substr(0, open));
|
||||||
|
std::string index = trim(rightSide.substr(open + 1, close - open - 1));
|
||||||
|
|
||||||
|
// Specjalna flaga w arg3: ARRAY_IDX:indeks
|
||||||
|
f.instructions.push_back({ OpType::ASSIGN, varName, arrName, "ARRAY_IDX:" + index });
|
||||||
}
|
}
|
||||||
|
// 3. Wywołanie funkcji: x = func()
|
||||||
|
else if (rightSide.find("(") != std::string::npos && rightSide.find(")") != std::string::npos) {
|
||||||
// 1. Czy to wywołanie funkcji? int x = func();
|
|
||||||
if (rightSide.find("(") != std::string::npos && rightSide.find(")") != std::string::npos) {
|
|
||||||
size_t open = rightSide.find('(');
|
size_t open = rightSide.find('(');
|
||||||
std::string funcName = trim(rightSide.substr(0, open));
|
std::string funcName = trim(rightSide.substr(0, open));
|
||||||
std::string argsContent = rightSide.substr(open + 1, rightSide.find(')') - open - 1);
|
std::string argsContent = rightSide.substr(open + 1, rightSide.find(')') - open - 1);
|
||||||
|
|
||||||
// CALL func
|
|
||||||
f.instructions.push_back({ OpType::CALL, funcName, argsContent, "" });
|
f.instructions.push_back({ OpType::CALL, funcName, argsContent, "" });
|
||||||
// ASSIGN result (RAX) to variable
|
|
||||||
f.instructions.push_back({ OpType::ASSIGN, varName, "RAX", "" });
|
f.instructions.push_back({ OpType::ASSIGN, varName, "RAX", "" });
|
||||||
std::cout << " [PARSER] Call & Assign: " << varName << " = " << funcName << "()\n";
|
|
||||||
}
|
}
|
||||||
// 2. Czy to dodawanie? a + b
|
// 4. Operacje arytmetyczne
|
||||||
else if (rightSide.find("+") != std::string::npos) {
|
else if (rightSide.find("+") != std::string::npos) {
|
||||||
size_t opPos = rightSide.find("+");
|
size_t opPos = rightSide.find("+");
|
||||||
std::string a = trim(rightSide.substr(0, opPos));
|
f.instructions.push_back({ OpType::ADD, varName, trim(rightSide.substr(0, opPos)), trim(rightSide.substr(opPos + 1)) });
|
||||||
std::string b = trim(rightSide.substr(opPos + 1));
|
|
||||||
f.instructions.push_back({ OpType::ADD, varName, a, b });
|
|
||||||
}
|
}
|
||||||
// 3. NOWOŚĆ: Czy to odejmowanie? a - b
|
|
||||||
else if (rightSide.find("-") != std::string::npos) {
|
else if (rightSide.find("-") != std::string::npos) {
|
||||||
size_t opPos = rightSide.find("-");
|
size_t opPos = rightSide.find("-");
|
||||||
std::string a = trim(rightSide.substr(0, opPos));
|
f.instructions.push_back({ OpType::SUB, varName, trim(rightSide.substr(0, opPos)), trim(rightSide.substr(opPos + 1)) });
|
||||||
std::string b = trim(rightSide.substr(opPos + 1));
|
|
||||||
f.instructions.push_back({ OpType::SUB, varName, a, b }); // <--- Używamy SUB
|
|
||||||
}
|
}
|
||||||
// 4. NOWOŚĆ: Czy to mnożenie? a * b
|
|
||||||
else if (rightSide.find("*") != std::string::npos) {
|
else if (rightSide.find("*") != std::string::npos) {
|
||||||
size_t opPos = rightSide.find("*");
|
size_t opPos = rightSide.find("*");
|
||||||
std::string a = trim(rightSide.substr(0, opPos));
|
f.instructions.push_back({ OpType::MUL, varName, trim(rightSide.substr(0, opPos)), trim(rightSide.substr(opPos + 1)) });
|
||||||
std::string b = trim(rightSide.substr(opPos + 1));
|
|
||||||
f.instructions.push_back({ OpType::MUL, varName, a, b }); // <--- Używamy MUL
|
|
||||||
}
|
}
|
||||||
else if (rightSide.find("/") != std::string::npos) {
|
else if (rightSide.find("/") != std::string::npos) {
|
||||||
size_t opPos = rightSide.find("/");
|
size_t opPos = rightSide.find("/");
|
||||||
std::string a = trim(rightSide.substr(0, opPos));
|
f.instructions.push_back({ OpType::DIV, varName, trim(rightSide.substr(0, opPos)), trim(rightSide.substr(opPos + 1)) });
|
||||||
std::string b = trim(rightSide.substr(opPos + 1));
|
|
||||||
f.instructions.push_back({ OpType::DIV, varName, a, b });
|
|
||||||
}
|
}
|
||||||
// MODULO: a % b
|
|
||||||
else if (rightSide.find("%") != std::string::npos) {
|
else if (rightSide.find("%") != std::string::npos) {
|
||||||
size_t opPos = rightSide.find("%");
|
size_t opPos = rightSide.find("%");
|
||||||
std::string a = trim(rightSide.substr(0, opPos));
|
f.instructions.push_back({ OpType::MOD, varName, trim(rightSide.substr(0, opPos)), trim(rightSide.substr(opPos + 1)) });
|
||||||
std::string b = trim(rightSide.substr(opPos + 1));
|
}
|
||||||
f.instructions.push_back({ OpType::MOD, varName, a, b });
|
// 5. Logika
|
||||||
|
else if (rightSide.find("&&") != std::string::npos) {
|
||||||
|
size_t opPos = rightSide.find("&&");
|
||||||
|
f.instructions.push_back({ OpType::LOGIC_AND, varName, trim(rightSide.substr(0, opPos)), trim(rightSide.substr(opPos + 2)) });
|
||||||
|
}
|
||||||
|
else if (rightSide.find("||") != std::string::npos) {
|
||||||
|
size_t opPos = rightSide.find("||");
|
||||||
|
f.instructions.push_back({ OpType::LOGIC_OR, varName, trim(rightSide.substr(0, opPos)), trim(rightSide.substr(opPos + 2)) });
|
||||||
}
|
}
|
||||||
// 3. Czy to porównanie? a == b (Ważne: == może być w IFie, ale tu jesteśmy w linii z '=')
|
|
||||||
// UWAGA: To rzadkie w C++ (bool x = a == b), ale obsłużmy proste przypisanie wartości logicznej
|
|
||||||
else if (rightSide.find("==") != std::string::npos) {
|
else if (rightSide.find("==") != std::string::npos) {
|
||||||
size_t opPos = rightSide.find("==");
|
size_t opPos = rightSide.find("==");
|
||||||
std::string a = trim(rightSide.substr(0, opPos));
|
f.instructions.push_back({ OpType::EQ, varName, trim(rightSide.substr(0, opPos)), trim(rightSide.substr(opPos + 2)) });
|
||||||
std::string b = trim(rightSide.substr(opPos + 2));
|
|
||||||
f.instructions.push_back({ OpType::EQ, varName, a, b });
|
|
||||||
}
|
}
|
||||||
else if (rightSide.size() >= 2 && rightSide.front() == '"' && rightSide.back() == '"')
|
// 6. Zwykłe przypisanie stringa
|
||||||
{
|
else if (rightSide.size() >= 2 && rightSide.front() == '"') {
|
||||||
{
|
std::string content = rightSide.substr(1, rightSide.size() - 2);
|
||||||
// Wyciągamy treść bez cudzysłowów
|
std::string label = registerStringLiteral(state, content);
|
||||||
std::string content = rightSide.substr(1, rightSide.size() - 2);
|
state.varTypes[varName] = "string";
|
||||||
|
f.instructions.push_back({ OpType::ASSIGN, varName, label, "" });
|
||||||
// Rejestrujemy stringa w sekcji danych, jeśli jeszcze go nie ma
|
|
||||||
std::string label;
|
|
||||||
if (state.stringLiterals.count(content)) {
|
|
||||||
label = state.stringLiterals[content];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
label = "str_" + std::to_string(state.stringCounter++);
|
|
||||||
state.stringLiterals[content] = label;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generujemy instrukcję przypisania ADRESU etykiety do zmiennej
|
|
||||||
f.instructions.push_back({ OpType::ASSIGN, varName, label, "STRING" });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// 4. Zwykłe przypisanie: a = 5
|
// 7. Zwykłe przypisanie wartości
|
||||||
else {
|
else {
|
||||||
f.instructions.push_back({ OpType::ASSIGN, varName, rightSide, "" });
|
f.instructions.push_back({ OpType::ASSIGN, varName, rightSide, "" });
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
// E. SAMODZIELNE WYWOŁANIE FUNKCJI (bez =)
|
|
||||||
// np. func();
|
// I. SAMODZIELNE WYWOŁANIE FUNKCJI (np. input(); )
|
||||||
else if (line.find("(") != std::string::npos && line.find(")") != std::string::npos) {
|
else if (line.find("(") != std::string::npos && line.find(")") != std::string::npos) {
|
||||||
size_t open = line.find('(');
|
size_t open = line.find('(');
|
||||||
std::string funcName = trim(line.substr(0, open));
|
std::string funcName = trim(line.substr(0, open));
|
||||||
@@ -244,4 +420,5 @@ void processSource(const std::string& src, CompilerState& state) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void calculateExpressions(CompilerState& state) {}
|
void calculateExpressions(CompilerState& state) {}
|
||||||
|
|||||||
35
push.bat
Normal file
35
push.bat
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
@echo off
|
||||||
|
echo --- AUTO GIT PUSHER ---
|
||||||
|
echo.
|
||||||
|
|
||||||
|
:: 1. Dodajemy wszystkie pliki
|
||||||
|
echo [1/3] Adding files...
|
||||||
|
git add .
|
||||||
|
|
||||||
|
:: 2. Pytamy o nazwę commita
|
||||||
|
echo.
|
||||||
|
set /p commit_msg="Enter commit message: "
|
||||||
|
|
||||||
|
:: Jeśli użytkownik nic nie wpisze, ustaw domyślną
|
||||||
|
if "%commit_msg%"=="" set commit_msg="Auto update"
|
||||||
|
|
||||||
|
:: 3. Robimy commit
|
||||||
|
echo.
|
||||||
|
echo [2/3] Committing...
|
||||||
|
git commit -m "%commit_msg%"
|
||||||
|
|
||||||
|
:: 4. Wysyłamy (używamy origin, który już skonfigurowałeś)
|
||||||
|
echo.
|
||||||
|
echo [3/3] Pushing to Gitea...
|
||||||
|
git push origin main
|
||||||
|
|
||||||
|
:: Jeśli push się nie uda (np. konflikt), spróbuj wymusić
|
||||||
|
if %errorlevel% neq 0 (
|
||||||
|
echo.
|
||||||
|
echo [WARNING] Standard push failed. Trying force push...
|
||||||
|
git push origin main --force
|
||||||
|
)
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo DONE!
|
||||||
|
pause
|
||||||
Reference in New Issue
Block a user