diff --git a/src/Compiler/ModuleBuilder.cpp b/src/Compiler/ModuleBuilder.cpp index 18008d0..cb0fa73 100644 --- a/src/Compiler/ModuleBuilder.cpp +++ b/src/Compiler/ModuleBuilder.cpp @@ -70,7 +70,7 @@ void ModuleBuilder::buildStatement(shared_ptr statement) { buildRawFunction(dynamic_pointer_cast(statement)); break; case StatementKind::BLOB: - buildType(dynamic_pointer_cast(statement)); + buildBlob(dynamic_pointer_cast(statement)); break; case StatementKind::VARIABLE: buildVarDeclaration(dynamic_pointer_cast(statement)); @@ -164,10 +164,18 @@ void ModuleBuilder::buildRawFunction(shared_ptr statement) return; } -void ModuleBuilder::buildType(shared_ptr statement) { +void ModuleBuilder::buildBlob(shared_ptr statement) { llvm::StructType *structType = llvm::StructType::create(*context, statement->getIdentifier()); - vector elements; - structType->setBody(elements, false); + + // Generate types for body + vector types; + for (pair> &variable: statement->getVariables()) { + llvm::Type *type = typeForValueType(variable.second); + if (type == nullptr) + return; + types.push_back(type); + } + structType->setBody(types, false); if (!setStruct(statement->getIdentifier(), structType)) return; } diff --git a/src/Compiler/ModuleBuilder.h b/src/Compiler/ModuleBuilder.h index fef55a3..d63b0a7 100644 --- a/src/Compiler/ModuleBuilder.h +++ b/src/Compiler/ModuleBuilder.h @@ -71,7 +71,7 @@ private: void buildStatement(shared_ptr statement); void buildFunction(shared_ptr statement); void buildRawFunction(shared_ptr statement); - void buildType(shared_ptr statement); + void buildBlob(shared_ptr statement); void buildVarDeclaration(shared_ptr statement); void buildAssignment(shared_ptr statement); void buildBlock(shared_ptr statement); diff --git a/src/Logger.cpp b/src/Logger.cpp index 6ea6f3f..134009e 100644 --- a/src/Logger.cpp +++ b/src/Logger.cpp @@ -307,6 +307,8 @@ string Logger::toString(shared_ptr statement) { string text; text += format("BLOB(\"{}\"):\n", statement->getIdentifier()); + for (pair> &variable : statement->getVariables()) + text += format("{}: {}\n", variable.first, toString(variable.second)); return text; } diff --git a/src/Parser/Parser.cpp b/src/Parser/Parser.cpp index 1a9df82..2507a37 100644 --- a/src/Parser/Parser.cpp +++ b/src/Parser/Parser.cpp @@ -537,18 +537,6 @@ shared_ptr Parser::matchStatementBlob() { break; } - // consume new line - /*if (!tryMatchingTokenKinds({TokenKind::NEW_LINE}, true, true)) { - markError(TokenKind::NEW_LINE, {}); - return nullptr; - }*/ - - // closing semicolon - /*if(!tryMatchingTokenKinds({TokenKind::SEMICOLON}, false, true)) { - markError(TokenKind::SEMICOLON, {}); - return nullptr; - }*/ - return make_shared(identifier, variables); }