Switch Value to Ptr (#799)

Co-authored-by: Geoff Romer <gromer@google.com>
This commit is contained in:
Jon Meow
2021-09-01 15:59:56 -07:00
committed by GitHub
co-authored by Geoff Romer
parent 31b4f1e7ac
commit 0601f5620b
10 changed files with 307 additions and 308 deletions
+3 -5
View File
@@ -9,25 +9,23 @@
namespace Carbon {
auto Heap::AllocateValue(const Value* v) -> Address {
auto Heap::AllocateValue(Ptr<const Value> v) -> Address {
// Putting the following two side effects together in this function
// ensures that we don't do anything else in between, which is really bad!
// Consider whether to include a copy of the input v in this function
// or to leave it up to the caller.
CHECK(v != nullptr);
Address a(values_.size());
values_.push_back(v);
alive_.push_back(true);
return a;
}
auto Heap::Read(const Address& a, SourceLocation loc) -> const Value* {
auto Heap::Read(const Address& a, SourceLocation loc) -> Ptr<const Value> {
this->CheckAlive(a, loc);
return values_[a.index]->GetField(a.field_path, loc);
}
void Heap::Write(const Address& a, const Value* v, SourceLocation loc) {
CHECK(v != nullptr);
void Heap::Write(const Address& a, Ptr<const Value> v, SourceLocation loc) {
this->CheckAlive(a, loc);
values_[a.index] = values_[a.index]->SetField(a.field_path, v, loc);
}