Skip to content

Commit 3ca2a52

Browse files
committed
Now all types are capitalized
1 parent 7cb550f commit 3ca2a52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+276
-278
lines changed

src/ast.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ bool ast::InterfaceType::operator!=(const InterfaceType &interface) const {
1616

1717
ast::Type ast::InterfaceType::get_default_type() {
1818
if (this->name== "number") {
19-
return ast::Type("int64");
19+
return ast::Type("Int64");
2020
}
2121
else if (this->name == "float") {
22-
return ast::Type("float64");
22+
return ast::Type("Float64");
2323
}
2424
else {
2525
return ast::Type(ast::NoType{});
@@ -363,16 +363,16 @@ bool ast::Type::is_concrete() const {
363363
}
364364

365365
bool ast::Type::is_integer() const {
366-
if (*this == ast::Type("int64")) return true;
367-
else if (*this == ast::Type("int32")) return true;
368-
else if (*this == ast::Type("int16")) return true;
369-
else if (*this == ast::Type("int8")) return true;
366+
if (*this == ast::Type("Int64")) return true;
367+
else if (*this == ast::Type("Int32")) return true;
368+
else if (*this == ast::Type("Int16")) return true;
369+
else if (*this == ast::Type("Int8")) return true;
370370
else return false;
371371
}
372372

373373
bool ast::Type::is_float() const {
374-
if (*this == ast::Type("float64")) return true;
375-
else if (*this == ast::Type("float32")) return true;
374+
if (*this == ast::Type("Float64")) return true;
375+
else if (*this == ast::Type("Float32")) return true;
376376
else return false;
377377
}
378378

@@ -381,7 +381,7 @@ bool ast::Type::is_pointer() const {
381381
return false;
382382
}
383383

384-
if (std::get<ast::NominalType>(this->type).name != "pointer") {
384+
if (std::get<ast::NominalType>(this->type).name != "Pointer") {
385385
return false;
386386
}
387387

@@ -393,7 +393,7 @@ bool ast::Type::is_boxed() const {
393393
return false;
394394
}
395395

396-
if (std::get<ast::NominalType>(this->type).name != "boxed") {
396+
if (std::get<ast::NominalType>(this->type).name != "Boxed") {
397397
return false;
398398
}
399399

@@ -426,7 +426,7 @@ bool ast::Type::is_array() const {
426426
}
427427

428428
if (this->as_nominal_type().name.size() < 5
429-
|| this->as_nominal_type().name.substr(0, 5) != "array") {
429+
|| this->as_nominal_type().name.substr(0, 5) != "Array") {
430430
return false;
431431
}
432432

src/codegen/codegen.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -525,13 +525,13 @@ std::string codegen::Context::get_mangled_function_name(std::filesystem::path mo
525525

526526
// Types
527527
llvm::Type* codegen::Context::as_llvm_type(ast::Type type) {
528-
if (type == ast::Type("float64")) return llvm::Type::getDoubleTy(*(this->context));
529-
else if (type == ast::Type("int64")) return llvm::Type::getInt64Ty(*(this->context));
530-
else if (type == ast::Type("int32")) return llvm::Type::getInt32Ty(*(this->context));
531-
else if (type == ast::Type("int8")) return llvm::Type::getInt8Ty(*(this->context));
532-
else if (type == ast::Type("bool")) return llvm::Type::getInt1Ty(*(this->context));
533-
else if (type == ast::Type("string")) return llvm::Type::getInt8PtrTy(*(this->context));
534-
else if (type == ast::Type("void")) return llvm::Type::getVoidTy(*(this->context));
528+
if (type == ast::Type("Float64")) return llvm::Type::getDoubleTy(*(this->context));
529+
else if (type == ast::Type("Int64")) return llvm::Type::getInt64Ty(*(this->context));
530+
else if (type == ast::Type("Int32")) return llvm::Type::getInt32Ty(*(this->context));
531+
else if (type == ast::Type("Int8")) return llvm::Type::getInt8Ty(*(this->context));
532+
else if (type == ast::Type("Bool")) return llvm::Type::getInt1Ty(*(this->context));
533+
else if (type == ast::Type("String")) return llvm::Type::getInt8PtrTy(*(this->context));
534+
else if (type == ast::Type("None")) return llvm::Type::getVoidTy(*(this->context));
535535
else if (type.is_pointer()) return this->as_llvm_type(ast::get_concrete_type(type.as_nominal_type().parameters[0], this->type_bindings))->getPointerTo();
536536
else if (type.is_boxed()) return this->as_llvm_type(ast::get_concrete_type(type.as_nominal_type().parameters[0], this->type_bindings))->getPointerTo();
537537
else if (type.is_array()) {
@@ -598,27 +598,27 @@ codegen::CollectionAsArguments codegen::Context::get_struct_type_as_argument(llv
598598
size_t bytes = 0;
599599
while (bytes < 8) {
600600
if (fields[i]->isDoubleTy()) {
601-
type = ast::Type("float64");
601+
type = ast::Type("Float64");
602602
bytes += 8;
603603
}
604604
else if (fields[i]->isIntegerTy(64)) {
605-
type = ast::Type("int64");
605+
type = ast::Type("Int64");
606606
bytes += 8;
607607
}
608608
else if (fields[i]->isIntegerTy(32)) {
609-
type = ast::Type("int64");
609+
type = ast::Type("Int64");
610610
bytes += 4;
611611
}
612612
else if (fields[i]->isIntegerTy(8)) {
613-
type = ast::Type("int64");
613+
type = ast::Type("Int64");
614614
bytes += 4;
615615
}
616616
else if (fields[i]->isIntegerTy(1)) {
617-
type = ast::Type("int64");
617+
type = ast::Type("Int64");
618618
bytes += 1;
619619
}
620620
else if (fields[i]->isPointerTy()) {
621-
type = ast::Type("int64");
621+
type = ast::Type("Int64");
622622
bytes += 8;
623623
}
624624
else {
@@ -1011,7 +1011,7 @@ void codegen::Context::codegen(ast::Ast& ast) {
10111011
// Codegen array wrapper type
10121012
llvm::StructType* array_type = llvm::StructType::create(*this->context, "arrayWrapper");
10131013
std::vector<llvm::Type*> fields;
1014-
fields.push_back(this->as_llvm_type(ast::Type("int64")));
1014+
fields.push_back(this->as_llvm_type(ast::Type("Int64")));
10151015
fields.push_back(llvm::Type::getVoidTy(*(this->context))->getPointerTo());
10161016
array_type->setBody(fields);
10171017

@@ -1275,15 +1275,15 @@ void codegen::Context::codegen_function_bodies(std::filesystem::path module_path
12751275
}
12761276

12771277
// Codegen body
1278-
if (ast::is_expression(function_body) && return_type != ast::Type("void")) {
1278+
if (ast::is_expression(function_body) && return_type != ast::Type("None")) {
12791279
llvm::Value* result = this->codegen(function_body);
12801280
if (result) {
12811281
this->builder->CreateRet(result);
12821282
}
12831283
}
12841284
else {
12851285
this->codegen(function_body);
1286-
if (return_type == ast::Type("void")) {
1286+
if (return_type == ast::Type("None")) {
12871287
this->builder->CreateRetVoid();
12881288
}
12891289
}
@@ -1440,7 +1440,7 @@ llvm::Value* codegen::Context::codegen(ast::ContinueNode& node) {
14401440
}
14411441

14421442
llvm::Value* codegen::Context::codegen(ast::IfElseNode& node) {
1443-
if (ast::is_expression((ast::Node*) &node) && ast::get_type((ast::Node*) &node) == ast::Type("void")) {
1443+
if (ast::is_expression((ast::Node*) &node) && ast::get_type((ast::Node*) &node) == ast::Type("None")) {
14441444
llvm::Function *current_function = this->builder->GetInsertBlock()->getParent();
14451445
llvm::BasicBlock *block = llvm::BasicBlock::Create(*(this->context), "then", current_function);
14461446
llvm::BasicBlock *else_block = llvm::BasicBlock::Create(*(this->context), "else");
@@ -1710,7 +1710,7 @@ llvm::Value* codegen::Context::codegen_size_function(std::variant<llvm::Value*,
17101710

17111711
// Load size
17121712
return this->builder->CreateLoad(
1713-
this->as_llvm_type(ast::Type("int64")),
1713+
this->as_llvm_type(ast::Type("Int64")),
17141714
size_ptr
17151715
);
17161716
}
@@ -1747,7 +1747,7 @@ llvm::Value* codegen::Context::codegen_print_struct_function(ast::Type arg_type,
17471747
);
17481748
}
17491749
else {
1750-
std::string print_function_name = this->get_mangled_function_name(utilities::get_folder_of_executable() + "/std/std" + ".dmd", "printWithoutLineEnding", {struct_type.as_nominal_type().type_definition->fields[i]->type}, ast::Type("void"), false);
1750+
std::string print_function_name = this->get_mangled_function_name(utilities::get_folder_of_executable() + "/std/std" + ".dmd", "printWithoutLineEnding", {struct_type.as_nominal_type().type_definition->fields[i]->type}, ast::Type("None"), false);
17511751
llvm::Function* llvm_function = this->module->getFunction(print_function_name);
17521752
assert(llvm_function);
17531753

@@ -1964,15 +1964,15 @@ llvm::Value* codegen::Context::codegen(ast::FloatNode& node) {
19641964
}
19651965

19661966
llvm::Value* codegen::Context::codegen(ast::IntegerNode& node) {
1967-
if (ast::get_concrete_type((ast::Node*) &node, this->type_bindings) == ast::Type("float64"))
1967+
if (ast::get_concrete_type((ast::Node*) &node, this->type_bindings) == ast::Type("Float64"))
19681968
return llvm::ConstantFP::get(*(this->context), llvm::APFloat((double)node.value));
1969-
else if (ast::get_concrete_type((ast::Node*) &node, this->type_bindings) == ast::Type("int64")) {
1969+
else if (ast::get_concrete_type((ast::Node*) &node, this->type_bindings) == ast::Type("Int64")) {
19701970
return llvm::ConstantInt::get(*(this->context), llvm::APInt(64, node.value, true));
19711971
}
1972-
else if (ast::get_concrete_type((ast::Node*) &node, this->type_bindings) == ast::Type("int32")) {
1972+
else if (ast::get_concrete_type((ast::Node*) &node, this->type_bindings) == ast::Type("Int32")) {
19731973
return llvm::ConstantInt::get(*(this->context), llvm::APInt(32, node.value, true));
19741974
}
1975-
else if (ast::get_concrete_type((ast::Node*) &node, this->type_bindings) == ast::Type("int8")) {
1975+
else if (ast::get_concrete_type((ast::Node*) &node, this->type_bindings) == ast::Type("Int8")) {
19761976
return llvm::ConstantInt::get(*(this->context), llvm::APInt(8, node.value, true));
19771977
}
19781978

src/semantic/intrinsics.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
#include "../utilities.hpp"
33

44
Set<std::string> primitive_types = Set<std::string>({
5-
"int8",
6-
"int32",
7-
"int64",
8-
"float64",
9-
"bool",
10-
"string",
11-
"void"
5+
"Int8",
6+
"Int32",
7+
"Int64",
8+
"Float64",
9+
"Bool",
10+
"String",
11+
"None"
1212
});
1313

1414
extern Set<std::filesystem::path> std_libs = Set<std::filesystem::path>({

src/semantic/semantic.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Result<Ok, Error> semantic::analyze_block_or_expression(semantic::Context& conte
149149
for (size_t i = 0; i < context.type_inference.type_constraints.size(); i++) {
150150
if (context.type_inference.type_constraints[i].contains(context.current_function.value()->return_type)) {
151151
if (context.type_inference.type_constraints[i].size() == 1) {
152-
context.type_inference.type_constraints[i].insert(ast::Type("void"));
152+
context.type_inference.type_constraints[i].insert(ast::Type("None"));
153153
}
154154
}
155155
}
@@ -173,9 +173,9 @@ Result<Ok, Error> semantic::analyze_block_or_expression(semantic::Context& conte
173173
ast::Type representative = representatives[0];
174174
for (size_t i = 1; i < representatives.size(); i++) {
175175
if (representative.is_nominal_type() && representatives[i].is_nominal_type()) {
176-
if ((representative.as_nominal_type().name == "boxed" || representatives[i].as_nominal_type().name == "boxed")
177-
&& (representative.as_nominal_type().name == "pointer" || representatives[i].as_nominal_type().name == "pointer")) {
178-
representative = representative.as_nominal_type().name == "boxed" ? representative : representatives[i];
176+
if ((representative.as_nominal_type().name == "Boxed" || representatives[i].as_nominal_type().name == "Boxed")
177+
&& (representative.as_nominal_type().name == "Pointer" || representatives[i].as_nominal_type().name == "Pointer")) {
178+
representative = representative.as_nominal_type().name == "Boxed" ? representative : representatives[i];
179179
}
180180
else if (representative.is_array() || representatives[i].is_array()) {
181181
if (representative.array_size_known() && representatives[i].array_size_known()) {
@@ -396,13 +396,13 @@ Result<Ok, Error> semantic::analyze(semantic::Context& context, ast::FunctionNod
396396
Result<Ok, Error> semantic::analyze(semantic::Context& context, ast::Type& type) {
397397
if (type.is_type_variable()) return Ok {};
398398
else if (type.is_final_type_variable()) return Ok {};
399-
else if (type == ast::Type("int64")) return Ok {};
400-
else if (type == ast::Type("int32")) return Ok {};
401-
else if (type == ast::Type("int8")) return Ok {};
402-
else if (type == ast::Type("float64")) return Ok {};
403-
else if (type == ast::Type("bool")) return Ok {};
404-
else if (type == ast::Type("void")) return Ok {};
405-
else if (type == ast::Type("string")) return Ok {};
399+
else if (type == ast::Type("Int64")) return Ok {};
400+
else if (type == ast::Type("Int32")) return Ok {};
401+
else if (type == ast::Type("Int8")) return Ok {};
402+
else if (type == ast::Type("Float64")) return Ok {};
403+
else if (type == ast::Type("Bool")) return Ok {};
404+
else if (type == ast::Type("None")) return Ok {};
405+
else if (type == ast::Type("String")) return Ok {};
406406
else if (type.is_pointer()) return semantic::analyze(context, type.as_nominal_type().parameters[0]);
407407
else if (type.is_boxed()) return semantic::analyze(context, type.as_nominal_type().parameters[0]);
408408
else if (type.is_array()) return semantic::analyze(context, type.as_nominal_type().parameters[0]);
@@ -462,7 +462,7 @@ bool semantic::are_types_compatible(ast::FunctionNode& function, semantic::Funct
462462
}
463463
return true;
464464
}
465-
if (function_type.as_nominal_type().name == "array" && argument_type.is_array()) {
465+
if (function_type.as_nominal_type().name == "Array" && argument_type.is_array()) {
466466
for (size_t i = 0; i < function_type.as_nominal_type().parameters.size(); i++) {
467467
if (!semantic::are_types_compatible(function, function_and_types_scopes, function_type.as_nominal_type().parameters[i], argument_type.as_nominal_type().parameters[i])) {
468468
return false;
@@ -677,7 +677,7 @@ Result<ast::Type, Error> semantic::get_function_type(Context& context, ast::Node
677677
auto& struct_type = call_args[0];
678678
for (auto field: struct_type.as_nominal_type().type_definition->fields) {
679679
auto print_function = semantic::get_binding(context, "printWithoutLineEnding");
680-
(void) semantic::get_function_type(context, print_function.value().value, {false}, {field->type}, ast::Type("void"));
680+
(void) semantic::get_function_type(context, print_function.value().value, {false}, {field->type}, ast::Type("None"));
681681
}
682682
}
683683

src/semantic/type_infer.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Result<Ok, Error> semantic::type_infer_and_analyze(semantic::Context& context, a
4141
case ast::Call: break;
4242
case ast::Return: {
4343
if (result.is_ok()) {
44-
auto return_type = std::get<ast::ReturnNode>(*node.statements[i]).expression.has_value() ? ast::get_type(std::get<ast::ReturnNode>(*node.statements[i]).expression.value()) : ast::Type("void");
44+
auto return_type = std::get<ast::ReturnNode>(*node.statements[i]).expression.has_value() ? ast::get_type(std::get<ast::ReturnNode>(*node.statements[i]).expression.value()) : ast::Type("None");
4545
node.type = return_type;
4646
}
4747
break;
@@ -65,7 +65,7 @@ Result<Ok, Error> semantic::type_infer_and_analyze(semantic::Context& context, a
6565
case ast::While: break;
6666
case ast::Break:
6767
case ast::Continue: {
68-
node.type = ast::Type("void");
68+
node.type = ast::Type("None");
6969
break;
7070
}
7171
default: assert(false);
@@ -185,7 +185,7 @@ Result<Ok, Error> semantic::type_infer_and_analyze(semantic::Context& context, a
185185
}
186186
else {
187187
assert(context.current_function.has_value());
188-
semantic::add_constraint(context, Set<ast::Type>({context.current_function.value()->return_type, ast::Type("void")}));
188+
semantic::add_constraint(context, Set<ast::Type>({context.current_function.value()->return_type, ast::Type("None")}));
189189
}
190190

191191
return Ok {};
@@ -292,17 +292,17 @@ Result<Ok, Error> semantic::type_infer_and_analyze(semantic::Context& context, a
292292
}
293293

294294
Result<Ok, Error> semantic::type_infer_and_analyze(semantic::Context& context, ast::BooleanNode& node) {
295-
node.type = ast::Type("bool");
295+
node.type = ast::Type("Bool");
296296
return Ok {};
297297
}
298298

299299
Result<Ok, Error> semantic::type_infer_and_analyze(semantic::Context& context, ast::StringNode& node) {
300-
node.type = ast::Type("string");
300+
node.type = ast::Type("String");
301301
return Ok {};
302302
}
303303

304304
Result<Ok, Error> semantic::type_infer_and_analyze(semantic::Context& context, ast::InterpolatedStringNode& node) {
305-
node.type = ast::Type("string");
305+
node.type = ast::Type("String");
306306
for (auto expression: node.expressions) {
307307
auto result = semantic::type_infer_and_analyze(context, expression);
308308
if (result.is_error()) return result;
@@ -327,13 +327,13 @@ Result<Ok, Error> semantic::type_infer_and_analyze(semantic::Context& context, a
327327
}
328328

329329
if (node.type.is_no_type()) {
330-
node.type = ast::Type(ast::NominalType("array" + std::to_string(node.elements.size())));
330+
node.type = ast::Type(ast::NominalType("Array" + std::to_string(node.elements.size())));
331331
if (node.elements.size() > 0) {
332332
node.type.as_nominal_type().parameters.push_back(ast::get_type(node.elements[0]));
333333
}
334334
}
335-
else if (node.type.is_array() && node.type.as_nominal_type().name == "array") {
336-
node.type = ast::Type(ast::NominalType("array" + std::to_string(node.elements.size())));
335+
else if (node.type.is_array() && node.type.as_nominal_type().name == "Array") {
336+
node.type = ast::Type(ast::NominalType("Array" + std::to_string(node.elements.size())));
337337
if (node.elements.size() > 0) {
338338
node.type.as_nominal_type().parameters.push_back(ast::get_type(node.elements[0]));
339339
}
@@ -630,7 +630,7 @@ Result<Ok, Error> semantic::type_infer_and_analyze(semantic::Context& context, a
630630
}
631631

632632
if (node.type.is_no_type()) {
633-
node.type = ast::Type(ast::NominalType("pointer"));
633+
node.type = ast::Type(ast::NominalType("Pointer"));
634634
node.type.as_nominal_type().parameters.push_back(ast::get_type(node.expression));
635635
}
636636
else if (!node.type.is_type_variable() && !node.type.is_pointer()) {
@@ -680,10 +680,10 @@ Result<Ok, Error> semantic::type_infer_and_analyze(semantic::Context& context, a
680680
}
681681

682682
if (node.type.is_no_type()) {
683-
node.type = ast::Type(ast::NominalType("boxed"));
683+
node.type = ast::Type(ast::NominalType("Boxed"));
684684
node.type.as_nominal_type().parameters.push_back(ast::get_type(node.expression));
685685
}
686-
else if (!node.type.is_type_variable() && !(node.type.as_nominal_type().name != "boxed")) {
686+
else if (!node.type.is_type_variable() && !(node.type.as_nominal_type().name != "Boxed")) {
687687
context.errors.push_back(Error("Error: Type mismatch between type annotation and expression"));
688688
return Error {};
689689
}

0 commit comments

Comments
 (0)