mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Factor Heap class out of State (#491)
Additional miscellaneous cleanup: - Use the term "deallocate" instead of "kill" in function names, for symmetry with "allocate". - Drop an unnecessary memory allocation in `AllocateValue`. - Implement `PrintHeap` in terms of `PrintAddress`, so that dead values are flagged with `!!`.
This commit is contained in:
@@ -214,13 +214,6 @@ auto MakeChoiceTypeVal(std::string name,
|
||||
return v;
|
||||
}
|
||||
|
||||
auto State::PrintAddress(Address a, std::ostream& out) -> void {
|
||||
if (!this->alive[a]) {
|
||||
out << "!!";
|
||||
}
|
||||
PrintValue(this->heap[a], out);
|
||||
}
|
||||
|
||||
auto PrintValue(const Value* val, std::ostream& out) -> void {
|
||||
switch (val->tag) {
|
||||
case ValKind::AltConsV: {
|
||||
@@ -235,7 +228,7 @@ auto PrintValue(const Value* val, std::ostream& out) -> void {
|
||||
case ValKind::AltV: {
|
||||
out << "alt " << *val->u.alt.choice_name << "." << *val->u.alt.alt_name
|
||||
<< " ";
|
||||
state->PrintAddress(val->u.alt.argument, out);
|
||||
state->heap.PrintAddress(val->u.alt.argument, out);
|
||||
break;
|
||||
}
|
||||
case ValKind::StructV: {
|
||||
@@ -254,7 +247,7 @@ auto PrintValue(const Value* val, std::ostream& out) -> void {
|
||||
}
|
||||
|
||||
out << elt.first << " = ";
|
||||
state->PrintAddress(elt.second, out);
|
||||
state->heap.PrintAddress(elt.second, out);
|
||||
out << "@" << elt.second;
|
||||
}
|
||||
out << ")";
|
||||
@@ -342,9 +335,8 @@ auto TypeEqual(const Value* t1, const Value* t2) -> bool {
|
||||
if ((*t1->u.tuple.elts)[i].first != (*t2->u.tuple.elts)[i].first) {
|
||||
return false;
|
||||
}
|
||||
if (!TypeEqual(
|
||||
state->ReadFromMemory((*t1->u.tuple.elts)[i].second, 0),
|
||||
state->ReadFromMemory((*t2->u.tuple.elts)[i].second, 0))) {
|
||||
if (!TypeEqual(state->heap.Read((*t1->u.tuple.elts)[i].second, 0),
|
||||
state->heap.Read((*t2->u.tuple.elts)[i].second, 0))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -378,8 +370,8 @@ static auto FieldsValueEqual(VarAddresses* ts1, VarAddresses* ts2, int line_num)
|
||||
if (iter == ts2->end()) {
|
||||
return false;
|
||||
}
|
||||
if (!ValueEqual(state->ReadFromMemory(address, line_num),
|
||||
state->ReadFromMemory(iter->second, line_num), line_num)) {
|
||||
if (!ValueEqual(state->heap.Read(address, line_num),
|
||||
state->heap.Read(iter->second, line_num), line_num)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user