Jelajahi Sumber

refactoring and bugfixes

Kajetan Johannes Hammerle 3 tahun lalu
induk
melakukan
5238801789
6 mengubah file dengan 277 tambahan dan 370 penghapusan
  1. 232 352
      Compiler.c
  2. 25 10
      DataType.c
  3. 8 4
      DataType.h
  4. 10 0
      tests/mix
  5. 1 3
      tokenizer/Tokenizer.c
  6. 1 1
      tokenizer/Tokenizer.h

File diff ditekan karena terlalu besar
+ 232 - 352
Compiler.c


+ 25 - 10
DataType.c

@@ -4,7 +4,7 @@
 
 #include "DataType.h"
 
-#define ARRAY_NAME 30
+#define ARRAY_NAME 256
 
 static int typeNameIndex = 0;
 static int typeNameSwap = 0;
@@ -88,9 +88,12 @@ DataType dtReference(DataType dt) {
     return dt;
 }
 
-DataType dtDereference(DataType dt) {
-    dt.pointers++;
-    return dt;
+bool dtDereference(DataType* dt) {
+    if(dt->pointers == 15) {
+        return true;
+    }
+    dt->pointers++;
+    return false;
 }
 
 bool dtCompare(DataType a, DataType b) {
@@ -98,14 +101,30 @@ bool dtCompare(DataType a, DataType b) {
            a.type == b.type;
 }
 
-int dtMaxDimensions() {
-    return 15;
+bool dtIsInt(DataType dt) {
+    return dtCompare(dt, dtInt());
+}
+
+bool dtIsFloat(DataType dt) {
+    return dtCompare(dt, dtFloat());
+}
+
+bool dtIsBool(DataType dt) {
+    return dtCompare(dt, dtBool());
+}
+
+bool dtIsVoid(DataType dt) {
+    return dtCompare(dt, dtVoid());
 }
 
 bool dtIsPointer(DataType dt) {
     return dt.pointers > 0;
 }
 
+bool dtIsVariable(DataType dt) {
+    return dt.type & 8;
+}
+
 Struct* dtGetStruct(Structs* sts, DataType dt) {
     if(dt.type != DT_STRUCT) {
         return NULL;
@@ -118,10 +137,6 @@ DataType dtToVariable(DataType dt) {
     return dt;
 }
 
-bool dtIsVariable(DataType dt) {
-    return dt.type & 8;
-}
-
 bool dtRemoveVariable(DataType* dt) {
     if(dtIsVariable(*dt)) {
         dt->type &= 7;

+ 8 - 4
DataType.h

@@ -47,15 +47,19 @@ DataType dtVoid();
 DataType dtStruct(Struct* st);
 
 DataType dtReference(DataType dt);
-DataType dtDereference(DataType dt);
-bool dtIsPointer(DataType dt);
+bool dtDereference(DataType* dt);
 Struct* dtGetStruct(Structs* sts, DataType dt);
 DataType dtToVariable(DataType dt);
-bool dtIsVariable(DataType dt);
 bool dtRemoveVariable(DataType* dt);
 
 bool dtCompare(DataType a, DataType b);
-int dtMaxDimensions();
+bool dtIsInt(DataType dt);
+bool dtIsFloat(DataType dt);
+bool dtIsBool(DataType dt);
+bool dtIsVoid(DataType dt);
+bool dtIsPointer(DataType dt);
+bool dtIsVariable(DataType dt);
+
 const char* dtGetName(Structs* sts, DataType dt);
 
 void stAddVariable(Struct* st, const char* name, DataType type);

+ 10 - 0
tests/mix

@@ -5,6 +5,10 @@ int test() {
     return 4;
 }
 
+int* wusi(int* a, int t) {
+    return a;
+}
+
 void main() {
     int a = 5;
     int b = 6;
@@ -21,4 +25,10 @@ void main() {
     a = *&a;
     
     a = test();
+    
+    a = - - - 3;
+    
+    (*wusi(c, a++))++;
+    (*wusi(c, a++))++;
+    int h = ~~3;
 }

+ 1 - 3
tokenizer/Tokenizer.c

@@ -289,11 +289,9 @@ bool tReadFloat(float* f) {
     return false;
 }
 
-const char* tReadString(int* length) {
-    *length = 0;
+const char* tReadString() {
     const char* s = tokenBuffer + readIndex;
     while(readIndex <= writeIndex) {
-        (*length)++;
         if(tokenBuffer[readIndex++] == '\0') {
             return s;
         }

+ 1 - 1
tokenizer/Tokenizer.h

@@ -17,7 +17,7 @@ Token tReadToken();
 bool tReadInt(int* i);
 bool tReadInt16(int16* i);
 bool tReadFloat(float* f);
-const char* tReadString(int* length);
+const char* tReadString();
 int tGetMarker();
 void tReset(int marker);
 

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini