Generic classes (#1124)

* start of generic classes

* fix regressions

* class functions in interfaces

* access to class function on interface from class parameter

* more stuff working for generic classes

* fixing bugs

* update TypeEqual for generic classes

* fixing bugs and finding new ones

* disable unqualified access to members from other members for now

* minor edits

* bug fixes

* introduce compile_time_value to use in type checker instead of constant_value

* cleanup

* put a CHECK back in

* failure test cases for the new FATAL_COMPILATION_ERROR

* change a runtime FATAL into a FATAL_COMPILATION_ERROR

* Update executable_semantics/ast/declaration.h

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/interpreter/action_stack.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/interpreter/interpreter.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/interpreter/value.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/interpreter/value.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/interpreter/interpreter.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/interpreter/value.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/interpreter/value.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/interpreter/resolve_names.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/interpreter/type_checker.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/interpreter/type_checker.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/interpreter/type_checker.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* responses to reviews

* Update executable_semantics/interpreter/type_checker.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* rename compile_time_value to symbolic_identity

* Update executable_semantics/interpreter/type_checker.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/interpreter/type_checker.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/interpreter/type_checker.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/interpreter/type_checker.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/interpreter/type_checker.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/interpreter/type_checker.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/interpreter/value.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/interpreter/value.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* Update executable_semantics/interpreter/value.cpp

Co-authored-by: Jon Meow <jperkins@google.com>

* more edits from review

* Apply suggestions from code review

Co-authored-by: Geoff Romer <gromer@google.com>

* review responses

* Update executable_semantics/interpreter/interpreter.cpp

Co-authored-by: Geoff Romer <gromer@google.com>

* const impl_scope for TypeCheckChoiceDeclaration

* add some const

Co-authored-by: Jon Meow <jperkins@google.com>
Co-authored-by: Geoff Romer <gromer@google.com>
This commit is contained in:
Jeremy G. Siek
2022-03-29 13:09:41 -04:00
committed by GitHub
co-authored by Jon Meow Geoff Romer
parent 37a0e35b31
commit 210856dd57
41 changed files with 1597 additions and 401 deletions
+58 -29
View File
@@ -116,12 +116,6 @@ void Expression::Print(llvm::raw_ostream& out) const {
PrintFields(out, cast<StructTypeLiteral>(*this).fields(), ": ");
out << "}";
break;
case ExpressionKind::IntLiteral:
out << cast<IntLiteral>(*this).value();
break;
case ExpressionKind::BoolLiteral:
out << (cast<BoolLiteral>(*this).value() ? "true" : "false");
break;
case ExpressionKind::PrimitiveOperatorExpression: {
out << "(";
const auto& op = cast<PrimitiveOperatorExpression>(*this);
@@ -142,9 +136,6 @@ void Expression::Print(llvm::raw_ostream& out) const {
out << ")";
break;
}
case ExpressionKind::IdentifierExpression:
out << cast<IdentifierExpression>(*this).name();
break;
case ExpressionKind::CallExpression: {
const auto& call = cast<CallExpression>(*this);
out << call.function();
@@ -155,26 +146,6 @@ void Expression::Print(llvm::raw_ostream& out) const {
}
break;
}
case ExpressionKind::BoolTypeLiteral:
out << "Bool";
break;
case ExpressionKind::IntTypeLiteral:
out << "i32";
break;
case ExpressionKind::StringLiteral:
out << "\"";
out.write_escaped(cast<StringLiteral>(*this).value());
out << "\"";
break;
case ExpressionKind::StringTypeLiteral:
out << "String";
break;
case ExpressionKind::TypeTypeLiteral:
out << "Type";
break;
case ExpressionKind::ContinuationTypeLiteral:
out << "Continuation";
break;
case ExpressionKind::FunctionTypeLiteral: {
const auto& fn = cast<FunctionTypeLiteral>(*this);
out << "fn " << fn.parameter() << " -> " << fn.return_type();
@@ -205,6 +176,64 @@ void Expression::Print(llvm::raw_ostream& out) const {
out << ")";
break;
}
case ExpressionKind::IdentifierExpression:
case ExpressionKind::IntLiteral:
case ExpressionKind::BoolLiteral:
case ExpressionKind::BoolTypeLiteral:
case ExpressionKind::IntTypeLiteral:
case ExpressionKind::StringLiteral:
case ExpressionKind::StringTypeLiteral:
case ExpressionKind::TypeTypeLiteral:
case ExpressionKind::ContinuationTypeLiteral:
PrintID(out);
break;
}
}
void Expression::PrintID(llvm::raw_ostream& out) const {
switch (kind()) {
case ExpressionKind::IdentifierExpression:
out << cast<IdentifierExpression>(*this).name();
break;
case ExpressionKind::IntLiteral:
out << cast<IntLiteral>(*this).value();
break;
case ExpressionKind::BoolLiteral:
out << (cast<BoolLiteral>(*this).value() ? "true" : "false");
break;
case ExpressionKind::BoolTypeLiteral:
out << "Bool";
break;
case ExpressionKind::IntTypeLiteral:
out << "i32";
break;
case ExpressionKind::StringLiteral:
out << "\"";
out.write_escaped(cast<StringLiteral>(*this).value());
out << "\"";
break;
case ExpressionKind::StringTypeLiteral:
out << "String";
break;
case ExpressionKind::TypeTypeLiteral:
out << "Type";
break;
case ExpressionKind::ContinuationTypeLiteral:
out << "Continuation";
break;
case ExpressionKind::IndexExpression:
case ExpressionKind::FieldAccessExpression:
case ExpressionKind::IfExpression:
case ExpressionKind::TupleLiteral:
case ExpressionKind::StructLiteral:
case ExpressionKind::StructTypeLiteral:
case ExpressionKind::CallExpression:
case ExpressionKind::PrimitiveOperatorExpression:
case ExpressionKind::IntrinsicExpression:
case ExpressionKind::UnimplementedExpression:
case ExpressionKind::FunctionTypeLiteral:
out << "...";
break;
}
}