Express prelude using Carbon syntax (#955)

This should be clearer, more maintainable, and more scalable than building the prelude AST by hand.
This commit is contained in:
Geoff Romer
2021-11-29 13:56:55 -08:00
committed by GitHub
parent b14c97d0d7
commit 3e188c8562
9 changed files with 106 additions and 38 deletions
+14
View File
@@ -4,6 +4,7 @@
#include "executable_semantics/ast/expression.h"
#include <map>
#include <optional>
#include "executable_semantics/common/arena.h"
@@ -17,6 +18,19 @@ namespace Carbon {
using llvm::cast;
using llvm::isa;
auto IntrinsicExpression::FindIntrinsic(std::string_view name,
SourceLocation source_loc)
-> Intrinsic {
static const auto& intrinsic_map =
*new std::map<std::string_view, Intrinsic>({{"print", Intrinsic::Print}});
name.remove_prefix(std::strlen("__intrinsic_"));
auto it = intrinsic_map.find(name);
if (it == intrinsic_map.end()) {
FATAL_COMPILATION_ERROR(source_loc) << "Unknown intrinsic '" << name << "'";
}
return it->second;
}
auto ExpressionFromParenContents(
Nonnull<Arena*> arena, SourceLocation source_loc,
const ParenContents<Expression>& paren_contents) -> Nonnull<Expression*> {