mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 21:21:19 +01:00
Extends carbon to generate random number to make samples more interesting (#1643)
Implements the Rand function to carbon Co-authored-by: m new <michael.burzan@outlook.de>
This commit is contained in:
@@ -29,7 +29,8 @@ auto IntrinsicExpression::FindIntrinsic(std::string_view name,
|
||||
static const auto& intrinsic_map = *new std::map<std::string_view, Intrinsic>(
|
||||
{{"print", Intrinsic::Print},
|
||||
{"new", Intrinsic::Alloc},
|
||||
{"delete", Intrinsic::Dealloc}});
|
||||
{"delete", Intrinsic::Dealloc},
|
||||
{"rand", Intrinsic::Rand}});
|
||||
name.remove_prefix(std::strlen("__intrinsic_"));
|
||||
auto it = intrinsic_map.find(name);
|
||||
if (it == intrinsic_map.end()) {
|
||||
@@ -175,6 +176,7 @@ void Expression::Print(llvm::raw_ostream& out) const {
|
||||
out << "Print" << iexp.args();
|
||||
break;
|
||||
}
|
||||
|
||||
out << "intrinsic_";
|
||||
switch (iexp.intrinsic()) {
|
||||
case IntrinsicExpression::Intrinsic::Print:
|
||||
@@ -186,6 +188,9 @@ void Expression::Print(llvm::raw_ostream& out) const {
|
||||
case IntrinsicExpression::Intrinsic::Dealloc:
|
||||
out << "delete";
|
||||
break;
|
||||
case IntrinsicExpression::Intrinsic::Rand:
|
||||
out << "rand";
|
||||
break;
|
||||
}
|
||||
out << iexp.args();
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user