Nicolas Winkler 6 سال پیش
والد
کامیت
a5d992206a
6فایلهای تغییر یافته به همراه70 افزوده شده و 22 حذف شده
  1. 1 1
      src/Ast.h
  2. 24 17
      src/Builtin.cpp
  3. 31 2
      src/Type.cpp
  4. 6 1
      src/Type.h
  5. 1 1
      src/parser.y
  6. 7 0
      src/test.qlw

+ 1 - 1
src/Ast.h

@@ -126,7 +126,7 @@ struct qlow::ast::Type : public AstObject
     }
     
     virtual std::string asString(void) const = 0;
-    virtual inline std::unique_ptr<sem::SemanticObject> accept(StructureVisitor& v, sem::Scope&) override { return nullptr; }
+    virtual inline std::unique_ptr<sem::SemanticObject> accept(StructureVisitor& v, sem::Scope&) override {}
 };
 
 

+ 24 - 17
src/Builtin.cpp

@@ -13,26 +13,33 @@ sem::NativeScope qlow::sem::generateNativeScope(void)
     
     NativeScope scope;
     
-    scope.types.insert(
-        {"Integer", std::make_unique<NativeType>(NativeType::INTEGER)}
-    );
-    
-    scope.types.insert(
-        {"Boolean", std::make_unique<NativeType>(NativeType::BOOLEAN)}
-    );
+    std::map<std::string, NativeType::Type> natives = {
+        { "Integer",    NativeType::INTEGER },
+        { "Boolean",    NativeType::BOOLEAN },
+        { "Char",       NativeType::CHAR },
+        { "String",     NativeType::STRING },
+        
+        { "Int8",       NativeType::INT8 },
+        { "Int16",      NativeType::INT16 },
+        { "Int32",      NativeType::INT32 },
+        { "Int64",      NativeType::INT64 },
+        { "Int128",     NativeType::INT128 },
+        
+        { "UInt8",      NativeType::UINT8 },
+        { "UInt16",     NativeType::UINT16 },
+        { "UInt32",     NativeType::UINT32 },
+        { "UInt64",     NativeType::UINT64 },
+        { "UInt128",    NativeType::UINT128 },
+        
+        { "Float32",    NativeType::FLOAT32 },
+        { "Float64",    NativeType::FLOAT64 },
+    };
     
-    return scope;
+    for (auto [name, type] : natives) {
+        scope.types.insert({ name, std::make_unique<NativeType>(type) });
+    }
     
-    /*
-    std::unique_ptr<sem::Type> int32 =
-        std::make_unique<sem::Type>(sem::Type::Kind::INTEGER, &sem::int32);
-    std::unique_ptr<sem::Type> boolean =
-        std::make_unique<sem::Type>(sem::Type::Kind::BOOLEAN, &sem::int32);
-        
-    scope.types.insert({"Integer", std::move(int32)});
-    scope.types.insert({"Boolean", std::move(boolean)});
     return scope;
-    */
 }
 
 

+ 31 - 2
src/Type.cpp

@@ -70,8 +70,37 @@ llvm::Type* sem::NativeType::getLlvmType (llvm::LLVMContext& context) const
             return llvm::Type::getInt32Ty(context);
         case BOOLEAN:
             return llvm::Type::getInt1Ty(context);
-        /*case Kind::CLASS:
-            return data.classType->llvmType;*/
+        case CHAR:
+            return llvm::Type::getInt32Ty(context);
+            
+        case INT8:
+            return llvm::Type::getInt8Ty(context);
+        case INT16:
+            return llvm::Type::getInt16Ty(context);
+        case INT32:
+            return llvm::Type::getInt32Ty(context);
+        case INT64:
+            return llvm::Type::getInt64Ty(context);
+        case INT128:
+            return llvm::Type::getInt128Ty(context);
+            
+        case UINT8:
+            return llvm::Type::getInt8Ty(context);
+        case UINT16:
+            return llvm::Type::getInt16Ty(context);
+        case UINT32:
+            return llvm::Type::getInt32Ty(context);
+        case UINT64:
+            return llvm::Type::getInt64Ty(context);
+        case UINT128:
+            return llvm::Type::getInt128Ty(context);
+            
+        case FLOAT32:
+            return llvm::Type::getFloatTy(context);
+        case FLOAT64:
+            return llvm::Type::getDoubleTy(context);
+        case FLOAT128:
+            return llvm::Type::getFP128Ty(context);
     }
 }
 

+ 6 - 1
src/Type.h

@@ -93,7 +93,12 @@ public:
     enum Type {
         VOID,
         INTEGER,
-        BOOLEAN
+        BOOLEAN,
+        CHAR,
+        STRING,
+        INT8, INT16, INT32, INT64, INT128,
+        UINT8, UINT16, UINT32, UINT64, UINT128,
+        FLOAT32, FLOAT64, FLOAT128,
     };
     
     Type type;

+ 1 - 1
src/parser.y

@@ -116,7 +116,7 @@ typedef qlow::CodePosition QLOW_PARSER_LTYPE;
 
     qlow::ast::UnaryOperation* unaryOperation;
     qlow::ast::BinaryOperation* binaryOperation;
-    
+
     qlow::ast::NewArrayExpression* newArrayExpression;
 
     const char* cString;

+ 7 - 0
src/test.qlw

@@ -18,6 +18,13 @@ end
 
 extern do_shit
 
+bignumbers do
+    a: Int128
+    b: Int128
+
+    b := b + a
+end
+
 main do
     value: Integer
     do_shit