mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 06:54:44 +01:00
improved checking for liveness when reading and writing memory (#448)
* improved checking for liveness when reading and writing memory * moving some functions to be methods of State * finished moving functions into State * Update executable_semantics/interpreter/interpreter.h Co-authored-by: Geoff Romer <gromer@google.com> * moved some comments, other minor edits Co-authored-by: Geoff Romer <gromer@google.com>
This commit is contained in:
committed by
GitHub
co-authored by
Geoff Romer
parent
7e81fb9c62
commit
27fd9de5bf
@@ -59,10 +59,30 @@ struct Frame {
|
||||
continuation(UINT_MAX) {}
|
||||
};
|
||||
|
||||
// TODO(geoffromer): Make this a class, with all members private
|
||||
struct State {
|
||||
Stack<Frame*> stack;
|
||||
std::vector<const Value*> heap;
|
||||
std::vector<bool> alive;
|
||||
|
||||
// Returns the value at the given address in the heap after
|
||||
// checking that it is alive.
|
||||
auto ReadFromMemory(Address a, int line_num) -> const Value*;
|
||||
// Writes the given value at the address in the heap after
|
||||
// checking that the address is alive.
|
||||
auto WriteToMemory(Address a, const Value* v, int line_num) -> void;
|
||||
// Print the value at the given address to the stream `out`.
|
||||
auto PrintAddress(Address a, std::ostream& out) -> void;
|
||||
// Signal an error if the address is no longer alive.
|
||||
void CheckAlive(Address address, int line_num);
|
||||
// Put the given value on the heap and mark it as alive.
|
||||
auto AllocateValue(const Value* v) -> Address;
|
||||
// Marks the object at this address, and all of its sub-objects, as dead.
|
||||
auto KillObject(Address address) -> void;
|
||||
// Print all the values on the heap to the stream `out`.
|
||||
auto PrintHeap(std::ostream& out) -> void;
|
||||
|
||||
private:
|
||||
std::vector<const Value*> heap;
|
||||
};
|
||||
|
||||
extern State* state;
|
||||
@@ -70,7 +90,6 @@ extern State* state;
|
||||
auto PrintFrame(Frame* frame, std::ostream& out) -> void;
|
||||
void PrintStack(Stack<Frame*> ls, std::ostream& out);
|
||||
void PrintEnv(Env values);
|
||||
auto AllocateValue(const Value* v) -> Address;
|
||||
auto CopyVal(const Value* val, int line_num) -> const Value*;
|
||||
auto ToInteger(const Value* v) -> int;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user