mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-27 21:20:09 +01:00
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:
@@ -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*> {
|
||||
|
||||
Reference in New Issue
Block a user