added classes and bug fix

This commit is contained in:
mmichlol
2026-02-15 12:18:38 +01:00
parent 1eb29c430a
commit 61458d8582
3 changed files with 813 additions and 518 deletions

View File

@@ -16,11 +16,11 @@ enum class OpType {
MOD, // a = b % c
EQ, // a == b
PRINT, // print(int)
PRINT_STRING, // print(string) - NOWE
PRINT_STRING, // print(string)
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
ARRAY_GET, // x = t[0];
JMP, // else / pêtla
LOGIC_AND, // &&
LOGIC_OR, // ||
@@ -28,6 +28,9 @@ enum class OpType {
CALL, // wywo³anie funkcji
RETURN, // return x
MSGBOX, // msg box
ALLOC_OBJECT, // alokacja obiektu na stosie - NOWE
STORE_FIELD, // zapis do pola obiektu - NOWE
LOAD_FIELD, // odczyt z pola obiektu - NOWE
NOP // pusta instrukcja
};
@@ -47,11 +50,37 @@ struct Function {
std::vector<Instruction> instructions;
};
// Definicja pola klasy
struct ClassField {
std::string name;
std::string type; // "int", "string", itp.
int offset; // offset w bajtach od pocz¹tku obiektu
};
// Definicja metody klasy
struct ClassMethod {
std::string name;
std::string returnType;
std::vector<std::string> args;
std::string mangledName; // np. "User_setAge"
};
// Definicja klasy
struct ClassDef {
std::string name;
std::vector<ClassField> fields;
std::vector<ClassMethod> methods;
int totalSize; // rozmiar ca³ego obiektu w bajtach
};
// G£ÓWNY STAN KOMPILATORA
struct CompilerState {
// Mapa funkcji
std::map<std::string, Function> functions;
// Mapa klas (NOWE)
std::map<std::string, ClassDef> classes;
// Zmienne globalne
std::map<std::string, int> globals;
@@ -61,6 +90,7 @@ struct CompilerState {
// Stan parsera
Function* currentFunction = nullptr;
std::string currentClass = ""; // (NOWE) - nazwa aktualnie parsowanej klasy
int labelCounter = 0;
// Stosy bloków