Add void and char types
This commit is contained in:
parent
7cf752f67b
commit
6855360a97
@ -222,6 +222,10 @@ namespace types {
|
||||
return builder.builder->getInt32Ty();
|
||||
case FundamentalTypeKind::Bool:
|
||||
return builder.builder->getInt1Ty();
|
||||
case FundamentalTypeKind::Char:
|
||||
return builder.builder->getInt8Ty();
|
||||
case FundamentalTypeKind::Void:
|
||||
return builder.builder->getVoidTy();
|
||||
default:
|
||||
return builder.builder->getVoidTy();
|
||||
}
|
||||
|
||||
@ -14,8 +14,24 @@ namespace parsing {
|
||||
|
||||
stream.m_position = inner.m_position;
|
||||
|
||||
auto ty = new types::FundamentalType{ types::FundamentalTypeKind::Int };
|
||||
return std::unique_ptr<types::Type>{ ty };
|
||||
// TODO eventually make this be potentially more than one word
|
||||
std::string type_name = token.content;
|
||||
|
||||
if (type_name == "int") {
|
||||
auto ty = new types::FundamentalType{ types::FundamentalTypeKind::Int };
|
||||
return std::unique_ptr<types::Type>{ ty };
|
||||
}
|
||||
else if (type_name == "char") {
|
||||
auto ty = new types::FundamentalType{ types::FundamentalTypeKind::Char };
|
||||
return std::unique_ptr<types::Type>{ ty };
|
||||
}
|
||||
else if (type_name == "void") {
|
||||
auto ty = new types::FundamentalType{ types::FundamentalTypeKind::Void };
|
||||
return std::unique_ptr<types::Type>{ ty };
|
||||
}
|
||||
else {
|
||||
throw std::runtime_error("Expected type name, got " + type_name);
|
||||
}
|
||||
}
|
||||
catch (std::runtime_error& error) {
|
||||
return std::string{ error.what() };
|
||||
|
||||
@ -42,6 +42,12 @@ namespace types {
|
||||
switch (this->m_ty) {
|
||||
case FundamentalTypeKind::Int:
|
||||
return "Int";
|
||||
case FundamentalTypeKind::Bool:
|
||||
return "Bool";
|
||||
case FundamentalTypeKind::Char:
|
||||
return "Char";
|
||||
case FundamentalTypeKind::Void:
|
||||
return "Void";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
@ -20,7 +20,9 @@ namespace types {
|
||||
|
||||
enum FundamentalTypeKind {
|
||||
Int,
|
||||
Bool
|
||||
Bool,
|
||||
Char,
|
||||
Void,
|
||||
};
|
||||
|
||||
class Type {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user