Browse Source

updated types

Nicolas Winkler 6 years ago
parent
commit
3f1d6f97cd

+ 13 - 3
src/Builtin.cpp

@@ -8,10 +8,20 @@ using namespace qlow;
 sem::NativeScope qlow::sem::generateNativeScope(Context& context)
 sem::NativeScope qlow::sem::generateNativeScope(Context& context)
 {
 {
     using sem::Class;
     using sem::Class;
-    using sem::NativeType;
     using sem::NativeScope;
     using sem::NativeScope;
     
     
     NativeScope scope{ context };
     NativeScope scope{ context };
+
+    std::map<std::string, Type::Native> natives = {
+        { "Void",       Type::Native::VOID },
+        { "Boolean",    Type::Native::BOOLEAN },
+        { "Integer",    Type::Native::INTEGER },
+    };
+
+    for (auto [name, type] : natives) {
+        TypeId id = context.addType(Type::createNativeType(context, name, type));
+        scope.addNativeType(name, type, id);
+    }
     
     
     /*std::map<std::string, NativeType::Type> natives = {
     /*std::map<std::string, NativeType::Type> natives = {
         { "Boolean",    NativeType::BOOLEAN },
         { "Boolean",    NativeType::BOOLEAN },
@@ -114,7 +124,7 @@ sem::NativeScope qlow::sem::generateNativeScope(Context& context)
     return scope;
     return scope;
 }
 }
 
 
-
+/*
 llvm::Value* qlow::sem::UnaryNativeMethod::generateCode(llvm::IRBuilder<>& builder,
 llvm::Value* qlow::sem::UnaryNativeMethod::generateCode(llvm::IRBuilder<>& builder,
     std::vector<llvm::Value*> arguments)
     std::vector<llvm::Value*> arguments)
 {
 {
@@ -132,7 +142,7 @@ llvm::Value* qlow::sem::BinaryNativeMethod::generateCode(llvm::IRBuilder<>& buil
     return generator(builder, arguments[0], arguments[1]);
     return generator(builder, arguments[0], arguments[1]);
 }
 }
 
 
-
+*/
 
 
 
 
 
 

+ 7 - 8
src/Builtin.h

@@ -23,8 +23,8 @@ namespace qlow
 
 
 struct qlow::sem::NativeMethod : public sem::Method
 struct qlow::sem::NativeMethod : public sem::Method
 {
 {
-    inline NativeMethod(Context& context, TypeId returnType) :
-        Method{ NativeScope::getInstance(), returnType }
+    inline NativeMethod(NativeScope& scope, TypeId returnType) :
+        Method{ scope, returnType }
     {
     {
     }
     }
     
     
@@ -37,11 +37,11 @@ struct qlow::sem::UnaryNativeMethod : public sem::NativeMethod
 {
 {
     std::function<llvm::Value*(llvm::IRBuilder<>&, llvm::Value*)> generator;
     std::function<llvm::Value*(llvm::IRBuilder<>&, llvm::Value*)> generator;
     
     
-    inline UnaryNativeMethod(Context& context,
+    inline UnaryNativeMethod(NativeScope& scope,
                              TypeId returnType,
                              TypeId returnType,
                              const std::function
                              const std::function
                              <llvm::Value*(llvm::IRBuilder<>&, llvm::Value*)>& generator) :
                              <llvm::Value*(llvm::IRBuilder<>&, llvm::Value*)>& generator) :
-        NativeMethod{ context, returnType },
+        NativeMethod{ scope, returnType },
         generator{ generator }
         generator{ generator }
     {
     {
     }
     }
@@ -59,12 +59,11 @@ struct qlow::sem::BinaryNativeMethod : public sem::NativeMethod
     Func generator;
     Func generator;
     Variable argument;
     Variable argument;
     
     
-    inline BinaryNativeMethod(Context& context,
+    inline BinaryNativeMethod(NativeScope& scope,
                               TypeId returnType,
                               TypeId returnType,
                               TypeId argumentType,
                               TypeId argumentType,
-        
-        Func&& generator) :
-        NativeMethod{ context, returnType },
+                              Func&& generator) :
+        NativeMethod{ scope, returnType },
         generator{ generator },
         generator{ generator },
         argument{ context, argumentType, "arg" }
         argument{ context, argumentType, "arg" }
     {
     {

+ 1 - 1
src/CMakeLists.txt

@@ -10,7 +10,7 @@ check_ipo_supported(RESULT ipo_supported)
 set(CMAKE_CXX_STANDARD 17)
 set(CMAKE_CXX_STANDARD 17)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
 
 
-set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -g -DDEBUGGING")
+set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -g -DDEBUGGING -std=gnu++17")
 
 
 find_package(BISON 3.0.0 REQUIRED)
 find_package(BISON 3.0.0 REQUIRED)
 find_package(FLEX 2.4.0 REQUIRED)
 find_package(FLEX 2.4.0 REQUIRED)

+ 11 - 2
src/CodegenVisitor.cpp

@@ -43,6 +43,7 @@ llvm::Value* ExpressionCodegenVisitor::visit(sem::UnaryOperation& unop, llvm::IR
         default:
         default:
             throw "operator not supported";
             throw "operator not supported";
     }*/
     }*/
+    return nullptr;
 }
 }
 
 
 
 
@@ -59,10 +60,11 @@ llvm::Value* ExpressionCodegenVisitor::visit(sem::BinaryOperation& binop, llvm::
     sem::Method* operation = binop.operationMethod;
     sem::Method* operation = binop.operationMethod;
     
     
     if (operation != nullptr) {
     if (operation != nullptr) {
-        if (sem::NativeMethod* nm = dynamic_cast<sem::NativeMethod*>(operation); nm) {
+        // TODO rewrite
+        /*if (sem::NativeMethod* nm = dynamic_cast<sem::NativeMethod*>(operation); nm) {
             return nm->generateCode(builder, {left, right});
             return nm->generateCode(builder, {left, right});
         }
         }
-        else
+        else*/
             throw "only native operations supported at the moment";
             throw "only native operations supported at the moment";
     }
     }
     else {
     else {
@@ -117,6 +119,7 @@ llvm::Value* ExpressionCodegenVisitor::visit(sem::CastExpression& cast, llvm::IR
         cast.expression->accept(*this, builder),
         cast.expression->accept(*this, builder),
         context.getType(cast.targetType).value().getLlvmType(builder.getContext())
         context.getType(cast.targetType).value().getLlvmType(builder.getContext())
     );*/
     );*/
+    return nullptr;
 }
 }
 
 
 
 
@@ -124,6 +127,7 @@ llvm::Value* ExpressionCodegenVisitor::visit(sem::NewArrayExpression& naexpr, ll
 {
 {
     using llvm::Value;
     using llvm::Value;
     // TODO implement
     // TODO implement
+    return nullptr;
 }
 }
 
 
 
 
@@ -161,6 +165,7 @@ llvm::Value* ExpressionCodegenVisitor::visit(sem::MethodCallExpression& call, ll
     //auto returnType = call.callee->returnType;
     //auto returnType = call.callee->returnType;
     llvm::CallInst* callInst = builder.CreateCall(call.callee->llvmNode, arguments);
     llvm::CallInst* callInst = builder.CreateCall(call.callee->llvmNode, arguments);
     return callInst;*/
     return callInst;*/
+    return nullptr;
 }
 }
 
 
 
 
@@ -193,6 +198,7 @@ llvm::Value* ExpressionCodegenVisitor::visit(sem::FieldAccessExpression& access,
     //                               llvm::APInt(32, 0, false)), 0);
     //                               llvm::APInt(32, 0, false)), 0);
     return llvm::ConstantInt::get(builder.getContext(),
     return llvm::ConstantInt::get(builder.getContext(),
                                    llvm::APInt(32, 0, false));*/
                                    llvm::APInt(32, 0, false));*/
+                                   return nullptr;
 }
 }
 
 
 
 
@@ -292,6 +298,7 @@ llvm::Value* LValueVisitor::visit(sem::FieldAccessExpression& access, llvm::IRBu
     };
     };
     Value* ptr = builder.CreateGEP(type, target, indexList);
     Value* ptr = builder.CreateGEP(type, target, indexList);
     return ptr;*/
     return ptr;*/
+    return nullptr;
 }
 }
 
 
 
 
@@ -339,6 +346,7 @@ llvm::Value* StatementVisitor::visit(sem::IfElseBlock& ifElseBlock,
     fg.popBlock();
     fg.popBlock();
     fg.popBlock();
     fg.popBlock();
     fg.pushBlock(merge);
     fg.pushBlock(merge);
+    return nullptr;
 }
 }
 
 
 
 
@@ -464,6 +472,7 @@ llvm::Value* CastGenerator::generateCast(llvm::Value* toCast,
     /*return b.CreateCast(
     /*return b.CreateCast(
         llvm::Instruction::CastOps::BitCast, toCast,
         llvm::Instruction::CastOps::BitCast, toCast,
         cast.to->getLlvmType(b.getContext()));*/
         cast.to->getLlvmType(b.getContext()));*/
+    return nullptr;
 }
 }
 
 
 
 

+ 5 - 1
src/Driver.cpp

@@ -69,7 +69,7 @@ Driver::Driver(int argc, char** argv) :
 }
 }
 
 
 
 
-int Driver::run(void)
+int Driver::run(void) try
 {
 {
     Printer& printer = Printer::getInstance();
     Printer& printer = Printer::getInstance();
 #ifdef DEBUGGING
 #ifdef DEBUGGING
@@ -157,6 +157,10 @@ int Driver::run(void)
     
     
     return 0;
     return 0;
 }
 }
+catch (InternalError& e) {
+    e.print(Printer::getInstance());
+    return 1;
+}
 
 
 
 
 bool Driver::parseStage(void)
 bool Driver::parseStage(void)

+ 35 - 21
src/ErrorReporting.cpp

@@ -4,13 +4,14 @@
 #include <fstream>
 #include <fstream>
 #include <sstream>
 #include <sstream>
 
 
+using qlow::InternalError;
 using qlow::CompileError;
 using qlow::CompileError;
 using qlow::SyntaxError;
 using qlow::SyntaxError;
 using qlow::SemanticError;
 using qlow::SemanticError;
 
 
 namespace qlow
 namespace qlow
 {
 {
-    void reportError(const CompileError& ce)
+    void reportError(const CompileError& ce) noexcept
     {
     {
         Printer& printer = Printer::getInstance();
         Printer& printer = Printer::getInstance();
         
         
@@ -18,21 +19,15 @@ namespace qlow
     }
     }
     
     
     
     
-    void reportError(const std::string& msg)
+    void reportError(const std::string& msg) noexcept
     {
     {
         Printer& printer = Printer::getInstance();
         Printer& printer = Printer::getInstance();
         
         
         printError(printer, msg);
         printError(printer, msg);
-        
-        printer <<
-            "\n"
-            "This kind of error isn't supposed to happen.\n\n"
-            "Please submit a bug report to nicolas.winkler@gmx.ch\n"
-        ;
     }
     }
 
 
 
 
-    void printError(Printer& printer, const std::string& msg)
+    void printError(Printer& printer, const std::string& msg) noexcept
     {
     {
         printer.bold();
         printer.bold();
         printer.foreground(Printer::RED, true);
         printer.foreground(Printer::RED, true);
@@ -42,7 +37,7 @@ namespace qlow
     }
     }
 
 
 
 
-    void printError(Printer& printer, const std::string& msg, const CodePosition& cp)
+    void printError(Printer& printer, const std::string& msg, const CodePosition& cp) noexcept
     {
     {
         printer.bold();
         printer.bold();
         printer << cp.getReportFormat() << ": "; //cp.filename << ":" << cp.first_line << ":" << cp.first_column << ": ";
         printer << cp.getReportFormat() << ": "; //cp.filename << ":" << cp.first_line << ":" << cp.first_column << ": ";
@@ -54,26 +49,45 @@ namespace qlow
 }
 }
 
 
 
 
-std::string qlow::CodePosition::getReportFormat(void) const
+std::string qlow::CodePosition::getReportFormat(void) const noexcept
 {
 {
     std::ostringstream s;
     std::ostringstream s;
-    if (filename == nullptr) {
-        s << first_line << ":" << first_column;
-    }
-    else {
-        s << filename << ":" << first_line << ":" << first_column;
-    }
+    s << filename << ":" << first_line << ":" << first_column;
     return s.str();
     return s.str();
 }
 }
 
 
 
 
+void InternalError::print(Printer& printer) const noexcept
+{
+    printError(printer, getMessage());
+    printer <<
+        "\n"
+        "This kind of error isn't supposed to happen.\n\n"
+        "Please submit a bug report to nicolas.winkler@gmx.ch\n"
+    ;
+}
+
+
+const std::string& InternalError::getMessage(void) const noexcept
+{
+    static std::map<ErrorCode, std::string> errors = {
+        {ErrorCode::OUT_OF_MEMORY, "out of memory"},
+        {ErrorCode::PARSER_INIT_FAILED, "parser initialization failed"},
+        {ErrorCode::PARSER_DEST_FAILED, "parser destruction failed"},
+        {ErrorCode::PARSER_FAILED, "parser failed"},
+        {ErrorCode::PARSER_FAILED, "invalid type encountered"},
+    };
+    return errors.at(errorCode);
+}
+
+
 CompileError::~CompileError(void)
 CompileError::~CompileError(void)
 {
 {
 }
 }
 
 
 
 
 // TODO rewrite more compact and more readable
 // TODO rewrite more compact and more readable
-void CompileError::underlineError(Printer& printer) const
+void CompileError::underlineError(Printer& printer) const noexcept
 {
 {
     std::ifstream file(where.filename);
     std::ifstream file(where.filename);
     
     
@@ -155,7 +169,7 @@ void CompileError::underlineError(Printer& printer) const
 }
 }
 
 
 
 
-void SyntaxError::print(Printer& printer) const
+void SyntaxError::print(Printer& printer) const noexcept
 {
 {
     using namespace std::literals;
     using namespace std::literals;
     if (message == "")
     if (message == "")
@@ -166,7 +180,7 @@ void SyntaxError::print(Printer& printer) const
 }
 }
 
 
 
 
-void SemanticError::print(Printer& printer) const
+void SemanticError::print(Printer& printer) const noexcept
 {
 {
     std::string errMsg = getMessage();
     std::string errMsg = getMessage();
     printError(printer, errMsg + (errMsg != "" ?  ": " : "") + message, where);
     printError(printer, errMsg + (errMsg != "" ?  ": " : "") + message, where);
@@ -174,7 +188,7 @@ void SemanticError::print(Printer& printer) const
 }
 }
 
 
 
 
-std::string SemanticError::getMessage(void) const
+std::string SemanticError::getMessage(void) const noexcept
 {
 {
     static const std::map<ErrorCode, std::string> error = {
     static const std::map<ErrorCode, std::string> error = {
         {UNKNOWN_TYPE, "unknown type"},
         {UNKNOWN_TYPE, "unknown type"},

+ 40 - 14
src/ErrorReporting.h

@@ -8,17 +8,18 @@ namespace qlow
 {
 {
     struct CodePosition;
     struct CodePosition;
     
     
+    class InternalError;
+
     class CompileError;
     class CompileError;
-    
     class SyntaxError;
     class SyntaxError;
     
     
     class SemanticError;
     class SemanticError;
     class NotLValue;
     class NotLValue;
     
     
-    void reportError(const CompileError& ce);
-    void reportError(const std::string& message);
-    void printError(Printer& printer, const std::string& message);
-    void printError(Printer& printer, const std::string& message, const CodePosition& where);
+    void reportError(const CompileError& ce) noexcept;
+    void reportError(const std::string& message) noexcept;
+    void printError(Printer& printer, const std::string& message) noexcept;
+    void printError(Printer& printer, const std::string& message, const CodePosition& where) noexcept;
 }
 }
 
 
 
 
@@ -27,7 +28,7 @@ namespace qlow
  */
  */
 struct qlow::CodePosition
 struct qlow::CodePosition
 {
 {
-    const char* filename = "";
+    std::string filename = "";
     int first_line;
     int first_line;
     int last_line;
     int last_line;
     int first_column;
     int first_column;
@@ -35,7 +36,32 @@ struct qlow::CodePosition
     
     
     inline bool isMultiline(void) const { return first_line != last_line; }
     inline bool isMultiline(void) const { return first_line != last_line; }
 
 
-    std::string getReportFormat(void) const;
+    std::string getReportFormat(void) const noexcept;
+};
+
+
+class qlow::InternalError
+{
+public:
+    enum ErrorCode
+    {
+        OUT_OF_MEMORY,
+        /// initialization of the flex lexer failed
+        PARSER_INIT_FAILED,
+        /// destruction of the flex lexer failed
+        PARSER_DEST_FAILED,
+        /// bison routine returned error value
+        PARSER_FAILED,
+        /// tried to determine the kind of an invalid type
+        INVALID_TYPE
+    };
+private:
+    ErrorCode errorCode;
+public:
+    InternalError(ErrorCode ec) :
+        errorCode{ ec } {}
+    void print(Printer& printer = Printer::getInstance()) const noexcept;
+    const std::string& getMessage(void) const noexcept;
 };
 };
 
 
 
 
@@ -50,9 +76,9 @@ public:
     }
     }
     
     
     virtual ~CompileError(void);
     virtual ~CompileError(void);
-    virtual void print(Printer& printer = Printer::getInstance()) const = 0;
+    virtual void print(Printer& printer = Printer::getInstance()) const noexcept = 0;
     
     
-    void underlineError(Printer& printer = Printer::getInstance()) const;
+    void underlineError(Printer& printer = Printer::getInstance()) const noexcept;
 };
 };
 
 
 
 
@@ -71,7 +97,7 @@ public:
     {
     {
     }
     }
     
     
-    virtual void print(Printer&) const override;
+    virtual void print(Printer&) const noexcept override;
 };
 };
 
 
 
 
@@ -109,8 +135,8 @@ public:
     {
     {
     }
     }
 
 
-    virtual void print(Printer& p = Printer::getInstance()) const override;
-    virtual std::string getMessage(void) const;
+    virtual void print(Printer& p = Printer::getInstance()) const noexcept override;
+    virtual std::string getMessage(void) const noexcept;
 };
 };
 
 
 
 
@@ -118,13 +144,13 @@ class qlow::NotLValue : public SemanticError
 {
 {
     std::string type;
     std::string type;
 public:
 public:
-    inline NotLValue(const std::string& type, const CodePosition& where) :
+    inline NotLValue(const std::string& type, const CodePosition& where) noexcept :
         SemanticError{ where },
         SemanticError{ where },
         type{ type }
         type{ type }
     {
     {
     }
     }
     
     
-    inline virtual std::string getMessage(void) const override
+    inline virtual std::string getMessage(void) const noexcept override
     {
     {
         return "Can't take address of non-lvalue value of type '" +
         return "Can't take address of non-lvalue value of type '" +
             type + "'";
             type + "'";

+ 32 - 20
src/Scope.cpp

@@ -3,6 +3,7 @@
 #include "Semantic.h"
 #include "Semantic.h"
 #include "Type.h"
 #include "Type.h"
 #include "Builtin.h"
 #include "Builtin.h"
+#include "Context.h"
 
 
 using namespace qlow;
 using namespace qlow;
 
 
@@ -22,7 +23,7 @@ sem::Method* sem::Scope::resolveMethod(const std::string& name,
         return nullptr;
         return nullptr;
     
     
     for (size_t i = 0; i < argumentTypes.size(); i++) {
     for (size_t i = 0; i < argumentTypes.size(); i++) {
-        if (!m->arguments[i]->type == argumentTypes[i])
+        if (m->arguments[i]->type != argumentTypes[i])
             return nullptr;
             return nullptr;
     }
     }
     
     
@@ -45,22 +46,26 @@ sem::Method* sem::GlobalScope::getMethod(const std::string& name)
 }
 }
 
 
 
 
-sem::TypeId sem::GlobalScope::getType(const ast::Type& name)
+sem::TypeId sem::GlobalScope::getType(const ast::Type* name)
 {
 {
-    if (const auto* arr = dynamic_cast<const ast::ArrayType*>(&name); arr) {
-        return context.getArrayOf(getType(*arr->arrayType));
+    if (name == nullptr) {
+        return context.getVoidTypeId();
+    }
+
+    if (const auto* arr = dynamic_cast<const ast::ArrayType*>(name); arr) {
+        return context.getArrayOf(getType(arr->arrayType.get()));
     }
     }
     
     
-    if (const auto* ptr = dynamic_cast<const ast::PointerType*>(&name)) {
-        return context.getPointerTo(getType(*ptr->derefType));
+    if (const auto* ptr = dynamic_cast<const ast::PointerType*>(name)) {
+        return context.getPointerTo(getType(ptr->derefType.get()));
     }
     }
     
     
-    auto native = NativeScope::getInstance().getType(name);
+    auto native = context.getNativeScope().getType(name);
     if (native) {
     if (native) {
         return native;
         return native;
     }
     }
     
     
-    const auto* classType = dynamic_cast<const ast::ClassType*>(&name);
+    const auto* classType = dynamic_cast<const ast::ClassType*>(name);
    
    
     if (!classType)
     if (!classType)
         throw "internal error, non class-type top-level type";
         throw "internal error, non class-type top-level type";
@@ -93,13 +98,13 @@ std::string sem::GlobalScope::toString(void)
 }
 }
 
 
 
 
-sem::TypeId sem::NativeScope::getType(const ast::Type& name)
+sem::TypeId sem::NativeScope::getType(const ast::Type* name)
 {
 {
-    if (const auto* arr = dynamic_cast<const ast::ArrayType*>(&name); arr) {
-        return context.getArrayOf(getType(*arr->arrayType));
+    if (const auto* arr = dynamic_cast<const ast::ArrayType*>(name); arr) {
+        return context.getArrayOf(getType(arr->arrayType.get()));
     }
     }
     
     
-    const auto* classType = dynamic_cast<const ast::ClassType*>(&name);
+    const auto* classType = dynamic_cast<const ast::ClassType*>(name);
    
    
     if (!classType)
     if (!classType)
         return NO_TYPE;
         return NO_TYPE;
@@ -113,12 +118,19 @@ sem::TypeId sem::NativeScope::getType(const ast::Type& name)
 }
 }
 
 
 
 
-// TODO rewrite
-static sem::Context c;
-sem::NativeScope sem::NativeScope::instance = sem::generateNativeScope(c);
-sem::NativeScope& sem::NativeScope::getInstance(void)
+sem::TypeId sem::NativeScope::getType(Type::Native nt)
+{
+    if (typesByNative.find(nt) == typesByNative.end())
+        return sem::NO_TYPE;
+    else
+        return typesByNative[nt];
+}
+
+
+void sem::NativeScope::addNativeType(std::string name, Type::Native nt, TypeId id)
 {
 {
-    return instance;
+    types.emplace(std::move(name), id);
+    typesByNative.emplace(nt, id);
 }
 }
 
 
 
 
@@ -168,7 +180,7 @@ std::string sem::ClassScope::toString(void)
 }
 }
 
 
 
 
-sem::TypeId sem::ClassScope::getType(const ast::Type& name)
+sem::TypeId sem::ClassScope::getType(const ast::Type* name)
 {
 {
     return parentScope.getType(name);
     return parentScope.getType(name);
 }
 }
@@ -231,7 +243,7 @@ sem::Method* sem::LocalScope::getMethod(const std::string& name)
 }
 }
 
 
 
 
-sem::TypeId sem::LocalScope::getType(const ast::Type& name)
+sem::TypeId sem::LocalScope::getType(const ast::Type* name)
 {
 {
     return parentScope.getType(name);
     return parentScope.getType(name);
 }
 }
@@ -283,7 +295,7 @@ sem::Method* sem::TypeScope::getMethod(const std::string& name)
 }
 }
 
 
 
 
-sem::TypeId sem::TypeScope::getType(const ast::Type& name)
+sem::TypeId sem::TypeScope::getType(const ast::Type* name)
 {
 {
     return NO_TYPE;
     return NO_TYPE;
 }
 }

+ 13 - 13
src/Scope.h

@@ -9,6 +9,7 @@
 #include <llvm/IR/Value.h>
 #include <llvm/IR/Value.h>
 
 
 #include "Util.h"
 #include "Util.h"
+#include "Type.h"
 #include "Context.h"
 #include "Context.h"
 
 
 namespace qlow
 namespace qlow
@@ -40,8 +41,9 @@ namespace qlow
         class NativeTypeScope;
         class NativeTypeScope;
         
         
         class Type;
         class Type;
-        class NativeType;
     }
     }
+    
+    class Context;
 }
 }
 
 
 
 
@@ -56,7 +58,7 @@ public:
     virtual ~Scope(void);
     virtual ~Scope(void);
     virtual Variable* getVariable(const std::string& name) = 0;
     virtual Variable* getVariable(const std::string& name) = 0;
     virtual Method* getMethod(const std::string& name) = 0;
     virtual Method* getMethod(const std::string& name) = 0;
-    virtual TypeId getType(const ast::Type& name) = 0;
+    virtual TypeId getType(const ast::Type* name) = 0;
     virtual TypeId getReturnableType(void) = 0;
     virtual TypeId getReturnableType(void) = 0;
     virtual Method* resolveMethod(const std::string& name,
     virtual Method* resolveMethod(const std::string& name,
         const std::vector<TypeId> argumentTypes);
         const std::vector<TypeId> argumentTypes);
@@ -73,15 +75,13 @@ public:
     SymbolTable<Class> classes;
     SymbolTable<Class> classes;
     SymbolTable<Method> functions;
     SymbolTable<Method> functions;
     //OwningList<Cast> casts;
     //OwningList<Cast> casts;
-
-    Context typeContext;
 public:
 public:
     inline GlobalScope(Context& context) :
     inline GlobalScope(Context& context) :
         Scope{ context } {}
         Scope{ context } {}
 
 
     virtual Variable* getVariable(const std::string& name);
     virtual Variable* getVariable(const std::string& name);
     virtual Method* getMethod(const std::string& name);
     virtual Method* getMethod(const std::string& name);
-    virtual TypeId getType(const ast::Type& name);
+    virtual TypeId getType(const ast::Type* name);
     virtual TypeId getReturnableType(void);
     virtual TypeId getReturnableType(void);
 
 
     inline const SymbolTable<Class>& getClasses(void) const { return classes; }
     inline const SymbolTable<Class>& getClasses(void) const { return classes; }
@@ -93,18 +93,18 @@ public:
 
 
 class qlow::sem::NativeScope : public GlobalScope
 class qlow::sem::NativeScope : public GlobalScope
 {
 {
-    static NativeScope instance;
-public:
+protected:
     std::unordered_map<std::string, TypeId> types;
     std::unordered_map<std::string, TypeId> types;
+    std::map<Type::Native, TypeId> typesByNative;
 public:
 public:
     inline NativeScope(Context& context) :
     inline NativeScope(Context& context) :
         GlobalScope{ context } {}
         GlobalScope{ context } {}
 
 
-    virtual TypeId getType(const ast::Type& name);
+    virtual TypeId getType(const ast::Type* name);
+    virtual TypeId getType(Type::Native nt);
+    virtual void addNativeType(std::string name, Type::Native nt, TypeId id);
 
 
     virtual std::string toString(void);
     virtual std::string toString(void);
-    
-    static NativeScope& getInstance(void);
 };
 };
 
 
 
 
@@ -121,7 +121,7 @@ public:
     }
     }
     virtual Variable* getVariable(const std::string& name);
     virtual Variable* getVariable(const std::string& name);
     virtual Method* getMethod(const std::string& name);
     virtual Method* getMethod(const std::string& name);
-    virtual TypeId getType(const ast::Type& name);
+    virtual TypeId getType(const ast::Type* name);
     virtual TypeId getReturnableType(void);
     virtual TypeId getReturnableType(void);
     virtual std::string toString(void);
     virtual std::string toString(void);
 };
 };
@@ -142,7 +142,7 @@ public:
 
 
     virtual Variable* getVariable(const std::string& name);
     virtual Variable* getVariable(const std::string& name);
     virtual Method* getMethod(const std::string& name);
     virtual Method* getMethod(const std::string& name);
-    virtual TypeId getType(const ast::Type& name);
+    virtual TypeId getType(const ast::Type* name);
     virtual TypeId getReturnableType(void);
     virtual TypeId getReturnableType(void);
     virtual std::string toString(void);
     virtual std::string toString(void);
 };
 };
@@ -161,7 +161,7 @@ public:
     
     
     virtual Variable* getVariable(const std::string& name);
     virtual Variable* getVariable(const std::string& name);
     virtual Method* getMethod(const std::string& name);
     virtual Method* getMethod(const std::string& name);
-    virtual TypeId getType(const ast::Type& name);
+    virtual TypeId getType(const ast::Type* name);
     virtual TypeId getReturnableType(void);
     virtual TypeId getReturnableType(void);
     virtual std::string toString(void);
     virtual std::string toString(void);
 };
 };

+ 5 - 0
src/ast/Ast.cpp

@@ -60,6 +60,11 @@ qlow::ast::IntConst::IntConst(std::string&& val, const qlow::CodePosition& p) :
 {
 {
 }
 }
 
 
+std::unique_ptr<qlow::sem::SemanticObject> qlow::ast::Type::accept(StructureVisitor&, sem::Scope&)
+{
+    return nullptr;
+}
+
 
 
 
 
 
 

+ 1 - 1
src/ast/Ast.h

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

+ 12 - 12
src/ast/AstVisitor.cpp

@@ -29,8 +29,8 @@ std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::FieldDeclarati
 {
 {
     auto f = std::make_unique<sem::Field>(scope.getContext());
     auto f = std::make_unique<sem::Field>(scope.getContext());
     f->name = ast.name;
     f->name = ast.name;
-    auto type = scope.getType(*ast.type);
-    if (type) {
+    auto type = scope.getType(ast.type.get());
+    if (type != sem::NO_TYPE) {
         f->type = type;
         f->type = type;
     }
     }
     else {
     else {
@@ -45,8 +45,8 @@ std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::FieldDeclarati
 
 
 std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::MethodDefinition& ast, sem::Scope& scope)
 std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::MethodDefinition& ast, sem::Scope& scope)
 {
 {
-    auto returnType = scope.getType(*ast.type);
-    if (!returnType) {
+    auto returnType = scope.getType(ast.type.get());
+    if (returnType == sem::NO_TYPE) {
         throw SemanticError(SemanticError::UNKNOWN_TYPE,
         throw SemanticError(SemanticError::UNKNOWN_TYPE,
             ast.type->asString(),
             ast.type->asString(),
             ast.type->pos
             ast.type->pos
@@ -80,9 +80,9 @@ std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::VariableDeclar
 {
 {
     auto v = std::make_unique<sem::Variable>(scope.getContext());
     auto v = std::make_unique<sem::Variable>(scope.getContext());
     v->name = ast.name;
     v->name = ast.name;
-    auto type = scope.getType(*ast.type);
-    if (type) {
-        v->type = std::move(type);
+    auto type = scope.getType(ast.type.get());
+    if (type != sem::NO_TYPE) {
+        v->type = type;
     }
     }
     else {
     else {
         throw SemanticError(SemanticError::UNKNOWN_TYPE,
         throw SemanticError(SemanticError::UNKNOWN_TYPE,
@@ -111,9 +111,9 @@ std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::DoEndBlock& as
     for (auto& statement : ast.statements) {
     for (auto& statement : ast.statements) {
         
         
         if (ast::LocalVariableStatement* nvs = dynamic_cast<ast::LocalVariableStatement*>(statement.get()); nvs) {
         if (ast::LocalVariableStatement* nvs = dynamic_cast<ast::LocalVariableStatement*>(statement.get()); nvs) {
-            auto type = body->scope.getType(*nvs->type);
+            auto type = body->scope.getType(nvs->type.get());
 
 
-            if (!type)
+            if (type == sem::NO_TYPE)
                 throw SemanticError(SemanticError::UNKNOWN_TYPE,
                 throw SemanticError(SemanticError::UNKNOWN_TYPE,
                                     nvs->type->asString(),
                                     nvs->type->asString(),
                                     nvs->type->pos);
                                     nvs->type->pos);
@@ -414,7 +414,7 @@ std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::BinaryOperatio
 
 
 std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::NewArrayExpression& ast, sem::Scope& scope)
 std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::NewArrayExpression& ast, sem::Scope& scope)
 {
 {
-    auto ret = std::make_unique<sem::NewArrayExpression>(scope.getContext(), scope.getType(*ast.type));
+    auto ret = std::make_unique<sem::NewArrayExpression>(scope.getContext(), scope.getType(ast.type.get()));
     return ret;
     return ret;
 }
 }
 
 
@@ -422,8 +422,8 @@ std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::NewArrayExpres
 std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::CastExpression& ast, sem::Scope& scope)
 std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::CastExpression& ast, sem::Scope& scope)
 {
 {
     auto expr = unique_dynamic_cast<sem::Expression>(ast.expression->accept(*this, scope));
     auto expr = unique_dynamic_cast<sem::Expression>(ast.expression->accept(*this, scope));
-    auto type = scope.getType(*ast.targetType);
+    auto type = scope.getType(ast.targetType.get());
     return std::make_unique<sem::CastExpression>(
     return std::make_unique<sem::CastExpression>(
-        std::move(expr), std::move(type), &ast);
+        std::move(expr), type, &ast);
 }
 }
 
 

+ 14 - 2
src/ast/Parser.cpp

@@ -7,9 +7,21 @@ qlow::ast::Ast Parser::parse(void)
 {
 {
     qlow::ast::Ast result;
     qlow::ast::Ast result;
     yyscan_t scanner;
     yyscan_t scanner;
-    qlow_parser_lex_init(&scanner);
+    int lexInit = qlow_parser_lex_init(&scanner);
+
+    if (lexInit != 0)
+        throw qlow::InternalError(InternalError::PARSER_INIT_FAILED);
+
     qlow_parser_set_in(this->stream, scanner);
     qlow_parser_set_in(this->stream, scanner);
     auto error = qlow_parser_parse(scanner, result, *this);
     auto error = qlow_parser_parse(scanner, result, *this);
-    qlow_parser_lex_destroy(scanner);
+
+    if (error != 0)
+        throw qlow::InternalError(InternalError::PARSER_FAILED);
+
+    int lexDest = qlow_parser_lex_destroy(scanner);
+
+    if (lexDest != 0)
+        throw qlow::InternalError(InternalError::PARSER_DEST_FAILED);
+
     return result;
     return result;
 }
 }

+ 13 - 12
src/ast/lexer.l

@@ -26,14 +26,15 @@
 
 
 %option 8bit
 %option 8bit
 %option header-file="lexer.h"
 %option header-file="lexer.h"
+%option extra-type="std::string"
 
 
 %{
 %{
+
+
 #include "Parser.h"
 #include "Parser.h"
 #include "syntax.hpp"
 #include "syntax.hpp"
 
 
 
 
-#define yylval qlow_parser_lval
-#define YY_EXTRA_TYPE size_t
 #define SET_TOKEN(t) (yylval_param->token = t)
 #define SET_TOKEN(t) (yylval_param->token = t)
 #define SET_STRING (yylval_param->string = new std::string(yytext, yyleng))
 #define SET_STRING (yylval_param->string = new std::string(yytext, yyleng))
 
 
@@ -43,11 +44,11 @@ extern "C" int qlow_parser_wrap(yyscan_t s);
 #define YY_USER_ACTION                                \
 #define YY_USER_ACTION                                \
   do {                                                \
   do {                                                \
     yylloc_param->first_line = yylineno;              \
     yylloc_param->first_line = yylineno;              \
-    yylloc_param->first_column = yyg->yyextra_r;      \
-    yyg->yyextra_r += yyleng;                         \
+    yylloc_param->first_column = yycolumn;            \
+    yycolumn += yyleng;                               \
     yylloc_param->last_line = yylineno;               \
     yylloc_param->last_line = yylineno;               \
-    yylloc_param->last_column = yyg->yyextra_r;       \
-    yylloc_param->filename = nullptr;                 \
+    yylloc_param->last_column = yycolumn;             \
+    yylloc_param->filename = yyextra;                 \
   } while(0);
   } while(0);
 %}
 %}
 
 
@@ -67,16 +68,16 @@ UTF8CHAR [\x00-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xe
     int commentDepth = 0;
     int commentDepth = 0;
 
 
 <COMMENT>"/*"           commentDepth++;
 <COMMENT>"/*"           commentDepth++;
-<COMMENT>"*/"           if ((--commentDepth) == 0) { BEGIN(INITIAL); };
-<COMMENT>\n             yyg->yyextra_r = 0;
+<COMMENT>"*/"           if ((--commentDepth) <= 0) { yy_pop_state(yyscanner); };
+<COMMENT>\n             yycolumn = 0;
 <COMMENT>.              ; // inside comment, ignore everything
 <COMMENT>.              ; // inside comment, ignore everything
 
 
-<LINE_COMMENT>\n        yyg->yyextra_r = 0; yy_pop_state(yyscanner); //yy_push_state(INITIAL);
+<LINE_COMMENT>"\n"      yycolumn = 0; yy_pop_state(yyscanner); //yy_push_state(INITIAL);
 <LINE_COMMENT>.         ; // inside comment, ignore everything
 <LINE_COMMENT>.         ; // inside comment, ignore everything
 
 
 <STRING>"\""            yy_pop_state(yyscanner);
 <STRING>"\""            yy_pop_state(yyscanner);
 <STRING>[^\"^\n]*          printf("%s\n", std::string(yytext, yyleng).c_str());
 <STRING>[^\"^\n]*          printf("%s\n", std::string(yytext, yyleng).c_str());
-<STRING>\n              yyg->yyextra_r = 0; SET_STRING; return UNEXPECTED_SYMBOL; 
+<STRING>\n              yycolumn = 0; SET_STRING; return UNEXPECTED_SYMBOL; 
 
 
 "/*"                    yy_push_state(COMMENT, yyscanner); commentDepth = 1;
 "/*"                    yy_push_state(COMMENT, yyscanner); commentDepth = 1;
 "//"                    yy_push_state(LINE_COMMENT, yyscanner);
 "//"                    yy_push_state(LINE_COMMENT, yyscanner);
@@ -84,8 +85,8 @@ UTF8CHAR [\x00-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xe
 
 
 
 
 [\t ]                   ; // Space or tab ignored
 [\t ]                   ; // Space or tab ignored
-<METHOD>\n              yyg->yyextra_r = 0; return SET_TOKEN(NEW_LINE);
-\n                      yyg->yyextra_r = 0; //return SET_TOKEN(NEW_LINE);
+<METHOD>\n              yycolumn = 0; return SET_TOKEN(NEW_LINE);
+\n                      yycolumn = 0; //return SET_TOKEN(NEW_LINE);
 
 
 "class"                 return SET_TOKEN(CLASS);
 "class"                 return SET_TOKEN(CLASS);
 "do"                    yy_push_state(METHOD, yyscanner); return SET_TOKEN(DO);
 "do"                    yy_push_state(METHOD, yyscanner); return SET_TOKEN(DO);

+ 6 - 4
src/ast/syntax.y

@@ -33,6 +33,7 @@ using YYSTYPE = QLOW_PARSER_STYPE;
 #define YY_TYPEDEF_YY_SCANNER_T
 #define YY_TYPEDEF_YY_SCANNER_T
 typedef void* yyscan_t;
 typedef void* yyscan_t;
 #endif
 #endif
+//#define qlow_parser_lex(a,b,c)  (({ auto v = qlow_parser_lex(a, b, c); v; }))
 }
 }
 
 
 %{
 %{
@@ -75,7 +76,7 @@ do                                                        \
       (Cur).first_column = YYRHSLOC(Rhs, 1).first_column; \
       (Cur).first_column = YYRHSLOC(Rhs, 1).first_column; \
       (Cur).last_line    = YYRHSLOC(Rhs, N).last_line;    \
       (Cur).last_line    = YYRHSLOC(Rhs, N).last_line;    \
       (Cur).last_column  = YYRHSLOC(Rhs, N).last_column;  \
       (Cur).last_column  = YYRHSLOC(Rhs, N).last_column;  \
-      (Cur).filename     = YYRHSLOC(Rhs, 1).filename;     \
+      (Cur).filename     = parser.getFilename().c_str();  \
     }                                                     \
     }                                                     \
   else                                                    \
   else                                                    \
     {                                                     \
     {                                                     \
@@ -83,7 +84,7 @@ do                                                        \
         YYRHSLOC(Rhs, 0).last_line;                       \
         YYRHSLOC(Rhs, 0).last_line;                       \
       (Cur).first_column = (Cur).last_column =            \
       (Cur).first_column = (Cur).last_column =            \
         YYRHSLOC(Rhs, 0).last_column;                     \
         YYRHSLOC(Rhs, 0).last_column;                     \
-      (Cur).filename = YYRHSLOC(Rhs, 0).filename;         \
+      (Cur).filename = parser.getFilename().c_str();      \
     }                                                     \
     }                                                     \
 while (0)
 while (0)
 %}
 %}
@@ -107,10 +108,11 @@ while (0)
 {
 {
     // NOTE: the filename only lives as long as the parser.
     // NOTE: the filename only lives as long as the parser.
     // Do not use after deletion of the parser.
     // Do not use after deletion of the parser.
-    @$.filename = parser.getFilename().c_str();
+    const auto* filename = parser.getFilename().c_str();
+    @$.filename = filename;
+    qlow_parser_set_extra(parser.getFilename(), scanner);
 };
 };
 
 
-//%define api.location.type {qlow::CodePosition}
 
 
 %union {
 %union {
     qlow::ast::Ast* topLevel;
     qlow::ast::Ast* topLevel;

+ 34 - 2
src/sem/Context.cpp

@@ -1,5 +1,7 @@
 #include "Context.h"
 #include "Context.h"
-#include "Type.h"
+#include "Semantic.h"
+#include "Scope.h"
+#include "Builtin.h"
 
 
 using qlow::sem::Context;
 using qlow::sem::Context;
 
 
@@ -9,6 +11,12 @@ size_t std::hash<std::reference_wrapper<qlow::sem::Type>>::operator() (const std
 }
 }
 
 
 
 
+Context::Context(void)
+{
+    nativeScope = std::make_unique<NativeScope>(sem::generateNativeScope(*this));
+}
+
+
 qlow::sem::TypeId Context::addType(Type&& type) {
 qlow::sem::TypeId Context::addType(Type&& type) {
     if (typesMap.find(type) != typesMap.end()) {
     if (typesMap.find(type) != typesMap.end()) {
         return typesMap[type];
         return typesMap[type];
@@ -22,7 +30,7 @@ qlow::sem::TypeId Context::addType(Type&& type) {
 
 
 std::optional<std::reference_wrapper<qlow::sem::Type>> Context::getType(TypeId tid)
 std::optional<std::reference_wrapper<qlow::sem::Type>> Context::getType(TypeId tid)
 {
 {
-    if (tid >= 0 && tid <= types.size()) {
+    if (tid <= types.size()) {
         return std::make_optional<std::reference_wrapper<qlow::sem::Type>>(types[tid]);
         return std::make_optional<std::reference_wrapper<qlow::sem::Type>>(types[tid]);
     }
     }
     else {
     else {
@@ -42,3 +50,27 @@ qlow::sem::TypeId Context::getArrayOf(TypeId id)
     return addType(Type::createArrayType(*this, id));
     return addType(Type::createArrayType(*this, id));
 }
 }
 
 
+
+qlow::sem::TypeId Context::getVoidTypeId(void)
+{
+    return getNativeTypeId(Type::Native::VOID);
+}
+
+
+qlow::sem::TypeId Context::getNativeTypeId(Type::Native n)
+{
+    return nativeScope->getType(n);
+}
+
+
+std::unique_ptr<qlow::sem::TypeScope> Context::getTypeScope(TypeId id)
+{
+    return std::make_unique<TypeScope>(*this, id);
+}
+
+
+qlow::sem::NativeScope& Context::getNativeScope(void)
+{
+    return *nativeScope;
+}
+

+ 13 - 1
src/sem/Context.h

@@ -12,6 +12,9 @@ namespace qlow::sem
 {
 {
     class Type;
     class Type;
     class Context;
     class Context;
+
+    class TypeScope;
+    class NativeScope;
 }
 }
 
 
 namespace std
 namespace std
@@ -27,17 +30,26 @@ namespace std
 class qlow::sem::Context
 class qlow::sem::Context
 {
 {
 private:
 private:
-    std::string test = "ayayay";
     std::vector<Type> types;
     std::vector<Type> types;
     std::unordered_map<std::reference_wrapper<Type>, TypeId, std::hash<std::reference_wrapper<Type>>, std::equal_to<Type>> typesMap;
     std::unordered_map<std::reference_wrapper<Type>, TypeId, std::hash<std::reference_wrapper<Type>>, std::equal_to<Type>> typesMap;
     
     
+    std::unique_ptr<NativeScope> nativeScope;
+
 public:
 public:
+    Context(void);
     
     
     TypeId addType(Type&& type);
     TypeId addType(Type&& type);
     std::optional<std::reference_wrapper<Type>> getType(TypeId tid);
     std::optional<std::reference_wrapper<Type>> getType(TypeId tid);
 
 
     TypeId getPointerTo(TypeId id);
     TypeId getPointerTo(TypeId id);
     TypeId getArrayOf(TypeId id);
     TypeId getArrayOf(TypeId id);
+
+
+    TypeId getVoidTypeId(void);
+    TypeId getNativeTypeId(Type::Native n);
+
+    std::unique_ptr<TypeScope> getTypeScope(TypeId);
+    NativeScope& getNativeScope(void);
 };
 };
 
 
 #endif // QLOW_SEM_CONTEXT_H
 #endif // QLOW_SEM_CONTEXT_H

+ 4 - 4
src/sem/Semantic.cpp

@@ -70,14 +70,14 @@ std::pair<std::unique_ptr<Context>, std::unique_ptr<GlobalScope>>
     }
     }
     
     
     for (auto& [name, method] : globalScope->functions) {
     for (auto& [name, method] : globalScope->functions) {
-        auto returnType = globalScope->getType(*method->astNode->type);
-        if (returnType) {
+        auto returnType = globalScope->getType(method->astNode->type.get());
+        if (returnType != NO_TYPE) {
             method->returnType = returnType;
             method->returnType = returnType;
         }
         }
         else {
         else {
             SemanticError se(SemanticError::UNKNOWN_TYPE,
             SemanticError se(SemanticError::UNKNOWN_TYPE,
-                             method->astNode->type->asString(),
-                             method->astNode->type->pos);
+                            method->astNode->type->asString(),
+                            method->astNode->type->pos);
         }
         }
         
         
         // otherwise add to the methods list
         // otherwise add to the methods list

+ 5 - 5
src/sem/Semantic.h

@@ -170,11 +170,11 @@ struct qlow::sem::Method : public SemanticObject
         SemanticObject{ parentScope.getContext() },
         SemanticObject{ parentScope.getContext() },
         containingClass{ nullptr },
         containingClass{ nullptr },
         returnType{ parentScope.getReturnableType()},
         returnType{ parentScope.getReturnableType()},
-        astNode{ astNode },
         name{ astNode->name },
         name{ astNode->name },
-        scope{ parentScope, this },
+        astNode{ astNode },
         thisExpression{ nullptr },
         thisExpression{ nullptr },
-        body{ nullptr }
+        body{ nullptr },
+        scope{ parentScope, this }
     {
     {
     }
     }
     
     
@@ -332,7 +332,7 @@ struct qlow::sem::LocalVariableExpression : public Expression
     inline virtual bool isLValue(void) const override { return true; }
     inline virtual bool isLValue(void) const override { return true; }
 
 
     virtual llvm::Value* accept(ExpressionCodegenVisitor& visitor, llvm::IRBuilder<>& arg2) override;
     virtual llvm::Value* accept(ExpressionCodegenVisitor& visitor, llvm::IRBuilder<>& arg2) override;
-    virtual llvm::Value* accept(LValueVisitor& visitor, llvm::IRBuilder<>& arg2);
+    virtual llvm::Value* accept(LValueVisitor& visitor, llvm::IRBuilder<>& arg2) override;
     virtual std::string toString(void) const override;
     virtual std::string toString(void) const override;
 };
 };
 
 
@@ -475,7 +475,7 @@ struct qlow::sem::IntConst : public Expression
     unsigned long long value;
     unsigned long long value;
 
 
     inline IntConst(Context& context, unsigned long long value) :
     inline IntConst(Context& context, unsigned long long value) :
-        Expression{ context, context.addType(Type::createNativeType(context, "integer")) },
+        Expression{ context, context.getNativeTypeId(Type::Native::INTEGER) },
         value{ value }
         value{ value }
     {
     {
     }
     }

+ 5 - 2
src/sem/Type.cpp

@@ -1,6 +1,7 @@
 #include "Type.h"
 #include "Type.h"
 
 
 #include "Context.h"
 #include "Context.h"
+#include "ErrorReporting.h"
 
 
 using qlow::sem::TypeId;
 using qlow::sem::TypeId;
 using qlow::sem::Type;
 using qlow::sem::Type;
@@ -28,6 +29,8 @@ Type::Kind Type::getKind(void) const
         case 2: return Kind::POINTER;
         case 2: return Kind::POINTER;
         case 3: return Kind::ARRAY;
         case 3: return Kind::ARRAY;
     }
     }
+    // should never arrive here
+    throw InternalError(InternalError::INVALID_TYPE);
 }
 }
 
 
 
 
@@ -90,9 +93,9 @@ llvm::Type* Type::getLLVMType(llvm::LLVMContext* context)
 }
 }
 
 
 
 
-Type Type::createNativeType(Context& c, std::string name)
+Type Type::createNativeType(Context& c, std::string name, Native type)
 {
 {
-    return Type{ Union{ NativeType{} }, std::move(name) };
+    return Type{ Union{ NativeType{ type } }, std::move(name) };
 }
 }
 
 
 
 

+ 12 - 2
src/sem/Type.h

@@ -62,6 +62,7 @@ public:
 
 
 class qlow::sem::Type
 class qlow::sem::Type
 {
 {
+    friend class Context;
 public:
 public:
     enum class Kind
     enum class Kind
     {
     {
@@ -70,12 +71,21 @@ public:
         POINTER,
         POINTER,
         ARRAY
         ARRAY
     };
     };
+
+    enum class Native
+    {
+        VOID,
+        BOOLEAN,
+        INTEGER,
+    };
+
 private:
 private:
     std::string name;
     std::string name;
 
 
     struct NativeType
     struct NativeType
     {
     {
-        inline bool operator==(const NativeType& other) const { return true; }
+        Native type;
+        inline bool operator==(const NativeType& other) const { return type == other.type; }
     };
     };
 
 
     struct ClassType
     struct ClassType
@@ -116,7 +126,7 @@ public:
 
 
     llvm::Type* getLLVMType(llvm::LLVMContext* context);
     llvm::Type* getLLVMType(llvm::LLVMContext* context);
 
 
-    static Type createNativeType(Context& c, std::string name);
+    static Type createNativeType(Context& c, std::string name, Native type);
     static Type createClassType(Context& c, Class* classType);
     static Type createClassType(Context& c, Class* classType);
     static Type createPointerType(Context& c, TypeId pointsTo);
     static Type createPointerType(Context& c, TypeId pointsTo);
     static Type createArrayType(Context& c, TypeId pointsTo);
     static Type createArrayType(Context& c, TypeId pointsTo);

+ 2 - 1
src/test.qlw

@@ -6,7 +6,6 @@ fast_fibonacci(i: Integer): Integer do
     count := i
     count := i
     a := 0
     a := 0
     b := 1
     b := 1
-    //b := a <=> b
     while count != 0 do
     while count != 0 do
         temp := a
         temp := a
         a := a + b
         a := a + b
@@ -19,6 +18,7 @@ end
 //extern do_shit
 //extern do_shit
 
 
 
 
+/*
 bignumbers do
 bignumbers do
     a: Int128
     a: Int128
     b: Int128
     b: Int128
@@ -27,6 +27,7 @@ bignumbers do
     b := a + c as Int128
     b := a + c as Int128
     //c := b as Int64
     //c := b as Int64
 end
 end
+*/
 
 
 main: Integer do
 main: Integer do
     value: Integer
     value: Integer